bfad_attr.c 29.6 KB
Newer Older
1
/*
K
Krishna Gudipati 已提交
2
 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * All rights reserved
 * www.brocade.com
 *
 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (GPL) Version 2 as
 * published by the Free Software Foundation
 *
 * 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.
 */

J
Jing Huang 已提交
18
/*
19 20 21 22 23 24
 *  bfa_attr.c Linux driver configuration interface module.
 */

#include "bfad_drv.h"
#include "bfad_im.h"

J
Jing Huang 已提交
25
/*
26 27
 * FC transport template entry, get SCSI target port ID.
 */
28
static void
29 30 31 32 33 34 35 36 37
bfad_im_get_starget_port_id(struct scsi_target *starget)
{
	struct Scsi_Host *shost;
	struct bfad_im_port_s *im_port;
	struct bfad_s         *bfad;
	struct bfad_itnim_s   *itnim = NULL;
	u32        fc_id = -1;
	unsigned long   flags;

K
Krishna Gudipati 已提交
38
	shost = dev_to_shost(starget->dev.parent);
39 40 41 42
	im_port = (struct bfad_im_port_s *) shost->hostdata[0];
	bfad = im_port->bfad;
	spin_lock_irqsave(&bfad->bfad_lock, flags);

M
Maggie Zhang 已提交
43
	itnim = bfad_get_itnim(im_port, starget->id);
44 45 46 47 48 49 50
	if (itnim)
		fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);

	fc_starget_port_id(starget) = fc_id;
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
}

J
Jing Huang 已提交
51
/*
52 53
 * FC transport template entry, get SCSI target nwwn.
 */
54
static void
55 56 57 58 59 60 61 62 63
bfad_im_get_starget_node_name(struct scsi_target *starget)
{
	struct Scsi_Host *shost;
	struct bfad_im_port_s *im_port;
	struct bfad_s         *bfad;
	struct bfad_itnim_s   *itnim = NULL;
	u64             node_name = 0;
	unsigned long   flags;

K
Krishna Gudipati 已提交
64
	shost = dev_to_shost(starget->dev.parent);
65 66 67 68
	im_port = (struct bfad_im_port_s *) shost->hostdata[0];
	bfad = im_port->bfad;
	spin_lock_irqsave(&bfad->bfad_lock, flags);

M
Maggie Zhang 已提交
69
	itnim = bfad_get_itnim(im_port, starget->id);
70 71 72
	if (itnim)
		node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);

73
	fc_starget_node_name(starget) = cpu_to_be64(node_name);
74 75 76
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
}

J
Jing Huang 已提交
77
/*
78 79
 * FC transport template entry, get SCSI target pwwn.
 */
80
static void
81 82 83 84 85 86 87 88 89
bfad_im_get_starget_port_name(struct scsi_target *starget)
{
	struct Scsi_Host *shost;
	struct bfad_im_port_s *im_port;
	struct bfad_s         *bfad;
	struct bfad_itnim_s   *itnim = NULL;
	u64             port_name = 0;
	unsigned long   flags;

K
Krishna Gudipati 已提交
90
	shost = dev_to_shost(starget->dev.parent);
91 92 93 94
	im_port = (struct bfad_im_port_s *) shost->hostdata[0];
	bfad = im_port->bfad;
	spin_lock_irqsave(&bfad->bfad_lock, flags);

M
Maggie Zhang 已提交
95
	itnim = bfad_get_itnim(im_port, starget->id);
96 97 98
	if (itnim)
		port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);

99
	fc_starget_port_name(starget) = cpu_to_be64(port_name);
100 101 102
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
}

J
Jing Huang 已提交
103
/*
104 105
 * FC transport template entry, get SCSI host port ID.
 */
106
static void
107 108 109 110 111 112 113
bfad_im_get_host_port_id(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_port_s    *port = im_port->port;

	fc_host_port_id(shost) =
M
Maggie Zhang 已提交
114
			bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
115 116
}

J
Jing Huang 已提交
117
/*
118 119 120 121 122 123 124 125
 * FC transport template entry, get SCSI host port type.
 */
