scsi_transport_fc.c 99.5 KB
Newer Older
1
/*
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *  FiberChannel transport specific attributes exported to sysfs.
 *
 *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  ========
 *
22
 *  Copyright (C) 2004-2007   James Smart, Emulex Corporation
Linus Torvalds's avatar
Linus Torvalds committed
23 24
 *    Rewrite for host, target, device, and remote port attributes,
 *    statistics, and service functions...
25
 *    Add vports, etc
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28 29 30 31 32 33
 *
 */
#include <linux/module.h>
#include <linux/init.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_transport.h>
#include <scsi/scsi_transport_fc.h>
34
#include <scsi/scsi_cmnd.h>
35 36 37
#include <linux/netlink.h>
#include <net/netlink.h>
#include <scsi/scsi_netlink_fc.h>
Linus Torvalds's avatar
Linus Torvalds committed
38
#include "scsi_priv.h"
39
#include "scsi_transport_fc_internal.h"
Linus Torvalds's avatar
Linus Torvalds committed
40

41
static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
42
static void fc_vport_sched_delete(struct work_struct *work);
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/*
 * This is a temporary carrier for creating a vport. It will eventually
 * be replaced  by a real message definition for sgio or netlink.
 *
 * fc_vport_identifiers: This set of data contains all elements
 * to uniquely identify and instantiate a FC virtual port.
 *
 * Notes:
 *   symbolic_name: The driver is to append the symbolic_name string data
 *      to the symbolic_node_name data that it generates by default.
 *      the resulting combination should then be registered with the switch.
 *      It is expected that things like Xen may stuff a VM title into
 *      this field.
 */
struct fc_vport_identifiers {
	u64 node_name;
	u64 port_name;
	u32 roles;
	bool disable;
	enum fc_port_type vport_type;	/* only FC_PORTTYPE_NPIV allowed */
	char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
};

static int fc_vport_create(struct Scsi_Host *shost, int channel,
	struct device *pdev, struct fc_vport_identifiers  *ids,
	struct fc_vport **vport);

Linus Torvalds's avatar
Linus Torvalds committed
71 72 73 74
/*
 * Redefine so that we can have same named attributes in the
 * sdev/starget/host objects.
 */
75 76
#define FC_DEVICE_ATTR(_prefix,_name,_mode,_show,_store)		\
struct device_attribute device_attr_##_prefix##_##_name = 	\
Linus Torvalds's avatar
Linus Torvalds committed
77 78 79 80 81 82 83 84
	__ATTR(_name,_mode,_show,_store)

#define fc_enum_name_search(title, table_type, table)			\
static const char *get_fc_##title##_name(enum table_type table_key)	\
{									\
	int i;								\
	char *name = NULL;						\
									\
85
	for (i = 0; i < ARRAY_SIZE(table); i++) {			\
Linus Torvalds's avatar
Linus Torvalds committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
		if (table[i].value == table_key) {			\
			name = table[i].name;				\
			break;						\
		}							\
	}								\
	return name;							\
}

#define fc_enum_name_match(title, table_type, table)			\
static int get_fc_##title##_match(const char *table_key,		\
		enum table_type *value)					\
{									\
	int i;								\
									\
100
	for (i = 0; i < ARRAY_SIZE(table); i++) {			\
Linus Torvalds's avatar
Linus Torvalds committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
		if (strncmp(table_key, table[i].name,			\
				table[i].matchlen) == 0) {		\
			*value = table[i].value;			\
			return 0; /* success */				\
		}							\
	}								\
	return 1; /* failure */						\
}


/* Convert fc_port_type values to ascii string name */
static struct {
	enum fc_port_type	value;
	char			*name;
} fc_port_type_names[] = {
	{ FC_PORTTYPE_UNKNOWN,		"Unknown" },
	{ FC_PORTTYPE_OTHER,		"Other" },
	{ FC_PORTTYPE_NOTPRESENT,	"Not Present" },
	{ FC_PORTTYPE_NPORT,	"NPort (fabric via point-to-point)" },
	{ FC_PORTTYPE_NLPORT,	"NLPort (fabric via loop)" },
	{ FC_PORTTYPE_LPORT,	"LPort (private loop)" },
	{ FC_PORTTYPE_PTP,	"Point-To-Point (direct nport connection" },
123
	{ FC_PORTTYPE_NPIV,		"NPIV VPORT" },
Linus Torvalds's avatar
Linus Torvalds committed
124 125 126 127
};
fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
#define FC_PORTTYPE_MAX_NAMELEN		50

128 129 130
/* Reuse fc_port_type enum function for vport_type */
#define get_fc_vport_type_name get_fc_port_type_name

Linus Torvalds's avatar
Linus Torvalds committed
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
/* Convert fc_host_event_code values to ascii string name */
static const struct {
	enum fc_host_event_code		value;
	char				*name;
} fc_host_event_code_names[] = {
	{ FCH_EVT_LIP,			"lip" },
	{ FCH_EVT_LINKUP,		"link_up" },
	{ FCH_EVT_LINKDOWN,		"link_down" },
	{ FCH_EVT_LIPRESET,		"lip_reset" },
	{ FCH_EVT_RSCN,			"rscn" },
	{ FCH_EVT_ADAPTER_CHANGE,	"adapter_chg" },
	{ FCH_EVT_PORT_UNKNOWN,		"port_unknown" },
	{ FCH_EVT_PORT_ONLINE,		"port_online" },
	{ FCH_EVT_PORT_OFFLINE,		"port_offline" },
	{ FCH_EVT_PORT_FABRIC,		"port_fabric" },
	{ FCH_EVT_LINK_UNKNOWN,		"link_unknown" },
	{ FCH_EVT_VENDOR_UNIQUE,	"vendor_unique" },
};
fc_enum_name_search(host_event_code, fc_host_event_code,
		fc_host_event_code_names)
#define FC_HOST_EVENT_CODE_MAX_NAMELEN	30


Linus Torvalds's avatar
Linus Torvalds committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
/* Convert fc_port_state values to ascii string name */
static struct {
	enum fc_port_state	value;
	char			*name;
} fc_port_state_names[] = {
	{ FC_PORTSTATE_UNKNOWN,		"Unknown" },
	{ FC_PORTSTATE_NOTPRESENT,	"Not Present" },
	{ FC_PORTSTATE_ONLINE,		"Online" },
	{ FC_PORTSTATE_OFFLINE,		"Offline" },
	{ FC_PORTSTATE_BLOCKED,		"Blocked" },
	{ FC_PORTSTATE_BYPASSED,	"Bypassed" },
	{ FC_PORTSTATE_DIAGNOSTICS,	"Diagnostics" },
	{ FC_PORTSTATE_LINKDOWN,	"Linkdown" },
	{ FC_PORTSTATE_ERROR,		"Error" },
	{ FC_PORTSTATE_LOOPBACK,	"Loopback" },
170
	{ FC_PORTSTATE_DELETED,		"Deleted" },
Linus Torvalds's avatar
Linus Torvalds committed
171 172 173 174 175
};
fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
#define FC_PORTSTATE_MAX_NAMELEN	20


