2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 * port_api.c BFA FCS port
22 #include <fcs/bfa_fcs.h>
23 #include <fcs/bfa_fcs_lport.h>
24 #include <fcs/bfa_fcs_rport.h>
25 #include "fcs_rport.h"
26 #include "fcs_fabric.h"
27 #include "fcs_trcmod.h"
28 #include "fcs_vport.h"
30 BFA_TRC_FILE(FCS, PORT_API);
35 * fcs_port_api BFA FCS port API
39 bfa_fcs_cfg_base_port(struct bfa_fcs_s *fcs, struct bfa_port_cfg_s *port_cfg)
43 struct bfa_fcs_port_s *
44 bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
46 return &fcs->fabric.bport;
50 bfa_fcs_port_get_rport(struct bfa_fcs_port_s *port, wwn_t wwn, int index,
51 int nrports, bfa_boolean_t bwwn)
53 struct list_head *qh, *qe;
54 struct bfa_fcs_rport_s *rport = NULL;
56 struct bfa_fcs_s *fcs;
58 if (port == NULL || nrports == 0)
62 bfa_trc(fcs, (u32) nrports);
68 while ((qe != qh) && (i < nrports)) {
69 rport = (struct bfa_fcs_rport_s *)qe;
70 if (bfa_os_ntoh3b(rport->pid) > 0xFFF000) {
72 bfa_trc(fcs, (u32) rport->pwwn);
73 bfa_trc(fcs, rport->pid);
79 if (!memcmp(&wwn, &rport->pwwn, 8))
98 bfa_fcs_port_get_rports(struct bfa_fcs_port_s *port, wwn_t rport_wwns[],
101 struct list_head *qh, *qe;
102 struct bfa_fcs_rport_s *rport = NULL;
104 struct bfa_fcs_s *fcs;
106 if (port == NULL || rport_wwns == NULL || *nrports == 0)
110 bfa_trc(fcs, (u32) *nrports);
114 qe = bfa_q_first(qh);
116 while ((qe != qh) && (i < *nrports)) {
117 rport = (struct bfa_fcs_rport_s *)qe;
118 if (bfa_os_ntoh3b(rport->pid) > 0xFFF000) {
120 bfa_trc(fcs, (u32) rport->pwwn);
121 bfa_trc(fcs, rport->pid);
126 rport_wwns[i] = rport->pwwn;
138 * Iterate's through all the rport's in the given port to
139 * determine the maximum operating speed.
141 * To be used in TRL Functionality only
144 bfa_fcs_port_get_rport_max_speed(struct bfa_fcs_port_s *port)
146 struct list_head *qh, *qe;
147 struct bfa_fcs_rport_s *rport = NULL;
148 struct bfa_fcs_s *fcs;
149 enum bfa_pport_speed max_speed = 0;
150 struct bfa_pport_attr_s pport_attr;
151 enum bfa_pport_speed pport_speed, rport_speed;
152 bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
160 * Get Physical port's current speed
162 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
163 pport_speed = pport_attr.speed;
164 bfa_trc(fcs, pport_speed);
167 qe = bfa_q_first(qh);
170 rport = (struct bfa_fcs_rport_s *) qe;
171 if ((bfa_os_ntoh3b(rport->pid) > 0xFFF000) ||
172 (bfa_fcs_rport_get_state(rport) ==
173 BFA_RPORT_OFFLINE)) {
178 rport_speed = rport->rpf.rpsc_speed;
179 if ((trl_enabled) && (rport_speed ==
180 BFA_PPORT_SPEED_UNKNOWN)) {
181 /* Use default ratelim speed setting */
183 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
186 if ((rport_speed == BFA_PPORT_SPEED_8GBPS) ||
187 (rport_speed > pport_speed)) {
188 max_speed = rport_speed;
190 } else if (rport_speed > max_speed) {
191 max_speed = rport_speed;
197 bfa_trc(fcs, max_speed);
201 struct bfa_fcs_port_s *
202 bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
204 struct bfa_fcs_vport_s *vport;
207 bfa_assert(fcs != NULL);
209 vf = bfa_fcs_vf_lookup(fcs, vf_id);
215 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
218 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
220 return &vport->lport;
226 * API corresponding to VmWare's NPIV_VPORT_GETINFO.
229 bfa_fcs_port_get_info(struct bfa_fcs_port_s *port,
230 struct bfa_port_info_s *port_info)
233 bfa_trc(port->fcs, port->fabric->fabric_name);
235 if (port->vport == NULL) {
237 * This is a Physical port
239 port_info->port_type = BFA_PORT_TYPE_PHYSICAL;
242 * @todo : need to fix the state & reason
244 port_info->port_state = 0;
245 port_info->offline_reason = 0;
247 port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
248 port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
250 port_info->max_vports_supp =
251 bfa_lps_get_max_vport(port->fcs->bfa);
252 port_info->num_vports_inuse =
253 bfa_fcs_fabric_vport_count(port->fabric);
254 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
255 port_info->num_rports_inuse = port->num_rports;
258 * This is a virtual port
260 port_info->port_type = BFA_PORT_TYPE_VIRTUAL;
263 * @todo : need to fix the state & reason
265 port_info->port_state = 0;
266 port_info->offline_reason = 0;
268 port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
269 port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
274 bfa_fcs_port_get_stats(struct bfa_fcs_port_s *fcs_port,
275 struct bfa_port_stats_s *port_stats)
277 bfa_os_memcpy(port_stats, &fcs_port->stats,
278 sizeof(struct bfa_port_stats_s));
283 bfa_fcs_port_clear_stats(struct bfa_fcs_port_s *fcs_port)
285 bfa_os_memset(&fcs_port->stats, 0, sizeof(struct bfa_port_stats_s));
290 bfa_fcs_port_enable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
292 fcs_port->port_cfg.roles |= BFA_PORT_ROLE_FCP_IPFC;
297 bfa_fcs_port_disable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
299 fcs_port->port_cfg.roles &= ~BFA_PORT_ROLE_FCP_IPFC;