static void
bfad_im_get_host_port_type(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s         *bfad = im_port->bfad;
K
Krishna Gudipati 已提交
126
	struct bfa_lport_attr_s port_attr;
127

K
Krishna Gudipati 已提交
128
	bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
129

K
Krishna Gudipati 已提交
130 131
	switch (port_attr.port_type) {
	case BFA_PORT_TYPE_NPORT:
132 133
		fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
		break;
K
Krishna Gudipati 已提交
134
	case BFA_PORT_TYPE_NLPORT:
135 136
		fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
		break;
K
Krishna Gudipati 已提交
137
	case BFA_PORT_TYPE_P2P:
138 139
		fc_host_port_type(shost) = FC_PORTTYPE_PTP;
		break;
K
Krishna Gudipati 已提交
140
	case BFA_PORT_TYPE_LPORT:
141 142 143 144 145 146 147 148
		fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
		break;
	default:
		fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
		break;
	}
}

J
Jing Huang 已提交
149
/*
150 151 152 153 154 155 156 157
 * FC transport template entry, get SCSI host port state.
 */
static void
bfad_im_get_host_port_state(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s         *bfad = im_port->bfad;
K
Krishna Gudipati 已提交
158
	struct bfa_port_attr_s attr;
159

160
	bfa_fcport_get_attr(&bfad->bfa, &attr);
161 162

	switch (attr.port_state) {
K
Krishna Gudipati 已提交
163
	case BFA_PORT_ST_LINKDOWN:
164 165
		fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
		break;
K
Krishna Gudipati 已提交
166
	case BFA_PORT_ST_LINKUP:
167 168
		fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
		break;
K
Krishna Gudipati 已提交
169 170 171 172 173 174 175 176 177 178 179
	case BFA_PORT_ST_DISABLED:
	case BFA_PORT_ST_STOPPED:
	case BFA_PORT_ST_IOCDOWN:
	case BFA_PORT_ST_IOCDIS:
		fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
		break;
	case BFA_PORT_ST_UNINIT:
	case BFA_PORT_ST_ENABLING_QWAIT:
	case BFA_PORT_ST_ENABLING:
	case BFA_PORT_ST_DISABLING_QWAIT:
	case BFA_PORT_ST_DISABLING:
180 181 182 183 184 185
	default:
		fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
		break;
	}
}

J
Jing Huang 已提交
186
/*
187 188 189 190 191 192 193 194 195 196 197 198
 * FC transport template entry, get SCSI host active fc4s.
 */
static void
bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_port_s    *port = im_port->port;

	memset(fc_host_active_fc4s(shost), 0,
	       sizeof(fc_host_active_fc4s(shost)));

K
Krishna Gudipati 已提交
199
	if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
200 201 202 203 204
		fc_host_active_fc4s(shost)[2] = 1;

	fc_host_active_fc4s(shost)[7] = 1;
}

J
Jing Huang 已提交
205
/*
206 207 208 209 210 211 212 213
 * FC transport template entry, get SCSI host link speed.
 */
static void
bfad_im_get_host_speed(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s         *bfad = im_port->bfad;
K
Krishna Gudipati 已提交
214
	struct bfa_port_attr_s attr;
215

216
	bfa_fcport_get_attr(&bfad->bfa, &attr);
217
	switch (attr.speed) {
K
Krishna Gudipati 已提交
218 219 220
	case BFA_PORT_SPEED_10GBPS:
		fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
		break;
221 222 223
	case BFA_PORT_SPEED_16GBPS:
		fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
		break;
K
Krishna Gudipati 已提交
224
	case BFA_PORT_SPEED_8GBPS:
225 226
		fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
		break;
K
Krishna Gudipati 已提交
227
	case BFA_PORT_SPEED_4GBPS:
228 229
		fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
		break;
K
Krishna Gudipati 已提交
230
	case BFA_PORT_SPEED_2GBPS:
231 232
		fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
		break;
K
Krishna Gudipati 已提交
233
	case BFA_PORT_SPEED_1GBPS:
234 235 236 237 238 239 240 241
		fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
		break;
	default:
		fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
		break;
	}
}

J
Jing Huang 已提交
242
/*
243 244 245 246 247 248 249 250 251 252
 * FC transport template entry, get SCSI host port type.
 */