176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
/* Convert fc_vport_state values to ascii string name */
static struct {
	enum fc_vport_state	value;
	char			*name;
} fc_vport_state_names[] = {
	{ FC_VPORT_UNKNOWN,		"Unknown" },
	{ FC_VPORT_ACTIVE,		"Active" },
	{ FC_VPORT_DISABLED,		"Disabled" },
	{ FC_VPORT_LINKDOWN,		"Linkdown" },
	{ FC_VPORT_INITIALIZING,	"Initializing" },
	{ FC_VPORT_NO_FABRIC_SUPP,	"No Fabric Support" },
	{ FC_VPORT_NO_FABRIC_RSCS,	"No Fabric Resources" },
	{ FC_VPORT_FABRIC_LOGOUT,	"Fabric Logout" },
	{ FC_VPORT_FABRIC_REJ_WWN,	"Fabric Rejected WWN" },
	{ FC_VPORT_FAILED,		"VPort Failed" },
};
fc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names)
#define FC_VPORTSTATE_MAX_NAMELEN	24

/* Reuse fc_vport_state enum function for vport_last_state */
#define get_fc_vport_last_state_name get_fc_vport_state_name


Linus Torvalds's avatar
Linus Torvalds committed
199
/* Convert fc_tgtid_binding_type values to ascii string name */
200
static const struct {
Linus Torvalds's avatar
Linus Torvalds committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	enum fc_tgtid_binding_type	value;
	char				*name;
	int				matchlen;
} fc_tgtid_binding_type_names[] = {
	{ FC_TGTID_BIND_NONE, "none", 4 },
	{ FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
	{ FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
	{ FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
};
fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
		fc_tgtid_binding_type_names)
fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
		fc_tgtid_binding_type_names)
#define FC_BINDTYPE_MAX_NAMELEN	30


#define fc_bitfield_name_search(title, table)			\
static ssize_t							\
get_fc_##title##_names(u32 table_key, char *buf)		\
{								\
	char *prefix = "";					\
	ssize_t len = 0;					\
	int i;							\
								\
225
	for (i = 0; i < ARRAY_SIZE(table); i++) {		\
Linus Torvalds's avatar
Linus Torvalds committed
226 227 228 229 230 231 232 233 234 235 236 237
		if (table[i].value & table_key) {		\
			len += sprintf(buf + len, "%s%s",	\
				prefix, table[i].name);		\
			prefix = ", ";				\
		}						\
	}							\
	len += sprintf(buf + len, "\n");			\
	return len;						\
}


/* Convert FC_COS bit values to ascii string name */
238
static const struct {
Linus Torvalds's avatar
Linus Torvalds committed
239 240 241 242 243 244 245 246 247 248 249 250 251
	u32 			value;
	char			*name;
} fc_cos_names[] = {
	{ FC_COS_CLASS1,	"Class 1" },
	{ FC_COS_CLASS2,	"Class 2" },
	{ FC_COS_CLASS3,	"Class 3" },
	{ FC_COS_CLASS4,	"Class 4" },
	{ FC_COS_CLASS6,	"Class 6" },
};
fc_bitfield_name_search(cos, fc_cos_names)


/* Convert FC_PORTSPEED bit values to ascii string name */
252
static const struct {
Linus Torvalds's avatar
Linus Torvalds committed
253 254 255 256 257 258 259
	u32 			value;
	char			*name;
} fc_port_speed_names[] = {
	{ FC_PORTSPEED_1GBIT,		"1 Gbit" },
	{ FC_PORTSPEED_2GBIT,		"2 Gbit" },
	{ FC_PORTSPEED_4GBIT,		"4 Gbit" },
	{ FC_PORTSPEED_10GBIT,		"10 Gbit" },
260 261
	{ FC_PORTSPEED_8GBIT,		"8 Gbit" },
	{ FC_PORTSPEED_16GBIT,		"16 Gbit" },
Linus Torvalds's avatar
Linus Torvalds committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	{ FC_PORTSPEED_NOT_NEGOTIATED,	"Not Negotiated" },
};
fc_bitfield_name_search(port_speed, fc_port_speed_names)


static int
show_fc_fc4s (char *buf, u8 *fc4_list)
{
	int i, len=0;

	for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
		len += sprintf(buf + len , "0x%02x ", *fc4_list);
	len += sprintf(buf + len, "\n");
	return len;
}


279
/* Convert FC_PORT_ROLE bit values to ascii string name */
280
static const struct {
Linus Torvalds's avatar
Linus Torvalds committed
281 282
	u32 			value;
	char			*name;
283 284 285 286
} fc_port_role_names[] = {
	{ FC_PORT_ROLE_FCP_TARGET,	"FCP Target" },
	{ FC_PORT_ROLE_FCP_INITIATOR,	"FCP Initiator" },
	{ FC_PORT_ROLE_IP_PORT,		"IP Port" },
Linus Torvalds's avatar
Linus Torvalds committed
287
};
288
fc_bitfield_name_search(port_roles, fc_port_role_names)
Linus Torvalds's avatar
Linus Torvalds committed
289 290 291 292 293 294 295 296 297 298 299 300 301

/*
 * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
 */
#define FC_WELLKNOWN_PORTID_MASK	0xfffff0
#define FC_WELLKNOWN_ROLE_MASK  	0x00000f
#define FC_FPORT_PORTID			0x00000e
#define FC_FABCTLR_PORTID		0x00000d
#define FC_DIRSRVR_PORTID		0x00000c
#define FC_TIMESRVR_PORTID		0x00000b
#define FC_MGMTSRVR_PORTID		0x00000a


302 303 304
static void fc_timeout_deleted_rport(struct work_struct *work);
static void fc_timeout_fail_rport_io(struct work_struct *work);
static void fc_scsi_scan_rport(struct work_struct *work);
Linus Torvalds's avatar
Linus Torvalds committed
305 306 307 308 309 310

/*
 * Attribute counts pre object type...
 * Increase these values if you add attributes
 */
#define FC_STARGET_NUM_ATTRS 	3
311
#define FC_RPORT_NUM_ATTRS	10
312 313
#define FC_VPORT_NUM_ATTRS	9
#define FC_HOST_NUM_ATTRS	21
Linus Torvalds's avatar
Linus Torvalds committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

struct fc_internal {
	struct scsi_transport_template t;
	struct fc_function_template *f;

	/*
	 * For attributes : each object has :
	 *   An array of the actual attributes structures
	 *   An array of null-terminated pointers to the attribute
	 *     structures - used for mid-layer interaction.
	 *
	 * The attribute containers for the starget and host are are
	 * part of the midlayer. As the remote port is specific to the
	 * fc transport, we must provide the attribute container.
	 */
329
	struct device_attribute private_starget_attrs[
Linus Torvalds's avatar
Linus Torvalds committed
330
							FC_STARGET_NUM_ATTRS];
331
	struct device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
Linus Torvalds's avatar
Linus Torvalds committed
332

333 334
	struct device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
	struct device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
Linus Torvalds's avatar
Linus Torvalds committed
335 336

	struct transport_container rport_attr_cont;
337 338
	struct device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
	struct device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
339 340

	struct transport_container vport_attr_cont;
341 342
	struct device_attribute private_vport_attrs[FC_VPORT_NUM_ATTRS];
	struct device_attribute *vport_attrs[FC_VPORT_NUM_ATTRS + 1];
Linus Torvalds's avatar
Linus Torvalds committed
343 344 345 346
};

#define to_fc_internal(tmpl)	container_of(tmpl, struct fc_internal, t)

347
static int fc_target_setup(struct transport_container *tc, struct device *dev,
348
			   struct device *cdev)
Linus Torvalds's avatar
Linus Torvalds committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
{
	struct scsi_target *starget = to_scsi_target(dev);
	struct fc_rport *rport = starget_to_rport(starget);

	/*
	 * if parent is remote port, use values from remote port.
	 * Otherwise, this host uses the fc_transport, but not the
	 * remote port interface. As such, initialize to known non-values.
	 */
	if (rport) {
		fc_starget_node_name(starget) = rport->node_name;
		fc_starget_port_name(starget) = rport->port_name;
		fc_starget_port_id(starget) = rport->port_id;
	} else {
		fc_starget_node_name(starget) = -1;
		fc_starget_port_name(starget) = -1;
		fc_starget_port_id(starget) = -1;
	}

	return 0;
}

static DECLARE_TRANSPORT_CLASS(fc_transport_class,
			       "fc_transport",
			       fc_target_setup,
			       NULL,
			       NULL);

377
static int fc_host_setup(struct transport_container *tc, struct device *dev,
378
			 struct device *cdev)
Linus Torvalds's avatar
Linus Torvalds committed
379 380
{
	struct Scsi_Host *shost = dev_to_shost(dev);
381
	struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
Linus Torvalds's avatar
Linus Torvalds committed
382

383
	/*
Linus Torvalds's avatar
Linus Torvalds committed
384 385 386 387
	 * Set default values easily detected by the midlayer as
	 * failure cases.  The scsi lldd is responsible for initializing
	 * all transport attributes to valid values per host.
	 */
388 389 390 391 392 393 394 395
	fc_host->node_name = -1;
	fc_host->port_name = -1;
	fc_host->permanent_port_name = -1;
	fc_host->supported_classes = FC_COS_UNSPECIFIED;
	memset(fc_host->supported_fc4s, 0,
		sizeof(fc_host->supported_fc4s));
	fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
	fc_host->maxframe_size = -1;
396
	fc_host->max_npiv_vports = 0;
397 398 399 400 401 402 403 404 405 406
	memset(fc_host->serial_number, 0,
		sizeof(fc_host->serial_number));

	fc_host->port_id = -1;
	fc_host->port_type = FC_PORTTYPE_UNKNOWN;
	fc_host->port_state = FC_PORTSTATE_UNKNOWN;
	memset(fc_host->active_fc4s, 0,
		sizeof(fc_host->active_fc4s));
	fc_host->speed = FC_PORTSPEED_UNKNOWN;
	fc_host->fabric_name = -1;
407 408
	memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
	memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
409 410 411 412 413

	fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;

	INIT_LIST_HEAD(&fc_host->rports);
	INIT_LIST_HEAD(&fc_host->rport_bindings);
414
	INIT_LIST_HEAD(&fc_host->vports);
415 416
	fc_host->next_rport_number = 0;
	fc_host->next_target_id = 0;
417 418
	fc_host->next_vport_number = 0;
	fc_host->npiv_vports_inuse = 0;
419

420 421
	snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name),
		 "fc_wq_%d", shost->host_no);
