Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * PowerNV OPAL IPMI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2014 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define pr_fmt(fmt)        "ipmi-powernv: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/ipmi_smi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/opal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct ipmi_smi_powernv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	u64			interface_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct ipmi_smi		*intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	unsigned int		irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	 * We assume that there can only be one outstanding request, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	 * keep the pending message in cur_msg. We protect this from concurrent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	 * updates through send & recv calls, (and consequently opal_msg, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 * is in-use when cur_msg is set) with msg_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	spinlock_t		msg_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct ipmi_smi_msg	*cur_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct opal_ipmi_msg	*opal_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int ipmi_powernv_start_processing(void *send_info, struct ipmi_smi *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct ipmi_smi_powernv *smi = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	smi->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static void send_error_reply(struct ipmi_smi_powernv *smi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		struct ipmi_smi_msg *msg, u8 completion_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	msg->rsp[0] = msg->data[0] | 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	msg->rsp[1] = msg->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	msg->rsp[2] = completion_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	msg->rsp_size = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ipmi_smi_msg_received(smi->intf, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static void ipmi_powernv_send(void *send_info, struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct ipmi_smi_powernv *smi = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct opal_ipmi_msg *opal_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int comp, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* ensure data_len will fit in the opal_ipmi_msg buffer... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (msg->data_size > IPMI_MAX_MSG_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		comp = IPMI_REQ_LEN_EXCEEDED_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* ... and that we at least have netfn and cmd bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (msg->data_size < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		comp = IPMI_REQ_LEN_INVALID_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	spin_lock_irqsave(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (smi->cur_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		comp = IPMI_NODE_BUSY_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* format our data for the OPAL API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	opal_msg = smi->opal_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	opal_msg->version = OPAL_IPMI_MSG_FORMAT_VERSION_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	opal_msg->netfn = msg->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	opal_msg->cmd = msg->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (msg->data_size > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		memcpy(opal_msg->data, msg->data + 2, msg->data_size - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/* data_size already includes the netfn and cmd bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	size = sizeof(*opal_msg) + msg->data_size - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	pr_devel("%s: opal_ipmi_send(0x%llx, %p, %ld)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			smi->interface_id, opal_msg, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	rc = opal_ipmi_send(smi->interface_id, opal_msg, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	pr_devel("%s:  -> %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		smi->cur_msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	comp = IPMI_ERR_UNSPECIFIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	send_error_reply(smi, msg, comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct opal_ipmi_msg *opal_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct ipmi_smi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	uint64_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	pr_devel("%s: opal_ipmi_recv(%llx, msg, sz)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			smi->interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	spin_lock_irqsave(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!smi->cur_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		pr_warn("no current message?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	msg = smi->cur_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	opal_msg = smi->opal_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	size = cpu_to_be64(sizeof(*opal_msg) + IPMI_MAX_MSG_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	rc = opal_ipmi_recv(smi->interface_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			opal_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			&size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	size = be64_to_cpu(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	pr_devel("%s:   -> %d (size %lld)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			rc, rc == 0 ? size : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		/* If came via the poll, and response was not yet ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (rc == OPAL_EMPTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		smi->cur_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (size < sizeof(*opal_msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		pr_warn("unexpected IPMI message size %lld\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (opal_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		pr_warn("unexpected IPMI message format (version %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				opal_msg->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	msg->rsp[0] = opal_msg->netfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	msg->rsp[1] = opal_msg->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (size > sizeof(*opal_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		memcpy(&msg->rsp[2], opal_msg->data, size - sizeof(*opal_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	msg->rsp_size = 2 + size - sizeof(*opal_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	smi->cur_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	spin_unlock_irqrestore(&smi->msg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ipmi_smi_msg_received(smi->intf, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void ipmi_powernv_request_events(void *send_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static void ipmi_powernv_set_run_to_completion(void *send_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		bool run_to_completion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void ipmi_powernv_poll(void *send_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct ipmi_smi_powernv *smi = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	ipmi_powernv_recv(smi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static const struct ipmi_smi_handlers ipmi_powernv_smi_handlers = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.owner			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.start_processing	= ipmi_powernv_start_processing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.sender			= ipmi_powernv_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.request_events		= ipmi_powernv_request_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.set_run_to_completion	= ipmi_powernv_set_run_to_completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.poll			= ipmi_powernv_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static irqreturn_t ipmi_opal_event(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct ipmi_smi_powernv *smi = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ipmi_powernv_recv(smi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static int ipmi_powernv_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct ipmi_smi_powernv *ipmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	u32 prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (!pdev || !pdev->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	ipmi = devm_kzalloc(dev, sizeof(*ipmi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (!ipmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	spin_lock_init(&ipmi->msg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	rc = of_property_read_u32(dev->of_node, "ibm,ipmi-interface-id",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			&prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		dev_warn(dev, "No interface ID property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	ipmi->interface_id = prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	rc = of_property_read_u32(dev->of_node, "interrupts", &prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		dev_warn(dev, "No interrupts property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	ipmi->irq = irq_of_parse_and_map(dev->of_node, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!ipmi->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		dev_info(dev, "Unable to map irq from device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		ipmi->irq = opal_event_request(prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	rc = request_irq(ipmi->irq, ipmi_opal_event, IRQ_TYPE_LEVEL_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			 "opal-ipmi", ipmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dev_warn(dev, "Unable to request irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto err_dispose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	ipmi->opal_msg = devm_kmalloc(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			sizeof(*ipmi->opal_msg) + IPMI_MAX_MSG_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!ipmi->opal_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		goto err_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	rc = ipmi_register_smi(&ipmi_powernv_smi_handlers, ipmi, dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		dev_warn(dev, "IPMI SMI registration failed (%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto err_free_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	dev_set_drvdata(dev, ipmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) err_free_msg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	devm_kfree(dev, ipmi->opal_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) err_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	free_irq(ipmi->irq, ipmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err_dispose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	irq_dispose_mapping(ipmi->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	devm_kfree(dev, ipmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int ipmi_powernv_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct ipmi_smi_powernv *smi = dev_get_drvdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	ipmi_unregister_smi(smi->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	free_irq(smi->irq, smi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	irq_dispose_mapping(smi->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static const struct of_device_id ipmi_powernv_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	{ .compatible = "ibm,opal-ipmi" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static struct platform_driver powernv_ipmi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		.name		= "ipmi-powernv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		.of_match_table	= ipmi_powernv_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.probe	= ipmi_powernv_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.remove	= ipmi_powernv_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) module_platform_driver(powernv_ipmi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_DEVICE_TABLE(of, ipmi_powernv_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_DESCRIPTION("powernv IPMI driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_AUTHOR("Jeremy Kerr <jk@ozlabs.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) MODULE_LICENSE("GPL");