[zbin] Fix check for existence of most recent output byte
[ipxe.git] / src / usr / fcmgmt.c
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
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <errno.h>
25 #include <ipxe/fc.h>
26 #include <ipxe/fcels.h>
27 #include <ipxe/monojob.h>
28 #include <usr/fcmgmt.h>
29
30 /** @file
31 *
32 * Fibre Channel management
33 *
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 /**
60 * Print status of Fibre Channel peer
61 *
62 * @v peer Fibre Channel peer
63 */
64 void fcpeerstat ( struct fc_peer *peer ) {
65 struct fc_ulp *ulp;
66 uint8_t *param;
67 unsigned int i;
68
69 printf ( "%s:\n [Link:", fc_ntoa ( &peer->port_wwn ) );
70 if ( fc_link_ok ( &peer->link ) ) {
71 printf ( " up, port %s id %s]\n", peer->port->name,
72 fc_id_ntoa ( &peer->port_id ) );
73 } else {
74 printf ( " down: %s]\n", strerror ( peer->link.rc ) );
75 }
76
77 list_for_each_entry ( ulp, &peer->ulps, list ) {
78 printf ( " [Type %02x link:", ulp->type );
79 if ( fc_link_ok ( &ulp->link ) ) {
80 printf ( " up, params" );
81 param = ulp->param;
82 for ( i = 0 ; i < ulp->param_len ; i++ ) {
83 printf ( "%c%02x", ( ( i == 0 ) ? ' ' : ':' ),
84 param[i] );
85 }
86 } else {
87 printf ( " down: %s", strerror ( ulp->link.rc ) );
88 }
89 printf ( "]\n" );
90 }
91 }
92
93 /**
94 * Issue Fibre Channel ELS
95 *
96 * @v port Fibre Channel port
97 * @v peer_port_id Peer port ID
98 * @v handler ELS handler
99 * @ret rc Return status code
100 */
101 int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
102 struct fc_els_handler *handler ) {
103 int rc;
104
105 /* Initiate ELS */
106 printf ( "%s %s to %s...",
107 port->name, handler->name, fc_id_ntoa ( peer_port_id ) );
108 if ( ( rc = fc_els_request ( &monojob, port, peer_port_id,
109 handler ) ) != 0 ) {
110 printf ( "%s\n", strerror ( rc ) );
111 return rc;
112 }
113
114 /* Wait for ELS to complete */
115 return monojob_wait ( "", 0 );
116 }