iPXE
fcmgmt.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 <string.h>
27#include <stdio.h>
28#include <errno.h>
29#include <ipxe/fc.h>
30#include <ipxe/fcels.h>
31#include <ipxe/monojob.h>
32#include <usr/fcmgmt.h>
33
34/** @file
35 *
36 * Fibre Channel management
37 *
38 */
39
40/**
41 * Print status of Fibre Channel port
42 *
43 * @v port Fibre Channel port
44 */
45void fcportstat ( struct fc_port *port ) {
46 printf ( "%s: %s id %s", port->name, fc_ntoa ( &port->port_wwn ),
47 fc_id_ntoa ( &port->port_id ) );
48 printf ( " node %s\n [Link:", fc_ntoa ( &port->node_wwn ) );
49 if ( fc_link_ok ( &port->link ) ) {
50 printf ( " up, %s", fc_ntoa ( &port->link_port_wwn ) );
51 if ( ( port->flags & FC_PORT_HAS_FABRIC ) ) {
52 printf ( " fabric" );
53 } else {
54 printf ( " id %s",
55 fc_id_ntoa ( &port->ptp_link_port_id ) );
56 }
57 printf ( " node %s]\n", fc_ntoa ( &port->link_node_wwn ) );
58 } else {
59 printf ( " down: %s]\n", strerror ( port->link.rc ) );
60 }
61}
62
63/**
64 * Print status of Fibre Channel peer
65 *
66 * @v peer Fibre Channel peer
67 */
68void fcpeerstat ( struct fc_peer *peer ) {
69 struct fc_ulp *ulp;
71 unsigned int i;
72
73 printf ( "%s:\n [Link:", fc_ntoa ( &peer->port_wwn ) );
74 if ( fc_link_ok ( &peer->link ) ) {
75 printf ( " up, port %s id %s]\n", peer->port->name,
76 fc_id_ntoa ( &peer->port_id ) );
77 } else {
78 printf ( " down: %s]\n", strerror ( peer->link.rc ) );
79 }
80
81 list_for_each_entry ( ulp, &peer->ulps, list ) {
82 printf ( " [Type %02x link:", ulp->type );
83 if ( fc_link_ok ( &ulp->link ) ) {
84 printf ( " up, params" );
85 param = ulp->param;
86 for ( i = 0 ; i < ulp->param_len ; i++ ) {
87 printf ( "%c%02x", ( ( i == 0 ) ? ' ' : ':' ),
88 param[i] );
89 }
90 } else {
91 printf ( " down: %s", strerror ( ulp->link.rc ) );
92 }
93 printf ( "]\n" );
94 }
95}
96
97/**
98 * Issue Fibre Channel ELS
99 *
100 * @v port Fibre Channel port
101 * @v peer_port_id Peer port ID
102 * @v handler ELS handler
103 * @ret rc Return status code
104 */
105int fcels ( struct fc_port *port, struct fc_port_id *peer_port_id,
106 struct fc_els_handler *handler ) {
107 int rc;
108
109 /* Initiate ELS */
110 printf ( "%s %s to %s...",
111 port->name, handler->name, fc_id_ntoa ( peer_port_id ) );
112 if ( ( rc = fc_els_request ( &monojob, port, peer_port_id,
113 handler ) ) != 0 ) {
114 printf ( "%s\n", strerror ( rc ) );
115 return rc;
116 }
117
118 /* Wait for ELS to complete */
119 return monojob_wait ( "", 0 );
120}
u8 port
Port number.
Definition CIB_PRM.h:3
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned char uint8_t
Definition stdint.h:10
Error codes.
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition fc.c:127
const char * fc_id_ntoa(const struct fc_port_id *id)
Format Fibre Channel port ID.
Definition fc.c:92
Fibre Channel.
@ FC_PORT_HAS_FABRIC
Port is attached to a fabric.
Definition fc.h:293
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition fc.h:109
int fc_els_request(struct interface *job, struct fc_port *port, struct fc_port_id *peer_port_id, struct fc_els_handler *handler)
Create ELS request.
Definition fcels.c:323
Fibre Channel Extended Link Services.
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.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
struct hv_monitor_parameter param[4][32]
Parameters.
Definition hyperv.h:13
String functions.
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
struct interface monojob
Definition monojob.c:57
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition monojob.c:82
Single foreground job.
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A Fibre Channel extended link services handler.
Definition fcels.h:353
const char * name
Name.
Definition fcels.h:355
A Fibre Channel peer.
Definition fc.h:341
A Fibre Channel port identifier.
Definition fc.h:38
A Fibre Channel port.
Definition fc.h:253
A Fibre Channel upper-layer protocol.
Definition fc.h:414
unsigned int type
Type.
Definition fc.h:423
size_t param_len
Service parameter length.
Definition fc.h:434
struct fc_link_state link
Link state monitor.
Definition fc.h:428
struct list_head list
List of upper-layer protocols.
Definition fc.h:420
void * param
Service parameters, if any.
Definition fc.h:432
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465