static void
bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_port_s    *port = im_port->port;
	wwn_t           fabric_nwwn = 0;

K
Krishna Gudipati 已提交
253
	fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
254

255
	fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
256 257 258

}

J
Jing Huang 已提交
259
/*
260 261 262 263 264 265 266 267 268
 * FC transport template entry, get BFAD statistics.
 */
static struct fc_host_statistics *
bfad_im_get_stats(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s         *bfad = im_port->bfad;
	struct bfad_hal_comp fcomp;
K
Krishna Gudipati 已提交
269
	union bfa_port_stats_u *fcstats;
270 271 272 273
	struct fc_host_statistics *hstats;
	bfa_status_t    rc;
	unsigned long   flags;

K
Krishna Gudipati 已提交
274 275 276 277
	fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
	if (fcstats == NULL)
		return NULL;

278 279 280 281
	hstats = &bfad->link_stats;
	init_completion(&fcomp.comp);
	spin_lock_irqsave(&bfad->bfad_lock, flags);
	memset(hstats, 0, sizeof(struct fc_host_statistics));
K
Krishna Gudipati 已提交
282 283
	rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
				fcstats, bfad_hcb_comp, &fcomp);
284 285 286 287 288 289
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
	if (rc != BFA_STATUS_OK)
		return NULL;

	wait_for_completion(&fcomp.comp);

K
Krishna Gudipati 已提交
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
	/* Fill the fc_host_statistics structure */
	hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
	hstats->tx_frames = fcstats->fc.tx_frames;
	hstats->tx_words  = fcstats->fc.tx_words;
	hstats->rx_frames = fcstats->fc.rx_frames;
	hstats->rx_words  = fcstats->fc.rx_words;
	hstats->lip_count = fcstats->fc.lip_count;
	hstats->nos_count = fcstats->fc.nos_count;
	hstats->error_frames = fcstats->fc.error_frames;
	hstats->dumped_frames = fcstats->fc.dropped_frames;
	hstats->link_failure_count = fcstats->fc.link_failures;
	hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
	hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
	hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
	hstats->invalid_crc_count = fcstats->fc.invalid_crcs;

	kfree(fcstats);
307 308 309
	return hstats;
}

J
Jing Huang 已提交
310
/*
311 312 313 314 315 316 317 318 319 320 321 322 323 324
 * FC transport template entry, reset BFAD statistics.
 */
static void
bfad_im_reset_stats(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s         *bfad = im_port->bfad;
	struct bfad_hal_comp fcomp;
	unsigned long   flags;
	bfa_status_t    rc;

	init_completion(&fcomp.comp);
	spin_lock_irqsave(&bfad->bfad_lock, flags);
325
	rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
K
Krishna Gudipati 已提交
326
					&fcomp);
327 328 329 330 331 332 333 334 335 336
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	if (rc != BFA_STATUS_OK)
		return;

	wait_for_completion(&fcomp.comp);

	return;
}

J
Jing Huang 已提交
337
/*
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
 * FC transport template entry, get rport loss timeout.
 */
static void
bfad_im_get_rport_loss_tmo(struct fc_rport *rport)
{
	struct bfad_itnim_data_s *itnim_data = rport->dd_data;
	struct bfad_itnim_s   *itnim = itnim_data->itnim;
	struct bfad_s         *bfad = itnim->im->bfad;
	unsigned long   flags;

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
}

J
Jing Huang 已提交
353
/*
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
 * FC transport template entry, set rport loss timeout.
 */
static void
bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
{
	struct bfad_itnim_data_s *itnim_data = rport->dd_data;
	struct bfad_itnim_s   *itnim = itnim_data->itnim;
	struct bfad_s         *bfad = itnim->im->bfad;
	unsigned long   flags;

	if (timeout > 0) {
		spin_lock_irqsave(&bfad->bfad_lock, flags);
		bfa_fcpim_path_tov_set(&bfad->bfa, timeout);
		rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
	}

}

