iPXE
fcmgmt_cmd.c
Go to the documentation of this file.
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 * 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.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdio.h>
27#include <errno.h>
28#include <getopt.h>
29#include <strings.h>
30#include <ipxe/fc.h>
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>
36
37/** @file
38 *
39 * Fibre Channel management commands
40 *
41 */
42
43/**
44 * Parse Fibre Channel port name
45 *
46 * @v text Text
47 * @ret port Fibre Channel port
48 * @ret rc Return status code
49 */
50static int parse_fc_port ( char *text, struct fc_port **port ) {
51
52 /* Sanity check */
53 assert ( text != NULL );
54
55 /* Find Fibre Channel port */
56 *port = fc_port_find ( text );
57 if ( ! *port ) {
58 printf ( "\"%s\": no such port\n", text );
59 return -ENODEV;
60 }
61
62 return 0;
63}
64
65/**
66 * Parse Fibre Channel port ID
67 *
68 * @v text Text
69 * @ret port_id Fibre Channel port ID
70 * @ret rc Return status code
71 */
72static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
73 int rc;
74
75 /* Sanity check */
76 assert ( text != NULL );
77
78 /* Parse port ID */
79 if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
80 printf ( "\"%s\": invalid port ID\n", text );
81 return -EINVAL;
82 }
83
84 return 0;
85}
86
87/**
88 * Parse Fibre Channel ELS handler name
89 *
90 * @v text Text
91 * @ret handler Fibre Channel ELS handler
92 * @ret rc Return status code
93 */
94static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
95
97 if ( strcasecmp ( (*handler)->name, text ) == 0 )
98 return 0;
99 }
100
101 printf ( "\"%s\": unrecognised ELS\n", text );
102 return -ENOENT;
103}
104
105/** "fcstat" options */
107
108/** "fcstat" option list */
109static struct option_descriptor fcstat_opts[] = {};
110
111/** "fcstat" command descriptor */
113 COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
114
115/**
116 * The "fcstat" command
117 *
118 * @v argc Argument count
119 * @v argv Argument list
120 * @ret rc Return status code
121 */
122static int fcstat_exec ( int argc, char **argv ) {
123 struct fcstat_options opts;
124 struct fc_port *port;
125 struct fc_peer *peer;
126 int rc;
127
128 /* Parse options */
129 if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
130 return rc;
131
133 fcportstat ( port );
135 fcpeerstat ( peer );
136
137 return 0;
138}
139
140/** "fcels" options */
142 /** Fibre Channel port */
143 struct fc_port *port;
144 /** Fibre Channel peer port ID */
146};
147
148/** "fcels" option list */
149static struct option_descriptor fcels_opts[] = {
150 OPTION_DESC ( "port", 'p', required_argument,
152 OPTION_DESC ( "id", 'i', required_argument,
153 struct fcels_options, peer_port_id, parse_fc_port_id ),
154};
155
156/** "fcels" command descriptor */
158 COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
159
160/**
161 * The "fcels" command
162 *
163 * @v argc Argument count
164 * @v argv Argument list
165 * @ret rc Return status code
166 */
167static int fcels_exec ( int argc, char **argv ) {
168 struct fcels_options opts;
169 struct fc_els_handler *handler;
170 struct fc_port_id *id;
171 int rc;
172
173 /* Parse options */
174 if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
175 return rc;
176
177 /* Parse ELS handler */
178 if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
179 return rc;
180
181 /* Use first port if no port specified */
182 if ( ! opts.port ) {
183 opts.port = list_first_entry ( &fc_ports, struct fc_port,
184 list );
185 if ( ! opts.port ) {
186 printf ( "No ports\n" );
187 return -ENODEV;
188 }
189 }
190
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;
197 } else {
198 id = &fc_f_port_id;
199 }
200 }
201
202 /** Issue ELS */
203 if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
204 return rc;
205
206 return 0;
207}
208
209/** Fibre Channel management commands */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
uint8_t id
Request identifier.
Definition ena.h:1
Error codes.
struct fc_port_id fc_f_port_id
F_Port contoller port ID.
Definition fc.c:68
struct fc_port_id fc_empty_port_id
Unassigned port ID.
Definition fc.c:65
struct fc_port * fc_port_find(const char *name)
Find Fibre Channel port by name.
Definition fc.c:1224
int fc_id_aton(const char *id_text, struct fc_port_id *id)
Parse Fibre Channel port ID.
Definition fc.c:107
Fibre Channel.
@ FC_PORT_HAS_FABRIC
Port is attached to a fabric.
Definition fc.h:293
struct list_head fc_peers
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition fc.h:109
struct list_head fc_ports
Fibre Channel Extended Link Services.
#define FC_ELS_HANDLERS
Fibre Channel ELS handler table.
Definition fcels.h:381
void fcportstat(struct fc_port *port)
Print status of Fibre Channel port.
Definition fcmgmt.c:45
int fcels(struct fc_port *port, struct fc_port_id *peer_port_id, struct fc_els_handler *handler)
Issue Fibre Channel ELS.
Definition fcmgmt.c:105
void fcpeerstat(struct fc_peer *peer)
Print status of Fibre Channel peer.
Definition fcmgmt.c:68
Fibre Channel management.
static int fcstat_exec(int argc, char **argv)
The "fcstat" command.
Definition fcmgmt_cmd.c:122
static int parse_fc_port(char *text, struct fc_port **port)
Parse Fibre Channel port name.
Definition fcmgmt_cmd.c:50
static struct option_descriptor fcels_opts[]
"fcels" option list
Definition fcmgmt_cmd.c:149
static struct command_descriptor fcels_cmd
"fcels" command descriptor
Definition fcmgmt_cmd.c:157
static struct command_descriptor fcstat_cmd
"fcstat" command descriptor
Definition fcmgmt_cmd.c:112
static struct option_descriptor fcstat_opts[]
"fcstat" option list
Definition fcmgmt_cmd.c:109
static int fcels_exec(int argc, char **argv)
The "fcels" command.
Definition fcmgmt_cmd.c:167
static int parse_fc_port_id(char *text, struct fc_port_id *port_id)
Parse Fibre Channel port ID.
Definition fcmgmt_cmd.c:72
static int parse_fc_els_handler(char *text, struct fc_els_handler **handler)
Parse Fibre Channel ELS handler name.
Definition fcmgmt_cmd.c:94
int optind
Current option index.
Definition getopt.c:52
Parse command-line options.
@ required_argument
Option requires an argument.
Definition getopt.h:19
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOENT
No such file or directory.
Definition errno.h:515
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENODEV
No such device.
Definition errno.h:510
String functions.
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition list.h:334
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition string.c:209
A command descriptor.
Definition parseopt.h:78
A Fibre Channel extended link services handler.
Definition fcels.h:353
A Fibre Channel peer.
Definition fc.h:341
struct list_head list
List of all peers.
Definition fc.h:345
A Fibre Channel port identifier.
Definition fc.h:38
A Fibre Channel port.
Definition fc.h:253
"fcels" options
Definition fcmgmt_cmd.c:141
struct fc_port * port
Fibre Channel port.
Definition fcmgmt_cmd.c:143
struct fc_port_id peer_port_id
Fibre Channel peer port ID.
Definition fcmgmt_cmd.c:145
"fcstat" options
Definition fcmgmt_cmd.c:106
A command-line option descriptor.
Definition parseopt.h:24
Linker tables.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465