]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/scsi/scsi_transport_fc.h
[SCSI] convert to PCI_DEVICE() macro
[mirror_ubuntu-bionic-kernel.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
4e57b681 30#include <linux/sched.h>
19a7b4ae 31#include <scsi/scsi.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,
42e33148 81 FC_PORTSTATE_DELETED,
1da177e4
LT
82};
83
84
85/*
86 * FC Classes of Service
87 * Note: values are not enumerated, as they can be "or'd" together
88 * for reporting (e.g. report supported_classes). If you alter this list,
89 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
90 */
91#define FC_COS_UNSPECIFIED 0
92#define FC_COS_CLASS1 2
93#define FC_COS_CLASS2 4
94#define FC_COS_CLASS3 8
95#define FC_COS_CLASS4 0x10
96#define FC_COS_CLASS6 0x40
97
98/*
99 * FC Port Speeds
100 * Note: values are not enumerated, as they can be "or'd" together
101 * for reporting (e.g. report supported_speeds). If you alter this list,
102 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
103 */
104#define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
105 incapable of reporting */
106#define FC_PORTSPEED_1GBIT 1
107#define FC_PORTSPEED_2GBIT 2
1832a586
AH
108#define FC_PORTSPEED_4GBIT 4
109#define FC_PORTSPEED_10GBIT 8
1da177e4
LT
110#define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
111
112/*
113 * fc_tgtid_binding_type: If you alter this, you also need to alter
114 * scsi_transport_fc.c (for the ascii descriptions).
115 */
116enum fc_tgtid_binding_type {
117 FC_TGTID_BIND_NONE,
118 FC_TGTID_BIND_BY_WWPN,
119 FC_TGTID_BIND_BY_WWNN,
120 FC_TGTID_BIND_BY_ID,
121};
122
123/*
124 * FC Remote Port Roles
125 * Note: values are not enumerated, as they can be "or'd" together
126 * for reporting (e.g. report roles). If you alter this list,
127 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
128 */
129#define FC_RPORT_ROLE_UNKNOWN 0x00
130#define FC_RPORT_ROLE_FCP_TARGET 0x01
131#define FC_RPORT_ROLE_FCP_INITIATOR 0x02
132#define FC_RPORT_ROLE_IP_PORT 0x04
133
134
135/*
136 * fc_rport_identifiers: This set of data contains all elements
137 * to uniquely identify a remote FC port. The driver uses this data
138 * to report the existence of a remote FC port in the topology. Internally,
139 * the transport uses this data for attributes and to manage consistent
140 * target id bindings.
141 */
142struct fc_rport_identifiers {
143 u64 node_name;
144 u64 port_name;
145 u32 port_id;
146 u32 roles;
147};
148
149/* Macro for use in defining Remote Port attributes */
150#define FC_RPORT_ATTR(_name,_mode,_show,_store) \
151struct class_device_attribute class_device_attr_rport_##_name = \
152 __ATTR(_name,_mode,_show,_store)
153
154
155/*
156 * FC Remote Port Attributes
157 *
158 * This structure exists for each remote FC port that a LLDD notifies
159 * the subsystem of. A remote FC port may or may not be a SCSI Target,
160 * also be a SCSI initiator, IP endpoint, etc. As such, the remote
161 * port is considered a separate entity, independent of "role" (such
162 * as scsi target).
163 *
164 * --
165 *
166 * Attributes are based on HBAAPI V2.0 definitions. Only those
167 * attributes that are determinable by the local port (aka Host)
168 * are contained.
169 *
170 * Fixed attributes are not expected to change. The driver is
171 * expected to set these values after successfully calling
172 * fc_remote_port_add(). The transport fully manages all get functions
173 * w/o driver interaction.
174 *
175 * Dynamic attributes are expected to change. The driver participates
176 * in all get/set operations via functions provided by the driver.
177 *
178 * Private attributes are transport-managed values. They are fully
179 * managed by the transport w/o driver interaction.
180 */
181
182struct fc_rport { /* aka fc_starget_attrs */
183 /* Fixed Attributes */
184 u32 maxframe_size;
185 u32 supported_classes;
186
187 /* Dynamic Attributes */
188 u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
189
190 /* Private (Transport-managed) Attributes */
191 u64 node_name;
192 u64 port_name;
193 u32 port_id;
194 u32 roles;
195 enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
196 u32 scsi_target_id;
197
198 /* exported data */
199 void *dd_data; /* Used for driver-specific storage */
200
201 /* internal data */
202 unsigned int channel;
203 u32 number;
aedf3497 204 u8 flags;
1da177e4
LT
205 struct list_head peers;
206 struct device dev;
207 struct work_struct dev_loss_work;
208 struct work_struct scan_work;
aedf3497
JS
209 struct work_struct stgt_delete_work;
210 struct work_struct rport_delete_work;
1da177e4
LT
211} __attribute__((aligned(sizeof(unsigned long))));
212
aedf3497
JS
213/* bit field values for struct fc_rport "flags" field: */
214#define FC_RPORT_DEVLOSS_PENDING 0x01
215#define FC_RPORT_SCAN_PENDING 0x02
216
1da177e4
LT
217#define dev_to_rport(d) \
218 container_of(d, struct fc_rport, dev)
219#define transport_class_to_rport(classdev) \
220 dev_to_rport(classdev->dev)
221#define rport_to_shost(r) \
222 dev_to_shost(r->dev.parent)
223
224/*
225 * FC SCSI Target Attributes
226 *
227 * The SCSI Target is considered an extention of a remote port (as
228 * a remote port can be more than a SCSI Target). Within the scsi
229 * subsystem, we leave the Target as a separate entity. Doing so
230 * provides backward compatibility with prior FC transport api's,
231 * and lets remote ports be handled entirely within the FC transport
232 * and independently from the scsi subsystem. The drawback is that
233 * some data will be duplicated.
234 */
235
236struct fc_starget_attrs { /* aka fc_target_attrs */
237 /* Dynamic Attributes */
238 u64 node_name;
239 u64 port_name;
240 u32 port_id;
241};
242
243#define fc_starget_node_name(x) \
244 (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
245#define fc_starget_port_name(x) \
246 (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
247#define fc_starget_port_id(x) \
248 (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
249
250#define starget_to_rport(s) \
251 scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
252
253
254/*
255 * FC Local Port (Host) Statistics
256 */
257
258/* FC Statistics - Following FC HBAAPI v2.0 guidelines */
259struct fc_host_statistics {
260 /* port statistics */
261 u64 seconds_since_last_reset;
262 u64 tx_frames;
263 u64 tx_words;
264 u64 rx_frames;
265 u64 rx_words;
266 u64 lip_count;
267 u64 nos_count;
268 u64 error_frames;
269 u64 dumped_frames;
270 u64 link_failure_count;
271 u64 loss_of_sync_count;
272 u64 loss_of_signal_count;
273 u64 prim_seq_protocol_err_count;
274 u64 invalid_tx_word_count;
275 u64 invalid_crc_count;
276
277 /* fc4 statistics (only FCP supported currently) */
278 u64 fcp_input_requests;
279 u64 fcp_output_requests;
280 u64 fcp_control_requests;
281 u64 fcp_input_megabytes;
282 u64 fcp_output_megabytes;
283};
284
285
286/*
287 * FC Local Port (Host) Attributes
288 *
289 * Attributes are based on HBAAPI V2.0 definitions.
290 * Note: OSDeviceName is determined by user-space library
291 *
292 * Fixed attributes are not expected to change. The driver is
293 * expected to set these values after successfully calling scsi_add_host().
294 * The transport fully manages all get functions w/o driver interaction.
295 *
296 * Dynamic attributes are expected to change. The driver participates
297 * in all get/set operations via functions provided by the driver.
298 *
299 * Private attributes are transport-managed values. They are fully
300 * managed by the transport w/o driver interaction.
301 */
302
303#define FC_FC4_LIST_SIZE 32
304#define FC_SYMBOLIC_NAME_SIZE 256
305#define FC_VERSION_STRING_SIZE 64
306#define FC_SERIAL_NUMBER_SIZE 80
307
308struct fc_host_attrs {
309 /* Fixed Attributes */
310 u64 node_name;
311 u64 port_name;
6b7281d0 312 u64 permanent_port_name;
1da177e4
LT
313 u32 supported_classes;
314 u8 supported_fc4s[FC_FC4_LIST_SIZE];
315 char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
316 u32 supported_speeds;
317 u32 maxframe_size;
318 char serial_number[FC_SERIAL_NUMBER_SIZE];
319
320 /* Dynamic Attributes */
321 u32 port_id;
322 enum fc_port_type port_type;
323 enum fc_port_state port_state;
324 u8 active_fc4s[FC_FC4_LIST_SIZE];
325 u32 speed;
326 u64 fabric_name;
327
328 /* Private (Transport-managed) Attributes */
329 enum fc_tgtid_binding_type tgtid_bind_type;
330
331 /* internal data */
332 struct list_head rports;
333 struct list_head rport_bindings;
334 u32 next_rport_number;
335 u32 next_target_id;
1da177e4 336
aedf3497
JS
337 /* work queues for rport state manipulation */
338 char work_q_name[KOBJ_NAME_LEN];
339 struct workqueue_struct *work_q;
340 char devloss_work_q_name[KOBJ_NAME_LEN];
341 struct workqueue_struct *devloss_work_q;
342};
42e33148 343
aedf3497
JS
344#define shost_to_fc_host(x) \
345 ((struct fc_host_attrs *)(x)->shost_data)
42e33148 346
1da177e4
LT
347#define fc_host_node_name(x) \
348 (((struct fc_host_attrs *)(x)->shost_data)->node_name)
349#define fc_host_port_name(x) \
350 (((struct fc_host_attrs *)(x)->shost_data)->port_name)
6b7281d0
AH
351#define fc_host_permanent_port_name(x) \
352 (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
1da177e4
LT
353#define fc_host_supported_classes(x) \
354 (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
355#define fc_host_supported_fc4s(x) \
356 (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
357#define fc_host_symbolic_name(x) \
358 (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
359#define fc_host_supported_speeds(x) \
360 (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
361#define fc_host_maxframe_size(x) \
362 (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
363#define fc_host_serial_number(x) \
364 (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
365#define fc_host_port_id(x) \
366 (((struct fc_host_attrs *)(x)->shost_data)->port_id)
367#define fc_host_port_type(x) \
368 (((struct fc_host_attrs *)(x)->shost_data)->port_type)
369#define fc_host_port_state(x) \
370 (((struct fc_host_attrs *)(x)->shost_data)->port_state)
371#define fc_host_active_fc4s(x) \
372 (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
373#define fc_host_speed(x) \
374 (((struct fc_host_attrs *)(x)->shost_data)->speed)
375#define fc_host_fabric_name(x) \
376 (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
377#define fc_host_tgtid_bind_type(x) \
378 (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
379#define fc_host_rports(x) \
380 (((struct fc_host_attrs *)(x)->shost_data)->rports)
381#define fc_host_rport_bindings(x) \
382 (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
383#define fc_host_next_rport_number(x) \
384 (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
385#define fc_host_next_target_id(x) \
386 (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
aedf3497
JS
387#define fc_host_work_q_name(x) \
388 (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
389#define fc_host_work_q(x) \
390 (((struct fc_host_attrs *)(x)->shost_data)->work_q)
391#define fc_host_devloss_work_q_name(x) \
392 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
393#define fc_host_devloss_work_q(x) \
394 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
1da177e4
LT
395
396
397/* The functions by which the transport class and the driver communicate */
398struct fc_function_template {
399 void (*get_rport_dev_loss_tmo)(struct fc_rport *);
400 void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
401
402 void (*get_starget_node_name)(struct scsi_target *);
403 void (*get_starget_port_name)(struct scsi_target *);
404 void (*get_starget_port_id)(struct scsi_target *);
405
406 void (*get_host_port_id)(struct Scsi_Host *);
407 void (*get_host_port_type)(struct Scsi_Host *);
408 void (*get_host_port_state)(struct Scsi_Host *);
409 void (*get_host_active_fc4s)(struct Scsi_Host *);
410 void (*get_host_speed)(struct Scsi_Host *);
411 void (*get_host_fabric_name)(struct Scsi_Host *);
016131b8 412 void (*get_host_symbolic_name)(struct Scsi_Host *);
1da177e4
LT
413
414 struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
415 void (*reset_fc_host_stats)(struct Scsi_Host *);
416
91ca7b01
AV
417 int (*issue_fc_host_lip)(struct Scsi_Host *);
418
1da177e4
LT
419 /* allocation lengths for host-specific data */
420 u32 dd_fcrport_size;
421
422 /*
423 * The driver sets these to tell the transport class it
424 * wants the attributes displayed in sysfs. If the show_ flag
425 * is not set, the attribute will be private to the transport
426 * class
427 */
428
429 /* remote port fixed attributes */
430 unsigned long show_rport_maxframe_size:1;
431 unsigned long show_rport_supported_classes:1;
432 unsigned long show_rport_dev_loss_tmo:1;
433
434 /*
435 * target dynamic attributes
436 * These should all be "1" if the driver uses the remote port
437 * add/delete functions (so attributes reflect rport values).
438 */
439 unsigned long show_starget_node_name:1;
440 unsigned long show_starget_port_name:1;
441 unsigned long show_starget_port_id:1;
442
443 /* host fixed attributes */
444 unsigned long show_host_node_name:1;
445 unsigned long show_host_port_name:1;
6b7281d0 446 unsigned long show_host_permanent_port_name:1;
1da177e4
LT
447 unsigned long show_host_supported_classes:1;
448 unsigned long show_host_supported_fc4s:1;
1da177e4
LT
449 unsigned long show_host_supported_speeds:1;
450 unsigned long show_host_maxframe_size:1;
451 unsigned long show_host_serial_number:1;
452 /* host dynamic attributes */
453 unsigned long show_host_port_id:1;
454 unsigned long show_host_port_type:1;
455 unsigned long show_host_port_state:1;
456 unsigned long show_host_active_fc4s:1;
457 unsigned long show_host_speed:1;
458 unsigned long show_host_fabric_name:1;
016131b8 459 unsigned long show_host_symbolic_name:1;
1da177e4
LT
460};
461
462
19a7b4ae
JSEC
463/**
464 * fc_remote_port_chkready - called to validate the remote port state
465 * prior to initiating io to the port.
466 *
467 * Returns a scsi result code that can be returned by the LLDD.
468 *
469 * @rport: remote port to be checked
470 **/
471static inline int
472fc_remote_port_chkready(struct fc_rport *rport)
473{
474 int result;
475
476 switch (rport->port_state) {
477 case FC_PORTSTATE_ONLINE:
aedf3497
JS
478 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
479 result = 0;
480 else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
481 result = DID_IMM_RETRY << 16;
482 else
483 result = DID_NO_CONNECT << 16;
19a7b4ae
JSEC
484 break;
485 case FC_PORTSTATE_BLOCKED:
aedf3497 486 result = DID_IMM_RETRY << 16;
19a7b4ae
JSEC
487 break;
488 default:
489 result = DID_NO_CONNECT << 16;
490 break;
491 }
492 return result;
493}
494
495
1da177e4
LT
496struct scsi_transport_template *fc_attach_transport(
497 struct fc_function_template *);
498void fc_release_transport(struct scsi_transport_template *);
499void fc_remove_host(struct Scsi_Host *);
500struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
501 int channel, struct fc_rport_identifiers *ids);
502void fc_remote_port_delete(struct fc_rport *rport);
503void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
1da177e4
LT
504int scsi_is_fc_rport(const struct device *);
505
218fba00
AV
506static inline u64 wwn_to_u64(u8 *wwn)
507{
508 return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
509 (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
510 (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
511 (u64)wwn[6] << 8 | (u64)wwn[7];
512}
513
1da177e4 514#endif /* SCSI_TRANSPORT_FC_H */