lport_api.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. * To be used in TRL Functionality only
  117. */
  118. enum bfa_pport_speed
  119. bfa_fcs_port_get_rport_max_speed(struct bfa_fcs_port_s *port)
  120. {
  121. struct list_head *qh, *qe;
  122. struct bfa_fcs_rport_s *rport = NULL;
  123. struct bfa_fcs_s *fcs;
  124. enum bfa_pport_speed max_speed = 0;
  125. struct bfa_pport_attr_s pport_attr;
  126. enum bfa_pport_speed pport_speed, rport_speed;
  127. bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
  128. if (port == NULL)
  129. return 0;
  130. fcs = port->fcs;
  131. /*
  132. * Get Physical port's current speed
  133. */
  134. bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
  135. pport_speed = pport_attr.speed;
  136. bfa_trc(fcs, pport_speed);
  137. qh = &port->rport_q;
  138. qe = bfa_q_first(qh);
  139. while (qe != qh) {
  140. rport = (struct bfa_fcs_rport_s *) qe;
  141. if ((bfa_os_ntoh3b(rport->pid) > 0xFFF000) ||
  142. (bfa_fcs_rport_get_state(rport) ==
  143. BFA_RPORT_OFFLINE)) {
  144. qe = bfa_q_next(qe);
  145. continue;
  146. }
  147. rport_speed = rport->rpf.rpsc_speed;
  148. if ((trl_enabled) && (rport_speed ==
  149. BFA_PPORT_SPEED_UNKNOWN)) {
  150. /* Use default ratelim speed setting */
  151. rport_speed =
  152. bfa_fcport_get_ratelim_speed(port->fcs->bfa);
  153. }
  154. if ((rport_speed == BFA_PPORT_SPEED_8GBPS) ||
  155. (rport_speed > pport_speed)) {
  156. max_speed = rport_speed;
  157. break;
  158. } else if (rport_speed > max_speed) {
  159. max_speed = rport_speed;
  160. }
  161. qe = bfa_q_next(qe);
  162. }
  163. bfa_trc(fcs, max_speed);
  164. return max_speed;
  165. }
  166. struct bfa_fcs_port_s *
  167. bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
  168. {
  169. struct bfa_fcs_vport_s *vport;
  170. bfa_fcs_vf_t *vf;
  171. bfa_assert(fcs != NULL);
  172. vf = bfa_fcs_vf_lookup(fcs, vf_id);
  173. if (vf == NULL) {
  174. bfa_trc(fcs, vf_id);
  175. return NULL;
  176. }
  177. if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
  178. return &vf->bport;
  179. vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
  180. if (vport)
  181. return &vport->lport;
  182. return NULL;
  183. }
  184. /*
  185. * API corresponding to VmWare's NPIV_VPORT_GETINFO.
  186. */
  187. void
  188. bfa_fcs_port_get_info(struct bfa_fcs_port_s *port,
  189. struct bfa_port_info_s *port_info)
  190. {
  191. bfa_trc(port->fcs, port->fabric->fabric_name);
  192. if (port->vport == NULL) {
  193. /*
  194. * This is a Physical port
  195. */
  196. port_info->port_type = BFA_PORT_TYPE_PHYSICAL;
  197. /*
  198. * @todo : need to fix the state & reason
  199. */
  200. port_info->port_state = 0;
  201. port_info->offline_reason = 0;
  202. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  203. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  204. port_info->max_vports_supp =
  205. bfa_lps_get_max_vport(port->fcs->bfa);
  206. port_info->num_vports_inuse =
  207. bfa_fcs_fabric_vport_count(port->fabric);
  208. port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
  209. port_info->num_rports_inuse = port->num_rports;
  210. } else {
  211. /*
  212. * This is a virtual port
  213. */
  214. port_info->port_type = BFA_PORT_TYPE_VIRTUAL;
  215. /*
  216. * @todo : need to fix the state & reason
  217. */
  218. port_info->port_state = 0;
  219. port_info->offline_reason = 0;
  220. port_info->port_wwn = bfa_fcs_port_get_pwwn(port);
  221. port_info->node_wwn = bfa_fcs_port_get_nwwn(port);
  222. }
  223. }
  224. void
  225. bfa_fcs_port_get_stats(struct bfa_fcs_port_s *fcs_port,
  226. struct bfa_port_stats_s *port_stats)
  227. {
  228. bfa_os_memcpy(port_stats, &fcs_port->stats,
  229. sizeof(struct bfa_port_stats_s));
  230. return;
  231. }
  232. void
  233. bfa_fcs_port_clear_stats(struct bfa_fcs_port_s *fcs_port)
  234. {
  235. bfa_os_memset(&fcs_port->stats, 0, sizeof(struct bfa_port_stats_s));
  236. return;
  237. }
  238. void
  239. bfa_fcs_port_enable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  240. {
  241. fcs_port->port_cfg.roles |= BFA_PORT_ROLE_FCP_IPFC;
  242. return;
  243. }
  244. void
  245. bfa_fcs_port_disable_ipfc_roles(struct bfa_fcs_port_s *fcs_port)
  246. {
  247. fcs_port->port_cfg.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  248. return;
  249. }