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
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.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 #include <ipxe/fcels.h>
32 #include <ipxe/command.h>
33 #include <ipxe/parseopt.h>
34 #include <ipxe/tables.h>
35 #include <usr/fcmgmt.h>
39 * Fibre Channel management commands
44 * Parse Fibre Channel port name
47 * @ret port Fibre Channel port
48 * @ret rc Return status code
50 static int parse_fc_port ( char *text, struct fc_port **port ) {
53 assert ( text != NULL );
55 /* Find Fibre Channel port */
56 *port = fc_port_find ( text );
58 printf ( "\"%s\": no such port\n", text );
66 * Parse Fibre Channel port ID
69 * @ret port_id Fibre Channel port ID
70 * @ret rc Return status code
72 static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
76 assert ( text != NULL );
79 if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
80 printf ( "\"%s\": invalid port ID\n", text );
88 * Parse Fibre Channel ELS handler name
91 * @ret handler Fibre Channel ELS handler
92 * @ret rc Return status code
94 static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
96 for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
97 if ( strcasecmp ( (*handler)->name, text ) == 0 )
101 printf ( "\"%s\": unrecognised ELS\n", text );
105 /** "fcstat" options */
106 struct fcstat_options {};
108 /** "fcstat" option list */
109 static struct option_descriptor fcstat_opts[] = {};
111 /** "fcstat" command descriptor */
112 static struct command_descriptor fcstat_cmd =
113 COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
116 * The "fcstat" command
118 * @v argc Argument count
119 * @v argv Argument list
120 * @ret rc Return status code
122 static int fcstat_exec ( int argc, char **argv ) {
123 struct fcstat_options opts;
124 struct fc_port *port;
125 struct fc_peer *peer;
129 if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
132 list_for_each_entry ( port, &fc_ports, list )
134 list_for_each_entry ( peer, &fc_peers, list )
140 /** "fcels" options */
141 struct fcels_options {
142 /** Fibre Channel port */
143 struct fc_port *port;
144 /** Fibre Channel peer port ID */
145 struct fc_port_id peer_port_id;
148 /** "fcels" option list */
149 static struct option_descriptor fcels_opts[] = {
150 OPTION_DESC ( "port", 'p', required_argument,
151 struct fcels_options, port, parse_fc_port ),
152 OPTION_DESC ( "id", 'i', required_argument,
153 struct fcels_options, peer_port_id, parse_fc_port_id ),
156 /** "fcels" command descriptor */
157 static struct command_descriptor fcels_cmd =
158 COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
161 * The "fcels" command
163 * @v argc Argument count
164 * @v argv Argument list
165 * @ret rc Return status code
167 static int fcels_exec ( int argc, char **argv ) {
168 struct fcels_options opts;
169 struct fc_els_handler *handler;
170 struct fc_port_id *id;
174 if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
177 /* Parse ELS handler */
178 if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
181 /* Use first port if no port specified */
183 opts.port = list_first_entry ( &fc_ports, struct fc_port,
186 printf ( "No ports\n" );
191 /* Use link peer port ID if no peer port ID specified */
192 id = &opts.peer_port_id;
193 if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
194 if ( fc_link_ok ( &opts.port->link ) &&
195 ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
196 id = &opts.port->ptp_link_port_id;
203 if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
209 /** Fibre Channel management commands */
210 struct command fcmgmt_commands[] __command = {