373 374 375 376 377 378 379 380
static int
bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
{
	char *vname = fc_vport->symbolic_name;
	struct Scsi_Host *shost = fc_vport->shost;
	struct bfad_im_port_s *im_port =
		(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s *bfad = im_port->bfad;
K
Krishna Gudipati 已提交
381 382
	struct bfa_lport_cfg_s port_cfg;
	struct bfad_vport_s *vp;
383 384 385 386
	int status = 0, rc;
	unsigned long flags;

	memset(&port_cfg, 0, sizeof(port_cfg));
J
Jing Huang 已提交
387 388
	u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
	u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
389 390
	if (strlen(vname) > 0)
		strcpy((char *)&port_cfg.sym_name, vname);
K
Krishna Gudipati 已提交
391
	port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
392

J
Jing Huang 已提交
393
	spin_lock_irqsave(&bfad->bfad_lock, flags);
K
Krishna Gudipati 已提交
394 395 396 397 398
	list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
		if (port_cfg.pwwn ==
				vp->fcs_vport.lport.port_cfg.pwwn) {
			port_cfg.preboot_vp =
				vp->fcs_vport.lport.port_cfg.preboot_vp;
J
Jing Huang 已提交
399 400 401 402 403 404
			break;
		}
	}
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
405
	if (rc == BFA_STATUS_OK) {
J
Jing Huang 已提交
406
		struct bfad_vport_s *vport;
407 408 409 410 411 412
		struct bfa_fcs_vport_s *fcs_vport;
		struct Scsi_Host *vshost;

		spin_lock_irqsave(&bfad->bfad_lock, flags);
		fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
					port_cfg.pwwn);
J
Jing Huang 已提交
413 414
		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
		if (fcs_vport == NULL)
415 416 417 418
			return VPCERR_BAD_WWN;

		fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
		if (disable) {
J
Jing Huang 已提交
419
			spin_lock_irqsave(&bfad->bfad_lock, flags);
420
			bfa_fcs_vport_stop(fcs_vport);
J
Jing Huang 已提交
421
			spin_unlock_irqrestore(&bfad->bfad_lock, flags);
422 423 424 425 426
			fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
		}

		vport = fcs_vport->vport_drv;
		vshost = vport->drv_port.im_port->shost;
J
Jing Huang 已提交
427 428
		fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
		fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
		fc_host_supported_classes(vshost) = FC_COS_CLASS3;

		memset(fc_host_supported_fc4s(vshost), 0,
			sizeof(fc_host_supported_fc4s(vshost)));

		/* For FCP type 0x08 */
		if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
			fc_host_supported_fc4s(vshost)[2] = 1;

		/* For fibre channel services type 0x20 */
		fc_host_supported_fc4s(vshost)[7] = 1;

		fc_host_supported_speeds(vshost) =
				bfad_im_supported_speeds(&bfad->bfa);
		fc_host_maxframe_size(vshost) =
				bfa_fcport_get_maxfrsize(&bfad->bfa);

446 447 448 449 450 451 452 453 454 455
		fc_vport->dd_data = vport;
		vport->drv_port.im_port->fc_vport = fc_vport;
	} else if (rc == BFA_STATUS_INVALID_WWN)
		return VPCERR_BAD_WWN;
	else if (rc == BFA_STATUS_VPORT_EXISTS)
		return VPCERR_BAD_WWN;
	else if (rc == BFA_STATUS_VPORT_MAX)
		return VPCERR_NO_FABRIC_SUPP;
	else if (rc == BFA_STATUS_VPORT_WWN_BP)
		return VPCERR_BAD_WWN;
J
Jing Huang 已提交
456
	else
457 458 459 460 461
		return FC_VPORT_FAILED;

	return status;
}

462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
int
bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
{
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_s *bfad = im_port->bfad;
	struct bfad_hal_comp fcomp;
	unsigned long flags;
	uint32_t status;

	init_completion(&fcomp.comp);
	spin_lock_irqsave(&bfad->bfad_lock, flags);
	status = bfa_port_disable(&bfad->bfa.modules.port,
					bfad_hcb_comp, &fcomp);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	if (status != BFA_STATUS_OK)
		return -EIO;

	wait_for_completion(&fcomp.comp);
	if (fcomp.status != BFA_STATUS_OK)
		return -EIO;

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	status = bfa_port_enable(&bfad->bfa.modules.port,
					bfad_hcb_comp, &fcomp);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
	if (status != BFA_STATUS_OK)
		return -EIO;

	wait_for_completion(&fcomp.comp);
	if (fcomp.status != BFA_STATUS_OK)
		return -EIO;

	return 0;
}

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
static int
bfad_im_vport_delete(struct fc_vport *fc_vport)
{
	struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) vport->drv_port.im_port;
	struct bfad_s *bfad = im_port->bfad;
	struct bfad_port_s *port;
	struct bfa_fcs_vport_s *fcs_vport;
	struct Scsi_Host *vshost;
	wwn_t   pwwn;
	int rc;
	unsigned long flags;
	struct completion fcomp;

