Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is part of the Chelsio FCoE driver for Linux.
0003  *
0004  * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #ifndef __CSIO_MB_H__
0036 #define __CSIO_MB_H__
0037 
0038 #include <linux/timer.h>
0039 #include <linux/completion.h>
0040 
0041 #include "t4fw_api.h"
0042 #include "t4fw_api_stor.h"
0043 #include "csio_defs.h"
0044 
0045 #define CSIO_STATS_OFFSET (2)
0046 #define CSIO_NUM_STATS_PER_MB (6)
0047 
0048 struct fw_fcoe_port_cmd_params {
0049     uint8_t     portid;
0050     uint8_t     idx;
0051     uint8_t     nstats;
0052 };
0053 
0054 #define CSIO_DUMP_MB(__hw, __num, __mb)                 \
0055     csio_dbg(__hw, "\t%llx %llx %llx %llx %llx %llx %llx %llx\n",   \
0056         (unsigned long long)csio_rd_reg64(__hw, __mb),      \
0057         (unsigned long long)csio_rd_reg64(__hw, __mb + 8),  \
0058         (unsigned long long)csio_rd_reg64(__hw, __mb + 16), \
0059         (unsigned long long)csio_rd_reg64(__hw, __mb + 24), \
0060         (unsigned long long)csio_rd_reg64(__hw, __mb + 32), \
0061         (unsigned long long)csio_rd_reg64(__hw, __mb + 40), \
0062         (unsigned long long)csio_rd_reg64(__hw, __mb + 48), \
0063         (unsigned long long)csio_rd_reg64(__hw, __mb + 56))
0064 
0065 #define CSIO_MB_MAX_REGS    8
0066 #define CSIO_MAX_MB_SIZE    64
0067 #define CSIO_MB_POLL_FREQ   5       /*  5 ms */
0068 #define CSIO_MB_DEFAULT_TMO FW_CMD_MAX_TIMEOUT
0069 
0070 /* Device master in HELLO command */
0071 enum csio_dev_master { CSIO_MASTER_CANT, CSIO_MASTER_MAY, CSIO_MASTER_MUST };
0072 
0073 enum csio_mb_owner { CSIO_MBOWNER_NONE, CSIO_MBOWNER_FW, CSIO_MBOWNER_PL };
0074 
0075 enum csio_dev_state {
0076     CSIO_DEV_STATE_UNINIT,
0077     CSIO_DEV_STATE_INIT,
0078     CSIO_DEV_STATE_ERR
0079 };
0080 
0081 #define FW_PARAM_DEV(param) \
0082     (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
0083      FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
0084 
0085 #define FW_PARAM_PFVF(param) \
0086     (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
0087      FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)|  \
0088      FW_PARAMS_PARAM_Y_V(0) | \
0089      FW_PARAMS_PARAM_Z_V(0))
0090 
0091 #define CSIO_INIT_MBP(__mbp, __cp,  __tmo, __priv, __fn, __clear)   \
0092 do {                                    \
0093     if (__clear)                            \
0094         memset((__cp), 0,                   \
0095                 CSIO_MB_MAX_REGS * sizeof(__be64));     \
0096     INIT_LIST_HEAD(&(__mbp)->list);                 \
0097     (__mbp)->tmo        = (__tmo);              \
0098     (__mbp)->priv       = (void *)(__priv);         \
0099     (__mbp)->mb_cbfn    = (__fn);               \
0100     (__mbp)->mb_size    = sizeof(*(__cp));          \
0101 } while (0)
0102 
0103 struct csio_mbm_stats {
0104     uint32_t    n_req;      /* number of mbox req */
0105     uint32_t    n_rsp;      /* number of mbox rsp */
0106     uint32_t    n_activeq;  /* number of mbox req active Q */
0107     uint32_t    n_cbfnq;    /* number of mbox req cbfn Q */
0108     uint32_t    n_tmo;      /* number of mbox timeout */
0109     uint32_t    n_cancel;   /* number of mbox cancel */
0110     uint32_t    n_err;      /* number of mbox error */
0111 };
0112 
0113 /* Driver version of Mailbox */
0114 struct csio_mb {
0115     struct list_head    list;           /* for req/resp */
0116                             /* queue in driver */
0117     __be64          mb[CSIO_MB_MAX_REGS];   /* MB in HW format */
0118     int         mb_size;        /* Size of this
0119                              * mailbox.
0120                              */
0121     uint32_t        tmo;            /* Timeout */
0122     struct completion   cmplobj;        /* MB Completion
0123                              * object
0124                              */
0125     void            (*mb_cbfn) (struct csio_hw *, struct csio_mb *);
0126                             /* Callback fn */
0127     void            *priv;          /* Owner private ptr */
0128 };
0129 
0130 struct csio_mbm {
0131     uint32_t        a_mbox;         /* Async mbox num */
0132     uint32_t        intr_idx;       /* Interrupt index */
0133     struct timer_list   timer;          /* Mbox timer */
0134     struct csio_hw      *hw;            /* Hardware pointer */
0135     struct list_head    req_q;          /* Mbox request queue */
0136     struct list_head    cbfn_q;         /* Mbox completion q */
0137     struct csio_mb      *mcurrent;      /* Current mailbox */
0138     uint32_t        req_q_cnt;      /* Outstanding mbox
0139                              * cmds
0140                              */
0141     struct csio_mbm_stats   stats;          /* Statistics */
0142 };
0143 
0144 #define csio_set_mb_intr_idx(_m, _i)    ((_m)->intr_idx = (_i))
0145 #define csio_get_mb_intr_idx(_m)    ((_m)->intr_idx)
0146 
0147 struct csio_iq_params;
0148 struct csio_eq_params;
0149 
0150 enum fw_retval csio_mb_fw_retval(struct csio_mb *);
0151 
0152 /* MB helpers */
0153 void csio_mb_hello(struct csio_hw *, struct csio_mb *, uint32_t,
0154            uint32_t, uint32_t, enum csio_dev_master,
0155            void (*)(struct csio_hw *, struct csio_mb *));
0156 
0157 void csio_mb_process_hello_rsp(struct csio_hw *, struct csio_mb *,
0158                    enum fw_retval *, enum csio_dev_state *,
0159                    uint8_t *);
0160 
0161 void csio_mb_bye(struct csio_hw *, struct csio_mb *, uint32_t,
0162          void (*)(struct csio_hw *, struct csio_mb *));
0163 
0164 void csio_mb_reset(struct csio_hw *, struct csio_mb *, uint32_t, int, int,
0165            void (*)(struct csio_hw *, struct csio_mb *));
0166 
0167 void csio_mb_params(struct csio_hw *, struct csio_mb *, uint32_t, unsigned int,
0168             unsigned int, unsigned int, const u32 *, u32 *, bool,
0169             void (*)(struct csio_hw *, struct csio_mb *));
0170 
0171 void csio_mb_process_read_params_rsp(struct csio_hw *, struct csio_mb *,
0172                 enum fw_retval *, unsigned int , u32 *);
0173 
0174 void csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
0175           int reg);
0176 
0177 void csio_mb_caps_config(struct csio_hw *, struct csio_mb *, uint32_t,
0178                 bool, bool, bool, bool,
0179                 void (*)(struct csio_hw *, struct csio_mb *));
0180 
0181 void csio_mb_port(struct csio_hw *, struct csio_mb *, uint32_t,
0182           uint8_t, bool, uint32_t, uint16_t,
0183           void (*) (struct csio_hw *, struct csio_mb *));
0184 
0185 void csio_mb_process_read_port_rsp(struct csio_hw *, struct csio_mb *,
0186                    enum fw_retval *, uint16_t,
0187                    uint32_t *, uint32_t *);
0188 
0189 void csio_mb_initialize(struct csio_hw *, struct csio_mb *, uint32_t,
0190             void (*)(struct csio_hw *, struct csio_mb *));
0191 
0192 void csio_mb_iq_alloc_write(struct csio_hw *, struct csio_mb *, void *,
0193             uint32_t, struct csio_iq_params *,
0194             void (*) (struct csio_hw *, struct csio_mb *));
0195 
0196 void csio_mb_iq_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
0197                 enum fw_retval *, struct csio_iq_params *);
0198 
0199 void csio_mb_iq_free(struct csio_hw *, struct csio_mb *, void *,
0200              uint32_t, struct csio_iq_params *,
0201              void (*) (struct csio_hw *, struct csio_mb *));
0202 
0203 void csio_mb_eq_ofld_alloc_write(struct csio_hw *, struct csio_mb *, void *,
0204                  uint32_t, struct csio_eq_params *,
0205                  void (*) (struct csio_hw *, struct csio_mb *));
0206 
0207 void csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
0208                      enum fw_retval *, struct csio_eq_params *);
0209 
0210 void csio_mb_eq_ofld_free(struct csio_hw *, struct csio_mb *, void *,
0211               uint32_t , struct csio_eq_params *,
0212               void (*) (struct csio_hw *, struct csio_mb *));
0213 
0214 void csio_fcoe_read_res_info_init_mb(struct csio_hw *, struct csio_mb *,
0215             uint32_t,
0216             void (*) (struct csio_hw *, struct csio_mb *));
0217 
0218 void csio_write_fcoe_link_cond_init_mb(struct csio_lnode *, struct csio_mb *,
0219             uint32_t, uint8_t, uint32_t, uint8_t, bool, uint32_t,
0220             void (*) (struct csio_hw *, struct csio_mb *));
0221 
0222 void csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *, struct csio_mb *,
0223             uint32_t, uint32_t , uint32_t , uint16_t,
0224             uint8_t [8], uint8_t [8],
0225             void (*) (struct csio_hw *, struct csio_mb *));
0226 
0227 void csio_fcoe_vnp_read_init_mb(struct csio_lnode *, struct csio_mb *,
0228             uint32_t, uint32_t , uint32_t ,
0229             void (*) (struct csio_hw *, struct csio_mb *));
0230 
0231 void csio_fcoe_vnp_free_init_mb(struct csio_lnode *, struct csio_mb *,
0232             uint32_t , uint32_t, uint32_t ,
0233             void (*) (struct csio_hw *, struct csio_mb *));
0234 
0235 void csio_fcoe_read_fcf_init_mb(struct csio_lnode *, struct csio_mb *,
0236             uint32_t, uint32_t, uint32_t,
0237             void (*cbfn) (struct csio_hw *, struct csio_mb *));
0238 
0239 void csio_fcoe_read_portparams_init_mb(struct csio_hw *hw,
0240             struct csio_mb *mbp, uint32_t mb_tmo,
0241             struct fw_fcoe_port_cmd_params *portparams,
0242             void (*cbfn)(struct csio_hw *, struct csio_mb *));
0243 
0244 void csio_mb_process_portparams_rsp(struct csio_hw *hw, struct csio_mb *mbp,
0245                 enum fw_retval *retval,
0246                 struct fw_fcoe_port_cmd_params *portparams,
0247                 struct fw_fcoe_port_stats *portstats);
0248 
0249 /* MB module functions */
0250 int csio_mbm_init(struct csio_mbm *, struct csio_hw *,
0251                 void (*)(struct timer_list *));
0252 void csio_mbm_exit(struct csio_mbm *);
0253 void csio_mb_intr_enable(struct csio_hw *);
0254 void csio_mb_intr_disable(struct csio_hw *);
0255 
0256 int csio_mb_issue(struct csio_hw *, struct csio_mb *);
0257 void csio_mb_completions(struct csio_hw *, struct list_head *);
0258 int csio_mb_fwevt_handler(struct csio_hw *, __be64 *);
0259 int csio_mb_isr_handler(struct csio_hw *);
0260 struct csio_mb *csio_mb_tmo_handler(struct csio_hw *);
0261 void csio_mb_cancel_all(struct csio_hw *, struct list_head *);
0262 
0263 #endif /* ifndef __CSIO_MB_H__ */