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