162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci * Marvell OcteonTX CPT driver
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2019 Marvell International Ltd.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
762306a36Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as
862306a36Sopenharmony_ci * published by the Free Software Foundation.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __OTX_CPTVF_H
1262306a36Sopenharmony_ci#define __OTX_CPTVF_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/list.h>
1562306a36Sopenharmony_ci#include <linux/interrupt.h>
1662306a36Sopenharmony_ci#include <linux/device.h>
1762306a36Sopenharmony_ci#include "otx_cpt_common.h"
1862306a36Sopenharmony_ci#include "otx_cptvf_reqmgr.h"
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* Flags to indicate the features supported */
2162306a36Sopenharmony_ci#define OTX_CPT_FLAG_DEVICE_READY  BIT(1)
2262306a36Sopenharmony_ci#define otx_cpt_device_ready(cpt)  ((cpt)->flags & OTX_CPT_FLAG_DEVICE_READY)
2362306a36Sopenharmony_ci/* Default command queue length */
2462306a36Sopenharmony_ci#define OTX_CPT_CMD_QLEN	(4*2046)
2562306a36Sopenharmony_ci#define OTX_CPT_CMD_QCHUNK_SIZE	1023
2662306a36Sopenharmony_ci#define OTX_CPT_NUM_QS_PER_VF	1
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistruct otx_cpt_cmd_chunk {
2962306a36Sopenharmony_ci	u8 *head;
3062306a36Sopenharmony_ci	dma_addr_t dma_addr;
3162306a36Sopenharmony_ci	u32 size; /* Chunk size, max OTX_CPT_INST_CHUNK_MAX_SIZE */
3262306a36Sopenharmony_ci	struct list_head nextchunk;
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct otx_cpt_cmd_queue {
3662306a36Sopenharmony_ci	u32 idx;	/* Command queue host write idx */
3762306a36Sopenharmony_ci	u32 num_chunks;	/* Number of command chunks */
3862306a36Sopenharmony_ci	struct otx_cpt_cmd_chunk *qhead;/*
3962306a36Sopenharmony_ci					 * Command queue head, instructions
4062306a36Sopenharmony_ci					 * are inserted here
4162306a36Sopenharmony_ci					 */
4262306a36Sopenharmony_ci	struct otx_cpt_cmd_chunk *base;
4362306a36Sopenharmony_ci	struct list_head chead;
4462306a36Sopenharmony_ci};
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistruct otx_cpt_cmd_qinfo {
4762306a36Sopenharmony_ci	u32 qchunksize; /* Command queue chunk size */
4862306a36Sopenharmony_ci	struct otx_cpt_cmd_queue queue[OTX_CPT_NUM_QS_PER_VF];
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistruct otx_cpt_pending_qinfo {
5262306a36Sopenharmony_ci	u32 num_queues;	/* Number of queues supported */
5362306a36Sopenharmony_ci	struct otx_cpt_pending_queue queue[OTX_CPT_NUM_QS_PER_VF];
5462306a36Sopenharmony_ci};
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define for_each_pending_queue(qinfo, q, i)	\
5762306a36Sopenharmony_ci		for (i = 0, q = &qinfo->queue[i]; i < qinfo->num_queues; i++, \
5862306a36Sopenharmony_ci		     q = &qinfo->queue[i])
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct otx_cptvf_wqe {
6162306a36Sopenharmony_ci	struct tasklet_struct twork;
6262306a36Sopenharmony_ci	struct otx_cptvf *cptvf;
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct otx_cptvf_wqe_info {
6662306a36Sopenharmony_ci	struct otx_cptvf_wqe vq_wqe[OTX_CPT_NUM_QS_PER_VF];
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistruct otx_cptvf {
7062306a36Sopenharmony_ci	u16 flags;	/* Flags to hold device status bits */
7162306a36Sopenharmony_ci	u8 vfid;	/* Device Index 0...OTX_CPT_MAX_VF_NUM */
7262306a36Sopenharmony_ci	u8 num_vfs;	/* Number of enabled VFs */
7362306a36Sopenharmony_ci	u8 vftype;	/* VF type of SE_TYPE(2) or AE_TYPE(1) */
7462306a36Sopenharmony_ci	u8 vfgrp;	/* VF group (0 - 8) */
7562306a36Sopenharmony_ci	u8 node;	/* Operating node: Bits (46:44) in BAR0 address */
7662306a36Sopenharmony_ci	u8 priority;	/*
7762306a36Sopenharmony_ci			 * VF priority ring: 1-High proirity round
7862306a36Sopenharmony_ci			 * robin ring;0-Low priority round robin ring;
7962306a36Sopenharmony_ci			 */
8062306a36Sopenharmony_ci	struct pci_dev *pdev;	/* Pci device handle */
8162306a36Sopenharmony_ci	void __iomem *reg_base;	/* Register start address */
8262306a36Sopenharmony_ci	void *wqe_info;		/* BH worker info */
8362306a36Sopenharmony_ci	/* MSI-X */
8462306a36Sopenharmony_ci	cpumask_var_t affinity_mask[OTX_CPT_VF_MSIX_VECTORS];
8562306a36Sopenharmony_ci	/* Command and Pending queues */
8662306a36Sopenharmony_ci	u32 qsize;
8762306a36Sopenharmony_ci	u32 num_queues;
8862306a36Sopenharmony_ci	struct otx_cpt_cmd_qinfo cqinfo; /* Command queue information */
8962306a36Sopenharmony_ci	struct otx_cpt_pending_qinfo pqinfo; /* Pending queue information */
9062306a36Sopenharmony_ci	/* VF-PF mailbox communication */
9162306a36Sopenharmony_ci	bool pf_acked;
9262306a36Sopenharmony_ci	bool pf_nacked;
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciint otx_cptvf_send_vf_up(struct otx_cptvf *cptvf);
9662306a36Sopenharmony_ciint otx_cptvf_send_vf_down(struct otx_cptvf *cptvf);
9762306a36Sopenharmony_ciint otx_cptvf_send_vf_to_grp_msg(struct otx_cptvf *cptvf, int group);
9862306a36Sopenharmony_ciint otx_cptvf_send_vf_priority_msg(struct otx_cptvf *cptvf);
9962306a36Sopenharmony_ciint otx_cptvf_send_vq_size_msg(struct otx_cptvf *cptvf);
10062306a36Sopenharmony_ciint otx_cptvf_check_pf_ready(struct otx_cptvf *cptvf);
10162306a36Sopenharmony_civoid otx_cptvf_handle_mbox_intr(struct otx_cptvf *cptvf);
10262306a36Sopenharmony_civoid otx_cptvf_write_vq_doorbell(struct otx_cptvf *cptvf, u32 val);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#endif /* __OTX_CPTVF_H */
105