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.7KB

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