422 423 424 425 426
	fc_host->work_q = create_singlethread_workqueue(
					fc_host->work_q_name);
	if (!fc_host->work_q)
		return -ENOMEM;

427 428 429
	snprintf(fc_host->devloss_work_q_name,
		 sizeof(fc_host->devloss_work_q_name),
		 "fc_dl_%d", shost->host_no);
430 431 432 433 434 435 436 437
	fc_host->devloss_work_q = create_singlethread_workqueue(
					fc_host->devloss_work_q_name);
	if (!fc_host->devloss_work_q) {
		destroy_workqueue(fc_host->work_q);
		fc_host->work_q = NULL;
		return -ENOMEM;
	}

Linus Torvalds's avatar
Linus Torvalds committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	return 0;
}

static DECLARE_TRANSPORT_CLASS(fc_host_class,
			       "fc_host",
			       fc_host_setup,
			       NULL,
			       NULL);

/*
 * Setup and Remove actions for remote ports are handled
 * in the service functions below.
 */
static DECLARE_TRANSPORT_CLASS(fc_rport_class,
			       "fc_remote_ports",
			       NULL,
			       NULL,
			       NULL);

457 458 459 460 461 462 463 464 465 466
/*
 * Setup and Remove actions for virtual ports are handled
 * in the service functions below.
 */
static DECLARE_TRANSPORT_CLASS(fc_vport_class,
			       "fc_vports",
			       NULL,
			       NULL,
			       NULL);

Linus Torvalds's avatar
Linus Torvalds committed
467 468 469 470 471 472 473 474 475
/*
 * Module Parameters
 */

/*
 * dev_loss_tmo: the default number of seconds that the FC transport
 *   should insulate the loss of a remote port.
 *   The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
 */
476
static unsigned int fc_dev_loss_tmo = 60;		/* seconds */
Linus Torvalds's avatar
Linus Torvalds committed
477

478
module_param_named(dev_loss_tmo, fc_dev_loss_tmo, uint, S_IRUGO|S_IWUSR);
Linus Torvalds's avatar
Linus Torvalds committed
479 480 481 482 483 484
MODULE_PARM_DESC(dev_loss_tmo,
		 "Maximum number of seconds that the FC transport should"
		 " insulate the loss of a remote port. Once this value is"
		 " exceeded, the scsi target is removed. Value should be"
		 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");

485
/*
486
 * Netlink Infrastructure
487
 */
488 489 490 491 492 493 494

static atomic_t fc_event_seq;

/**
 * fc_get_event_number - Obtain the next sequential FC event number
 *
 * Notes:
495
 *   We could have inlined this, but it would have required fc_event_seq to
496 497
 *   be exposed. For now, live with the subroutine call.
 *   Atomic used to avoid lock/unlock...
498
 */
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
u32
fc_get_event_number(void)
{
	return atomic_add_return(1, &fc_event_seq);
}
EXPORT_SYMBOL(fc_get_event_number);


/**
 * fc_host_post_event - called to post an even on an fc_host.
 * @shost:		host the event occurred on
 * @event_number:	fc event number obtained from get_fc_event_number()
 * @event_code:		fc_host event being posted
 * @event_data:		32bits of data for the event being posted
 *
 * Notes:
 *	This routine assumes no locks are held on entry.
516
 */
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
void
fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
		enum fc_host_event_code event_code, u32 event_data)
{
	struct sk_buff *skb;
	struct nlmsghdr	*nlh;
	struct fc_nl_event *event;
	const char *name;
	u32 len, skblen;
	int err;

	if (!scsi_nl_sock) {
		err = -ENOENT;
		goto send_fail;
	}

	len = FC_NL_MSGALIGN(sizeof(*event));
	skblen = NLMSG_SPACE(len);

	skb = alloc_skb(skblen, GFP_KERNEL);
	if (!skb) {
		err = -ENOBUFS;
		goto send_fail;
	}

	nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
				skblen - sizeof(*nlh), 0);
	if (!nlh) {
		err = -ENOBUFS;
		goto send_fail_skb;
	}
	event = NLMSG_DATA(nlh);

	INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
				FC_NL_ASYNC_EVENT, len);
	event->seconds = get_seconds();
	event->vendor_id = 0;
	event->host_no = shost->host_no;
	event->event_datalen = sizeof(u32);	/* bytes */
	event->event_num = event_number;
	event->event_code = event_code;
	event->event_data = event_data;

560 561
	err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
			      GFP_KERNEL);
562 563 564 565 566 567 568 569 570 571 572 573
	if (err && (err != -ESRCH))	/* filter no recipient errors */
		/* nlmsg_multicast already kfree_skb'd */
		goto send_fail;

	return;

send_fail_skb:
	kfree_skb(skb);
send_fail:
	name = get_fc_host_event_code_name(event_code);
	printk(KERN_WARNING
		"%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
574
		__func__, shost->host_no,
575 576 577 578 579 580 581
		(name) ? name : "<unknown>", event_data, err);
	return;
}
EXPORT_SYMBOL(fc_host_post_event);


