You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fcmgmt.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <errno.h>
  27. #include <ipxe/fc.h>
  28. #include <ipxe/fcels.h>
  29. #include <ipxe/monojob.h>
  30. #include <usr/fcmgmt.h>
  31. /** @file
  32. *
  33. * Fibre Channel management
  34. *
  35. */
  36. /**
  37. * Print status of Fibre Channel port
  38. *
  39. * @v port Fibre Channel port
  40. */
  41. void fcportstat ( struct fc_port *port ) {
  42. printf ( "%s: %s id %s", port->name, fc_ntoa ( &port->port_wwn ),
  43. fc_id_ntoa ( &port->port_id ) );
  44. printf ( " node %s\n [Link:", fc_ntoa ( &port->node_wwn ) );
  45. if ( fc_link_ok ( &port->link ) ) {
  46. printf ( " up, %s", fc_ntoa ( &port->link_port_wwn ) );
  47. if ( ( port->flags & FC_PORT_HAS_FABRIC ) ) {
  48. printf ( " fabric" );
  49. } else {
  50. printf ( " id %s",
  51. fc_id_ntoa ( &port->ptp_link_port_id ) );
  52. }
  53. printf ( " node %s]\n", fc_ntoa ( &port->link_node_wwn ) );
  54. } else {
  55. printf ( " down: %s]\n", strerror ( port->link.rc ) );
  56. }
  57. }
  58. /**
  59. * Print status of Fibre Channel peer
  60. *
  61. * @v peer Fibre Channel peer
  62. */
  63. void fcpeerstat ( struct fc_peer *peer ) {
  64. struct fc_ulp *ulp;
  65. uint8_t *param;
  66. unsigned int i;
  67. printf ( "%s:\n [Link:", fc_ntoa ( &peer->port_wwn ) );
  68. if ( fc_link_ok ( &peer->link ) ) {
  69. printf ( " up, port %s id %s]\n", peer->port->name,
  70. fc_id_ntoa ( &peer->port_id ) );
  71. } else {
  72. printf ( " down: %s]\n", strerror ( peer->link.rc ) );
  73. }
  74. list_for_each_entry ( ulp, &peer->ulps, list ) {
  75. printf ( " [Type %02x link:", ulp->type );
  76. if ( fc_link_ok ( &ulp->link ) ) {
  77. printf ( " up, params" );
  78. param = ulp->param;
  79. for ( i = 0 ; i < ulp->param_len ; i++ ) {
  80. printf ( "%c%02x", ( ( i == 0 ) ? ' ' : ':' ),
  81. param[i] );
  82. }
  83. } else {
  84. printf ( " down: %s", strerror ( ulp->link.rc ) );
  85. }
  86. printf ( "]\n" );
  87. }
  88. }
  89. /**
  90. * Issue Fibre Channel ELS
  91. *
  92. * @v port Fibre Channel port
  93. * @v peer_port_id Peer port ID
  94. * @v handler ELS handler
  95. * @ret rc Return status code
  96. */
  97. int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
  98. struct fc_els_handler *handler ) {
  99. int rc;
  100. /* Initiate ELS */
  101. printf ( "%s %s to %s...",
  102. port->name, handler->name, fc_id_ntoa ( peer_port_id ) );
  103. if ( ( rc = fc_els_request ( &monojob, port, peer_port_id,
  104. handler ) ) != 0 ) {
  105. printf ( "%s\n", strerror ( rc ) );
  106. return rc;
  107. }
  108. /* Wait for ELS to complete */
  109. return monojob_wait ( "", 0 );
  110. }