1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4  * Copyright (c) 2014- QLogic Corporation.
5  * All rights reserved
6  * www.qlogic.com
7  *
8  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9  */
10 #ifndef __BFA_PORTLOG_H__
11 #define __BFA_PORTLOG_H__
12 
13 #include "bfa_fc.h"
14 #include "bfa_defs.h"
15 
16 #define BFA_PL_NLOG_ENTS 256
17 #define BFA_PL_LOG_REC_INCR(_x) ((_x)++, (_x) %= BFA_PL_NLOG_ENTS)
18 
19 #define BFA_PL_STRING_LOG_SZ   32   /* number of chars in string log */
20 #define BFA_PL_INT_LOG_SZ      8    /* number of integers in the integer log */
21 
22 enum bfa_plog_log_type {
23 	BFA_PL_LOG_TYPE_INVALID	= 0,
24 	BFA_PL_LOG_TYPE_INT	= 1,
25 	BFA_PL_LOG_TYPE_STRING	= 2,
26 };
27 
28 /*
29  * the (fixed size) record format for each entry in the portlog
30  */
31 struct bfa_plog_rec_s {
32 	u64	tv;	/* timestamp */
33 	u8	 port;	/* Source port that logged this entry */
34 	u8	 mid;	/* module id */
35 	u8	 eid;	/* indicates Rx, Tx, IOCTL, etc.  bfa_plog_eid */
36 	u8	 log_type; /* string/integer log, bfa_plog_log_type_t */
37 	u8	 log_num_ints;
38 	/*
39 	 * interpreted only if log_type is INT_LOG. indicates number of
40 	 * integers in the int_log[] (0-PL_INT_LOG_SZ).
41 	 */
42 	u8	 rsvd;
43 	u16	misc;	/* can be used to indicate fc frame length */
44 	union {
45 		char	    string_log[BFA_PL_STRING_LOG_SZ];
46 		u32	int_log[BFA_PL_INT_LOG_SZ];
47 	} log_entry;
48 
49 };
50 
51 /*
52  * the following #defines will be used by the logging entities to indicate
53  * their module id. BFAL will convert the integer value to string format
54  *
55 * process to be used while changing the following #defines:
56  *  - Always add new entries at the end
57  *  - define corresponding string in BFAL
58  *  - Do not remove any entry or rearrange the order.
59  */
60 enum bfa_plog_mid {
61 	BFA_PL_MID_INVALID	= 0,
62 	BFA_PL_MID_DEBUG	= 1,
63 	BFA_PL_MID_DRVR		= 2,
64 	BFA_PL_MID_HAL		= 3,
65 	BFA_PL_MID_HAL_FCXP	= 4,
66 	BFA_PL_MID_HAL_UF	= 5,
67 	BFA_PL_MID_FCS		= 6,
68 	BFA_PL_MID_LPS		= 7,
69 	BFA_PL_MID_MAX		= 8
70 };
71 
72 #define BFA_PL_MID_STRLEN    8
73 struct bfa_plog_mid_strings_s {
74 	char	    m_str[BFA_PL_MID_STRLEN];
75 };
76 
77 /*
78  * the following #defines will be used by the logging entities to indicate
79  * their event type. BFAL will convert the integer value to string format
80  *
81 * process to be used while changing the following #defines:
82  *  - Always add new entries at the end
83  *  - define corresponding string in BFAL
84  *  - Do not remove any entry or rearrange the order.
85  */
86 enum bfa_plog_eid {
87 	BFA_PL_EID_INVALID		= 0,
88 	BFA_PL_EID_IOC_DISABLE		= 1,
89 	BFA_PL_EID_IOC_ENABLE		= 2,
90 	BFA_PL_EID_PORT_DISABLE		= 3,
91 	BFA_PL_EID_PORT_ENABLE		= 4,
92 	BFA_PL_EID_PORT_ST_CHANGE	= 5,
93 	BFA_PL_EID_TX			= 6,
94 	BFA_PL_EID_TX_ACK1		= 7,
95 	BFA_PL_EID_TX_RJT		= 8,
96 	BFA_PL_EID_TX_BSY		= 9,
97 	BFA_PL_EID_RX			= 10,
98 	BFA_PL_EID_RX_ACK1		= 11,
99 	BFA_PL_EID_RX_RJT		= 12,
100 	BFA_PL_EID_RX_BSY		= 13,
101 	BFA_PL_EID_CT_IN		= 14,
102 	BFA_PL_EID_CT_OUT		= 15,
103 	BFA_PL_EID_DRIVER_START		= 16,
104 	BFA_PL_EID_RSCN			= 17,
105 	BFA_PL_EID_DEBUG		= 18,
106 	BFA_PL_EID_MISC			= 19,
107 	BFA_PL_EID_FIP_FCF_DISC		= 20,
108 	BFA_PL_EID_FIP_FCF_CVL		= 21,
109 	BFA_PL_EID_LOGIN		= 22,
110 	BFA_PL_EID_LOGO			= 23,
111 	BFA_PL_EID_TRUNK_SCN		= 24,
112 	BFA_PL_EID_MAX
113 };
114 
115 #define BFA_PL_ENAME_STRLEN	8
116 struct bfa_plog_eid_strings_s {
117 	char	    e_str[BFA_PL_ENAME_STRLEN];
118 };
119 
120 #define BFA_PL_SIG_LEN	8
121 #define BFA_PL_SIG_STR  "12pl123"
122 
123 /*
124  * per port circular log buffer
125  */
126 struct bfa_plog_s {
127 	char	    plog_sig[BFA_PL_SIG_LEN];	/* Start signature */
128 	u8	 plog_enabled;
129 	u8	 rsvd[7];
130 	u32	ticks;
131 	u16	head;
132 	u16	tail;
133 	struct bfa_plog_rec_s  plog_recs[BFA_PL_NLOG_ENTS];
134 };
135 
136 void bfa_plog_init(struct bfa_plog_s *plog);
137 void bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
138 			enum bfa_plog_eid event, u16 misc, char *log_str);
139 void bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
140 			enum bfa_plog_eid event, u16 misc,
141 			u32 *intarr, u32 num_ints);
142 void bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
143 		enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr);
144 void bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
145 			enum bfa_plog_eid event, u16 misc,
146 			struct fchs_s *fchdr, u32 pld_w0);
147 
148 #endif /* __BFA_PORTLOG_H__ */
149