ipmi_si_hardcode.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #define pr_fmt(fmt) "ipmi_hardcode: " fmt
  3. #include <linux/moduleparam.h>
  4. #include "ipmi_si.h"
  5. /*
  6. * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
  7. * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
  8. */
  9. #define SI_MAX_PARMS 4
  10. static char *si_type[SI_MAX_PARMS];
  11. #define MAX_SI_TYPE_STR 30
  12. static char si_type_str[MAX_SI_TYPE_STR];
  13. static unsigned long addrs[SI_MAX_PARMS];
  14. static unsigned int num_addrs;
  15. static unsigned int ports[SI_MAX_PARMS];
  16. static unsigned int num_ports;
  17. static int irqs[SI_MAX_PARMS];
  18. static unsigned int num_irqs;
  19. static int regspacings[SI_MAX_PARMS];
  20. static unsigned int num_regspacings;
  21. static int regsizes[SI_MAX_PARMS];
  22. static unsigned int num_regsizes;
  23. static int regshifts[SI_MAX_PARMS];
  24. static unsigned int num_regshifts;
  25. static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
  26. static unsigned int num_slave_addrs;
  27. module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
  28. MODULE_PARM_DESC(type, "Defines the type of each interface, each"
  29. " interface separated by commas. The types are 'kcs',"
  30. " 'smic', and 'bt'. For example si_type=kcs,bt will set"
  31. " the first interface to kcs and the second to bt");
  32. module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
  33. MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the"
  34. " addresses separated by commas. Only use if an interface"
  35. " is in memory. Otherwise, set it to zero or leave"
  36. " it blank.");
  37. module_param_hw_array(ports, uint, ioport, &num_ports, 0);
  38. MODULE_PARM_DESC(ports, "Sets the port address of each interface, the"
  39. " addresses separated by commas. Only use if an interface"
  40. " is a port. Otherwise, set it to zero or leave"
  41. " it blank.");
  42. module_param_hw_array(irqs, int, irq, &num_irqs, 0);
  43. MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the"
  44. " addresses separated by commas. Only use if an interface"
  45. " has an interrupt. Otherwise, set it to zero or leave"
  46. " it blank.");
  47. module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
  48. MODULE_PARM_DESC(regspacings, "The number of bytes between the start address"
  49. " and each successive register used by the interface. For"
  50. " instance, if the start address is 0xca2 and the spacing"
  51. " is 2, then the second address is at 0xca4. Defaults"
  52. " to 1.");
  53. module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
  54. MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes."
  55. " This should generally be 1, 2, 4, or 8 for an 8-bit,"
  56. " 16-bit, 32-bit, or 64-bit register. Use this if you"
  57. " the 8-bit IPMI register has to be read from a larger"
  58. " register.");
  59. module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
  60. MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the."
  61. " IPMI register, in bits. For instance, if the data"
  62. " is read from a 32-bit word and the IPMI data is in"
  63. " bit 8-15, then the shift would be 8");
  64. module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
  65. MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
  66. " the controller. Normally this is 0x20, but can be"
  67. " overridden by this parm. This is an array indexed"
  68. " by interface number.");
  69. int ipmi_si_hardcode_find_bmc(void)
  70. {
  71. int ret = -ENODEV;
  72. int i;
  73. struct si_sm_io io;
  74. char *str;
  75. /* Parse out the si_type string into its components. */
  76. str = si_type_str;
  77. if (*str != '\0') {
  78. for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
  79. si_type[i] = str;
  80. str = strchr(str, ',');
  81. if (str) {
  82. *str = '\0';
  83. str++;
  84. } else {
  85. break;
  86. }
  87. }
  88. }
  89. memset(&io, 0, sizeof(io));
  90. for (i = 0; i < SI_MAX_PARMS; i++) {
  91. if (!ports[i] && !addrs[i])
  92. continue;
  93. io.addr_source = SI_HARDCODED;
  94. pr_info("probing via hardcoded address\n");
  95. if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
  96. io.si_type = SI_KCS;
  97. } else if (strcmp(si_type[i], "smic") == 0) {
  98. io.si_type = SI_SMIC;
  99. } else if (strcmp(si_type[i], "bt") == 0) {
  100. io.si_type = SI_BT;
  101. } else {
  102. pr_warn("Interface type specified for interface %d, was invalid: %s\n",
  103. i, si_type[i]);
  104. continue;
  105. }
  106. if (ports[i]) {
  107. /* An I/O port */
  108. io.addr_data = ports[i];
  109. io.addr_type = IPMI_IO_ADDR_SPACE;
  110. } else if (addrs[i]) {
  111. /* A memory port */
  112. io.addr_data = addrs[i];
  113. io.addr_type = IPMI_MEM_ADDR_SPACE;
  114. } else {
  115. pr_warn("Interface type specified for interface %d, but port and address were not set or set to zero\n",
  116. i);
  117. continue;
  118. }
  119. io.addr = NULL;
  120. io.regspacing = regspacings[i];
  121. if (!io.regspacing)
  122. io.regspacing = DEFAULT_REGSPACING;
  123. io.regsize = regsizes[i];
  124. if (!io.regsize)
  125. io.regsize = DEFAULT_REGSIZE;
  126. io.regshift = regshifts[i];
  127. io.irq = irqs[i];
  128. if (io.irq)
  129. io.irq_setup = ipmi_std_irq_setup;
  130. io.slave_addr = slave_addrs[i];
  131. ret = ipmi_si_add_smi(&io);
  132. }
  133. return ret;
  134. }