lport_api.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. }
  81. void
  82. bfa_fcs_port_get_rports(struct bfa_fcs_port_s *port, wwn_t rport_wwns[],
  83. int *nrports)
  84. {
  85. struct list_head *qh, *qe;
  86. struct bfa_fcs_rport_s *rport = NULL;
  87. int i;
  88. struct bfa_fcs_s *fcs;
  89. if (port == NULL || rport_wwns == NULL || *nrports == 0)
  90. return;
  91. fcs = port->fcs;
  92. bfa_trc(fcs, (u32) *nrports);
  93. i = 0;
  94. qh = &port->rport_q;
  95. qe = bfa_q_first(qh);
  96. while ((qe != qh) && (i < *nrports)) {
  97. rport = (struct bfa_fcs_rport_s *)qe;
  98. if (bfa_os_ntoh3b(rport->pid) > 0xFFF000) {
  99. qe = bfa_q_next(qe);
  100. bfa_trc(fcs, (u32) rport->pwwn);
  101. bfa_trc(fcs, rport->pid);
  102. bfa_trc(fcs, i);
  103. continue;
  104. }
  105. rport_wwns[i] = rport->pwwn;
  106. i++;
  107. qe = bfa_q_next(qe);
  108. }
  109. bfa_trc(fcs, i);
  110. *nrports = i;
  111. return;
  112. }
  113. /*
  114. * Iterate's through all the rport's in the given port to
  115. * determine the maximum operating speed.
  116. */
  117. enum bfa_pport_speed
  118. bfa_fcs_port_get_rport_max_speed(struct bfa_fcs_port_s *port)
  119. {
  120. struct list_head *qh, *qe;
  121. struct bfa_fcs_rport_s *rport = NULL;
  122. struct bfa_fcs_s *fcs;
  123. enum bfa_pport_speed max_speed = 0;
  124. struct bfa_pport_attr_s pport_attr;
  125. enum bfa_pport_speed pport_speed;
  126. if (port == NULL)
  127. return 0;
  128. fcs = port->fcs;
  129. /*
  130. * Get Physical port's current speed
  131. */
  132. bfa_pport_get_attr(port->fcs->bfa, &pport_attr);
  133. pport_speed = pport_attr.speed;
  134. bfa_trc(fcs, pport_speed);
  135. qh = &port->rport_q;
  136. qe = bfa_q_first(qh);
  137. while (qe != qh) {
  138. rport = (struct bfa_fcs_rport_s *)qe;
  139. if ((bfa_os_ntoh3b(rport->pid) > 0xFFF000)
  140. || (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE)) {
  141. qe = bfa_q_next(qe);
  142. continue;
  143. }
  144. if ((rport->rpf.rpsc_speed == BFA_PPORT_SPEED_8GBPS)
  145. || (rport->rpf.rpsc_speed > pport_speed)) {
  146. max_speed = rport->rpf.rpsc_speed;
  147. break;
  148. } else if (rport->rpf.rpsc_speed > max_speed) {
  149. max_speed = rport->rpf.rpsc_speed;
  150. }
  151. qe = bfa_q_next(qe);
  152. }
  153. bfa_trc(fcs, max_speed);
  154. return max_speed;
  155. }
  156. struct bfa_fcs_port_s *
  157. bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
  158. {
  159. struct bfa_fcs_vport_s *vport;
  160. bfa_fcs_vf_t *vf;
  161. bfa_assert(fcs != NULL);
  162. vf = bfa_fcs_vf_lookup(fcs, vf_id);
  163. if (vf == NULL) {
  164. bfa_trc(fcs, vf_id);
  165. return (NULL);
  166. }
  167. if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
  168. return (&vf->bport);
  169. vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
  170. if (vport)
  171. return (&vport->lport);
  172. return (NULL);
  173. }
  174. /*
  175. * API corresponding to VmWare's NPIV_VPORT_GETINFO.
  176. */
  177. void
  178. bfa_fcs_port_get_info(struct bfa_fcs_port_s *port,
  179. struct bfa_port_info_s *port_info)
  180. {
  181. bfa_trc(port->fcs, port->fabric->fabric_name);
  182. if (port->vport == NULL) {
  183. /*
  184. * This is a Physical port
  185. */
  186. port_info->port_type = BFA_PORT_TYPE_PHYSICAL;
  187. /*
  188. * @todo : need to fix the state & reason
  189. */
  190. port_info->port_state = 0;
  191. port_info->offline_reason = 0;
  192. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  193. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  194. port_info->max_vports_supp = bfa_fcs_vport_get_max(port->fcs);
  195. port_info->num_vports_inuse =
  196. bfa_fcs_fabric_vport_count(port->fabric);
  197. port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
  198. port_info->num_rports_inuse = port->num_rports;
  199. } else {
  200. /*
  201. * This is a virtual port
  202. */
  203. port_info->port_type = BFA_PORT_TYPE_VIRTUAL;
  204. /*
  205. * @todo : need to fix the state & reason
  206. */
  207. port_info->port_state = 0;
  208. port_info->offline_reason = 0;
  209. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  210. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  211. }
  212. }
  213. void
  214. bfa_fcs_port_get_stats(struct bfa_fcs_port_s *fcs_port,
  215. struct bfa_port_stats_s *port_stats)
  216. {
  217. bfa_os_memcpy(port_stats, &fcs_port->stats,
  218. sizeof(struct bfa_port_stats_s));
  219. return;
  220. }
  221. void
  222. bfa_fcs_port_clear_stats(struct bfa_fcs_port_s *fcs_port)
  223. {
  224. bfa_os_memset(&fcs_port->stats, 0, sizeof(struct bfa_port_stats_s));
  225. return;
  226. }
  227. void
  228. bfa_fcs_port_enable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  229. {
  230. fcs_port->port_cfg.roles |= BFA_PORT_ROLE_FCP_IPFC;
  231. return;
  232. }
  233. void
  234. bfa_fcs_port_disable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  235. {
  236. fcs_port->port_cfg.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  237. return;
  238. }