18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is part of the Chelsio FCoE driver for Linux.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
78c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
138c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
148c2ecf20Sopenharmony_ci *     conditions are met:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
178c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
188c2ecf20Sopenharmony_ci *        disclaimer.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
218c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
228c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
238c2ecf20Sopenharmony_ci *        provided with the distribution.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
328c2ecf20Sopenharmony_ci * SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef __CSIO_MB_H__
368c2ecf20Sopenharmony_ci#define __CSIO_MB_H__
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/timer.h>
398c2ecf20Sopenharmony_ci#include <linux/completion.h>
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include "t4fw_api.h"
428c2ecf20Sopenharmony_ci#include "t4fw_api_stor.h"
438c2ecf20Sopenharmony_ci#include "csio_defs.h"
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define CSIO_STATS_OFFSET (2)
468c2ecf20Sopenharmony_ci#define CSIO_NUM_STATS_PER_MB (6)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct fw_fcoe_port_cmd_params {
498c2ecf20Sopenharmony_ci	uint8_t		portid;
508c2ecf20Sopenharmony_ci	uint8_t		idx;
518c2ecf20Sopenharmony_ci	uint8_t		nstats;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define CSIO_DUMP_MB(__hw, __num, __mb)					\
558c2ecf20Sopenharmony_ci	csio_dbg(__hw, "\t%llx %llx %llx %llx %llx %llx %llx %llx\n",	\
568c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb),		\
578c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 8),	\
588c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 16),	\
598c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 24),	\
608c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 32),	\
618c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 40),	\
628c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 48),	\
638c2ecf20Sopenharmony_ci		(unsigned long long)csio_rd_reg64(__hw, __mb + 56))
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define CSIO_MB_MAX_REGS	8
668c2ecf20Sopenharmony_ci#define CSIO_MAX_MB_SIZE	64
678c2ecf20Sopenharmony_ci#define CSIO_MB_POLL_FREQ	5		/*  5 ms */
688c2ecf20Sopenharmony_ci#define CSIO_MB_DEFAULT_TMO	FW_CMD_MAX_TIMEOUT
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* Device master in HELLO command */
718c2ecf20Sopenharmony_cienum csio_dev_master { CSIO_MASTER_CANT, CSIO_MASTER_MAY, CSIO_MASTER_MUST };
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cienum csio_mb_owner { CSIO_MBOWNER_NONE, CSIO_MBOWNER_FW, CSIO_MBOWNER_PL };
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cienum csio_dev_state {
768c2ecf20Sopenharmony_ci	CSIO_DEV_STATE_UNINIT,
778c2ecf20Sopenharmony_ci	CSIO_DEV_STATE_INIT,
788c2ecf20Sopenharmony_ci	CSIO_DEV_STATE_ERR
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define FW_PARAM_DEV(param) \
828c2ecf20Sopenharmony_ci	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
838c2ecf20Sopenharmony_ci	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define FW_PARAM_PFVF(param) \
868c2ecf20Sopenharmony_ci	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
878c2ecf20Sopenharmony_ci	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)|  \
888c2ecf20Sopenharmony_ci	 FW_PARAMS_PARAM_Y_V(0) | \
898c2ecf20Sopenharmony_ci	 FW_PARAMS_PARAM_Z_V(0))
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define CSIO_INIT_MBP(__mbp, __cp,  __tmo, __priv, __fn, __clear)	\
928c2ecf20Sopenharmony_cido {									\
938c2ecf20Sopenharmony_ci	if (__clear)							\
948c2ecf20Sopenharmony_ci		memset((__cp), 0,					\
958c2ecf20Sopenharmony_ci			    CSIO_MB_MAX_REGS * sizeof(__be64));		\
968c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&(__mbp)->list);					\
978c2ecf20Sopenharmony_ci	(__mbp)->tmo		= (__tmo);				\
988c2ecf20Sopenharmony_ci	(__mbp)->priv		= (void *)(__priv);			\
998c2ecf20Sopenharmony_ci	(__mbp)->mb_cbfn	= (__fn);				\
1008c2ecf20Sopenharmony_ci	(__mbp)->mb_size	= sizeof(*(__cp));			\
1018c2ecf20Sopenharmony_ci} while (0)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistruct csio_mbm_stats {
1048c2ecf20Sopenharmony_ci	uint32_t	n_req;		/* number of mbox req */
1058c2ecf20Sopenharmony_ci	uint32_t	n_rsp;		/* number of mbox rsp */
1068c2ecf20Sopenharmony_ci	uint32_t	n_activeq;	/* number of mbox req active Q */
1078c2ecf20Sopenharmony_ci	uint32_t	n_cbfnq;	/* number of mbox req cbfn Q */
1088c2ecf20Sopenharmony_ci	uint32_t	n_tmo;		/* number of mbox timeout */
1098c2ecf20Sopenharmony_ci	uint32_t	n_cancel;	/* number of mbox cancel */
1108c2ecf20Sopenharmony_ci	uint32_t	n_err;		/* number of mbox error */
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Driver version of Mailbox */
1148c2ecf20Sopenharmony_cistruct csio_mb {
1158c2ecf20Sopenharmony_ci	struct list_head	list;			/* for req/resp */
1168c2ecf20Sopenharmony_ci							/* queue in driver */
1178c2ecf20Sopenharmony_ci	__be64			mb[CSIO_MB_MAX_REGS];	/* MB in HW format */
1188c2ecf20Sopenharmony_ci	int			mb_size;		/* Size of this
1198c2ecf20Sopenharmony_ci							 * mailbox.
1208c2ecf20Sopenharmony_ci							 */
1218c2ecf20Sopenharmony_ci	uint32_t		tmo;			/* Timeout */
1228c2ecf20Sopenharmony_ci	struct completion	cmplobj;		/* MB Completion
1238c2ecf20Sopenharmony_ci							 * object
1248c2ecf20Sopenharmony_ci							 */
1258c2ecf20Sopenharmony_ci	void			(*mb_cbfn) (struct csio_hw *, struct csio_mb *);
1268c2ecf20Sopenharmony_ci							/* Callback fn */
1278c2ecf20Sopenharmony_ci	void			*priv;			/* Owner private ptr */
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistruct csio_mbm {
1318c2ecf20Sopenharmony_ci	uint32_t		a_mbox;			/* Async mbox num */
1328c2ecf20Sopenharmony_ci	uint32_t		intr_idx;		/* Interrupt index */
1338c2ecf20Sopenharmony_ci	struct timer_list	timer;			/* Mbox timer */
1348c2ecf20Sopenharmony_ci	struct csio_hw		*hw;			/* Hardware pointer */
1358c2ecf20Sopenharmony_ci	struct list_head	req_q;			/* Mbox request queue */
1368c2ecf20Sopenharmony_ci	struct list_head	cbfn_q;			/* Mbox completion q */
1378c2ecf20Sopenharmony_ci	struct csio_mb		*mcurrent;		/* Current mailbox */
1388c2ecf20Sopenharmony_ci	uint32_t		req_q_cnt;		/* Outstanding mbox
1398c2ecf20Sopenharmony_ci							 * cmds
1408c2ecf20Sopenharmony_ci							 */
1418c2ecf20Sopenharmony_ci	struct csio_mbm_stats	stats;			/* Statistics */
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define csio_set_mb_intr_idx(_m, _i)	((_m)->intr_idx = (_i))
1458c2ecf20Sopenharmony_ci#define csio_get_mb_intr_idx(_m)	((_m)->intr_idx)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistruct csio_iq_params;
1488c2ecf20Sopenharmony_cistruct csio_eq_params;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cienum fw_retval csio_mb_fw_retval(struct csio_mb *);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* MB helpers */
1538c2ecf20Sopenharmony_civoid csio_mb_hello(struct csio_hw *, struct csio_mb *, uint32_t,
1548c2ecf20Sopenharmony_ci		   uint32_t, uint32_t, enum csio_dev_master,
1558c2ecf20Sopenharmony_ci		   void (*)(struct csio_hw *, struct csio_mb *));
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_civoid csio_mb_process_hello_rsp(struct csio_hw *, struct csio_mb *,
1588c2ecf20Sopenharmony_ci			       enum fw_retval *, enum csio_dev_state *,
1598c2ecf20Sopenharmony_ci			       uint8_t *);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_civoid csio_mb_bye(struct csio_hw *, struct csio_mb *, uint32_t,
1628c2ecf20Sopenharmony_ci		 void (*)(struct csio_hw *, struct csio_mb *));
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_civoid csio_mb_reset(struct csio_hw *, struct csio_mb *, uint32_t, int, int,
1658c2ecf20Sopenharmony_ci		   void (*)(struct csio_hw *, struct csio_mb *));
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_civoid csio_mb_params(struct csio_hw *, struct csio_mb *, uint32_t, unsigned int,
1688c2ecf20Sopenharmony_ci		    unsigned int, unsigned int, const u32 *, u32 *, bool,
1698c2ecf20Sopenharmony_ci		    void (*)(struct csio_hw *, struct csio_mb *));
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_civoid csio_mb_process_read_params_rsp(struct csio_hw *, struct csio_mb *,
1728c2ecf20Sopenharmony_ci				enum fw_retval *, unsigned int , u32 *);
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_civoid csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
1758c2ecf20Sopenharmony_ci		  int reg);
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_civoid csio_mb_caps_config(struct csio_hw *, struct csio_mb *, uint32_t,
1788c2ecf20Sopenharmony_ci			    bool, bool, bool, bool,
1798c2ecf20Sopenharmony_ci			    void (*)(struct csio_hw *, struct csio_mb *));
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_civoid csio_mb_port(struct csio_hw *, struct csio_mb *, uint32_t,
1828c2ecf20Sopenharmony_ci		  uint8_t, bool, uint32_t, uint16_t,
1838c2ecf20Sopenharmony_ci		  void (*) (struct csio_hw *, struct csio_mb *));
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_civoid csio_mb_process_read_port_rsp(struct csio_hw *, struct csio_mb *,
1868c2ecf20Sopenharmony_ci				   enum fw_retval *, uint16_t,
1878c2ecf20Sopenharmony_ci				   uint32_t *, uint32_t *);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_civoid csio_mb_initialize(struct csio_hw *, struct csio_mb *, uint32_t,
1908c2ecf20Sopenharmony_ci			void (*)(struct csio_hw *, struct csio_mb *));
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_civoid csio_mb_iq_alloc_write(struct csio_hw *, struct csio_mb *, void *,
1938c2ecf20Sopenharmony_ci			uint32_t, struct csio_iq_params *,
1948c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_civoid csio_mb_iq_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
1978c2ecf20Sopenharmony_ci				enum fw_retval *, struct csio_iq_params *);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_civoid csio_mb_iq_free(struct csio_hw *, struct csio_mb *, void *,
2008c2ecf20Sopenharmony_ci		     uint32_t, struct csio_iq_params *,
2018c2ecf20Sopenharmony_ci		     void (*) (struct csio_hw *, struct csio_mb *));
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_civoid csio_mb_eq_ofld_alloc_write(struct csio_hw *, struct csio_mb *, void *,
2048c2ecf20Sopenharmony_ci				 uint32_t, struct csio_eq_params *,
2058c2ecf20Sopenharmony_ci				 void (*) (struct csio_hw *, struct csio_mb *));
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_civoid csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
2088c2ecf20Sopenharmony_ci				     enum fw_retval *, struct csio_eq_params *);
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_civoid csio_mb_eq_ofld_free(struct csio_hw *, struct csio_mb *, void *,
2118c2ecf20Sopenharmony_ci			  uint32_t , struct csio_eq_params *,
2128c2ecf20Sopenharmony_ci			  void (*) (struct csio_hw *, struct csio_mb *));
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_civoid csio_fcoe_read_res_info_init_mb(struct csio_hw *, struct csio_mb *,
2158c2ecf20Sopenharmony_ci			uint32_t,
2168c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_civoid csio_write_fcoe_link_cond_init_mb(struct csio_lnode *, struct csio_mb *,
2198c2ecf20Sopenharmony_ci			uint32_t, uint8_t, uint32_t, uint8_t, bool, uint32_t,
2208c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_civoid csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *, struct csio_mb *,
2238c2ecf20Sopenharmony_ci			uint32_t, uint32_t , uint32_t , uint16_t,
2248c2ecf20Sopenharmony_ci			uint8_t [8], uint8_t [8],
2258c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_civoid csio_fcoe_vnp_read_init_mb(struct csio_lnode *, struct csio_mb *,
2288c2ecf20Sopenharmony_ci			uint32_t, uint32_t , uint32_t ,
2298c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_civoid csio_fcoe_vnp_free_init_mb(struct csio_lnode *, struct csio_mb *,
2328c2ecf20Sopenharmony_ci			uint32_t , uint32_t, uint32_t ,
2338c2ecf20Sopenharmony_ci			void (*) (struct csio_hw *, struct csio_mb *));
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_civoid csio_fcoe_read_fcf_init_mb(struct csio_lnode *, struct csio_mb *,
2368c2ecf20Sopenharmony_ci			uint32_t, uint32_t, uint32_t,
2378c2ecf20Sopenharmony_ci			void (*cbfn) (struct csio_hw *, struct csio_mb *));
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_civoid csio_fcoe_read_portparams_init_mb(struct csio_hw *hw,
2408c2ecf20Sopenharmony_ci			struct csio_mb *mbp, uint32_t mb_tmo,
2418c2ecf20Sopenharmony_ci			struct fw_fcoe_port_cmd_params *portparams,
2428c2ecf20Sopenharmony_ci			void (*cbfn)(struct csio_hw *, struct csio_mb *));
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_civoid csio_mb_process_portparams_rsp(struct csio_hw *hw, struct csio_mb *mbp,
2458c2ecf20Sopenharmony_ci				enum fw_retval *retval,
2468c2ecf20Sopenharmony_ci				struct fw_fcoe_port_cmd_params *portparams,
2478c2ecf20Sopenharmony_ci				struct fw_fcoe_port_stats *portstats);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/* MB module functions */
2508c2ecf20Sopenharmony_ciint csio_mbm_init(struct csio_mbm *, struct csio_hw *,
2518c2ecf20Sopenharmony_ci			    void (*)(struct timer_list *));
2528c2ecf20Sopenharmony_civoid csio_mbm_exit(struct csio_mbm *);
2538c2ecf20Sopenharmony_civoid csio_mb_intr_enable(struct csio_hw *);
2548c2ecf20Sopenharmony_civoid csio_mb_intr_disable(struct csio_hw *);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ciint csio_mb_issue(struct csio_hw *, struct csio_mb *);
2578c2ecf20Sopenharmony_civoid csio_mb_completions(struct csio_hw *, struct list_head *);
2588c2ecf20Sopenharmony_ciint csio_mb_fwevt_handler(struct csio_hw *, __be64 *);
2598c2ecf20Sopenharmony_ciint csio_mb_isr_handler(struct csio_hw *);
2608c2ecf20Sopenharmony_cistruct csio_mb *csio_mb_tmo_handler(struct csio_hw *);
2618c2ecf20Sopenharmony_civoid csio_mb_cancel_all(struct csio_hw *, struct list_head *);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci#endif /* ifndef __CSIO_MB_H__ */
264