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_RNODE_H__
36  #define __CSIO_RNODE_H__
37  
38  #include "csio_defs.h"
39  
40  /* State machine evets */
41  enum csio_rn_ev {
42  	CSIO_RNFE_NONE = (uint32_t)0,			/* None */
43  	CSIO_RNFE_LOGGED_IN,				/* [N/F]Port login
44  							 * complete.
45  							 */
46  	CSIO_RNFE_PRLI_DONE,				/* PRLI completed */
47  	CSIO_RNFE_PLOGI_RECV,				/* Received PLOGI */
48  	CSIO_RNFE_PRLI_RECV,				/* Received PLOGI */
49  	CSIO_RNFE_LOGO_RECV,				/* Received LOGO */
50  	CSIO_RNFE_PRLO_RECV,				/* Received PRLO */
51  	CSIO_RNFE_DOWN,					/* Rnode is down */
52  	CSIO_RNFE_CLOSE,				/* Close rnode */
53  	CSIO_RNFE_NAME_MISSING,				/* Rnode name missing
54  							 * in name server.
55  							 */
56  	CSIO_RNFE_MAX_EVENT,
57  };
58  
59  /* rnode stats */
60  struct csio_rnode_stats {
61  	uint32_t	n_err;		/* error */
62  	uint32_t	n_err_inval;	/* invalid parameter */
63  	uint32_t	n_err_nomem;	/* error nomem */
64  	uint32_t	n_evt_unexp;	/* unexpected event */
65  	uint32_t	n_evt_drop;	/* unexpected event */
66  	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];	/* fw events */
67  	enum csio_rn_ev	n_evt_sm[CSIO_RNFE_MAX_EVENT];	/* State m/c events */
68  	uint32_t	n_lun_rst;	/* Number of resets of
69  					 * of LUNs under this
70  					 * target
71  					 */
72  	uint32_t	n_lun_rst_fail;	/* Number of LUN reset
73  					 * failures.
74  					 */
75  	uint32_t	n_tgt_rst;	/* Number of target resets */
76  	uint32_t	n_tgt_rst_fail;	/* Number of target reset
77  					 * failures.
78  					 */
79  };
80  
81  /* Defines for rnode role */
82  #define	CSIO_RNFR_INITIATOR	0x1
83  #define	CSIO_RNFR_TARGET	0x2
84  #define CSIO_RNFR_FABRIC	0x4
85  #define	CSIO_RNFR_NS		0x8
86  #define CSIO_RNFR_NPORT		0x10
87  
88  struct csio_rnode {
89  	struct csio_sm		sm;			/* State machine -
90  							 * should be the
91  							 * 1st member
92  							 */
93  	struct csio_lnode	*lnp;			/* Pointer to owning
94  							 * Lnode */
95  	uint32_t		flowid;			/* Firmware ID */
96  	struct list_head	host_cmpl_q;		/* SCSI IOs
97  							 * pending to completed
98  							 * to Mid-layer.
99  							 */
100  	/* FC identifiers for remote node */
101  	uint32_t		nport_id;
102  	uint16_t		fcp_flags;		/* FCP Flags */
103  	uint8_t			cur_evt;		/* Current event */
104  	uint8_t			prev_evt;		/* Previous event */
105  	uint32_t		role;			/* Fabric/Target/
106  							 * Initiator/NS
107  							 */
108  	struct fcoe_rdev_entry		*rdev_entry;	/* Rdev entry */
109  	struct csio_service_parms	rn_sparm;
110  
111  	/* FC transport attributes */
112  	struct fc_rport		*rport;		/* FC transport rport */
113  	uint32_t		supp_classes;	/* Supported FC classes */
114  	uint32_t		maxframe_size;	/* Max Frame size */
115  	uint32_t		scsi_id;	/* Transport given SCSI id */
116  
117  	struct csio_rnode_stats	stats;		/* Common rnode stats */
118  };
119  
120  #define csio_rn_flowid(rn)			((rn)->flowid)
121  #define csio_rn_wwpn(rn)			((rn)->rn_sparm.wwpn)
122  #define csio_rn_wwnn(rn)			((rn)->rn_sparm.wwnn)
123  #define csio_rnode_to_lnode(rn)			((rn)->lnp)
124  
125  int csio_is_rnode_ready(struct csio_rnode *rn);
126  void csio_rnode_state_to_str(struct csio_rnode *rn, int8_t *str);
127  
128  struct csio_rnode *csio_rnode_lookup_portid(struct csio_lnode *, uint32_t);
129  struct csio_rnode *csio_confirm_rnode(struct csio_lnode *,
130  					  uint32_t, struct fcoe_rdev_entry *);
131  
132  void csio_rnode_fwevt_handler(struct csio_rnode *rn, uint8_t fwevt);
133  
134  void csio_put_rnode(struct csio_lnode *ln, struct csio_rnode *rn);
135  
136  void csio_reg_rnode(struct csio_rnode *);
137  void csio_unreg_rnode(struct csio_rnode *);
138  
139  void csio_rnode_devloss_handler(struct csio_rnode *);
140  
141  #endif /* ifndef __CSIO_RNODE_H__ */
142