123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <ipxe/fc.h>
  23. #include <ipxe/fcels.h>
  24. #include <ipxe/monojob.h>
  25. #include <usr/fcmgmt.h>
  26. /** @file
  27. *
  28. * Fibre Channel management
  29. *
  30. */
  31. /**
  32. * Print status of Fibre Channel port
  33. *
  34. * @v port Fibre Channel port
  35. */
  36. void fcportstat ( struct fc_port *port ) {
  37. printf ( "%s: %s id %s", port->name, fc_ntoa ( &port->port_wwn ),
  38. fc_id_ntoa ( &port->port_id ) );
  39. printf ( " node %s\n [Link:", fc_ntoa ( &port->node_wwn ) );
  40. if ( fc_link_ok ( &port->link ) ) {
  41. printf ( " up, %s", fc_ntoa ( &port->link_port_wwn ) );
  42. if ( ( port->flags & FC_PORT_HAS_FABRIC ) ) {
  43. printf ( " fabric" );
  44. } else {
  45. printf ( " id %s",
  46. fc_id_ntoa ( &port->ptp_link_port_id ) );
  47. }
  48. printf ( " node %s]\n", fc_ntoa ( &port->link_node_wwn ) );
  49. } else {
  50. printf ( " down: %s]\n", strerror ( port->link.rc ) );
  51. }
  52. }
  53. /**
  54. * Print status of Fibre Channel peer
  55. *
  56. * @v peer Fibre Channel peer
  57. */
  58. void fcpeerstat ( struct fc_peer *peer ) {
  59. struct fc_ulp *ulp;
  60. uint8_t *param;
  61. unsigned int i;
  62. printf ( "%s:\n [Link:", fc_ntoa ( &peer->port_wwn ) );
  63. if ( fc_link_ok ( &peer->link ) ) {
  64. printf ( " up, port %s id %s]\n", peer->port->name,
  65. fc_id_ntoa ( &peer->port_id ) );
  66. } else {
  67. printf ( " down: %s]\n", strerror ( peer->link.rc ) );
  68. }
  69. list_for_each_entry ( ulp, &peer->ulps, list ) {
  70. printf ( " [Type %02x usage %d link:",
  71. ulp->type, ulp->usage );
  72. if ( fc_link_ok ( &ulp->link ) ) {
  73. printf ( " up, params" );
  74. param = ulp->param;
  75. for ( i = 0 ; i < ulp->param_len ; i++ ) {
  76. printf ( "%c%02x", ( ( i == 0 ) ? ' ' : ':' ),
  77. param[i] );
  78. }
  79. } else {
  80. printf ( " down: %s", strerror ( ulp->link.rc ) );
  81. }
  82. printf ( "]\n" );
  83. }
  84. }
  85. /**
  86. * Issue Fibre Channel ELS
  87. *
  88. * @v port Fibre Channel port
  89. * @v peer_port_id Peer port ID
  90. * @v handler ELS handler
  91. * @ret rc Return status code
  92. */
  93. int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
  94. struct fc_els_handler *handler ) {
  95. int rc;
  96. /* Initiate ELS */
  97. printf ( "%s %s to %s...",
  98. port->name, handler->name, fc_id_ntoa ( peer_port_id ) );
  99. if ( ( rc = fc_els_request ( &monojob, port, peer_port_id,
  100. handler ) ) != 0 ) {
  101. printf ( "%s\n", strerror ( rc ) );
  102. return rc;
  103. }
  104. /* Wait for ELS to complete */
  105. return monojob_wait ( "" );
  106. }