blob: dd5cb20d4b3785259a538d74fcd686368b25aeaa [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
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
11 *
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.
16 */
17
18/**
19 * bfa_attr.c Linux driver configuration interface module.
20 */
21
22#include "bfad_drv.h"
23#include "bfad_im.h"
24#include "bfad_trcmod.h"
25#include "bfad_attr.h"
26
27/**
28 * FC_transport_template FC transport template
29 */
30
31/**
32 * FC transport template entry, get SCSI target port ID.
33 */
34void
35bfad_im_get_starget_port_id(struct scsi_target *starget)
36{
37 struct Scsi_Host *shost;
38 struct bfad_im_port_s *im_port;
39 struct bfad_s *bfad;
40 struct bfad_itnim_s *itnim = NULL;
41 u32 fc_id = -1;
42 unsigned long flags;
43
44 shost = bfad_os_starget_to_shost(starget);
45 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
46 bfad = im_port->bfad;
47 spin_lock_irqsave(&bfad->bfad_lock, flags);
48
49 itnim = bfad_os_get_itnim(im_port, starget->id);
50 if (itnim)
51 fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
52
53 fc_starget_port_id(starget) = fc_id;
54 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
55}
56
57/**
58 * FC transport template entry, get SCSI target nwwn.
59 */
60void
61bfad_im_get_starget_node_name(struct scsi_target *starget)
62{
63 struct Scsi_Host *shost;
64 struct bfad_im_port_s *im_port;
65 struct bfad_s *bfad;
66 struct bfad_itnim_s *itnim = NULL;
67 u64 node_name = 0;
68 unsigned long flags;
69
70 shost = bfad_os_starget_to_shost(starget);
71 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
72 bfad = im_port->bfad;
73 spin_lock_irqsave(&bfad->bfad_lock, flags);
74
75 itnim = bfad_os_get_itnim(im_port, starget->id);
76 if (itnim)
77 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
78
79 fc_starget_node_name(starget) = bfa_os_htonll(node_name);
80 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
81}
82
83/**
84 * FC transport template entry, get SCSI target pwwn.
85 */
86void
87bfad_im_get_starget_port_name(struct scsi_target *starget)
88{
89 struct Scsi_Host *shost;
90 struct bfad_im_port_s *im_port;
91 struct bfad_s *bfad;
92 struct bfad_itnim_s *itnim = NULL;
93 u64 port_name = 0;
94 unsigned long flags;
95
96 shost = bfad_os_starget_to_shost(starget);
97 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
98 bfad = im_port->bfad;
99 spin_lock_irqsave(&bfad->bfad_lock, flags);
100
101 itnim = bfad_os_get_itnim(im_port, starget->id);
102 if (itnim)
103 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
104
105 fc_starget_port_name(starget) = bfa_os_htonll(port_name);
106 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
107}
108
109/**
110 * FC transport template entry, get SCSI host port ID.
111 */
112void
113bfad_im_get_host_port_id(struct Scsi_Host *shost)
114{
115 struct bfad_im_port_s *im_port =
116 (struct bfad_im_port_s *) shost->hostdata[0];
117 struct bfad_port_s *port = im_port->port;
118
119 fc_host_port_id(shost) =
120 bfa_os_hton3b(bfa_fcs_port_get_fcid(port->fcs_port));
121}
122
123
124
125
126
127struct Scsi_Host *
128bfad_os_starget_to_shost(struct scsi_target *starget)
129{
130 return dev_to_shost(starget->dev.parent);
131}
132
133/**
134 * FC transport template entry, get SCSI host port type.
135 */
136static void
137bfad_im_get_host_port_type(struct Scsi_Host *shost)
138{
139 struct bfad_im_port_s *im_port =
140 (struct bfad_im_port_s *) shost->hostdata[0];
141 struct bfad_s *bfad = im_port->bfad;
142 struct bfa_pport_attr_s attr;
143
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800144 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700145
146 switch (attr.port_type) {
147 case BFA_PPORT_TYPE_NPORT:
148 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
149 break;
150 case BFA_PPORT_TYPE_NLPORT:
151 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
152 break;
153 case BFA_PPORT_TYPE_P2P:
154 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
155 break;
156 case BFA_PPORT_TYPE_LPORT:
157 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
158 break;
159 default:
160 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
161 break;
162 }
163}
164
165/**
166 * FC transport template entry, get SCSI host port state.
167 */
168static void
169bfad_im_get_host_port_state(struct Scsi_Host *shost)
170{
171 struct bfad_im_port_s *im_port =
172 (struct bfad_im_port_s *) shost->hostdata[0];
173 struct bfad_s *bfad = im_port->bfad;
174 struct bfa_pport_attr_s attr;
175
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800176 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700177
178 switch (attr.port_state) {
179 case BFA_PPORT_ST_LINKDOWN:
180 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
181 break;
182 case BFA_PPORT_ST_LINKUP:
183 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
184 break;
185 case BFA_PPORT_ST_UNINIT:
186 case BFA_PPORT_ST_ENABLING_QWAIT:
187 case BFA_PPORT_ST_ENABLING:
188 case BFA_PPORT_ST_DISABLING_QWAIT:
189 case BFA_PPORT_ST_DISABLING:
190 case BFA_PPORT_ST_DISABLED:
191 case BFA_PPORT_ST_STOPPED:
192 case BFA_PPORT_ST_IOCDOWN:
193 default:
194 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
195 break;
196 }
197}
198
199/**
200 * FC transport template entry, get SCSI host active fc4s.
201 */
202static void
203bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
204{
205 struct bfad_im_port_s *im_port =
206 (struct bfad_im_port_s *) shost->hostdata[0];
207 struct bfad_port_s *port = im_port->port;
208
209 memset(fc_host_active_fc4s(shost), 0,
210 sizeof(fc_host_active_fc4s(shost)));
211
212 if (port->supported_fc4s &
213 (BFA_PORT_ROLE_FCP_IM | BFA_PORT_ROLE_FCP_TM))
214 fc_host_active_fc4s(shost)[2] = 1;
215
216 if (port->supported_fc4s & BFA_PORT_ROLE_FCP_IPFC)
217 fc_host_active_fc4s(shost)[3] = 0x20;
218
219 fc_host_active_fc4s(shost)[7] = 1;
220}
221
222/**
223 * FC transport template entry, get SCSI host link speed.
224 */
225static void
226bfad_im_get_host_speed(struct Scsi_Host *shost)
227{
228 struct bfad_im_port_s *im_port =
229 (struct bfad_im_port_s *) shost->hostdata[0];
230 struct bfad_s *bfad = im_port->bfad;
231 struct bfa_pport_attr_s attr;
Krishna Gudipati4c147dd2010-03-03 17:42:11 -0800232 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700233
Krishna Gudipati4c147dd2010-03-03 17:42:11 -0800234 spin_lock_irqsave(shost->host_lock, flags);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800235 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700236 switch (attr.speed) {
237 case BFA_PPORT_SPEED_8GBPS:
238 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
239 break;
240 case BFA_PPORT_SPEED_4GBPS:
241 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
242 break;
243 case BFA_PPORT_SPEED_2GBPS:
244 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
245 break;
246 case BFA_PPORT_SPEED_1GBPS:
247 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
248 break;
249 default:
250 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
251 break;
252 }
Krishna Gudipati4c147dd2010-03-03 17:42:11 -0800253 spin_unlock_irqrestore(shost->host_lock, flags);
Jing Huang7725ccf2009-09-23 17:46:15 -0700254}
255
256/**
257 * FC transport template entry, get SCSI host port type.
258 */
259static void
260bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
261{
262 struct bfad_im_port_s *im_port =
263 (struct bfad_im_port_s *) shost->hostdata[0];
264 struct bfad_port_s *port = im_port->port;
265 wwn_t fabric_nwwn = 0;
266
267 fabric_nwwn = bfa_fcs_port_get_fabric_name(port->fcs_port);
268
269 fc_host_fabric_name(shost) = bfa_os_htonll(fabric_nwwn);
270
271}
272
273/**
274 * FC transport template entry, get BFAD statistics.
275 */
276static struct fc_host_statistics *
277bfad_im_get_stats(struct Scsi_Host *shost)
278{
279 struct bfad_im_port_s *im_port =
280 (struct bfad_im_port_s *) shost->hostdata[0];
281 struct bfad_s *bfad = im_port->bfad;
282 struct bfad_hal_comp fcomp;
283 struct fc_host_statistics *hstats;
284 bfa_status_t rc;
285 unsigned long flags;
286
287 hstats = &bfad->link_stats;
288 init_completion(&fcomp.comp);
289 spin_lock_irqsave(&bfad->bfad_lock, flags);
290 memset(hstats, 0, sizeof(struct fc_host_statistics));
291 rc = bfa_pport_get_stats(&bfad->bfa,
292 (union bfa_pport_stats_u *) hstats,
293 bfad_hcb_comp, &fcomp);
294 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
295 if (rc != BFA_STATUS_OK)
296 return NULL;
297
298 wait_for_completion(&fcomp.comp);
299
300 return hstats;
301}
302
303/**
304 * FC transport template entry, reset BFAD statistics.
305 */
306static void
307bfad_im_reset_stats(struct Scsi_Host *shost)
308{
309 struct bfad_im_port_s *im_port =
310 (struct bfad_im_port_s *) shost->hostdata[0];
311 struct bfad_s *bfad = im_port->bfad;
312 struct bfad_hal_comp fcomp;
313 unsigned long flags;
314 bfa_status_t rc;
315
316 init_completion(&fcomp.comp);
317 spin_lock_irqsave(&bfad->bfad_lock, flags);
318 rc = bfa_pport_clear_stats(&bfad->bfa, bfad_hcb_comp, &fcomp);
319 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
320
321 if (rc != BFA_STATUS_OK)
322 return;
323
324 wait_for_completion(&fcomp.comp);
325
326 return;
327}
328
329/**
330 * FC transport template entry, get rport loss timeout.
331 */
332static void
333bfad_im_get_rport_loss_tmo(struct fc_rport *rport)
334{
335 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
336 struct bfad_itnim_s *itnim = itnim_data->itnim;
337 struct bfad_s *bfad = itnim->im->bfad;
338 unsigned long flags;
339
340 spin_lock_irqsave(&bfad->bfad_lock, flags);
341 rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
342 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
343}
344
345/**
346 * FC transport template entry, set rport loss timeout.
347 */
348static void
349bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
350{
351 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
352 struct bfad_itnim_s *itnim = itnim_data->itnim;
353 struct bfad_s *bfad = itnim->im->bfad;
354 unsigned long flags;
355
356 if (timeout > 0) {
357 spin_lock_irqsave(&bfad->bfad_lock, flags);
358 bfa_fcpim_path_tov_set(&bfad->bfa, timeout);
359 rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
360 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
361 }
362
363}
364
365struct fc_function_template bfad_im_fc_function_template = {
366
367 /* Target dynamic attributes */
368 .get_starget_port_id = bfad_im_get_starget_port_id,
369 .show_starget_port_id = 1,
370 .get_starget_node_name = bfad_im_get_starget_node_name,
371 .show_starget_node_name = 1,
372 .get_starget_port_name = bfad_im_get_starget_port_name,
373 .show_starget_port_name = 1,
374
375 /* Host dynamic attribute */
376 .get_host_port_id = bfad_im_get_host_port_id,
377 .show_host_port_id = 1,
378
379 /* Host fixed attributes */
380 .show_host_node_name = 1,
381 .show_host_port_name = 1,
382 .show_host_supported_classes = 1,
383 .show_host_supported_fc4s = 1,
384 .show_host_supported_speeds = 1,
385 .show_host_maxframe_size = 1,
386
387 /* More host dynamic attributes */
388 .show_host_port_type = 1,
389 .get_host_port_type = bfad_im_get_host_port_type,
390 .show_host_port_state = 1,
391 .get_host_port_state = bfad_im_get_host_port_state,
392 .show_host_active_fc4s = 1,
393 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
394 .show_host_speed = 1,
395 .get_host_speed = bfad_im_get_host_speed,
396 .show_host_fabric_name = 1,
397 .get_host_fabric_name = bfad_im_get_host_fabric_name,
398
399 .show_host_symbolic_name = 1,
400
401 /* Statistics */
402 .get_fc_host_stats = bfad_im_get_stats,
403 .reset_fc_host_stats = bfad_im_reset_stats,
404
405 /* Allocation length for host specific data */
406 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
407
408 /* Remote port fixed attributes */
409 .show_rport_maxframe_size = 1,
410 .show_rport_supported_classes = 1,
411 .show_rport_dev_loss_tmo = 1,
412 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
413 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
414};
415
416/**
417 * Scsi_Host_attrs SCSI host attributes
418 */
419static ssize_t
420bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
421 char *buf)
422{
423 struct Scsi_Host *shost = class_to_shost(dev);
424 struct bfad_im_port_s *im_port =
425 (struct bfad_im_port_s *) shost->hostdata[0];
426 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800427 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700428
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800429 bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
430 return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
Jing Huang7725ccf2009-09-23 17:46:15 -0700431}
432
433static ssize_t
434bfad_im_model_show(struct device *dev, struct device_attribute *attr,
435 char *buf)
436{
437 struct Scsi_Host *shost = class_to_shost(dev);
438 struct bfad_im_port_s *im_port =
439 (struct bfad_im_port_s *) shost->hostdata[0];
440 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800441 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700442
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800443 bfa_get_adapter_model(&bfad->bfa, model);
444 return snprintf(buf, PAGE_SIZE, "%s\n", model);
Jing Huang7725ccf2009-09-23 17:46:15 -0700445}
446
447static ssize_t
448bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
449 char *buf)
450{
451 struct Scsi_Host *shost = class_to_shost(dev);
452 struct bfad_im_port_s *im_port =
453 (struct bfad_im_port_s *) shost->hostdata[0];
454 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800455 char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700456
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800457 bfa_get_adapter_model(&bfad->bfa, model_descr);
458 return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700459}
460
461static ssize_t
462bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
463 char *buf)
464{
465 struct Scsi_Host *shost = class_to_shost(dev);
466 struct bfad_im_port_s *im_port =
467 (struct bfad_im_port_s *) shost->hostdata[0];
468 struct bfad_port_s *port = im_port->port;
469 u64 nwwn;
470
471 nwwn = bfa_fcs_port_get_nwwn(port->fcs_port);
472 return snprintf(buf, PAGE_SIZE, "0x%llx\n", bfa_os_htonll(nwwn));
473}
474
475static ssize_t
476bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
477 char *buf)
478{
479 struct Scsi_Host *shost = class_to_shost(dev);
480 struct bfad_im_port_s *im_port =
481 (struct bfad_im_port_s *) shost->hostdata[0];
482 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800483 char model[BFA_ADAPTER_MODEL_NAME_LEN];
484 char fw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700485
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800486 bfa_get_adapter_model(&bfad->bfa, model);
487 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700488 return snprintf(buf, PAGE_SIZE, "Brocade %s FV%s DV%s\n",
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800489 model, fw_ver, BFAD_DRIVER_VERSION);
Jing Huang7725ccf2009-09-23 17:46:15 -0700490}
491
492static ssize_t
493bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
494 char *buf)
495{
496 struct Scsi_Host *shost = class_to_shost(dev);
497 struct bfad_im_port_s *im_port =
498 (struct bfad_im_port_s *) shost->hostdata[0];
499 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800500 char hw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700501
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800502 bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
503 return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700504}
505
506static ssize_t
507bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
508 char *buf)
509{
510 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
511}
512
513static ssize_t
514bfad_im_optionrom_version_show(struct device *dev,
515 struct device_attribute *attr, char *buf)
516{
517 struct Scsi_Host *shost = class_to_shost(dev);
518 struct bfad_im_port_s *im_port =
519 (struct bfad_im_port_s *) shost->hostdata[0];
520 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800521 char optrom_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700522
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800523 bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
524 return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700525}
526
527static ssize_t
528bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
529 char *buf)
530{
531 struct Scsi_Host *shost = class_to_shost(dev);
532 struct bfad_im_port_s *im_port =
533 (struct bfad_im_port_s *) shost->hostdata[0];
534 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800535 char fw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700536
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800537 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
538 return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700539}
540
541static ssize_t
542bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
543 char *buf)
544{
545 struct Scsi_Host *shost = class_to_shost(dev);
546 struct bfad_im_port_s *im_port =
547 (struct bfad_im_port_s *) shost->hostdata[0];
548 struct bfad_s *bfad = im_port->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -0700549
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800550 return snprintf(buf, PAGE_SIZE, "%d\n",
551 bfa_get_nports(&bfad->bfa));
Jing Huang7725ccf2009-09-23 17:46:15 -0700552}
553
554static ssize_t
555bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
556 char *buf)
557{
558 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
559}
560
561static ssize_t
562bfad_im_num_of_discovered_ports_show(struct device *dev,
563 struct device_attribute *attr, char *buf)
564{
565 struct Scsi_Host *shost = class_to_shost(dev);
566 struct bfad_im_port_s *im_port =
567 (struct bfad_im_port_s *) shost->hostdata[0];
568 struct bfad_port_s *port = im_port->port;
569 struct bfad_s *bfad = im_port->bfad;
570 int nrports = 2048;
571 wwn_t *rports = NULL;
572 unsigned long flags;
573
574 rports = kzalloc(sizeof(wwn_t) * nrports , GFP_ATOMIC);
575 if (rports == NULL)
576 return -ENOMEM;
577
578 spin_lock_irqsave(&bfad->bfad_lock, flags);
579 bfa_fcs_port_get_rports(port->fcs_port, rports, &nrports);
580 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
581 kfree(rports);
582
583 return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
584}
585
586static DEVICE_ATTR(serial_number, S_IRUGO,
587 bfad_im_serial_num_show, NULL);
588static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
589static DEVICE_ATTR(model_description, S_IRUGO,
590 bfad_im_model_desc_show, NULL);
591static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
592static DEVICE_ATTR(symbolic_name, S_IRUGO,
593 bfad_im_symbolic_name_show, NULL);
594static DEVICE_ATTR(hardware_version, S_IRUGO,
595 bfad_im_hw_version_show, NULL);
596static DEVICE_ATTR(driver_version, S_IRUGO,
597 bfad_im_drv_version_show, NULL);
598static DEVICE_ATTR(option_rom_version, S_IRUGO,
599 bfad_im_optionrom_version_show, NULL);
600static DEVICE_ATTR(firmware_version, S_IRUGO,
601 bfad_im_fw_version_show, NULL);
602static DEVICE_ATTR(number_of_ports, S_IRUGO,
603 bfad_im_num_of_ports_show, NULL);
604static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
605static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
606 bfad_im_num_of_discovered_ports_show, NULL);
607
608struct device_attribute *bfad_im_host_attrs[] = {
609 &dev_attr_serial_number,
610 &dev_attr_model,
611 &dev_attr_model_description,
612 &dev_attr_node_name,
613 &dev_attr_symbolic_name,
614 &dev_attr_hardware_version,
615 &dev_attr_driver_version,
616 &dev_attr_option_rom_version,
617 &dev_attr_firmware_version,
618 &dev_attr_number_of_ports,
619 &dev_attr_driver_name,
620 &dev_attr_number_of_discovered_ports,
621 NULL,
622};
623
624struct device_attribute *bfad_im_vport_attrs[] = {
625 &dev_attr_serial_number,
626 &dev_attr_model,
627 &dev_attr_model_description,
628 &dev_attr_node_name,
629 &dev_attr_symbolic_name,
630 &dev_attr_hardware_version,
631 &dev_attr_driver_version,
632 &dev_attr_option_rom_version,
633 &dev_attr_firmware_version,
634 &dev_attr_number_of_ports,
635 &dev_attr_driver_name,
636 &dev_attr_number_of_discovered_ports,
637 NULL,
638};
639
640