162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is part of the Chelsio FCoE driver for Linux.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * This software is available to you under a choice of one of two
762306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
862306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
962306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
1062306a36Sopenharmony_ci * OpenIB.org BSD license below:
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1362306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1462306a36Sopenharmony_ci *     conditions are met:
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1762306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1862306a36Sopenharmony_ci *        disclaimer.
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
2162306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2262306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2362306a36Sopenharmony_ci *        provided with the distribution.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2662306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2762306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2862306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2962306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3062306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3162306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3262306a36Sopenharmony_ci * SOFTWARE.
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#ifndef __CSIO_MB_H__
3662306a36Sopenharmony_ci#define __CSIO_MB_H__
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#include <linux/timer.h>
3962306a36Sopenharmony_ci#include <linux/completion.h>
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#include "t4fw_api.h"
4262306a36Sopenharmony_ci#include "t4fw_api_stor.h"
4362306a36Sopenharmony_ci#include "csio_defs.h"
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define CSIO_STATS_OFFSET (2)
4662306a36Sopenharmony_ci#define CSIO_NUM_STATS_PER_MB (6)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistruct fw_fcoe_port_cmd_params {
4962306a36Sopenharmony_ci	uint8_t		portid;
5062306a36Sopenharmony_ci	uint8_t		idx;
5162306a36Sopenharmony_ci	uint8_t		nstats;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define CSIO_DUMP_MB(__hw, __num, __mb)					\
5562306a36Sopenharmony_ci	csio_dbg(__hw, "\t%llx %llx %llx %llx %llx %llx %llx %llx\n",	\
5662306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb),		\
5762306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 8),	\
5862306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 16),	\
5962306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 24),	\
6062306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 32),	\
6162306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 40),	\
6262306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 48),	\
6362306a36Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 56))
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define CSIO_MB_MAX_REGS	8
6662306a36Sopenharmony_ci#define CSIO_MAX_MB_SIZE	64
6762306a36Sopenharmony_ci#define CSIO_MB_POLL_FREQ	5		/*  5 ms */
6862306a36Sopenharmony_ci#define CSIO_MB_DEFAULT_TMO	FW_CMD_MAX_TIMEOUT
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Device master in HELLO command */
7162306a36Sopenharmony_cienum csio_dev_master { CSIO_MASTER_CANT, CSIO_MASTER_MAY, CSIO_MASTER_MUST };
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cienum csio_mb_owner { CSIO_MBOWNER_NONE, CSIO_MBOWNER_FW, CSIO_MBOWNER_PL };
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cienum csio_dev_state {
7662306a36Sopenharmony_ci	CSIO_DEV_STATE_UNINIT,
7762306a36Sopenharmony_ci	CSIO_DEV_STATE_INIT,
7862306a36Sopenharmony_ci	CSIO_DEV_STATE_ERR
7962306a36Sopenharmony_ci};
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define FW_PARAM_DEV(param) \
8262306a36Sopenharmony_ci	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
8362306a36Sopenharmony_ci	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define FW_PARAM_PFVF(param) \
8662306a36Sopenharmony_ci	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
8762306a36Sopenharmony_ci	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)|  \
8862306a36Sopenharmony_ci	 FW_PARAMS_PARAM_Y_V(0) | \
8962306a36Sopenharmony_ci	 FW_PARAMS_PARAM_Z_V(0))
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define CSIO_INIT_MBP(__mbp, __cp,  __tmo, __priv, __fn, __clear)	\
9262306a36Sopenharmony_cido {									\
9362306a36Sopenharmony_ci	if (__clear)							\
9462306a36Sopenharmony_ci		memset((__cp), 0,					\
9562306a36Sopenharmony_ci			    CSIO_MB_MAX_REGS * sizeof(__be64));		\
9662306a36Sopenharmony_ci	INIT_LIST_HEAD(&(__mbp)->list);					\
9762306a36Sopenharmony_ci	(__mbp)->tmo		= (__tmo);				\
9862306a36Sopenharmony_ci	(__mbp)->priv		= (void *)(__priv);			\
9962306a36Sopenharmony_ci	(__mbp)->mb_cbfn	= (__fn);				\
10062306a36Sopenharmony_ci	(__mbp)->mb_size	= sizeof(*(__cp));			\
10162306a36Sopenharmony_ci} while (0)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_cistruct csio_mbm_stats {
10462306a36Sopenharmony_ci	uint32_t	n_req;		/* number of mbox req */
10562306a36Sopenharmony_ci	uint32_t	n_rsp;		/* number of mbox rsp */
10662306a36Sopenharmony_ci	uint32_t	n_activeq;	/* number of mbox req active Q */
10762306a36Sopenharmony_ci	uint32_t	n_cbfnq;	/* number of mbox req cbfn Q */
10862306a36Sopenharmony_ci	uint32_t	n_tmo;		/* number of mbox timeout */
10962306a36Sopenharmony_ci	uint32_t	n_cancel;	/* number of mbox cancel */
11062306a36Sopenharmony_ci	uint32_t	n_err;		/* number of mbox error */
11162306a36Sopenharmony_ci};
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Driver version of Mailbox */
11462306a36Sopenharmony_cistruct csio_mb {
11562306a36Sopenharmony_ci	struct list_head	list;			/* for req/resp */
11662306a36Sopenharmony_ci							/* queue in driver */
11762306a36Sopenharmony_ci	__be64			mb[CSIO_MB_MAX_REGS];	/* MB in HW format */
11862306a36Sopenharmony_ci	int			mb_size;		/* Size of this
11962306a36Sopenharmony_ci							 * mailbox.
12062306a36Sopenharmony_ci							 */
12162306a36Sopenharmony_ci	uint32_t		tmo;			/* Timeout */
12262306a36Sopenharmony_ci	struct completion	cmplobj;		/* MB Completion
12362306a36Sopenharmony_ci							 * object
12462306a36Sopenharmony_ci							 */
12562306a36Sopenharmony_ci	void			(*mb_cbfn) (struct csio_hw *, struct csio_mb *);
12662306a36Sopenharmony_ci							/* Callback fn */
12762306a36Sopenharmony_ci	void			*priv;			/* Owner private ptr */
12862306a36Sopenharmony_ci};
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cistruct csio_mbm {
13162306a36Sopenharmony_ci	uint32_t		a_mbox;			/* Async mbox num */
13262306a36Sopenharmony_ci	uint32_t		intr_idx;		/* Interrupt index */
13362306a36Sopenharmony_ci	struct timer_list	timer;			/* Mbox timer */
13462306a36Sopenharmony_ci	struct csio_hw		*hw;			/* Hardware pointer */
13562306a36Sopenharmony_ci	struct list_head	req_q;			/* Mbox request queue */
13662306a36Sopenharmony_ci	struct list_head	cbfn_q;			/* Mbox completion q */
13762306a36Sopenharmony_ci	struct csio_mb		*mcurrent;		/* Current mailbox */
13862306a36Sopenharmony_ci	uint32_t		req_q_cnt;		/* Outstanding mbox
13962306a36Sopenharmony_ci							 * cmds
14062306a36Sopenharmony_ci							 */
14162306a36Sopenharmony_ci	struct csio_mbm_stats	stats;			/* Statistics */
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci#define csio_set_mb_intr_idx(_m, _i)	((_m)->intr_idx = (_i))
14562306a36Sopenharmony_ci#define csio_get_mb_intr_idx(_m)	((_m)->intr_idx)
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_cistruct csio_iq_params;
14862306a36Sopenharmony_cistruct csio_eq_params;
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cienum fw_retval csio_mb_fw_retval(struct csio_mb *);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* MB helpers */
15362306a36Sopenharmony_civoid csio_mb_hello(struct csio_hw *, struct csio_mb *, uint32_t,
15462306a36Sopenharmony_ci		   uint32_t, uint32_t, enum csio_dev_master,
15562306a36Sopenharmony_ci		   void (*)(struct csio_hw *, struct csio_mb *));
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_civoid csio_mb_process_hello_rsp(struct csio_hw *, struct csio_mb *,
15862306a36Sopenharmony_ci			       enum fw_retval *, enum csio_dev_state *,
15962306a36Sopenharmony_ci			       uint8_t *);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_civoid csio_mb_bye(struct csio_hw *, struct csio_mb *, uint32_t,
16262306a36Sopenharmony_ci		 void (*)(struct csio_hw *, struct csio_mb *));
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_civoid csio_mb_reset(struct csio_hw *, struct csio_mb *, uint32_t, int, int,
16562306a36Sopenharmony_ci		   void (*)(struct csio_hw *, struct csio_mb *));
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_civoid csio_mb_params(struct csio_hw *, struct csio_mb *, uint32_t, unsigned int,
16862306a36Sopenharmony_ci		    unsigned int, unsigned int, const u32 *, u32 *, bool,
16962306a36Sopenharmony_ci		    void (*)(struct csio_hw *, struct csio_mb *));
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_civoid csio_mb_process_read_params_rsp(struct csio_hw *, struct csio_mb *,
17262306a36Sopenharmony_ci				enum fw_retval *, unsigned int , u32 *);
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_civoid csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
17562306a36Sopenharmony_ci		  int reg);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_civoid csio_mb_caps_config(struct csio_hw *, struct csio_mb *, uint32_t,
17862306a36Sopenharmony_ci			    bool, bool, bool, bool,
17962306a36Sopenharmony_ci			    void (*)(struct csio_hw *, struct csio_mb *));
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_civoid csio_mb_port(struct csio_hw *, struct csio_mb *, uint32_t,
18262306a36Sopenharmony_ci		  uint8_t, bool, uint32_t, uint16_t,
18362306a36Sopenharmony_ci		  void (*) (struct csio_hw *, struct csio_mb *));
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_civoid csio_mb_process_read_port_rsp(struct csio_hw *, struct csio_mb *,
18662306a36Sopenharmony_ci				   enum fw_retval *, uint16_t,
18762306a36Sopenharmony_ci				   uint32_t *, uint32_t *);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_civoid csio_mb_initialize(struct csio_hw *, struct csio_mb *, uint32_t,
19062306a36Sopenharmony_ci			void (*)(struct csio_hw *, struct csio_mb *));
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_civoid csio_mb_iq_alloc_write(struct csio_hw *, struct csio_mb *, void *,
19362306a36Sopenharmony_ci			uint32_t, struct csio_iq_params *,
19462306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_civoid csio_mb_iq_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
19762306a36Sopenharmony_ci				enum fw_retval *, struct csio_iq_params *);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_civoid csio_mb_iq_free(struct csio_hw *, struct csio_mb *, void *,
20062306a36Sopenharmony_ci		     uint32_t, struct csio_iq_params *,
20162306a36Sopenharmony_ci		     void (*) (struct csio_hw *, struct csio_mb *));
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_civoid csio_mb_eq_ofld_alloc_write(struct csio_hw *, struct csio_mb *, void *,
20462306a36Sopenharmony_ci				 uint32_t, struct csio_eq_params *,
20562306a36Sopenharmony_ci				 void (*) (struct csio_hw *, struct csio_mb *));
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_civoid csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
20862306a36Sopenharmony_ci				     enum fw_retval *, struct csio_eq_params *);
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_civoid csio_mb_eq_ofld_free(struct csio_hw *, struct csio_mb *, void *,
21162306a36Sopenharmony_ci			  uint32_t , struct csio_eq_params *,
21262306a36Sopenharmony_ci			  void (*) (struct csio_hw *, struct csio_mb *));
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_civoid csio_fcoe_read_res_info_init_mb(struct csio_hw *, struct csio_mb *,
21562306a36Sopenharmony_ci			uint32_t,
21662306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_civoid csio_write_fcoe_link_cond_init_mb(struct csio_lnode *, struct csio_mb *,
21962306a36Sopenharmony_ci			uint32_t, uint8_t, uint32_t, uint8_t, bool, uint32_t,
22062306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_civoid csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *, struct csio_mb *,
22362306a36Sopenharmony_ci			uint32_t, uint32_t , uint32_t , uint16_t,
22462306a36Sopenharmony_ci			uint8_t [8], uint8_t [8],
22562306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_civoid csio_fcoe_vnp_read_init_mb(struct csio_lnode *, struct csio_mb *,
22862306a36Sopenharmony_ci			uint32_t, uint32_t , uint32_t ,
22962306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_civoid csio_fcoe_vnp_free_init_mb(struct csio_lnode *, struct csio_mb *,
23262306a36Sopenharmony_ci			uint32_t , uint32_t, uint32_t ,
23362306a36Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_civoid csio_fcoe_read_fcf_init_mb(struct csio_lnode *, struct csio_mb *,
23662306a36Sopenharmony_ci			uint32_t, uint32_t, uint32_t,
23762306a36Sopenharmony_ci			void (*cbfn) (struct csio_hw *, struct csio_mb *));
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_civoid csio_fcoe_read_portparams_init_mb(struct csio_hw *hw,
24062306a36Sopenharmony_ci			struct csio_mb *mbp, uint32_t mb_tmo,
24162306a36Sopenharmony_ci			struct fw_fcoe_port_cmd_params *portparams,
24262306a36Sopenharmony_ci			void (*cbfn)(struct csio_hw *, struct csio_mb *));
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_civoid csio_mb_process_portparams_rsp(struct csio_hw *hw, struct csio_mb *mbp,
24562306a36Sopenharmony_ci				enum fw_retval *retval,
24662306a36Sopenharmony_ci				struct fw_fcoe_port_cmd_params *portparams,
24762306a36Sopenharmony_ci				struct fw_fcoe_port_stats *portstats);
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* MB module functions */
25062306a36Sopenharmony_ciint csio_mbm_init(struct csio_mbm *, struct csio_hw *,
25162306a36Sopenharmony_ci			    void (*)(struct timer_list *));
25262306a36Sopenharmony_civoid csio_mbm_exit(struct csio_mbm *);
25362306a36Sopenharmony_civoid csio_mb_intr_enable(struct csio_hw *);
25462306a36Sopenharmony_civoid csio_mb_intr_disable(struct csio_hw *);
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ciint csio_mb_issue(struct csio_hw *, struct csio_mb *);
25762306a36Sopenharmony_civoid csio_mb_completions(struct csio_hw *, struct list_head *);
25862306a36Sopenharmony_ciint csio_mb_fwevt_handler(struct csio_hw *, __be64 *);
25962306a36Sopenharmony_ciint csio_mb_isr_handler(struct csio_hw *);
26062306a36Sopenharmony_cistruct csio_mb *csio_mb_tmo_handler(struct csio_hw *);
26162306a36Sopenharmony_civoid csio_mb_cancel_all(struct csio_hw *, struct list_head *);
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci#endif /* ifndef __CSIO_MB_H__ */
264