Annotation of qemu/roms/ipxe/src/tests/bofm_test.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (C) 2011 Michael Brown <[email protected]>.
                      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., 675 Mass Ave, Cambridge, MA 02139, USA.
                     17:  */
                     18: 
                     19: FILE_LICENCE ( GPL2_OR_LATER );
                     20: 
                     21: #include <stdint.h>
                     22: #include <stdio.h>
                     23: #include <string.h>
                     24: #include <ipxe/uaccess.h>
                     25: #include <ipxe/init.h>
                     26: #include <ipxe/pci.h>
                     27: #include <ipxe/ethernet.h>
                     28: #include <ipxe/bofm.h>
                     29: 
                     30: /** @file
                     31:  *
                     32:  * IBM BladeCenter Open Fabric Manager (BOFM) tests
                     33:  *
                     34:  */
                     35: 
                     36: /** Harvest test table */
                     37: static struct {
                     38:        struct bofm_global_header header;
                     39:        struct bofm_section_header en_header;
                     40:        struct bofm_en en;
                     41:        struct bofm_section_header done;
                     42: } __attribute__ (( packed )) bofmtab_harvest = {
                     43:        .header = {
                     44:                .magic = BOFM_IOAA_MAGIC,
                     45:                .action = BOFM_ACTION_HVST,
                     46:                .version = 0x01,
                     47:                .level = 0x01,
                     48:                .length = sizeof ( bofmtab_harvest ),
                     49:                .profile = "Harvest test profile",
                     50:        },
                     51:        .en_header = {
                     52:                .magic = BOFM_EN_MAGIC,
                     53:                .length = sizeof ( bofmtab_harvest.en ),
                     54:        },
                     55:        .en = {
                     56:                .options = ( BOFM_EN_MAP_PFA | BOFM_EN_USAGE_HARVEST |
                     57:                             BOFM_EN_RQ_HVST_ACTIVE ),
                     58:                .mport = 1,
                     59:        },
                     60:        .done = {
                     61:                .magic = BOFM_DONE_MAGIC,
                     62:        },
                     63: };
                     64: 
                     65: /** Update test table */
                     66: static struct {
                     67:        struct bofm_global_header header;
                     68:        struct bofm_section_header en_header;
                     69:        struct bofm_en en;
                     70:        struct bofm_section_header done;
                     71: } __attribute__ (( packed )) bofmtab_update = {
                     72:        .header = {
                     73:                .magic = BOFM_IOAA_MAGIC,
                     74:                .action = BOFM_ACTION_UPDT,
                     75:                .version = 0x01,
                     76:                .level = 0x01,
                     77:                .length = sizeof ( bofmtab_update ),
                     78:                .profile = "Update test profile",
                     79:        },
                     80:        .en_header = {
                     81:                .magic = BOFM_EN_MAGIC,
                     82:                .length = sizeof ( bofmtab_update.en ),
                     83:        },
                     84:        .en = {
                     85:                .options = ( BOFM_EN_MAP_PFA | BOFM_EN_EN_A |
                     86:                             BOFM_EN_USAGE_ENTRY ),
                     87:                .mport = 1,
                     88:                .mac_a = { 0x02, 0x00, 0x69, 0x50, 0x58, 0x45 },
                     89:        },
                     90:        .done = {
                     91:                .magic = BOFM_DONE_MAGIC,
                     92:        },
                     93: };
                     94: 
                     95: /**
                     96:  * Perform BOFM test
                     97:  *
                     98:  * @v pci              PCI device
                     99:  */
                    100: void bofm_test ( struct pci_device *pci ) {
                    101:        int bofmrc;
                    102: 
                    103:        printf ( "BOFMTEST using " PCI_FMT "\n", PCI_ARGS ( pci ) );
                    104: 
                    105:        /* Perform harvest test */
                    106:        printf ( "BOFMTEST performing harvest\n" );
                    107:        bofmtab_harvest.en.busdevfn = pci->busdevfn;
                    108:        DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
                    109:        bofmrc = bofm ( virt_to_user ( &bofmtab_harvest ), pci );
                    110:        printf ( "BOFMTEST harvest result %08x\n", bofmrc );
                    111:        if ( bofmtab_harvest.en.options & BOFM_EN_HVST ) {
                    112:                printf ( "BOFMTEST harvested MAC address %s\n",
                    113:                         eth_ntoa ( &bofmtab_harvest.en.mac_a ) );
                    114:        } else {
                    115:                printf ( "BOFMTEST failed to harvest a MAC address\n" );
                    116:        }
                    117:        DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) );
                    118: 
                    119:        /* Perform update test */
                    120:        printf ( "BOFMTEST performing update\n" );
                    121:        bofmtab_update.en.busdevfn = pci->busdevfn;
                    122:        DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
                    123:        bofmrc = bofm ( virt_to_user ( &bofmtab_update ), pci );
                    124:        printf ( "BOFMTEST update result %08x\n", bofmrc );
                    125:        if ( bofmtab_update.en.options & BOFM_EN_CSM_SUCCESS ) {
                    126:                printf ( "BOFMTEST updated MAC address to %s\n",
                    127:                         eth_ntoa ( &bofmtab_update.en.mac_a ) );
                    128:        } else {
                    129:                printf ( "BOFMTEST failed to update MAC address\n" );
                    130:        }
                    131:        DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) );
                    132: }
                    133: 
                    134: /**
                    135:  * Perform BOFM test at initialisation time
                    136:  *
                    137:  */
                    138: static void bofm_test_init ( void ) {
                    139:        struct pci_device pci;
                    140:        int busdevfn = -1;
                    141:        int rc;
                    142: 
                    143:        /* Uncomment the following line and specify the correct PCI
                    144:         * bus:dev.fn address in order to perform a BOFM test at
                    145:         * initialisation time.
                    146:         */
                    147:        // busdevfn = PCI_BUSDEVFN ( <bus>, <dev>, <fn> );
                    148: 
                    149:        /* Skip test if no PCI bus:dev.fn is defined */
                    150:        if ( busdevfn < 0 )
                    151:                return;
                    152: 
                    153:        /* Initialise PCI device */
                    154:        memset ( &pci, 0, sizeof ( pci ) );
                    155:        pci_init ( &pci, busdevfn );
                    156:        if ( ( rc = pci_read_config ( &pci ) ) != 0 ) {
                    157:                printf ( "BOFMTEST could not create " PCI_FMT " device: %s\n",
                    158:                         PCI_ARGS ( &pci ), strerror ( rc ) );
                    159:                return;
                    160:        }
                    161: 
                    162:        /* Perform test */
                    163:        bofm_test ( &pci );
                    164: }
                    165: 
                    166: /** BOFM test initialisation function */
                    167: struct init_fn bofm_test_init_fn __init_fn ( INIT_NORMAL ) = {
                    168:        .initialise = bofm_test_init,
                    169: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.