iPXE
Data Structures | Functions | Variables
fcmgmt_cmd.c File Reference

Fibre Channel management commands. More...

#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>

Go to the source code of this file.

Data Structures

struct  fcstat_options
 "fcstat" options More...
 
struct  fcels_options
 "fcels" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int parse_fc_port (char *text, struct fc_port **port)
 Parse Fibre Channel port name. More...
 
static int parse_fc_port_id (char *text, struct fc_port_id *port_id)
 Parse Fibre Channel port ID. More...
 
static int parse_fc_els_handler (char *text, struct fc_els_handler **handler)
 Parse Fibre Channel ELS handler name. More...
 
static int fcstat_exec (int argc, char **argv)
 The "fcstat" command. More...
 
static int fcels_exec (int argc, char **argv)
 The "fcels" command. More...
 

Variables

static struct option_descriptor fcstat_opts [] = {}
 "fcstat" option list More...
 
static struct command_descriptor fcstat_cmd
 "fcstat" command descriptor More...
 
static struct option_descriptor fcels_opts []
 "fcels" option list More...
 
static struct command_descriptor fcels_cmd
 "fcels" command descriptor More...
 
struct command fcmgmt_commands [] __command
 Fibre Channel management commands. More...
 

Detailed Description

Fibre Channel management commands.

Definition in file fcmgmt_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ parse_fc_port()

static int parse_fc_port ( char *  text,
struct fc_port **  port 
)
static

Parse Fibre Channel port name.

Parameters
textText
Return values
portFibre Channel port
rcReturn status code

Definition at line 50 of file fcmgmt_cmd.c.

50  {
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 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define ENODEV
No such device.
Definition: errno.h:509
struct fc_port * fc_port_find(const char *name)
Find Fibre Channel port by name.
Definition: fc.c:1224
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), ENODEV, fc_port_find(), NULL, port, and printf().

◆ parse_fc_port_id()

static int parse_fc_port_id ( char *  text,
struct fc_port_id port_id 
)
static

Parse Fibre Channel port ID.

Parameters
textText
Return values
port_idFibre Channel port ID
rcReturn status code

Definition at line 72 of file fcmgmt_cmd.c.

