2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
20 FILE_LICENCE ( GPL2_OR_LATER );
27 #include <ipxe/fcels.h>
28 #include <ipxe/command.h>
29 #include <ipxe/parseopt.h>
30 #include <ipxe/tables.h>
31 #include <usr/fcmgmt.h>
35 * Fibre Channel management commands
40 * Parse Fibre Channel port name
43 * @ret port Fibre Channel port
44 * @ret rc Return status code
46 static int parse_fc_port ( char *text, struct fc_port **port ) {
49 assert ( text != NULL );
51 /* Find Fibre Channel port */
52 *port = fc_port_find ( text );
54 printf ( "\"%s\": no such port\n", text );
62 * Parse Fibre Channel port ID
65 * @ret port_id Fibre Channel port ID
66 * @ret rc Return status code
68 static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
72 assert ( text != NULL );
75 if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
76 printf ( "\"%s\": invalid port ID\n", text );
84 * Parse Fibre Channel ELS handler name
87 * @ret handler Fibre Channel ELS handler
88 * @ret rc Return status code
90 static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
92 for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
93 if ( strcasecmp ( (*handler)->name, text ) == 0 )
97 printf ( "\"%s\": unrecognised ELS\n", text );
101 /** "fcstat" options */
102 struct fcstat_options {};
104 /** "fcstat" option list */
105 static struct option_descriptor fcstat_opts[] = {};
107 /** "fcstat" command descriptor */
108 static struct command_descriptor fcstat_cmd =
109 COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
112 * The "fcstat" command
114 * @v argc Argument count
115 * @v argv Argument list
116 * @ret rc Return status code
118 static int fcstat_exec ( int argc, char **argv ) {
119 struct fcstat_options opts;
120 struct fc_port *port;
121 struct fc_peer *peer;
125 if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
128 list_for_each_entry ( port, &fc_ports, list )
130 list_for_each_entry ( peer, &fc_peers, list )
136 /** "fcels" options */
137 struct fcels_options {
138 /** Fibre Channel port */
139 struct fc_port *port;
140 /** Fibre Channel peer port ID */
141 struct fc_port_id peer_port_id;
144 /** "fcels" option list */
145 static struct option_descriptor fcels_opts[] = {
146 OPTION_DESC ( "port", 'p', required_argument,
147 struct fcels_options, port, parse_fc_port ),
148 OPTION_DESC ( "id", 'i', required_argument,
149 struct fcels_options, peer_port_id, parse_fc_port_id ),
152 /** "fcels" command descriptor */
153 static struct command_descriptor fcels_cmd =
154 COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
157 * The "fcels" command
159 * @v argc Argument count
160 * @v argv Argument list
161 * @ret rc Return status code
163 static int fcels_exec ( int argc, char **argv ) {
164 struct fcels_options opts;
165 struct fc_els_handler *handler;
166 struct fc_port_id *id;
170 if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
173 /* Parse ELS handler */
174 if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
177 /* Use first port if no port specified */
179 opts.port = list_first_entry ( &fc_ports, struct fc_port,
182 printf ( "No ports\n" );
187 /* Use link peer port ID if no peer port ID specified */
188 id = &opts.peer_port_id;
189 if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
190 if ( fc_link_ok ( &opts.port->link ) &&
191 ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
192 id = &opts.port->ptp_link_port_id;
199 if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
205 /** Fibre Channel management commands */
206 struct command fcmgmt_commands[] __command = {