You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bofm_test.c 4.5KB

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