2 * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
20 FILE_LICENCE ( GPL2_OR_LATER );
25 #include <ipxe/uaccess.h>
26 #include <ipxe/init.h>
28 #include <ipxe/ethernet.h>
29 #include <ipxe/bofm.h>
33 * IBM BladeCenter Open Fabric Manager (BOFM) tests
37 /** Harvest test table */
39 struct bofm_global_header header;
40 struct bofm_section_header en_header;
42 struct bofm_section_header done;
43 } __attribute__ (( packed )) bofmtab_harvest = {
45 .magic = BOFM_IOAA_MAGIC,
46 .action = BOFM_ACTION_HVST,
49 .length = sizeof ( bofmtab_harvest ),
50 .profile = "Harvest test profile",
53 .magic = BOFM_EN_MAGIC,
54 .length = sizeof ( bofmtab_harvest.en ),
57 .options = ( BOFM_EN_MAP_PFA | BOFM_EN_USAGE_HARVEST |
58 BOFM_EN_RQ_HVST_ACTIVE ),
62 .magic = BOFM_DONE_MAGIC,
66 /** Update test table */
68 struct bofm_global_header header;
69 struct bofm_section_header en_header;
71 struct bofm_section_header done;
72 } __attribute__ (( packed )) bofmtab_update = {
74 .magic = BOFM_IOAA_MAGIC,
75 .action = BOFM_ACTION_UPDT,
78 .length = sizeof ( bofmtab_update ),
79 .profile = "Update test profile",
82 .magic = BOFM_EN_MAGIC,
83 .length = sizeof ( bofmtab_update.en ),
86 .options = ( BOFM_EN_MAP_PFA | BOFM_EN_EN_A |
87 BOFM_EN_USAGE_ENTRY ),
89 .mac_a = { 0x02, 0x00, 0x69, 0x50, 0x58, 0x45 },
92 .magic = BOFM_DONE_MAGIC,
101 void bofm_test ( struct pci_device *pci ) {
104 printf ( "BOFMTEST using " PCI_FMT "\n", PCI_ARGS ( pci ) );
106 /* Perform harvest test */
107 printf ( "BOFMTEST performing harvest\n" );
108 bofmtab_harvest.en.busdevfn = pci->busdevfn;
109 DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
110 bofmrc = bofm ( virt_to_user ( &bofmtab_harvest ), pci );
111 printf ( "BOFMTEST harvest result %08x\n", bofmrc );
112 if ( bofmtab_harvest.en.options & BOFM_EN_HVST ) {
113 printf ( "BOFMTEST harvested MAC address %s\n",
114 eth_ntoa ( &bofmtab_harvest.en.mac_a ) );
116 printf ( "BOFMTEST failed to harvest a MAC address\n" );
118 DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
120 /* Perform update test */
121 printf ( "BOFMTEST performing update\n" );
122 bofmtab_update.en.busdevfn = pci->busdevfn;
123 DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
124 bofmrc = bofm ( virt_to_user ( &bofmtab_update ), pci );
125 printf ( "BOFMTEST update result %08x\n", bofmrc );
126 if ( bofmtab_update.en.options & BOFM_EN_CSM_SUCCESS ) {
127 printf ( "BOFMTEST updated MAC address to %s\n",
128 eth_ntoa ( &bofmtab_update.en.mac_a ) );
130 printf ( "BOFMTEST failed to update MAC address\n" );
132 DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
136 * Perform BOFM test at initialisation time
139 static void bofm_test_init ( void ) {
140 struct pci_device pci;
144 /* Uncomment the following line and specify the correct PCI
145 * bus:dev.fn address in order to perform a BOFM test at
146 * initialisation time.
148 // busdevfn = PCI_BUSDEVFN ( <bus>, <dev>, <fn> );
150 /* Skip test if no PCI bus:dev.fn is defined */
154 /* Initialise PCI device */
155 memset ( &pci, 0, sizeof ( pci ) );
156 pci_init ( &pci, busdevfn );
157 if ( ( rc = pci_read_config ( &pci ) ) != 0 ) {
158 printf ( "BOFMTEST could not create " PCI_FMT " device: %s\n",
159 PCI_ARGS ( &pci ), strerror ( rc ) );
167 /** BOFM test initialisation function */
168 struct init_fn bofm_test_init_fn __init_fn ( INIT_NORMAL ) = {
169 .initialise = bofm_test_init,