iPXE
fcmgmt.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <string.h>
00027 #include <stdio.h>
00028 #include <errno.h>
00029 #include <ipxe/fc.h>
00030 #include <ipxe/fcels.h>
00031 #include <ipxe/monojob.h>
00032 #include <usr/fcmgmt.h>
00033 
00034 /** @file
00035  *
00036  * Fibre Channel management
00037  *
00038  */
00039 
00040 /**
00041  * Print status of Fibre Channel port
00042  *
00043  * @v port              Fibre Channel port
00044  */
00045 void fcportstat ( struct fc_port *port ) {
00046         printf ( "%s: %s id %s", port->name, fc_ntoa ( &port->port_wwn ),
00047                  fc_id_ntoa ( &port->port_id ) );
00048         printf ( " node %s\n  [Link:", fc_ntoa ( &port->node_wwn ) );
00049         if ( fc_link_ok ( &port->link ) ) {
00050                 printf ( " up, %s", fc_ntoa ( &port->link_port_wwn ) );
00051                 if ( ( port->flags & FC_PORT_HAS_FABRIC ) ) {
00052                         printf ( " fabric" );
00053                 } else {
00054                         printf ( " id %s",
00055                                  fc_id_ntoa ( &port->ptp_link_port_id ) );
00056                 }
00057                 printf ( " node %s]\n", fc_ntoa ( &port->link_node_wwn ) );
00058         } else {
00059                 printf ( " down: %s]\n", strerror ( port->link.rc ) );
00060         }
00061 }
00062 
00063 /**
00064  * Print status of Fibre Channel peer
00065  *
00066  * @v peer              Fibre Channel peer
00067  */
00068 void fcpeerstat ( struct fc_peer *peer ) {
00069         struct fc_ulp *ulp;
00070         uint8_t *param;
00071         unsigned int i;
00072 
00073         printf ( "%s:\n  [Link:", fc_ntoa ( &peer->port_wwn ) );
00074         if ( fc_link_ok ( &peer->link ) ) {
00075                 printf ( " up, port %s id %s]\n", peer->port->name,
00076                          fc_id_ntoa ( &peer->port_id ) );
00077         } else {
00078                 printf ( " down: %s]\n", strerror ( peer->link.rc ) );
00079         }
00080 
00081         list_for_each_entry ( ulp, &peer->ulps, list ) {
00082                 printf ( "  [Type %02x link:", ulp->type );
00083                 if ( fc_link_ok ( &ulp->link ) ) {
00084                         printf ( " up, params" );
00085                         param = ulp->param;
00086                         for ( i = 0 ; i < ulp->param_len ; i++ ) {
00087                                 printf ( "%c%02x", ( ( i == 0 ) ? ' ' : ':' ),
00088                                          param[i] );
00089                         }
00090                 } else {
00091                         printf ( " down: %s", strerror ( ulp->link.rc ) );
00092                 }
00093                 printf ( "]\n" );
00094         }
00095 }
00096 
00097 /**
00098  * Issue Fibre Channel ELS
00099  *
00100  * @v port              Fibre Channel port
00101  * @v peer_port_id      Peer port ID
00102  * @v handler           ELS handler
00103  * @ret rc              Return status code
00104  */
00105 int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
00106             struct fc_els_handler *handler ) {
00107         int rc;
00108 
00109         /* Initiate ELS */
00110         printf ( "%s %s to %s...",
00111                  port->name, handler->name, fc_id_ntoa ( peer_port_id ) );
00112         if ( ( rc = fc_els_request ( &monojob, port, peer_port_id,
00113                                      handler ) ) != 0 ) {
00114                 printf ( "%s\n", strerror ( rc ) );
00115                 return rc;
00116         }
00117 
00118         /* Wait for ELS to complete */
00119         return monojob_wait ( "", 0 );
00120 }