blob: d12be9dff4ba6be5fb5ec10f1df7c21b2ed1e231 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * 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
Jing Huang5fbe25c2010-10-18 17:17:23 -070018/*
Jing Huang7725ccf2009-09-23 17:46:15 -070019 * bfa_attr.c Linux driver configuration interface module.
20 */
21
22#include "bfad_drv.h"
23#include "bfad_im.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070024
Jing Huang5fbe25c2010-10-18 17:17:23 -070025/*
Jing Huang7725ccf2009-09-23 17:46:15 -070026 * FC transport template entry, get SCSI target port ID.
27 */
Maggie52f94b62010-11-29 18:21:32 -080028static void
Jing Huang7725ccf2009-09-23 17:46:15 -070029bfad_im_get_starget_port_id(struct scsi_target *starget)
30{
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;
37
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070038 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070039 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
40 bfad = im_port->bfad;
41 spin_lock_irqsave(&bfad->bfad_lock, flags);
42
Maggie Zhangf16a1752010-12-09 19:12:32 -080043 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070044 if (itnim)
45 fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
46
47 fc_starget_port_id(starget) = fc_id;
48 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
49}
50
Jing Huang5fbe25c2010-10-18 17:17:23 -070051/*
Jing Huang7725ccf2009-09-23 17:46:15 -070052 * FC transport template entry, get SCSI target nwwn.
53 */
Maggie52f94b62010-11-29 18:21:32 -080054static void
Jing Huang7725ccf2009-09-23 17:46:15 -070055bfad_im_get_starget_node_name(struct scsi_target *starget)
56{
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;
63
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070064 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070065 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
66 bfad = im_port->bfad;
67 spin_lock_irqsave(&bfad->bfad_lock, flags);
68
Maggie Zhangf16a1752010-12-09 19:12:32 -080069 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070070 if (itnim)
71 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
72
Jing Huangba816ea2010-10-18 17:10:50 -070073 fc_starget_node_name(starget) = cpu_to_be64(node_name);
Jing Huang7725ccf2009-09-23 17:46:15 -070074 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
75}
76
Jing Huang5fbe25c2010-10-18 17:17:23 -070077/*
Jing Huang7725ccf2009-09-23 17:46:15 -070078 * FC transport template entry, get SCSI target pwwn.
79 */
Maggie52f94b62010-11-29 18:21:32 -080080static void
Jing Huang7725ccf2009-09-23 17:46:15 -070081bfad_im_get_starget_port_name(struct scsi_target *starget)
82{
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;
89
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070090 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070091 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
92 bfad = im_port->bfad;
93 spin_lock_irqsave(&bfad->bfad_lock, flags);
94
Maggie Zhangf16a1752010-12-09 19:12:32 -080095 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070096 if (itnim)
97 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
98
Jing Huangba816ea2010-10-18 17:10:50 -070099 fc_starget_port_name(starget) = cpu_to_be64(port_name);
Jing Huang7725ccf2009-09-23 17:46:15 -0700100 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
101}
102
Jing Huang5fbe25c2010-10-18 17:17:23 -0700103/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700104 * FC transport template entry, get SCSI host port ID.
105 */
Maggie52f94b62010-11-29 18:21:32 -0800106static void
Jing Huang7725ccf2009-09-23 17:46:15 -0700107bfad_im_get_host_port_id(struct Scsi_Host *shost)
108{
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;
112
113 fc_host_port_id(shost) =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800114 bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
Jing Huang7725ccf2009-09-23 17:46:15 -0700115}
116
Jing Huang5fbe25c2010-10-18 17:17:23 -0700117/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700118 * FC transport template entry, get SCSI host port type.
119 */
120static void
121bfad_im_get_host_port_type(struct Scsi_Host *shost)
122{
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;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700126 struct bfa_lport_attr_s port_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700127
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700128 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700129
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 switch (port_attr.port_type) {
131 case BFA_PORT_TYPE_NPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700132 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
133 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700134 case BFA_PORT_TYPE_NLPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700135 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
136 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700137 case BFA_PORT_TYPE_P2P:
Jing Huang7725ccf2009-09-23 17:46:15 -0700138 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
139 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700140 case BFA_PORT_TYPE_LPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700141 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
142 break;
143 default:
144 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
145 break;
146 }
147}
148
Jing Huang5fbe25c2010-10-18 17:17:23 -0700149/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700150 * FC transport template entry, get SCSI host port state.
151 */
152static void
153bfad_im_get_host_port_state(struct Scsi_Host *shost)
154{
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;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158 struct bfa_port_attr_s attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700159
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800160 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700161
162 switch (attr.port_state) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700163 case BFA_PORT_ST_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700164 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
165 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700166 case BFA_PORT_ST_LINKUP:
Jing Huang7725ccf2009-09-23 17:46:15 -0700167 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
168 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169 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:
Jing Huang7725ccf2009-09-23 17:46:15 -0700180 default:
181 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
182 break;
183 }
184}
185
Jing Huang5fbe25c2010-10-18 17:17:23 -0700186/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700187 * FC transport template entry, get SCSI host active fc4s.
188 */
189static void
190bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
191{
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;
195
196 memset(fc_host_active_fc4s(shost), 0,
197 sizeof(fc_host_active_fc4s(shost)));
198
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700199 if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
Jing Huang7725ccf2009-09-23 17:46:15 -0700200 fc_host_active_fc4s(shost)[2] = 1;
201
Jing Huang7725ccf2009-09-23 17:46:15 -0700202 fc_host_active_fc4s(shost)[7] = 1;
203}
204
Jing Huang5fbe25c2010-10-18 17:17:23 -0700205/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700206 * FC transport template entry, get SCSI host link speed.
207 */
208static void
209bfad_im_get_host_speed(struct Scsi_Host *shost)
210{
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;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700214 struct bfa_port_attr_s attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700215
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800216 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700217 switch (attr.speed) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700218 case BFA_PORT_SPEED_10GBPS:
219 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
220 break;
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700221 case BFA_PORT_SPEED_16GBPS:
222 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
223 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700224 case BFA_PORT_SPEED_8GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700225 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
226 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700227 case BFA_PORT_SPEED_4GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700228 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
229 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230 case BFA_PORT_SPEED_2GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700231 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
232 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233 case BFA_PORT_SPEED_1GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700234 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
235 break;
236 default:
237 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
238 break;
239 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700240}
241
Jing Huang5fbe25c2010-10-18 17:17:23 -0700242/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700243 * FC transport template entry, get SCSI host port type.
244 */
245static void
246bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
247{
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;
252
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700254
Jing Huangba816ea2010-10-18 17:10:50 -0700255 fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
Jing Huang7725ccf2009-09-23 17:46:15 -0700256
257}
258
Jing Huang5fbe25c2010-10-18 17:17:23 -0700259/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700260 * FC transport template entry, get BFAD statistics.
261 */
262static struct fc_host_statistics *
263bfad_im_get_stats(struct Scsi_Host *shost)
264{
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;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700269 union bfa_port_stats_u *fcstats;
Jing Huang7725ccf2009-09-23 17:46:15 -0700270 struct fc_host_statistics *hstats;
271 bfa_status_t rc;
272 unsigned long flags;
273
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
275 if (fcstats == NULL)
276 return NULL;
277
Jing Huang7725ccf2009-09-23 17:46:15 -0700278 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));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
283 fcstats, bfad_hcb_comp, &fcomp);
Jing Huang7725ccf2009-09-23 17:46:15 -0700284 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
285 if (rc != BFA_STATUS_OK)
286 return NULL;
287
288 wait_for_completion(&fcomp.comp);
289
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700290 /* Fill the fc_host_statistics structure */
291 hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
292 hstats->tx_frames = fcstats->fc.tx_frames;
293 hstats->tx_words = fcstats->fc.tx_words;
294 hstats->rx_frames = fcstats->fc.rx_frames;
295 hstats->rx_words = fcstats->fc.rx_words;
296 hstats->lip_count = fcstats->fc.lip_count;
297 hstats->nos_count = fcstats->fc.nos_count;
298 hstats->error_frames = fcstats->fc.error_frames;
299 hstats->dumped_frames = fcstats->fc.dropped_frames;
300 hstats->link_failure_count = fcstats->fc.link_failures;
301 hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
302 hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
303 hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
304 hstats->invalid_crc_count = fcstats->fc.invalid_crcs;
305
306 kfree(fcstats);
Jing Huang7725ccf2009-09-23 17:46:15 -0700307 return hstats;
308}
309
Jing Huang5fbe25c2010-10-18 17:17:23 -0700310/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700311 * FC transport template entry, reset BFAD statistics.
312 */
313static void
314bfad_im_reset_stats(struct Scsi_Host *shost)
315{
316 struct bfad_im_port_s *im_port =
317 (struct bfad_im_port_s *) shost->hostdata[0];
318 struct bfad_s *bfad = im_port->bfad;
319 struct bfad_hal_comp fcomp;
320 unsigned long flags;
321 bfa_status_t rc;
322
323 init_completion(&fcomp.comp);
324 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800325 rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700326 &fcomp);
Jing Huang7725ccf2009-09-23 17:46:15 -0700327 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
328
329 if (rc != BFA_STATUS_OK)
330 return;
331
332 wait_for_completion(&fcomp.comp);
333
334 return;
335}
336
Jing Huang5fbe25c2010-10-18 17:17:23 -0700337/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700338 * FC transport template entry, get rport loss timeout.
339 */
340static void
341bfad_im_get_rport_loss_tmo(struct fc_rport *rport)
342{
343 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
344 struct bfad_itnim_s *itnim = itnim_data->itnim;
345 struct bfad_s *bfad = itnim->im->bfad;
346 unsigned long flags;
347
348 spin_lock_irqsave(&bfad->bfad_lock, flags);
349 rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
350 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
351}
352
Jing Huang5fbe25c2010-10-18 17:17:23 -0700353/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700354 * FC transport template entry, set rport loss timeout.
355 */
356static void
357bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
358{
359 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
360 struct bfad_itnim_s *itnim = itnim_data->itnim;
361 struct bfad_s *bfad = itnim->im->bfad;
362 unsigned long flags;
363
364 if (timeout > 0) {
365 spin_lock_irqsave(&bfad->bfad_lock, flags);
366 bfa_fcpim_path_tov_set(&bfad->bfa, timeout);
367 rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa);
368 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
369 }
370
371}
372
Jing Huangb5042932010-03-19 11:05:39 -0700373static int
374bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
375{
376 char *vname = fc_vport->symbolic_name;
377 struct Scsi_Host *shost = fc_vport->shost;
378 struct bfad_im_port_s *im_port =
379 (struct bfad_im_port_s *) shost->hostdata[0];
380 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381 struct bfa_lport_cfg_s port_cfg;
382 struct bfad_vport_s *vp;
Jing Huangb5042932010-03-19 11:05:39 -0700383 int status = 0, rc;
384 unsigned long flags;
385
386 memset(&port_cfg, 0, sizeof(port_cfg));
Jing Huangd9883542010-07-08 19:46:26 -0700387 u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
388 u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700389 if (strlen(vname) > 0)
390 strcpy((char *)&port_cfg.sym_name, vname);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700391 port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
Jing Huangb5042932010-03-19 11:05:39 -0700392
Jing Huangd9883542010-07-08 19:46:26 -0700393 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700394 list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
395 if (port_cfg.pwwn ==
396 vp->fcs_vport.lport.port_cfg.pwwn) {
397 port_cfg.preboot_vp =
398 vp->fcs_vport.lport.port_cfg.preboot_vp;
Jing Huangd9883542010-07-08 19:46:26 -0700399 break;
400 }
401 }
402 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
403
404 rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
Jing Huangb5042932010-03-19 11:05:39 -0700405 if (rc == BFA_STATUS_OK) {
Jing Huangd9883542010-07-08 19:46:26 -0700406 struct bfad_vport_s *vport;
Jing Huangb5042932010-03-19 11:05:39 -0700407 struct bfa_fcs_vport_s *fcs_vport;
408 struct Scsi_Host *vshost;
409
410 spin_lock_irqsave(&bfad->bfad_lock, flags);
411 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
412 port_cfg.pwwn);
Jing Huangd9883542010-07-08 19:46:26 -0700413 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
414 if (fcs_vport == NULL)
Jing Huangb5042932010-03-19 11:05:39 -0700415 return VPCERR_BAD_WWN;
Jing Huangb5042932010-03-19 11:05:39 -0700416
417 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
418 if (disable) {
Jing Huangd9883542010-07-08 19:46:26 -0700419 spin_lock_irqsave(&bfad->bfad_lock, flags);
Jing Huangb5042932010-03-19 11:05:39 -0700420 bfa_fcs_vport_stop(fcs_vport);
Jing Huangd9883542010-07-08 19:46:26 -0700421 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Jing Huangb5042932010-03-19 11:05:39 -0700422 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
423 }
Jing Huangb5042932010-03-19 11:05:39 -0700424
425 vport = fcs_vport->vport_drv;
426 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700427 fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
428 fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700429 fc_vport->dd_data = vport;
430 vport->drv_port.im_port->fc_vport = fc_vport;
Jing Huangb5042932010-03-19 11:05:39 -0700431 } else if (rc == BFA_STATUS_INVALID_WWN)
432 return VPCERR_BAD_WWN;
433 else if (rc == BFA_STATUS_VPORT_EXISTS)
434 return VPCERR_BAD_WWN;
435 else if (rc == BFA_STATUS_VPORT_MAX)
436 return VPCERR_NO_FABRIC_SUPP;
437 else if (rc == BFA_STATUS_VPORT_WWN_BP)
438 return VPCERR_BAD_WWN;
Jing Huangd9883542010-07-08 19:46:26 -0700439 else
Jing Huangb5042932010-03-19 11:05:39 -0700440 return FC_VPORT_FAILED;
441
442 return status;
443}
444
Krishna Gudipatiacea2412012-03-13 17:37:26 -0700445int
446bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
447{
448 struct bfad_im_port_s *im_port =
449 (struct bfad_im_port_s *) shost->hostdata[0];
450 struct bfad_s *bfad = im_port->bfad;
451 struct bfad_hal_comp fcomp;
452 unsigned long flags;
453 uint32_t status;
454
455 init_completion(&fcomp.comp);
456 spin_lock_irqsave(&bfad->bfad_lock, flags);
457 status = bfa_port_disable(&bfad->bfa.modules.port,
458 bfad_hcb_comp, &fcomp);
459 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
460
461 if (status != BFA_STATUS_OK)
462 return -EIO;
463
464 wait_for_completion(&fcomp.comp);
465 if (fcomp.status != BFA_STATUS_OK)
466 return -EIO;
467
468 spin_lock_irqsave(&bfad->bfad_lock, flags);
469 status = bfa_port_enable(&bfad->bfa.modules.port,
470 bfad_hcb_comp, &fcomp);
471 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
472 if (status != BFA_STATUS_OK)
473 return -EIO;
474
475 wait_for_completion(&fcomp.comp);
476 if (fcomp.status != BFA_STATUS_OK)
477 return -EIO;
478
479 return 0;
480}
481
Jing Huangb5042932010-03-19 11:05:39 -0700482static int
483bfad_im_vport_delete(struct fc_vport *fc_vport)
484{
485 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
486 struct bfad_im_port_s *im_port =
487 (struct bfad_im_port_s *) vport->drv_port.im_port;
488 struct bfad_s *bfad = im_port->bfad;
489 struct bfad_port_s *port;
490 struct bfa_fcs_vport_s *fcs_vport;
491 struct Scsi_Host *vshost;
492 wwn_t pwwn;
493 int rc;
494 unsigned long flags;
495 struct completion fcomp;
496
Krishna Gudipatiff179e02012-03-13 17:40:31 -0700497 if (im_port->flags & BFAD_PORT_DELETE) {
498 bfad_scsi_host_free(bfad, im_port);
499 list_del(&vport->list_entry);
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700500 kfree(vport);
Krishna Gudipatiff179e02012-03-13 17:40:31 -0700501 return 0;
502 }
Jing Huangb5042932010-03-19 11:05:39 -0700503
504 port = im_port->port;
505
506 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700507 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700508
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);
512
513 if (fcs_vport == NULL)
514 return VPCERR_BAD_WWN;
515
516 vport->drv_port.flags |= BFAD_PORT_DELETE;
517
518 vport->comp_del = &fcomp;
519 init_completion(vport->comp_del);
520
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);
524
Jing Huangc54d5572010-07-08 20:01:49 -0700525 if (rc == BFA_STATUS_PBC) {
526 vport->drv_port.flags &= ~BFAD_PORT_DELETE;
527 vport->comp_del = NULL;
Jing Huangd9883542010-07-08 19:46:26 -0700528 return -1;
Jing Huangc54d5572010-07-08 20:01:49 -0700529 }
Jing Huangd9883542010-07-08 19:46:26 -0700530
Jing Huangb5042932010-03-19 11:05:39 -0700531 wait_for_completion(vport->comp_del);
532
Maggie Zhangf16a1752010-12-09 19:12:32 -0800533 bfad_scsi_host_free(bfad, im_port);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800534 list_del(&vport->list_entry);
Jing Huangb5042932010-03-19 11:05:39 -0700535 kfree(vport);
536
537 return 0;
538}
539
540static int
541bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
542{
543 struct bfad_vport_s *vport;
544 struct bfad_s *bfad;
545 struct bfa_fcs_vport_s *fcs_vport;
546 struct Scsi_Host *vshost;
547 wwn_t pwwn;
548 unsigned long flags;
549
550 vport = (struct bfad_vport_s *)fc_vport->dd_data;
551 bfad = vport->drv_port.bfad;
552 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700553 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700554
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);
558
559 if (fcs_vport == NULL)
560 return VPCERR_BAD_WWN;
561
562 if (disable) {
563 bfa_fcs_vport_stop(fcs_vport);
564 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
565 } else {
566 bfa_fcs_vport_start(fcs_vport);
567 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
568 }
569
570 return 0;
571}
572
Jing Huang7725ccf2009-09-23 17:46:15 -0700573struct fc_function_template bfad_im_fc_function_template = {
574
575 /* Target dynamic attributes */
576 .get_starget_port_id = bfad_im_get_starget_port_id,
577 .show_starget_port_id = 1,
578 .get_starget_node_name = bfad_im_get_starget_node_name,
579 .show_starget_node_name = 1,
580 .get_starget_port_name = bfad_im_get_starget_port_name,
581 .show_starget_port_name = 1,
582
583 /* Host dynamic attribute */
584 .get_host_port_id = bfad_im_get_host_port_id,
585 .show_host_port_id = 1,
586
587 /* Host fixed attributes */
588 .show_host_node_name = 1,
589 .show_host_port_name = 1,
590 .show_host_supported_classes = 1,
591 .show_host_supported_fc4s = 1,
592 .show_host_supported_speeds = 1,
593 .show_host_maxframe_size = 1,
594
595 /* More host dynamic attributes */
596 .show_host_port_type = 1,
597 .get_host_port_type = bfad_im_get_host_port_type,
598 .show_host_port_state = 1,
599 .get_host_port_state = bfad_im_get_host_port_state,
600 .show_host_active_fc4s = 1,
601 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
602 .show_host_speed = 1,
603 .get_host_speed = bfad_im_get_host_speed,
604 .show_host_fabric_name = 1,
605 .get_host_fabric_name = bfad_im_get_host_fabric_name,
606
607 .show_host_symbolic_name = 1,
608
609 /* Statistics */
610 .get_fc_host_stats = bfad_im_get_stats,
611 .reset_fc_host_stats = bfad_im_reset_stats,
612
613 /* Allocation length for host specific data */
614 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
615
616 /* Remote port fixed attributes */
617 .show_rport_maxframe_size = 1,
618 .show_rport_supported_classes = 1,
619 .show_rport_dev_loss_tmo = 1,
620 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
621 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
Krishna Gudipatiacea2412012-03-13 17:37:26 -0700622 .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
Jing Huangb5042932010-03-19 11:05:39 -0700623 .vport_create = bfad_im_vport_create,
624 .vport_delete = bfad_im_vport_delete,
625 .vport_disable = bfad_im_vport_disable,
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700626 .bsg_request = bfad_im_bsg_request,
627 .bsg_timeout = bfad_im_bsg_timeout,
Jing Huangb5042932010-03-19 11:05:39 -0700628};
629
630struct fc_function_template bfad_im_vport_fc_function_template = {
631
632 /* Target dynamic attributes */
633 .get_starget_port_id = bfad_im_get_starget_port_id,
634 .show_starget_port_id = 1,
635 .get_starget_node_name = bfad_im_get_starget_node_name,
636 .show_starget_node_name = 1,
637 .get_starget_port_name = bfad_im_get_starget_port_name,
638 .show_starget_port_name = 1,
639
640 /* Host dynamic attribute */
641 .get_host_port_id = bfad_im_get_host_port_id,
642 .show_host_port_id = 1,
643
644 /* Host fixed attributes */
645 .show_host_node_name = 1,
646 .show_host_port_name = 1,
647 .show_host_supported_classes = 1,
648 .show_host_supported_fc4s = 1,
649 .show_host_supported_speeds = 1,
650 .show_host_maxframe_size = 1,
651
652 /* More host dynamic attributes */
653 .show_host_port_type = 1,
654 .get_host_port_type = bfad_im_get_host_port_type,
655 .show_host_port_state = 1,
656 .get_host_port_state = bfad_im_get_host_port_state,
657 .show_host_active_fc4s = 1,
658 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
659 .show_host_speed = 1,
660 .get_host_speed = bfad_im_get_host_speed,
661 .show_host_fabric_name = 1,
662 .get_host_fabric_name = bfad_im_get_host_fabric_name,
663
664 .show_host_symbolic_name = 1,
665
666 /* Statistics */
667 .get_fc_host_stats = bfad_im_get_stats,
668 .reset_fc_host_stats = bfad_im_reset_stats,
669
670 /* Allocation length for host specific data */
671 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
672
673 /* Remote port fixed attributes */
674 .show_rport_maxframe_size = 1,
675 .show_rport_supported_classes = 1,
676 .show_rport_dev_loss_tmo = 1,
677 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
678 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
Jing Huang7725ccf2009-09-23 17:46:15 -0700679};
680
Jing Huang5fbe25c2010-10-18 17:17:23 -0700681/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700682 * Scsi_Host_attrs SCSI host attributes
683 */
684static ssize_t
685bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
686 char *buf)
687{
688 struct Scsi_Host *shost = class_to_shost(dev);
689 struct bfad_im_port_s *im_port =
690 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700691 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800692 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700693
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800694 bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
695 return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
Jing Huang7725ccf2009-09-23 17:46:15 -0700696}
697
698static ssize_t
699bfad_im_model_show(struct device *dev, struct device_attribute *attr,
700 char *buf)
701{
702 struct Scsi_Host *shost = class_to_shost(dev);
703 struct bfad_im_port_s *im_port =
704 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700705 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800706 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700707
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800708 bfa_get_adapter_model(&bfad->bfa, model);
709 return snprintf(buf, PAGE_SIZE, "%s\n", model);
Jing Huang7725ccf2009-09-23 17:46:15 -0700710}
711
712static ssize_t
713bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
714 char *buf)
715{
716 struct Scsi_Host *shost = class_to_shost(dev);
717 struct bfad_im_port_s *im_port =
718 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719 struct bfad_s *bfad = im_port->bfad;
720 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800721 char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
Krishna Gudipati75332a72011-06-13 15:54:31 -0700722 int nports = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -0700723
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700724 bfa_get_adapter_model(&bfad->bfa, model);
Krishna Gudipati75332a72011-06-13 15:54:31 -0700725 nports = bfa_get_nports(&bfad->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700726 if (!strcmp(model, "Brocade-425"))
727 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
728 "Brocade 4Gbps PCIe dual port FC HBA");
729 else if (!strcmp(model, "Brocade-825"))
730 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
731 "Brocade 8Gbps PCIe dual port FC HBA");
732 else if (!strcmp(model, "Brocade-42B"))
733 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700734 "Brocade 4Gbps PCIe dual port FC HBA for HP");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700735 else if (!strcmp(model, "Brocade-82B"))
736 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700737 "Brocade 8Gbps PCIe dual port FC HBA for HP");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738 else if (!strcmp(model, "Brocade-1010"))
739 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
740 "Brocade 10Gbps single port CNA");
741 else if (!strcmp(model, "Brocade-1020"))
742 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
743 "Brocade 10Gbps dual port CNA");
744 else if (!strcmp(model, "Brocade-1007"))
745 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700746 "Brocade 10Gbps CNA for IBM Blade Center");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700747 else if (!strcmp(model, "Brocade-415"))
748 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
749 "Brocade 4Gbps PCIe single port FC HBA");
750 else if (!strcmp(model, "Brocade-815"))
751 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
752 "Brocade 8Gbps PCIe single port FC HBA");
753 else if (!strcmp(model, "Brocade-41B"))
754 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700755 "Brocade 4Gbps PCIe single port FC HBA for HP");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700756 else if (!strcmp(model, "Brocade-81B"))
757 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700758 "Brocade 8Gbps PCIe single port FC HBA for HP");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700759 else if (!strcmp(model, "Brocade-804"))
760 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700761 "Brocade 8Gbps FC HBA for HP Bladesystem C-class");
762 else if (!strcmp(model, "Brocade-902") ||
763 !strcmp(model, "Brocade-1741"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700764 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Krishna Gudipati75332a72011-06-13 15:54:31 -0700765 "Brocade 10Gbps CNA for Dell M-Series Blade Servers");
766 else if (strstr(model, "Brocade-1560")) {
767 if (nports == 1)
768 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
769 "Brocade 16Gbps PCIe single port FC HBA");
770 else
771 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
772 "Brocade 16Gbps PCIe dual port FC HBA");
773 } else if (strstr(model, "Brocade-1710")) {
774 if (nports == 1)
775 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
776 "Brocade 10Gbps single port CNA");
777 else
778 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
779 "Brocade 10Gbps dual port CNA");
780 } else if (strstr(model, "Brocade-1860")) {
781 if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
782 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
783 "Brocade 10Gbps single port CNA");
784 else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
785 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
786 "Brocade 16Gbps PCIe single port FC HBA");
787 else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
788 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
789 "Brocade 10Gbps dual port CNA");
790 else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
791 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
792 "Brocade 16Gbps PCIe dual port FC HBA");
793 } else
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700794 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
795 "Invalid Model");
796
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800797 return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700798}
799
800static ssize_t
801bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
802 char *buf)
803{
804 struct Scsi_Host *shost = class_to_shost(dev);
805 struct bfad_im_port_s *im_port =
806 (struct bfad_im_port_s *) shost->hostdata[0];
807 struct bfad_port_s *port = im_port->port;
808 u64 nwwn;
809
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700810 nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
Jing Huangba816ea2010-10-18 17:10:50 -0700811 return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
Jing Huang7725ccf2009-09-23 17:46:15 -0700812}
813
814static ssize_t
815bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
816 char *buf)
817{
818 struct Scsi_Host *shost = class_to_shost(dev);
819 struct bfad_im_port_s *im_port =
820 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700821 struct bfad_s *bfad = im_port->bfad;
822 struct bfa_lport_attr_s port_attr;
823 char symname[BFA_SYMNAME_MAXLEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700824
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700825 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
826 strncpy(symname, port_attr.port_cfg.sym_name.symname,
827 BFA_SYMNAME_MAXLEN);
828 return snprintf(buf, PAGE_SIZE, "%s\n", symname);
Jing Huang7725ccf2009-09-23 17:46:15 -0700829}
830
831static ssize_t
832bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
833 char *buf)
834{
835 struct Scsi_Host *shost = class_to_shost(dev);
836 struct bfad_im_port_s *im_port =
837 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700838 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800839 char hw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700840
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800841 bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
842 return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700843}
844
845static ssize_t
846bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
847 char *buf)
848{
849 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
850}
851
852static ssize_t
853bfad_im_optionrom_version_show(struct device *dev,
854 struct device_attribute *attr, char *buf)
855{
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];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700859 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800860 char optrom_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700861
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800862 bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
863 return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700864}
865
866static ssize_t
867bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
868 char *buf)
869{
870 struct Scsi_Host *shost = class_to_shost(dev);
871 struct bfad_im_port_s *im_port =
872 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700873 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800874 char fw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700875
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800876 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
877 return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700878}
879
880static ssize_t
881bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
882 char *buf)
883{
884 struct Scsi_Host *shost = class_to_shost(dev);
885 struct bfad_im_port_s *im_port =
886 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700887 struct bfad_s *bfad = im_port->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -0700888
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800889 return snprintf(buf, PAGE_SIZE, "%d\n",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 bfa_get_nports(&bfad->bfa));
Jing Huang7725ccf2009-09-23 17:46:15 -0700891}
892
893static ssize_t
894bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
895 char *buf)
896{
897 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
898}
899
900static ssize_t
901bfad_im_num_of_discovered_ports_show(struct device *dev,
902 struct device_attribute *attr, char *buf)
903{
904 struct Scsi_Host *shost = class_to_shost(dev);
905 struct bfad_im_port_s *im_port =
906 (struct bfad_im_port_s *) shost->hostdata[0];
907 struct bfad_port_s *port = im_port->port;
908 struct bfad_s *bfad = im_port->bfad;
909 int nrports = 2048;
910 wwn_t *rports = NULL;
911 unsigned long flags;
912
913 rports = kzalloc(sizeof(wwn_t) * nrports , GFP_ATOMIC);
914 if (rports == NULL)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700915 return snprintf(buf, PAGE_SIZE, "Failed\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700916
917 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700918 bfa_fcs_lport_get_rports(port->fcs_port, rports, &nrports);
Jing Huang7725ccf2009-09-23 17:46:15 -0700919 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
920 kfree(rports);
921
922 return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
923}
924
925static DEVICE_ATTR(serial_number, S_IRUGO,
926 bfad_im_serial_num_show, NULL);
927static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
928static DEVICE_ATTR(model_description, S_IRUGO,
929 bfad_im_model_desc_show, NULL);
930static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
931static DEVICE_ATTR(symbolic_name, S_IRUGO,
932 bfad_im_symbolic_name_show, NULL);
933static DEVICE_ATTR(hardware_version, S_IRUGO,
934 bfad_im_hw_version_show, NULL);
935static DEVICE_ATTR(driver_version, S_IRUGO,
936 bfad_im_drv_version_show, NULL);
937static DEVICE_ATTR(option_rom_version, S_IRUGO,
938 bfad_im_optionrom_version_show, NULL);
939static DEVICE_ATTR(firmware_version, S_IRUGO,
940 bfad_im_fw_version_show, NULL);
941static DEVICE_ATTR(number_of_ports, S_IRUGO,
942 bfad_im_num_of_ports_show, NULL);
943static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
944static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
945 bfad_im_num_of_discovered_ports_show, NULL);
946
947struct device_attribute *bfad_im_host_attrs[] = {
948 &dev_attr_serial_number,
949 &dev_attr_model,
950 &dev_attr_model_description,
951 &dev_attr_node_name,
952 &dev_attr_symbolic_name,
953 &dev_attr_hardware_version,
954 &dev_attr_driver_version,
955 &dev_attr_option_rom_version,
956 &dev_attr_firmware_version,
957 &dev_attr_number_of_ports,
958 &dev_attr_driver_name,
959 &dev_attr_number_of_discovered_ports,
960 NULL,
961};
962
963struct device_attribute *bfad_im_vport_attrs[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700964 &dev_attr_serial_number,
965 &dev_attr_model,
966 &dev_attr_model_description,
967 &dev_attr_node_name,
968 &dev_attr_symbolic_name,
969 &dev_attr_hardware_version,
970 &dev_attr_driver_version,
971 &dev_attr_option_rom_version,
972 &dev_attr_firmware_version,
973 &dev_attr_number_of_ports,
974 &dev_attr_driver_name,
975 &dev_attr_number_of_discovered_ports,
976 NULL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700977};
978
979