HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage()
[linux/fpc-iii.git] / drivers / scsi / bfa / bfad_attr.c
blobe37ab2425e1a1d2f85202e9c83cc3d48119407cb
1 /*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 * bfa_attr.c Linux driver configuration interface module.
22 #include "bfad_drv.h"
23 #include "bfad_im.h"
26 * FC transport template entry, get SCSI target port ID.
28 static void
29 bfad_im_get_starget_port_id(struct scsi_target *starget)
31 struct Scsi_Host *shost;
32 struct bfad_im_port_s *im_port;
33 struct bfad_s *bfad;
34 struct bfad_itnim_s *itnim = NULL;
35 u32 fc_id = -1;
36 unsigned long flags;
38 shost = dev_to_shost(starget->dev.parent);
39 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
40 bfad = im_port->bfad;
41 spin_lock_irqsave(&bfad->bfad_lock, flags);
43 itnim = bfad_get_itnim(im_port, starget->id);
44 if (itnim)
45 fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
47 fc_starget_port_id(starget) = fc_id;
48 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
52 * FC transport template entry, get SCSI target nwwn.
54 static void
55 bfad_im_get_starget_node_name(struct scsi_target *starget)
57 struct Scsi_Host *shost;
58 struct bfad_im_port_s *im_port;
59 struct bfad_s *bfad;
60 struct bfad_itnim_s *itnim = NULL;
61 u64 node_name = 0;
62 unsigned long flags;
64 shost = dev_to_shost(starget->dev.parent);
65 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
66 bfad = im_port->bfad;
67 spin_lock_irqsave(&bfad->bfad_lock, flags);
69 itnim = bfad_get_itnim(im_port, starget->id);
70 if (itnim)
71 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
73 fc_starget_node_name(starget) = cpu_to_be64(node_name);
74 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
78 * FC transport template entry, get SCSI target pwwn.
80 static void
81 bfad_im_get_starget_port_name(struct scsi_target *starget)
83 struct Scsi_Host *shost;
84 struct bfad_im_port_s *im_port;
85 struct bfad_s *bfad;
86 struct bfad_itnim_s *itnim = NULL;
87 u64 port_name = 0;
88 unsigned long flags;
90 shost = dev_to_shost(starget->dev.parent);
91 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
92 bfad = im_port->bfad;
93 spin_lock_irqsave(&bfad->bfad_lock, flags);
95 itnim = bfad_get_itnim(im_port, starget->id);
96 if (itnim)
97 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
99 fc_starget_port_name(starget) = cpu_to_be64(port_name);
100 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
104 * FC transport template entry, get SCSI host port ID.
106 static void
107 bfad_im_get_host_port_id(struct Scsi_Host *shost)
109 struct bfad_im_port_s *im_port =
110 (struct bfad_im_port_s *) shost->hostdata[0];
111 struct bfad_port_s *port = im_port->port;
113 fc_host_port_id(shost) =
114 bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
118 * FC transport template entry, get SCSI host port type.
120 static void
121 bfad_im_get_host_port_type(struct Scsi_Host *shost)
123 struct bfad_im_port_s *im_port =
124 (struct bfad_im_port_s *) shost->hostdata[0];
125 struct bfad_s *bfad = im_port->bfad;
126 struct bfa_lport_attr_s port_attr;
128 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
130 switch (port_attr.port_type) {
131 case BFA_PORT_TYPE_NPORT:
132 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
133 break;
134 case BFA_PORT_TYPE_NLPORT:
135 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
136 break;
137 case BFA_PORT_TYPE_P2P:
138 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
139 break;
140 case BFA_PORT_TYPE_LPORT:
141 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
142 break;
143 default:
144 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
145 break;
150 * FC transport template entry, get SCSI host port state.
152 static void
153 bfad_im_get_host_port_state(struct Scsi_Host *shost)
155 struct bfad_im_port_s *im_port =
156 (struct bfad_im_port_s *) shost->hostdata[0];
157 struct bfad_s *bfad = im_port->bfad;
158 struct bfa_port_attr_s attr;
160 bfa_fcport_get_attr(&bfad->bfa, &attr);
162 switch (attr.port_state) {
163 case BFA_PORT_ST_LINKDOWN:
164 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
165 break;
166 case BFA_PORT_ST_LINKUP:
167 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
168 break;
169 case BFA_PORT_ST_DISABLED:
170 case BFA_PORT_ST_STOPPED:
171 case BFA_PORT_ST_IOCDOWN:
172 case BFA_PORT_ST_IOCDIS:
173 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
174 break;
175 case BFA_PORT_ST_UNINIT:
176 case BFA_PORT_ST_ENABLING_QWAIT:
177 case BFA_PORT_ST_ENABLING:
178 case BFA_PORT_ST_DISABLING_QWAIT:
179 case BFA_PORT_ST_DISABLING:
180 default:
181 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
182 break;
187 * FC transport template entry, get SCSI host active fc4s.
189 static void
190 bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
192 struct bfad_im_port_s *im_port =
193 (struct bfad_im_port_s *) shost->hostdata[0];
194 struct bfad_port_s *port = im_port->port;
196 memset(fc_host_active_fc4s(shost), 0,
197 sizeof(fc_host_active_fc4s(shost)));
199 if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
200 fc_host_active_fc4s(shost)[2] = 1;
202 fc_host_active_fc4s(shost)[7] = 1;
206 * FC transport template entry, get SCSI host link speed.
208 static void
209 bfad_im_get_host_speed(struct Scsi_Host *shost)
211 struct bfad_im_port_s *im_port =
212 (struct bfad_im_port_s *) shost->hostdata[0];
213 struct bfad_s *bfad = im_port->bfad;
214 struct bfa_port_attr_s attr;
216 bfa_fcport_get_attr(&bfad->bfa, &attr);
217 switch (attr.speed) {
218 case BFA_PORT_SPEED_10GBPS:
219 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
220 break;
221 case BFA_PORT_SPEED_16GBPS:
222 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
223 break;
224 case BFA_PORT_SPEED_8GBPS:
225 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
226 break;
227 case BFA_PORT_SPEED_4GBPS:
228 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
229 break;
230 case BFA_PORT_SPEED_2GBPS:
231 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
232 break;
233 case BFA_PORT_SPEED_1GBPS:
234 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
235 break;
236 default:
237 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
238 break;
243 * FC transport template entry, get SCSI host port type.
245 static void
246 bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
248 struct bfad_im_port_s *im_port =
249 (struct bfad_im_port_s *) shost->hostdata[0];
250 struct bfad_port_s *port = im_port->port;
251 wwn_t fabric_nwwn = 0;
253 fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
255 fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
260 * FC transport template entry, get BFAD statistics.
262 static struct fc_host_statistics *
263 bfad_im_get_stats(struct Scsi_Host *shost)
265 struct bfad_im_port_s *im_port =
266 (struct bfad_im_port_s *) shost->hostdata[0];
267 struct bfad_s *bfad = im_port->bfad;
268 struct bfad_hal_comp fcomp;
269 union bfa_port_stats_u *fcstats;
270 struct fc_host_statistics *hstats;
271 bfa_status_t rc;
272 unsigned long flags;
274 fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
275 if (fcstats == NULL)
276 return NULL;
278 hstats = &bfad->link_stats;
279 init_completion(&fcomp.comp);
280 spin_lock_irqsave(&bfad->bfad_lock, flags);
281 memset(hstats, 0, sizeof(struct fc_host_statistics));
282 rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
283 fcstats, bfad_hcb_comp, &fcomp);
284 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
285 if (rc != BFA_STATUS_OK) {
286 kfree(fcstats);
287 return NULL;
290 wait_for_completion(&fcomp.comp);
292 /* Fill the fc_host_statistics structure */
293 hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
294 hstats->tx_frames = fcstats->fc.tx_frames;
295 hstats->tx_words = fcstats->fc.tx_words;
296 hstats->rx_frames = fcstats->fc.rx_frames;
297 hstats->rx_words = fcstats->fc.rx_words;
298 hstats->lip_count = fcstats->fc.lip_count;
299 hstats->nos_count = fcstats->fc.nos_count;
300 hstats->error_frames = fcstats->fc.error_frames;
301 hstats->dumped_frames = fcstats->fc.dropped_frames;
302 hstats->link_failure_count = fcstats->fc.link_failures;
303 hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
304 hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
305 hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
306 hstats->invalid_crc_count = fcstats->fc.invalid_crcs;
308 kfree(fcstats);
309 return hstats;
313 * FC transport template entry, reset BFAD statistics.
315 static void
316 bfad_im_reset_stats(struct Scsi_Host *shost)
318 struct bfad_im_port_s *im_port =
319 (struct bfad_im_port_s *) shost->hostdata[0];
320 struct bfad_s *bfad = im_port->bfad;
321 struct bfad_hal_comp fcomp;
322 unsigned long flags;
323 bfa_status_t rc;
325 init_completion(&fcomp.comp);
326 spin_lock_irqsave(&bfad->bfad_lock, flags);
327 rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
328 &fcomp);
329 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
331 if (rc != BFA_STATUS_OK)
332 return;
334 wait_for_completion(&fcomp.comp);
336 return;
340 * FC transport template entry, set rport loss timeout.
341 * Update dev_loss_tmo based on the value pushed down by the stack
342 * In case it is lesser than path_tov of driver, set it to path_tov + 1
343 * to ensure that the driver times out before the application
345 static void
346 bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
348 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
349 struct bfad_itnim_s *itnim = itnim_data->itnim;
350 struct bfad_s *bfad = itnim->im->bfad;
351 uint16_t path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
353 rport->dev_loss_tmo = timeout;
354 if (timeout < path_tov)
355 rport->dev_loss_tmo = path_tov + 1;
358 static int
359 bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
361 char *vname = fc_vport->symbolic_name;
362 struct Scsi_Host *shost = fc_vport->shost;
363 struct bfad_im_port_s *im_port =
364 (struct bfad_im_port_s *) shost->hostdata[0];
365 struct bfad_s *bfad = im_port->bfad;
366 struct bfa_lport_cfg_s port_cfg;
367 struct bfad_vport_s *vp;
368 int status = 0, rc;
369 unsigned long flags;
371 memset(&port_cfg, 0, sizeof(port_cfg));
372 u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
373 u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
374 if (strlen(vname) > 0)
375 strcpy((char *)&port_cfg.sym_name, vname);
376 port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
378 spin_lock_irqsave(&bfad->bfad_lock, flags);
379 list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
380 if (port_cfg.pwwn ==
381 vp->fcs_vport.lport.port_cfg.pwwn) {
382 port_cfg.preboot_vp =
383 vp->fcs_vport.lport.port_cfg.preboot_vp;
384 break;
387 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
389 rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
390 if (rc == BFA_STATUS_OK) {
391 struct bfad_vport_s *vport;
392 struct bfa_fcs_vport_s *fcs_vport;
393 struct Scsi_Host *vshost;
395 spin_lock_irqsave(&bfad->bfad_lock, flags);
396 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
397 port_cfg.pwwn);
398 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
399 if (fcs_vport == NULL)
400 return VPCERR_BAD_WWN;
402 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
403 if (disable) {
404 spin_lock_irqsave(&bfad->bfad_lock, flags);
405 bfa_fcs_vport_stop(fcs_vport);
406 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
407 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
410 vport = fcs_vport->vport_drv;
411 vshost = vport->drv_port.im_port->shost;
412 fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
413 fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
414 fc_host_supported_classes(vshost) = FC_COS_CLASS3;
416 memset(fc_host_supported_fc4s(vshost), 0,
417 sizeof(fc_host_supported_fc4s(vshost)));
419 /* For FCP type 0x08 */
420 if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
421 fc_host_supported_fc4s(vshost)[2] = 1;
423 /* For fibre channel services type 0x20 */
424 fc_host_supported_fc4s(vshost)[7] = 1;
426 fc_host_supported_speeds(vshost) =
427 bfad_im_supported_speeds(&bfad->bfa);
428 fc_host_maxframe_size(vshost) =
429 bfa_fcport_get_maxfrsize(&bfad->bfa);
431 fc_vport->dd_data = vport;
432 vport->drv_port.im_port->fc_vport = fc_vport;
433 } else if (rc == BFA_STATUS_INVALID_WWN)
434 return VPCERR_BAD_WWN;
435 else if (rc == BFA_STATUS_VPORT_EXISTS)
436 return VPCERR_BAD_WWN;
437 else if (rc == BFA_STATUS_VPORT_MAX)
438 return VPCERR_NO_FABRIC_SUPP;
439 else if (rc == BFA_STATUS_VPORT_WWN_BP)
440 return VPCERR_BAD_WWN;
441 else
442 return FC_VPORT_FAILED;
444 return status;
448 bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
450 struct bfad_im_port_s *im_port =
451 (struct bfad_im_port_s *) shost->hostdata[0];
452 struct bfad_s *bfad = im_port->bfad;
453 struct bfad_hal_comp fcomp;
454 unsigned long flags;
455 uint32_t status;
457 init_completion(&fcomp.comp);
458 spin_lock_irqsave(&bfad->bfad_lock, flags);
459 status = bfa_port_disable(&bfad->bfa.modules.port,
460 bfad_hcb_comp, &fcomp);
461 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
463 if (status != BFA_STATUS_OK)
464 return -EIO;
466 wait_for_completion(&fcomp.comp);
467 if (fcomp.status != BFA_STATUS_OK)
468 return -EIO;
470 spin_lock_irqsave(&bfad->bfad_lock, flags);
471 status = bfa_port_enable(&bfad->bfa.modules.port,
472 bfad_hcb_comp, &fcomp);
473 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
474 if (status != BFA_STATUS_OK)
475 return -EIO;
477 wait_for_completion(&fcomp.comp);
478 if (fcomp.status != BFA_STATUS_OK)
479 return -EIO;
481 return 0;
484 static int
485 bfad_im_vport_delete(struct fc_vport *fc_vport)
487 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
488 struct bfad_im_port_s *im_port =
489 (struct bfad_im_port_s *) vport->drv_port.im_port;
490 struct bfad_s *bfad = im_port->bfad;
491 struct bfad_port_s *port;
492 struct bfa_fcs_vport_s *fcs_vport;
493 struct Scsi_Host *vshost;
494 wwn_t pwwn;
495 int rc;
496 unsigned long flags;
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);
502 kfree(vport);
503 return 0;
506 port = im_port->port;
508 vshost = vport->drv_port.im_port->shost;
509 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
511 spin_lock_irqsave(&bfad->bfad_lock, flags);
512 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
513 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
515 if (fcs_vport == NULL)
516 return VPCERR_BAD_WWN;
518 vport->drv_port.flags |= BFAD_PORT_DELETE;
520 vport->comp_del = &fcomp;
521 init_completion(vport->comp_del);
523 spin_lock_irqsave(&bfad->bfad_lock, flags);
524 rc = bfa_fcs_vport_delete(&vport->fcs_vport);
525 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
527 if (rc == BFA_STATUS_PBC) {
528 vport->drv_port.flags &= ~BFAD_PORT_DELETE;
529 vport->comp_del = NULL;
530 return -1;
533 wait_for_completion(vport->comp_del);
535 bfad_scsi_host_free(bfad, im_port);
536 list_del(&vport->list_entry);
537 kfree(vport);
539 return 0;
542 static int
543 bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
545 struct bfad_vport_s *vport;
546 struct bfad_s *bfad;
547 struct bfa_fcs_vport_s *fcs_vport;
548 struct Scsi_Host *vshost;
549 wwn_t pwwn;
550 unsigned long flags;
552 vport = (struct bfad_vport_s *)fc_vport->dd_data;
553 bfad = vport->drv_port.bfad;
554 vshost = vport->drv_port.im_port->shost;
555 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
557 spin_lock_irqsave(&bfad->bfad_lock, flags);
558 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
559 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
561 if (fcs_vport == NULL)
562 return VPCERR_BAD_WWN;
564 if (disable) {
565 bfa_fcs_vport_stop(fcs_vport);
566 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
567 } else {
568 bfa_fcs_vport_start(fcs_vport);
569 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
572 return 0;
575 void
576 bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport)
578 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
579 struct bfad_im_port_s *im_port =
580 (struct bfad_im_port_s *)vport->drv_port.im_port;
581 struct bfad_s *bfad = im_port->bfad;
582 struct Scsi_Host *vshost = vport->drv_port.im_port->shost;
583 char *sym_name = fc_vport->symbolic_name;
584 struct bfa_fcs_vport_s *fcs_vport;
585 wwn_t pwwn;
586 unsigned long flags;
588 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
590 spin_lock_irqsave(&bfad->bfad_lock, flags);
591 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
592 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
594 if (fcs_vport == NULL)
595 return;
597 spin_lock_irqsave(&bfad->bfad_lock, flags);
598 if (strlen(sym_name) > 0)
599 bfa_fcs_lport_set_symname(&fcs_vport->lport, sym_name);
600 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
603 struct fc_function_template bfad_im_fc_function_template = {
605 /* Target dynamic attributes */
606 .get_starget_port_id = bfad_im_get_starget_port_id,
607 .show_starget_port_id = 1,
608 .get_starget_node_name = bfad_im_get_starget_node_name,
609 .show_starget_node_name = 1,
610 .get_starget_port_name = bfad_im_get_starget_port_name,
611 .show_starget_port_name = 1,
613 /* Host dynamic attribute */
614 .get_host_port_id = bfad_im_get_host_port_id,
615 .show_host_port_id = 1,
617 /* Host fixed attributes */
618 .show_host_node_name = 1,
619 .show_host_port_name = 1,
620 .show_host_supported_classes = 1,
621 .show_host_supported_fc4s = 1,
622 .show_host_supported_speeds = 1,
623 .show_host_maxframe_size = 1,
625 /* More host dynamic attributes */
626 .show_host_port_type = 1,
627 .get_host_port_type = bfad_im_get_host_port_type,
628 .show_host_port_state = 1,
629 .get_host_port_state = bfad_im_get_host_port_state,
630 .show_host_active_fc4s = 1,
631 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
632 .show_host_speed = 1,
633 .get_host_speed = bfad_im_get_host_speed,
634 .show_host_fabric_name = 1,
635 .get_host_fabric_name = bfad_im_get_host_fabric_name,
637 .show_host_symbolic_name = 1,
639 /* Statistics */
640 .get_fc_host_stats = bfad_im_get_stats,
641 .reset_fc_host_stats = bfad_im_reset_stats,
643 /* Allocation length for host specific data */
644 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
646 /* Remote port fixed attributes */
647 .show_rport_maxframe_size = 1,
648 .show_rport_supported_classes = 1,
649 .show_rport_dev_loss_tmo = 1,
650 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
651 .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
652 .vport_create = bfad_im_vport_create,
653 .vport_delete = bfad_im_vport_delete,
654 .vport_disable = bfad_im_vport_disable,
655 .set_vport_symbolic_name = bfad_im_vport_set_symbolic_name,
656 .bsg_request = bfad_im_bsg_request,
657 .bsg_timeout = bfad_im_bsg_timeout,
660 struct fc_function_template bfad_im_vport_fc_function_template = {
662 /* Target dynamic attributes */
663 .get_starget_port_id = bfad_im_get_starget_port_id,
664 .show_starget_port_id = 1,
665 .get_starget_node_name = bfad_im_get_starget_node_name,
666 .show_starget_node_name = 1,
667 .get_starget_port_name = bfad_im_get_starget_port_name,
668 .show_starget_port_name = 1,
670 /* Host dynamic attribute */
671 .get_host_port_id = bfad_im_get_host_port_id,
672 .show_host_port_id = 1,
674 /* Host fixed attributes */
675 .show_host_node_name = 1,
676 .show_host_port_name = 1,
677 .show_host_supported_classes = 1,
678 .show_host_supported_fc4s = 1,
679 .show_host_supported_speeds = 1,
680 .show_host_maxframe_size = 1,
682 /* More host dynamic attributes */
683 .show_host_port_type = 1,
684 .get_host_port_type = bfad_im_get_host_port_type,
685 .show_host_port_state = 1,
686 .get_host_port_state = bfad_im_get_host_port_state,
687 .show_host_active_fc4s = 1,
688 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
689 .show_host_speed = 1,
690 .get_host_speed = bfad_im_get_host_speed,
691 .show_host_fabric_name = 1,
692 .get_host_fabric_name = bfad_im_get_host_fabric_name,
694 .show_host_symbolic_name = 1,
696 /* Statistics */
697 .get_fc_host_stats = bfad_im_get_stats,
698 .reset_fc_host_stats = bfad_im_reset_stats,
700 /* Allocation length for host specific data */
701 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
703 /* Remote port fixed attributes */
704 .show_rport_maxframe_size = 1,
705 .show_rport_supported_classes = 1,
706 .show_rport_dev_loss_tmo = 1,
707 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
711 * Scsi_Host_attrs SCSI host attributes
713 static ssize_t
714 bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
715 char *buf)
717 struct Scsi_Host *shost = class_to_shost(dev);
718 struct bfad_im_port_s *im_port =
719 (struct bfad_im_port_s *) shost->hostdata[0];
720 struct bfad_s *bfad = im_port->bfad;
721 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
723 bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
724 return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
727 static ssize_t
728 bfad_im_model_show(struct device *dev, struct device_attribute *attr,
729 char *buf)
731 struct Scsi_Host *shost = class_to_shost(dev);
732 struct bfad_im_port_s *im_port =
733 (struct bfad_im_port_s *) shost->hostdata[0];
734 struct bfad_s *bfad = im_port->bfad;
735 char model[BFA_ADAPTER_MODEL_NAME_LEN];
737 bfa_get_adapter_model(&bfad->bfa, model);
738 return snprintf(buf, PAGE_SIZE, "%s\n", model);
741 static ssize_t
742 bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
743 char *buf)
745 struct Scsi_Host *shost = class_to_shost(dev);
746 struct bfad_im_port_s *im_port =
747 (struct bfad_im_port_s *) shost->hostdata[0];
748 struct bfad_s *bfad = im_port->bfad;
749 char model[BFA_ADAPTER_MODEL_NAME_LEN];
750 char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
751 int nports = 0;
753 bfa_get_adapter_model(&bfad->bfa, model);
754 nports = bfa_get_nports(&bfad->bfa);
755 if (!strcmp(model, "Brocade-425"))
756 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
757 "Brocade 4Gbps PCIe dual port FC HBA");
758 else if (!strcmp(model, "Brocade-825"))
759 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
760 "Brocade 8Gbps PCIe dual port FC HBA");
761 else if (!strcmp(model, "Brocade-42B"))
762 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
763 "Brocade 4Gbps PCIe dual port FC HBA for HP");
764 else if (!strcmp(model, "Brocade-82B"))
765 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
766 "Brocade 8Gbps PCIe dual port FC HBA for HP");
767 else if (!strcmp(model, "Brocade-1010"))
768 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
769 "Brocade 10Gbps single port CNA");
770 else if (!strcmp(model, "Brocade-1020"))
771 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
772 "Brocade 10Gbps dual port CNA");
773 else if (!strcmp(model, "Brocade-1007"))
774 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
775 "Brocade 10Gbps CNA for IBM Blade Center");
776 else if (!strcmp(model, "Brocade-415"))
777 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
778 "Brocade 4Gbps PCIe single port FC HBA");
779 else if (!strcmp(model, "Brocade-815"))
780 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
781 "Brocade 8Gbps PCIe single port FC HBA");
782 else if (!strcmp(model, "Brocade-41B"))
783 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
784 "Brocade 4Gbps PCIe single port FC HBA for HP");
785 else if (!strcmp(model, "Brocade-81B"))
786 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
787 "Brocade 8Gbps PCIe single port FC HBA for HP");
788 else if (!strcmp(model, "Brocade-804"))
789 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
790 "Brocade 8Gbps FC HBA for HP Bladesystem C-class");
791 else if (!strcmp(model, "Brocade-1741"))
792 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
793 "Brocade 10Gbps CNA for Dell M-Series Blade Servers");
794 else if (strstr(model, "Brocade-1860")) {
795 if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
796 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
797 "Brocade 10Gbps single port CNA");
798 else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
799 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
800 "Brocade 16Gbps PCIe single port FC HBA");
801 else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
802 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
803 "Brocade 10Gbps dual port CNA");
804 else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
805 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
806 "Brocade 16Gbps PCIe dual port FC HBA");
807 } else if (!strcmp(model, "Brocade-1867")) {
808 if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
809 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
810 "Brocade 16Gbps PCIe single port FC HBA for IBM");
811 else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
812 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
813 "Brocade 16Gbps PCIe dual port FC HBA for IBM");
814 } else
815 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
816 "Invalid Model");
818 return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
821 static ssize_t
822 bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
823 char *buf)
825 struct Scsi_Host *shost = class_to_shost(dev);
826 struct bfad_im_port_s *im_port =
827 (struct bfad_im_port_s *) shost->hostdata[0];
828 struct bfad_port_s *port = im_port->port;
829 u64 nwwn;
831 nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
832 return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
835 static ssize_t
836 bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
837 char *buf)
839 struct Scsi_Host *shost = class_to_shost(dev);
840 struct bfad_im_port_s *im_port =
841 (struct bfad_im_port_s *) shost->hostdata[0];
842 struct bfad_s *bfad = im_port->bfad;
843 struct bfa_lport_attr_s port_attr;
844 char symname[BFA_SYMNAME_MAXLEN];
846 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
847 strlcpy(symname, port_attr.port_cfg.sym_name.symname,
848 BFA_SYMNAME_MAXLEN);
849 return snprintf(buf, PAGE_SIZE, "%s\n", symname);
852 static ssize_t
853 bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
854 char *buf)
856 struct Scsi_Host *shost = class_to_shost(dev);
857 struct bfad_im_port_s *im_port =
858 (struct bfad_im_port_s *) shost->hostdata[0];
859 struct bfad_s *bfad = im_port->bfad;
860 char hw_ver[BFA_VERSION_LEN];
862 bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
863 return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
866 static ssize_t
867 bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
868 char *buf)
870 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
873 static ssize_t
874 bfad_im_optionrom_version_show(struct device *dev,
875 struct device_attribute *attr, char *buf)
877 struct Scsi_Host *shost = class_to_shost(dev);
878 struct bfad_im_port_s *im_port =
879 (struct bfad_im_port_s *) shost->hostdata[0];
880 struct bfad_s *bfad = im_port->bfad;
881 char optrom_ver[BFA_VERSION_LEN];
883 bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
884 return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
887 static ssize_t
888 bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
889 char *buf)
891 struct Scsi_Host *shost = class_to_shost(dev);
892 struct bfad_im_port_s *im_port =
893 (struct bfad_im_port_s *) shost->hostdata[0];
894 struct bfad_s *bfad = im_port->bfad;
895 char fw_ver[BFA_VERSION_LEN];
897 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
898 return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
901 static ssize_t
902 bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
903 char *buf)
905 struct Scsi_Host *shost = class_to_shost(dev);
906 struct bfad_im_port_s *im_port =
907 (struct bfad_im_port_s *) shost->hostdata[0];
908 struct bfad_s *bfad = im_port->bfad;
910 return snprintf(buf, PAGE_SIZE, "%d\n",
911 bfa_get_nports(&bfad->bfa));
914 static ssize_t
915 bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
916 char *buf)
918 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
921 static ssize_t
922 bfad_im_num_of_discovered_ports_show(struct device *dev,
923 struct device_attribute *attr, char *buf)
925 struct Scsi_Host *shost = class_to_shost(dev);
926 struct bfad_im_port_s *im_port =
927 (struct bfad_im_port_s *) shost->hostdata[0];
928 struct bfad_port_s *port = im_port->port;
929 struct bfad_s *bfad = im_port->bfad;
930 int nrports = 2048;
931 struct bfa_rport_qualifier_s *rports = NULL;
932 unsigned long flags;
934 rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports,
935 GFP_ATOMIC);
936 if (rports == NULL)
937 return snprintf(buf, PAGE_SIZE, "Failed\n");
939 spin_lock_irqsave(&bfad->bfad_lock, flags);
940 bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports);
941 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
942 kfree(rports);
944 return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
947 static DEVICE_ATTR(serial_number, S_IRUGO,
948 bfad_im_serial_num_show, NULL);
949 static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
950 static DEVICE_ATTR(model_description, S_IRUGO,
951 bfad_im_model_desc_show, NULL);
952 static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
953 static DEVICE_ATTR(symbolic_name, S_IRUGO,
954 bfad_im_symbolic_name_show, NULL);
955 static DEVICE_ATTR(hardware_version, S_IRUGO,
956 bfad_im_hw_version_show, NULL);
957 static DEVICE_ATTR(driver_version, S_IRUGO,
958 bfad_im_drv_version_show, NULL);
959 static DEVICE_ATTR(option_rom_version, S_IRUGO,
960 bfad_im_optionrom_version_show, NULL);
961 static DEVICE_ATTR(firmware_version, S_IRUGO,
962 bfad_im_fw_version_show, NULL);
963 static DEVICE_ATTR(number_of_ports, S_IRUGO,
964 bfad_im_num_of_ports_show, NULL);
965 static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
966 static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
967 bfad_im_num_of_discovered_ports_show, NULL);
969 struct device_attribute *bfad_im_host_attrs[] = {
970 &dev_attr_serial_number,
971 &dev_attr_model,
972 &dev_attr_model_description,
973 &dev_attr_node_name,
974 &dev_attr_symbolic_name,
975 &dev_attr_hardware_version,
976 &dev_attr_driver_version,
977 &dev_attr_option_rom_version,
978 &dev_attr_firmware_version,
979 &dev_attr_number_of_ports,
980 &dev_attr_driver_name,
981 &dev_attr_number_of_discovered_ports,
982 NULL,
985 struct device_attribute *bfad_im_vport_attrs[] = {
986 &dev_attr_serial_number,
987 &dev_attr_model,
988 &dev_attr_model_description,
989 &dev_attr_node_name,
990 &dev_attr_symbolic_name,
991 &dev_attr_hardware_version,
992 &dev_attr_driver_version,
993 &dev_attr_option_rom_version,
994 &dev_attr_firmware_version,
995 &dev_attr_number_of_ports,
996 &dev_attr_driver_name,
997 &dev_attr_number_of_discovered_ports,
998 NULL,