514 515 516
	if (im_port->flags & BFAD_PORT_DELETE) {
		bfad_scsi_host_free(bfad, im_port);
		list_del(&vport->list_entry);
517
		kfree(vport);
518 519
		return 0;
	}
520 521 522 523

	port = im_port->port;

	vshost = vport->drv_port.im_port->shost;
J
Jing Huang 已提交
524
	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	if (fcs_vport == NULL)
		return VPCERR_BAD_WWN;

	vport->drv_port.flags |= BFAD_PORT_DELETE;

	vport->comp_del = &fcomp;
	init_completion(vport->comp_del);

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	rc = bfa_fcs_vport_delete(&vport->fcs_vport);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

J
Jing Huang 已提交
542 543 544
	if (rc == BFA_STATUS_PBC) {
		vport->drv_port.flags &= ~BFAD_PORT_DELETE;
		vport->comp_del = NULL;
J
Jing Huang 已提交
545
		return -1;
J
Jing Huang 已提交
546
	}
J
Jing Huang 已提交
547

548 549
	wait_for_completion(vport->comp_del);

M
Maggie Zhang 已提交
550
	bfad_scsi_host_free(bfad, im_port);
551
	list_del(&vport->list_entry);
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
	kfree(vport);

	return 0;
}

static int
bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
{
	struct bfad_vport_s *vport;
	struct bfad_s *bfad;
	struct bfa_fcs_vport_s *fcs_vport;
	struct Scsi_Host *vshost;
	wwn_t   pwwn;
	unsigned long flags;

	vport = (struct bfad_vport_s *)fc_vport->dd_data;
	bfad = vport->drv_port.bfad;
	vshost = vport->drv_port.im_port->shost;
J
Jing Huang 已提交
570
	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	if (fcs_vport == NULL)
		return VPCERR_BAD_WWN;

	if (disable) {
		bfa_fcs_vport_stop(fcs_vport);
		fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
	} else {
		bfa_fcs_vport_start(fcs_vport);
		fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
	}

	return 0;
}

590 591 592 593 594 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
void
bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport)
{
	struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *)vport->drv_port.im_port;
	struct bfad_s *bfad = im_port->bfad;
	struct Scsi_Host *vshost = vport->drv_port.im_port->shost;
	char *sym_name = fc_vport->symbolic_name;
	struct bfa_fcs_vport_s *fcs_vport;
	wwn_t	pwwn;
	unsigned long flags;

	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);

	if (fcs_vport == NULL)
		return;

	spin_lock_irqsave(&bfad->bfad_lock, flags);
	if (strlen(sym_name) > 0) {
		strcpy(fcs_vport->lport.port_cfg.sym_name.symname, sym_name);
		bfa_fcs_lport_ns_util_send_rspn_id(
			BFA_FCS_GET_NS_FROM_PORT((&fcs_vport->lport)), NULL);
	}
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
}

621 622 623 624 625 626 627 628 629
struct fc_function_template bfad_im_fc_function_template = {

	/* Target dynamic attributes */
	.get_starget_port_id = bfad_im_get_starget_port_id,
	.show_starget_port_id = 1,
	.get_starget_node_name = bfad_im_get_starget_node_name,
	.show_starget_node_name = 1,
	.get_starget_port_name = bfad_im_get_starget_port_name,
	.show_starget_port_name = 1,
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669

	/* Host dynamic attribute */
	.get_host_port_id = bfad_im_get_host_port_id,
	.show_host_port_id = 1,