/**
582
 * fc_host_post_vendor_event - called to post a vendor unique event on an fc_host
583 584 585 586
 * @shost:		host the event occurred on
 * @event_number:	fc event number obtained from get_fc_event_number()
 * @data_len:		amount, in bytes, of vendor unique data
 * @data_buf:		pointer to vendor unique data
587
 * @vendor_id:          Vendor id
588 589 590
 *
 * Notes:
 *	This routine assumes no locks are held on entry.
591
 */
592 593
void
fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
594
		u32 data_len, char * data_buf, u64 vendor_id)
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
{
	struct sk_buff *skb;
	struct nlmsghdr	*nlh;
	struct fc_nl_event *event;
	u32 len, skblen;
	int err;

	if (!scsi_nl_sock) {
		err = -ENOENT;
		goto send_vendor_fail;
	}

	len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
	skblen = NLMSG_SPACE(len);

	skb = alloc_skb(skblen, GFP_KERNEL);
	if (!skb) {
		err = -ENOBUFS;
		goto send_vendor_fail;
	}

	nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
				skblen - sizeof(*nlh), 0);
	if (!nlh) {
		err = -ENOBUFS;
		goto send_vendor_fail_skb;
	}
	event = NLMSG_DATA(nlh);

	INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
				FC_NL_ASYNC_EVENT, len);
	event->seconds = get_seconds();
	event->vendor_id = vendor_id;
	event->host_no = shost->host_no;
	event->event_datalen = data_len;	/* bytes */
	event->event_num = event_number;
	event->event_code = FCH_EVT_VENDOR_UNIQUE;
	memcpy(&event->event_data, data_buf, data_len);

634 635
	err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
			      GFP_KERNEL);
636 637 638 639 640 641 642 643 644 645 646
	if (err && (err != -ESRCH))	/* filter no recipient errors */
		/* nlmsg_multicast already kfree_skb'd */
		goto send_vendor_fail;

	return;

send_vendor_fail_skb:
	kfree_skb(skb);
send_vendor_fail:
	printk(KERN_WARNING
		"%s: Dropped Event : host %d vendor_unique - err %d\n",
647
		__func__, shost->host_no, err);
648 649 650 651 652
	return;
}
EXPORT_SYMBOL(fc_host_post_vendor_event);


Linus Torvalds's avatar
Linus Torvalds committed
653 654 655

static __init int fc_transport_init(void)
{
656 657 658 659 660
	int error;

	atomic_set(&fc_event_seq, 0);

	error = transport_class_register(&fc_host_class);
661 662 663
	if (error)
		return error;
	error = transport_class_register(&fc_vport_class);
Linus Torvalds's avatar
Linus Torvalds committed
664 665 666 667 668 669 670 671 672 673 674 675 676
	if (error)
		return error;
	error = transport_class_register(&fc_rport_class);
	if (error)
		return error;
	return transport_class_register(&fc_transport_class);
}

static void __exit fc_transport_exit(void)
{
	transport_class_unregister(&fc_transport_class);
	transport_class_unregister(&fc_rport_class);
	transport_class_unregister(&fc_host_class);
677
	transport_class_unregister(&fc_vport_class);
Linus Torvalds's avatar
Linus Torvalds committed
678 679 680 681 682 683 684 685
}

/*
 * FC Remote Port Attribute Management
 */

#define fc_rport_show_function(field, format_string, sz, cast)		\
static ssize_t								\
686 687
show_fc_rport_##field (struct device *dev, 				\
		       struct device_attribute *attr, char *buf)	\
Linus Torvalds's avatar
Linus Torvalds committed
688
{									\
689
	struct fc_rport *rport = transport_class_to_rport(dev);		\
Linus Torvalds's avatar
Linus Torvalds committed
690 691
	struct Scsi_Host *shost = rport_to_shost(rport);		\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
692 693
	if ((i->f->get_rport_##field) &&				\
	    !((rport->port_state == FC_PORTSTATE_BLOCKED) ||		\
694
	      (rport->port_state == FC_PORTSTATE_DELETED) ||		\
695
	      (rport->port_state == FC_PORTSTATE_NOTPRESENT)))		\
Linus Torvalds's avatar
Linus Torvalds committed
696 697 698 699 700 701
		i->f->get_rport_##field(rport);				\
	return snprintf(buf, sz, format_string, cast rport->field); 	\
}

#define fc_rport_store_function(field)					\
static ssize_t								\
702 703 704
store_fc_rport_##field(struct device *dev,				\
		       struct device_attribute *attr,			\
		       const char *buf,	size_t count)			\
Linus Torvalds's avatar
Linus Torvalds committed
705 706
{									\
	int val;							\
707
	struct fc_rport *rport = transport_class_to_rport(dev);		\
Linus Torvalds's avatar
Linus Torvalds committed
708 709
	struct Scsi_Host *shost = rport_to_shost(rport);		\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
710
	char *cp;							\
711
	if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||		\
712
	    (rport->port_state == FC_PORTSTATE_DELETED) ||		\
713 714
	    (rport->port_state == FC_PORTSTATE_NOTPRESENT))		\
		return -EBUSY;						\
715 716 717
	val = simple_strtoul(buf, &cp, 0);				\
	if (*cp && (*cp != '\n'))					\
		return -EINVAL;						\
Linus Torvalds's avatar
Linus Torvalds committed
718 719 720 721 722 723
	i->f->set_rport_##field(rport, val);				\
	return count;							\
}

#define fc_rport_rd_attr(field, format_string, sz)			\
	fc_rport_show_function(field, format_string, sz, )		\
724
static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
725 726 727 728
			 show_fc_rport_##field, NULL)

#define fc_rport_rd_attr_cast(field, format_string, sz, cast)		\
	fc_rport_show_function(field, format_string, sz, (cast))	\
729
static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
730 731 732 733 734
			  show_fc_rport_##field, NULL)

#define fc_rport_rw_attr(field, format_string, sz)			\
	fc_rport_show_function(field, format_string, sz, )		\
	fc_rport_store_function(field)					\
735
static FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR,		\
Linus Torvalds's avatar
Linus Torvalds committed
736 737 738 739 740 741
			show_fc_rport_##field,				\
			store_fc_rport_##field)


#define fc_private_rport_show_function(field, format_string, sz, cast)	\
static ssize_t								\
742 743
show_fc_rport_##field (struct device *dev, 				\
		       struct device_attribute *attr, char *buf)	\
Linus Torvalds's avatar
Linus Torvalds committed
744
{									\
745
	struct fc_rport *rport = transport_class_to_rport(dev);		\
Linus Torvalds's avatar
Linus Torvalds committed
746 747 748 749 750
	return snprintf(buf, sz, format_string, cast rport->field); 	\
}

#define fc_private_rport_rd_attr(field, format_string, sz)		\
	fc_private_rport_show_function(field, format_string, sz, )	\
751
static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
752 753 754 755
			 show_fc_rport_##field, NULL)

#define fc_private_rport_rd_attr_cast(field, format_string, sz, cast)	\
	fc_private_rport_show_function(field, format_string, sz, (cast)) \
756
static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
757 758 759 760 761
			  show_fc_rport_##field, NULL)


#define fc_private_rport_rd_enum_attr(title, maxlen)			\
static ssize_t								\
762 763
show_fc_rport_##title (struct device *dev,				\
		       struct device_attribute *attr, char *buf)	\
