1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
* Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* You can also choose to distribute this program under the terms of
* the Unmodified Binary Distribution Licence (as given in the file
* COPYING.UBDL), provided that you have satisfied its requirements.
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <strings.h>
#include <ipxe/fc.h>
#include <ipxe/fcels.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/tables.h>
#include <usr/fcmgmt.h>
/** @file
*
* Fibre Channel management commands
*
*/
/**
* Parse Fibre Channel port name
*
* @v text Text
* @ret port Fibre Channel port
* @ret rc Return status code
*/
static int parse_fc_port ( char *text, struct fc_port **port ) {
/* Sanity check */
assert ( text != NULL );
/* Find Fibre Channel port */
*port = fc_port_find ( text );
if ( ! *port ) {
printf ( "\"%s\": no such port\n", text );
return -ENODEV;
}
return 0;
}
/**
* Parse Fibre Channel port ID
*
* @v text Text
* @ret port_id Fibre Channel port ID
* @ret rc Return status code
*/
static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
int rc;
/* Sanity check */
assert ( text != NULL );
/* Parse port ID */
if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
printf ( "\"%s\": invalid port ID\n", text );
return -EINVAL;
}
return 0;
}
/**
* Parse Fibre Channel ELS handler name
*
* @v text Text
* @ret handler Fibre Channel ELS handler
* @ret rc Return status code
*/
static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
if ( strcasecmp ( (*handler)->name, text ) == 0 )
return 0;
}
printf ( "\"%s\": unrecognised ELS\n", text );
return -ENOENT;
}
/** "fcstat" options */
struct fcstat_options {};
/** "fcstat" option list */
static struct option_descriptor fcstat_opts[] = {};
/** "fcstat" command descriptor */
static struct command_descriptor fcstat_cmd =
COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
/**
* The "fcstat" command
*
* @v argc Argument count
* @v argv Argument list
* @ret rc Return status code
*/
static int fcstat_exec ( int argc, char **argv ) {
struct fcstat_options opts;
struct fc_port *port;
struct fc_peer *peer;
int rc;
/* Parse options */
if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
return rc;
list_for_each_entry ( port, &fc_ports, list )
fcportstat ( port );
list_for_each_entry ( peer, &fc_peers, list )
fcpeerstat ( peer );
return 0;
}
/** "fcels" options */
struct fcels_options {
/** Fibre Channel port */
struct fc_port *port;
/** Fibre Channel peer port ID */
struct fc_port_id peer_port_id;
};
/** "fcels" option list */
static struct option_descriptor fcels_opts[] = {
OPTION_DESC ( "port", 'p', required_argument,
struct fcels_options, port, parse_fc_port ),
OPTION_DESC ( "id", 'i', required_argument,
struct fcels_options, peer_port_id, parse_fc_port_id ),
};
/** "fcels" command descriptor */
static struct command_descriptor fcels_cmd =
COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
/**
* The "fcels" command
*
* @v argc Argument count
* @v argv Argument list
* @ret rc Return status code
*/
static int fcels_exec ( int argc, char **argv ) {
struct fcels_options opts;
struct fc_els_handler *handler;
struct fc_port_id *id;
int rc;
/* Parse options */
if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
return rc;
/* Parse ELS handler */
if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
return rc;
/* Use first port if no port specified */
if ( ! opts.port ) {
opts.port = list_first_entry ( &fc_ports, struct fc_port,
list );
if ( ! opts.port ) {
printf ( "No ports\n" );
return -ENODEV;
}
}
/* Use link peer port ID if no peer port ID specified */
id = &opts.peer_port_id;
if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
if ( fc_link_ok ( &opts.port->link ) &&
! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
id = &opts.port->ptp_link_port_id;
} else {
id = &fc_f_port_id;
}
}
/** Issue ELS */
if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
return rc;
return 0;
}
/** Fibre Channel management commands */
struct command fcmgmt_commands[] __command = {
{
.name = "fcstat",
.exec = fcstat_exec,
},
{
.name = "fcels",
.exec = fcels_exec,
},
};
|