Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[pandora-kernel.git] / include / scsi / scsi_transport_fc.h
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>
31 #include <linux/sched.h>
32 #include <scsi/scsi.h>
33
34 struct scsi_transport_template;
35
36
37 /*
38  * FC Port definitions - Following FC HBAAPI guidelines
39  *
40  * Note: Not all binary values for the different fields match HBAAPI.
41  *  Instead, we use densely packed ordinal values or enums.
42  *  We get away with this as we never present the actual binary values
43  *  externally. For sysfs, we always present the string that describes
44  *  the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
45  *  to understand the values. The HBAAPI user-space library is free to
46  *  convert the strings into the HBAAPI-specified binary values.
47  *
48  * Note: Not all HBAAPI-defined values are contained in the definitions
49  *  below. Those not appropriate to an fc_host (e.g. FCP initiator) have
50  *  been removed.
51  */
52
53 /*
54  * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
55  * (for the ascii descriptions).
56  */
57 enum fc_port_type {
58         FC_PORTTYPE_UNKNOWN,
59         FC_PORTTYPE_OTHER,
60         FC_PORTTYPE_NOTPRESENT,
61         FC_PORTTYPE_NPORT,              /* Attached to FPort */
62         FC_PORTTYPE_NLPORT,             /* (Public) Loop w/ FLPort */
63         FC_PORTTYPE_LPORT,              /* (Private) Loop w/o FLPort */
64         FC_PORTTYPE_PTP,                /* Point to Point w/ another NPort */
65 };
66
67 /*
68  * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
69  * (for the ascii descriptions).
70  */
71 enum fc_port_state {
72         FC_PORTSTATE_UNKNOWN,
73         FC_PORTSTATE_NOTPRESENT,
74         FC_PORTSTATE_ONLINE,
75         FC_PORTSTATE_OFFLINE,           /* User has taken Port Offline */
76         FC_PORTSTATE_BLOCKED,
77         FC_PORTSTATE_BYPASSED,
78         FC_PORTSTATE_DIAGNOSTICS,
79         FC_PORTSTATE_LINKDOWN,
80         FC_PORTSTATE_ERROR,
81         FC_PORTSTATE_LOOPBACK,
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
108 #define FC_PORTSPEED_4GBIT              4
109 #define FC_PORTSPEED_10GBIT             8
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  */
116 enum 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  */
142 struct 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)                         \
151 struct 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
182 struct 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;
204         struct list_head peers;
205         struct device dev;
206         struct work_struct dev_loss_work;
207         struct work_struct scan_work;
208 } __attribute__((aligned(sizeof(unsigned long))));
209
210 #define dev_to_rport(d)                         \
211         container_of(d, struct fc_rport, dev)
212 #define transport_class_to_rport(classdev)      \
213         dev_to_rport(classdev->dev)
214 #define rport_to_shost(r)                       \
215         dev_to_shost(r->dev.parent)
216
217 /*
218  * FC SCSI Target Attributes
219  *
220  * The SCSI Target is considered an extention of a remote port (as
221  * a remote port can be more than a SCSI Target). Within the scsi
222  * subsystem, we leave the Target as a separate entity. Doing so
223  * provides backward compatibility with prior FC transport api's,
224  * and lets remote ports be handled entirely within the FC transport
225  * and independently from the scsi subsystem. The drawback is that
226  * some data will be duplicated.
227  */
228
229 struct fc_starget_attrs {       /* aka fc_target_attrs */
230         /* Dynamic Attributes */
231         u64 node_name;
232         u64 port_name;
233         u32 port_id;
234 };
235
236 #define fc_starget_node_name(x) \
237         (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
238 #define fc_starget_port_name(x) \
239         (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
240 #define fc_starget_port_id(x) \
241         (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
242
243 #define starget_to_rport(s)                     \
244         scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
245
246
247 /*
248  * FC Local Port (Host) Statistics
249  */
250
251 /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
252 struct fc_host_statistics {
253         /* port statistics */
254         u64 seconds_since_last_reset;
255         u64 tx_frames;
256         u64 tx_words;
257         u64 rx_frames;
258         u64 rx_words;
259         u64 lip_count;
260         u64 nos_count;
261         u64 error_frames;
262         u64 dumped_frames;
263         u64 link_failure_count;
264         u64 loss_of_sync_count;
265         u64 loss_of_signal_count;
266         u64 prim_seq_protocol_err_count;
267         u64 invalid_tx_word_count;
268         u64 invalid_crc_count;
269         
270         /* fc4 statistics  (only FCP supported currently) */
271         u64 fcp_input_requests;
272         u64 fcp_output_requests;
273         u64 fcp_control_requests;
274         u64 fcp_input_megabytes;
275         u64 fcp_output_megabytes;
276 };
277
278
279 /*
280  * FC Local Port (Host) Attributes
281  *
282  * Attributes are based on HBAAPI V2.0 definitions.
283  * Note: OSDeviceName is determined by user-space library
284  *
285  * Fixed attributes are not expected to change. The driver is
286  * expected to set these values after successfully calling scsi_add_host().
287  * The transport fully manages all get functions w/o driver interaction.
288  *
289  * Dynamic attributes are expected to change. The driver participates
290  * in all get/set operations via functions provided by the driver.
291  *
292  * Private attributes are transport-managed values. They are fully
293  * managed by the transport w/o driver interaction.
294  */
295
296 #define FC_FC4_LIST_SIZE                32
297 #define FC_SYMBOLIC_NAME_SIZE           256
298 #define FC_VERSION_STRING_SIZE          64
299 #define FC_SERIAL_NUMBER_SIZE           80
300
301 struct fc_host_attrs {
302         /* Fixed Attributes */
303         u64 node_name;
304         u64 port_name;
305         u32 supported_classes;
306         u8  supported_fc4s[FC_FC4_LIST_SIZE];
307         char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
308         u32 supported_speeds;
309         u32 maxframe_size;
310         char serial_number[FC_SERIAL_NUMBER_SIZE];
311
312         /* Dynamic Attributes */
313         u32 port_id;
314         enum fc_port_type port_type;
315         enum fc_port_state port_state;
316         u8  active_fc4s[FC_FC4_LIST_SIZE];
317         u32 speed;
318         u64 fabric_name;
319
320         /* Private (Transport-managed) Attributes */
321         enum fc_tgtid_binding_type  tgtid_bind_type;
322
323         /* internal data */
324         struct list_head rports;
325         struct list_head rport_bindings;
326         u32 next_rport_number;
327         u32 next_target_id;
328 };
329
330 #define fc_host_node_name(x) \
331         (((struct fc_host_attrs *)(x)->shost_data)->node_name)
332 #define fc_host_port_name(x)    \
333         (((struct fc_host_attrs *)(x)->shost_data)->port_name)
334 #define fc_host_supported_classes(x)    \
335         (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
336 #define fc_host_supported_fc4s(x)       \
337         (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
338 #define fc_host_symbolic_name(x)        \
339         (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
340 #define fc_host_supported_speeds(x)     \
341         (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
342 #define fc_host_maxframe_size(x)        \
343         (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
344 #define fc_host_serial_number(x)        \
345         (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
346 #define fc_host_port_id(x)      \
347         (((struct fc_host_attrs *)(x)->shost_data)->port_id)
348 #define fc_host_port_type(x)    \
349         (((struct fc_host_attrs *)(x)->shost_data)->port_type)
350 #define fc_host_port_state(x)   \
351         (((struct fc_host_attrs *)(x)->shost_data)->port_state)
352 #define fc_host_active_fc4s(x)  \
353         (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
354 #define fc_host_speed(x)        \
355         (((struct fc_host_attrs *)(x)->shost_data)->speed)
356 #define fc_host_fabric_name(x)  \
357         (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
358 #define fc_host_tgtid_bind_type(x) \
359         (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
360 #define fc_host_rports(x) \
361         (((struct fc_host_attrs *)(x)->shost_data)->rports)
362 #define fc_host_rport_bindings(x) \
363         (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
364 #define fc_host_next_rport_number(x) \
365         (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
366 #define fc_host_next_target_id(x) \
367         (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
368
369
370 /* The functions by which the transport class and the driver communicate */
371 struct fc_function_template {
372         void    (*get_rport_dev_loss_tmo)(struct fc_rport *);
373         void    (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
374
375         void    (*get_starget_node_name)(struct scsi_target *);
376         void    (*get_starget_port_name)(struct scsi_target *);
377         void    (*get_starget_port_id)(struct scsi_target *);
378
379         void    (*get_host_port_id)(struct Scsi_Host *);
380         void    (*get_host_port_type)(struct Scsi_Host *);
381         void    (*get_host_port_state)(struct Scsi_Host *);
382         void    (*get_host_active_fc4s)(struct Scsi_Host *);
383         void    (*get_host_speed)(struct Scsi_Host *);
384         void    (*get_host_fabric_name)(struct Scsi_Host *);
385
386         struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
387         void    (*reset_fc_host_stats)(struct Scsi_Host *);
388
389         int     (*issue_fc_host_lip)(struct Scsi_Host *);
390
391         /* allocation lengths for host-specific data */
392         u32                             dd_fcrport_size;
393
394         /* 
395          * The driver sets these to tell the transport class it
396          * wants the attributes displayed in sysfs.  If the show_ flag
397          * is not set, the attribute will be private to the transport
398          * class 
399          */
400
401         /* remote port fixed attributes */
402         unsigned long   show_rport_maxframe_size:1;
403         unsigned long   show_rport_supported_classes:1;
404         unsigned long   show_rport_dev_loss_tmo:1;
405
406         /*
407          * target dynamic attributes
408          * These should all be "1" if the driver uses the remote port
409          * add/delete functions (so attributes reflect rport values).
410          */
411         unsigned long   show_starget_node_name:1;
412         unsigned long   show_starget_port_name:1;
413         unsigned long   show_starget_port_id:1;
414
415         /* host fixed attributes */
416         unsigned long   show_host_node_name:1;
417         unsigned long   show_host_port_name:1;
418         unsigned long   show_host_supported_classes:1;
419         unsigned long   show_host_supported_fc4s:1;
420         unsigned long   show_host_symbolic_name:1;
421         unsigned long   show_host_supported_speeds:1;
422         unsigned long   show_host_maxframe_size:1;
423         unsigned long   show_host_serial_number:1;
424         /* host dynamic attributes */
425         unsigned long   show_host_port_id:1;
426         unsigned long   show_host_port_type:1;
427         unsigned long   show_host_port_state:1;
428         unsigned long   show_host_active_fc4s:1;
429         unsigned long   show_host_speed:1;
430         unsigned long   show_host_fabric_name:1;
431 };
432
433
434 /**
435  * fc_remote_port_chkready - called to validate the remote port state
436  *   prior to initiating io to the port.
437  *
438  * Returns a scsi result code that can be returned by the LLDD.
439  *
440  * @rport:      remote port to be checked
441  **/
442 static inline int
443 fc_remote_port_chkready(struct fc_rport *rport)
444 {
445         int result;
446
447         switch (rport->port_state) {
448         case FC_PORTSTATE_ONLINE:
449                 result = 0;
450                 break;
451         case FC_PORTSTATE_BLOCKED:
452                 result = DID_BUS_BUSY << 16;
453                 break;
454         default:
455                 result = DID_NO_CONNECT << 16;
456                 break;
457         }
458         return result;
459 }
460
461
462 struct scsi_transport_template *fc_attach_transport(
463                         struct fc_function_template *);
464 void fc_release_transport(struct scsi_transport_template *);
465 void fc_remove_host(struct Scsi_Host *);
466 struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
467                         int channel, struct fc_rport_identifiers  *ids);
468 void fc_remote_port_delete(struct fc_rport  *rport);
469 void fc_remote_port_rolechg(struct fc_rport  *rport, u32 roles);
470 int scsi_is_fc_rport(const struct device *);
471
472 static inline u64 wwn_to_u64(u8 *wwn)
473 {
474         return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
475             (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
476             (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
477             (u64)wwn[6] <<  8 | (u64)wwn[7];
478 }
479
480 #endif /* SCSI_TRANSPORT_FC_H */