Linus Torvalds's avatar
Linus Torvalds committed
764
{									\
765
	struct fc_rport *rport = transport_class_to_rport(dev);		\
Linus Torvalds's avatar
Linus Torvalds committed
766 767 768 769 770 771
	const char *name;						\
	name = get_fc_##title##_name(rport->title);			\
	if (!name)							\
		return -EINVAL;						\
	return snprintf(buf, maxlen, "%s\n", name);			\
}									\
772
static FC_DEVICE_ATTR(rport, title, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
773 774 775 776
			show_fc_rport_##title, NULL)


#define SETUP_RPORT_ATTRIBUTE_RD(field)					\
777
	i->private_rport_attrs[count] = device_attr_rport_##field; \
Linus Torvalds's avatar
Linus Torvalds committed
778 779 780 781 782 783 784
	i->private_rport_attrs[count].attr.mode = S_IRUGO;		\
	i->private_rport_attrs[count].store = NULL;			\
	i->rport_attrs[count] = &i->private_rport_attrs[count];		\
	if (i->f->show_rport_##field)					\
		count++

#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field)				\
785
	i->private_rport_attrs[count] = device_attr_rport_##field; \
Linus Torvalds's avatar
Linus Torvalds committed
786 787 788 789 790 791
	i->private_rport_attrs[count].attr.mode = S_IRUGO;		\
	i->private_rport_attrs[count].store = NULL;			\
	i->rport_attrs[count] = &i->private_rport_attrs[count];		\
	count++

#define SETUP_RPORT_ATTRIBUTE_RW(field)					\
792
	i->private_rport_attrs[count] = device_attr_rport_##field; \
Linus Torvalds's avatar
Linus Torvalds committed
793 794 795 796 797 798 799 800
	if (!i->f->set_rport_##field) {					\
		i->private_rport_attrs[count].attr.mode = S_IRUGO;	\
		i->private_rport_attrs[count].store = NULL;		\
	}								\
	i->rport_attrs[count] = &i->private_rport_attrs[count];		\
	if (i->f->show_rport_##field)					\
		count++

801 802
#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(field)				\
{									\
803
	i->private_rport_attrs[count] = device_attr_rport_##field; \
804 805 806 807
	i->rport_attrs[count] = &i->private_rport_attrs[count];		\
	count++;							\
}

Linus Torvalds's avatar
Linus Torvalds committed
808 809 810 811 812 813 814 815

/* The FC Transport Remote Port Attributes: */

/* Fixed Remote Port Attributes */

fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);

static ssize_t
816 817
show_fc_rport_supported_classes (struct device *dev,
				 struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
818
{
819
	struct fc_rport *rport = transport_class_to_rport(dev);
Linus Torvalds's avatar
Linus Torvalds committed
820 821 822 823
	if (rport->supported_classes == FC_COS_UNSPECIFIED)
		return snprintf(buf, 20, "unspecified\n");
	return get_fc_cos_names(rport->supported_classes, buf);
}
824
static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
825 826 827 828
		show_fc_rport_supported_classes, NULL);

/* Dynamic Remote Port Attributes */

829 830 831 832 833
/*
 * dev_loss_tmo attribute
 */
fc_rport_show_function(dev_loss_tmo, "%d\n", 20, )
static ssize_t
834 835
store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
			    const char *buf, size_t count)
836 837
{
	int val;
838
	struct fc_rport *rport = transport_class_to_rport(dev);
839 840
	struct Scsi_Host *shost = rport_to_shost(rport);
	struct fc_internal *i = to_fc_internal(shost->transportt);
841
	char *cp;
842
	if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
843
	    (rport->port_state == FC_PORTSTATE_DELETED) ||
844 845
	    (rport->port_state == FC_PORTSTATE_NOTPRESENT))
		return -EBUSY;
846 847 848
	val = simple_strtoul(buf, &cp, 0);
	if ((*cp && (*cp != '\n')) ||
	    (val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
849 850 851 852
		return -EINVAL;
	i->f->set_rport_dev_loss_tmo(rport, val);
	return count;
}
853
static FC_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
854
		show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
Linus Torvalds's avatar
Linus Torvalds committed
855 856 857 858 859 860 861 862 863


/* Private Remote Port Attributes */

fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);

static ssize_t
864 865
show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
		     char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
866
{
867
	struct fc_rport *rport = transport_class_to_rport(dev);
Linus Torvalds's avatar
Linus Torvalds committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887

	/* identify any roles that are port_id specific */
	if ((rport->port_id != -1) &&
	    (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
					FC_WELLKNOWN_PORTID_MASK) {
		switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
		case FC_FPORT_PORTID:
			return snprintf(buf, 30, "Fabric Port\n");
		case FC_FABCTLR_PORTID:
			return snprintf(buf, 30, "Fabric Controller\n");
		case FC_DIRSRVR_PORTID:
			return snprintf(buf, 30, "Directory Server\n");
		case FC_TIMESRVR_PORTID:
			return snprintf(buf, 30, "Time Server\n");
		case FC_MGMTSRVR_PORTID:
			return snprintf(buf, 30, "Management Server\n");
		default:
			return snprintf(buf, 30, "Unknown Fabric Entity\n");
		}
	} else {
888
		if (rport->roles == FC_PORT_ROLE_UNKNOWN)
Linus Torvalds's avatar
Linus Torvalds committed
889
			return snprintf(buf, 20, "unknown\n");
890
		return get_fc_port_roles_names(rport->roles, buf);
Linus Torvalds's avatar
Linus Torvalds committed
891 892
	}
}
893
static FC_DEVICE_ATTR(rport, roles, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
894 895 896 897 898
		show_fc_rport_roles, NULL);

fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);

899 900 901 902
/*
 * fast_io_fail_tmo attribute
 */
static ssize_t
903 904
show_fc_rport_fast_io_fail_tmo (struct device *dev,
				struct device_attribute *attr, char *buf)
905
{
906
	struct fc_rport *rport = transport_class_to_rport(dev);
907 908 909 910 911 912 913

	if (rport->fast_io_fail_tmo == -1)
		return snprintf(buf, 5, "off\n");
	return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo);
}

static ssize_t
914 915 916
store_fc_rport_fast_io_fail_tmo(struct device *dev,
				struct device_attribute *attr, const char *buf,
				size_t count)
917 918 919
{
	int val;
	char *cp;
920
	struct fc_rport *rport = transport_class_to_rport(dev);
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936

	if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
	    (rport->port_state == FC_PORTSTATE_DELETED) ||
	    (rport->port_state == FC_PORTSTATE_NOTPRESENT))
		return -EBUSY;
	if (strncmp(buf, "off", 3) == 0)
		rport->fast_io_fail_tmo = -1;
	else {
		val = simple_strtoul(buf, &cp, 0);
		if ((*cp && (*cp != '\n')) ||
		    (val < 0) || (val >= rport->dev_loss_tmo))
			return -EINVAL;
		rport->fast_io_fail_tmo = val;
	}
	return count;
}
937
static FC_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR,
938
	show_fc_rport_fast_io_fail_tmo, store_fc_rport_fast_io_fail_tmo);
Linus Torvalds's avatar
Linus Torvalds committed
939 940 941 942 943 944 945 946


/*
 * FC SCSI Target Attribute Management
 */

/*
 * Note: in the target show function we recognize when the remote
947
 *  port is in the heirarchy and do not allow the driver to get
Linus Torvalds's avatar
Linus Torvalds committed
948 949 950 951 952
 *  involved in sysfs functions. The driver only gets involved if
 *  it's the "old" style that doesn't use rports.
 */
#define fc_starget_show_function(field, format_string, sz, cast)	\
static ssize_t								\
953 954
show_fc_starget_##field (struct device *dev, 				\
			 struct device_attribute *attr, char *buf)	\
