18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Linux network driver for QLogic BR-series Converged Network Adapter.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
78c2ecf20Sopenharmony_ci * Copyright (c) 2014-2015 QLogic Corporation
88c2ecf20Sopenharmony_ci * All rights reserved
98c2ecf20Sopenharmony_ci * www.qlogic.com
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __BFA_MSGQ_H__
138c2ecf20Sopenharmony_ci#define __BFA_MSGQ_H__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "bfa_defs.h"
168c2ecf20Sopenharmony_ci#include "bfi.h"
178c2ecf20Sopenharmony_ci#include "bfa_ioc.h"
188c2ecf20Sopenharmony_ci#include "bfa_cs.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define BFA_MSGQ_FREE_CNT(_q)						\
218c2ecf20Sopenharmony_ci	(((_q)->consumer_index - (_q)->producer_index - 1) & ((_q)->depth - 1))
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define BFA_MSGQ_INDX_ADD(_q_indx, _qe_num, _q_depth)			\
248c2ecf20Sopenharmony_ci	((_q_indx) = (((_q_indx) + (_qe_num)) & ((_q_depth) - 1)))
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define BFA_MSGQ_CMDQ_NUM_ENTRY		128
278c2ecf20Sopenharmony_ci#define BFA_MSGQ_CMDQ_SIZE						\
288c2ecf20Sopenharmony_ci	(BFI_MSGQ_CMD_ENTRY_SIZE * BFA_MSGQ_CMDQ_NUM_ENTRY)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define BFA_MSGQ_RSPQ_NUM_ENTRY		128
318c2ecf20Sopenharmony_ci#define BFA_MSGQ_RSPQ_SIZE						\
328c2ecf20Sopenharmony_ci	(BFI_MSGQ_RSP_ENTRY_SIZE * BFA_MSGQ_RSPQ_NUM_ENTRY)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define bfa_msgq_cmd_set(_cmd, _cbfn, _cbarg, _msg_size, _msg_hdr)	\
358c2ecf20Sopenharmony_cido {									\
368c2ecf20Sopenharmony_ci	(_cmd)->cbfn = (_cbfn);						\
378c2ecf20Sopenharmony_ci	(_cmd)->cbarg = (_cbarg);					\
388c2ecf20Sopenharmony_ci	(_cmd)->msg_size = (_msg_size);					\
398c2ecf20Sopenharmony_ci	(_cmd)->msg_hdr = (_msg_hdr);					\
408c2ecf20Sopenharmony_ci} while (0)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct bfa_msgq;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_citypedef void (*bfa_msgq_cmdcbfn_t)(void *cbarg, enum bfa_status status);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct bfa_msgq_cmd_entry {
478c2ecf20Sopenharmony_ci	struct list_head				qe;
488c2ecf20Sopenharmony_ci	bfa_msgq_cmdcbfn_t		cbfn;
498c2ecf20Sopenharmony_ci	void				*cbarg;
508c2ecf20Sopenharmony_ci	size_t				msg_size;
518c2ecf20Sopenharmony_ci	struct bfi_msgq_mhdr *msg_hdr;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cienum bfa_msgq_cmdq_flags {
558c2ecf20Sopenharmony_ci	BFA_MSGQ_CMDQ_F_DB_UPDATE	= 1,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct bfa_msgq_cmdq {
598c2ecf20Sopenharmony_ci	bfa_fsm_t			fsm;
608c2ecf20Sopenharmony_ci	enum bfa_msgq_cmdq_flags flags;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	u16			producer_index;
638c2ecf20Sopenharmony_ci	u16			consumer_index;
648c2ecf20Sopenharmony_ci	u16			depth; /* FW Q depth is 16 bits */
658c2ecf20Sopenharmony_ci	struct bfa_dma addr;
668c2ecf20Sopenharmony_ci	struct bfa_mbox_cmd dbell_mb;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	u16			token;
698c2ecf20Sopenharmony_ci	int				offset;
708c2ecf20Sopenharmony_ci	int				bytes_to_copy;
718c2ecf20Sopenharmony_ci	struct bfa_mbox_cmd copy_mb;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	struct list_head		pending_q; /* pending command queue */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	struct bfa_msgq *msgq;
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cienum bfa_msgq_rspq_flags {
798c2ecf20Sopenharmony_ci	BFA_MSGQ_RSPQ_F_DB_UPDATE	= 1,
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_citypedef void (*bfa_msgq_mcfunc_t)(void *cbarg, struct bfi_msgq_mhdr *mhdr);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistruct bfa_msgq_rspq {
858c2ecf20Sopenharmony_ci	bfa_fsm_t			fsm;
868c2ecf20Sopenharmony_ci	enum bfa_msgq_rspq_flags flags;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	u16			producer_index;
898c2ecf20Sopenharmony_ci	u16			consumer_index;
908c2ecf20Sopenharmony_ci	u16			depth; /* FW Q depth is 16 bits */
918c2ecf20Sopenharmony_ci	struct bfa_dma addr;
928c2ecf20Sopenharmony_ci	struct bfa_mbox_cmd dbell_mb;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	int				nmclass;
958c2ecf20Sopenharmony_ci	struct {
968c2ecf20Sopenharmony_ci		bfa_msgq_mcfunc_t	cbfn;
978c2ecf20Sopenharmony_ci		void			*cbarg;
988c2ecf20Sopenharmony_ci	} rsphdlr[BFI_MC_MAX];
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	struct bfa_msgq *msgq;
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistruct bfa_msgq {
1048c2ecf20Sopenharmony_ci	struct bfa_msgq_cmdq cmdq;
1058c2ecf20Sopenharmony_ci	struct bfa_msgq_rspq rspq;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	struct bfa_wc			init_wc;
1088c2ecf20Sopenharmony_ci	struct bfa_mbox_cmd init_mb;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	struct bfa_ioc_notify ioc_notify;
1118c2ecf20Sopenharmony_ci	struct bfa_ioc *ioc;
1128c2ecf20Sopenharmony_ci};
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciu32 bfa_msgq_meminfo(void);
1158c2ecf20Sopenharmony_civoid bfa_msgq_memclaim(struct bfa_msgq *msgq, u8 *kva, u64 pa);
1168c2ecf20Sopenharmony_civoid bfa_msgq_attach(struct bfa_msgq *msgq, struct bfa_ioc *ioc);
1178c2ecf20Sopenharmony_civoid bfa_msgq_regisr(struct bfa_msgq *msgq, enum bfi_mclass mc,
1188c2ecf20Sopenharmony_ci		     bfa_msgq_mcfunc_t cbfn, void *cbarg);
1198c2ecf20Sopenharmony_civoid bfa_msgq_cmd_post(struct bfa_msgq *msgq,
1208c2ecf20Sopenharmony_ci		       struct bfa_msgq_cmd_entry *cmd);
1218c2ecf20Sopenharmony_civoid bfa_msgq_rsp_copy(struct bfa_msgq *msgq, u8 *buf, size_t buf_len);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#endif
124