	/* Host fixed attributes */
	.show_host_node_name = 1,
	.show_host_port_name = 1,
	.show_host_supported_classes = 1,
	.show_host_supported_fc4s = 1,
	.show_host_supported_speeds = 1,
	.show_host_maxframe_size = 1,

	/* More host dynamic attributes */
	.show_host_port_type = 1,
	.get_host_port_type = bfad_im_get_host_port_type,
	.show_host_port_state = 1,
	.get_host_port_state = bfad_im_get_host_port_state,
	.show_host_active_fc4s = 1,
	.get_host_active_fc4s = bfad_im_get_host_active_fc4s,
	.show_host_speed = 1,
	.get_host_speed = bfad_im_get_host_speed,
	.show_host_fabric_name = 1,
	.get_host_fabric_name = bfad_im_get_host_fabric_name,

	.show_host_symbolic_name = 1,

	/* Statistics */
	.get_fc_host_stats = bfad_im_get_stats,
	.reset_fc_host_stats = bfad_im_reset_stats,

	/* Allocation length for host specific data */
	.dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),

	/* Remote port fixed attributes */
	.show_rport_maxframe_size = 1,
	.show_rport_supported_classes = 1,
	.show_rport_dev_loss_tmo = 1,
	.get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
	.set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
670
	.issue_fc_host_lip = bfad_im_issue_fc_host_lip,
671 672 673
	.vport_create = bfad_im_vport_create,
	.vport_delete = bfad_im_vport_delete,
	.vport_disable = bfad_im_vport_disable,
674
	.set_vport_symbolic_name = bfad_im_vport_set_symbolic_name,
675 676
	.bsg_request = bfad_im_bsg_request,
	.bsg_timeout = bfad_im_bsg_timeout,
677 678 679 680 681 682 683 684 685 686 687
};

struct fc_function_template bfad_im_vport_fc_function_template = {

	/* Target dynamic attributes */
	.get_starget_port_id = bfad_im_get_starget_port_id,
	.show_starget_port_id = 1,
	.get_starget_node_name = bfad_im_get_starget_node_name,
	.show_starget_node_name = 1,
	.get_starget_port_name = bfad_im_get_starget_port_name,
	.show_starget_port_name = 1,
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729

	/* Host dynamic attribute */
	.get_host_port_id = bfad_im_get_host_port_id,
	.show_host_port_id = 1,

	/* Host fixed attributes */
	.show_host_node_name = 1,
	.show_host_port_name = 1,
	.show_host_supported_classes = 1,
	.show_host_supported_fc4s = 1,
	.show_host_supported_speeds = 1,
	.show_host_maxframe_size = 1,

	/* More host dynamic attributes */
	.show_host_port_type = 1,
	.get_host_port_type = bfad_im_get_host_port_type,
	.show_host_port_state = 1,
	.get_host_port_state = bfad_im_get_host_port_state,
	.show_host_active_fc4s = 1,
	.get_host_active_fc4s = bfad_im_get_host_active_fc4s,
	.show_host_speed = 1,
	.get_host_speed = bfad_im_get_host_speed,
	.show_host_fabric_name = 1,
	.get_host_fabric_name = bfad_im_get_host_fabric_name,

	.show_host_symbolic_name = 1,

	/* Statistics */
	.get_fc_host_stats = bfad_im_get_stats,
	.reset_fc_host_stats = bfad_im_reset_stats,

	/* Allocation length for host specific data */
	.dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),

	/* Remote port fixed attributes */
	.show_rport_maxframe_size = 1,
	.show_rport_supported_classes = 1,
	.show_rport_dev_loss_tmo = 1,
	.get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
	.set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
};

J
Jing Huang 已提交
730
/*
731 732 733 734 735 736 737 738 739
 *  Scsi_Host_attrs SCSI host attributes
 */
static ssize_t
bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
740
	struct bfad_s *bfad = im_port->bfad;
741
	char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
742

743 744
	bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
	return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
745 746 747 748 749 750 751 752 753
}

static ssize_t
bfad_im_model_show(struct device *dev, struct device_attribute *attr,
			char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
754
	struct bfad_s *bfad = im_port->bfad;
755
	char model[BFA_ADAPTER_MODEL_NAME_LEN];
756

757 758
	bfa_get_adapter_model(&bfad->bfa, model);
	return snprintf(buf, PAGE_SIZE, "%s\n", model);
759 760 761 762 763 764 765 766 767
}