Linus Torvalds's avatar
Linus Torvalds committed
955
{									\
956
	struct scsi_target *starget = transport_class_to_starget(dev);	\
Linus Torvalds's avatar
Linus Torvalds committed
957 958 959 960 961 962 963 964 965 966 967 968 969
	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);	\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	struct fc_rport *rport = starget_to_rport(starget);		\
	if (rport)							\
		fc_starget_##field(starget) = rport->field;		\
	else if (i->f->get_starget_##field)				\
		i->f->get_starget_##field(starget);			\
	return snprintf(buf, sz, format_string, 			\
		cast fc_starget_##field(starget)); 			\
}

#define fc_starget_rd_attr(field, format_string, sz)			\
	fc_starget_show_function(field, format_string, sz, )		\
970
static FC_DEVICE_ATTR(starget, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
971 972 973 974
			 show_fc_starget_##field, NULL)

#define fc_starget_rd_attr_cast(field, format_string, sz, cast)		\
	fc_starget_show_function(field, format_string, sz, (cast))	\
975
static FC_DEVICE_ATTR(starget, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
976 977 978
			  show_fc_starget_##field, NULL)

#define SETUP_STARGET_ATTRIBUTE_RD(field)				\
979
	i->private_starget_attrs[count] = device_attr_starget_##field; \
Linus Torvalds's avatar
Linus Torvalds committed
980 981 982 983 984 985 986
	i->private_starget_attrs[count].attr.mode = S_IRUGO;		\
	i->private_starget_attrs[count].store = NULL;			\
	i->starget_attrs[count] = &i->private_starget_attrs[count];	\
	if (i->f->show_starget_##field)					\
		count++

#define SETUP_STARGET_ATTRIBUTE_RW(field)				\
987
	i->private_starget_attrs[count] = device_attr_starget_##field; \
Linus Torvalds's avatar
Linus Torvalds committed
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
	if (!i->f->set_starget_##field) {				\
		i->private_starget_attrs[count].attr.mode = S_IRUGO;	\
		i->private_starget_attrs[count].store = NULL;		\
	}								\
	i->starget_attrs[count] = &i->private_starget_attrs[count];	\
	if (i->f->show_starget_##field)					\
		count++

/* The FC Transport SCSI Target Attributes: */
fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
fc_starget_rd_attr(port_id, "0x%06x\n", 20);


1002 1003 1004 1005 1006 1007
/*
 * FC Virtual Port Attribute Management
 */

#define fc_vport_show_function(field, format_string, sz, cast)		\
static ssize_t								\
1008 1009
show_fc_vport_##field (struct device *dev, 				\
		       struct device_attribute *attr, char *buf)	\
1010
{									\
1011
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
	struct Scsi_Host *shost = vport_to_shost(vport);		\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	if ((i->f->get_vport_##field) &&				\
	    !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)))	\
		i->f->get_vport_##field(vport);				\
	return snprintf(buf, sz, format_string, cast vport->field); 	\
}

#define fc_vport_store_function(field)					\
static ssize_t								\
1022 1023 1024
store_fc_vport_##field(struct device *dev,				\
		       struct device_attribute *attr,			\
		       const char *buf,	size_t count)			\
1025 1026
{									\
	int val;							\
1027
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
	struct Scsi_Host *shost = vport_to_shost(vport);		\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	char *cp;							\
	if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))	\
		return -EBUSY;						\
	val = simple_strtoul(buf, &cp, 0);				\
	if (*cp && (*cp != '\n'))					\
		return -EINVAL;						\
	i->f->set_vport_##field(vport, val);				\
	return count;							\
}

#define fc_vport_store_str_function(field, slen)			\
static ssize_t								\
1042 1043 1044
store_fc_vport_##field(struct device *dev,				\
		       struct device_attribute *attr, 			\
		       const char *buf,	size_t count)			\
1045
{									\
1046
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	struct Scsi_Host *shost = vport_to_shost(vport);		\
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	unsigned int cnt=count;						\
									\
	/* count may include a LF at end of string */			\
	if (buf[cnt-1] == '\n')						\
		cnt--;							\
	if (cnt > ((slen) - 1))						\
		return -EINVAL;						\
	memcpy(vport->field, buf, cnt);					\
	i->f->set_vport_##field(vport);					\
	return count;							\
}

#define fc_vport_rd_attr(field, format_string, sz)			\
	fc_vport_show_function(field, format_string, sz, )		\
1063
static FC_DEVICE_ATTR(vport, field, S_IRUGO,			\
1064 1065 1066 1067
			 show_fc_vport_##field, NULL)

#define fc_vport_rd_attr_cast(field, format_string, sz, cast)		\
	fc_vport_show_function(field, format_string, sz, (cast))	\
1068
static FC_DEVICE_ATTR(vport, field, S_IRUGO,			\
1069 1070 1071 1072 1073
			  show_fc_vport_##field, NULL)

#define fc_vport_rw_attr(field, format_string, sz)			\
	fc_vport_show_function(field, format_string, sz, )		\
	fc_vport_store_function(field)					\
1074
static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR,		\
1075 1076 1077 1078 1079
			show_fc_vport_##field,				\
			store_fc_vport_##field)

#define fc_private_vport_show_function(field, format_string, sz, cast)	\
static ssize_t								\
1080 1081
show_fc_vport_##field (struct device *dev,				\
		       struct device_attribute *attr, char *buf)	\
1082
{									\
1083
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1084 1085 1086 1087 1088
	return snprintf(buf, sz, format_string, cast vport->field); 	\
}

#define fc_private_vport_store_u32_function(field)			\
static ssize_t								\
1089 1090 1091
store_fc_vport_##field(struct device *dev,				\
		       struct device_attribute *attr,			\
		       const char *buf,	size_t count)			\
1092 1093
{									\
	u32 val;							\
1094
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
	char *cp;							\
	if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))		\
		return -EBUSY;						\
	val = simple_strtoul(buf, &cp, 0);				\
	if (*cp && (*cp != '\n'))					\
		return -EINVAL;						\
	vport->field = val;						\
	return count;							\
}


#define fc_private_vport_rd_attr(field, format_string, sz)		\
	fc_private_vport_show_function(field, format_string, sz, )	\
