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.0KB

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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <errno.h>
  23. #include <ipxe/fc.h>
  24. #include <ipxe/fcels.h>
  25. #include <ipxe/monojob.h>
  26. #include <usr/fcmgmt.h>
  27. /** @file
  28. *
  29. * Fibre Channel management
  30. *
  31. */
  32. /**
  33. * Print status of Fibre Channel port
  34. *
  35. * @v port Fibre Channel port
  36. */
  37. void fcportstat ( struct fc_port *port ) {
  38. printf ( "%s: %s id %s", port->name, fc_ntoa ( &port->port_wwn ),
  39. fc_id_ntoa ( &port->port_id ) );
  40. printf ( " node %s\n [Link:", fc_ntoa ( &port->node_wwn ) );
  41. if ( fc_link_ok ( &port->link ) ) {
  42. printf ( " up, %s", fc_ntoa ( &port->link_port_wwn ) );
  43. if ( ( port->flags & FC_PORT_HAS_FABRIC ) ) {
  44. printf ( " fabric" );
  45. } else {
  46. printf ( " id %s",
  47. fc_id_ntoa ( &port->ptp_link_port_id ) );
  48. }
  49. printf ( " node %s]\n", fc_ntoa ( &port->link_node_wwn ) );
  50. } else {
  51. printf ( " down: %s]\n", strerror ( port->link.rc ) );
  52. }
  53. }
  54. /**
  55. * Print status of Fibre Channel peer
  56. *
  57. * @v peer Fibre Channel peer
  58. */
  59. void fcpeerstat ( struct fc_peer *peer ) {
  60. struct fc_ulp *ulp;
  61. uint8_t *param;
  62. unsigned int i;
  63. printf ( "%s:\n [Link:", fc_ntoa ( &peer->port_wwn ) );
  64. if ( fc_link_ok ( &peer->link ) ) {
  65. printf ( " up, port %s id %s]\n", peer->port->name,
  66. fc_id_ntoa ( &peer->port_id ) );
  67. } else {
  68. printf ( " down: %s]\n", strerror ( peer->link.rc ) );
  69. }
  70. list_for_each_entry ( ulp, &peer->ulps, list ) {
  71. printf ( " [Type %02x link:", ulp->type );
  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 ( "", 0 );
  106. }