1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
5  */
6 
7 #if !defined(__EFCT_XPORT_H__)
8 #define __EFCT_XPORT_H__
9 
10 enum efct_xport_ctrl {
11 	EFCT_XPORT_PORT_ONLINE = 1,
12 	EFCT_XPORT_PORT_OFFLINE,
13 	EFCT_XPORT_SHUTDOWN,
14 	EFCT_XPORT_POST_NODE_EVENT,
15 	EFCT_XPORT_WWNN_SET,
16 	EFCT_XPORT_WWPN_SET,
17 };
18 
19 enum efct_xport_status {
20 	EFCT_XPORT_PORT_STATUS,
21 	EFCT_XPORT_CONFIG_PORT_STATUS,
22 	EFCT_XPORT_LINK_SPEED,
23 	EFCT_XPORT_IS_SUPPORTED_LINK_SPEED,
24 	EFCT_XPORT_LINK_STATISTICS,
25 	EFCT_XPORT_LINK_STAT_RESET,
26 	EFCT_XPORT_IS_QUIESCED
27 };
28 
29 struct efct_xport_link_stats {
30 	bool		rec;
31 	bool		gec;
32 	bool		w02of;
33 	bool		w03of;
34 	bool		w04of;
35 	bool		w05of;
36 	bool		w06of;
37 	bool		w07of;
38 	bool		w08of;
39 	bool		w09of;
40 	bool		w10of;
41 	bool		w11of;
42 	bool		w12of;
43 	bool		w13of;
44 	bool		w14of;
45 	bool		w15of;
46 	bool		w16of;
47 	bool		w17of;
48 	bool		w18of;
49 	bool		w19of;
50 	bool		w20of;
51 	bool		w21of;
52 	bool		clrc;
53 	bool		clof1;
54 	u32		link_failure_error_count;
55 	u32		loss_of_sync_error_count;
56 	u32		loss_of_signal_error_count;
57 	u32		primitive_sequence_error_count;
58 	u32		invalid_transmission_word_error_count;
59 	u32		crc_error_count;
60 	u32		primitive_sequence_event_timeout_count;
61 	u32		elastic_buffer_overrun_error_count;
62 	u32		arbitration_fc_al_timeout_count;
63 	u32		advertised_receive_bufftor_to_buffer_credit;
64 	u32		current_receive_buffer_to_buffer_credit;
65 	u32		advertised_transmit_buffer_to_buffer_credit;
66 	u32		current_transmit_buffer_to_buffer_credit;
67 	u32		received_eofa_count;
68 	u32		received_eofdti_count;
69 	u32		received_eofni_count;
70 	u32		received_soff_count;
71 	u32		received_dropped_no_aer_count;
72 	u32		received_dropped_no_available_rpi_resources_count;
73 	u32		received_dropped_no_available_xri_resources_count;
74 };
75 
76 struct efct_xport_host_stats {
77 	bool		cc;
78 	u32		transmit_kbyte_count;
79 	u32		receive_kbyte_count;
80 	u32		transmit_frame_count;
81 	u32		receive_frame_count;
82 	u32		transmit_sequence_count;
83 	u32		receive_sequence_count;
84 	u32		total_exchanges_originator;
85 	u32		total_exchanges_responder;
86 	u32		receive_p_bsy_count;
87 	u32		receive_f_bsy_count;
88 	u32		dropped_frames_due_to_no_rq_buffer_count;
89 	u32		empty_rq_timeout_count;
90 	u32		dropped_frames_due_to_no_xri_count;
91 	u32		empty_xri_pool_count;
92 };
93 
94 struct efct_xport_host_statistics {
95 	struct completion		done;
96 	struct efct_xport_link_stats	link_stats;
97 	struct efct_xport_host_stats	host_stats;
98 };
99 
100 union efct_xport_stats_u {
101 	u32	value;
102 	struct efct_xport_host_statistics stats;
103 };
104 
105 struct efct_xport_fcp_stats {
106 	u64		input_bytes;
107 	u64		output_bytes;
108 	u64		input_requests;
109 	u64		output_requests;
110 	u64		control_requests;
111 };
112 
113 struct efct_xport {
114 	struct efct		*efct;
115 	/* wwpn requested by user for primary nport */
116 	u64			req_wwpn;
117 	/* wwnn requested by user for primary nport */
118 	u64			req_wwnn;
119 
120 	/* Nodes */
121 	/* number of allocated nodes */
122 	u32			nodes_count;
123 	/* used to track how often IO pool is empty */
124 	atomic_t		io_alloc_failed_count;
125 	/* array of pointers to nodes */
126 	struct efc_node		**nodes;
127 
128 	/* Io pool and counts */
129 	/* pointer to IO pool */
130 	struct efct_io_pool	*io_pool;
131 	/* lock for io_pending_list */
132 	spinlock_t		io_pending_lock;
133 	/* list of IOs waiting for HW resources
134 	 *  lock: xport->io_pending_lock
135 	 *  link: efct_io_s->io_pending_link
136 	 */
137 	struct list_head	io_pending_list;
138 	/* count of totals IOS allocated */
139 	atomic_t		io_total_alloc;
140 	/* count of totals IOS free'd */
141 	atomic_t		io_total_free;
142 	/* count of totals IOS that were pended */
143 	atomic_t		io_total_pending;
144 	/* count of active IOS */
145 	atomic_t		io_active_count;
146 	/* count of pending IOS */
147 	atomic_t		io_pending_count;
148 	/* non-zero if efct_scsi_check_pending is executing */
149 	atomic_t		io_pending_recursing;
150 
151 	/* Port */
152 	/* requested link state */
153 	u32			configured_link_state;
154 
155 	/* Timer for Statistics */
156 	struct timer_list	stats_timer;
157 	union efct_xport_stats_u fc_xport_stats;
158 	struct efct_xport_fcp_stats fcp_stats;
159 };
160 
161 struct efct_rport_data {
162 	struct efc_node		*node;
163 };
164 
165 struct efct_xport *
166 efct_xport_alloc(struct efct *efct);
167 int
168 efct_xport_attach(struct efct_xport *xport);
169 int
170 efct_xport_initialize(struct efct_xport *xport);
171 void
172 efct_xport_detach(struct efct_xport *xport);
173 int
174 efct_xport_control(struct efct_xport *xport, enum efct_xport_ctrl cmd, ...);
175 int
176 efct_xport_status(struct efct_xport *xport, enum efct_xport_status cmd,
177 		  union efct_xport_stats_u *result);
178 void
179 efct_xport_free(struct efct_xport *xport);
180 
181 struct scsi_transport_template *efct_attach_fc_transport(void);
182 struct scsi_transport_template *efct_attach_vport_fc_transport(void);
183 void
184 efct_release_fc_transport(struct scsi_transport_template *transport_template);
185 
186 #endif /* __EFCT_XPORT_H__ */
187