1a3667aaeSNaresh Kumar Inna /* 2a3667aaeSNaresh Kumar Inna * This file is part of the Chelsio FCoE driver for Linux. 3a3667aaeSNaresh Kumar Inna * 4a3667aaeSNaresh Kumar Inna * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved. 5a3667aaeSNaresh Kumar Inna * 6a3667aaeSNaresh Kumar Inna * This software is available to you under a choice of one of two 7a3667aaeSNaresh Kumar Inna * licenses. You may choose to be licensed under the terms of the GNU 8a3667aaeSNaresh Kumar Inna * General Public License (GPL) Version 2, available from the file 9a3667aaeSNaresh Kumar Inna * COPYING in the main directory of this source tree, or the 10a3667aaeSNaresh Kumar Inna * OpenIB.org BSD license below: 11a3667aaeSNaresh Kumar Inna * 12a3667aaeSNaresh Kumar Inna * Redistribution and use in source and binary forms, with or 13a3667aaeSNaresh Kumar Inna * without modification, are permitted provided that the following 14a3667aaeSNaresh Kumar Inna * conditions are met: 15a3667aaeSNaresh Kumar Inna * 16a3667aaeSNaresh Kumar Inna * - Redistributions of source code must retain the above 17a3667aaeSNaresh Kumar Inna * copyright notice, this list of conditions and the following 18a3667aaeSNaresh Kumar Inna * disclaimer. 19a3667aaeSNaresh Kumar Inna * 20a3667aaeSNaresh Kumar Inna * - Redistributions in binary form must reproduce the above 21a3667aaeSNaresh Kumar Inna * copyright notice, this list of conditions and the following 22a3667aaeSNaresh Kumar Inna * disclaimer in the documentation and/or other materials 23a3667aaeSNaresh Kumar Inna * provided with the distribution. 24a3667aaeSNaresh Kumar Inna * 25a3667aaeSNaresh Kumar Inna * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26a3667aaeSNaresh Kumar Inna * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27a3667aaeSNaresh Kumar Inna * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28a3667aaeSNaresh Kumar Inna * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29a3667aaeSNaresh Kumar Inna * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30a3667aaeSNaresh Kumar Inna * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31a3667aaeSNaresh Kumar Inna * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32a3667aaeSNaresh Kumar Inna * SOFTWARE. 33a3667aaeSNaresh Kumar Inna */ 34a3667aaeSNaresh Kumar Inna 35a3667aaeSNaresh Kumar Inna #ifndef __CSIO_MB_H__ 36a3667aaeSNaresh Kumar Inna #define __CSIO_MB_H__ 37a3667aaeSNaresh Kumar Inna 38a3667aaeSNaresh Kumar Inna #include <linux/timer.h> 39a3667aaeSNaresh Kumar Inna #include <linux/completion.h> 40a3667aaeSNaresh Kumar Inna 41a3667aaeSNaresh Kumar Inna #include "t4fw_api.h" 42a3667aaeSNaresh Kumar Inna #include "t4fw_api_stor.h" 43a3667aaeSNaresh Kumar Inna #include "csio_defs.h" 44a3667aaeSNaresh Kumar Inna 45a3667aaeSNaresh Kumar Inna #define CSIO_STATS_OFFSET (2) 46a3667aaeSNaresh Kumar Inna #define CSIO_NUM_STATS_PER_MB (6) 47a3667aaeSNaresh Kumar Inna 48a3667aaeSNaresh Kumar Inna struct fw_fcoe_port_cmd_params { 49a3667aaeSNaresh Kumar Inna uint8_t portid; 50a3667aaeSNaresh Kumar Inna uint8_t idx; 51a3667aaeSNaresh Kumar Inna uint8_t nstats; 52a3667aaeSNaresh Kumar Inna }; 53a3667aaeSNaresh Kumar Inna 54a3667aaeSNaresh Kumar Inna #define CSIO_DUMP_MB(__hw, __num, __mb) \ 55a3667aaeSNaresh Kumar Inna csio_dbg(__hw, "\t%llx %llx %llx %llx %llx %llx %llx %llx\n", \ 56a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb), \ 57a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 8), \ 58a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 16), \ 59a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 24), \ 60a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 32), \ 61a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 40), \ 62a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 48), \ 63a3667aaeSNaresh Kumar Inna (unsigned long long)csio_rd_reg64(__hw, __mb + 56)) 64a3667aaeSNaresh Kumar Inna 65a3667aaeSNaresh Kumar Inna #define CSIO_MB_MAX_REGS 8 66a3667aaeSNaresh Kumar Inna #define CSIO_MAX_MB_SIZE 64 67a3667aaeSNaresh Kumar Inna #define CSIO_MB_POLL_FREQ 5 /* 5 ms */ 68a3667aaeSNaresh Kumar Inna #define CSIO_MB_DEFAULT_TMO FW_CMD_MAX_TIMEOUT 69a3667aaeSNaresh Kumar Inna 70a3667aaeSNaresh Kumar Inna /* Device master in HELLO command */ 71a3667aaeSNaresh Kumar Inna enum csio_dev_master { CSIO_MASTER_CANT, CSIO_MASTER_MAY, CSIO_MASTER_MUST }; 72a3667aaeSNaresh Kumar Inna 73a3667aaeSNaresh Kumar Inna enum csio_mb_owner { CSIO_MBOWNER_NONE, CSIO_MBOWNER_FW, CSIO_MBOWNER_PL }; 74a3667aaeSNaresh Kumar Inna 75a3667aaeSNaresh Kumar Inna enum csio_dev_state { 76a3667aaeSNaresh Kumar Inna CSIO_DEV_STATE_UNINIT, 77a3667aaeSNaresh Kumar Inna CSIO_DEV_STATE_INIT, 78a3667aaeSNaresh Kumar Inna CSIO_DEV_STATE_ERR 79a3667aaeSNaresh Kumar Inna }; 80a3667aaeSNaresh Kumar Inna 81a3667aaeSNaresh Kumar Inna #define FW_PARAM_DEV(param) \ 825167865aSHariprasad Shenai (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \ 835167865aSHariprasad Shenai FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param)) 84a3667aaeSNaresh Kumar Inna 85a3667aaeSNaresh Kumar Inna #define FW_PARAM_PFVF(param) \ 865167865aSHariprasad Shenai (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \ 875167865aSHariprasad Shenai FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \ 885167865aSHariprasad Shenai FW_PARAMS_PARAM_Y_V(0) | \ 895167865aSHariprasad Shenai FW_PARAMS_PARAM_Z_V(0)) 90a3667aaeSNaresh Kumar Inna 91a3667aaeSNaresh Kumar Inna #define CSIO_INIT_MBP(__mbp, __cp, __tmo, __priv, __fn, __clear) \ 92a3667aaeSNaresh Kumar Inna do { \ 93a3667aaeSNaresh Kumar Inna if (__clear) \ 94a3667aaeSNaresh Kumar Inna memset((__cp), 0, \ 95a3667aaeSNaresh Kumar Inna CSIO_MB_MAX_REGS * sizeof(__be64)); \ 96a3667aaeSNaresh Kumar Inna INIT_LIST_HEAD(&(__mbp)->list); \ 97a3667aaeSNaresh Kumar Inna (__mbp)->tmo = (__tmo); \ 98a3667aaeSNaresh Kumar Inna (__mbp)->priv = (void *)(__priv); \ 99a3667aaeSNaresh Kumar Inna (__mbp)->mb_cbfn = (__fn); \ 100a3667aaeSNaresh Kumar Inna (__mbp)->mb_size = sizeof(*(__cp)); \ 101a3667aaeSNaresh Kumar Inna } while (0) 102a3667aaeSNaresh Kumar Inna 103a3667aaeSNaresh Kumar Inna struct csio_mbm_stats { 104a3667aaeSNaresh Kumar Inna uint32_t n_req; /* number of mbox req */ 105a3667aaeSNaresh Kumar Inna uint32_t n_rsp; /* number of mbox rsp */ 106a3667aaeSNaresh Kumar Inna uint32_t n_activeq; /* number of mbox req active Q */ 107a3667aaeSNaresh Kumar Inna uint32_t n_cbfnq; /* number of mbox req cbfn Q */ 108a3667aaeSNaresh Kumar Inna uint32_t n_tmo; /* number of mbox timeout */ 109a3667aaeSNaresh Kumar Inna uint32_t n_cancel; /* number of mbox cancel */ 110a3667aaeSNaresh Kumar Inna uint32_t n_err; /* number of mbox error */ 111a3667aaeSNaresh Kumar Inna }; 112a3667aaeSNaresh Kumar Inna 113a3667aaeSNaresh Kumar Inna /* Driver version of Mailbox */ 114a3667aaeSNaresh Kumar Inna struct csio_mb { 115a3667aaeSNaresh Kumar Inna struct list_head list; /* for req/resp */ 116a3667aaeSNaresh Kumar Inna /* queue in driver */ 117a3667aaeSNaresh Kumar Inna __be64 mb[CSIO_MB_MAX_REGS]; /* MB in HW format */ 118a3667aaeSNaresh Kumar Inna int mb_size; /* Size of this 119a3667aaeSNaresh Kumar Inna * mailbox. 120a3667aaeSNaresh Kumar Inna */ 121a3667aaeSNaresh Kumar Inna uint32_t tmo; /* Timeout */ 122a3667aaeSNaresh Kumar Inna struct completion cmplobj; /* MB Completion 123a3667aaeSNaresh Kumar Inna * object 124a3667aaeSNaresh Kumar Inna */ 125a3667aaeSNaresh Kumar Inna void (*mb_cbfn) (struct csio_hw *, struct csio_mb *); 126a3667aaeSNaresh Kumar Inna /* Callback fn */ 127a3667aaeSNaresh Kumar Inna void *priv; /* Owner private ptr */ 128a3667aaeSNaresh Kumar Inna }; 129a3667aaeSNaresh Kumar Inna 130a3667aaeSNaresh Kumar Inna struct csio_mbm { 131a3667aaeSNaresh Kumar Inna uint32_t a_mbox; /* Async mbox num */ 132a3667aaeSNaresh Kumar Inna uint32_t intr_idx; /* Interrupt index */ 133a3667aaeSNaresh Kumar Inna struct timer_list timer; /* Mbox timer */ 134fa60a31bSKees Cook struct csio_hw *hw; /* Hardware pointer */ 135a3667aaeSNaresh Kumar Inna struct list_head req_q; /* Mbox request queue */ 136a3667aaeSNaresh Kumar Inna struct list_head cbfn_q; /* Mbox completion q */ 137a3667aaeSNaresh Kumar Inna struct csio_mb *mcurrent; /* Current mailbox */ 138a3667aaeSNaresh Kumar Inna uint32_t req_q_cnt; /* Outstanding mbox 139a3667aaeSNaresh Kumar Inna * cmds 140a3667aaeSNaresh Kumar Inna */ 141a3667aaeSNaresh Kumar Inna struct csio_mbm_stats stats; /* Statistics */ 142a3667aaeSNaresh Kumar Inna }; 143a3667aaeSNaresh Kumar Inna 144a3667aaeSNaresh Kumar Inna #define csio_set_mb_intr_idx(_m, _i) ((_m)->intr_idx = (_i)) 145a3667aaeSNaresh Kumar Inna #define csio_get_mb_intr_idx(_m) ((_m)->intr_idx) 146a3667aaeSNaresh Kumar Inna 147a3667aaeSNaresh Kumar Inna struct csio_iq_params; 148a3667aaeSNaresh Kumar Inna struct csio_eq_params; 149a3667aaeSNaresh Kumar Inna 150a3667aaeSNaresh Kumar Inna enum fw_retval csio_mb_fw_retval(struct csio_mb *); 151a3667aaeSNaresh Kumar Inna 152a3667aaeSNaresh Kumar Inna /* MB helpers */ 153a3667aaeSNaresh Kumar Inna void csio_mb_hello(struct csio_hw *, struct csio_mb *, uint32_t, 154a3667aaeSNaresh Kumar Inna uint32_t, uint32_t, enum csio_dev_master, 155a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 156a3667aaeSNaresh Kumar Inna 157a3667aaeSNaresh Kumar Inna void csio_mb_process_hello_rsp(struct csio_hw *, struct csio_mb *, 158a3667aaeSNaresh Kumar Inna enum fw_retval *, enum csio_dev_state *, 159a3667aaeSNaresh Kumar Inna uint8_t *); 160a3667aaeSNaresh Kumar Inna 161a3667aaeSNaresh Kumar Inna void csio_mb_bye(struct csio_hw *, struct csio_mb *, uint32_t, 162a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 163a3667aaeSNaresh Kumar Inna 164a3667aaeSNaresh Kumar Inna void csio_mb_reset(struct csio_hw *, struct csio_mb *, uint32_t, int, int, 165a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 166a3667aaeSNaresh Kumar Inna 167a3667aaeSNaresh Kumar Inna void csio_mb_params(struct csio_hw *, struct csio_mb *, uint32_t, unsigned int, 168a3667aaeSNaresh Kumar Inna unsigned int, unsigned int, const u32 *, u32 *, bool, 169a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 170a3667aaeSNaresh Kumar Inna 171a3667aaeSNaresh Kumar Inna void csio_mb_process_read_params_rsp(struct csio_hw *, struct csio_mb *, 172a3667aaeSNaresh Kumar Inna enum fw_retval *, unsigned int , u32 *); 173a3667aaeSNaresh Kumar Inna 174a3667aaeSNaresh Kumar Inna void csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo, 175a3667aaeSNaresh Kumar Inna int reg); 176a3667aaeSNaresh Kumar Inna 177a3667aaeSNaresh Kumar Inna void csio_mb_caps_config(struct csio_hw *, struct csio_mb *, uint32_t, 178a3667aaeSNaresh Kumar Inna bool, bool, bool, bool, 179a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 180a3667aaeSNaresh Kumar Inna 181a3667aaeSNaresh Kumar Inna void csio_mb_port(struct csio_hw *, struct csio_mb *, uint32_t, 182a3667aaeSNaresh Kumar Inna uint8_t, bool, uint32_t, uint16_t, 183a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 184a3667aaeSNaresh Kumar Inna 185a3667aaeSNaresh Kumar Inna void csio_mb_process_read_port_rsp(struct csio_hw *, struct csio_mb *, 186*e1735d9aSVarun Prakash enum fw_retval *, uint16_t, 187*e1735d9aSVarun Prakash uint32_t *, uint32_t *); 188a3667aaeSNaresh Kumar Inna 189a3667aaeSNaresh Kumar Inna void csio_mb_initialize(struct csio_hw *, struct csio_mb *, uint32_t, 190a3667aaeSNaresh Kumar Inna void (*)(struct csio_hw *, struct csio_mb *)); 191a3667aaeSNaresh Kumar Inna 192a3667aaeSNaresh Kumar Inna void csio_mb_iq_alloc_write(struct csio_hw *, struct csio_mb *, void *, 193a3667aaeSNaresh Kumar Inna uint32_t, struct csio_iq_params *, 194a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 195a3667aaeSNaresh Kumar Inna 196a3667aaeSNaresh Kumar Inna void csio_mb_iq_alloc_write_rsp(struct csio_hw *, struct csio_mb *, 197a3667aaeSNaresh Kumar Inna enum fw_retval *, struct csio_iq_params *); 198a3667aaeSNaresh Kumar Inna 199a3667aaeSNaresh Kumar Inna void csio_mb_iq_free(struct csio_hw *, struct csio_mb *, void *, 200a3667aaeSNaresh Kumar Inna uint32_t, struct csio_iq_params *, 201a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 202a3667aaeSNaresh Kumar Inna 203a3667aaeSNaresh Kumar Inna void csio_mb_eq_ofld_alloc_write(struct csio_hw *, struct csio_mb *, void *, 204a3667aaeSNaresh Kumar Inna uint32_t, struct csio_eq_params *, 205a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 206a3667aaeSNaresh Kumar Inna 207a3667aaeSNaresh Kumar Inna void csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *, struct csio_mb *, 208a3667aaeSNaresh Kumar Inna enum fw_retval *, struct csio_eq_params *); 209a3667aaeSNaresh Kumar Inna 210a3667aaeSNaresh Kumar Inna void csio_mb_eq_ofld_free(struct csio_hw *, struct csio_mb *, void *, 211a3667aaeSNaresh Kumar Inna uint32_t , struct csio_eq_params *, 212a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 213a3667aaeSNaresh Kumar Inna 214a3667aaeSNaresh Kumar Inna void csio_fcoe_read_res_info_init_mb(struct csio_hw *, struct csio_mb *, 215a3667aaeSNaresh Kumar Inna uint32_t, 216a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 217a3667aaeSNaresh Kumar Inna 218a3667aaeSNaresh Kumar Inna void csio_write_fcoe_link_cond_init_mb(struct csio_lnode *, struct csio_mb *, 219a3667aaeSNaresh Kumar Inna uint32_t, uint8_t, uint32_t, uint8_t, bool, uint32_t, 220a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 221a3667aaeSNaresh Kumar Inna 222a3667aaeSNaresh Kumar Inna void csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *, struct csio_mb *, 223a3667aaeSNaresh Kumar Inna uint32_t, uint32_t , uint32_t , uint16_t, 224a3667aaeSNaresh Kumar Inna uint8_t [8], uint8_t [8], 225a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 226a3667aaeSNaresh Kumar Inna 227a3667aaeSNaresh Kumar Inna void csio_fcoe_vnp_read_init_mb(struct csio_lnode *, struct csio_mb *, 228a3667aaeSNaresh Kumar Inna uint32_t, uint32_t , uint32_t , 229a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 230a3667aaeSNaresh Kumar Inna 231a3667aaeSNaresh Kumar Inna void csio_fcoe_vnp_free_init_mb(struct csio_lnode *, struct csio_mb *, 232a3667aaeSNaresh Kumar Inna uint32_t , uint32_t, uint32_t , 233a3667aaeSNaresh Kumar Inna void (*) (struct csio_hw *, struct csio_mb *)); 234a3667aaeSNaresh Kumar Inna 235a3667aaeSNaresh Kumar Inna void csio_fcoe_read_fcf_init_mb(struct csio_lnode *, struct csio_mb *, 236a3667aaeSNaresh Kumar Inna uint32_t, uint32_t, uint32_t, 237a3667aaeSNaresh Kumar Inna void (*cbfn) (struct csio_hw *, struct csio_mb *)); 238a3667aaeSNaresh Kumar Inna 239a3667aaeSNaresh Kumar Inna void csio_fcoe_read_portparams_init_mb(struct csio_hw *hw, 240a3667aaeSNaresh Kumar Inna struct csio_mb *mbp, uint32_t mb_tmo, 241a3667aaeSNaresh Kumar Inna struct fw_fcoe_port_cmd_params *portparams, 242a3667aaeSNaresh Kumar Inna void (*cbfn)(struct csio_hw *, struct csio_mb *)); 243a3667aaeSNaresh Kumar Inna 244a3667aaeSNaresh Kumar Inna void csio_mb_process_portparams_rsp(struct csio_hw *hw, struct csio_mb *mbp, 245a3667aaeSNaresh Kumar Inna enum fw_retval *retval, 246a3667aaeSNaresh Kumar Inna struct fw_fcoe_port_cmd_params *portparams, 247a3667aaeSNaresh Kumar Inna struct fw_fcoe_port_stats *portstats); 248a3667aaeSNaresh Kumar Inna 249a3667aaeSNaresh Kumar Inna /* MB module functions */ 250a3667aaeSNaresh Kumar Inna int csio_mbm_init(struct csio_mbm *, struct csio_hw *, 251fa60a31bSKees Cook void (*)(struct timer_list *)); 252a3667aaeSNaresh Kumar Inna void csio_mbm_exit(struct csio_mbm *); 253a3667aaeSNaresh Kumar Inna void csio_mb_intr_enable(struct csio_hw *); 254a3667aaeSNaresh Kumar Inna void csio_mb_intr_disable(struct csio_hw *); 255a3667aaeSNaresh Kumar Inna 256a3667aaeSNaresh Kumar Inna int csio_mb_issue(struct csio_hw *, struct csio_mb *); 257a3667aaeSNaresh Kumar Inna void csio_mb_completions(struct csio_hw *, struct list_head *); 258a3667aaeSNaresh Kumar Inna int csio_mb_fwevt_handler(struct csio_hw *, __be64 *); 259a3667aaeSNaresh Kumar Inna int csio_mb_isr_handler(struct csio_hw *); 260a3667aaeSNaresh Kumar Inna struct csio_mb *csio_mb_tmo_handler(struct csio_hw *); 261a3667aaeSNaresh Kumar Inna void csio_mb_cancel_all(struct csio_hw *, struct list_head *); 262a3667aaeSNaresh Kumar Inna 263a3667aaeSNaresh Kumar Inna #endif /* ifndef __CSIO_MB_H__ */ 264