1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
8 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
12 * bfa_attr.c Linux driver configuration interface module.
19 * FC transport template entry, get SCSI target port ID.
22 bfad_im_get_starget_port_id(struct scsi_target
*starget
)
24 struct Scsi_Host
*shost
;
25 struct bfad_im_port_s
*im_port
;
27 struct bfad_itnim_s
*itnim
= NULL
;
31 shost
= dev_to_shost(starget
->dev
.parent
);
32 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
34 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
36 itnim
= bfad_get_itnim(im_port
, starget
->id
);
38 fc_id
= bfa_fcs_itnim_get_fcid(&itnim
->fcs_itnim
);
40 fc_starget_port_id(starget
) = fc_id
;
41 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
45 * FC transport template entry, get SCSI target nwwn.
48 bfad_im_get_starget_node_name(struct scsi_target
*starget
)
50 struct Scsi_Host
*shost
;
51 struct bfad_im_port_s
*im_port
;
53 struct bfad_itnim_s
*itnim
= NULL
;
57 shost
= dev_to_shost(starget
->dev
.parent
);
58 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
60 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
62 itnim
= bfad_get_itnim(im_port
, starget
->id
);
64 node_name
= bfa_fcs_itnim_get_nwwn(&itnim
->fcs_itnim
);
66 fc_starget_node_name(starget
) = cpu_to_be64(node_name
);
67 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
71 * FC transport template entry, get SCSI target pwwn.
74 bfad_im_get_starget_port_name(struct scsi_target
*starget
)
76 struct Scsi_Host
*shost
;
77 struct bfad_im_port_s
*im_port
;
79 struct bfad_itnim_s
*itnim
= NULL
;
83 shost
= dev_to_shost(starget
->dev
.parent
);
84 im_port
= (struct bfad_im_port_s
*) shost
->hostdata
[0];
86 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
88 itnim
= bfad_get_itnim(im_port
, starget
->id
);
90 port_name
= bfa_fcs_itnim_get_pwwn(&itnim
->fcs_itnim
);
92 fc_starget_port_name(starget
) = cpu_to_be64(port_name
);
93 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
97 * FC transport template entry, get SCSI host port ID.
100 bfad_im_get_host_port_id(struct Scsi_Host
*shost
)
102 struct bfad_im_port_s
*im_port
=
103 (struct bfad_im_port_s
*) shost
->hostdata
[0];
104 struct bfad_port_s
*port
= im_port
->port
;
106 fc_host_port_id(shost
) =
107 bfa_hton3b(bfa_fcs_lport_get_fcid(port
->fcs_port
));
111 * FC transport template entry, get SCSI host port type.
114 bfad_im_get_host_port_type(struct Scsi_Host
*shost
)
116 struct bfad_im_port_s
*im_port
=
117 (struct bfad_im_port_s
*) shost
->hostdata
[0];
118 struct bfad_s
*bfad
= im_port
->bfad
;
119 struct bfa_lport_attr_s port_attr
;
121 bfa_fcs_lport_get_attr(&bfad
->bfa_fcs
.fabric
.bport
, &port_attr
);
123 switch (port_attr
.port_type
) {
124 case BFA_PORT_TYPE_NPORT
:
125 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
127 case BFA_PORT_TYPE_NLPORT
:
128 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
130 case BFA_PORT_TYPE_P2P
:
131 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
133 case BFA_PORT_TYPE_LPORT
:
134 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
137 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
143 * FC transport template entry, get SCSI host port state.
146 bfad_im_get_host_port_state(struct Scsi_Host
*shost
)
148 struct bfad_im_port_s
*im_port
=
149 (struct bfad_im_port_s
*) shost
->hostdata
[0];
150 struct bfad_s
*bfad
= im_port
->bfad
;
151 struct bfa_port_attr_s attr
;
153 bfa_fcport_get_attr(&bfad
->bfa
, &attr
);
155 switch (attr
.port_state
) {
156 case BFA_PORT_ST_LINKDOWN
:
157 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
159 case BFA_PORT_ST_LINKUP
:
160 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
162 case BFA_PORT_ST_DISABLED
:
163 case BFA_PORT_ST_STOPPED
:
164 case BFA_PORT_ST_IOCDOWN
:
165 case BFA_PORT_ST_IOCDIS
:
166 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
168 case BFA_PORT_ST_UNINIT
:
169 case BFA_PORT_ST_ENABLING_QWAIT
:
170 case BFA_PORT_ST_ENABLING
:
171 case BFA_PORT_ST_DISABLING_QWAIT
:
172 case BFA_PORT_ST_DISABLING
:
174 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
180 * FC transport template entry, get SCSI host active fc4s.
183 bfad_im_get_host_active_fc4s(struct Scsi_Host
*shost
)
185 struct bfad_im_port_s
*im_port
=
186 (struct bfad_im_port_s
*) shost
->hostdata
[0];
187 struct bfad_port_s
*port
= im_port
->port
;
189 memset(fc_host_active_fc4s(shost
), 0,
190 sizeof(fc_host_active_fc4s(shost
)));
192 if (port
->supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
)
193 fc_host_active_fc4s(shost
)[2] = 1;
195 fc_host_active_fc4s(shost
)[7] = 1;
199 * FC transport template entry, get SCSI host link speed.
202 bfad_im_get_host_speed(struct Scsi_Host
*shost
)
204 struct bfad_im_port_s
*im_port
=
205 (struct bfad_im_port_s
*) shost
->hostdata
[0];
206 struct bfad_s
*bfad
= im_port
->bfad
;
207 struct bfa_port_attr_s attr
;
209 bfa_fcport_get_attr(&bfad
->bfa
, &attr
);
210 switch (attr
.speed
) {
211 case BFA_PORT_SPEED_10GBPS
:
212 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
214 case BFA_PORT_SPEED_16GBPS
:
215 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
217 case BFA_PORT_SPEED_8GBPS
:
218 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
220 case BFA_PORT_SPEED_4GBPS
:
221 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
223 case BFA_PORT_SPEED_2GBPS
:
224 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
226 case BFA_PORT_SPEED_1GBPS
:
227 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
230 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
236 * FC transport template entry, get SCSI host port type.
239 bfad_im_get_host_fabric_name(struct Scsi_Host
*shost
)
241 struct bfad_im_port_s
*im_port
=
242 (struct bfad_im_port_s
*) shost
->hostdata
[0];
243 struct bfad_port_s
*port
= im_port
->port
;
244 wwn_t fabric_nwwn
= 0;
246 fabric_nwwn
= bfa_fcs_lport_get_fabric_name(port
->fcs_port
);
248 fc_host_fabric_name(shost
) = cpu_to_be64(fabric_nwwn
);
253 * FC transport template entry, get BFAD statistics.
255 static struct fc_host_statistics
*
256 bfad_im_get_stats(struct Scsi_Host
*shost
)
258 struct bfad_im_port_s
*im_port
=
259 (struct bfad_im_port_s
*) shost
->hostdata
[0];
260 struct bfad_s
*bfad
= im_port
->bfad
;
261 struct bfad_hal_comp fcomp
;
262 union bfa_port_stats_u
*fcstats
;
263 struct fc_host_statistics
*hstats
;
267 fcstats
= kzalloc(sizeof(union bfa_port_stats_u
), GFP_KERNEL
);
271 hstats
= &bfad
->link_stats
;
272 init_completion(&fcomp
.comp
);
273 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
274 memset(hstats
, 0, sizeof(struct fc_host_statistics
));
275 rc
= bfa_port_get_stats(BFA_FCPORT(&bfad
->bfa
),
276 fcstats
, bfad_hcb_comp
, &fcomp
);
277 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
278 if (rc
!= BFA_STATUS_OK
) {
283 wait_for_completion(&fcomp
.comp
);
285 /* Fill the fc_host_statistics structure */
286 hstats
->seconds_since_last_reset
= fcstats
->fc
.secs_reset
;
287 hstats
->tx_frames
= fcstats
->fc
.tx_frames
;
288 hstats
->tx_words
= fcstats
->fc
.tx_words
;
289 hstats
->rx_frames
= fcstats
->fc
.rx_frames
;
290 hstats
->rx_words
= fcstats
->fc
.rx_words
;
291 hstats
->lip_count
= fcstats
->fc
.lip_count
;
292 hstats
->nos_count
= fcstats
->fc
.nos_count
;
293 hstats
->error_frames
= fcstats
->fc
.error_frames
;
294 hstats
->dumped_frames
= fcstats
->fc
.dropped_frames
;
295 hstats
->link_failure_count
= fcstats
->fc
.link_failures
;
296 hstats
->loss_of_sync_count
= fcstats
->fc
.loss_of_syncs
;
297 hstats
->loss_of_signal_count
= fcstats
->fc
.loss_of_signals
;
298 hstats
->prim_seq_protocol_err_count
= fcstats
->fc
.primseq_errs
;
299 hstats
->invalid_crc_count
= fcstats
->fc
.invalid_crcs
;
306 * FC transport template entry, reset BFAD statistics.
309 bfad_im_reset_stats(struct Scsi_Host
*shost
)
311 struct bfad_im_port_s
*im_port
=
312 (struct bfad_im_port_s
*) shost
->hostdata
[0];
313 struct bfad_s
*bfad
= im_port
->bfad
;
314 struct bfad_hal_comp fcomp
;
318 init_completion(&fcomp
.comp
);
319 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
320 rc
= bfa_port_clear_stats(BFA_FCPORT(&bfad
->bfa
), bfad_hcb_comp
,
322 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
324 if (rc
!= BFA_STATUS_OK
)
327 wait_for_completion(&fcomp
.comp
);
333 * FC transport template entry, set rport loss timeout.
334 * Update dev_loss_tmo based on the value pushed down by the stack
335 * In case it is lesser than path_tov of driver, set it to path_tov + 1
336 * to ensure that the driver times out before the application
339 bfad_im_set_rport_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
341 struct bfad_itnim_data_s
*itnim_data
= rport
->dd_data
;
342 struct bfad_itnim_s
*itnim
= itnim_data
->itnim
;
343 struct bfad_s
*bfad
= itnim
->im
->bfad
;
344 uint16_t path_tov
= bfa_fcpim_path_tov_get(&bfad
->bfa
);
346 rport
->dev_loss_tmo
= timeout
;
347 if (timeout
< path_tov
)
348 rport
->dev_loss_tmo
= path_tov
+ 1;
352 bfad_im_vport_create(struct fc_vport
*fc_vport
, bool disable
)
354 char *vname
= fc_vport
->symbolic_name
;
355 struct Scsi_Host
*shost
= fc_vport
->shost
;
356 struct bfad_im_port_s
*im_port
=
357 (struct bfad_im_port_s
*) shost
->hostdata
[0];
358 struct bfad_s
*bfad
= im_port
->bfad
;
359 struct bfa_lport_cfg_s port_cfg
;
360 struct bfad_vport_s
*vp
;
364 memset(&port_cfg
, 0, sizeof(port_cfg
));
365 u64_to_wwn(fc_vport
->node_name
, (u8
*)&port_cfg
.nwwn
);
366 u64_to_wwn(fc_vport
->port_name
, (u8
*)&port_cfg
.pwwn
);
367 if (strlen(vname
) > 0)
368 strcpy((char *)&port_cfg
.sym_name
, vname
);
369 port_cfg
.roles
= BFA_LPORT_ROLE_FCP_IM
;
371 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
372 list_for_each_entry(vp
, &bfad
->pbc_vport_list
, list_entry
) {
374 vp
->fcs_vport
.lport
.port_cfg
.pwwn
) {
375 port_cfg
.preboot_vp
=
376 vp
->fcs_vport
.lport
.port_cfg
.preboot_vp
;
380 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
382 rc
= bfad_vport_create(bfad
, 0, &port_cfg
, &fc_vport
->dev
);
383 if (rc
== BFA_STATUS_OK
) {
384 struct bfad_vport_s
*vport
;
385 struct bfa_fcs_vport_s
*fcs_vport
;
386 struct Scsi_Host
*vshost
;
388 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
389 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0,
391 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
392 if (fcs_vport
== NULL
)
393 return VPCERR_BAD_WWN
;
395 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
397 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
398 bfa_fcs_vport_stop(fcs_vport
);
399 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
400 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
403 vport
= fcs_vport
->vport_drv
;
404 vshost
= vport
->drv_port
.im_port
->shost
;
405 fc_host_node_name(vshost
) = wwn_to_u64((u8
*)&port_cfg
.nwwn
);
406 fc_host_port_name(vshost
) = wwn_to_u64((u8
*)&port_cfg
.pwwn
);
407 fc_host_supported_classes(vshost
) = FC_COS_CLASS3
;
409 memset(fc_host_supported_fc4s(vshost
), 0,
410 sizeof(fc_host_supported_fc4s(vshost
)));
412 /* For FCP type 0x08 */
413 if (supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
)
414 fc_host_supported_fc4s(vshost
)[2] = 1;
416 /* For fibre channel services type 0x20 */
417 fc_host_supported_fc4s(vshost
)[7] = 1;
419 fc_host_supported_speeds(vshost
) =
420 bfad_im_supported_speeds(&bfad
->bfa
);
421 fc_host_maxframe_size(vshost
) =
422 bfa_fcport_get_maxfrsize(&bfad
->bfa
);
424 fc_vport
->dd_data
= vport
;
425 vport
->drv_port
.im_port
->fc_vport
= fc_vport
;
426 } else if (rc
== BFA_STATUS_INVALID_WWN
)
427 return VPCERR_BAD_WWN
;
428 else if (rc
== BFA_STATUS_VPORT_EXISTS
)
429 return VPCERR_BAD_WWN
;
430 else if (rc
== BFA_STATUS_VPORT_MAX
)
431 return VPCERR_NO_FABRIC_SUPP
;
432 else if (rc
== BFA_STATUS_VPORT_WWN_BP
)
433 return VPCERR_BAD_WWN
;
435 return FC_VPORT_FAILED
;
441 bfad_im_issue_fc_host_lip(struct Scsi_Host
*shost
)
443 struct bfad_im_port_s
*im_port
=
444 (struct bfad_im_port_s
*) shost
->hostdata
[0];
445 struct bfad_s
*bfad
= im_port
->bfad
;
446 struct bfad_hal_comp fcomp
;
450 init_completion(&fcomp
.comp
);
451 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
452 status
= bfa_port_disable(&bfad
->bfa
.modules
.port
,
453 bfad_hcb_comp
, &fcomp
);
454 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
456 if (status
!= BFA_STATUS_OK
)
459 wait_for_completion(&fcomp
.comp
);
460 if (fcomp
.status
!= BFA_STATUS_OK
)
463 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
464 status
= bfa_port_enable(&bfad
->bfa
.modules
.port
,
465 bfad_hcb_comp
, &fcomp
);
466 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
467 if (status
!= BFA_STATUS_OK
)
470 wait_for_completion(&fcomp
.comp
);
471 if (fcomp
.status
!= BFA_STATUS_OK
)
478 bfad_im_vport_delete(struct fc_vport
*fc_vport
)
480 struct bfad_vport_s
*vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
481 struct bfad_im_port_s
*im_port
=
482 (struct bfad_im_port_s
*) vport
->drv_port
.im_port
;
483 struct bfad_s
*bfad
= im_port
->bfad
;
484 struct bfa_fcs_vport_s
*fcs_vport
;
485 struct Scsi_Host
*vshost
;
489 struct completion fcomp
;
491 if (im_port
->flags
& BFAD_PORT_DELETE
) {
492 bfad_scsi_host_free(bfad
, im_port
);
493 list_del(&vport
->list_entry
);
498 vshost
= vport
->drv_port
.im_port
->shost
;
499 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
501 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
502 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
503 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
505 if (fcs_vport
== NULL
)
506 return VPCERR_BAD_WWN
;
508 vport
->drv_port
.flags
|= BFAD_PORT_DELETE
;
510 vport
->comp_del
= &fcomp
;
511 init_completion(vport
->comp_del
);
513 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
514 rc
= bfa_fcs_vport_delete(&vport
->fcs_vport
);
515 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
517 if (rc
== BFA_STATUS_PBC
) {
518 vport
->drv_port
.flags
&= ~BFAD_PORT_DELETE
;
519 vport
->comp_del
= NULL
;
523 wait_for_completion(vport
->comp_del
);
525 bfad_scsi_host_free(bfad
, im_port
);
526 list_del(&vport
->list_entry
);
533 bfad_im_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
535 struct bfad_vport_s
*vport
;
537 struct bfa_fcs_vport_s
*fcs_vport
;
538 struct Scsi_Host
*vshost
;
542 vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
543 bfad
= vport
->drv_port
.bfad
;
544 vshost
= vport
->drv_port
.im_port
->shost
;
545 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
547 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
548 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
549 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
551 if (fcs_vport
== NULL
)
552 return VPCERR_BAD_WWN
;
555 bfa_fcs_vport_stop(fcs_vport
);
556 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
558 bfa_fcs_vport_start(fcs_vport
);
559 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
566 bfad_im_vport_set_symbolic_name(struct fc_vport
*fc_vport
)
568 struct bfad_vport_s
*vport
= (struct bfad_vport_s
*)fc_vport
->dd_data
;
569 struct bfad_im_port_s
*im_port
=
570 (struct bfad_im_port_s
*)vport
->drv_port
.im_port
;
571 struct bfad_s
*bfad
= im_port
->bfad
;
572 struct Scsi_Host
*vshost
= vport
->drv_port
.im_port
->shost
;
573 char *sym_name
= fc_vport
->symbolic_name
;
574 struct bfa_fcs_vport_s
*fcs_vport
;
578 u64_to_wwn(fc_host_port_name(vshost
), (u8
*)&pwwn
);
580 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
581 fcs_vport
= bfa_fcs_vport_lookup(&bfad
->bfa_fcs
, 0, pwwn
);
582 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
584 if (fcs_vport
== NULL
)
587 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
588 if (strlen(sym_name
) > 0)
589 bfa_fcs_lport_set_symname(&fcs_vport
->lport
, sym_name
);
590 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
593 struct fc_function_template bfad_im_fc_function_template
= {
595 /* Target dynamic attributes */
596 .get_starget_port_id
= bfad_im_get_starget_port_id
,
597 .show_starget_port_id
= 1,
598 .get_starget_node_name
= bfad_im_get_starget_node_name
,
599 .show_starget_node_name
= 1,
600 .get_starget_port_name
= bfad_im_get_starget_port_name
,
601 .show_starget_port_name
= 1,
603 /* Host dynamic attribute */
604 .get_host_port_id
= bfad_im_get_host_port_id
,
605 .show_host_port_id
= 1,
607 /* Host fixed attributes */
608 .show_host_node_name
= 1,
609 .show_host_port_name
= 1,
610 .show_host_supported_classes
= 1,
611 .show_host_supported_fc4s
= 1,
612 .show_host_supported_speeds
= 1,
613 .show_host_maxframe_size
= 1,
615 /* More host dynamic attributes */
616 .show_host_port_type
= 1,
617 .get_host_port_type
= bfad_im_get_host_port_type
,
618 .show_host_port_state
= 1,
619 .get_host_port_state
= bfad_im_get_host_port_state
,
620 .show_host_active_fc4s
= 1,
621 .get_host_active_fc4s
= bfad_im_get_host_active_fc4s
,
622 .show_host_speed
= 1,
623 .get_host_speed
= bfad_im_get_host_speed
,
624 .show_host_fabric_name
= 1,
625 .get_host_fabric_name
= bfad_im_get_host_fabric_name
,
627 .show_host_symbolic_name
= 1,
630 .get_fc_host_stats
= bfad_im_get_stats
,
631 .reset_fc_host_stats
= bfad_im_reset_stats
,
633 /* Allocation length for host specific data */
634 .dd_fcrport_size
= sizeof(struct bfad_itnim_data_s
*),
636 /* Remote port fixed attributes */
637 .show_rport_maxframe_size
= 1,
638 .show_rport_supported_classes
= 1,
639 .show_rport_dev_loss_tmo
= 1,
640 .set_rport_dev_loss_tmo
= bfad_im_set_rport_loss_tmo
,
641 .issue_fc_host_lip
= bfad_im_issue_fc_host_lip
,
642 .vport_create
= bfad_im_vport_create
,
643 .vport_delete
= bfad_im_vport_delete
,
644 .vport_disable
= bfad_im_vport_disable
,
645 .set_vport_symbolic_name
= bfad_im_vport_set_symbolic_name
,
646 .bsg_request
= bfad_im_bsg_request
,
647 .bsg_timeout
= bfad_im_bsg_timeout
,
650 struct fc_function_template bfad_im_vport_fc_function_template
= {
652 /* Target dynamic attributes */
653 .get_starget_port_id
= bfad_im_get_starget_port_id
,
654 .show_starget_port_id
= 1,
655 .get_starget_node_name
= bfad_im_get_starget_node_name
,
656 .show_starget_node_name
= 1,
657 .get_starget_port_name
= bfad_im_get_starget_port_name
,
658 .show_starget_port_name
= 1,
660 /* Host dynamic attribute */
661 .get_host_port_id
= bfad_im_get_host_port_id
,
662 .show_host_port_id
= 1,
664 /* Host fixed attributes */
665 .show_host_node_name
= 1,
666 .show_host_port_name
= 1,
667 .show_host_supported_classes
= 1,
668 .show_host_supported_fc4s
= 1,
669 .show_host_supported_speeds
= 1,
670 .show_host_maxframe_size
= 1,
672 /* More host dynamic attributes */
673 .show_host_port_type
= 1,
674 .get_host_port_type
= bfad_im_get_host_port_type
,
675 .show_host_port_state
= 1,
676 .get_host_port_state
= bfad_im_get_host_port_state
,
677 .show_host_active_fc4s
= 1,
678 .get_host_active_fc4s
= bfad_im_get_host_active_fc4s
,
679 .show_host_speed
= 1,
680 .get_host_speed
= bfad_im_get_host_speed
,
681 .show_host_fabric_name
= 1,
682 .get_host_fabric_name
= bfad_im_get_host_fabric_name
,
684 .show_host_symbolic_name
= 1,
687 .get_fc_host_stats
= bfad_im_get_stats
,
688 .reset_fc_host_stats
= bfad_im_reset_stats
,
690 /* Allocation length for host specific data */
691 .dd_fcrport_size
= sizeof(struct bfad_itnim_data_s
*),
693 /* Remote port fixed attributes */
694 .show_rport_maxframe_size
= 1,
695 .show_rport_supported_classes
= 1,
696 .show_rport_dev_loss_tmo
= 1,
697 .set_rport_dev_loss_tmo
= bfad_im_set_rport_loss_tmo
,
701 * Scsi_Host_attrs SCSI host attributes
704 bfad_im_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
707 struct Scsi_Host
*shost
= class_to_shost(dev
);
708 struct bfad_im_port_s
*im_port
=
709 (struct bfad_im_port_s
*) shost
->hostdata
[0];
710 struct bfad_s
*bfad
= im_port
->bfad
;
711 char serial_num
[BFA_ADAPTER_SERIAL_NUM_LEN
];
713 bfa_get_adapter_serial_num(&bfad
->bfa
, serial_num
);
714 return snprintf(buf
, PAGE_SIZE
, "%s\n", serial_num
);
718 bfad_im_model_show(struct device
*dev
, struct device_attribute
*attr
,
721 struct Scsi_Host
*shost
= class_to_shost(dev
);
722 struct bfad_im_port_s
*im_port
=
723 (struct bfad_im_port_s
*) shost
->hostdata
[0];
724 struct bfad_s
*bfad
= im_port
->bfad
;
725 char model
[BFA_ADAPTER_MODEL_NAME_LEN
];
727 bfa_get_adapter_model(&bfad
->bfa
, model
);
728 return snprintf(buf
, PAGE_SIZE
, "%s\n", model
);
732 bfad_im_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
735 struct Scsi_Host
*shost
= class_to_shost(dev
);
736 struct bfad_im_port_s
*im_port
=
737 (struct bfad_im_port_s
*) shost
->hostdata
[0];
738 struct bfad_s
*bfad
= im_port
->bfad
;
739 char model
[BFA_ADAPTER_MODEL_NAME_LEN
];
740 char model_descr
[BFA_ADAPTER_MODEL_DESCR_LEN
];
743 bfa_get_adapter_model(&bfad
->bfa
, model
);
744 nports
= bfa_get_nports(&bfad
->bfa
);
745 if (!strcmp(model
, "QLogic-425"))
746 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
747 "QLogic BR-series 4Gbps PCIe dual port FC HBA");
748 else if (!strcmp(model
, "QLogic-825"))
749 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
750 "QLogic BR-series 8Gbps PCIe dual port FC HBA");
751 else if (!strcmp(model
, "QLogic-42B"))
752 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
753 "QLogic BR-series 4Gbps PCIe dual port FC HBA for HP");
754 else if (!strcmp(model
, "QLogic-82B"))
755 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
756 "QLogic BR-series 8Gbps PCIe dual port FC HBA for HP");
757 else if (!strcmp(model
, "QLogic-1010"))
758 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
759 "QLogic BR-series 10Gbps single port CNA");
760 else if (!strcmp(model
, "QLogic-1020"))
761 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
762 "QLogic BR-series 10Gbps dual port CNA");
763 else if (!strcmp(model
, "QLogic-1007"))
764 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
765 "QLogic BR-series 10Gbps CNA for IBM Blade Center");
766 else if (!strcmp(model
, "QLogic-415"))
767 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
768 "QLogic BR-series 4Gbps PCIe single port FC HBA");
769 else if (!strcmp(model
, "QLogic-815"))
770 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
771 "QLogic BR-series 8Gbps PCIe single port FC HBA");
772 else if (!strcmp(model
, "QLogic-41B"))
773 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
774 "QLogic BR-series 4Gbps PCIe single port FC HBA for HP");
775 else if (!strcmp(model
, "QLogic-81B"))
776 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
777 "QLogic BR-series 8Gbps PCIe single port FC HBA for HP");
778 else if (!strcmp(model
, "QLogic-804"))
779 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
780 "QLogic BR-series 8Gbps FC HBA for HP Bladesystem C-class");
781 else if (!strcmp(model
, "QLogic-1741"))
782 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
783 "QLogic BR-series 10Gbps CNA for Dell M-Series Blade Servers");
784 else if (strstr(model
, "QLogic-1860")) {
785 if (nports
== 1 && bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
786 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
787 "QLogic BR-series 10Gbps single port CNA");
788 else if (nports
== 1 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
789 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
790 "QLogic BR-series 16Gbps PCIe single port FC HBA");
791 else if (nports
== 2 && bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
792 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
793 "QLogic BR-series 10Gbps dual port CNA");
794 else if (nports
== 2 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
795 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
796 "QLogic BR-series 16Gbps PCIe dual port FC HBA");
797 } else if (!strcmp(model
, "QLogic-1867")) {
798 if (nports
== 1 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
799 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
800 "QLogic BR-series 16Gbps PCIe single port FC HBA for IBM");
801 else if (nports
== 2 && !bfa_ioc_is_cna(&bfad
->bfa
.ioc
))
802 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
803 "QLogic BR-series 16Gbps PCIe dual port FC HBA for IBM");
805 snprintf(model_descr
, BFA_ADAPTER_MODEL_DESCR_LEN
,
808 return snprintf(buf
, PAGE_SIZE
, "%s\n", model_descr
);
812 bfad_im_node_name_show(struct device
*dev
, struct device_attribute
*attr
,
815 struct Scsi_Host
*shost
= class_to_shost(dev
);
816 struct bfad_im_port_s
*im_port
=
817 (struct bfad_im_port_s
*) shost
->hostdata
[0];
818 struct bfad_port_s
*port
= im_port
->port
;
821 nwwn
= bfa_fcs_lport_get_nwwn(port
->fcs_port
);
822 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n", cpu_to_be64(nwwn
));
826 bfad_im_symbolic_name_show(struct device
*dev
, struct device_attribute
*attr
,
829 struct Scsi_Host
*shost
= class_to_shost(dev
);
830 struct bfad_im_port_s
*im_port
=
831 (struct bfad_im_port_s
*) shost
->hostdata
[0];
832 struct bfad_s
*bfad
= im_port
->bfad
;
833 struct bfa_lport_attr_s port_attr
;
834 char symname
[BFA_SYMNAME_MAXLEN
];
836 bfa_fcs_lport_get_attr(&bfad
->bfa_fcs
.fabric
.bport
, &port_attr
);
837 strlcpy(symname
, port_attr
.port_cfg
.sym_name
.symname
,
839 return snprintf(buf
, PAGE_SIZE
, "%s\n", symname
);
843 bfad_im_hw_version_show(struct device
*dev
, struct device_attribute
*attr
,
846 struct Scsi_Host
*shost
= class_to_shost(dev
);
847 struct bfad_im_port_s
*im_port
=
848 (struct bfad_im_port_s
*) shost
->hostdata
[0];
849 struct bfad_s
*bfad
= im_port
->bfad
;
850 char hw_ver
[BFA_VERSION_LEN
];
852 bfa_get_pci_chip_rev(&bfad
->bfa
, hw_ver
);
853 return snprintf(buf
, PAGE_SIZE
, "%s\n", hw_ver
);
857 bfad_im_drv_version_show(struct device
*dev
, struct device_attribute
*attr
,
860 return snprintf(buf
, PAGE_SIZE
, "%s\n", BFAD_DRIVER_VERSION
);
864 bfad_im_optionrom_version_show(struct device
*dev
,
865 struct device_attribute
*attr
, char *buf
)
867 struct Scsi_Host
*shost
= class_to_shost(dev
);
868 struct bfad_im_port_s
*im_port
=
869 (struct bfad_im_port_s
*) shost
->hostdata
[0];
870 struct bfad_s
*bfad
= im_port
->bfad
;
871 char optrom_ver
[BFA_VERSION_LEN
];
873 bfa_get_adapter_optrom_ver(&bfad
->bfa
, optrom_ver
);
874 return snprintf(buf
, PAGE_SIZE
, "%s\n", optrom_ver
);
878 bfad_im_fw_version_show(struct device
*dev
, struct device_attribute
*attr
,
881 struct Scsi_Host
*shost
= class_to_shost(dev
);
882 struct bfad_im_port_s
*im_port
=
883 (struct bfad_im_port_s
*) shost
->hostdata
[0];
884 struct bfad_s
*bfad
= im_port
->bfad
;
885 char fw_ver
[BFA_VERSION_LEN
];
887 bfa_get_adapter_fw_ver(&bfad
->bfa
, fw_ver
);
888 return snprintf(buf
, PAGE_SIZE
, "%s\n", fw_ver
);
892 bfad_im_num_of_ports_show(struct device
*dev
, struct device_attribute
*attr
,
895 struct Scsi_Host
*shost
= class_to_shost(dev
);
896 struct bfad_im_port_s
*im_port
=
897 (struct bfad_im_port_s
*) shost
->hostdata
[0];
898 struct bfad_s
*bfad
= im_port
->bfad
;
900 return snprintf(buf
, PAGE_SIZE
, "%d\n",
901 bfa_get_nports(&bfad
->bfa
));
905 bfad_im_drv_name_show(struct device
*dev
, struct device_attribute
*attr
,
908 return snprintf(buf
, PAGE_SIZE
, "%s\n", BFAD_DRIVER_NAME
);
912 bfad_im_num_of_discovered_ports_show(struct device
*dev
,
913 struct device_attribute
*attr
, char *buf
)
915 struct Scsi_Host
*shost
= class_to_shost(dev
);
916 struct bfad_im_port_s
*im_port
=
917 (struct bfad_im_port_s
*) shost
->hostdata
[0];
918 struct bfad_port_s
*port
= im_port
->port
;
919 struct bfad_s
*bfad
= im_port
->bfad
;
921 struct bfa_rport_qualifier_s
*rports
= NULL
;
924 rports
= kcalloc(nrports
, sizeof(struct bfa_rport_qualifier_s
),
927 return snprintf(buf
, PAGE_SIZE
, "Failed\n");
929 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
930 bfa_fcs_lport_get_rport_quals(port
->fcs_port
, rports
, &nrports
);
931 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
934 return snprintf(buf
, PAGE_SIZE
, "%d\n", nrports
);
937 static DEVICE_ATTR(serial_number
, S_IRUGO
,
938 bfad_im_serial_num_show
, NULL
);
939 static DEVICE_ATTR(model
, S_IRUGO
, bfad_im_model_show
, NULL
);
940 static DEVICE_ATTR(model_description
, S_IRUGO
,
941 bfad_im_model_desc_show
, NULL
);
942 static DEVICE_ATTR(node_name
, S_IRUGO
, bfad_im_node_name_show
, NULL
);
943 static DEVICE_ATTR(symbolic_name
, S_IRUGO
,
944 bfad_im_symbolic_name_show
, NULL
);
945 static DEVICE_ATTR(hardware_version
, S_IRUGO
,
946 bfad_im_hw_version_show
, NULL
);
947 static DEVICE_ATTR(driver_version
, S_IRUGO
,
948 bfad_im_drv_version_show
, NULL
);
949 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
950 bfad_im_optionrom_version_show
, NULL
);
951 static DEVICE_ATTR(firmware_version
, S_IRUGO
,
952 bfad_im_fw_version_show
, NULL
);
953 static DEVICE_ATTR(number_of_ports
, S_IRUGO
,
954 bfad_im_num_of_ports_show
, NULL
);
955 static DEVICE_ATTR(driver_name
, S_IRUGO
, bfad_im_drv_name_show
, NULL
);
956 static DEVICE_ATTR(number_of_discovered_ports
, S_IRUGO
,
957 bfad_im_num_of_discovered_ports_show
, NULL
);
959 struct device_attribute
*bfad_im_host_attrs
[] = {
960 &dev_attr_serial_number
,
962 &dev_attr_model_description
,
964 &dev_attr_symbolic_name
,
965 &dev_attr_hardware_version
,
966 &dev_attr_driver_version
,
967 &dev_attr_option_rom_version
,
968 &dev_attr_firmware_version
,
969 &dev_attr_number_of_ports
,
970 &dev_attr_driver_name
,
971 &dev_attr_number_of_discovered_ports
,
975 struct device_attribute
*bfad_im_vport_attrs
[] = {
976 &dev_attr_serial_number
,
978 &dev_attr_model_description
,
980 &dev_attr_symbolic_name
,
981 &dev_attr_hardware_version
,
982 &dev_attr_driver_version
,
983 &dev_attr_option_rom_version
,
984 &dev_attr_firmware_version
,
985 &dev_attr_number_of_ports
,
986 &dev_attr_driver_name
,
987 &dev_attr_number_of_discovered_ports
,