2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * bfa_attr.c Linux driver configuration interface module.
27 * FC transport template entry, get SCSI target port ID.
30 bfad_im_get_starget_port_id(struct scsi_target
*starget
)
32 struct Scsi_Host
*shost
;
33 struct bfad_im_port_s
*im_port
;
35 struct bfad_itnim_s
*itnim
= NULL
;
39 shost
= dev_to_shost(starget
->dev
.parent
);
40 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
42 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
44 itnim
= bfad_get_itnim(im_port
, starget
->id
);
46 fc_id
= bfa_fcs_itnim_get_fcid(&itnim
->fcs_itnim
);
48 fc_starget_port_id(starget
) = fc_id
;
49 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
53 * FC transport template entry, get SCSI target nwwn.
56 bfad_im_get_starget_node_name(struct scsi_target
*starget
)
58 struct Scsi_Host
*shost
;
59 struct bfad_im_port_s
*im_port
;
61 struct bfad_itnim_s
*itnim
= NULL
;
65 shost
= dev_to_shost(starget
->dev
.parent
);
66 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
68 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
70 itnim
= bfad_get_itnim(im_port
, starget
->id
);
72 node_name
= bfa_fcs_itnim_get_nwwn(&itnim
->fcs_itnim
);
74 fc_starget_node_name(starget
) = cpu_to_be64(node_name
);
75 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
79 * FC transport template entry, get SCSI target pwwn.
82 bfad_im_get_starget_port_name(struct scsi_target
*starget
)
84 struct Scsi_Host
*shost
;
85 struct bfad_im_port_s
*im_port
;
87 struct bfad_itnim_s
*itnim
= NULL
;
91 shost
= dev_to_shost(starget
->dev
.parent
);
92 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
94 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
96 itnim
= bfad_get_itnim(im_port
, starget
->id
);
98 port_name
= bfa_fcs_itnim_get_pwwn(&itnim
->fcs_itnim
);
100 fc_starget_port_name(starget
) = cpu_to_be64(port_name
);
101 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
105 * FC transport template entry, get SCSI host port ID.
108 bfad_im_get_host_port_id(struct Scsi_Host
*shost
)
110 struct bfad_im_port_s
*im_port
=
111 (struct bfad_im_port_s
*) shost
->hostdata
[0];
112 struct bfad_port_s
*port
= im_port
->port
;
114 fc_host_port_id(shost
) =
115 bfa_hton3b(bfa_fcs_lport_get_fcid(port
->fcs_port
));
119 * FC transport template entry, get SCSI host port type.
122 bfad_im_get_host_port_type(struct Scsi_Host
*shost
)
124 struct bfad_im_port_s
*im_port
=
125 (struct bfad_im_port_s
*) shost
->hostdata
[0];
126 struct bfad_s
*bfad
= im_port
->bfad
;
127 struct bfa_lport_attr_s port_attr
;
129 bfa_fcs_lport_get_attr(&bfad
->bfa_fcs
.fabric
.bport
, &port_attr
);
131 switch (port_attr
.port_type
) {
132 case BFA_PORT_TYPE_NPORT
:
133 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
135 case BFA_PORT_TYPE_NLPORT
:
136 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
138 case BFA_PORT_TYPE_P2P
:
139 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
141 case BFA_PORT_TYPE_LPORT
:
142 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
145 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
151 * FC transport template entry, get SCSI host port state.
154 bfad_im_get_host_port_state(struct Scsi_Host
*shost
)
156 struct bfad_im_port_s
*im_port
=
157 (struct bfad_im_port_s
*) shost
->hostdata
[0];
158 struct bfad_s
*bfad
= im_port
->bfad
;
159 struct bfa_port_attr_s attr
;
161 bfa_fcport_get_attr(&bfad
->bfa
, &attr
);
163 switch (attr
.port_state
) {
164 case BFA_PORT_ST_LINKDOWN
:
165 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
167 case BFA_PORT_ST_LINKUP
:
168 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
170 case BFA_PORT_ST_DISABLED
:
171 case BFA_PORT_ST_STOPPED
:
172 case BFA_PORT_ST_IOCDOWN
:
173 case BFA_PORT_ST_IOCDIS
:
174 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
176 case BFA_PORT_ST_UNINIT
:
177 case BFA_PORT_ST_ENABLING_QWAIT
:
178 case BFA_PORT_ST_ENABLING
:
179 case BFA_PORT_ST_DISABLING_QWAIT
:
180 case BFA_PORT_ST_DISABLING
:
182 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
188 * FC transport template entry, get SCSI host active fc4s.
191 bfad_im_get_host_active_fc4s(struct Scsi_Host
*shost
)
193 struct bfad_im_port_s
*im_port
=
194 (struct bfad_im_port_s
*) shost
->hostdata
[0];
195 struct bfad_port_s
*port
= im_port
->port
;
197 memset(fc_host_active_fc4s(shost
), 0,
198 sizeof(fc_host_active_fc4s(shost
)));
200 if (port
->supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
)
201 fc_host_active_fc4s(shost
)[2] = 1;
203 fc_host_active_fc4s(shost
)[7] = 1;
207 * FC transport template entry, get SCSI host link speed.
210 bfad_im_get_host_speed(struct Scsi_Host
*shost
)
212 struct bfad_im_port_s
*im_port
=
213 (struct bfad_im_port_s
*) shost
->hostdata
[0];
214 struct bfad_s
*bfad
= im_port
->bfad
;
215 struct bfa_port_attr_s attr
;
217 bfa_fcport_get_attr(&bfad
->bfa
, &attr
);
218 switch (attr
.speed
) {
219 case BFA_PORT_SPEED_10GBPS
:
220 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
222 case BFA_PORT_SPEED_16GBPS
:
223 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
225 case BFA_PORT_SPEED_8GBPS
:
226 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
228 case BFA_PORT_SPEED_4GBPS
:
229 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
231 case BFA_PORT_SPEED_2GBPS
:
232 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
234 case BFA_PORT_SPEED_1GBPS
:
235 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
238 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
244 * FC transport template entry, get SCSI host port type.
247 bfad_im_get_host_fabric_name(struct Scsi_Host
*shost
)
249 struct bfad_im_port_s
*im_port
=
250 (struct bfad_im_port_s
*) shost
->hostdata
[0];
251 struct bfad_port_s
*port
= im_port
->port
;
252 wwn_t fabric_nwwn
= 0;
254 fabric_nwwn
= bfa_fcs_lport_get_fabric_name(port
->fcs_port
);
256 fc_host_fabric_name(shost
) = cpu_to_be64(fabric_nwwn
);
261 * FC transport template entry, get BFAD statistics.
263 static struct fc_host_statistics
*
264 bfad_im_get_stats(struct Scsi_Host
*shost
)
266 struct bfad_im_port_s
*im_port
=
267 (struct bfad_im_port_s
*) shost
->hostdata
[0];
268 struct bfad_s
*bfad
= im_port
->bfad
;
269 struct bfad_hal_comp fcomp
;
270 union bfa_port_stats_u
*fcstats
;
271 struct fc_host_statistics
*hstats
;
275 fcstats
= kzalloc(sizeof(union bfa_port_stats_u
), GFP_KERNEL
);
279 hstats
= &bfad
->link_stats
;
280 init_completion(&fcomp
.comp
);
281 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
282 memset(hstats
, 0, sizeof(struct fc_host_statistics
));
283 rc
= bfa_port_get_stats(BFA_FCPORT(&bfad
->bfa
),
284 fcstats
, bfad_hcb_comp
, &fcomp
);
285 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
286 if (rc
!= BFA_STATUS_OK
) {
291 wait_for_completion(&fcomp
.comp
);
293 /* Fill the fc_host_statistics structure */
294 hstats
->seconds_since_last_reset
= fcstats
->fc
.secs_reset
;
295 hstats
->tx_frames
= fcstats
->fc
.tx_frames
;
296 hstats
->tx_words
= fcstats
->fc
.tx_words
;
297 hstats
->rx_frames
= fcstats
->fc
.rx_frames
;
298 hstats
->rx_words
= fcstats
->fc
.rx_words
;
299 hstats
->lip_count
= fcstats
->fc
.lip_count
;
300 hstats
->nos_count
= fcstats
->fc
.nos_count
;
301 hstats
->error_frames
= fcstats
->fc
.error_frames
;
302 hstats
->dumped_frames
= fcstats
->fc
.dropped_frames
;
303 hstats
->link_failure_count
= fcstats
->fc
.link_failures
;
304 hstats
->loss_of_sync_count
= fcstats
->fc
.loss_of_syncs
;
305 hstats
->loss_of_signal_count
= fcstats
->fc
.loss_of_signals
;
306 hstats
->prim_seq_protocol_err_count
= fcstats
->fc
.primseq_errs
;
307 hstats
->invalid_crc_count
= fcstats
->fc
.invalid_crcs
;
314 * FC transport template entry, reset BFAD statistics.
317 bfad_im_reset_stats(struct Scsi_Host
*shost
)
319 struct bfad_im_port_s
*im_port
=
320 (struct bfad_im_port_s
*) shost
->hostdata
[0];
321 struct bfad_s
*bfad
= im_port
->bfad
;
322 struct bfad_hal_comp fcomp
;
326 init_completion(&fcomp
.comp
);
327 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
328 rc
= bfa_port_clear_stats(BFA_FCPORT(&bfad
->bfa
), bfad_hcb_comp
,
330 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
332 if (rc
!= BFA_STATUS_OK
)
335 wait_for_completion(&fcomp
.comp
);
341 * FC transport template entry, set rport loss timeout.
342 * Update dev_loss_tmo based on the value pushed down by the stack
343 * In case it is lesser than path_tov of driver, set it to path_tov + 1
344 * to ensure that the driver times out before the application
347 bfad_im_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
349 struct bfad_itnim_data_s
*itnim_data
= rport
->dd_data
;
350 struct bfad_itnim_s
*itnim
= itnim_data
->itnim
;
351 struct bfad_s
*bfad
= itnim
->im
->bfad
;
352 uint16_t path_tov
= bfa_fcpim_path_tov_get(&bfad
->bfa
);
354 rport
->dev_loss_tmo
= timeout
;
355 if (timeout
< path_tov
)
356 rport
->dev_loss_tmo
= path_tov
+ 1;
360 bfad_im_vport_create(struct fc_vport
*fc_vport
, bool disable
)
362 char *vname
= fc_vport
->symbolic_name
;
363 struct Scsi_Host
*shost
= fc_vport
->shost
;
364 struct bfad_im_port_s
*im_port
=
365 (struct bfad_im_port_s
*) shost
->hostdata
[0];
366 struct bfad_s
*bfad
= im_port
->bfad
;
367 struct bfa_lport_cfg_s port_cfg
;
368 struct bfad_vport_s
*vp
;
372 memset(&port_cfg
, 0, sizeof(port_cfg
));
373 u64_to_wwn(fc_vport
->node_name
, (u8
*)&port_cfg
.nwwn
);
374 u64_to_wwn(fc_vport
->port_name
, (u8
*)&port_cfg
.pwwn
);
375 if (strlen(vname
) > 0)
376 strcpy((char *)&port_cfg
.sym_name
, vname
);
377 port_cfg
.roles
= BFA_LPORT_ROLE_FCP_IM
;
379 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
380 list_for_each_entry(vp
, &bfad
->pbc_vport_list
, list_entry
) {
382 vp
->fcs_vport
.lport
.port_cfg
.pwwn
) {
383 port_cfg
.preboot_vp
=
384 vp
->fcs_vport
.lport
.port_cfg
.preboot_vp
;
388 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
390 rc
= bfad_vport_create(bfad
, 0, &port_cfg
, &fc_vport
->dev
);
391 if (rc
== BFA_STATUS_OK
) {
392 struct bfad_vport_s
*vport
;
393 struct bfa_fcs_vport_s
*fcs_vport
;
394 struct Scsi_Host
*vshost
;
396 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
397 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0,
399 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
400 if (fcs_vport
== NULL
)
401 return VPCERR_BAD_WWN
;
403 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
405 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
406 bfa_fcs_vport_stop(fcs_vport
);
407 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
408 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
411 vport
= fcs_vport
->vport_drv
;
412 vshost
= vport
->drv_port
.im_port
->shost
;
413 fc_host_node_name(vshost
) = wwn_to_u64((u8
*)&port_cfg
.nwwn
);
414 fc_host_port_name(vshost
) = wwn_to_u64((u8
*)&port_cfg
.pwwn
);
415 fc_host_supported_classes(vshost
) = FC_COS_CLASS3
;
417 memset(fc_host_supported_fc4s(vshost
), 0,
418 sizeof(fc_host_supported_fc4s(vshost
)));
420 /* For FCP type 0x08 */
421 if (supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
)
422 fc_host_supported_fc4s(vshost
)[2] = 1;
424 /* For fibre channel services type 0x20 */
425 fc_host_supported_fc4s(vshost
)[7] = 1;
427 fc_host_supported_speeds(vshost
) =
428 bfad_im_supported_speeds(&bfad
->bfa
);
429 fc_host_maxframe_size(vshost
) =
430 bfa_fcport_get_maxfrsize(&bfad
->bfa
);
432 fc_vport
->dd_data
= vport
;
433 vport
->drv_port
.im_port
->fc_vport
= fc_vport
;
434 } else if (rc
== BFA_STATUS_INVALID_WWN
)
435 return VPCERR_BAD_WWN
;
436 else if (rc
== BFA_STATUS_VPORT_EXISTS
)
437 return VPCERR_BAD_WWN
;
438 else if (rc
== BFA_STATUS_VPORT_MAX
)
439 return VPCERR_NO_FABRIC_SUPP
;
440 else if (rc
== BFA_STATUS_VPORT_WWN_BP
)
441 return VPCERR_BAD_WWN
;
443 return FC_VPORT_FAILED
;
449 bfad_im_issue_fc_host_lip(struct Scsi_Host
*shost
)
451 struct bfad_im_port_s
*im_port
=
452 (struct bfad_im_port_s
*) shost
->hostdata
[0];
453 struct bfad_s
*bfad
= im_port
->bfad
;
454 struct bfad_hal_comp fcomp
;
458 init_completion(&fcomp
.comp
);
459 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
460 status
= bfa_port_disable(&bfad
->bfa
.modules
.port
,
461 bfad_hcb_comp
, &fcomp
);
462 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
464 if (status
!= BFA_STATUS_OK
)
467 wait_for_completion(&fcomp
.comp
);
468 if (fcomp
.status
!= BFA_STATUS_OK
)
471 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
472 status
= bfa_port_enable(&bfad
->bfa
.modules
.port
,
473 bfad_hcb_comp
, &fcomp
);
474 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
475 if (status
!= BFA_STATUS_OK
)
478 wait_for_completion(&fcomp
.comp
);
479 if (fcomp
.status
!= BFA_STATUS_OK
)
486 bfad_im_vport_delete(struct fc_vport
*fc_vport
)
488 struct bfad_vport_s
*vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
489 struct bfad_im_port_s
*im_port
=
490 (struct bfad_im_port_s
*) vport
->drv_port
.im_port
;
491 struct bfad_s
*bfad
= im_port
->bfad
;
492 struct bfa_fcs_vport_s
*fcs_vport
;
493 struct Scsi_Host
*vshost
;
497 struct completion fcomp
;
499 if (im_port
->flags
& BFAD_PORT_DELETE
) {
500 bfad_scsi_host_free(bfad
, im_port
);
501 list_del(&vport
->list_entry
);
506 vshost
= vport
->drv_port
.im_port
->shost
;
507 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
509 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
510 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
511 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
513 if (fcs_vport
== NULL
)
514 return VPCERR_BAD_WWN
;
516 vport
->drv_port
.flags
|= BFAD_PORT_DELETE
;
518 vport
->comp_del
= &fcomp
;
519 init_completion(vport
->comp_del
);
521 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
522 rc
= bfa_fcs_vport_delete(&vport
->fcs_vport
);
523 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
525 if (rc
== BFA_STATUS_PBC
) {
526 vport
->drv_port
.flags
&= ~BFAD_PORT_DELETE
;
527 vport
->comp_del
= NULL
;
531 wait_for_completion(vport
->comp_del
);
533 bfad_scsi_host_free(bfad
, im_port
);
534 list_del(&vport
->list_entry
);
541 bfad_im_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
543 struct bfad_vport_s
*vport
;
545 struct bfa_fcs_vport_s
*fcs_vport
;
546 struct Scsi_Host
*vshost
;
550 vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
551 bfad
= vport
->drv_port
.bfad
;
552 vshost
= vport
->drv_port
.im_port
->shost
;
553 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
555 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
556 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
557 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
559 if (fcs_vport
== NULL
)
560 return VPCERR_BAD_WWN
;
563 bfa_fcs_vport_stop(fcs_vport
);
564 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
566 bfa_fcs_vport_start(fcs_vport
);
567 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
574 bfad_im_vport_set_symbolic_name(struct fc_vport
*fc_vport
)
576 struct bfad_vport_s
*vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
577 struct bfad_im_port_s
*im_port
=
578 (struct bfad_im_port_s
*)vport
->drv_port
.im_port
;
579 struct bfad_s
*bfad
= im_port
->bfad
;
580 struct Scsi_Host
*vshost
= vport
->drv_port
.im_port
->shost
;
581 char *sym_name
= fc_vport
->symbolic_name
;
582 struct bfa_fcs_vport_s
*fcs_vport
;
586 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
588 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
589 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
590 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
592 if (fcs_vport
== NULL
)
595 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
596 if (strlen(sym_name
) > 0)
597 bfa_fcs_lport_set_symname(&fcs_vport
->lport
, sym_name
);
598 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
601 struct fc_function_template bfad_im_fc_function_template
= {
603 /* Target dynamic attributes */
604 .get_starget_port_id
= bfad_im_get_starget_port_id
,
605 .show_starget_port_id
= 1,
606 .get_starget_node_name
= bfad_im_get_starget_node_name
,
607 .show_starget_node_name
= 1,
608 .get_starget_port_name
= bfad_im_get_starget_port_name
,
609 .show_starget_port_name
= 1,
611 /* Host dynamic attribute */
612 .get_host_port_id
= bfad_im_get_host_port_id
,
613 .show_host_port_id
= 1,
615 /* Host fixed attributes */
616 .show_host_node_name
= 1,
617 .show_host_port_name
= 1,
618 .show_host_supported_classes
= 1,
619 .show_host_supported_fc4s
= 1,
620 .show_host_supported_speeds
= 1,
621 .show_host_maxframe_size
= 1,
623 /* More host dynamic attributes */
624 .show_host_port_type
= 1,
625 .get_host_port_type
= bfad_im_get_host_port_type
,
626 .show_host_port_state
= 1,
627 .get_host_port_state
= bfad_im_get_host_port_state
,
628 .show_host_active_fc4s
= 1,
629 .get_host_active_fc4s
= bfad_im_get_host_active_fc4s
,
630 .show_host_speed
= 1,
631 .get_host_speed
= bfad_im_get_host_speed
,
632 .show_host_fabric_name
= 1,
633 .get_host_fabric_name
= bfad_im_get_host_fabric_name
,
635 .show_host_symbolic_name
= 1,
638 .get_fc_host_stats
= bfad_im_get_stats
,
639 .reset_fc_host_stats
= bfad_im_reset_stats
,
641 /* Allocation length for host specific data */
642 .dd_fcrport_size
= sizeof(struct bfad_itnim_data_s
*),
644 /* Remote port fixed attributes */
645 .show_rport_maxframe_size
= 1,
646 .show_rport_supported_classes
= 1,
647 .show_rport_dev_loss_tmo
= 1,
648 .set_rport_dev_loss_tmo
= bfad_im_set_rport_loss_tmo
,
649 .issue_fc_host_lip
= bfad_im_issue_fc_host_lip
,
650 .vport_create
= bfad_im_vport_create
,
651 .vport_delete
= bfad_im_vport_delete
,
652 .vport_disable
= bfad_im_vport_disable
,
653 .set_vport_symbolic_name
= bfad_im_vport_set_symbolic_name
,
654 .bsg_request
= bfad_im_bsg_request
,
655 .bsg_timeout
= bfad_im_bsg_timeout
,
658 struct fc_function_template bfad_im_vport_fc_function_template
= {
660 /* Target dynamic attributes */
661 .get_starget_port_id
= bfad_im_get_starget_port_id
,
662 .show_starget_port_id
= 1,
663 .get_starget_node_name
= bfad_im_get_starget_node_name
,
664 .show_starget_node_name
= 1,
665 .get_starget_port_name
= bfad_im_get_starget_port_name
,
666 .show_starget_port_name
= 1,
668 /* Host dynamic attribute */
669 .get_host_port_id
= bfad_im_get_host_port_id
,
670 .show_host_port_id
= 1,
672 /* Host fixed attributes */
673 .show_host_node_name
= 1,
674 .show_host_port_name
= 1,
675 .show_host_supported_classes
= 1,
676 .show_host_supported_fc4s
= 1,
677 .show_host_supported_speeds
= 1,
678 .show_host_maxframe_size
= 1,
680 /* More host dynamic attributes */
681 .show_host_port_type
= 1,
682 .get_host_port_type
= bfad_im_get_host_port_type
,
683 .show_host_port_state
= 1,
684 .get_host_port_state
= bfad_im_get_host_port_state
,
685 .show_host_active_fc4s
= 1,
686 .get_host_active_fc4s
= bfad_im_get_host_active_fc4s
,
687 .show_host_speed
= 1,
688 .get_host_speed
= bfad_im_get_host_speed
,
689 .show_host_fabric_name
= 1,
690 .get_host_fabric_name
= bfad_im_get_host_fabric_name
,
692 .show_host_symbolic_name
= 1,
695 .get_fc_host_stats
= bfad_im_get_stats
,
696 .reset_fc_host_stats
= bfad_im_reset_stats
,
698 /* Allocation length for host specific data */
699 .dd_fcrport_size
= sizeof(struct bfad_itnim_data_s
*),
701 /* Remote port fixed attributes */
702 .show_rport_maxframe_size
= 1,
703 .show_rport_supported_classes
= 1,
704 .show_rport_dev_loss_tmo
= 1,
705 .set_rport_dev_loss_tmo
= bfad_im_set_rport_loss_tmo
,
709 * Scsi_Host_attrs SCSI host attributes
712 bfad_im_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
715 struct Scsi_Host
*shost
= class_to_shost(dev
);
716 struct bfad_im_port_s
*im_port
=
717 (struct bfad_im_port_s
*) shost
->hostdata
[0];
718 struct bfad_s
*bfad
= im_port
->bfad
;
719 char serial_num
[BFA_ADAPTER_SERIAL_NUM_LEN
];
721 bfa_get_adapter_serial_num(&bfad
->bfa
, serial_num
);
722 return snprintf(buf
, PAGE_SIZE
, "%s\n", serial_num
);
726 bfad_im_model_show(struct device
*dev
, struct device_attribute
*attr
,
729 struct Scsi_Host
*shost
= class_to_shost(dev
);
730 struct bfad_im_port_s
*im_port
=
731 (struct bfad_im_port_s
*) shost
->hostdata
[0];
732 struct bfad_s
*bfad
= im_port
->bfad
;
733 char model
[BFA_ADAPTER_MODEL_NAME_LEN
];
735 bfa_get_adapter_model(&bfad
->bfa
, model
);
736 return snprintf(buf
, PAGE_SIZE
, "%s\n", model
);
740 bfad_im_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
743 struct Scsi_Host
*shost
= class_to_shost(dev
);
744 struct bfad_im_port_s
*im_port
=
745 (struct bfad_im_port_s
*) shost
->hostdata
[0];
746 struct bfad_s
*bfad
= im_port
->bfad
;
747 char model
[BFA_ADAPTER_MODEL_NAME_LEN
];
748 char model_descr
[BFA_ADAPTER_MODEL_DESCR_LEN
];
751 bfa_get_adapter_model(&bfad
->bfa
, model
);
752 nports
= bfa_get_nports(&bfad
->bfa
);
753 if (!strcmp(model
, "QLogic-425"))
754 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
755 "QLogic BR-series 4Gbps PCIe dual port FC HBA");
756 else if (!strcmp(model
, "QLogic-825"))
757 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
758 "QLogic BR-series 8Gbps PCIe dual port FC HBA");
759 else if (!strcmp(model
, "QLogic-42B"))
760 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
761 "QLogic BR-series 4Gbps PCIe dual port FC HBA for HP");
762 else if (!strcmp(model
, "QLogic-82B"))
763 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
764 "QLogic BR-series 8Gbps PCIe dual port FC HBA for HP");
765 else if (!strcmp(model
, "QLogic-1010"))
766 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
767 "QLogic BR-series 10Gbps single port CNA");
768 else if (!strcmp(model
, "QLogic-1020"))
769 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
770 "QLogic BR-series 10Gbps dual port CNA");
771 else if (!strcmp(model
, "QLogic-1007"))
772 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
773 "QLogic BR-series 10Gbps CNA for IBM Blade Center");
774 else if (!strcmp(model
, "QLogic-415"))
775 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
776 "QLogic BR-series 4Gbps PCIe single port FC HBA");
777 else if (!strcmp(model
, "QLogic-815"))
778 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
779 "QLogic BR-series 8Gbps PCIe single port FC HBA");
780 else if (!strcmp(model
, "QLogic-41B"))
781 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
782 "QLogic BR-series 4Gbps PCIe single port FC HBA for HP");
783 else if (!strcmp(model
, "QLogic-81B"))
784 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
785 "QLogic BR-series 8Gbps PCIe single port FC HBA for HP");
786 else if (!strcmp(model
, "QLogic-804"))
787 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
788 "QLogic BR-series 8Gbps FC HBA for HP Bladesystem C-class");
789 else if (!strcmp(model
, "QLogic-1741"))
790 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
791 "QLogic BR-series 10Gbps CNA for Dell M-Series Blade Servers");
792 else if (strstr(model
, "QLogic-1860")) {
793 if (nports
== 1 && bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
794 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
795 "QLogic BR-series 10Gbps single port CNA");
796 else if (nports
== 1 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
797 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
798 "QLogic BR-series 16Gbps PCIe single port FC HBA");
799 else if (nports
== 2 && bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
800 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
801 "QLogic BR-series 10Gbps dual port CNA");
802 else if (nports
== 2 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
803 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
804 "QLogic BR-series 16Gbps PCIe dual port FC HBA");
805 } else if (!strcmp(model
, "QLogic-1867")) {
806 if (nports
== 1 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
807 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
808 "QLogic BR-series 16Gbps PCIe single port FC HBA for IBM");
809 else if (nports
== 2 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
810 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
811 "QLogic BR-series 16Gbps PCIe dual port FC HBA for IBM");
813 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
816 return snprintf(buf
, PAGE_SIZE
, "%s\n", model_descr
);
820 bfad_im_node_name_show(struct device
*dev
, struct device_attribute
*attr
,
823 struct Scsi_Host
*shost
= class_to_shost(dev
);
824 struct bfad_im_port_s
*im_port
=
825 (struct bfad_im_port_s
*) shost
->hostdata
[0];
826 struct bfad_port_s
*port
= im_port
->port
;
829 nwwn
= bfa_fcs_lport_get_nwwn(port
->fcs_port
);
830 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n", cpu_to_be64(nwwn
));
834 bfad_im_symbolic_name_show(struct device
*dev
, struct device_attribute
*attr
,
837 struct Scsi_Host
*shost
= class_to_shost(dev
);
838 struct bfad_im_port_s
*im_port
=
839 (struct bfad_im_port_s
*) shost
->hostdata
[0];
840 struct bfad_s
*bfad
= im_port
->bfad
;
841 struct bfa_lport_attr_s port_attr
;
842 char symname
[BFA_SYMNAME_MAXLEN
];
844 bfa_fcs_lport_get_attr(&bfad
->bfa_fcs
.fabric
.bport
, &port_attr
);
845 strlcpy(symname
, port_attr
.port_cfg
.sym_name
.symname
,
847 return snprintf(buf
, PAGE_SIZE
, "%s\n", symname
);
851 bfad_im_hw_version_show(struct device
*dev
, struct device_attribute
*attr
,
854 struct Scsi_Host
*shost
= class_to_shost(dev
);
855 struct bfad_im_port_s
*im_port
=
856 (struct bfad_im_port_s
*) shost
->hostdata
[0];
857 struct bfad_s
*bfad
= im_port
->bfad
;
858 char hw_ver
[BFA_VERSION_LEN
];
860 bfa_get_pci_chip_rev(&bfad
->bfa
, hw_ver
);
861 return snprintf(buf
, PAGE_SIZE
, "%s\n", hw_ver
);
865 bfad_im_drv_version_show(struct device
*dev
, struct device_attribute
*attr
,
868 return snprintf(buf
, PAGE_SIZE
, "%s\n", BFAD_DRIVER_VERSION
);
872 bfad_im_optionrom_version_show(struct device
*dev
,
873 struct device_attribute
*attr
, char *buf
)
875 struct Scsi_Host
*shost
= class_to_shost(dev
);
876 struct bfad_im_port_s
*im_port
=
877 (struct bfad_im_port_s
*) shost
->hostdata
[0];
878 struct bfad_s
*bfad
= im_port
->bfad
;
879 char optrom_ver
[BFA_VERSION_LEN
];
881 bfa_get_adapter_optrom_ver(&bfad
->bfa
, optrom_ver
);
882 return snprintf(buf
, PAGE_SIZE
, "%s\n", optrom_ver
);
886 bfad_im_fw_version_show(struct device
*dev
, struct device_attribute
*attr
,
889 struct Scsi_Host
*shost
= class_to_shost(dev
);
890 struct bfad_im_port_s
*im_port
=
891 (struct bfad_im_port_s
*) shost
->hostdata
[0];
892 struct bfad_s
*bfad
= im_port
->bfad
;
893 char fw_ver
[BFA_VERSION_LEN
];
895 bfa_get_adapter_fw_ver(&bfad
->bfa
, fw_ver
);
896 return snprintf(buf
, PAGE_SIZE
, "%s\n", fw_ver
);
900 bfad_im_num_of_ports_show(struct device
*dev
, struct device_attribute
*attr
,
903 struct Scsi_Host
*shost
= class_to_shost(dev
);
904 struct bfad_im_port_s
*im_port
=
905 (struct bfad_im_port_s
*) shost
->hostdata
[0];
906 struct bfad_s
*bfad
= im_port
->bfad
;
908 return snprintf(buf
, PAGE_SIZE
, "%d\n",
909 bfa_get_nports(&bfad
->bfa
));
913 bfad_im_drv_name_show(struct device
*dev
, struct device_attribute
*attr
,
916 return snprintf(buf
, PAGE_SIZE
, "%s\n", BFAD_DRIVER_NAME
);
920 bfad_im_num_of_discovered_ports_show(struct device
*dev
,
921 struct device_attribute
*attr
, char *buf
)
923 struct Scsi_Host
*shost
= class_to_shost(dev
);
924 struct bfad_im_port_s
*im_port
=
925 (struct bfad_im_port_s
*) shost
->hostdata
[0];
926 struct bfad_port_s
*port
= im_port
->port
;
927 struct bfad_s
*bfad
= im_port
->bfad
;
929 struct bfa_rport_qualifier_s
*rports
= NULL
;
932 rports
= kcalloc(nrports
, sizeof(struct bfa_rport_qualifier_s
),
935 return snprintf(buf
, PAGE_SIZE
, "Failed\n");
937 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
938 bfa_fcs_lport_get_rport_quals(port
->fcs_port
, rports
, &nrports
);
939 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
942 return snprintf(buf
, PAGE_SIZE
, "%d\n", nrports
);
945 static DEVICE_ATTR(serial_number
, S_IRUGO
,
946 bfad_im_serial_num_show
, NULL
);
947 static DEVICE_ATTR(model
, S_IRUGO
, bfad_im_model_show
, NULL
);
948 static DEVICE_ATTR(model_description
, S_IRUGO
,
949 bfad_im_model_desc_show
, NULL
);
950 static DEVICE_ATTR(node_name
, S_IRUGO
, bfad_im_node_name_show
, NULL
);
951 static DEVICE_ATTR(symbolic_name
, S_IRUGO
,
952 bfad_im_symbolic_name_show
, NULL
);
953 static DEVICE_ATTR(hardware_version
, S_IRUGO
,
954 bfad_im_hw_version_show
, NULL
);
955 static DEVICE_ATTR(driver_version
, S_IRUGO
,
956 bfad_im_drv_version_show
, NULL
);
957 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
958 bfad_im_optionrom_version_show
, NULL
);
959 static DEVICE_ATTR(firmware_version
, S_IRUGO
,
960 bfad_im_fw_version_show
, NULL
);
961 static DEVICE_ATTR(number_of_ports
, S_IRUGO
,
962 bfad_im_num_of_ports_show
, NULL
);
963 static DEVICE_ATTR(driver_name
, S_IRUGO
, bfad_im_drv_name_show
, NULL
);
964 static DEVICE_ATTR(number_of_discovered_ports
, S_IRUGO
,
965 bfad_im_num_of_discovered_ports_show
, NULL
);
967 struct device_attribute
*bfad_im_host_attrs
[] = {
968 &dev_attr_serial_number
,
970 &dev_attr_model_description
,
972 &dev_attr_symbolic_name
,
973 &dev_attr_hardware_version
,
974 &dev_attr_driver_version
,
975 &dev_attr_option_rom_version
,
976 &dev_attr_firmware_version
,
977 &dev_attr_number_of_ports
,
978 &dev_attr_driver_name
,
979 &dev_attr_number_of_discovered_ports
,
983 struct device_attribute
*bfad_im_vport_attrs
[] = {
984 &dev_attr_serial_number
,
986 &dev_attr_model_description
,
988 &dev_attr_symbolic_name
,
989 &dev_attr_hardware_version
,
990 &dev_attr_driver_version
,
991 &dev_attr_option_rom_version
,
992 &dev_attr_firmware_version
,
993 &dev_attr_number_of_ports
,
994 &dev_attr_driver_name
,
995 &dev_attr_number_of_discovered_ports
,