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_LNODE_H__
0036 #define __CSIO_LNODE_H__
0037 
0038 #include <linux/kref.h>
0039 #include <linux/timer.h>
0040 #include <linux/workqueue.h>
0041 #include <scsi/fc/fc_els.h>
0042 
0043 
0044 #include "csio_defs.h"
0045 #include "csio_hw.h"
0046 
0047 #define CSIO_FCOE_MAX_NPIV  128
0048 #define CSIO_FCOE_MAX_RNODES    2048
0049 
0050 /* FDMI port attribute unknown speed */
0051 #define CSIO_HBA_PORTSPEED_UNKNOWN  0x8000
0052 
0053 extern int csio_fcoe_rnodes;
0054 extern int csio_fdmi_enable;
0055 
0056 /* State machine evets */
0057 enum csio_ln_ev {
0058     CSIO_LNE_NONE = (uint32_t)0,
0059     CSIO_LNE_LINKUP,
0060     CSIO_LNE_FAB_INIT_DONE,
0061     CSIO_LNE_LINK_DOWN,
0062     CSIO_LNE_DOWN_LINK,
0063     CSIO_LNE_LOGO,
0064     CSIO_LNE_CLOSE,
0065     CSIO_LNE_MAX_EVENT,
0066 };
0067 
0068 
0069 struct csio_fcf_info {
0070     struct list_head    list;
0071     uint8_t         priority;
0072     uint8_t         mac[6];
0073     uint8_t         name_id[8];
0074     uint8_t         fabric[8];
0075     uint16_t        vf_id;
0076     uint8_t         vlan_id;
0077     uint16_t        max_fcoe_size;
0078     uint8_t         fc_map[3];
0079     uint32_t        fka_adv;
0080     uint32_t        fcfi;
0081     uint8_t         get_next:1;
0082     uint8_t         link_aff:1;
0083     uint8_t         fpma:1;
0084     uint8_t         spma:1;
0085     uint8_t         login:1;
0086     uint8_t         portid;
0087     uint8_t         spma_mac[6];
0088     struct kref     kref;
0089 };
0090 
0091 /* Defines for flags */
0092 #define CSIO_LNF_FIPSUPP        0x00000001  /* Fip Supported */
0093 #define CSIO_LNF_NPIVSUPP       0x00000002  /* NPIV supported */
0094 #define CSIO_LNF_LINK_ENABLE        0x00000004  /* Link enabled */
0095 #define CSIO_LNF_FDMI_ENABLE        0x00000008  /* FDMI support */
0096 
0097 /* Transport events */
0098 enum csio_ln_fc_evt {
0099     CSIO_LN_FC_LINKUP = 1,
0100     CSIO_LN_FC_LINKDOWN,
0101     CSIO_LN_FC_RSCN,
0102     CSIO_LN_FC_ATTRIB_UPDATE,
0103 };
0104 
0105 /* Lnode stats */
0106 struct csio_lnode_stats {
0107     uint32_t    n_link_up;  /* Link down */
0108     uint32_t    n_link_down;    /* Link up */
0109     uint32_t    n_err;      /* error */
0110     uint32_t    n_err_nomem;    /* memory not available */
0111     uint32_t    n_inval_parm;   /* Invalid parameters */
0112     uint32_t    n_evt_unexp;    /* unexpected event */
0113     uint32_t    n_evt_drop; /* dropped event */
0114     uint32_t    n_rnode_match;  /* matched rnode */
0115     uint32_t    n_dev_loss_tmo; /* Device loss timeout */
0116     uint32_t    n_fdmi_err; /* fdmi err */
0117     uint32_t    n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];  /* fw events */
0118     enum csio_ln_ev n_evt_sm[CSIO_LNE_MAX_EVENT];   /* State m/c events */
0119     uint32_t    n_rnode_alloc;  /* rnode allocated */
0120     uint32_t    n_rnode_free;   /* rnode freed */
0121     uint32_t    n_rnode_nomem;  /* rnode alloc failure */
0122     uint32_t        n_input_requests; /* Input Requests */
0123     uint32_t        n_output_requests; /* Output Requests */
0124     uint32_t        n_control_requests; /* Control Requests */
0125     uint32_t        n_input_bytes; /* Input Bytes */
0126     uint32_t        n_output_bytes; /* Output Bytes */
0127     uint32_t    rsvd1;
0128 };
0129 
0130 /* Common Lnode params */
0131 struct csio_lnode_params {
0132     uint32_t    ra_tov;
0133     uint32_t    fcfi;
0134     uint32_t    log_level;  /* Module level for debugging */
0135 };
0136 
0137 struct csio_service_parms {
0138     struct fc_els_csp   csp;        /* Common service parms */
0139     uint8_t         wwpn[8];    /* WWPN */
0140     uint8_t         wwnn[8];    /* WWNN */
0141     struct fc_els_cssp  clsp[4];    /* Class service params */
0142     uint8_t         vvl[16];    /* Vendor version level */
0143 };
0144 
0145 /* Lnode */
0146 struct csio_lnode {
0147     struct csio_sm      sm;     /* State machine + sibling
0148                          * lnode list.
0149                          */
0150     struct csio_hw      *hwp;       /* Pointer to the HW module */
0151     uint8_t         portid;     /* Port ID */
0152     uint8_t         rsvd1;
0153     uint16_t        rsvd2;
0154     uint32_t        dev_num;    /* Device number */
0155     uint32_t        flags;      /* Flags */
0156     struct list_head    fcf_lsthead;    /* FCF entries */
0157     struct csio_fcf_info    *fcfinfo;   /* FCF in use */
0158     struct csio_ioreq   *mgmt_req;  /* MGMT request */
0159 
0160     /* FCoE identifiers */
0161     uint8_t         mac[6];
0162     uint32_t        nport_id;
0163     struct csio_service_parms ln_sparm; /* Service parms */
0164 
0165     /* Firmware identifiers */
0166     uint32_t        fcf_flowid; /*fcf flowid */
0167     uint32_t        vnp_flowid;
0168     uint16_t        ssn_cnt;    /* Registered Session */
0169     uint8_t         cur_evt;    /* Current event */
0170     uint8_t         prev_evt;   /* Previous event */
0171 
0172     /* Children */
0173     struct list_head    cln_head;   /* Head of the children lnode
0174                          * list.
0175                          */
0176     uint32_t        num_vports; /* Total NPIV/children LNodes*/
0177     struct csio_lnode   *pln;       /* Parent lnode of child
0178                          * lnodes.
0179                          */
0180     struct list_head    cmpl_q;     /* Pending I/Os on this lnode */
0181 
0182     /* Remote node information */
0183     struct list_head    rnhead;     /* Head of rnode list */
0184     uint32_t        num_reg_rnodes; /* Number of rnodes registered
0185                          * with the host.
0186                          */
0187     uint32_t        n_scsi_tgts;    /* Number of scsi targets
0188                          * found
0189                          */
0190     uint32_t        last_scan_ntgts;/* Number of scsi targets
0191                          * found per last scan.
0192                          */
0193     uint32_t        tgt_scan_tick;  /* timer started after
0194                          * new tgt found
0195                          */
0196     /* FC transport data */
0197     struct fc_vport     *fc_vport;
0198     struct fc_host_statistics fch_stats;
0199 
0200     struct csio_lnode_stats stats;      /* Common lnode stats */
0201     struct csio_lnode_params params;    /* Common lnode params */
0202 };
0203 
0204 #define csio_lnode_to_hw(ln)    ((ln)->hwp)
0205 #define csio_root_lnode(ln) (csio_lnode_to_hw((ln))->rln)
0206 #define csio_parent_lnode(ln)   ((ln)->pln)
0207 #define csio_ln_flowid(ln)  ((ln)->vnp_flowid)
0208 #define csio_ln_wwpn(ln)    ((ln)->ln_sparm.wwpn)
0209 #define csio_ln_wwnn(ln)    ((ln)->ln_sparm.wwnn)
0210 
0211 #define csio_is_root_ln(ln) (((ln) == csio_root_lnode((ln))) ? 1 : 0)
0212 #define csio_is_phys_ln(ln) (((ln)->pln == NULL) ? 1 : 0)
0213 #define csio_is_npiv_ln(ln) (((ln)->pln != NULL) ? 1 : 0)
0214 
0215 
0216 #define csio_ln_dbg(_ln, _fmt, ...) \
0217     csio_dbg(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
0218          CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
0219 
0220 #define csio_ln_err(_ln, _fmt, ...) \
0221     csio_err(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
0222          CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
0223 
0224 #define csio_ln_warn(_ln, _fmt, ...)    \
0225     csio_warn(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
0226          CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
0227 
0228 /* HW->Lnode notifications */
0229 enum csio_ln_notify {
0230     CSIO_LN_NOTIFY_HWREADY = 1,
0231     CSIO_LN_NOTIFY_HWSTOP,
0232     CSIO_LN_NOTIFY_HWREMOVE,
0233     CSIO_LN_NOTIFY_HWRESET,
0234 };
0235 
0236 void csio_fcoe_fwevt_handler(struct csio_hw *,  __u8 cpl_op, __be64 *);
0237 int csio_is_lnode_ready(struct csio_lnode *);
0238 void csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str);
0239 struct csio_lnode *csio_lnode_lookup_by_wwpn(struct csio_hw *, uint8_t *);
0240 int csio_get_phy_port_stats(struct csio_hw *, uint8_t ,
0241                       struct fw_fcoe_port_stats *);
0242 int csio_scan_done(struct csio_lnode *, unsigned long, unsigned long,
0243            unsigned long, unsigned long);
0244 void csio_notify_lnodes(struct csio_hw *, enum csio_ln_notify);
0245 void csio_disable_lnodes(struct csio_hw *, uint8_t, bool);
0246 void csio_lnode_async_event(struct csio_lnode *, enum csio_ln_fc_evt);
0247 int csio_ln_fdmi_start(struct csio_lnode *, void *);
0248 int csio_lnode_start(struct csio_lnode *);
0249 void csio_lnode_stop(struct csio_lnode *);
0250 void csio_lnode_close(struct csio_lnode *);
0251 int csio_lnode_init(struct csio_lnode *, struct csio_hw *,
0252                   struct csio_lnode *);
0253 void csio_lnode_exit(struct csio_lnode *);
0254 
0255 #endif /* ifndef __CSIO_LNODE_H__ */