[PATCH] fix missing includes
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / scsi / scsi_transport_fc.h
CommitLineData
1da177e4
LT
1/*
2 * FiberChannel transport specific attributes exported to sysfs.
3 *
4 * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * ========
21 *
22 * Copyright (C) 2004-2005 James Smart, Emulex Corporation
23 * Rewrite for host, target, device, and remote port attributes,
24 * statistics, and service functions...
25 *
26 */
27#ifndef SCSI_TRANSPORT_FC_H
28#define SCSI_TRANSPORT_FC_H
29
30#include <linux/config.h>
4e57b681 31#include <linux/sched.h>
1da177e4
LT
32
33struct scsi_transport_template;
34
35
36/*
37 * FC Port definitions - Following FC HBAAPI guidelines
38 *
39 * Note: Not all binary values for the different fields match HBAAPI.
40 * Instead, we use densely packed ordinal values or enums.
41 * We get away with this as we never present the actual binary values
42 * externally. For sysfs, we always present the string that describes
43 * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
44 * to understand the values. The HBAAPI user-space library is free to
45 * convert the strings into the HBAAPI-specified binary values.
46 *
47 * Note: Not all HBAAPI-defined values are contained in the definitions
48 * below. Those not appropriate to an fc_host (e.g. FCP initiator) have
49 * been removed.
50 */
51
52/*
53 * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
54 * (for the ascii descriptions).
55 */
56enum fc_port_type {
57 FC_PORTTYPE_UNKNOWN,
58 FC_PORTTYPE_OTHER,
59 FC_PORTTYPE_NOTPRESENT,
60 FC_PORTTYPE_NPORT, /* Attached to FPort */
61 FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */
62 FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */
63 FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */
64};
65
66/*
67 * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
68 * (for the ascii descriptions).
69 */
70enum fc_port_state {
71 FC_PORTSTATE_UNKNOWN,
72 FC_PORTSTATE_NOTPRESENT,
73 FC_PORTSTATE_ONLINE,
74 FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
75 FC_PORTSTATE_BLOCKED,
76 FC_PORTSTATE_BYPASSED,
77 FC_PORTSTATE_DIAGNOSTICS,
78 FC_PORTSTATE_LINKDOWN,
79 FC_PORTSTATE_ERROR,
80 FC_PORTSTATE_LOOPBACK,
81};
82
83
84/*
85 * FC Classes of Service
86 * Note: values are not enumerated, as they can be "or'd" together
87 * for reporting (e.g. report supported_classes). If you alter this list,
88 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
89 */
90#define FC_COS_UNSPECIFIED 0
91#define FC_COS_CLASS1 2
92#define FC_COS_CLASS2 4
93#define FC_COS_CLASS3 8
94#define FC_COS_CLASS4 0x10
95#define FC_COS_CLASS6 0x40
96
97/*
98 * FC Port Speeds
99 * Note: values are not enumerated, as they can be "or'd" together
100 * for reporting (e.g. report supported_speeds). If you alter this list,
101 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
102 */
103#define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
104 incapable of reporting */
105#define FC_PORTSPEED_1GBIT 1
106#define FC_PORTSPEED_2GBIT 2
1832a586
AH
107#define FC_PORTSPEED_4GBIT 4
108#define FC_PORTSPEED_10GBIT 8
1da177e4
LT
109#define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
110
111/*
112 * fc_tgtid_binding_type: If you alter this, you also need to alter
113 * scsi_transport_fc.c (for the ascii descriptions).
114 */
115enum fc_tgtid_binding_type {
116 FC_TGTID_BIND_NONE,
117 FC_TGTID_BIND_BY_WWPN,
118 FC_TGTID_BIND_BY_WWNN,
119 FC_TGTID_BIND_BY_ID,
120};
121
122/*
123 * FC Remote Port Roles
124 * Note: values are not enumerated, as they can be "or'd" together
125 * for reporting (e.g. report roles). If you alter this list,
126 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
127 */
128#define FC_RPORT_ROLE_UNKNOWN 0x00
129#define FC_RPORT_ROLE_FCP_TARGET 0x01
130#define FC_RPORT_ROLE_FCP_INITIATOR 0x02
131#define FC_RPORT_ROLE_IP_PORT 0x04
132
133
134/*
135 * fc_rport_identifiers: This set of data contains all elements
136 * to uniquely identify a remote FC port. The driver uses this data
137 * to report the existence of a remote FC port in the topology. Internally,
138 * the transport uses this data for attributes and to manage consistent
139 * target id bindings.
140 */
141struct fc_rport_identifiers {
142 u64 node_name;
143 u64 port_name;
144 u32 port_id;
145 u32 roles;
146};
147
148/* Macro for use in defining Remote Port attributes */
149#define FC_RPORT_ATTR(_name,_mode,_show,_store) \
150struct class_device_attribute class_device_attr_rport_##_name = \
151 __ATTR(_name,_mode,_show,_store)
152
153
154/*
155 * FC Remote Port Attributes
156 *
157 * This structure exists for each remote FC port that a LLDD notifies
158 * the subsystem of. A remote FC port may or may not be a SCSI Target,
159 * also be a SCSI initiator, IP endpoint, etc. As such, the remote
160 * port is considered a separate entity, independent of "role" (such
161 * as scsi target).
162 *
163 * --
164 *
165 * Attributes are based on HBAAPI V2.0 definitions. Only those
166 * attributes that are determinable by the local port (aka Host)
167 * are contained.
168 *
169 * Fixed attributes are not expected to change. The driver is
170 * expected to set these values after successfully calling
171 * fc_remote_port_add(). The transport fully manages all get functions
172 * w/o driver interaction.
173 *
174 * Dynamic attributes are expected to change. The driver participates
175 * in all get/set operations via functions provided by the driver.
176 *
177 * Private attributes are transport-managed values. They are fully
178 * managed by the transport w/o driver interaction.
179 */
180
181struct fc_rport { /* aka fc_starget_attrs */
182 /* Fixed Attributes */
183 u32 maxframe_size;
184 u32 supported_classes;
185
186 /* Dynamic Attributes */
187 u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
188
189 /* Private (Transport-managed) Attributes */
190 u64 node_name;
191 u64 port_name;
192 u32 port_id;
193 u32 roles;
194 enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
195 u32 scsi_target_id;
196
197 /* exported data */
198 void *dd_data; /* Used for driver-specific storage */
199
200 /* internal data */
201 unsigned int channel;
202 u32 number;
203 struct list_head peers;
204 struct device dev;
205 struct work_struct dev_loss_work;
206 struct work_struct scan_work;
207} __attribute__((aligned(sizeof(unsigned long))));
208
209#define dev_to_rport(d) \
210 container_of(d, struct fc_rport, dev)
211#define transport_class_to_rport(classdev) \
212 dev_to_rport(classdev->dev)
213#define rport_to_shost(r) \
214 dev_to_shost(r->dev.parent)
215
216/*
217 * FC SCSI Target Attributes
218 *
219 * The SCSI Target is considered an extention of a remote port (as
220 * a remote port can be more than a SCSI Target). Within the scsi
221 * subsystem, we leave the Target as a separate entity. Doing so
222 * provides backward compatibility with prior FC transport api's,
223 * and lets remote ports be handled entirely within the FC transport
224 * and independently from the scsi subsystem. The drawback is that
225 * some data will be duplicated.
226 */
227
228struct fc_starget_attrs { /* aka fc_target_attrs */
229 /* Dynamic Attributes */
230 u64 node_name;
231 u64 port_name;
232 u32 port_id;
233};
234
235#define fc_starget_node_name(x) \
236 (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
237#define fc_starget_port_name(x) \
238 (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
239#define fc_starget_port_id(x) \
240 (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
241
242#define starget_to_rport(s) \
243 scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
244
245
246/*
247 * FC Local Port (Host) Statistics
248 */
249
250/* FC Statistics - Following FC HBAAPI v2.0 guidelines */
251struct fc_host_statistics {
252 /* port statistics */
253 u64 seconds_since_last_reset;
254 u64 tx_frames;
255 u64 tx_words;
256 u64 rx_frames;
257 u64 rx_words;
258 u64 lip_count;
259 u64 nos_count;
260 u64 error_frames;
261 u64 dumped_frames;
262 u64 link_failure_count;
263 u64 loss_of_sync_count;
264 u64 loss_of_signal_count;
265 u64 prim_seq_protocol_err_count;
266 u64 invalid_tx_word_count;
267 u64 invalid_crc_count;
268
269 /* fc4 statistics (only FCP supported currently) */
270 u64 fcp_input_requests;
271 u64 fcp_output_requests;
272 u64 fcp_control_requests;
273 u64 fcp_input_megabytes;
274 u64 fcp_output_megabytes;
275};
276
277
278/*
279 * FC Local Port (Host) Attributes
280 *
281 * Attributes are based on HBAAPI V2.0 definitions.
282 * Note: OSDeviceName is determined by user-space library
283 *
284 * Fixed attributes are not expected to change. The driver is
285 * expected to set these values after successfully calling scsi_add_host().
286 * The transport fully manages all get functions w/o driver interaction.
287 *
288 * Dynamic attributes are expected to change. The driver participates
289 * in all get/set operations via functions provided by the driver.
290 *
291 * Private attributes are transport-managed values. They are fully
292 * managed by the transport w/o driver interaction.
293 */
294
295#define FC_FC4_LIST_SIZE 32
296#define FC_SYMBOLIC_NAME_SIZE 256
297#define FC_VERSION_STRING_SIZE 64
298#define FC_SERIAL_NUMBER_SIZE 80
299
300struct fc_host_attrs {
301 /* Fixed Attributes */
302 u64 node_name;
303 u64 port_name;
304 u32 supported_classes;
305 u8 supported_fc4s[FC_FC4_LIST_SIZE];
306 char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
307 u32 supported_speeds;
308 u32 maxframe_size;
309 char serial_number[FC_SERIAL_NUMBER_SIZE];
310
311 /* Dynamic Attributes */
312 u32 port_id;
313 enum fc_port_type port_type;
314 enum fc_port_state port_state;
315 u8 active_fc4s[FC_FC4_LIST_SIZE];
316 u32 speed;
317 u64 fabric_name;
318
319 /* Private (Transport-managed) Attributes */
320 enum fc_tgtid_binding_type tgtid_bind_type;
321
322 /* internal data */
323 struct list_head rports;
324 struct list_head rport_bindings;
325 u32 next_rport_number;
326 u32 next_target_id;
327};
328
329#define fc_host_node_name(x) \
330 (((struct fc_host_attrs *)(x)->shost_data)->node_name)
331#define fc_host_port_name(x) \
332 (((struct fc_host_attrs *)(x)->shost_data)->port_name)
333#define fc_host_supported_classes(x) \
334 (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
335#define fc_host_supported_fc4s(x) \
336 (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
337#define fc_host_symbolic_name(x) \
338 (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
339#define fc_host_supported_speeds(x) \
340 (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
341#define fc_host_maxframe_size(x) \
342 (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
343#define fc_host_serial_number(x) \
344 (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
345#define fc_host_port_id(x) \
346 (((struct fc_host_attrs *)(x)->shost_data)->port_id)
347#define fc_host_port_type(x) \
348 (((struct fc_host_attrs *)(x)->shost_data)->port_type)
349#define fc_host_port_state(x) \
350 (((struct fc_host_attrs *)(x)->shost_data)->port_state)
351#define fc_host_active_fc4s(x) \
352 (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
353#define fc_host_speed(x) \
354 (((struct fc_host_attrs *)(x)->shost_data)->speed)
355#define fc_host_fabric_name(x) \
356 (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
357#define fc_host_tgtid_bind_type(x) \
358 (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
359#define fc_host_rports(x) \
360 (((struct fc_host_attrs *)(x)->shost_data)->rports)
361#define fc_host_rport_bindings(x) \
362 (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
363#define fc_host_next_rport_number(x) \
364 (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
365#define fc_host_next_target_id(x) \
366 (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
367
368
369/* The functions by which the transport class and the driver communicate */
370struct fc_function_template {
371 void (*get_rport_dev_loss_tmo)(struct fc_rport *);
372 void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
373
374 void (*get_starget_node_name)(struct scsi_target *);
375 void (*get_starget_port_name)(struct scsi_target *);
376 void (*get_starget_port_id)(struct scsi_target *);
377
378 void (*get_host_port_id)(struct Scsi_Host *);
379 void (*get_host_port_type)(struct Scsi_Host *);
380 void (*get_host_port_state)(struct Scsi_Host *);
381 void (*get_host_active_fc4s)(struct Scsi_Host *);
382 void (*get_host_speed)(struct Scsi_Host *);
383 void (*get_host_fabric_name)(struct Scsi_Host *);
384
385 struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
386 void (*reset_fc_host_stats)(struct Scsi_Host *);
387
388 /* allocation lengths for host-specific data */
389 u32 dd_fcrport_size;
390
391 /*
392 * The driver sets these to tell the transport class it
393 * wants the attributes displayed in sysfs. If the show_ flag
394 * is not set, the attribute will be private to the transport
395 * class
396 */
397
398 /* remote port fixed attributes */
399 unsigned long show_rport_maxframe_size:1;
400 unsigned long show_rport_supported_classes:1;
401 unsigned long show_rport_dev_loss_tmo:1;
402
403 /*
404 * target dynamic attributes
405 * These should all be "1" if the driver uses the remote port
406 * add/delete functions (so attributes reflect rport values).
407 */
408 unsigned long show_starget_node_name:1;
409 unsigned long show_starget_port_name:1;
410 unsigned long show_starget_port_id:1;
411
412 /* host fixed attributes */
413 unsigned long show_host_node_name:1;
414 unsigned long show_host_port_name:1;
415 unsigned long show_host_supported_classes:1;
416 unsigned long show_host_supported_fc4s:1;
417 unsigned long show_host_symbolic_name:1;
418 unsigned long show_host_supported_speeds:1;
419 unsigned long show_host_maxframe_size:1;
420 unsigned long show_host_serial_number:1;
421 /* host dynamic attributes */
422 unsigned long show_host_port_id:1;
423 unsigned long show_host_port_type:1;
424 unsigned long show_host_port_state:1;
425 unsigned long show_host_active_fc4s:1;
426 unsigned long show_host_speed:1;
427 unsigned long show_host_fabric_name:1;
428};
429
430
431struct scsi_transport_template *fc_attach_transport(
432 struct fc_function_template *);
433void fc_release_transport(struct scsi_transport_template *);
434void fc_remove_host(struct Scsi_Host *);
435struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
436 int channel, struct fc_rport_identifiers *ids);
437void fc_remote_port_delete(struct fc_rport *rport);
438void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
439int fc_remote_port_block(struct fc_rport *rport);
440void fc_remote_port_unblock(struct fc_rport *rport);
441int scsi_is_fc_rport(const struct device *);
442
218fba00
AV
443static inline u64 wwn_to_u64(u8 *wwn)
444{
445 return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
446 (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
447 (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
448 (u64)wwn[6] << 8 | (u64)wwn[7];
449}
450
1da177e4 451#endif /* SCSI_TRANSPORT_FC_H */