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

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