Lines Matching +full:ipmi +full:- +full:ipmb
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_ipmi.c - ACPI IPMI opregion
12 #include <linux/ipmi.h>
16 MODULE_DESCRIPTION("ACPI IPMI Opregion driver");
22 /* the IPMI timeout is 5s */
32 /* the IPMI request message list */
39 int ipmi_ifnum; /* IPMI interface number */
52 * NOTE: IPMI System Interface Selection
53 * There is no system interface specified by the IPMI operation
55 * handle set. IPMI messages passed from the ACPI codes are sent
56 * to this selected global IPMI system interface.
68 * In fact it can also be IPMB type. But we will have to
75 /* it is used to track whether the IPMI message is finished */
89 /* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */
124 kref_init(&ipmi_device->kref); in ipmi_dev_alloc()
125 INIT_LIST_HEAD(&ipmi_device->head); in ipmi_dev_alloc()
126 INIT_LIST_HEAD(&ipmi_device->tx_msg_list); in ipmi_dev_alloc()
127 spin_lock_init(&ipmi_device->tx_msg_lock); in ipmi_dev_alloc()
128 ipmi_device->handle = handle; in ipmi_dev_alloc()
129 ipmi_device->dev = get_device(dev); in ipmi_dev_alloc()
130 ipmi_device->ipmi_ifnum = iface; in ipmi_dev_alloc()
139 ipmi_device->user_interface = user; in ipmi_dev_alloc()
146 ipmi_destroy_user(ipmi_device->user_interface); in ipmi_dev_release()
147 put_device(ipmi_device->dev); in ipmi_dev_release()
153 struct acpi_ipmi_device *ipmi = in ipmi_dev_release_kref() local
156 ipmi_dev_release(ipmi); in ipmi_dev_release_kref()
161 list_del(&ipmi_device->head); in __ipmi_dev_kill()
169 ipmi_device->dead = true; in __ipmi_dev_kill()
179 kref_get(&ipmi_device->kref); in acpi_ipmi_dev_get()
188 kref_put(&ipmi_device->kref, ipmi_dev_release_kref); in acpi_ipmi_dev_put()
193 struct acpi_ipmi_device *ipmi; in ipmi_msg_alloc() local
196 ipmi = acpi_ipmi_dev_get(); in ipmi_msg_alloc()
197 if (!ipmi) in ipmi_msg_alloc()
202 acpi_ipmi_dev_put(ipmi); in ipmi_msg_alloc()
206 kref_init(&ipmi_msg->kref); in ipmi_msg_alloc()
207 init_completion(&ipmi_msg->tx_complete); in ipmi_msg_alloc()
208 INIT_LIST_HEAD(&ipmi_msg->head); in ipmi_msg_alloc()
209 ipmi_msg->device = ipmi; in ipmi_msg_alloc()
210 ipmi_msg->msg_done = ACPI_IPMI_UNKNOWN; in ipmi_msg_alloc()
217 acpi_ipmi_dev_put(tx_msg->device); in ipmi_msg_release()
231 kref_get(&tx_msg->kref); in acpi_ipmi_msg_get()
238 kref_put(&tx_msg->kref, ipmi_msg_release_kref); in acpi_ipmi_msg_put()
252 msg = &tx_msg->tx_message; in acpi_format_ipmi_request()
255 * IPMI network function and command are encoded in the address in acpi_format_ipmi_request()
256 * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3. in acpi_format_ipmi_request()
258 msg->netfn = IPMI_OP_RGN_NETFN(address); in acpi_format_ipmi_request()
259 msg->cmd = IPMI_OP_RGN_CMD(address); in acpi_format_ipmi_request()
260 msg->data = tx_msg->data; in acpi_format_ipmi_request()
263 * value is the parameter passed by the IPMI opregion space handler. in acpi_format_ipmi_request()
264 * It points to the IPMI request message buffer in acpi_format_ipmi_request()
269 if (buffer->length > ACPI_IPMI_MAX_MSG_LENGTH) { in acpi_format_ipmi_request()
270 dev_WARN_ONCE(tx_msg->device->dev, true, in acpi_format_ipmi_request()
272 buffer->length); in acpi_format_ipmi_request()
273 return -EINVAL; in acpi_format_ipmi_request()
275 msg->data_len = buffer->length; in acpi_format_ipmi_request()
276 memcpy(tx_msg->data, buffer->data, msg->data_len); in acpi_format_ipmi_request()
281 * the addr type should be changed to IPMB. Then we will have to parse in acpi_format_ipmi_request()
282 * the IPMI request message buffer to get the IPMB address. in acpi_format_ipmi_request()
285 tx_msg->addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; in acpi_format_ipmi_request()
286 tx_msg->addr.channel = IPMI_BMC_CHANNEL; in acpi_format_ipmi_request()
287 tx_msg->addr.data[0] = 0; in acpi_format_ipmi_request()
290 device = tx_msg->device; in acpi_format_ipmi_request()
292 spin_lock_irqsave(&device->tx_msg_lock, flags); in acpi_format_ipmi_request()
293 device->curr_msgid++; in acpi_format_ipmi_request()
294 tx_msg->tx_msgid = device->curr_msgid; in acpi_format_ipmi_request()
295 spin_unlock_irqrestore(&device->tx_msg_lock, flags); in acpi_format_ipmi_request()
307 * IPMI message returned by IPMI command. in acpi_format_ipmi_response()
312 * If the flag of msg_done is not set, it means that the IPMI command is in acpi_format_ipmi_response()
315 buffer->status = msg->msg_done; in acpi_format_ipmi_response()
316 if (msg->msg_done != ACPI_IPMI_OK) in acpi_format_ipmi_response()
320 * If the IPMI response message is obtained correctly, the status code in acpi_format_ipmi_response()
323 buffer->length = msg->rx_len; in acpi_format_ipmi_response()
324 memcpy(buffer->data, msg->data, msg->rx_len); in acpi_format_ipmi_response()
327 static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi) in ipmi_flush_tx_msg() argument
333 * NOTE: On-going ipmi_recv_msg in ipmi_flush_tx_msg()
340 spin_lock_irqsave(&ipmi->tx_msg_lock, flags); in ipmi_flush_tx_msg()
341 while (!list_empty(&ipmi->tx_msg_list)) { in ipmi_flush_tx_msg()
342 tx_msg = list_first_entry(&ipmi->tx_msg_list, in ipmi_flush_tx_msg()
345 list_del(&tx_msg->head); in ipmi_flush_tx_msg()
346 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags); in ipmi_flush_tx_msg()
349 complete(&tx_msg->tx_complete); in ipmi_flush_tx_msg()
351 spin_lock_irqsave(&ipmi->tx_msg_lock, flags); in ipmi_flush_tx_msg()
353 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags); in ipmi_flush_tx_msg()
356 static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi, in ipmi_cancel_tx_msg() argument
362 spin_lock_irqsave(&ipmi->tx_msg_lock, flags); in ipmi_cancel_tx_msg()
363 list_for_each_entry_safe(iter, temp, &ipmi->tx_msg_list, head) { in ipmi_cancel_tx_msg()
366 list_del(&iter->head); in ipmi_cancel_tx_msg()
370 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags); in ipmi_cancel_tx_msg()
380 struct device *dev = ipmi_device->dev; in ipmi_msg_handler()
383 if (msg->user != ipmi_device->user_interface) { in ipmi_msg_handler()
386 msg->user, ipmi_device->user_interface); in ipmi_msg_handler()
390 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags); in ipmi_msg_handler()
391 list_for_each_entry_safe(iter, temp, &ipmi_device->tx_msg_list, head) { in ipmi_msg_handler()
392 if (msg->msgid == iter->tx_msgid) { in ipmi_msg_handler()
394 list_del(&iter->head); in ipmi_msg_handler()
398 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags); in ipmi_msg_handler()
403 msg->msgid); in ipmi_msg_handler()
408 if (msg->msg.data_len > ACPI_IPMI_MAX_MSG_LENGTH) { in ipmi_msg_handler()
411 msg->msg.data_len); in ipmi_msg_handler()
416 msg->recv_type = IPMI_RESPONSE_RECV_TYPE; in ipmi_msg_handler()
417 if (msg->recv_type == IPMI_RESPONSE_RECV_TYPE && in ipmi_msg_handler()
418 msg->msg.data_len == 1) { in ipmi_msg_handler()
419 if (msg->msg.data[0] == IPMI_TIMEOUT_COMPLETION_CODE) { in ipmi_msg_handler()
421 tx_msg->msg_done = ACPI_IPMI_TIMEOUT; in ipmi_msg_handler()
426 tx_msg->rx_len = msg->msg.data_len; in ipmi_msg_handler()
427 memcpy(tx_msg->data, msg->msg.data, tx_msg->rx_len); in ipmi_msg_handler()
428 tx_msg->msg_done = ACPI_IPMI_OK; in ipmi_msg_handler()
431 complete(&tx_msg->tx_complete); in ipmi_msg_handler()
456 dev_warn(smi_data.dev, "Can't create IPMI user interface\n"); in ipmi_register_bmc()
466 if (temp->handle == handle) in ipmi_register_bmc()
473 list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices); in ipmi_register_bmc()
493 if (iter->ipmi_ifnum != iface) { in ipmi_bmc_gone()
512 * This is the IPMI opregion space handler.
513 * @function: indicates the read/write. In fact as the IPMI message is driven
515 * @address: This contains the netfn/command of IPMI request message.
517 * @value : it is an in/out parameter. It points to the IPMI message buffer.
518 * Before the IPMI message is sent, it represents the actual request
519 * IPMI message. After the IPMI message is finished, it represents
520 * the response IPMI message returned by IPMI command.
521 * @handler_context: IPMI device context.
535 * IPMI opregion message. in acpi_ipmi_space_handler()
536 * IPMI message is firstly written to the BMC and system software in acpi_ipmi_space_handler()
538 * of IPMI opregion. in acpi_ipmi_space_handler()
546 ipmi_device = tx_msg->device; in acpi_ipmi_space_handler()
556 if (ipmi_device->dead) { in acpi_ipmi_space_handler()
561 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags); in acpi_ipmi_space_handler()
562 list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list); in acpi_ipmi_space_handler()
563 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags); in acpi_ipmi_space_handler()
566 err = ipmi_request_settime(ipmi_device->user_interface, in acpi_ipmi_space_handler()
567 &tx_msg->addr, in acpi_ipmi_space_handler()
568 tx_msg->tx_msgid, in acpi_ipmi_space_handler()
569 &tx_msg->tx_message, in acpi_ipmi_space_handler()
575 wait_for_completion(&tx_msg->tx_complete); in acpi_ipmi_space_handler()
594 return -ETIMEDOUT; in acpi_wait_for_acpi_ipmi()
615 pr_warn("Can't register IPMI opregion space handle\n"); in acpi_ipmi_init()
616 return -EINVAL; in acpi_ipmi_init()
624 pr_err("Can't register IPMI system interface watcher\n"); in acpi_ipmi_init()
642 * is not called. So explicitly uninstall the ACPI IPMI oregion in acpi_ipmi_exit()