static ssize_t
bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
				 char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
768 769
	struct bfad_s *bfad = im_port->bfad;
	char model[BFA_ADAPTER_MODEL_NAME_LEN];
770
	char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
771
	int nports = 0;
772

K
Krishna Gudipati 已提交
773
	bfa_get_adapter_model(&bfad->bfa, model);
774
	nports = bfa_get_nports(&bfad->bfa);
K
Krishna Gudipati 已提交
775 776 777 778 779 780 781 782
	if (!strcmp(model, "Brocade-425"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 4Gbps PCIe dual port FC HBA");
	else if (!strcmp(model, "Brocade-825"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 8Gbps PCIe dual port FC HBA");
	else if (!strcmp(model, "Brocade-42B"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
783
			"Brocade 4Gbps PCIe dual port FC HBA for HP");
K
Krishna Gudipati 已提交
784 785
	else if (!strcmp(model, "Brocade-82B"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
786
			"Brocade 8Gbps PCIe dual port FC HBA for HP");
K
Krishna Gudipati 已提交
787 788 789 790 791 792 793 794
	else if (!strcmp(model, "Brocade-1010"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 10Gbps single port CNA");
	else if (!strcmp(model, "Brocade-1020"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 10Gbps dual port CNA");
	else if (!strcmp(model, "Brocade-1007"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
795
			"Brocade 10Gbps CNA for IBM Blade Center");
K
Krishna Gudipati 已提交
796 797 798 799 800 801 802 803
	else if (!strcmp(model, "Brocade-415"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 4Gbps PCIe single port FC HBA");
	else if (!strcmp(model, "Brocade-815"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Brocade 8Gbps PCIe single port FC HBA");
	else if (!strcmp(model, "Brocade-41B"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
804
			"Brocade 4Gbps PCIe single port FC HBA for HP");
K
Krishna Gudipati 已提交
805 806
	else if (!strcmp(model, "Brocade-81B"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
807
			"Brocade 8Gbps PCIe single port FC HBA for HP");
K
Krishna Gudipati 已提交
808 809
	else if (!strcmp(model, "Brocade-804"))
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
810
			"Brocade 8Gbps FC HBA for HP Bladesystem C-class");
811
	else if (!strcmp(model, "Brocade-1741"))
K
Krishna Gudipati 已提交
812
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
813
			"Brocade 10Gbps CNA for Dell M-Series Blade Servers");
814
	else if (strstr(model, "Brocade-1860")) {
815 816 817 818 819 820 821 822 823 824 825 826
		if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 10Gbps single port CNA");
		else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 16Gbps PCIe single port FC HBA");
		else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 10Gbps dual port CNA");
		else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 16Gbps PCIe dual port FC HBA");
827 828 829 830 831 832 833
	} else if (!strcmp(model, "Brocade-1867")) {
		if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 16Gbps PCIe single port FC HBA for IBM");
		else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
				"Brocade 16Gbps PCIe dual port FC HBA for IBM");
834
	} else
K
Krishna Gudipati 已提交
835 836 837
		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
			"Invalid Model");

838
	return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
839 840 841 842 843 844 845 846 847 848 849 850
}

static ssize_t
bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
				 char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_port_s    *port = im_port->port;
	u64        nwwn;

K
Krishna Gudipati 已提交
851
	nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
852
	return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
853 854 855 856 857 858 859 860 861
}

static ssize_t
bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
				 char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
862 863 864
	struct bfad_s *bfad = im_port->bfad;
	struct bfa_lport_attr_s port_attr;
	char symname[BFA_SYMNAME_MAXLEN];
865

K
Krishna Gudipati 已提交
866 867 868 869
	bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
	strncpy(symname, port_attr.port_cfg.sym_name.symname,
			BFA_SYMNAME_MAXLEN);
	return snprintf(buf, PAGE_SIZE, "%s\n", symname);
870 871 872 873 874 875 876 877 878
}

static ssize_t
bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
				char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
879
	struct bfad_s *bfad = im_port->bfad;
880
	char hw_ver[BFA_VERSION_LEN];
881

882 883
	bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
	return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
}

static ssize_t
bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
				char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
}

static ssize_t
bfad_im_optionrom_version_show(struct device *dev,
			 struct device_attribute *attr, char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
900
	struct bfad_s *bfad = im_port->bfad;
901
	char optrom_ver[BFA_VERSION_LEN];
902

903 904
	bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
	return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
905 906 907 908 909 910 911 912 913
}

static ssize_t
bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
				 char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
914
	struct bfad_s *bfad = im_port->bfad;
915
	char fw_ver[BFA_VERSION_LEN];
916

917 918
	bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
	return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
919 920 921 922 923 924 925 926 927
}

static ssize_t
bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
				char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
K
Krishna Gudipati 已提交
928
	struct bfad_s *bfad = im_port->bfad;
929

930
	return snprintf(buf, PAGE_SIZE, "%d\n",
K
Krishna Gudipati 已提交
931
			bfa_get_nports(&bfad->bfa));
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
}

static ssize_t
bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
				char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
}

static ssize_t
bfad_im_num_of_discovered_ports_show(struct device *dev,
			struct device_attribute *attr, char *buf)
{
	struct Scsi_Host *shost = class_to_shost(dev);
	struct bfad_im_port_s *im_port =
			(struct bfad_im_port_s *) shost->hostdata[0];
	struct bfad_port_s    *port = im_port->port;
	struct bfad_s         *bfad = im_port->bfad;
	int        nrports = 2048;
951
	struct bfa_rport_qualifier_s *rports = NULL;
952 953
	unsigned long   flags;

954 955
	rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports,
			 GFP_ATOMIC);
956
	if (rports == NULL)
K
Krishna Gudipati 已提交
957
		return snprintf(buf, PAGE_SIZE, "Failed\n");
958 959

	spin_lock_irqsave(&bfad->bfad_lock, flags);
960
	bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports);
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
	kfree(rports);

	return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
}

static          DEVICE_ATTR(serial_number, S_IRUGO,
				bfad_im_serial_num_show, NULL);
static          DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
static          DEVICE_ATTR(model_description, S_IRUGO,
				bfad_im_model_desc_show, NULL);
static          DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
static          DEVICE_ATTR(symbolic_name, S_IRUGO,
				bfad_im_symbolic_name_show, NULL);
static          DEVICE_ATTR(hardware_version, S_IRUGO,
				bfad_im_hw_version_show, NULL);
static          DEVICE_ATTR(driver_version, S_IRUGO,
				bfad_im_drv_version_show, NULL);
static          DEVICE_ATTR(option_rom_version, S_IRUGO,
				bfad_im_optionrom_version_show, NULL);
static          DEVICE_ATTR(firmware_version, S_IRUGO,
				bfad_im_fw_version_show, NULL);
static          DEVICE_ATTR(number_of_ports, S_IRUGO,
				bfad_im_num_of_ports_show, NULL);
static          DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
static          DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
				bfad_im_num_of_discovered_ports_show, NULL);

struct device_attribute *bfad_im_host_attrs[] = {
	&dev_attr_serial_number,
	&dev_attr_model,
	&dev_attr_model_description,
	&dev_attr_node_name,
	&dev_attr_symbolic_name,
	&dev_attr_hardware_version,
	&dev_attr_driver_version,
	&dev_attr_option_rom_version,
	&dev_attr_firmware_version,
	&dev_attr_number_of_ports,
	&dev_attr_driver_name,
	&dev_attr_number_of_discovered_ports,
	NULL,
};

struct device_attribute *bfad_im_vport_attrs[] = {
K
Krishna Gudipati 已提交
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
	&dev_attr_serial_number,
	&dev_attr_model,
	&dev_attr_model_description,
	&dev_attr_node_name,
	&dev_attr_symbolic_name,
	&dev_attr_hardware_version,
	&dev_attr_driver_version,
	&dev_attr_option_rom_version,
	&dev_attr_firmware_version,
	&dev_attr_number_of_ports,
	&dev_attr_driver_name,
	&dev_attr_number_of_discovered_ports,
	NULL,
1019 1020 1021
};