iPXE
bofm_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 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 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <ipxe/uaccess.h>
30 #include <ipxe/init.h>
31 #include <ipxe/pci.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/bofm.h>
34 
35 /** @file
36  *
37  * IBM BladeCenter Open Fabric Manager (BOFM) tests
38  *
39  */
40 
41 /** Harvest test table */
42 static struct {
45  struct bofm_en en;
47 } __attribute__ (( packed )) bofmtab_harvest = {
48  .header = {
49  .magic = BOFM_IOAA_MAGIC,
50  .action = BOFM_ACTION_HVST,
51  .version = 0x01,
52  .level = 0x01,
53  .length = sizeof ( bofmtab_harvest ),
54  .profile = "Harvest test profile",
55  },
56  .en_header = {
57  .magic = BOFM_EN_MAGIC,
58  .length = sizeof ( bofmtab_harvest.en ),
59  },
60  .en = {
61  .options = ( BOFM_EN_MAP_PFA | BOFM_EN_USAGE_HARVEST |
63  .mport = 1,
64  },
65  .done = {
66  .magic = BOFM_DONE_MAGIC,
67  },
68 };
69 
70 /** Update test table */
71 static struct {
74  struct bofm_en en;
76 } __attribute__ (( packed )) bofmtab_update = {
77  .header = {
78  .magic = BOFM_IOAA_MAGIC,
79  .action = BOFM_ACTION_UPDT,
80  .version = 0x01,
81  .level = 0x01,
82  .length = sizeof ( bofmtab_update ),
83  .profile = "Update test profile",
84  },
85  .en_header = {
86  .magic = BOFM_EN_MAGIC,
87  .length = sizeof ( bofmtab_update.en ),
88  },
89  .en = {
90  .options = ( BOFM_EN_MAP_PFA | BOFM_EN_EN_A |
92  .mport = 1,
93  .mac_a = { 0x02, 0x00, 0x69, 0x50, 0x58, 0x45 },
94  },
95  .done = {
96  .magic = BOFM_DONE_MAGIC,
97  },
98 };
99 
100 /**
101  * Perform BOFM test
102  *
103  * @v pci PCI device
104  */
105 void bofm_test ( struct pci_device *pci ) {
106  int bofmrc;
107 
108  printf ( "BOFMTEST using " PCI_FMT "\n", PCI_ARGS ( pci ) );
109 
110  /* Perform harvest test */
111  printf ( "BOFMTEST performing harvest\n" );
112  bofmtab_harvest.en.busdevfn = pci->busdevfn;
113  DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
114  bofmrc = bofm ( virt_to_user ( &bofmtab_harvest ), pci );
115  printf ( "BOFMTEST harvest result %08x\n", bofmrc );
116  if ( bofmtab_harvest.en.options & BOFM_EN_HVST ) {
117  printf ( "BOFMTEST harvested MAC address %s\n",
118  eth_ntoa ( &bofmtab_harvest.en.mac_a ) );
119  } else {
120  printf ( "BOFMTEST failed to harvest a MAC address\n" );
121  }
122  DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
123 
124  /* Perform update test */
125  printf ( "BOFMTEST performing update\n" );
126  bofmtab_update.en.busdevfn = pci->busdevfn;
127  DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
128  bofmrc = bofm ( virt_to_user ( &bofmtab_update ), pci );
129  printf ( "BOFMTEST update result %08x\n", bofmrc );
130  if ( bofmtab_update.en.options & BOFM_EN_CSM_SUCCESS ) {
131  printf ( "BOFMTEST updated MAC address to %s\n",
132  eth_ntoa ( &bofmtab_update.en.mac_a ) );
133  } else {
134  printf ( "BOFMTEST failed to update MAC address\n" );
135  }
136  DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
137 }
138 
139 /**
140  * Perform BOFM test at initialisation time
141  *
142  */
143 static void bofm_test_init ( void ) {
144  struct pci_device pci;
145  int busdevfn = -1;
146  int rc;
147 
148  /* Uncomment the following line and specify the correct PCI
149  * bus:dev.fn address in order to perform a BOFM test at
150  * initialisation time.
151  */
152  // busdevfn = PCI_BUSDEVFN ( <bus>, <dev>, <fn> );
153 
154  /* Skip test if no PCI bus:dev.fn is defined */
155  if ( busdevfn < 0 )
156  return;
157 
158  /* Initialise PCI device */
159  memset ( &pci, 0, sizeof ( pci ) );
160  pci_init ( &pci, busdevfn );
161  if ( ( rc = pci_read_config ( &pci ) ) != 0 ) {
162  printf ( "BOFMTEST could not create " PCI_FMT " device: %s\n",
163  PCI_ARGS ( &pci ), strerror ( rc ) );
164  return;
165  }
166 
167  /* Perform test */
168  bofm_test ( &pci );
169 }
170 
171 /** BOFM test initialisation function */
172 struct init_fn bofm_test_init_fn __init_fn ( INIT_NORMAL ) = {
174 };
#define __attribute__(x)
Definition: compiler.h:10
struct bofm_en en
Definition: bofm_test.c:45
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
#define DBG_HDA(...)
Definition: compiler.h:499
void(* initialise)(void)
Definition: init.h:15
static struct @421 bofmtab_update
Update test table.
void bofm_test(struct pci_device *pci)
Perform BOFM test.
Definition: bofm_test.c:105
#define BOFM_EN_EN_A
MAC address A is present.
Definition: bofm.h:225
#define BOFM_EN_USAGE_HARVEST
Ignore values - it's harvest time.
Definition: bofm.h:252
#define BOFM_EN_MAGIC
EN start marker.
Definition: bofm.h:151
static void bofm_test_init(void)
Perform BOFM test at initialisation time.
Definition: bofm_test.c:143
static struct @420 bofmtab_harvest
Harvest test table.
Access to external ("user") memory.
#define BOFM_ACTION_UPDT
Update MAC/WWN.
Definition: bofm.h:114
#define INIT_NORMAL
Normal initialisation.
Definition: init.h:30
IBM BladeCenter Open Fabric Manager (BOFM)
An initialisation function.
Definition: init.h:14
__be16 profile
Definition: CIB_PRM.h:30
Ethernet protocol.
#define BOFM_EN_MAP_PFA
Port mapping is by PCI bus:dev.fn.
Definition: bofm.h:213
#define BOFM_IOAA_MAGIC
BOFM table header signature.
Definition: bofm.h:103
#define BOFM_DONE_MAGIC
End marker.
Definition: bofm.h:154
BOFM table header.
Definition: bofm.h:77
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
PCI bus.
A PCI device.
Definition: pci.h:187
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
#define BOFM_EN_HVST
Harvest complete.
Definition: bofm.h:261
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:177
struct bofm_global_header header
Definition: bofm_test.c:43
BOFM section header.
Definition: bofm.h:135
#define BOFM_EN_USAGE_ENTRY
Use entry values for assignment.
Definition: bofm.h:255
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct init_fn bofm_test_init_fn __init_fn(INIT_NORMAL)
BOFM test initialisation function.
int bofm(userptr_t bofmtab, struct pci_device *pci)
Process BOFM table.
Definition: bofm.c:238
BOFM Ethernet parameter entry.
Definition: bofm.h:163
struct bofm_section_header en_header
Definition: bofm_test.c:44
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
#define BOFM_EN_RQ_HVST_ACTIVE
Harvest active values.
Definition: bofm.h:273
#define BOFM_EN_CSM_SUCCESS
Entry has been used successfully.
Definition: bofm.h:237
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:313
#define BOFM_ACTION_HVST
Harvest MAC/WWN.
Definition: bofm.h:120
String functions.
struct bofm_section_header done
Definition: bofm_test.c:46
void * memset(void *dest, int character, size_t len) __nonnull