blob: 26b0fa4e90b58b5340bf18bb20e1a22fd8d5c677 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Jing Huang5fbe25c2010-10-18 17:17:23 -070019/*
Jing Huang7725ccf2009-09-23 17:46:15 -070020 * bfa_attr.c Linux driver configuration interface module.
21 */
22
23#include "bfad_drv.h"
24#include "bfad_im.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070025
Jing Huang5fbe25c2010-10-18 17:17:23 -070026/*
Jing Huang7725ccf2009-09-23 17:46:15 -070027 * FC transport template entry, get SCSI target port ID.
28 */
Maggie52f94b62010-11-29 18:21:32 -080029static void
Jing Huang7725ccf2009-09-23 17:46:15 -070030bfad_im_get_starget_port_id(struct scsi_target *starget)
31{
32 struct Scsi_Host *shost;
33 struct bfad_im_port_s *im_port;
34 struct bfad_s *bfad;
35 struct bfad_itnim_s *itnim = NULL;
36 u32 fc_id = -1;
37 unsigned long flags;
38
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070039 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070040 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
41 bfad = im_port->bfad;
42 spin_lock_irqsave(&bfad->bfad_lock, flags);
43
Maggie Zhangf16a1752010-12-09 19:12:32 -080044 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070045 if (itnim)
46 fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
47
48 fc_starget_port_id(starget) = fc_id;
49 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
50}
51
Jing Huang5fbe25c2010-10-18 17:17:23 -070052/*
Jing Huang7725ccf2009-09-23 17:46:15 -070053 * FC transport template entry, get SCSI target nwwn.
54 */
Maggie52f94b62010-11-29 18:21:32 -080055static void
Jing Huang7725ccf2009-09-23 17:46:15 -070056bfad_im_get_starget_node_name(struct scsi_target *starget)
57{
58 struct Scsi_Host *shost;
59 struct bfad_im_port_s *im_port;
60 struct bfad_s *bfad;
61 struct bfad_itnim_s *itnim = NULL;
62 u64 node_name = 0;
63 unsigned long flags;
64
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070065 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070066 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
67 bfad = im_port->bfad;
68 spin_lock_irqsave(&bfad->bfad_lock, flags);
69
Maggie Zhangf16a1752010-12-09 19:12:32 -080070 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070071 if (itnim)
72 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
73
Jing Huangba816ea2010-10-18 17:10:50 -070074 fc_starget_node_name(starget) = cpu_to_be64(node_name);
Jing Huang7725ccf2009-09-23 17:46:15 -070075 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
76}
77
Jing Huang5fbe25c2010-10-18 17:17:23 -070078/*
Jing Huang7725ccf2009-09-23 17:46:15 -070079 * FC transport template entry, get SCSI target pwwn.
80 */
Maggie52f94b62010-11-29 18:21:32 -080081static void
Jing Huang7725ccf2009-09-23 17:46:15 -070082bfad_im_get_starget_port_name(struct scsi_target *starget)
83{
84 struct Scsi_Host *shost;
85 struct bfad_im_port_s *im_port;
86 struct bfad_s *bfad;
87 struct bfad_itnim_s *itnim = NULL;
88 u64 port_name = 0;
89 unsigned long flags;
90
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070091 shost = dev_to_shost(starget->dev.parent);
Jing Huang7725ccf2009-09-23 17:46:15 -070092 im_port = (struct bfad_im_port_s *) shost->hostdata[0];
93 bfad = im_port->bfad;
94 spin_lock_irqsave(&bfad->bfad_lock, flags);
95
Maggie Zhangf16a1752010-12-09 19:12:32 -080096 itnim = bfad_get_itnim(im_port, starget->id);
Jing Huang7725ccf2009-09-23 17:46:15 -070097 if (itnim)
98 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
99
Jing Huangba816ea2010-10-18 17:10:50 -0700100 fc_starget_port_name(starget) = cpu_to_be64(port_name);
Jing Huang7725ccf2009-09-23 17:46:15 -0700101 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
102}
103
Jing Huang5fbe25c2010-10-18 17:17:23 -0700104/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700105 * FC transport template entry, get SCSI host port ID.
106 */
Maggie52f94b62010-11-29 18:21:32 -0800107static void
Jing Huang7725ccf2009-09-23 17:46:15 -0700108bfad_im_get_host_port_id(struct Scsi_Host *shost)
109{
110 struct bfad_im_port_s *im_port =
111 (struct bfad_im_port_s *) shost->hostdata[0];
112 struct bfad_port_s *port = im_port->port;
113
114 fc_host_port_id(shost) =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800115 bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
Jing Huang7725ccf2009-09-23 17:46:15 -0700116}
117
Jing Huang5fbe25c2010-10-18 17:17:23 -0700118/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700119 * FC transport template entry, get SCSI host port type.
120 */
121static void
122bfad_im_get_host_port_type(struct Scsi_Host *shost)
123{
124 struct bfad_im_port_s *im_port =
125 (struct bfad_im_port_s *) shost->hostdata[0];
126 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700127 struct bfa_lport_attr_s port_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700128
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700129 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700130
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700131 switch (port_attr.port_type) {
132 case BFA_PORT_TYPE_NPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700133 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
134 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700135 case BFA_PORT_TYPE_NLPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700136 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
137 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138 case BFA_PORT_TYPE_P2P:
Jing Huang7725ccf2009-09-23 17:46:15 -0700139 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
140 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700141 case BFA_PORT_TYPE_LPORT:
Jing Huang7725ccf2009-09-23 17:46:15 -0700142 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
143 break;
144 default:
145 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
146 break;
147 }
148}
149
Jing Huang5fbe25c2010-10-18 17:17:23 -0700150/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700151 * FC transport template entry, get SCSI host port state.
152 */
153static void
154bfad_im_get_host_port_state(struct Scsi_Host *shost)
155{
156 struct bfad_im_port_s *im_port =
157 (struct bfad_im_port_s *) shost->hostdata[0];
158 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700159 struct bfa_port_attr_s attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700160
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800161 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700162
163 switch (attr.port_state) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700164 case BFA_PORT_ST_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700165 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
166 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700167 case BFA_PORT_ST_LINKUP:
Jing Huang7725ccf2009-09-23 17:46:15 -0700168 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
169 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700170 case BFA_PORT_ST_DISABLED:
171 case BFA_PORT_ST_STOPPED:
172 case BFA_PORT_ST_IOCDOWN:
173 case BFA_PORT_ST_IOCDIS:
174 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
175 break;
176 case BFA_PORT_ST_UNINIT:
177 case BFA_PORT_ST_ENABLING_QWAIT:
178 case BFA_PORT_ST_ENABLING:
179 case BFA_PORT_ST_DISABLING_QWAIT:
180 case BFA_PORT_ST_DISABLING:
Jing Huang7725ccf2009-09-23 17:46:15 -0700181 default:
182 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
183 break;
184 }
185}
186
Jing Huang5fbe25c2010-10-18 17:17:23 -0700187/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700188 * FC transport template entry, get SCSI host active fc4s.
189 */
190static void
191bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
192{
193 struct bfad_im_port_s *im_port =
194 (struct bfad_im_port_s *) shost->hostdata[0];
195 struct bfad_port_s *port = im_port->port;
196
197 memset(fc_host_active_fc4s(shost), 0,
198 sizeof(fc_host_active_fc4s(shost)));
199
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700200 if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
Jing Huang7725ccf2009-09-23 17:46:15 -0700201 fc_host_active_fc4s(shost)[2] = 1;
202
Jing Huang7725ccf2009-09-23 17:46:15 -0700203 fc_host_active_fc4s(shost)[7] = 1;
204}
205
Jing Huang5fbe25c2010-10-18 17:17:23 -0700206/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700207 * FC transport template entry, get SCSI host link speed.
208 */
209static void
210bfad_im_get_host_speed(struct Scsi_Host *shost)
211{
212 struct bfad_im_port_s *im_port =
213 (struct bfad_im_port_s *) shost->hostdata[0];
214 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700215 struct bfa_port_attr_s attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700216
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800217 bfa_fcport_get_attr(&bfad->bfa, &attr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700218 switch (attr.speed) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219 case BFA_PORT_SPEED_10GBPS:
220 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
221 break;
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700222 case BFA_PORT_SPEED_16GBPS:
223 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
224 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700225 case BFA_PORT_SPEED_8GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700226 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
227 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700228 case BFA_PORT_SPEED_4GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700229 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
230 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231 case BFA_PORT_SPEED_2GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700232 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
233 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 case BFA_PORT_SPEED_1GBPS:
Jing Huang7725ccf2009-09-23 17:46:15 -0700235 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
236 break;
237 default:
238 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
239 break;
240 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700241}
242
Jing Huang5fbe25c2010-10-18 17:17:23 -0700243/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700244 * FC transport template entry, get SCSI host port type.
245 */
246static void
247bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
248{
249 struct bfad_im_port_s *im_port =
250 (struct bfad_im_port_s *) shost->hostdata[0];
251 struct bfad_port_s *port = im_port->port;
252 wwn_t fabric_nwwn = 0;
253
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700254 fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700255
Jing Huangba816ea2010-10-18 17:10:50 -0700256 fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
Jing Huang7725ccf2009-09-23 17:46:15 -0700257
258}
259
Jing Huang5fbe25c2010-10-18 17:17:23 -0700260/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700261 * FC transport template entry, get BFAD statistics.
262 */
263static struct fc_host_statistics *
264bfad_im_get_stats(struct Scsi_Host *shost)
265{
266 struct bfad_im_port_s *im_port =
267 (struct bfad_im_port_s *) shost->hostdata[0];
268 struct bfad_s *bfad = im_port->bfad;
269 struct bfad_hal_comp fcomp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700270 union bfa_port_stats_u *fcstats;
Jing Huang7725ccf2009-09-23 17:46:15 -0700271 struct fc_host_statistics *hstats;
272 bfa_status_t rc;
273 unsigned long flags;
274
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700275 fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
276 if (fcstats == NULL)
277 return NULL;
278
Jing Huang7725ccf2009-09-23 17:46:15 -0700279 hstats = &bfad->link_stats;
280 init_completion(&fcomp.comp);
281 spin_lock_irqsave(&bfad->bfad_lock, flags);
282 memset(hstats, 0, sizeof(struct fc_host_statistics));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
284 fcstats, bfad_hcb_comp, &fcomp);
Jing Huang7725ccf2009-09-23 17:46:15 -0700285 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
286 if (rc != BFA_STATUS_OK)
287 return NULL;
288
289 wait_for_completion(&fcomp.comp);
290
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700291 /* Fill the fc_host_statistics structure */
292 hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
293 hstats->tx_frames = fcstats->fc.tx_frames;
294 hstats->tx_words = fcstats->fc.tx_words;
295 hstats->rx_frames = fcstats->fc.rx_frames;
296 hstats->rx_words = fcstats->fc.rx_words;
297 hstats->lip_count = fcstats->fc.lip_count;
298 hstats->nos_count = fcstats->fc.nos_count;
299 hstats->error_frames = fcstats->fc.error_frames;
300 hstats->dumped_frames = fcstats->fc.dropped_frames;
301 hstats->link_failure_count = fcstats->fc.link_failures;
302 hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
303 hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
304 hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
305 hstats->invalid_crc_count = fcstats->fc.invalid_crcs;
306
307 kfree(fcstats);
Jing Huang7725ccf2009-09-23 17:46:15 -0700308 return hstats;
309}
310
Jing Huang5fbe25c2010-10-18 17:17:23 -0700311/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700312 * FC transport template entry, reset BFAD statistics.
313 */
314static void
315bfad_im_reset_stats(struct Scsi_Host *shost)
316{
317 struct bfad_im_port_s *im_port =
318 (struct bfad_im_port_s *) shost->hostdata[0];
319 struct bfad_s *bfad = im_port->bfad;
320 struct bfad_hal_comp fcomp;
321 unsigned long flags;
322 bfa_status_t rc;
323
324 init_completion(&fcomp.comp);
325 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800326 rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 &fcomp);
Jing Huang7725ccf2009-09-23 17:46:15 -0700328 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
329
330 if (rc != BFA_STATUS_OK)
331 return;
332
333 wait_for_completion(&fcomp.comp);
334
335 return;
336}
337
Jing Huang5fbe25c2010-10-18 17:17:23 -0700338/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700339 * FC transport template entry, set rport loss timeout.
Vijaya Mohan Guvva4dde5062013-05-13 02:33:34 -0700340 * Update dev_loss_tmo based on the value pushed down by the stack
341 * In case it is lesser than path_tov of driver, set it to path_tov + 1
342 * to ensure that the driver times out before the application
Jing Huang7725ccf2009-09-23 17:46:15 -0700343 */
344static void
345bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
346{
347 struct bfad_itnim_data_s *itnim_data = rport->dd_data;
348 struct bfad_itnim_s *itnim = itnim_data->itnim;
349 struct bfad_s *bfad = itnim->im->bfad;
Vijaya Mohan Guvva4dde5062013-05-13 02:33:34 -0700350 uint16_t path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700351
Vijaya Mohan Guvva4dde5062013-05-13 02:33:34 -0700352 rport->dev_loss_tmo = timeout;
353 if (timeout < path_tov)
354 rport->dev_loss_tmo = path_tov + 1;
Jing Huang7725ccf2009-09-23 17:46:15 -0700355}
356
Jing Huangb5042932010-03-19 11:05:39 -0700357static int
358bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
359{
360 char *vname = fc_vport->symbolic_name;
361 struct Scsi_Host *shost = fc_vport->shost;
362 struct bfad_im_port_s *im_port =
363 (struct bfad_im_port_s *) shost->hostdata[0];
364 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700365 struct bfa_lport_cfg_s port_cfg;
366 struct bfad_vport_s *vp;
Jing Huangb5042932010-03-19 11:05:39 -0700367 int status = 0, rc;
368 unsigned long flags;
369
370 memset(&port_cfg, 0, sizeof(port_cfg));
Jing Huangd9883542010-07-08 19:46:26 -0700371 u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
372 u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700373 if (strlen(vname) > 0)
374 strcpy((char *)&port_cfg.sym_name, vname);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700375 port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
Jing Huangb5042932010-03-19 11:05:39 -0700376
Jing Huangd9883542010-07-08 19:46:26 -0700377 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
379 if (port_cfg.pwwn ==
380 vp->fcs_vport.lport.port_cfg.pwwn) {
381 port_cfg.preboot_vp =
382 vp->fcs_vport.lport.port_cfg.preboot_vp;
Jing Huangd9883542010-07-08 19:46:26 -0700383 break;
384 }
385 }
386 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
387
388 rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
Jing Huangb5042932010-03-19 11:05:39 -0700389 if (rc == BFA_STATUS_OK) {
Jing Huangd9883542010-07-08 19:46:26 -0700390 struct bfad_vport_s *vport;
Jing Huangb5042932010-03-19 11:05:39 -0700391 struct bfa_fcs_vport_s *fcs_vport;
392 struct Scsi_Host *vshost;
393
394 spin_lock_irqsave(&bfad->bfad_lock, flags);
395 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
396 port_cfg.pwwn);
Jing Huangd9883542010-07-08 19:46:26 -0700397 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
398 if (fcs_vport == NULL)
Jing Huangb5042932010-03-19 11:05:39 -0700399 return VPCERR_BAD_WWN;
Jing Huangb5042932010-03-19 11:05:39 -0700400
401 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
402 if (disable) {
Jing Huangd9883542010-07-08 19:46:26 -0700403 spin_lock_irqsave(&bfad->bfad_lock, flags);
Jing Huangb5042932010-03-19 11:05:39 -0700404 bfa_fcs_vport_stop(fcs_vport);
Jing Huangd9883542010-07-08 19:46:26 -0700405 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Jing Huangb5042932010-03-19 11:05:39 -0700406 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
407 }
Jing Huangb5042932010-03-19 11:05:39 -0700408
409 vport = fcs_vport->vport_drv;
410 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700411 fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
412 fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
Krishna Gudipati6192bd72012-05-11 17:49:59 -0700413 fc_host_supported_classes(vshost) = FC_COS_CLASS3;
414
415 memset(fc_host_supported_fc4s(vshost), 0,
416 sizeof(fc_host_supported_fc4s(vshost)));
417
418 /* For FCP type 0x08 */
419 if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
420 fc_host_supported_fc4s(vshost)[2] = 1;
421
422 /* For fibre channel services type 0x20 */
423 fc_host_supported_fc4s(vshost)[7] = 1;
424
425 fc_host_supported_speeds(vshost) =
426 bfad_im_supported_speeds(&bfad->bfa);
427 fc_host_maxframe_size(vshost) =
428 bfa_fcport_get_maxfrsize(&bfad->bfa);
429
Jing Huangb5042932010-03-19 11:05:39 -0700430 fc_vport->dd_data = vport;
431 vport->drv_port.im_port->fc_vport = fc_vport;
Jing Huangb5042932010-03-19 11:05:39 -0700432 } else if (rc == BFA_STATUS_INVALID_WWN)
433 return VPCERR_BAD_WWN;
434 else if (rc == BFA_STATUS_VPORT_EXISTS)
435 return VPCERR_BAD_WWN;
436 else if (rc == BFA_STATUS_VPORT_MAX)
437 return VPCERR_NO_FABRIC_SUPP;
438 else if (rc == BFA_STATUS_VPORT_WWN_BP)
439 return VPCERR_BAD_WWN;
Jing Huangd9883542010-07-08 19:46:26 -0700440 else
Jing Huangb5042932010-03-19 11:05:39 -0700441 return FC_VPORT_FAILED;
442
443 return status;
444}
445
Krishna Gudipatiacea2412012-03-13 17:37:26 -0700446int
447bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
448{
449 struct bfad_im_port_s *im_port =
450 (struct bfad_im_port_s *) shost->hostdata[0];
451 struct bfad_s *bfad = im_port->bfad;
452 struct bfad_hal_comp fcomp;
453 unsigned long flags;
454 uint32_t status;
455
456 init_completion(&fcomp.comp);
457 spin_lock_irqsave(&bfad->bfad_lock, flags);
458 status = bfa_port_disable(&bfad->bfa.modules.port,
459 bfad_hcb_comp, &fcomp);
460 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
461
462 if (status != BFA_STATUS_OK)
463 return -EIO;
464
465 wait_for_completion(&fcomp.comp);
466 if (fcomp.status != BFA_STATUS_OK)
467 return -EIO;
468
469 spin_lock_irqsave(&bfad->bfad_lock, flags);
470 status = bfa_port_enable(&bfad->bfa.modules.port,
471 bfad_hcb_comp, &fcomp);
472 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
473 if (status != BFA_STATUS_OK)
474 return -EIO;
475
476 wait_for_completion(&fcomp.comp);
477 if (fcomp.status != BFA_STATUS_OK)
478 return -EIO;
479
480 return 0;
481}
482
Jing Huangb5042932010-03-19 11:05:39 -0700483static int
484bfad_im_vport_delete(struct fc_vport *fc_vport)
485{
486 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
487 struct bfad_im_port_s *im_port =
488 (struct bfad_im_port_s *) vport->drv_port.im_port;
489 struct bfad_s *bfad = im_port->bfad;
Jing Huangb5042932010-03-19 11:05:39 -0700490 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
Jing Huangb5042932010-03-19 11:05:39 -0700504 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700505 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700506
507 spin_lock_irqsave(&bfad->bfad_lock, flags);
508 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
509 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
510
511 if (fcs_vport == NULL)
512 return VPCERR_BAD_WWN;
513
514 vport->drv_port.flags |= BFAD_PORT_DELETE;
515
516 vport->comp_del = &fcomp;
517 init_completion(vport->comp_del);
518
519 spin_lock_irqsave(&bfad->bfad_lock, flags);
520 rc = bfa_fcs_vport_delete(&vport->fcs_vport);
521 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
522
Jing Huangc54d5572010-07-08 20:01:49 -0700523 if (rc == BFA_STATUS_PBC) {
524 vport->drv_port.flags &= ~BFAD_PORT_DELETE;
525 vport->comp_del = NULL;
Jing Huangd9883542010-07-08 19:46:26 -0700526 return -1;
Jing Huangc54d5572010-07-08 20:01:49 -0700527 }
Jing Huangd9883542010-07-08 19:46:26 -0700528
Jing Huangb5042932010-03-19 11:05:39 -0700529 wait_for_completion(vport->comp_del);
530
Maggie Zhangf16a1752010-12-09 19:12:32 -0800531 bfad_scsi_host_free(bfad, im_port);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800532 list_del(&vport->list_entry);
Jing Huangb5042932010-03-19 11:05:39 -0700533 kfree(vport);
534
535 return 0;
536}
537
538static int
539bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
540{
541 struct bfad_vport_s *vport;
542 struct bfad_s *bfad;
543 struct bfa_fcs_vport_s *fcs_vport;
544 struct Scsi_Host *vshost;
545 wwn_t pwwn;
546 unsigned long flags;
547
548 vport = (struct bfad_vport_s *)fc_vport->dd_data;
549 bfad = vport->drv_port.bfad;
550 vshost = vport->drv_port.im_port->shost;
Jing Huangd9883542010-07-08 19:46:26 -0700551 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
Jing Huangb5042932010-03-19 11:05:39 -0700552
553 spin_lock_irqsave(&bfad->bfad_lock, flags);
554 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
555 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
556
557 if (fcs_vport == NULL)
558 return VPCERR_BAD_WWN;
559
560 if (disable) {
561 bfa_fcs_vport_stop(fcs_vport);
562 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
563 } else {
564 bfa_fcs_vport_start(fcs_vport);
565 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
566 }
567
568 return 0;
569}
570
Krishna Gudipatiebfe8392012-08-22 19:50:20 -0700571void
572bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport)
573{
574 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
575 struct bfad_im_port_s *im_port =
576 (struct bfad_im_port_s *)vport->drv_port.im_port;
577 struct bfad_s *bfad = im_port->bfad;
578 struct Scsi_Host *vshost = vport->drv_port.im_port->shost;
579 char *sym_name = fc_vport->symbolic_name;
580 struct bfa_fcs_vport_s *fcs_vport;
581 wwn_t pwwn;
582 unsigned long flags;
583
584 u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
585
586 spin_lock_irqsave(&bfad->bfad_lock, flags);
587 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
588 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
589
590 if (fcs_vport == NULL)
591 return;
592
593 spin_lock_irqsave(&bfad->bfad_lock, flags);
Vijaya Mohan Guvva22a08532013-11-21 01:37:49 -0800594 if (strlen(sym_name) > 0)
595 bfa_fcs_lport_set_symname(&fcs_vport->lport, sym_name);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -0700596 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
597}
598
Jing Huang7725ccf2009-09-23 17:46:15 -0700599struct fc_function_template bfad_im_fc_function_template = {
600
601 /* Target dynamic attributes */
602 .get_starget_port_id = bfad_im_get_starget_port_id,
603 .show_starget_port_id = 1,
604 .get_starget_node_name = bfad_im_get_starget_node_name,
605 .show_starget_node_name = 1,
606 .get_starget_port_name = bfad_im_get_starget_port_name,
607 .show_starget_port_name = 1,
608
609 /* Host dynamic attribute */
610 .get_host_port_id = bfad_im_get_host_port_id,
611 .show_host_port_id = 1,
612
613 /* Host fixed attributes */
614 .show_host_node_name = 1,
615 .show_host_port_name = 1,
616 .show_host_supported_classes = 1,
617 .show_host_supported_fc4s = 1,
618 .show_host_supported_speeds = 1,
619 .show_host_maxframe_size = 1,
620
621 /* More host dynamic attributes */
622 .show_host_port_type = 1,
623 .get_host_port_type = bfad_im_get_host_port_type,
624 .show_host_port_state = 1,
625 .get_host_port_state = bfad_im_get_host_port_state,
626 .show_host_active_fc4s = 1,
627 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
628 .show_host_speed = 1,
629 .get_host_speed = bfad_im_get_host_speed,
630 .show_host_fabric_name = 1,
631 .get_host_fabric_name = bfad_im_get_host_fabric_name,
632
633 .show_host_symbolic_name = 1,
634
635 /* Statistics */
636 .get_fc_host_stats = bfad_im_get_stats,
637 .reset_fc_host_stats = bfad_im_reset_stats,
638
639 /* Allocation length for host specific data */
640 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
641
642 /* Remote port fixed attributes */
643 .show_rport_maxframe_size = 1,
644 .show_rport_supported_classes = 1,
645 .show_rport_dev_loss_tmo = 1,
Jing Huang7725ccf2009-09-23 17:46:15 -0700646 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
Krishna Gudipatiacea2412012-03-13 17:37:26 -0700647 .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
Jing Huangb5042932010-03-19 11:05:39 -0700648 .vport_create = bfad_im_vport_create,
649 .vport_delete = bfad_im_vport_delete,
650 .vport_disable = bfad_im_vport_disable,
Krishna Gudipatiebfe8392012-08-22 19:50:20 -0700651 .set_vport_symbolic_name = bfad_im_vport_set_symbolic_name,
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700652 .bsg_request = bfad_im_bsg_request,
653 .bsg_timeout = bfad_im_bsg_timeout,
Jing Huangb5042932010-03-19 11:05:39 -0700654};
655
656struct fc_function_template bfad_im_vport_fc_function_template = {
657
658 /* Target dynamic attributes */
659 .get_starget_port_id = bfad_im_get_starget_port_id,
660 .show_starget_port_id = 1,
661 .get_starget_node_name = bfad_im_get_starget_node_name,
662 .show_starget_node_name = 1,
663 .get_starget_port_name = bfad_im_get_starget_port_name,
664 .show_starget_port_name = 1,
665
666 /* Host dynamic attribute */
667 .get_host_port_id = bfad_im_get_host_port_id,
668 .show_host_port_id = 1,
669
670 /* Host fixed attributes */
671 .show_host_node_name = 1,
672 .show_host_port_name = 1,
673 .show_host_supported_classes = 1,
674 .show_host_supported_fc4s = 1,
675 .show_host_supported_speeds = 1,
676 .show_host_maxframe_size = 1,
677
678 /* More host dynamic attributes */
679 .show_host_port_type = 1,
680 .get_host_port_type = bfad_im_get_host_port_type,
681 .show_host_port_state = 1,
682 .get_host_port_state = bfad_im_get_host_port_state,
683 .show_host_active_fc4s = 1,
684 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
685 .show_host_speed = 1,
686 .get_host_speed = bfad_im_get_host_speed,
687 .show_host_fabric_name = 1,
688 .get_host_fabric_name = bfad_im_get_host_fabric_name,
689
690 .show_host_symbolic_name = 1,
691
692 /* Statistics */
693 .get_fc_host_stats = bfad_im_get_stats,
694 .reset_fc_host_stats = bfad_im_reset_stats,
695
696 /* Allocation length for host specific data */
697 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
698
699 /* Remote port fixed attributes */
700 .show_rport_maxframe_size = 1,
701 .show_rport_supported_classes = 1,
702 .show_rport_dev_loss_tmo = 1,
Jing Huangb5042932010-03-19 11:05:39 -0700703 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
Jing Huang7725ccf2009-09-23 17:46:15 -0700704};
705
Jing Huang5fbe25c2010-10-18 17:17:23 -0700706/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700707 * Scsi_Host_attrs SCSI host attributes
708 */
709static ssize_t
710bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
711 char *buf)
712{
713 struct Scsi_Host *shost = class_to_shost(dev);
714 struct bfad_im_port_s *im_port =
715 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700716 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800717 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700718
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800719 bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
720 return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
Jing Huang7725ccf2009-09-23 17:46:15 -0700721}
722
723static ssize_t
724bfad_im_model_show(struct device *dev, struct device_attribute *attr,
725 char *buf)
726{
727 struct Scsi_Host *shost = class_to_shost(dev);
728 struct bfad_im_port_s *im_port =
729 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700730 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800731 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700732
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800733 bfa_get_adapter_model(&bfad->bfa, model);
734 return snprintf(buf, PAGE_SIZE, "%s\n", model);
Jing Huang7725ccf2009-09-23 17:46:15 -0700735}
736
737static ssize_t
738bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
739 char *buf)
740{
741 struct Scsi_Host *shost = class_to_shost(dev);
742 struct bfad_im_port_s *im_port =
743 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700744 struct bfad_s *bfad = im_port->bfad;
745 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800746 char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
Krishna Gudipati75332a72011-06-13 15:54:31 -0700747 int nports = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -0700748
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749 bfa_get_adapter_model(&bfad->bfa, model);
Krishna Gudipati75332a72011-06-13 15:54:31 -0700750 nports = bfa_get_nports(&bfad->bfa);
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500751 if (!strcmp(model, "QLogic-425"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500753 "QLogic BR-series 4Gbps PCIe dual port FC HBA");
754 else if (!strcmp(model, "QLogic-825"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700755 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500756 "QLogic BR-series 8Gbps PCIe dual port FC HBA");
757 else if (!strcmp(model, "QLogic-42B"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700758 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500759 "QLogic BR-series 4Gbps PCIe dual port FC HBA for HP");
760 else if (!strcmp(model, "QLogic-82B"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500762 "QLogic BR-series 8Gbps PCIe dual port FC HBA for HP");
763 else if (!strcmp(model, "QLogic-1010"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700764 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500765 "QLogic BR-series 10Gbps single port CNA");
766 else if (!strcmp(model, "QLogic-1020"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700767 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500768 "QLogic BR-series 10Gbps dual port CNA");
769 else if (!strcmp(model, "QLogic-1007"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500771 "QLogic BR-series 10Gbps CNA for IBM Blade Center");
772 else if (!strcmp(model, "QLogic-415"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500774 "QLogic BR-series 4Gbps PCIe single port FC HBA");
775 else if (!strcmp(model, "QLogic-815"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500777 "QLogic BR-series 8Gbps PCIe single port FC HBA");
778 else if (!strcmp(model, "QLogic-41B"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700779 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500780 "QLogic BR-series 4Gbps PCIe single port FC HBA for HP");
781 else if (!strcmp(model, "QLogic-81B"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700782 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500783 "QLogic BR-series 8Gbps PCIe single port FC HBA for HP");
784 else if (!strcmp(model, "QLogic-804"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500786 "QLogic BR-series 8Gbps FC HBA for HP Bladesystem C-class");
787 else if (!strcmp(model, "QLogic-1741"))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700788 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500789 "QLogic BR-series 10Gbps CNA for Dell M-Series Blade Servers");
790 else if (strstr(model, "QLogic-1860")) {
Krishna Gudipati75332a72011-06-13 15:54:31 -0700791 if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
792 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500793 "QLogic BR-series 10Gbps single port CNA");
Krishna Gudipati75332a72011-06-13 15:54:31 -0700794 else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
795 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500796 "QLogic BR-series 16Gbps PCIe single port FC HBA");
Krishna Gudipati75332a72011-06-13 15:54:31 -0700797 else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
798 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500799 "QLogic BR-series 10Gbps dual port CNA");
Krishna Gudipati75332a72011-06-13 15:54:31 -0700800 else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
801 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500802 "QLogic BR-series 16Gbps PCIe dual port FC HBA");
803 } else if (!strcmp(model, "QLogic-1867")) {
Krishna Gudipati6dca60a32012-08-22 19:51:35 -0700804 if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
805 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500806 "QLogic BR-series 16Gbps PCIe single port FC HBA for IBM");
Krishna Gudipati6dca60a32012-08-22 19:51:35 -0700807 else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
808 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500809 "QLogic BR-series 16Gbps PCIe dual port FC HBA for IBM");
Krishna Gudipati75332a72011-06-13 15:54:31 -0700810 } else
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
812 "Invalid Model");
813
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800814 return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700815}
816
817static ssize_t
818bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
819 char *buf)
820{
821 struct Scsi_Host *shost = class_to_shost(dev);
822 struct bfad_im_port_s *im_port =
823 (struct bfad_im_port_s *) shost->hostdata[0];
824 struct bfad_port_s *port = im_port->port;
825 u64 nwwn;
826
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700827 nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
Jing Huangba816ea2010-10-18 17:10:50 -0700828 return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
Jing Huang7725ccf2009-09-23 17:46:15 -0700829}
830
831static ssize_t
832bfad_im_symbolic_name_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;
839 struct bfa_lport_attr_s port_attr;
840 char symname[BFA_SYMNAME_MAXLEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700841
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700842 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100843 strlcpy(symname, port_attr.port_cfg.sym_name.symname,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700844 BFA_SYMNAME_MAXLEN);
845 return snprintf(buf, PAGE_SIZE, "%s\n", symname);
Jing Huang7725ccf2009-09-23 17:46:15 -0700846}
847
848static ssize_t
849bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
850 char *buf)
851{
852 struct Scsi_Host *shost = class_to_shost(dev);
853 struct bfad_im_port_s *im_port =
854 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800856 char hw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700857
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800858 bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
859 return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700860}
861
862static ssize_t
863bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
864 char *buf)
865{
866 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
867}
868
869static ssize_t
870bfad_im_optionrom_version_show(struct device *dev,
871 struct device_attribute *attr, char *buf)
872{
873 struct Scsi_Host *shost = class_to_shost(dev);
874 struct bfad_im_port_s *im_port =
875 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700876 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800877 char optrom_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700878
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800879 bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
880 return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700881}
882
883static ssize_t
884bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
885 char *buf)
886{
887 struct Scsi_Host *shost = class_to_shost(dev);
888 struct bfad_im_port_s *im_port =
889 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800891 char fw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700892
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800893 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
894 return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700895}
896
897static ssize_t
898bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
899 char *buf)
900{
901 struct Scsi_Host *shost = class_to_shost(dev);
902 struct bfad_im_port_s *im_port =
903 (struct bfad_im_port_s *) shost->hostdata[0];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700904 struct bfad_s *bfad = im_port->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -0700905
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800906 return snprintf(buf, PAGE_SIZE, "%d\n",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700907 bfa_get_nports(&bfad->bfa));
Jing Huang7725ccf2009-09-23 17:46:15 -0700908}
909
910static ssize_t
911bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
912 char *buf)
913{
914 return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
915}
916
917static ssize_t
918bfad_im_num_of_discovered_ports_show(struct device *dev,
919 struct device_attribute *attr, char *buf)
920{
921 struct Scsi_Host *shost = class_to_shost(dev);
922 struct bfad_im_port_s *im_port =
923 (struct bfad_im_port_s *) shost->hostdata[0];
924 struct bfad_port_s *port = im_port->port;
925 struct bfad_s *bfad = im_port->bfad;
926 int nrports = 2048;
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700927 struct bfa_rport_qualifier_s *rports = NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700928 unsigned long flags;
929
Kees Cook6396bb22018-06-12 14:03:40 -0700930 rports = kcalloc(nrports, sizeof(struct bfa_rport_qualifier_s),
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700931 GFP_ATOMIC);
Jing Huang7725ccf2009-09-23 17:46:15 -0700932 if (rports == NULL)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700933 return snprintf(buf, PAGE_SIZE, "Failed\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700934
935 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700936 bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports);
Jing Huang7725ccf2009-09-23 17:46:15 -0700937 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
938 kfree(rports);
939
940 return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
941}
942
943static DEVICE_ATTR(serial_number, S_IRUGO,
944 bfad_im_serial_num_show, NULL);
945static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
946static DEVICE_ATTR(model_description, S_IRUGO,
947 bfad_im_model_desc_show, NULL);
948static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
949static DEVICE_ATTR(symbolic_name, S_IRUGO,
950 bfad_im_symbolic_name_show, NULL);
951static DEVICE_ATTR(hardware_version, S_IRUGO,
952 bfad_im_hw_version_show, NULL);
953static DEVICE_ATTR(driver_version, S_IRUGO,
954 bfad_im_drv_version_show, NULL);
955static DEVICE_ATTR(option_rom_version, S_IRUGO,
956 bfad_im_optionrom_version_show, NULL);
957static DEVICE_ATTR(firmware_version, S_IRUGO,
958 bfad_im_fw_version_show, NULL);
959static DEVICE_ATTR(number_of_ports, S_IRUGO,
960 bfad_im_num_of_ports_show, NULL);
961static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
962static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
963 bfad_im_num_of_discovered_ports_show, NULL);
964
965struct device_attribute *bfad_im_host_attrs[] = {
966 &dev_attr_serial_number,
967 &dev_attr_model,
968 &dev_attr_model_description,
969 &dev_attr_node_name,
970 &dev_attr_symbolic_name,
971 &dev_attr_hardware_version,
972 &dev_attr_driver_version,
973 &dev_attr_option_rom_version,
974 &dev_attr_firmware_version,
975 &dev_attr_number_of_ports,
976 &dev_attr_driver_name,
977 &dev_attr_number_of_discovered_ports,
978 NULL,
979};
980
981struct device_attribute *bfad_im_vport_attrs[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700982 &dev_attr_serial_number,
983 &dev_attr_model,
984 &dev_attr_model_description,
985 &dev_attr_node_name,
986 &dev_attr_symbolic_name,
987 &dev_attr_hardware_version,
988 &dev_attr_driver_version,
989 &dev_attr_option_rom_version,
990 &dev_attr_firmware_version,
991 &dev_attr_number_of_ports,
992 &dev_attr_driver_name,
993 &dev_attr_number_of_discovered_ports,
994 NULL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700995};
996
997