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