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
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.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
29 #include <ipxe/uaccess.h>
30 #include <ipxe/init.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/bofm.h>
37 * IBM BladeCenter Open Fabric Manager (BOFM) tests
41 /** Harvest test table */
43 struct bofm_global_header header;
44 struct bofm_section_header en_header;
46 struct bofm_section_header done;
47 } __attribute__ (( packed )) bofmtab_harvest = {
49 .magic = BOFM_IOAA_MAGIC,
50 .action = BOFM_ACTION_HVST,
53 .length = sizeof ( bofmtab_harvest ),
54 .profile = "Harvest test profile",
57 .magic = BOFM_EN_MAGIC,
58 .length = sizeof ( bofmtab_harvest.en ),
61 .options = ( BOFM_EN_MAP_PFA | BOFM_EN_USAGE_HARVEST |
62 BOFM_EN_RQ_HVST_ACTIVE ),
66 .magic = BOFM_DONE_MAGIC,
70 /** Update test table */
72 struct bofm_global_header header;
73 struct bofm_section_header en_header;
75 struct bofm_section_header done;
76 } __attribute__ (( packed )) bofmtab_update = {
78 .magic = BOFM_IOAA_MAGIC,
79 .action = BOFM_ACTION_UPDT,
82 .length = sizeof ( bofmtab_update ),
83 .profile = "Update test profile",
86 .magic = BOFM_EN_MAGIC,
87 .length = sizeof ( bofmtab_update.en ),
90 .options = ( BOFM_EN_MAP_PFA | BOFM_EN_EN_A |
91 BOFM_EN_USAGE_ENTRY ),
93 .mac_a = { 0x02, 0x00, 0x69, 0x50, 0x58, 0x45 },
96 .magic = BOFM_DONE_MAGIC,
105 void bofm_test ( struct pci_device *pci ) {
108 printf ( "BOFMTEST using " PCI_FMT "\n", PCI_ARGS ( pci ) );
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 ) );
120 printf ( "BOFMTEST failed to harvest a MAC address\n" );
122 DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
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 ) );
134 printf ( "BOFMTEST failed to update MAC address\n" );
136 DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
140 * Perform BOFM test at initialisation time
143 static void bofm_test_init ( void ) {
144 struct pci_device pci;
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.
152 // busdevfn = PCI_BUSDEVFN ( <bus>, <dev>, <fn> );
154 /* Skip test if no PCI bus:dev.fn is defined */
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 ) );
171 /** BOFM test initialisation function */
172 struct init_fn bofm_test_init_fn __init_fn ( INIT_NORMAL ) = {
173 .initialise = bofm_test_init,