1108
static FC_DEVICE_ATTR(vport, field, S_IRUGO,			\
1109 1110 1111 1112
			 show_fc_vport_##field, NULL)

#define fc_private_vport_rd_attr_cast(field, format_string, sz, cast)	\
	fc_private_vport_show_function(field, format_string, sz, (cast)) \
1113
static FC_DEVICE_ATTR(vport, field, S_IRUGO,			\
1114 1115 1116 1117 1118
			  show_fc_vport_##field, NULL)

#define fc_private_vport_rw_u32_attr(field, format_string, sz)		\
	fc_private_vport_show_function(field, format_string, sz, )	\
	fc_private_vport_store_u32_function(field)			\
1119
static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR,		\
1120 1121 1122 1123 1124 1125
			show_fc_vport_##field,				\
			store_fc_vport_##field)


#define fc_private_vport_rd_enum_attr(title, maxlen)			\
static ssize_t								\
1126 1127 1128
show_fc_vport_##title (struct device *dev,				\
		       struct device_attribute *attr,			\
		       char *buf)					\
1129
{									\
1130
	struct fc_vport *vport = transport_class_to_vport(dev);		\
1131 1132 1133 1134 1135 1136
	const char *name;						\
	name = get_fc_##title##_name(vport->title);			\
	if (!name)							\
		return -EINVAL;						\
	return snprintf(buf, maxlen, "%s\n", name);			\
}									\
1137
static FC_DEVICE_ATTR(vport, title, S_IRUGO,			\
1138 1139 1140 1141
			show_fc_vport_##title, NULL)


#define SETUP_VPORT_ATTRIBUTE_RD(field)					\
1142
	i->private_vport_attrs[count] = device_attr_vport_##field; \
1143 1144 1145 1146 1147 1148 1149 1150
	i->private_vport_attrs[count].attr.mode = S_IRUGO;		\
	i->private_vport_attrs[count].store = NULL;			\
	i->vport_attrs[count] = &i->private_vport_attrs[count];		\
	if (i->f->get_##field)						\
		count++
	/* NOTE: Above MACRO differs: checks function not show bit */

#define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field)				\
1151
	i->private_vport_attrs[count] = device_attr_vport_##field; \
1152 1153 1154 1155 1156 1157
	i->private_vport_attrs[count].attr.mode = S_IRUGO;		\
	i->private_vport_attrs[count].store = NULL;			\
	i->vport_attrs[count] = &i->private_vport_attrs[count];		\
	count++

#define SETUP_VPORT_ATTRIBUTE_WR(field)					\
1158
	i->private_vport_attrs[count] = device_attr_vport_##field; \
1159 1160 1161 1162 1163 1164
	i->vport_attrs[count] = &i->private_vport_attrs[count];		\
	if (i->f->field)						\
		count++
	/* NOTE: Above MACRO differs: checks function */

#define SETUP_VPORT_ATTRIBUTE_RW(field)					\
1165
	i->private_vport_attrs[count] = device_attr_vport_##field; \
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
	if (!i->f->set_vport_##field) {					\
		i->private_vport_attrs[count].attr.mode = S_IRUGO;	\
		i->private_vport_attrs[count].store = NULL;		\
	}								\
	i->vport_attrs[count] = &i->private_vport_attrs[count];		\
	count++
	/* NOTE: Above MACRO differs: does not check show bit */

#define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field)				\
{									\
1176
	i->private_vport_attrs[count] = device_attr_vport_##field; \
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
	i->vport_attrs[count] = &i->private_vport_attrs[count];		\
	count++;							\
}


/* The FC Transport Virtual Port Attributes: */

/* Fixed Virtual Port Attributes */

/* Dynamic Virtual Port Attributes */

/* Private Virtual Port Attributes */

fc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN);
fc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN);
fc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
fc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);

static ssize_t
1196 1197
show_fc_vport_roles (struct device *dev, struct device_attribute *attr,
		     char *buf)
1198
{
1199
	struct fc_vport *vport = transport_class_to_vport(dev);
1200 1201 1202 1203 1204

	if (vport->roles == FC_PORT_ROLE_UNKNOWN)
		return snprintf(buf, 20, "unknown\n");
	return get_fc_port_roles_names(vport->roles, buf);
}
1205
static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL);
1206 1207 1208 1209 1210 1211

fc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN);

fc_private_vport_show_function(symbolic_name, "%s\n",
		FC_VPORT_SYMBOLIC_NAMELEN + 1, )
fc_vport_store_str_function(symbolic_name, FC_VPORT_SYMBOLIC_NAMELEN)
1212
static FC_DEVICE_ATTR(vport, symbolic_name, S_IRUGO | S_IWUSR,
1213 1214 1215
		show_fc_vport_symbolic_name, store_fc_vport_symbolic_name);

static ssize_t
1216 1217
store_fc_vport_delete(struct device *dev, struct device_attribute *attr,
		      const char *buf, size_t count)
1218
{
1219
	struct fc_vport *vport = transport_class_to_vport(dev);
1220
	struct Scsi_Host *shost = vport_to_shost(vport);
1221

1222
	fc_queue_work(shost, &vport->vport_delete_work);
1223 1224
	return count;
}
1225
static FC_DEVICE_ATTR(vport, vport_delete, S_IWUSR,
1226 1227 1228 1229 1230 1231 1232 1233
			NULL, store_fc_vport_delete);


/*
 * Enable/Disable vport
 *  Write "1" to disable, write "0" to enable
 */
static ssize_t
1234 1235
store_fc_vport_disable(struct device *dev, struct device_attribute *attr,
		       const char *buf,
1236 1237
			   size_t count)
{
1238
	struct fc_vport *vport = transport_class_to_vport(dev);
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
	struct Scsi_Host *shost = vport_to_shost(vport);
	struct fc_internal *i = to_fc_internal(shost->transportt);
	int stat;

	if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))
		return -EBUSY;

	if (*buf == '0') {
		if (vport->vport_state != FC_VPORT_DISABLED)
			return -EALREADY;
	} else if (*buf == '1') {
		if (vport->vport_state == FC_VPORT_DISABLED)
			return -EALREADY;
	} else
		return -EINVAL;

	stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true));
	return stat ? stat : count;
}
1258
static FC_DEVICE_ATTR(vport, vport_disable, S_IWUSR,
1259 1260 1261
			NULL, store_fc_vport_disable);


Linus Torvalds's avatar
Linus Torvalds committed
1262 1263 1264 1265 1266 1267
/*
 * Host Attribute Management
 */

#define fc_host_show_function(field, format_string, sz, cast)		\
static ssize_t								\
1268 1269
show_fc_host_##field (struct device *dev,				\
		      struct device_attribute *attr, char *buf)		\
Linus Torvalds's avatar
Linus Torvalds committed
1270
{									\
1271
	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
Linus Torvalds's avatar
Linus Torvalds committed
1272 1273 1274 1275 1276 1277 1278 1279
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	if (i->f->get_host_##field)					\
		i->f->get_host_##field(shost);				\
	return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
}

#define fc_host_store_function(field)					\
static ssize_t								\
1280 1281 1282
store_fc_host_##field(struct device *dev, 				\
		      struct device_attribute *attr,			\
		      const char *buf,	size_t count)			\
Linus Torvalds's avatar
Linus Torvalds committed
1283 1284
{									\
	int val;							\
1285
	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
Linus Torvalds's avatar
Linus Torvalds committed
1286
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
1287
	char *cp;							\
Linus Torvalds's avatar
Linus Torvalds committed
1288
									\
1289 1290 1291
	val = simple_strtoul(buf, &cp, 0);				\
	if (*cp && (*cp != '\n'))					\
		return -EINVAL;						\
Linus Torvalds's avatar
Linus Torvalds committed
1292 1293 1294 1295
	i->f->set_host_##field(shost, val);				\
	return count;							\
}

1296 1297
#define fc_host_store_str_function(field, slen)				\
static ssize_t								\
1298 1299 1300
store_fc_host_##field(struct device *dev,				\
		      struct device_attribute *attr,			\
		      const char *buf, size_t count)			\
1301
{									\
1302
	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	unsigned int cnt=count;						\
									\
	/* count may include a LF at end of string */			\
	if (buf[cnt-1] == '\n')						\
		cnt--;							\
	if (cnt > ((slen) - 1))						\
		return -EINVAL;						\
	memcpy(fc_host_##field(shost), buf, cnt);			\
	i->f->set_host_##field(shost);					\
	return count;							\
}

Linus Torvalds's avatar
Linus Torvalds committed
1316 1317
#define fc_host_rd_attr(field, format_string, sz)			\
	fc_host_show_function(field, format_string, sz, )		\
1318
static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
1319 1320 1321 1322
			 show_fc_host_##field, NULL)

#define fc_host_rd_attr_cast(field, format_string, sz, cast)		\
	fc_host_show_function(field, format_string, sz, (cast))		\
1323
static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
1324 1325 1326 1327 1328
			  show_fc_host_##field, NULL)

#define fc_host_rw_attr(field, format_string, sz)			\
	fc_host_show_function(field, format_string, sz, )		\
	fc_host_store_function(field)					\
1329
static FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR,		\
Linus Torvalds's avatar
Linus Torvalds committed
1330 1331 1332 1333 1334
			show_fc_host_##field,				\
			store_fc_host_##field)

#define fc_host_rd_enum_attr(title, maxlen)				\
static ssize_t								\
1335 1336
show_fc_host_##title (struct device *dev,				\
		      struct device_attribute *attr, char *buf)		\
