lport_api.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  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. * port_api.c BFA FCS port
  19. */
  20. #include <fcs/bfa_fcs.h>
  21. #include <fcs/bfa_fcs_lport.h>
  22. #include <fcs/bfa_fcs_rport.h>
  23. #include "fcs_rport.h"
  24. #include "fcs_fabric.h"
  25. #include "fcs_trcmod.h"
  26. #include "fcs_vport.h"
  27. BFA_TRC_FILE(FCS, PORT_API);
  28. /**
  29. * fcs_port_api BFA FCS port API
  30. */
  31. void
  32. bfa_fcs_cfg_base_port(struct bfa_fcs_s *fcs, struct bfa_port_cfg_s *port_cfg)
  33. {
  34. }
  35. struct bfa_fcs_port_s *
  36. bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
  37. {
  38. return &fcs->fabric.bport;
  39. }
  40. wwn_t
  41. bfa_fcs_port_get_rport(struct bfa_fcs_port_s *port, wwn_t wwn, int index,
  42. int nrports, bfa_boolean_t bwwn)
  43. {
  44. struct list_head *qh, *qe;
  45. struct bfa_fcs_rport_s *rport = NULL;
  46. int i;
  47. struct bfa_fcs_s *fcs;
  48. if (port == NULL || nrports == 0)
  49. return (wwn_t) 0;
  50. fcs = port->fcs;
  51. bfa_trc(fcs, (u32) nrports);
  52. i = 0;
  53. qh = &port->rport_q;
  54. qe = bfa_q_first(qh);
  55. while ((qe != qh) && (i < nrports)) {
  56. rport = (struct bfa_fcs_rport_s *)qe;
  57. if (bfa_os_ntoh3b(rport->pid) > 0xFFF000) {
  58. qe = bfa_q_next(qe);
  59. bfa_trc(fcs, (u32) rport->pwwn);
  60. bfa_trc(fcs, rport->pid);
  61. bfa_trc(fcs, i);
  62. continue;
  63. }
  64. if (bwwn) {
  65. if (!memcmp(&wwn, &rport->pwwn, 8))
  66. break;
  67. } else {
  68. if (i == index)
  69. break;
  70. }
  71. i++;
  72. qe = bfa_q_next(qe);
  73. }
  74. bfa_trc(fcs, i);
  75. if (rport)
  76. return rport->pwwn;
  77. else
  78. return (wwn_t) 0;
  79. }
  80. void
  81. bfa_fcs_port_get_rports(struct bfa_fcs_port_s *port, wwn_t rport_wwns[],
  82. int *nrports)
  83. {
  84. struct list_head *qh, *qe;
  85. struct bfa_fcs_rport_s *rport = NULL;
  86. int i;
  87. struct bfa_fcs_s *fcs;
  88. if (port == NULL || rport_wwns == NULL || *nrports == 0)
  89. return;
  90. fcs = port->fcs;
  91. bfa_trc(fcs, (u32) *nrports);
  92. i = 0;
  93. qh = &port->rport_q;
  94. qe = bfa_q_first(qh);
  95. while ((qe != qh) && (i < *nrports)) {
  96. rport = (struct bfa_fcs_rport_s *)qe;
  97. if (bfa_os_ntoh3b(rport->pid) > 0xFFF000) {
  98. qe = bfa_q_next(qe);
  99. bfa_trc(fcs, (u32) rport->pwwn);
  100. bfa_trc(fcs, rport->pid);
  101. bfa_trc(fcs, i);
  102. continue;
  103. }
  104. rport_wwns[i] = rport->pwwn;
  105. i++;
  106. qe = bfa_q_next(qe);
  107. }
  108. bfa_trc(fcs, i);
  109. *nrports = i;
  110. return;
  111. }
  112. /*
  113. * Iterate's through all the rport's in the given port to
  114. * determine the maximum operating speed.
  115. */
  116. enum bfa_pport_speed
  117. bfa_fcs_port_get_rport_max_speed(struct bfa_fcs_port_s *port)
  118. {
  119. struct list_head *qh, *qe;
  120. struct bfa_fcs_rport_s *rport = NULL;
  121. struct bfa_fcs_s *fcs;
  122. enum bfa_pport_speed max_speed = 0;
  123. struct bfa_pport_attr_s pport_attr;
  124. enum bfa_pport_speed pport_speed;
  125. if (port == NULL)
  126. return 0;
  127. fcs = port->fcs;
  128. /*
  129. * Get Physical port's current speed
  130. */
  131. bfa_pport_get_attr(port->fcs->bfa, &pport_attr);
  132. pport_speed = pport_attr.speed;
  133. bfa_trc(fcs, pport_speed);
  134. qh = &port->rport_q;
  135. qe = bfa_q_first(qh);
  136. while (qe != qh) {
  137. rport = (struct bfa_fcs_rport_s *)qe;
  138. if ((bfa_os_ntoh3b(rport->pid) > 0xFFF000)
  139. || (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE)) {
  140. qe = bfa_q_next(qe);
  141. continue;
  142. }
  143. if ((rport->rpf.rpsc_speed == BFA_PPORT_SPEED_8GBPS)
  144. || (rport->rpf.rpsc_speed > pport_speed)) {
  145. max_speed = rport->rpf.rpsc_speed;
  146. break;
  147. } else if (rport->rpf.rpsc_speed > max_speed) {
  148. max_speed = rport->rpf.rpsc_speed;
  149. }
  150. qe = bfa_q_next(qe);
  151. }
  152. bfa_trc(fcs, max_speed);
  153. return max_speed;
  154. }
  155. struct bfa_fcs_port_s *
  156. bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
  157. {
  158. struct bfa_fcs_vport_s *vport;
  159. bfa_fcs_vf_t *vf;
  160. bfa_assert(fcs != NULL);
  161. vf = bfa_fcs_vf_lookup(fcs, vf_id);
  162. if (vf == NULL) {
  163. bfa_trc(fcs, vf_id);
  164. return NULL;
  165. }
  166. if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
  167. return &vf->bport;
  168. vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
  169. if (vport)
  170. return &vport->lport;
  171. return NULL;
  172. }
  173. /*
  174. * API corresponding to VmWare's NPIV_VPORT_GETINFO.
  175. */
  176. void
  177. bfa_fcs_port_get_info(struct bfa_fcs_port_s *port,
  178. struct bfa_port_info_s *port_info)
  179. {
  180. bfa_trc(port->fcs, port->fabric->fabric_name);
  181. if (port->vport == NULL) {
  182. /*
  183. * This is a Physical port
  184. */
  185. port_info->port_type = BFA_PORT_TYPE_PHYSICAL;
  186. /*
  187. * @todo : need to fix the state & reason
  188. */
  189. port_info->port_state = 0;
  190. port_info->offline_reason = 0;
  191. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  192. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  193. port_info->max_vports_supp = bfa_fcs_vport_get_max(port->fcs);
  194. port_info->num_vports_inuse =
  195. bfa_fcs_fabric_vport_count(port->fabric);
  196. port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
  197. port_info->num_rports_inuse = port->num_rports;
  198. } else {
  199. /*
  200. * This is a virtual port
  201. */
  202. port_info->port_type = BFA_PORT_TYPE_VIRTUAL;
  203. /*
  204. * @todo : need to fix the state & reason
  205. */
  206. port_info->port_state = 0;
  207. port_info->offline_reason = 0;
  208. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  209. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  210. }
  211. }
  212. void
  213. bfa_fcs_port_get_stats(struct bfa_fcs_port_s *fcs_port,
  214. struct bfa_port_stats_s *port_stats)
  215. {
  216. bfa_os_memcpy(port_stats, &fcs_port->stats,
  217. sizeof(struct bfa_port_stats_s));
  218. return;
  219. }
  220. void
  221. bfa_fcs_port_clear_stats(struct bfa_fcs_port_s *fcs_port)
  222. {
  223. bfa_os_memset(&fcs_port->stats, 0, sizeof(struct bfa_port_stats_s));
  224. return;
  225. }
  226. void
  227. bfa_fcs_port_enable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  228. {
  229. fcs_port->port_cfg.roles |= BFA_PORT_ROLE_FCP_IPFC;
  230. return;
  231. }
  232. void
  233. bfa_fcs_port_disable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  234. {
  235. fcs_port->port_cfg.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  236. return;
  237. }