72  {
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 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int fc_id_aton(const char *id_text, struct fc_port_id *id)
Parse Fibre Channel port ID.
Definition: fc.c:107

References assert(), EINVAL, fc_id_aton(), NULL, printf(), and rc.

◆ parse_fc_els_handler()

static int parse_fc_els_handler ( char *  text,
struct fc_els_handler **  handler 
)
static

Parse Fibre Channel ELS handler name.

Parameters
textText
Return values
handlerFibre Channel ELS handler
rcReturn status code

Definition at line 94 of file fcmgmt_cmd.c.

94  {
95 
96  for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
97  if ( strcasecmp ( (*handler)->name, text ) == 0 )
98  return 0;
99  }
100 
101  printf ( "\"%s\": unrecognised ELS\n", text );
102  return -ENOENT;
103 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ENOENT
No such file or directory.
Definition: errno.h:514
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
#define FC_ELS_HANDLERS
Fibre Channel ELS handler table.
Definition: fcels.h:380

References ENOENT, FC_ELS_HANDLERS, for_each_table_entry, printf(), and strcasecmp().

Referenced by fcels_exec().

◆ fcstat_exec()

static int fcstat_exec ( int  argc,
char **  argv 
)
static

The "fcstat" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 122 of file fcmgmt_cmd.c.

122  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct list_head fc_peers
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
struct list_head fc_ports
A Fibre Channel port.
Definition: fc.h:252
void fcportstat(struct fc_port *port)
Print status of Fibre Channel port.
Definition: fcmgmt.c:45
u8 port
Port number.
Definition: CIB_PRM.h:31
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
void fcpeerstat(struct fc_peer *peer)
Print status of Fibre Channel peer.
Definition: fcmgmt.c:68
static struct command_descriptor fcstat_cmd
"fcstat" command descriptor
Definition: fcmgmt_cmd.c:112
struct list_head list
List of all peers.
Definition: fc.h:344
"fcstat" options
Definition: fcmgmt_cmd.c:106
static union @437 opts
"cert<xxx>" option list
A Fibre Channel peer.
Definition: fc.h:340
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12

References fc_peers, fc_ports, fcpeerstat(), fcportstat(), fcstat_cmd, fc_peer::list, list_for_each_entry, opts, parse_options(), peer, port, and rc.

◆ fcels_exec()

static int fcels_exec ( int  argc,
char **  argv 
)
static

The "fcels" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Issue ELS

Definition at line 167 of file fcmgmt_cmd.c.

167  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
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
int optind
Current option index.
Definition: getopt.c:51
static struct command_descriptor fcels_cmd
"fcels" command descriptor
Definition: fcmgmt_cmd.c:157
A Fibre Channel extended link services handler.
Definition: fcels.h:352
static int parse_fc_els_handler(char *text, struct fc_els_handler **handler)
Parse Fibre Channel ELS handler name.
Definition: fcmgmt_cmd.c:94
struct fc_port_id fc_f_port_id
F_Port contoller port ID.
Definition: fc.c:68
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
struct list_head fc_ports
A Fibre Channel port.
Definition: fc.h:252
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
Port is attached to a fabric.
Definition: fc.h:292
A Fibre Channel port identifier.
Definition: fc.h:37
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition: fc.h:108
struct fc_port_id fc_empty_port_id
Unassigned port ID.
Definition: fc.c:65
uint8_t id
Request identifier.
Definition: ena.h:12
#define ENODEV
No such device.
Definition: errno.h:509
static union @437 opts
"cert<xxx>" option list
"fcels" options
Definition: fcmgmt_cmd.c:141
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114

References ENODEV, fc_empty_port_id, fc_f_port_id, fc_link_ok(), FC_PORT_HAS_FABRIC, fc_ports, fcels(), fcels_cmd, id, list_first_entry, memcmp(), optind, opts, parse_fc_els_handler(), parse_options(), printf(), and rc.

Variable Documentation

◆ fcstat_opts

struct option_descriptor fcstat_opts[] = {}
static

"fcstat" option list

Definition at line 109 of file fcmgmt_cmd.c.

◆ fcstat_cmd

struct command_descriptor fcstat_cmd
static
Initial value:
=
"fcstat" options
Definition: fcmgmt_cmd.c:106
static struct option_descriptor fcstat_opts[]
"fcstat" option list
Definition: fcmgmt_cmd.c:109
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

"fcstat" command descriptor

Definition at line 112 of file fcmgmt_cmd.c.

Referenced by fcstat_exec().

◆ fcels_opts

struct option_descriptor fcels_opts[]
static
Initial value:
= {
struct fcels_options, peer_port_id, parse_fc_port_id ),
}
u8 port
Port number.
Definition: CIB_PRM.h:31
static int parse_fc_port_id(char *text, struct fc_port_id *port_id)
Parse Fibre Channel port ID.
Definition: fcmgmt_cmd.c:72
"fcels" options
Definition: fcmgmt_cmd.c:141
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
static int parse_fc_port(char *text, struct fc_port **port)
Parse Fibre Channel port name.
Definition: fcmgmt_cmd.c:50

"fcels" option list

Definition at line 149 of file fcmgmt_cmd.c.

◆ fcels_cmd

struct command_descriptor fcels_cmd
static
Initial value:
=
COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" )
static struct option_descriptor fcels_opts[]
"fcels" option list
Definition: fcmgmt_cmd.c:149
"fcels" options
Definition: fcmgmt_cmd.c:141
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"fcels" command descriptor

Definition at line 157 of file fcmgmt_cmd.c.

Referenced by fcels_exec().

◆ __command

struct command fcmgmt_commands [] __command
Initial value:
= {
{
.name = "fcstat",
.exec = fcstat_exec,
},
{
.name = "fcels",
.exec = fcels_exec,
},
}
static int fcstat_exec(int argc, char **argv)
The "fcstat" command.
Definition: fcmgmt_cmd.c:122
static int fcels_exec(int argc, char **argv)
The "fcels" command.
Definition: fcmgmt_cmd.c:167

Fibre Channel management commands.

Definition at line 210 of file fcmgmt_cmd.c.