Linus Torvalds's avatar
Linus Torvalds committed
1337
{									\
1338
	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
Linus Torvalds's avatar
Linus Torvalds committed
1339 1340 1341 1342 1343 1344 1345 1346 1347
	struct fc_internal *i = to_fc_internal(shost->transportt);	\
	const char *name;						\
	if (i->f->get_host_##title)					\
		i->f->get_host_##title(shost);				\
	name = get_fc_##title##_name(fc_host_##title(shost));		\
	if (!name)							\
		return -EINVAL;						\
	return snprintf(buf, maxlen, "%s\n", name);			\
}									\
1348
static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
Linus Torvalds's avatar
Linus Torvalds committed
1349 1350

#define SETUP_HOST_ATTRIBUTE_RD(field)					\
1351
	i->private_host_attrs[count] = device_attr_host_##field;	\
Linus Torvalds's avatar
Linus Torvalds committed
1352 1353 1354 1355 1356 1357
	i->private_host_attrs[count].attr.mode = S_IRUGO;		\
	i->private_host_attrs[count].store = NULL;			\
	i->host_attrs[count] = &i->private_host_attrs[count];		\
	if (i->f->show_host_##field)					\
		count++

1358
#define SETUP_HOST_ATTRIBUTE_RD_NS(field)				\
1359
	i->private_host_attrs[count] = device_attr_host_##field;	\
1360 1361 1362 1363 1364
	i->private_host_attrs[count].attr.mode = S_IRUGO;		\
	i->private_host_attrs[count].store = NULL;			\
	i->host_attrs[count] = &i->private_host_attrs[count];		\
	count++

Linus Torvalds's avatar
Linus Torvalds committed
1365
#define SETUP_HOST_ATTRIBUTE_RW(field)					\
1366
	i->private_host_attrs[count] = device_attr_host_##field;	\
Linus Torvalds's avatar
Linus Torvalds committed
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
	if (!i->f->set_host_##field) {					\
		i->private_host_attrs[count].attr.mode = S_IRUGO;	\
		i->private_host_attrs[count].store = NULL;		\
	}								\
	i->host_attrs[count] = &i->private_host_attrs[count];		\
	if (i->f->show_host_##field)					\
		count++


#define fc_private_host_show_function(field, format_string, sz, cast)	\
static ssize_t								\
1378 1379
show_fc_host_##field (struct device *dev,				\
		      struct device_attribute *attr, char *buf)		\
Linus Torvalds's avatar
Linus Torvalds committed
1380
{									\
1381
	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
Linus Torvalds's avatar
Linus Torvalds committed
1382 1383 1384 1385 1386
	return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
}

#define fc_private_host_rd_attr(field, format_string, sz)		\
	fc_private_host_show_function(field, format_string, sz, )	\
1387
static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
1388 1389 1390 1391
			 show_fc_host_##field, NULL)

#define fc_private_host_rd_attr_cast(field, format_string, sz, cast)	\
	fc_private_host_show_function(field, format_string, sz, (cast)) \
1392
static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
Linus Torvalds's avatar
Linus Torvalds committed
1393 1394 1395
			  show_fc_host_##field, NULL)

#define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field)			\
1396
	i->private_host_attrs[count] = device_attr_host_##field;	\
Linus Torvalds's avatar
Linus Torvalds committed
1397 1398 1399 1400 1401 1402
	i->private_host_attrs[count].attr.mode = S_IRUGO;		\
	i->private_host_attrs[count].store = NULL;			\
	i->host_attrs[count] = &i->private_host_attrs[count];		\
	count++

#define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field)			\
1403
{									\
1404
	i->private_host_attrs[count] = device_attr_host_##field;	\
Linus Torvalds's avatar
Linus Torvalds committed
1405
	i->host_attrs[count] = &i->private_host_attrs[count];		\
1406 1407
	count++;							\
}
Linus Torvalds's avatar
Linus Torvalds committed
1408 1409 1410 1411 1412


/* Fixed Host Attributes */

static ssize_t
1413 1414
show_fc_host_supported_classes (struct device *dev,
			        struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
1415
{
1416
	struct Scsi_Host *shost = transport_class_to_shost(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1417 1418 1419 1420 1421 1422

	if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
		return snprintf(buf, 20, "unspecified\n");

	return get_fc_cos_names(fc_host_supported_classes(shost), buf);
}
1423
static FC_DEVICE_ATTR(host, supported_classes, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
1424 1425 1426
		show_fc_host_supported_classes, NULL);

static ssize_t
1427 1428
show_fc_host_supported_fc4s (struct device *dev,
			     struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
1429
{
1430
	struct Scsi_Host *shost = transport_class_to_shost(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1431 1432
	return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
}
1433
static FC_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
1434 1435 1436
		show_fc_host_supported_fc4s, NULL);

static ssize_t
1437 1438
show_fc_host_supported_speeds (struct device *dev,
			       struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
1439
{
1440
	struct Scsi_Host *shost = transport_class_to_shost(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1441 1442 1443 1444 1445 1446

	if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
		return snprintf(buf, 20, "unknown\n");

	return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
}
1447
static FC_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
1448 1449 1450 1451 1452
		show_fc_host_supported_speeds, NULL);


fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
1453 1454
fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
			     unsigned long long);
Linus Torvalds's avatar
Linus Torvalds committed
1455
fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
1456
fc_private_host_rd_attr(max_npiv_vports, "%u\n", 20);
Linus Torvalds's avatar
Linus Torvalds committed
1457 1458 1459 1460 1461 1462
fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));


/* Dynamic Host Attributes */

static ssize_t
1463 1464
show_fc_host_active_fc4s (struct device *dev,
			  struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
1465
{
1466
	struct Scsi_Host *shost = transport_class_to_shost(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1467 1468 1469 1470 1471 1472 1473
	struct fc_internal *i = to_fc_internal(shost->transportt);

	if (i->f->get_host_active_fc4s)
		i->f->get_host_active_fc4s(shost);

	return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
}
1474
static FC_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
1475 1476 1477
		show_fc_host_active_fc4s, NULL);

static ssize_t
1478 1479
show_fc_host_speed (struct device *dev,
		    struct device_attribute *attr, char *buf)
Linus Torvalds's avatar
Linus Torvalds committed
1480
{
1481
	struct Scsi_Host *shost = transport_class_to_shost(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
	struct fc_internal *i = to_fc_internal(shost->transportt);

	if (i->f->get_host_speed)
		i->f->get_host_speed(shost);

	if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
		return snprintf(buf, 20, "unknown\n");

	return get_fc_port_speed_names(fc_host_speed(shost), buf);
}
1492
static FC_DEVICE_ATTR(host, speed, S_IRUGO,
Linus Torvalds's avatar
Linus Torvalds committed
1493 1494 1495 1496 1497 1498 1499
		show_fc_host_speed, NULL);


fc_host_rd_attr(port_id, "0x%06x\n", 20);
fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
1500
fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
Linus Torvalds's avatar
Linus Torvalds committed
1501

1502 1503 1504
fc_private_host_show_function(system_hostname, "%s\n",
		FC_SYMBOLIC_NAME_SIZE + 1, )
fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
1505
static FC_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
1506 1507
		show_fc_host_system_hostname, store_fc_host_system_hostname);