From ebba75fdf6fde605741860cca056c9e3adb81e15 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Wed, 11 Apr 2018 13:05:33 -0500 Subject: [PATCH 01/21] acpi:ipmi: Convert ipmi_user_t to struct ipmi_user * Signed-off-by: Corey Minyard Cc: Zhao Yakui Cc: Lv Zheng Acked-by: Rafael J. Wysocki --- drivers/acpi/acpi_ipmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c index 1b64419e2fec..712fd31674a6 100644 --- a/drivers/acpi/acpi_ipmi.c +++ b/drivers/acpi/acpi_ipmi.c @@ -46,7 +46,7 @@ struct acpi_ipmi_device { spinlock_t tx_msg_lock; acpi_handle handle; struct device *dev; - ipmi_user_t user_interface; + struct ipmi_user *user_interface; int ipmi_ifnum; /* IPMI interface number */ long curr_msgid; bool dead; @@ -125,7 +125,7 @@ ipmi_dev_alloc(int iface, struct device *dev, acpi_handle handle) { struct acpi_ipmi_device *ipmi_device; int err; - ipmi_user_t user; + struct ipmi_user *user; ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL); if (!ipmi_device) From 3f901c865160d55bf66fb9b5a7e0ccd0f0458671 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Wed, 11 Apr 2018 16:11:39 -0500 Subject: [PATCH 02/21] hwmon:ibm: Change ipmi_user_t to struct ipmi_user * Signed-off-by: Corey Minyard Cc: Darrick J. Wong Acked-by: Guenter Roeck Reviewed-by: Darrick J. Wong --- drivers/hwmon/ibmaem.c | 2 +- drivers/hwmon/ibmpex.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c index 1f643782ce04..9e92673f6913 100644 --- a/drivers/hwmon/ibmaem.c +++ b/drivers/hwmon/ibmaem.c @@ -101,7 +101,7 @@ static struct platform_driver aem_driver = { struct aem_ipmi_data { struct completion read_complete; struct ipmi_addr address; - ipmi_user_t user; + struct ipmi_user *user; int interface; struct kernel_ipmi_msg tx_message; diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c index ab72cabf5a95..bb17a29af64c 100644 --- a/drivers/hwmon/ibmpex.c +++ b/drivers/hwmon/ibmpex.c @@ -84,7 +84,7 @@ struct ibmpex_bmc_data { struct ipmi_addr address; struct completion read_complete; - ipmi_user_t user; + struct ipmi_user *user; int interface; struct kernel_ipmi_msg tx_message; From 4a758c929dc0f0a1e5359d456e6978fd2fdee9b7 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Mon, 21 May 2018 20:25:31 -0500 Subject: [PATCH 03/21] ipmi:powernv: Convert ipmi_smi_t to struct ipmi_smi Since everything else has been converted. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_powernv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/ipmi/ipmi_powernv.c b/drivers/char/ipmi/ipmi_powernv.c index e96500372ce2..da22a8cbe68e 100644 --- a/drivers/char/ipmi/ipmi_powernv.c +++ b/drivers/char/ipmi/ipmi_powernv.c @@ -19,7 +19,7 @@ struct ipmi_smi_powernv { u64 interface_id; - ipmi_smi_t intf; + struct ipmi_smi *intf; unsigned int irq; /** @@ -33,7 +33,7 @@ struct ipmi_smi_powernv { struct opal_ipmi_msg *opal_msg; }; -static int ipmi_powernv_start_processing(void *send_info, ipmi_smi_t intf) +static int ipmi_powernv_start_processing(void *send_info, struct ipmi_smi *intf) { struct ipmi_smi_powernv *smi = send_info; From 4372ea94d40c5676814fc6d815a64caed963cb9f Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Wed, 18 Apr 2018 10:00:47 -0500 Subject: [PATCH 04/21] ipmi: Finally get rid of ipmi_user_t and ipmi_smi_t All the users have been removed, we can remove the typedefs. Signed-off-by: Corey Minyard --- include/linux/ipmi.h | 2 +- include/linux/ipmi_smi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/ipmi.h b/include/linux/ipmi.h index 41f5c086f670..ef61676cfe05 100644 --- a/include/linux/ipmi.h +++ b/include/linux/ipmi.h @@ -27,7 +27,7 @@ struct device; * Opaque type for a IPMI message user. One of these is needed to * send and receive messages. */ -typedef struct ipmi_user *ipmi_user_t; +struct ipmi_user; /* * Stuff coming from the receive interface comes as one of these. diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h index 7d5fd38d5282..8c4e2ab696c3 100644 --- a/include/linux/ipmi_smi.h +++ b/include/linux/ipmi_smi.h @@ -28,7 +28,7 @@ struct device; */ /* Structure for the low-level drivers. */ -typedef struct ipmi_smi *ipmi_smi_t; +struct ipmi_smi; /* * Messages to/from the lower layer. The smi interface will take one From 05c3d056086a6217a77937b7fa0df35ec75715e6 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Mon, 26 Feb 2018 12:49:16 -0600 Subject: [PATCH 05/21] pci:ipmi: Move IPMI PCI class id defines to pci_ids.h Signed-off-by: Corey Minyard Acked-by: Bjorn Helgaas --- drivers/char/ipmi/ipmi_si_pci.c | 5 ----- include/linux/pci_ids.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/char/ipmi/ipmi_si_pci.c b/drivers/char/ipmi/ipmi_si_pci.c index f54ca6869ed2..bdba12852a90 100644 --- a/drivers/char/ipmi/ipmi_si_pci.c +++ b/drivers/char/ipmi/ipmi_si_pci.c @@ -18,11 +18,6 @@ module_param_named(trypci, si_trypci, bool, 0); MODULE_PARM_DESC(trypci, "Setting this to zero will disable the" " default scan of the interfaces identified via pci"); -#define PCI_CLASS_SERIAL_IPMI 0x0c07 -#define PCI_CLASS_SERIAL_IPMI_SMIC 0x0c0700 -#define PCI_CLASS_SERIAL_IPMI_KCS 0x0c0701 -#define PCI_CLASS_SERIAL_IPMI_BT 0x0c0702 - #define PCI_DEVICE_ID_HP_MMC 0x121A static void ipmi_pci_cleanup(struct si_sm_io *io) diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index d157983b84cf..d4afd8086ed9 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -117,6 +117,10 @@ #define PCI_CLASS_SERIAL_USB_DEVICE 0x0c03fe #define PCI_CLASS_SERIAL_FIBER 0x0c04 #define PCI_CLASS_SERIAL_SMBUS 0x0c05 +#define PCI_CLASS_SERIAL_IPMI 0x0c07 +#define PCI_CLASS_SERIAL_IPMI_SMIC 0x0c0700 +#define PCI_CLASS_SERIAL_IPMI_KCS 0x0c0701 +#define PCI_CLASS_SERIAL_IPMI_BT 0x0c0702 #define PCI_BASE_CLASS_WIRELESS 0x0d #define PCI_CLASS_WIRELESS_RF_CONTROLLER 0x0d10 From 445e2cbda928a3523c1c1da76788d19df52611c8 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 9 May 2018 08:15:47 -0700 Subject: [PATCH 06/21] ipmi: msghandler: Add and use pr_fmt and dev_fmt, remove PFX Standardize the prefixing of output messages using the pr_fmt and dev_fmt mechanisms instead of a separate #define PFX Miscellanea: o Because this message prefix is very long, use a non-standard define of #define pr_fmt(fmt) "%s" fmt, "IPMI message handler: " which removes ~170 bytes of object code in an x86-64 defconfig with ipmi (with even more object code reduction on 32 bit compilations) Signed-off-by: Joe Perches Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_msghandler.c | 51 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 7fc9612070a1..04f64c55e275 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -11,6 +11,9 @@ * Copyright 2002 MontaVista Software Inc. */ +#define pr_fmt(fmt) "%s" fmt, "IPMI message handler: " +#define dev_fmt pr_fmt + #include #include #include @@ -30,8 +33,6 @@ #include #include -#define PFX "IPMI message handler: " - #define IPMI_DRIVER_VERSION "39.2" static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); @@ -1474,8 +1475,7 @@ int ipmi_set_gets_events(struct ipmi_user *user, bool val) list_move_tail(&msg->link, &msgs); intf->waiting_events_count = 0; if (intf->event_msg_printed) { - dev_warn(intf->si_dev, - PFX "Event queue no longer full\n"); + dev_warn(intf->si_dev, "Event queue no longer full\n"); intf->event_msg_printed = 0; } @@ -2276,16 +2276,15 @@ static void bmc_device_id_handler(struct ipmi_smi *intf, || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE) || (msg->msg.cmd != IPMI_GET_DEVICE_ID_CMD)) { dev_warn(intf->si_dev, - PFX "invalid device_id msg: addr_type=%d netfn=%x cmd=%x\n", - msg->addr.addr_type, msg->msg.netfn, msg->msg.cmd); + "invalid device_id msg: addr_type=%d netfn=%x cmd=%x\n", + msg->addr.addr_type, msg->msg.netfn, msg->msg.cmd); return; } rv = ipmi_demangle_device_id(msg->msg.netfn, msg->msg.cmd, msg->msg.data, msg->msg.data_len, &intf->bmc->fetch_id); if (rv) { - dev_warn(intf->si_dev, - PFX "device id demangle failed: %d\n", rv); + dev_warn(intf->si_dev, "device id demangle failed: %d\n", rv); intf->bmc->dyn_id_set = 0; } else { /* @@ -2908,8 +2907,7 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf, mutex_unlock(&bmc->dyn_mutex); dev_info(intf->si_dev, - "ipmi: interfacing existing BMC (man_id: 0x%6.6x," - " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", + "interfacing existing BMC (man_id: 0x%6.6x, prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", bmc->id.manufacturer_id, bmc->id.product_id, bmc->id.device_id); @@ -2948,7 +2946,7 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf, rv = platform_device_register(&bmc->pdev); if (rv) { dev_err(intf->si_dev, - PFX " Unable to register bmc device: %d\n", + "Unable to register bmc device: %d\n", rv); goto out_list_del; } @@ -2966,8 +2964,7 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf, */ rv = sysfs_create_link(&intf->si_dev->kobj, &bmc->pdev.dev.kobj, "bmc"); if (rv) { - dev_err(intf->si_dev, - PFX "Unable to create bmc symlink: %d\n", rv); + dev_err(intf->si_dev, "Unable to create bmc symlink: %d\n", rv); goto out_put_bmc; } @@ -2976,8 +2973,8 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf, intf->my_dev_name = kasprintf(GFP_KERNEL, "ipmi%d", intf_num); if (!intf->my_dev_name) { rv = -ENOMEM; - dev_err(intf->si_dev, - PFX "Unable to allocate link from BMC: %d\n", rv); + dev_err(intf->si_dev, "Unable to allocate link from BMC: %d\n", + rv); goto out_unlink1; } @@ -2986,8 +2983,8 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf, if (rv) { kfree(intf->my_dev_name); intf->my_dev_name = NULL; - dev_err(intf->si_dev, - PFX "Unable to create symlink to bmc: %d\n", rv); + dev_err(intf->si_dev, "Unable to create symlink to bmc: %d\n", + rv); goto out_free_my_dev_name; } @@ -3071,7 +3068,7 @@ static void guid_handler(struct ipmi_smi *intf, struct ipmi_recv_msg *msg) if (msg->msg.data_len < 17) { bmc->dyn_guid_set = 0; dev_warn(intf->si_dev, - PFX "The GUID response from the BMC was too short, it was %d but should have been 17. Assuming GUID is not available.\n", + "The GUID response from the BMC was too short, it was %d but should have been 17. Assuming GUID is not available.\n", msg->msg.data_len); goto out; } @@ -3195,7 +3192,7 @@ channel_handler(struct ipmi_smi *intf, struct ipmi_recv_msg *msg) if (rv) { /* Got an error somehow, just give up. */ dev_warn(intf->si_dev, - PFX "Error sending channel information for channel %d: %d\n", + "Error sending channel information for channel %d: %d\n", intf->curr_channel, rv); intf->channel_list = intf->wchannels + set; @@ -4075,7 +4072,7 @@ static int handle_read_event_rsp(struct ipmi_smi *intf, * message. */ dev_warn(intf->si_dev, - PFX "Event queue full, discarding incoming events\n"); + "Event queue full, discarding incoming events\n"); intf->event_msg_printed = 1; } @@ -4094,7 +4091,7 @@ static int handle_bmc_rsp(struct ipmi_smi *intf, recv_msg = (struct ipmi_recv_msg *) msg->user_data; if (recv_msg == NULL) { dev_warn(intf->si_dev, - "IPMI message received with no owner. This could be because of a malformed message, or because of a hardware error. Contact your hardware vender for assistance\n"); + "IPMI message received with no owner. This could be because of a malformed message, or because of a hardware error. Contact your hardware vendor for assistance.\n"); return 0; } @@ -4130,7 +4127,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf, if (msg->rsp_size < 2) { /* Message is too small to be correct. */ dev_warn(intf->si_dev, - PFX "BMC returned to small a message for netfn %x cmd %x, got %d bytes\n", + "BMC returned too small a message for netfn %x cmd %x, got %d bytes\n", (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size); /* Generate an error response for the message. */ @@ -4145,7 +4142,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf, * marginally correct. */ dev_warn(intf->si_dev, - PFX "BMC returned incorrect response, expected netfn %x cmd %x, got netfn %x cmd %x\n", + "BMC returned incorrect response, expected netfn %x cmd %x, got netfn %x cmd %x\n", (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp[0] >> 2, msg->rsp[1]); @@ -5035,11 +5032,11 @@ static int ipmi_init_msghandler(void) rv = driver_register(&ipmidriver.driver); if (rv) { - pr_err(PFX "Could not register IPMI driver\n"); + pr_err("Could not register IPMI driver\n"); return rv; } - pr_info("ipmi message handler version " IPMI_DRIVER_VERSION "\n"); + pr_info("version " IPMI_DRIVER_VERSION "\n"); timer_setup(&ipmi_timer, ipmi_timeout, 0); mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); @@ -5086,10 +5083,10 @@ static void __exit cleanup_ipmi(void) /* Check for buffer leaks. */ count = atomic_read(&smi_msg_inuse_count); if (count != 0) - pr_warn(PFX "SMI message count %d at exit\n", count); + pr_warn("SMI message count %d at exit\n", count); count = atomic_read(&recv_msg_inuse_count); if (count != 0) - pr_warn(PFX "recv message count %d at exit\n", count); + pr_warn("recv message count %d at exit\n", count); } module_exit(cleanup_ipmi); From 25880f7d61a4f2fdda29cadae55985431df82c5c Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 9 May 2018 08:15:48 -0700 Subject: [PATCH 07/21] ipmi: Use more common logging styles Add and use #define pr_fmt/dev_fmt, and remove #define PFX This also prefixes some messages that were not previously prefixed. Miscellanea: o Convert printk(KERN_ to pr_( o Use %s, __func__ where appropriate Signed-off-by: Joe Perches Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_poweroff.c | 67 ++++++++++++--------------- drivers/char/ipmi/ipmi_si_hardcode.c | 9 ++-- drivers/char/ipmi/ipmi_si_hotmod.c | 17 +++---- drivers/char/ipmi/ipmi_si_intf.c | 22 ++++----- drivers/char/ipmi/ipmi_si_pci.c | 12 ++--- drivers/char/ipmi/ipmi_si_platform.c | 20 ++++---- drivers/char/ipmi/ipmi_ssif.c | 69 +++++++++++++--------------- drivers/char/ipmi/ipmi_watchdog.c | 52 ++++++++++----------- 8 files changed, 130 insertions(+), 138 deletions(-) diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c index f6e19410dc57..bc3a18daf97a 100644 --- a/drivers/char/ipmi/ipmi_poweroff.c +++ b/drivers/char/ipmi/ipmi_poweroff.c @@ -11,6 +11,9 @@ * * Copyright 2002,2004 MontaVista Software Inc. */ + +#define pr_fmt(fmt) "IPMI poweroff: " fmt + #include #include #include @@ -21,8 +24,6 @@ #include #include -#define PFX "IPMI poweroff: " - static void ipmi_po_smi_gone(int if_num); static void ipmi_po_new_smi(int if_num, struct device *device); @@ -192,7 +193,7 @@ static void pps_poweroff_atca(struct ipmi_user *user) smi_addr.channel = IPMI_BMC_CHANNEL; smi_addr.lun = 0; - printk(KERN_INFO PFX "PPS powerdown hook used"); + pr_info("PPS powerdown hook used\n"); send_msg.netfn = IPMI_NETFN_OEM; send_msg.cmd = IPMI_ATCA_PPS_GRACEFUL_RESTART; @@ -201,10 +202,9 @@ static void pps_poweroff_atca(struct ipmi_user *user) rv = ipmi_request_in_rc_mode(user, (struct ipmi_addr *) &smi_addr, &send_msg); - if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) { - printk(KERN_ERR PFX "Unable to send ATCA ," - " IPMI error 0x%x\n", rv); - } + if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) + pr_err("Unable to send ATCA, IPMI error 0x%x\n", rv); + return; } @@ -234,12 +234,10 @@ static int ipmi_atca_detect(struct ipmi_user *user) (struct ipmi_addr *) &smi_addr, &send_msg); - printk(KERN_INFO PFX "ATCA Detect mfg 0x%X prod 0x%X\n", - mfg_id, prod_id); + pr_info("ATCA Detect mfg 0x%X prod 0x%X\n", mfg_id, prod_id); if ((mfg_id == IPMI_MOTOROLA_MANUFACTURER_ID) && (prod_id == IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID)) { - printk(KERN_INFO PFX - "Installing Pigeon Point Systems Poweroff Hook\n"); + pr_info("Installing Pigeon Point Systems Poweroff Hook\n"); atca_oem_poweroff_hook = pps_poweroff_atca; } return !rv; @@ -259,7 +257,7 @@ static void ipmi_poweroff_atca(struct ipmi_user *user) smi_addr.channel = IPMI_BMC_CHANNEL; smi_addr.lun = 0; - printk(KERN_INFO PFX "Powering down via ATCA power command\n"); + pr_info("Powering down via ATCA power command\n"); /* * Power down @@ -282,8 +280,8 @@ static void ipmi_poweroff_atca(struct ipmi_user *user) * return code */ if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) { - printk(KERN_ERR PFX "Unable to send ATCA powerdown message," - " IPMI error 0x%x\n", rv); + pr_err("Unable to send ATCA powerdown message, IPMI error 0x%x\n", + rv); goto out; } @@ -334,7 +332,7 @@ static void ipmi_poweroff_cpi1(struct ipmi_user *user) smi_addr.channel = IPMI_BMC_CHANNEL; smi_addr.lun = 0; - printk(KERN_INFO PFX "Powering down via CPI1 power command\n"); + pr_info("Powering down via CPI1 power command\n"); /* * Get IPMI ipmb address @@ -482,7 +480,7 @@ static void ipmi_poweroff_chassis(struct ipmi_user *user) smi_addr.lun = 0; powercyclefailed: - printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n", + pr_info("Powering %s via IPMI chassis control command\n", (poweroff_powercycle ? "cycle" : "down")); /* @@ -502,14 +500,14 @@ static void ipmi_poweroff_chassis(struct ipmi_user *user) if (rv) { if (poweroff_powercycle) { /* power cycle failed, default to power down */ - printk(KERN_ERR PFX "Unable to send chassis power " \ - "cycle message, IPMI error 0x%x\n", rv); + pr_err("Unable to send chassis power cycle message, IPMI error 0x%x\n", + rv); poweroff_powercycle = 0; goto powercyclefailed; } - printk(KERN_ERR PFX "Unable to send chassis power " \ - "down message, IPMI error 0x%x\n", rv); + pr_err("Unable to send chassis power down message, IPMI error 0x%x\n", + rv); } } @@ -571,8 +569,7 @@ static void ipmi_po_new_smi(int if_num, struct device *device) rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL, &ipmi_user); if (rv) { - printk(KERN_ERR PFX "could not create IPMI user, error %d\n", - rv); + pr_err("could not create IPMI user, error %d\n", rv); return; } @@ -594,14 +591,13 @@ static void ipmi_po_new_smi(int if_num, struct device *device) (struct ipmi_addr *) &smi_addr, &send_msg); if (rv) { - printk(KERN_ERR PFX "Unable to send IPMI get device id info," - " IPMI error 0x%x\n", rv); + pr_err("Unable to send IPMI get device id info, IPMI error 0x%x\n", + rv); goto out_err; } if (halt_recv_msg.msg.data_len < 12) { - printk(KERN_ERR PFX "(chassis) IPMI get device id info too," - " short, was %d bytes, needed %d bytes\n", + pr_err("(chassis) IPMI get device id info too short, was %d bytes, needed %d bytes\n", halt_recv_msg.msg.data_len, 12); goto out_err; } @@ -622,14 +618,13 @@ static void ipmi_po_new_smi(int if_num, struct device *device) } out_err: - printk(KERN_ERR PFX "Unable to find a poweroff function that" - " will work, giving up\n"); + pr_err("Unable to find a poweroff function that will work, giving up\n"); ipmi_destroy_user(ipmi_user); return; found: - printk(KERN_INFO PFX "Found a %s style poweroff function\n", - poweroff_functions[i].platform_type); + pr_info("Found a %s style poweroff function\n", + poweroff_functions[i].platform_type); specific_poweroff_func = poweroff_functions[i].poweroff_func; old_poweroff_func = pm_power_off; pm_power_off = ipmi_poweroff_function; @@ -692,16 +687,15 @@ static int __init ipmi_poweroff_init(void) { int rv; - printk(KERN_INFO "Copyright (C) 2004 MontaVista Software -" - " IPMI Powerdown via sys_reboot.\n"); + pr_info("Copyright (C) 2004 MontaVista Software - IPMI Powerdown via sys_reboot\n"); if (poweroff_powercycle) - printk(KERN_INFO PFX "Power cycle is enabled.\n"); + pr_info("Power cycle is enabled\n"); #ifdef CONFIG_PROC_FS ipmi_table_header = register_sysctl_table(ipmi_root_table); if (!ipmi_table_header) { - printk(KERN_ERR PFX "Unable to register powercycle sysctl\n"); + pr_err("Unable to register powercycle sysctl\n"); rv = -ENOMEM; goto out_err; } @@ -712,7 +706,7 @@ static int __init ipmi_poweroff_init(void) #ifdef CONFIG_PROC_FS if (rv) { unregister_sysctl_table(ipmi_table_header); - printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); + pr_err("Unable to register SMI watcher: %d\n", rv); goto out_err; } @@ -735,8 +729,7 @@ static void __exit ipmi_poweroff_cleanup(void) if (ready) { rv = ipmi_destroy_user(ipmi_user); if (rv) - printk(KERN_ERR PFX "could not cleanup the IPMI" - " user: 0x%x\n", rv); + pr_err("could not cleanup the IPMI user: 0x%x\n", rv); pm_power_off = old_poweroff_func; } } diff --git a/drivers/char/ipmi/ipmi_si_hardcode.c b/drivers/char/ipmi/ipmi_si_hardcode.c index 10219f24546b..487642809c58 100644 --- a/drivers/char/ipmi/ipmi_si_hardcode.c +++ b/drivers/char/ipmi/ipmi_si_hardcode.c @@ -1,9 +1,10 @@ // SPDX-License-Identifier: GPL-2.0+ +#define pr_fmt(fmt) "ipmi_hardcode: " fmt + #include #include "ipmi_si.h" -#define PFX "ipmi_hardcode: " /* * There can be 4 IO ports passed in (with or without IRQs), 4 addresses, * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS. @@ -100,7 +101,7 @@ int ipmi_si_hardcode_find_bmc(void) continue; io.addr_source = SI_HARDCODED; - pr_info(PFX "probing via hardcoded address\n"); + pr_info("probing via hardcoded address\n"); if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) { io.si_type = SI_KCS; @@ -109,7 +110,7 @@ int ipmi_si_hardcode_find_bmc(void) } else if (strcmp(si_type[i], "bt") == 0) { io.si_type = SI_BT; } else { - pr_warn(PFX "Interface type specified for interface %d, was invalid: %s\n", + pr_warn("Interface type specified for interface %d, was invalid: %s\n", i, si_type[i]); continue; } @@ -123,7 +124,7 @@ int ipmi_si_hardcode_find_bmc(void) io.addr_data = addrs[i]; io.addr_type = IPMI_MEM_ADDR_SPACE; } else { - pr_warn(PFX "Interface type specified for interface %d, but port and address were not set or set to zero.\n", + pr_warn("Interface type specified for interface %d, but port and address were not set or set to zero\n", i); continue; } diff --git a/drivers/char/ipmi/ipmi_si_hotmod.c b/drivers/char/ipmi/ipmi_si_hotmod.c index a98ca42a50b1..c0067fd0480d 100644 --- a/drivers/char/ipmi/ipmi_si_hotmod.c +++ b/drivers/char/ipmi/ipmi_si_hotmod.c @@ -5,12 +5,13 @@ * Handling for dynamically adding/removing IPMI devices through * a module parameter (and thus sysfs). */ + +#define pr_fmt(fmt) "ipmi_hotmod: " fmt + #include #include #include "ipmi_si.h" -#define PFX "ipmi_hotmod: " - static int hotmod_handler(const char *val, const struct kernel_param *kp); module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200); @@ -61,7 +62,7 @@ static int parse_str(const struct hotmod_vals *v, int *val, char *name, s = strchr(*curr, ','); if (!s) { - pr_warn(PFX "No hotmod %s given.\n", name); + pr_warn("No hotmod %s given\n", name); return -EINVAL; } *s = '\0'; @@ -74,7 +75,7 @@ static int parse_str(const struct hotmod_vals *v, int *val, char *name, } } - pr_warn(PFX "Invalid hotmod %s '%s'\n", name, *curr); + pr_warn("Invalid hotmod %s '%s'\n", name, *curr); return -EINVAL; } @@ -85,12 +86,12 @@ static int check_hotmod_int_op(const char *curr, const char *option, if (strcmp(curr, name) == 0) { if (!option) { - pr_warn(PFX "No option given for '%s'\n", curr); + pr_warn("No option given for '%s'\n", curr); return -EINVAL; } *val = simple_strtoul(option, &n, 0); if ((*n != '\0') || (*option == '\0')) { - pr_warn(PFX "Bad option given for '%s'\n", curr); + pr_warn("Bad option given for '%s'\n", curr); return -EINVAL; } return 1; @@ -160,7 +161,7 @@ static int hotmod_handler(const char *val, const struct kernel_param *kp) } addr = simple_strtoul(curr, &n, 0); if ((*n != '\0') || (*curr == '\0')) { - pr_warn(PFX "Invalid hotmod address '%s'\n", curr); + pr_warn("Invalid hotmod address '%s'\n", curr); break; } @@ -203,7 +204,7 @@ static int hotmod_handler(const char *val, const struct kernel_param *kp) continue; rv = -EINVAL; - pr_warn(PFX "Invalid hotmod option '%s'\n", curr); + pr_warn("Invalid hotmod option '%s'\n", curr); goto out; } diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index 5faa917df1b6..132bb508cd19 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -19,6 +19,8 @@ * and drives the real SMI state machine. */ +#define pr_fmt(fmt) "ipmi_si: " fmt + #include #include #include @@ -41,8 +43,6 @@ #include #include -#define PFX "ipmi_si: " - /* Measure times between events in the driver. */ #undef DEBUG_TIMING @@ -1530,7 +1530,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info) rv = wait_for_msg_done(smi_info); if (rv) { - pr_warn(PFX "Error getting response from get global enables command, the event buffer is not enabled.\n"); + pr_warn("Error getting response from get global enables command, the event buffer is not enabled\n"); goto out; } @@ -1541,7 +1541,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info) resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD || resp[2] != 0) { - pr_warn(PFX "Invalid return from get global enables command, cannot enable the event buffer.\n"); + pr_warn("Invalid return from get global enables command, cannot enable the event buffer\n"); rv = -EINVAL; goto out; } @@ -1559,7 +1559,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info) rv = wait_for_msg_done(smi_info); if (rv) { - pr_warn(PFX "Error getting response from set global, enables command, the event buffer is not enabled.\n"); + pr_warn("Error getting response from set global, enables command, the event buffer is not enabled\n"); goto out; } @@ -1569,7 +1569,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info) if (resp_len < 3 || resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) { - pr_warn(PFX "Invalid return from get global, enables command, not enable the event buffer.\n"); + pr_warn("Invalid return from get global, enables command, not enable the event buffer\n"); rv = -EINVAL; goto out; } @@ -1900,7 +1900,7 @@ int ipmi_si_add_smi(struct si_sm_io *io) } } - pr_info(PFX "Adding %s-specified %s state machine\n", + pr_info("Adding %s-specified %s state machine\n", ipmi_addr_src_to_str(new_smi->io.addr_source), si_to_str[new_smi->io.si_type]); @@ -1924,7 +1924,7 @@ static int try_smi_init(struct smi_info *new_smi) int i; char *init_name = NULL; - pr_info(PFX "Trying %s-specified %s state machine at %s address 0x%lx, slave address 0x%x, irq %d\n", + pr_info("Trying %s-specified %s state machine at %s address 0x%lx, slave address 0x%x, irq %d\n", ipmi_addr_src_to_str(new_smi->io.addr_source), si_to_str[new_smi->io.si_type], addr_space_to_str[new_smi->io.addr_type], @@ -1964,7 +1964,7 @@ static int try_smi_init(struct smi_info *new_smi) new_smi->pdev = platform_device_alloc("ipmi_si", new_smi->si_num); if (!new_smi->pdev) { - pr_err(PFX "Unable to allocate platform device\n"); + pr_err("Unable to allocate platform device\n"); rv = -ENOMEM; goto out_err; } @@ -2097,7 +2097,7 @@ static int init_ipmi_si(void) if (initialized) return 0; - pr_info("IPMI System Interface driver.\n"); + pr_info("IPMI System Interface driver\n"); /* If the user gave us a device, they presumably want us to use it */ if (!ipmi_si_hardcode_find_bmc()) @@ -2151,7 +2151,7 @@ skip_fallback_noirq: if (unload_when_empty && list_empty(&smi_infos)) { mutex_unlock(&smi_infos_lock); cleanup_ipmi_si(); - pr_warn(PFX "Unable to find any System Interface(s)\n"); + pr_warn("Unable to find any System Interface(s)\n"); return -ENODEV; } else { mutex_unlock(&smi_infos_lock); diff --git a/drivers/char/ipmi/ipmi_si_pci.c b/drivers/char/ipmi/ipmi_si_pci.c index bdba12852a90..5eaa850ce455 100644 --- a/drivers/char/ipmi/ipmi_si_pci.c +++ b/drivers/char/ipmi/ipmi_si_pci.c @@ -4,12 +4,13 @@ * * Handling for IPMI devices on the PCI bus. */ + +#define pr_fmt(fmt) "ipmi_pci: " fmt + #include #include #include "ipmi_si.h" -#define PFX "ipmi_pci: " - static bool pci_registered; static bool si_trypci = true; @@ -40,8 +41,7 @@ static int ipmi_pci_probe_regspacing(struct si_sm_io *io) for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) { io->regspacing = regspacing; if (io->io_setup(io)) { - dev_err(io->dev, - "Could not setup I/O space\n"); + dev_err(io->dev, "Could not setup I/O space\n"); return DEFAULT_REGSPACING; } /* write invalid cmd */ @@ -126,7 +126,7 @@ static int ipmi_pci_probe(struct pci_dev *pdev, io.dev = &pdev->dev; dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n", - &pdev->resource[0], io.regsize, io.regspacing, io.irq); + &pdev->resource[0], io.regsize, io.regspacing, io.irq); rv = ipmi_si_add_smi(&io); if (rv) @@ -161,7 +161,7 @@ void ipmi_si_pci_init(void) if (si_trypci) { int rv = pci_register_driver(&ipmi_pci_driver); if (rv) - pr_err(PFX "Unable to register PCI driver: %d\n", rv); + pr_err("Unable to register PCI driver: %d\n", rv); else pci_registered = true; } diff --git a/drivers/char/ipmi/ipmi_si_platform.c b/drivers/char/ipmi/ipmi_si_platform.c index bf69927502bd..999fba24e29c 100644 --- a/drivers/char/ipmi/ipmi_si_platform.c +++ b/drivers/char/ipmi/ipmi_si_platform.c @@ -5,6 +5,10 @@ * Handling for platform devices in IPMI (ACPI, OF, and things * coming from the platform. */ + +#define pr_fmt(fmt) "ipmi_platform: " fmt +#define dev_fmt pr_fmt + #include #include #include @@ -15,8 +19,6 @@ #include "ipmi_si.h" #include "ipmi_dmi.h" -#define PFX "ipmi_platform: " - static bool si_tryplatform = true; #ifdef CONFIG_ACPI static bool si_tryacpi = true; @@ -158,7 +160,7 @@ static int platform_ipmi_probe(struct platform_device *pdev) memset(&io, 0, sizeof(io)); io.addr_source = addr_source; - dev_info(&pdev->dev, PFX "probing via %s\n", + dev_info(&pdev->dev, "probing via %s\n", ipmi_addr_src_to_str(addr_source)); switch (type) { @@ -236,25 +238,25 @@ static int of_ipmi_probe(struct platform_device *pdev) ret = of_address_to_resource(np, 0, &resource); if (ret) { - dev_warn(&pdev->dev, PFX "invalid address from OF\n"); + dev_warn(&pdev->dev, "invalid address from OF\n"); return ret; } regsize = of_get_property(np, "reg-size", &proplen); if (regsize && proplen != 4) { - dev_warn(&pdev->dev, PFX "invalid regsize from OF\n"); + dev_warn(&pdev->dev, "invalid regsize from OF\n"); return -EINVAL; } regspacing = of_get_property(np, "reg-spacing", &proplen); if (regspacing && proplen != 4) { - dev_warn(&pdev->dev, PFX "invalid regspacing from OF\n"); + dev_warn(&pdev->dev, "invalid regspacing from OF\n"); return -EINVAL; } regshift = of_get_property(np, "reg-shift", &proplen); if (regshift && proplen != 4) { - dev_warn(&pdev->dev, PFX "invalid regshift from OF\n"); + dev_warn(&pdev->dev, "invalid regshift from OF\n"); return -EINVAL; } @@ -326,7 +328,7 @@ static int acpi_ipmi_probe(struct platform_device *pdev) memset(&io, 0, sizeof(io)); io.addr_source = SI_ACPI; - dev_info(&pdev->dev, PFX "probing via ACPI\n"); + dev_info(&pdev->dev, "probing via ACPI\n"); io.addr_info.acpi_info.acpi_handle = handle; @@ -431,7 +433,7 @@ void ipmi_si_platform_init(void) { int rv = platform_driver_register(&ipmi_platform_driver); if (rv) - pr_err(PFX "Unable to register driver: %d\n", rv); + pr_err("Unable to register driver: %d\n", rv); } void ipmi_si_platform_shutdown(void) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 29e67a80fb20..61bc493765b9 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -27,6 +27,8 @@ * interface into the I2C driver, I believe. */ +#define pr_fmt(fmt) "ipmi_ssif: " fmt + #if defined(MODVERSIONS) #include #endif @@ -52,7 +54,6 @@ #include "ipmi_si_sm.h" #include "ipmi_dmi.h" -#define PFX "ipmi_ssif: " #define DEVICE_NAME "ipmi_ssif" #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD 0x57 @@ -316,9 +317,8 @@ static void deliver_recv_msg(struct ssif_info *ssif_info, { if (msg->rsp_size < 0) { return_hosed_msg(ssif_info, msg); - pr_err(PFX - "Malformed message in deliver_recv_msg: rsp_size = %d\n", - msg->rsp_size); + pr_err("%s: Malformed message: rsp_size = %d\n", + __func__, msg->rsp_size); } else { ipmi_smi_msg_received(ssif_info->intf, msg); } @@ -652,7 +652,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, if (len == 0) { result = -EIO; if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) - pr_info(PFX "Middle message with no data\n"); + pr_info("Middle message with no data\n"); goto continue_op; } @@ -696,8 +696,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, I2C_SMBUS_BLOCK_DATA); if (rv < 0) { if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) - pr_info(PFX - "Error from ssif_i2c_send\n"); + pr_info("Error from ssif_i2c_send\n"); result = -EIO; } else @@ -715,7 +714,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, continue_op: if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) - pr_info(PFX "DONE 1: state = %d, result=%d.\n", + pr_info("DONE 1: state = %d, result=%d\n", ssif_info->ssif_state, result); flags = ipmi_ssif_lock_cond(ssif_info, &oflags); @@ -749,8 +748,8 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, */ ssif_info->ssif_state = SSIF_NORMAL; ipmi_ssif_unlock_cond(ssif_info, flags); - pr_warn(PFX "Error getting flags: %d %d, %x\n", - result, len, (len >= 3) ? data[2] : 0); + pr_warn("Error getting flags: %d %d, %x\n", + result, len, (len >= 3) ? data[2] : 0); } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || data[1] != IPMI_GET_MSG_FLAGS_CMD) { /* @@ -758,7 +757,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, * response to a previous command. */ ipmi_ssif_unlock_cond(ssif_info, flags); - pr_warn(PFX "Invalid response getting flags: %x %x\n", + pr_warn("Invalid response getting flags: %x %x\n", data[0], data[1]); } else { ssif_inc_stat(ssif_info, flag_fetches); @@ -771,11 +770,11 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, /* We cleared the flags. */ if ((result < 0) || (len < 3) || (data[2] != 0)) { /* Error clearing flags */ - pr_warn(PFX "Error clearing flags: %d %d, %x\n", - result, len, (len >= 3) ? data[2] : 0); + pr_warn("Error clearing flags: %d %d, %x\n", + result, len, (len >= 3) ? data[2] : 0); } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) { - pr_warn(PFX "Invalid response clearing flags: %x %x\n", + pr_warn("Invalid response clearing flags: %x %x\n", data[0], data[1]); } ssif_info->ssif_state = SSIF_NORMAL; @@ -792,7 +791,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, handle_flags(ssif_info, flags); } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || msg->rsp[1] != IPMI_READ_EVENT_MSG_BUFFER_CMD) { - pr_warn(PFX "Invalid response getting events: %x %x\n", + pr_warn("Invalid response getting events: %x %x\n", msg->rsp[0], msg->rsp[1]); msg->done(msg); /* Take off the event flag. */ @@ -815,7 +814,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, handle_flags(ssif_info, flags); } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || msg->rsp[1] != IPMI_GET_MSG_CMD) { - pr_warn(PFX "Invalid response clearing flags: %x %x\n", + pr_warn("Invalid response clearing flags: %x %x\n", msg->rsp[0], msg->rsp[1]); msg->done(msg); @@ -842,7 +841,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, ipmi_ssif_unlock_cond(ssif_info, flags); if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) - pr_info(PFX "DONE 2: state = %d.\n", ssif_info->ssif_state); + pr_info("DONE 2: state = %d.\n", ssif_info->ssif_state); } static void msg_written_handler(struct ssif_info *ssif_info, int result, @@ -862,8 +861,7 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result, ssif_inc_stat(ssif_info, send_errors); if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) - pr_info(PFX - "Out of retries in msg_written_handler\n"); + pr_info("%s: Out of retries\n", __func__); msg_done_handler(ssif_info, -EIO, NULL, 0); return; } @@ -1043,8 +1041,8 @@ static void sender(void *send_info, ktime_get_real_ts64(&t); pr_info("**Enqueue %02x %02x: %lld.%6.6ld\n", - msg->data[0], msg->data[1], - (long long) t.tv_sec, (long) t.tv_nsec / NSEC_PER_USEC); + msg->data[0], msg->data[1], + (long long)t.tv_sec, (long)t.tv_nsec / NSEC_PER_USEC); } } @@ -1435,9 +1433,9 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) slave_addr = find_slave_address(client, slave_addr); - pr_info(PFX "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n", - ipmi_addr_src_to_str(ssif_info->addr_source), - client->addr, client->adapter->name, slave_addr); + pr_info("Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n", + ipmi_addr_src_to_str(ssif_info->addr_source), + client->addr, client->adapter->name, slave_addr); ssif_info->client = client; i2c_set_clientdata(client, ssif_info); @@ -1450,7 +1448,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) if (!rv && (len >= 3) && (resp[2] == 0)) { if (len < 7) { if (ssif_dbg_probe) - pr_info(PFX "SSIF info too short: %d\n", len); + pr_info("SSIF info too short: %d\n", len); goto no_support; } @@ -1506,8 +1504,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) } else { no_support: /* Assume no multi-part or PEC support */ - pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", - rv, len, resp[2]); + pr_info("Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", + rv, len, resp[2]); ssif_info->max_xmit_msg_size = 32; ssif_info->max_recv_msg_size = 32; @@ -1521,7 +1519,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) msg[2] = WDT_PRE_TIMEOUT_INT; rv = do_cmd(client, 3, msg, &len, resp); if (rv || (len < 3) || (resp[2] != 0)) - pr_warn(PFX "Unable to clear message flags: %d %d %2.2x\n", + pr_warn("Unable to clear message flags: %d %d %2.2x\n", rv, len, resp[2]); /* Attempt to enable the event buffer. */ @@ -1529,7 +1527,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; rv = do_cmd(client, 2, msg, &len, resp); if (rv || (len < 4) || (resp[2] != 0)) { - pr_warn(PFX "Error getting global enables: %d %d %2.2x\n", + pr_warn("Error getting global enables: %d %d %2.2x\n", rv, len, resp[2]); rv = 0; /* Not fatal */ goto found; @@ -1548,7 +1546,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF; rv = do_cmd(client, 3, msg, &len, resp); if (rv || (len < 2)) { - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", + pr_warn("Error setting global enables: %d %d %2.2x\n", rv, len, resp[2]); rv = 0; /* Not fatal */ goto found; @@ -1569,7 +1567,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR; rv = do_cmd(client, 3, msg, &len, resp); if (rv || (len < 2)) { - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", + pr_warn("Error setting global enables: %d %d %2.2x\n", rv, len, resp[2]); rv = 0; /* Not fatal */ goto found; @@ -1637,7 +1635,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) &ssif_info->client->dev, slave_addr); if (rv) { - pr_err(PFX "Unable to register device: error %d\n", rv); + pr_err("Unable to register device: error %d\n", rv); goto out_remove_attr; } @@ -1790,7 +1788,7 @@ static int dmi_ipmi_probe(struct platform_device *pdev) rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr); if (rv) { - dev_warn(&pdev->dev, PFX "No i2c-addr property\n"); + dev_warn(&pdev->dev, "No i2c-addr property\n"); return -ENODEV; } @@ -1871,8 +1869,7 @@ static int init_ipmi_ssif(void) dbg[i], slave_addrs[i], SI_HARDCODED, NULL); if (rv) - pr_err(PFX - "Couldn't add hardcoded device at addr 0x%x\n", + pr_err("Couldn't add hardcoded device at addr 0x%x\n", addr[i]); } @@ -1883,7 +1880,7 @@ static int init_ipmi_ssif(void) if (ssif_trydmi) { rv = platform_driver_register(&ipmi_driver); if (rv) - pr_err(PFX "Unable to register driver: %d\n", rv); + pr_err("Unable to register driver: %d\n", rv); } ssif_i2c_driver.address_list = ssif_address_list(); diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c index ca1c5c5109f0..2924a4bc4a32 100644 --- a/drivers/char/ipmi/ipmi_watchdog.c +++ b/drivers/char/ipmi/ipmi_watchdog.c @@ -11,6 +11,8 @@ * Copyright 2002 MontaVista Software Inc. */ +#define pr_fmt(fmt) "IPMI Watchdog: " fmt + #include #include #include @@ -50,8 +52,6 @@ #define HAVE_DIE_NMI #endif -#define PFX "IPMI Watchdog: " - /* * The IPMI command/response information for the watchdog timer. */ @@ -407,7 +407,7 @@ static int __ipmi_set_timeout(struct ipmi_smi_msg *smi_msg, recv_msg, 1); if (rv) - pr_warn(PFX "set timeout error: %d\n", rv); + pr_warn("set timeout error: %d\n", rv); else if (send_heartbeat_now) *send_heartbeat_now = hbnow; @@ -530,7 +530,7 @@ static void panic_halt_ipmi_set_timeout(void) &send_heartbeat_now); if (rv) { atomic_sub(1, &panic_done_count); - pr_warn(PFX "Unable to extend the watchdog timeout."); + pr_warn("Unable to extend the watchdog timeout\n"); } else { if (send_heartbeat_now) panic_halt_ipmi_heartbeat(); @@ -573,7 +573,7 @@ restart: &recv_msg, 1); if (rv) { - pr_warn(PFX "heartbeat send failure: %d\n", rv); + pr_warn("heartbeat send failure: %d\n", rv); return rv; } @@ -583,7 +583,7 @@ restart: if (recv_msg.msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) { timeout_retries++; if (timeout_retries > 3) { - pr_err(PFX ": Unable to restore the IPMI watchdog's settings, giving up.\n"); + pr_err("Unable to restore the IPMI watchdog's settings, giving up\n"); rv = -EIO; goto out; } @@ -598,7 +598,7 @@ restart: */ rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); if (rv) { - pr_err(PFX ": Unable to send the command to set the watchdog's settings, giving up.\n"); + pr_err("Unable to send the command to set the watchdog's settings, giving up\n"); goto out; } @@ -876,8 +876,7 @@ static int ipmi_close(struct inode *ino, struct file *filep) _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); mutex_unlock(&ipmi_watchdog_mutex); } else { - pr_crit(PFX - "Unexpected close, not stopping watchdog!\n"); + pr_crit("Unexpected close, not stopping watchdog!\n"); ipmi_heartbeat(); } clear_bit(0, &ipmi_wdog_open); @@ -911,9 +910,9 @@ static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg, { if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER && msg->msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) - pr_info(PFX "response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n"); + pr_info("response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n"); else if (msg->msg.data[0] != 0) - pr_err(PFX "response: Error %x on cmd %x\n", + pr_err("response: Error %x on cmd %x\n", msg->msg.data[0], msg->msg.cmd); @@ -985,7 +984,7 @@ static void ipmi_register_watchdog(int ipmi_intf) rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user); if (rv < 0) { - pr_crit(PFX "Unable to register with ipmi\n"); + pr_crit("Unable to register with ipmi\n"); goto out; } @@ -993,7 +992,7 @@ static void ipmi_register_watchdog(int ipmi_intf) &ipmi_version_major, &ipmi_version_minor); if (rv) { - pr_warn(PFX "Unable to get IPMI version, assuming 1.0\n"); + pr_warn("Unable to get IPMI version, assuming 1.0\n"); ipmi_version_major = 1; ipmi_version_minor = 0; } @@ -1002,7 +1001,7 @@ static void ipmi_register_watchdog(int ipmi_intf) if (rv < 0) { ipmi_destroy_user(watchdog_user); watchdog_user = NULL; - pr_crit(PFX "Unable to register misc device\n"); + pr_crit("Unable to register misc device\n"); } #ifdef HAVE_DIE_NMI @@ -1024,7 +1023,7 @@ static void ipmi_register_watchdog(int ipmi_intf) rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB); if (rv) { - pr_warn(PFX "Error starting timer to test NMI: 0x%x. The NMI pretimeout will likely not work\n", + pr_warn("Error starting timer to test NMI: 0x%x. The NMI pretimeout will likely not work\n", rv); rv = 0; goto out_restore; @@ -1033,7 +1032,7 @@ static void ipmi_register_watchdog(int ipmi_intf) msleep(1500); if (testing_nmi != 2) { - pr_warn(PFX "IPMI NMI didn't seem to occur. The NMI pretimeout will likely not work\n"); + pr_warn("IPMI NMI didn't seem to occur. The NMI pretimeout will likely not work\n"); } out_restore: testing_nmi = 0; @@ -1049,7 +1048,7 @@ static void ipmi_register_watchdog(int ipmi_intf) start_now = 0; /* Disable this function after first startup. */ ipmi_watchdog_state = action_val; ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB); - pr_info(PFX "Starting now!\n"); + pr_info("Starting now!\n"); } else { /* Stop the timer now. */ ipmi_watchdog_state = WDOG_TIMEOUT_NONE; @@ -1086,7 +1085,7 @@ static void ipmi_unregister_watchdog(int ipmi_intf) /* Disconnect from IPMI. */ rv = ipmi_destroy_user(loc_user); if (rv) - pr_warn(PFX "error unlinking from IPMI: %d\n", rv); + pr_warn("error unlinking from IPMI: %d\n", rv); /* If it comes back, restart it properly. */ ipmi_start_timer_on_heartbeat = 1; @@ -1127,7 +1126,7 @@ ipmi_nmi(unsigned int val, struct pt_regs *regs) the timer. So do so. */ atomic_set(&pretimeout_since_last_heartbeat, 1); if (atomic_inc_and_test(&preop_panic_excl)) - nmi_panic(regs, PFX "pre-timeout"); + nmi_panic(regs, "pre-timeout"); } return NMI_HANDLED; @@ -1259,7 +1258,7 @@ static void check_parms(void) if (preaction_val == WDOG_PRETIMEOUT_NMI) { do_nmi = 1; if (preop_val == WDOG_PREOP_GIVE_DATA) { - pr_warn(PFX "Pretimeout op is to give data but NMI pretimeout is enabled, setting pretimeout op to none\n"); + pr_warn("Pretimeout op is to give data but NMI pretimeout is enabled, setting pretimeout op to none\n"); preop_op("preop_none", NULL); do_nmi = 0; } @@ -1268,7 +1267,7 @@ static void check_parms(void) rv = register_nmi_handler(NMI_UNKNOWN, ipmi_nmi, 0, "ipmi"); if (rv) { - pr_warn(PFX "Can't register nmi handler\n"); + pr_warn("Can't register nmi handler\n"); return; } else nmi_handler_registered = 1; @@ -1285,19 +1284,18 @@ static int __init ipmi_wdog_init(void) if (action_op(action, NULL)) { action_op("reset", NULL); - pr_info(PFX "Unknown action '%s', defaulting to reset\n", - action); + pr_info("Unknown action '%s', defaulting to reset\n", action); } if (preaction_op(preaction, NULL)) { preaction_op("pre_none", NULL); - pr_info(PFX "Unknown preaction '%s', defaulting to none\n", + pr_info("Unknown preaction '%s', defaulting to none\n", preaction); } if (preop_op(preop, NULL)) { preop_op("preop_none", NULL); - pr_info(PFX "Unknown preop '%s', defaulting to none\n", preop); + pr_info("Unknown preop '%s', defaulting to none\n", preop); } check_parms(); @@ -1311,11 +1309,11 @@ static int __init ipmi_wdog_init(void) unregister_nmi_handler(NMI_UNKNOWN, "ipmi"); #endif unregister_reboot_notifier(&wdog_reboot_notifier); - pr_warn(PFX "can't register smi watcher\n"); + pr_warn("can't register smi watcher\n"); return rv; } - pr_info(PFX "driver initialized\n"); + pr_info("driver initialized\n"); return 0; } From f993cdd99a5fc554bc79e1ce70a9f5335e386649 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 9 May 2018 08:15:49 -0700 Subject: [PATCH 08/21] ipmi: Convert printk(KERN_ to pr_( Use the more common logging style. Miscellanea: o Convert old style continuation printks without KERN_CONT to pr_cont o Coalesce formats o Realign arguments o Remove unnecessary casts Signed-off-by: Joe Perches Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_bt_sm.c | 60 +++++++++++++++----------------- drivers/char/ipmi/ipmi_devintf.c | 11 +++--- drivers/char/ipmi/ipmi_kcs_sm.c | 4 +-- drivers/char/ipmi/ipmi_smic_sm.c | 26 ++++++-------- 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c index 97d6856c9c0f..b4133832e075 100644 --- a/drivers/char/ipmi/ipmi_bt_sm.c +++ b/drivers/char/ipmi/ipmi_bt_sm.c @@ -215,11 +215,11 @@ static int bt_start_transaction(struct si_sm_data *bt, return IPMI_NOT_IN_MY_STATE_ERR; if (bt_debug & BT_DEBUG_MSG) { - printk(KERN_WARNING "BT: +++++++++++++++++ New command\n"); - printk(KERN_WARNING "BT: NetFn/LUN CMD [%d data]:", size - 2); + pr_warn("BT: +++++++++++++++++ New command\n"); + pr_warn("BT: NetFn/LUN CMD [%d data]:", size - 2); for (i = 0; i < size; i ++) - printk(" %02x", data[i]); - printk("\n"); + pr_cont(" %02x", data[i]); + pr_cont("\n"); } bt->write_data[0] = size + 1; /* all data plus seq byte */ bt->write_data[1] = *data; /* NetFn/LUN */ @@ -260,10 +260,10 @@ static int bt_get_result(struct si_sm_data *bt, memcpy(data + 2, bt->read_data + 4, msg_len - 2); if (bt_debug & BT_DEBUG_MSG) { - printk(KERN_WARNING "BT: result %d bytes:", msg_len); + pr_warn("BT: result %d bytes:", msg_len); for (i = 0; i < msg_len; i++) - printk(" %02x", data[i]); - printk("\n"); + pr_cont(" %02x", data[i]); + pr_cont("\n"); } return msg_len; } @@ -274,8 +274,7 @@ static int bt_get_result(struct si_sm_data *bt, static void reset_flags(struct si_sm_data *bt) { if (bt_debug) - printk(KERN_WARNING "IPMI BT: flag reset %s\n", - status2txt(BT_STATUS)); + pr_warn("IPMI BT: flag reset %s\n", status2txt(BT_STATUS)); if (BT_STATUS & BT_H_BUSY) BT_CONTROL(BT_H_BUSY); /* force clear */ BT_CONTROL(BT_CLR_WR_PTR); /* always reset */ @@ -301,14 +300,13 @@ static void drain_BMC2HOST(struct si_sm_data *bt) BT_CONTROL(BT_B2H_ATN); /* some BMCs are stubborn */ BT_CONTROL(BT_CLR_RD_PTR); /* always reset */ if (bt_debug) - printk(KERN_WARNING "IPMI BT: stale response %s; ", - status2txt(BT_STATUS)); + pr_warn("IPMI BT: stale response %s; ", status2txt(BT_STATUS)); size = BMC2HOST; for (i = 0; i < size ; i++) BMC2HOST; BT_CONTROL(BT_H_BUSY); /* now clear */ if (bt_debug) - printk("drained %d bytes\n", size + 1); + pr_cont("drained %d bytes\n", size + 1); } static inline void write_all_bytes(struct si_sm_data *bt) @@ -316,11 +314,11 @@ static inline void write_all_bytes(struct si_sm_data *bt) int i; if (bt_debug & BT_DEBUG_MSG) { - printk(KERN_WARNING "BT: write %d bytes seq=0x%02X", + pr_warn("BT: write %d bytes seq=0x%02X", bt->write_count, bt->seq); for (i = 0; i < bt->write_count; i++) - printk(" %02x", bt->write_data[i]); - printk("\n"); + pr_cont(" %02x", bt->write_data[i]); + pr_cont("\n"); } for (i = 0; i < bt->write_count; i++) HOST2BMC(bt->write_data[i]); @@ -340,8 +338,7 @@ static inline int read_all_bytes(struct si_sm_data *bt) if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { if (bt_debug & BT_DEBUG_MSG) - printk(KERN_WARNING "BT: bad raw rsp len=%d\n", - bt->read_count); + pr_warn("BT: bad raw rsp len=%d\n", bt->read_count); bt->truncated = 1; return 1; /* let next XACTION START clean it up */ } @@ -352,13 +349,12 @@ static inline int read_all_bytes(struct si_sm_data *bt) if (bt_debug & BT_DEBUG_MSG) { int max = bt->read_count; - printk(KERN_WARNING "BT: got %d bytes seq=0x%02X", - max, bt->read_data[2]); + pr_warn("BT: got %d bytes seq=0x%02X", max, bt->read_data[2]); if (max > 16) max = 16; for (i = 0; i < max; i++) - printk(KERN_CONT " %02x", bt->read_data[i]); - printk(KERN_CONT "%s\n", bt->read_count == max ? "" : " ..."); + pr_cont(" %02x", bt->read_data[i]); + pr_cont("%s\n", bt->read_count == max ? "" : " ..."); } /* per the spec, the (NetFn[1], Seq[2], Cmd[3]) tuples must match */ @@ -368,10 +364,10 @@ static inline int read_all_bytes(struct si_sm_data *bt) return 1; if (bt_debug & BT_DEBUG_MSG) - printk(KERN_WARNING "IPMI BT: bad packet: " - "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", - bt->write_data[1] | 0x04, bt->write_data[2], bt->write_data[3], - bt->read_data[1], bt->read_data[2], bt->read_data[3]); + pr_warn("IPMI BT: bad packet: want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", + bt->write_data[1] | 0x04, bt->write_data[2], + bt->write_data[3], + bt->read_data[1], bt->read_data[2], bt->read_data[3]); return 0; } @@ -394,7 +390,7 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt, break; } - printk(KERN_WARNING "IPMI BT: %s in %s %s ", /* open-ended line */ + pr_warn("IPMI BT: %s in %s %s ", /* open-ended line */ reason, STATE2TXT, STATUS2TXT); /* @@ -403,20 +399,20 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt, */ (bt->error_retries)++; if (bt->error_retries < bt->BT_CAP_retries) { - printk("%d retries left\n", + pr_cont("%d retries left\n", bt->BT_CAP_retries - bt->error_retries); bt->state = BT_STATE_RESTART; return SI_SM_CALL_WITHOUT_DELAY; } - printk(KERN_WARNING "failed %d retries, sending error response\n", - bt->BT_CAP_retries); + pr_warn("failed %d retries, sending error response\n", + bt->BT_CAP_retries); if (!bt->nonzero_status) - printk(KERN_ERR "IPMI BT: stuck, try power cycle\n"); + pr_err("IPMI BT: stuck, try power cycle\n"); /* this is most likely during insmod */ else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) { - printk(KERN_WARNING "IPMI: BT reset (takes 5 secs)\n"); + pr_warn("IPMI: BT reset (takes 5 secs)\n"); bt->state = BT_STATE_RESET1; return SI_SM_CALL_WITHOUT_DELAY; } @@ -452,7 +448,7 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time) status = BT_STATUS; bt->nonzero_status |= status; if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) { - printk(KERN_WARNING "BT: %s %s TO=%ld - %ld \n", + pr_warn("BT: %s %s TO=%ld - %ld\n", STATE2TXT, STATUS2TXT, bt->timeout, diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c index 1a486aec99b6..effab11887ca 100644 --- a/drivers/char/ipmi/ipmi_devintf.c +++ b/drivers/char/ipmi/ipmi_devintf.c @@ -818,8 +818,7 @@ static void ipmi_new_smi(int if_num, struct device *device) entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (!entry) { - printk(KERN_ERR "ipmi_devintf: Unable to create the" - " ipmi class device link\n"); + pr_err("ipmi_devintf: Unable to create the ipmi class device link\n"); return; } entry->dev = dev; @@ -861,18 +860,18 @@ static int __init init_ipmi_devintf(void) if (ipmi_major < 0) return -EINVAL; - printk(KERN_INFO "ipmi device interface\n"); + pr_info("ipmi device interface\n"); ipmi_class = class_create(THIS_MODULE, "ipmi"); if (IS_ERR(ipmi_class)) { - printk(KERN_ERR "ipmi: can't register device class\n"); + pr_err("ipmi: can't register device class\n"); return PTR_ERR(ipmi_class); } rv = register_chrdev(ipmi_major, DEVICE_NAME, &ipmi_fops); if (rv < 0) { class_destroy(ipmi_class); - printk(KERN_ERR "ipmi: can't get major %d\n", ipmi_major); + pr_err("ipmi: can't get major %d\n", ipmi_major); return rv; } @@ -884,7 +883,7 @@ static int __init init_ipmi_devintf(void) if (rv) { unregister_chrdev(ipmi_major, DEVICE_NAME); class_destroy(ipmi_class); - printk(KERN_WARNING "ipmi: can't register smi watcher\n"); + pr_warn("ipmi: can't register smi watcher\n"); return rv; } diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c index f4ea9f47230a..2e7cda08b079 100644 --- a/drivers/char/ipmi/ipmi_kcs_sm.c +++ b/drivers/char/ipmi/ipmi_kcs_sm.c @@ -274,8 +274,8 @@ static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data, if (kcs_debug & KCS_DEBUG_MSG) { printk(KERN_DEBUG "start_kcs_transaction -"); for (i = 0; i < size; i++) - printk(" %02x", (unsigned char) (data [i])); - printk("\n"); + pr_cont(" %02x", data[i]); + pr_cont("\n"); } kcs->error_retries = 0; memcpy(kcs->write_data, data, size); diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c index 466a5aac5298..b6225bba2532 100644 --- a/drivers/char/ipmi/ipmi_smic_sm.c +++ b/drivers/char/ipmi/ipmi_smic_sm.c @@ -132,8 +132,8 @@ static int start_smic_transaction(struct si_sm_data *smic, if (smic_debug & SMIC_DEBUG_MSG) { printk(KERN_DEBUG "start_smic_transaction -"); for (i = 0; i < size; i++) - printk(" %02x", (unsigned char) data[i]); - printk("\n"); + pr_cont(" %02x", data[i]); + pr_cont("\n"); } smic->error_retries = 0; memcpy(smic->write_data, data, size); @@ -154,8 +154,8 @@ static int smic_get_result(struct si_sm_data *smic, if (smic_debug & SMIC_DEBUG_MSG) { printk(KERN_DEBUG "smic_get result -"); for (i = 0; i < smic->read_pos; i++) - printk(" %02x", smic->read_data[i]); - printk("\n"); + pr_cont(" %02x", smic->read_data[i]); + pr_cont("\n"); } if (length < smic->read_pos) { smic->read_pos = length; @@ -212,8 +212,7 @@ static inline void start_error_recovery(struct si_sm_data *smic, char *reason) (smic->error_retries)++; if (smic->error_retries > SMIC_MAX_ERROR_RETRIES) { if (smic_debug & SMIC_DEBUG_ENABLE) - printk(KERN_WARNING - "ipmi_smic_drv: smic hosed: %s\n", reason); + pr_warn("ipmi_smic_drv: smic hosed: %s\n", reason); smic->state = SMIC_HOSED; } else { smic->write_count = smic->orig_write_count; @@ -326,8 +325,7 @@ static enum si_sm_result smic_event(struct si_sm_data *smic, long time) if (smic->state != SMIC_IDLE) { if (smic_debug & SMIC_DEBUG_STATES) printk(KERN_DEBUG - "smic_event - smic->smic_timeout = %ld," - " time = %ld\n", + "smic_event - smic->smic_timeout = %ld, time = %ld\n", smic->smic_timeout, time); /* * FIXME: smic_event is sometimes called with time > @@ -347,9 +345,7 @@ static enum si_sm_result smic_event(struct si_sm_data *smic, long time) status = read_smic_status(smic); if (smic_debug & SMIC_DEBUG_STATES) - printk(KERN_DEBUG - "smic_event - state = %d, flags = 0x%02x," - " status = 0x%02x\n", + printk(KERN_DEBUG "smic_event - state = %d, flags = 0x%02x, status = 0x%02x\n", smic->state, flags, status); switch (smic->state) { @@ -440,8 +436,8 @@ static enum si_sm_result smic_event(struct si_sm_data *smic, long time) data = read_smic_data(smic); if (data != 0) { if (smic_debug & SMIC_DEBUG_ENABLE) - printk(KERN_DEBUG - "SMIC_WRITE_END: data = %02x\n", data); + printk(KERN_DEBUG "SMIC_WRITE_END: data = %02x\n", + data); start_error_recovery(smic, "state = SMIC_WRITE_END, " "data != SUCCESS"); @@ -520,8 +516,8 @@ static enum si_sm_result smic_event(struct si_sm_data *smic, long time) /* data register holds an error code */ if (data != 0) { if (smic_debug & SMIC_DEBUG_ENABLE) - printk(KERN_DEBUG - "SMIC_READ_END: data = %02x\n", data); + printk(KERN_DEBUG "SMIC_READ_END: data = %02x\n", + data); start_error_recovery(smic, "state = SMIC_READ_END, " "data != SUCCESS"); From 01508d9ebf4fc863f2fc4561c390bf4b7c3301a6 Mon Sep 17 00:00:00 2001 From: Meelis Roos Date: Wed, 6 Jun 2018 16:11:26 +0300 Subject: [PATCH 09/21] ipmi_si_pci: fix NULL device in ipmi_si error message I noticed that 4.17.0 logs the follwing during ipmi_si setup: ipmi_si 0000:01:04.6: probing via PCI (NULL device *): Could not setup I/O space ipmi_si 0000:01:04.6: [mem 0xf5ef0000-0xf5ef00ff] regsize 1 spacing 1 irq 21 Fix the "NULL device *) by moving io.dev assignment before its potential use by ipmi_pci_probe_regspacing(). Result: ipmi_si 0000:01:04.6: probing via PCI ipmi_si 0000:01:04.6: Could not setup I/O space ipmi_si 0000:01:04.6: [mem 0xf5ef0000-0xf5ef00ff] regsize 1 spacing 1 irq 21 Signed-off-by: Meelis Roos Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_si_pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/ipmi/ipmi_si_pci.c b/drivers/char/ipmi/ipmi_si_pci.c index 5eaa850ce455..ce00c0da5866 100644 --- a/drivers/char/ipmi/ipmi_si_pci.c +++ b/drivers/char/ipmi/ipmi_si_pci.c @@ -115,6 +115,8 @@ static int ipmi_pci_probe(struct pci_dev *pdev, } io.addr_data = pci_resource_start(pdev, 0); + io.dev = &pdev->dev; + io.regspacing = ipmi_pci_probe_regspacing(&io); io.regsize = DEFAULT_REGSIZE; io.regshift = 0; @@ -123,8 +125,6 @@ static int ipmi_pci_probe(struct pci_dev *pdev, if (io.irq) io.irq_setup = ipmi_std_irq_setup; - io.dev = &pdev->dev; - dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n", &pdev->resource[0], io.regsize, io.regspacing, io.irq); From 97a103e6b584442cd848887ed8d47be2410b7e09 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 5 Jun 2018 17:51:07 +0100 Subject: [PATCH 10/21] ipmi_si: fix potential integer overflow on large shift Shifting unsigned char b by an int type can lead to sign-extension overflow. For example, if b is 0xff and the shift is 24, then top bit is sign-extended so the final value passed to writeq has all the upper 32 bits set. Fix this by casting b to a 64 bit unsigned before the shift. Detected by CoverityScan, CID#1465246 ("Unintended sign extension") Signed-off-by: Colin Ian King Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_si_mem_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/ipmi/ipmi_si_mem_io.c b/drivers/char/ipmi/ipmi_si_mem_io.c index 1b869d530884..fd0ec8d6bf0e 100644 --- a/drivers/char/ipmi/ipmi_si_mem_io.c +++ b/drivers/char/ipmi/ipmi_si_mem_io.c @@ -51,7 +51,7 @@ static unsigned char mem_inq(const struct si_sm_io *io, unsigned int offset) static void mem_outq(const struct si_sm_io *io, unsigned int offset, unsigned char b) { - writeq(b << io->regshift, (io->addr)+(offset * io->regspacing)); + writeq((u64)b << io->regshift, (io->addr)+(offset * io->regspacing)); } #endif From dd3535b937c192941daa9b966caa707fa31c2c4d Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 18 Jun 2018 16:27:09 +0200 Subject: [PATCH 11/21] ipmi: Change to ktime_get_ts64() getnstimeofday64() is deprecated because of the inconsistent naming, it is only a wrapper around ktime_get_real_ts64() now, which could be used as a direct replacement. However, it is generally better to use CLOCK_MONOTONIC timestamps where possible, to avoid glitches with a concurrent settimeofday() or leap second. The uses in ipmi are either for debugging prints or for comparing against a prior timestamp, so using a monotonic ktime_get_ts64() is probably best here. Signed-off-by: Arnd Bergmann Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_si_intf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index 132bb508cd19..677618e6f1f7 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -269,7 +269,7 @@ void debug_timestamp(char *msg) { struct timespec64 t; - getnstimeofday64(&t); + ktime_get_ts64(&t); pr_debug("**%s: %lld.%9.9ld\n", msg, (long long) t.tv_sec, t.tv_nsec); } #else @@ -961,12 +961,12 @@ static inline int ipmi_thread_busy_wait(enum si_sm_result smi_result, if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY) ipmi_si_set_not_busy(busy_until); else if (!ipmi_si_is_busy(busy_until)) { - getnstimeofday64(busy_until); + ktime_get_ts64(busy_until); timespec64_add_ns(busy_until, max_busy_us*NSEC_PER_USEC); } else { struct timespec64 now; - getnstimeofday64(&now); + ktime_get_ts64(&now); if (unlikely(timespec64_compare(&now, busy_until) > 0)) { ipmi_si_set_not_busy(busy_until); return 0; From 9abcfaaa7c77e5884322b710dbf6c25905ce3376 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 21 Jun 2018 15:25:21 -0500 Subject: [PATCH 12/21] ipmi:dmi: Use pr_fmt in the IPMI DMI code It make things a little neater and saves some memory. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_dmi.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/char/ipmi/ipmi_dmi.c b/drivers/char/ipmi/ipmi_dmi.c index e2c143861b1e..736ebbbc2fcd 100644 --- a/drivers/char/ipmi/ipmi_dmi.c +++ b/drivers/char/ipmi/ipmi_dmi.c @@ -4,6 +4,9 @@ * allow autoloading of the IPMI drive based on SMBIOS entries. */ +#define pr_fmt(fmt) "%s" fmt, "ipmi:dmi: " +#define dev_fmt pr_fmt + #include #include #include @@ -71,7 +74,7 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, si_type = SI_SMIC; break; default: - pr_err("ipmi:dmi: Invalid IPMI type: %d\n", type); + pr_err("Invalid IPMI type: %d\n", type); return; } @@ -83,7 +86,7 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) { - pr_warn("ipmi:dmi: Could not allocate dmi info\n"); + pr_warn("Could not allocate dmi info\n"); } else { info->si_type = si_type; info->flags = flags; @@ -95,7 +98,7 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, pdev = platform_device_alloc(name, ipmi_dmi_nr); if (!pdev) { - pr_err("ipmi:dmi: Error allocation IPMI platform device\n"); + pr_err("Error allocation IPMI platform device\n"); return; } pdev->driver_override = kasprintf(GFP_KERNEL, "%s", @@ -141,22 +144,20 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, rv = platform_device_add_resources(pdev, r, num_r); if (rv) { - dev_err(&pdev->dev, - "ipmi:dmi: Unable to add resources: %d\n", rv); + dev_err(&pdev->dev, "Unable to add resources: %d\n", rv); goto err; } add_properties: rv = platform_device_add_properties(pdev, p); if (rv) { - dev_err(&pdev->dev, - "ipmi:dmi: Unable to add properties: %d\n", rv); + dev_err(&pdev->dev, "Unable to add properties: %d\n", rv); goto err; } rv = platform_device_add(pdev); if (rv) { - dev_err(&pdev->dev, "ipmi:dmi: Unable to add device: %d\n", rv); + dev_err(&pdev->dev, "Unable to add device: %d\n", rv); goto err; } @@ -263,7 +264,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm) offset = 16; break; default: - pr_err("ipmi:dmi: Invalid offset: 0\n"); + pr_err("Invalid offset: 0\n"); return; } } From 1574608f5f4204440d6d9f52b971aba967664764 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 21 Jun 2018 15:32:48 -0500 Subject: [PATCH 13/21] ipmi:dmi: Ignore IPMI SMBIOS entries with a zero base address Looking at logs from systems all over the place, it looks like tons of broken systems exist that set the base address to zero. I can only guess that is some sort of non-standard idea to mark the interface as not being present. It can't be zero, anyway, so just complain and ignore it. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_dmi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/ipmi/ipmi_dmi.c b/drivers/char/ipmi/ipmi_dmi.c index 736ebbbc2fcd..8e0c78696c70 100644 --- a/drivers/char/ipmi/ipmi_dmi.c +++ b/drivers/char/ipmi/ipmi_dmi.c @@ -218,6 +218,10 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm) slave_addr = data[DMI_IPMI_SLAVEADDR]; memcpy(&base_addr, data + DMI_IPMI_ADDR, sizeof(unsigned long)); + if (!base_addr) { + pr_err("Base address is zero, assuming no IPMI interface\n"); + return; + } if (len >= DMI_IPMI_VER2_LENGTH) { if (type == IPMI_DMI_TYPE_SSIF) { offset = 0; From e3dbc6d1d470e924529adf1e3e8e8447dc9b6977 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 23 Aug 2018 15:31:47 -0500 Subject: [PATCH 14/21] ipmi: Convert pr_xxx() to dev_xxx() in the BT code Cleanups, do the replacement and change the levels to the proper ones for the function they are serving, as many were wrong. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_bt_sm.c | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c index b4133832e075..f3f216cdf686 100644 --- a/drivers/char/ipmi/ipmi_bt_sm.c +++ b/drivers/char/ipmi/ipmi_bt_sm.c @@ -8,6 +8,8 @@ * Author: Rocky Craig */ +#define DEBUG /* So dev_dbg() is always available. */ + #include /* For printk. */ #include #include @@ -215,8 +217,8 @@ static int bt_start_transaction(struct si_sm_data *bt, return IPMI_NOT_IN_MY_STATE_ERR; if (bt_debug & BT_DEBUG_MSG) { - pr_warn("BT: +++++++++++++++++ New command\n"); - pr_warn("BT: NetFn/LUN CMD [%d data]:", size - 2); + dev_dbg(bt->io->dev, "+++++++++++++++++ New command\n"); + dev_dbg(bt->io->dev, "NetFn/LUN CMD [%d data]:", size - 2); for (i = 0; i < size; i ++) pr_cont(" %02x", data[i]); pr_cont("\n"); @@ -260,7 +262,7 @@ static int bt_get_result(struct si_sm_data *bt, memcpy(data + 2, bt->read_data + 4, msg_len - 2); if (bt_debug & BT_DEBUG_MSG) { - pr_warn("BT: result %d bytes:", msg_len); + dev_dbg(bt->io->dev, "result %d bytes:", msg_len); for (i = 0; i < msg_len; i++) pr_cont(" %02x", data[i]); pr_cont("\n"); @@ -274,7 +276,7 @@ static int bt_get_result(struct si_sm_data *bt, static void reset_flags(struct si_sm_data *bt) { if (bt_debug) - pr_warn("IPMI BT: flag reset %s\n", status2txt(BT_STATUS)); + dev_dbg(bt->io->dev, "flag reset %s\n", status2txt(BT_STATUS)); if (BT_STATUS & BT_H_BUSY) BT_CONTROL(BT_H_BUSY); /* force clear */ BT_CONTROL(BT_CLR_WR_PTR); /* always reset */ @@ -300,7 +302,8 @@ static void drain_BMC2HOST(struct si_sm_data *bt) BT_CONTROL(BT_B2H_ATN); /* some BMCs are stubborn */ BT_CONTROL(BT_CLR_RD_PTR); /* always reset */ if (bt_debug) - pr_warn("IPMI BT: stale response %s; ", status2txt(BT_STATUS)); + dev_dbg(bt->io->dev, "stale response %s; ", + status2txt(BT_STATUS)); size = BMC2HOST; for (i = 0; i < size ; i++) BMC2HOST; @@ -314,7 +317,7 @@ static inline void write_all_bytes(struct si_sm_data *bt) int i; if (bt_debug & BT_DEBUG_MSG) { - pr_warn("BT: write %d bytes seq=0x%02X", + dev_dbg(bt->io->dev, "write %d bytes seq=0x%02X", bt->write_count, bt->seq); for (i = 0; i < bt->write_count; i++) pr_cont(" %02x", bt->write_data[i]); @@ -338,7 +341,8 @@ static inline int read_all_bytes(struct si_sm_data *bt) if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { if (bt_debug & BT_DEBUG_MSG) - pr_warn("BT: bad raw rsp len=%d\n", bt->read_count); + dev_dbg(bt->io->dev, + "bad raw rsp len=%d\n", bt->read_count); bt->truncated = 1; return 1; /* let next XACTION START clean it up */ } @@ -349,7 +353,8 @@ static inline int read_all_bytes(struct si_sm_data *bt) if (bt_debug & BT_DEBUG_MSG) { int max = bt->read_count; - pr_warn("BT: got %d bytes seq=0x%02X", max, bt->read_data[2]); + dev_dbg(bt->io->dev, + "got %d bytes seq=0x%02X", max, bt->read_data[2]); if (max > 16) max = 16; for (i = 0; i < max; i++) @@ -364,7 +369,8 @@ static inline int read_all_bytes(struct si_sm_data *bt) return 1; if (bt_debug & BT_DEBUG_MSG) - pr_warn("IPMI BT: bad packet: want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", + dev_dbg(bt->io->dev, + "IPMI BT: bad packet: want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", bt->write_data[1] | 0x04, bt->write_data[2], bt->write_data[3], bt->read_data[1], bt->read_data[2], bt->read_data[3]); @@ -390,8 +396,8 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt, break; } - pr_warn("IPMI BT: %s in %s %s ", /* open-ended line */ - reason, STATE2TXT, STATUS2TXT); + dev_warn(bt->io->dev, "IPMI BT: %s in %s %s ", /* open-ended line */ + reason, STATE2TXT, STATUS2TXT); /* * Per the IPMI spec, retries are based on the sequence number @@ -405,14 +411,14 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt, return SI_SM_CALL_WITHOUT_DELAY; } - pr_warn("failed %d retries, sending error response\n", - bt->BT_CAP_retries); + dev_warn(bt->io->dev, "failed %d retries, sending error response\n", + bt->BT_CAP_retries); if (!bt->nonzero_status) - pr_err("IPMI BT: stuck, try power cycle\n"); + dev_err(bt->io->dev, "stuck, try power cycle\n"); /* this is most likely during insmod */ else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) { - pr_warn("IPMI: BT reset (takes 5 secs)\n"); + dev_warn(bt->io->dev, "BT reset (takes 5 secs)\n"); bt->state = BT_STATE_RESET1; return SI_SM_CALL_WITHOUT_DELAY; } @@ -448,7 +454,7 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time) status = BT_STATUS; bt->nonzero_status |= status; if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) { - pr_warn("BT: %s %s TO=%ld - %ld\n", + dev_dbg(bt->io->dev, "BT: %s %s TO=%ld - %ld\n", STATE2TXT, STATUS2TXT, bt->timeout, From 060e8fb53fe3455568982d10ab8c3dd605565049 Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Tue, 28 Aug 2018 07:07:36 +0000 Subject: [PATCH 15/21] ipmi: fix return value of ipmi_set_my_LUN Fixes gcc '-Wunused-but-set-variable' warning: drivers/char/ipmi/ipmi_msghandler.c: In function 'ipmi_set_my_LUN': drivers/char/ipmi/ipmi_msghandler.c:1335:13: warning: variable 'rv' set but not used [-Wunused-but-set-variable] int index, rv = 0; 'rv' should be the correct return value. Fixes: 048f7c3e352e ("ipmi: Properly release srcu locks on error conditions") Signed-off-by: YueHaibing Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_msghandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 04f64c55e275..a74ce885b541 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -1344,7 +1344,7 @@ int ipmi_set_my_LUN(struct ipmi_user *user, user->intf->addrinfo[channel].lun = LUN & 0x3; release_ipmi_user(user, index); - return 0; + return rv; } EXPORT_SYMBOL(ipmi_set_my_LUN); From c75c5075e5c6c686dde62058d3a95984d22cfb11 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 30 Aug 2018 13:14:59 -0500 Subject: [PATCH 16/21] ipmi: Don't leave holes in the I2C address list in the ssif driver The algorithm to populate the I2C address list would leave holes in the list on duplicates. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_ssif.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 61bc493765b9..09dcfdd66ed5 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -1739,7 +1739,7 @@ static void free_ssif_clients(void) static unsigned short *ssif_address_list(void) { struct ssif_addr_info *info; - unsigned int count = 0, i; + unsigned int count = 0, i = 0; unsigned short *address_list; list_for_each_entry(info, &ssif_infos, link) @@ -1750,18 +1750,17 @@ static unsigned short *ssif_address_list(void) if (!address_list) return NULL; - i = 0; list_for_each_entry(info, &ssif_infos, link) { unsigned short addr = info->binfo.addr; int j; for (j = 0; j < i; j++) { if (address_list[j] == addr) - goto skip_addr; + /* Found a dup. */ + break; } - address_list[i] = addr; -skip_addr: - i++; + if (j == i) /* Didn't find it in the list. */ + address_list[i++] = addr; } address_list[i] = I2C_CLIENT_END; From 36e398d7ab020dc6290cfeff2925d63b81362189 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 30 Aug 2018 13:18:32 -0500 Subject: [PATCH 17/21] ipmi: Free the address list on module cleanup Otherwise the memory is leaked. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_ssif.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 09dcfdd66ed5..1ba787b9de3e 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -1901,6 +1901,8 @@ static void cleanup_ipmi_ssif(void) i2c_del_driver(&ssif_i2c_driver); + kfree(ssif_i2c_driver.address_list); + platform_driver_unregister(&ipmi_driver); free_ssif_clients(); From b3096c70b3faf0b08d7d461f359eb4b0447dff8e Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 30 Aug 2018 14:36:09 -0500 Subject: [PATCH 18/21] ipmi: Remove platform driver overrides and use the id_table The IPMI DMI code was adding platform overrides, which is not really an ideal solution. Switch to using the id_table in the drivers to identify the devices. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_dmi.c | 8 +------- drivers/char/ipmi/ipmi_si_platform.c | 6 ++++++ drivers/char/ipmi/ipmi_ssif.c | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/char/ipmi/ipmi_dmi.c b/drivers/char/ipmi/ipmi_dmi.c index 8e0c78696c70..249880457b17 100644 --- a/drivers/char/ipmi/ipmi_dmi.c +++ b/drivers/char/ipmi/ipmi_dmi.c @@ -44,7 +44,7 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, unsigned int num_r = 1, size; struct property_entry p[5]; unsigned int pidx = 0; - char *name, *override; + char *name; int rv; enum si_type si_type; struct ipmi_dmi_info *info; @@ -52,11 +52,9 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, memset(p, 0, sizeof(p)); name = "dmi-ipmi-si"; - override = "ipmi_si"; switch (type) { case IPMI_DMI_TYPE_SSIF: name = "dmi-ipmi-ssif"; - override = "ipmi_ssif"; offset = 1; size = 1; si_type = SI_TYPE_INVALID; @@ -101,10 +99,6 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, pr_err("Error allocation IPMI platform device\n"); return; } - pdev->driver_override = kasprintf(GFP_KERNEL, "%s", - override); - if (!pdev->driver_override) - goto err; if (type == IPMI_DMI_TYPE_SSIF) { p[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", base_addr); diff --git a/drivers/char/ipmi/ipmi_si_platform.c b/drivers/char/ipmi/ipmi_si_platform.c index 999fba24e29c..15cf819f884f 100644 --- a/drivers/char/ipmi/ipmi_si_platform.c +++ b/drivers/char/ipmi/ipmi_si_platform.c @@ -419,6 +419,11 @@ static int ipmi_remove(struct platform_device *pdev) return ipmi_si_remove_by_dev(&pdev->dev); } +static const struct platform_device_id si_plat_ids[] = { + { "dmi-ipmi-si", 0 }, + { } +}; + struct platform_driver ipmi_platform_driver = { .driver = { .name = DEVICE_NAME, @@ -427,6 +432,7 @@ struct platform_driver ipmi_platform_driver = { }, .probe = ipmi_probe, .remove = ipmi_remove, + .id_table = si_plat_ids }; void ipmi_si_platform_init(void) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 1ba787b9de3e..764d305a264d 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -1844,12 +1844,18 @@ static int ssif_platform_remove(struct platform_device *dev) return 0; } +static const struct platform_device_id ssif_plat_ids[] = { + { "dmi-ipmi-ssif", 0 }, + { } +}; + static struct platform_driver ipmi_driver = { .driver = { .name = DEVICE_NAME, }, .probe = ssif_platform_probe, .remove = ssif_platform_remove, + .id_table = ssif_plat_ids }; static int init_ipmi_ssif(void) From bb9e2eed77a5c7c13ea31b9316776da4f757d150 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 22 Jun 2018 12:08:15 +0200 Subject: [PATCH 19/21] MAINTAINERS: Add file patterns for ipmi device tree bindings Submitters of device tree binding documentation may forget to CC the subsystem maintainer if this is missing. Signed-off-by: Geert Uytterhoeven Signed-off-by: Corey Minyard --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4ece30f15777..c8eaec6de0f2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7635,6 +7635,7 @@ M: Corey Minyard L: openipmi-developer@lists.sourceforge.net (moderated for non-subscribers) W: http://openipmi.sourceforge.net/ S: Supported +F: Documentation/devicetree/bindings/ipmi/ F: Documentation/IPMI.txt F: drivers/char/ipmi/ F: include/linux/ipmi* From 10042504ed92c06077b8a20a4edd67ba784847d4 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Fri, 27 Jul 2018 07:36:20 -0500 Subject: [PATCH 20/21] ipmi:ssif: Add support for multi-part transmit messages > 2 parts The spec was fairly confusing about how multi-part transmit messages worked, so the original implementation only added support for two part messages. But after talking about it with others and finding something I missed, I think it makes more sense. The spec mentions smbus command 8 in a table at the end of the section on SSIF support as the end transaction. If that works, then all is good and as it should be. However, some implementations seem to use a middle transaction <32 bytes tomark the end because of the confusion in the spec, even though that is an SMBus violation if the number of bytes is zero. So this change adds some tests, if command=8 works, it uses that, otherwise if an empty end transaction works, it uses a middle transaction <32 bytes to mark the end. If neither works, then it limits the size to 63 bytes as it is now. Cc: Harri Hakkarainen Cc: Bazhenov, Dmitry Cc: Mach, Dat Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_ssif.c | 209 ++++++++++++++++++++++++++-------- 1 file changed, 159 insertions(+), 50 deletions(-) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 764d305a264d..137b03892806 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -61,6 +61,7 @@ #define SSIF_IPMI_REQUEST 2 #define SSIF_IPMI_MULTI_PART_REQUEST_START 6 #define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7 +#define SSIF_IPMI_MULTI_PART_REQUEST_END 8 #define SSIF_IPMI_RESPONSE 3 #define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9 @@ -272,6 +273,7 @@ struct ssif_info { /* Info from SSIF cmd */ unsigned char max_xmit_msg_size; unsigned char max_recv_msg_size; + bool cmd8_works; /* See test_multipart_messages() for details. */ unsigned int multi_support; int supports_pec; @@ -885,32 +887,33 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result, * in the SSIF_MULTI_n_PART case in the probe function * for details on the intricacies of this. */ - int left; + int left, to_write; unsigned char *data_to_send; + unsigned char cmd; ssif_inc_stat(ssif_info, sent_messages_parts); left = ssif_info->multi_len - ssif_info->multi_pos; - if (left > 32) - left = 32; + to_write = left; + if (to_write > 32) + to_write = 32; /* Length byte. */ - ssif_info->multi_data[ssif_info->multi_pos] = left; + ssif_info->multi_data[ssif_info->multi_pos] = to_write; data_to_send = ssif_info->multi_data + ssif_info->multi_pos; - ssif_info->multi_pos += left; - if (left < 32) - /* - * Write is finished. Note that we must end - * with a write of less than 32 bytes to - * complete the transaction, even if it is - * zero bytes. - */ + ssif_info->multi_pos += to_write; + cmd = SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE; + if (ssif_info->cmd8_works) { + if (left == to_write) { + cmd = SSIF_IPMI_MULTI_PART_REQUEST_END; + ssif_info->multi_data = NULL; + } + } else if (to_write < 32) { ssif_info->multi_data = NULL; + } rv = ssif_i2c_send(ssif_info, msg_written_handler, - I2C_SMBUS_WRITE, - SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, - data_to_send, - I2C_SMBUS_BLOCK_DATA); + I2C_SMBUS_WRITE, cmd, + data_to_send, I2C_SMBUS_BLOCK_DATA); if (rv < 0) { /* request failed, just return the error. */ ssif_inc_stat(ssif_info, send_errors); @@ -1242,6 +1245,24 @@ static int ssif_remove(struct i2c_client *client) return 0; } +static int read_response(struct i2c_client *client, unsigned char *resp) +{ + int ret = -ENODEV, retry_cnt = SSIF_RECV_RETRIES; + + while (retry_cnt > 0) { + ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE, + resp); + if (ret > 0) + break; + msleep(SSIF_MSG_MSEC); + retry_cnt--; + if (retry_cnt <= 0) + break; + } + + return ret; +} + static int do_cmd(struct i2c_client *client, int len, unsigned char *msg, int *resp_len, unsigned char *resp) { @@ -1258,26 +1279,16 @@ static int do_cmd(struct i2c_client *client, int len, unsigned char *msg, return -ENODEV; } - ret = -ENODEV; - retry_cnt = SSIF_RECV_RETRIES; - while (retry_cnt > 0) { - ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE, - resp); - if (ret > 0) - break; - msleep(SSIF_MSG_MSEC); - retry_cnt--; - if (retry_cnt <= 0) - break; - } - + ret = read_response(client, resp); if (ret > 0) { /* Validate that the response is correct. */ if (ret < 3 || (resp[0] != (msg[0] | (1 << 2))) || (resp[1] != msg[1])) ret = -EINVAL; - else { + else if (ret > IPMI_MAX_MSG_LENGTH) { + ret = -E2BIG; + } else { *resp_len = ret; ret = 0; } @@ -1389,6 +1400,121 @@ static int find_slave_address(struct i2c_client *client, int slave_addr) return slave_addr; } +static int start_multipart_test(struct i2c_client *client, + unsigned char *msg, bool do_middle) +{ + int retry_cnt = SSIF_SEND_RETRIES, ret; + +retry_write: + ret = i2c_smbus_write_block_data(client, + SSIF_IPMI_MULTI_PART_REQUEST_START, + 32, msg); + if (ret) { + retry_cnt--; + if (retry_cnt > 0) + goto retry_write; + dev_err(&client->dev, "Could not write multi-part start, though the BMC said it could handle it. Just limit sends to one part.\n"); + return ret; + } + + if (!do_middle) + return 0; + + ret = i2c_smbus_write_block_data(client, + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, + 32, msg + 32); + if (ret) { + dev_err(&client->dev, "Could not write multi-part middle, though the BMC said it could handle it. Just limit sends to one part.\n"); + return ret; + } + + return 0; +} + +static void test_multipart_messages(struct i2c_client *client, + struct ssif_info *ssif_info, + unsigned char *resp) +{ + unsigned char msg[65]; + int ret; + bool do_middle; + + if (ssif_info->max_xmit_msg_size <= 32) + return; + + do_middle = ssif_info->max_xmit_msg_size > 63; + + memset(msg, 0, sizeof(msg)); + msg[0] = IPMI_NETFN_APP_REQUEST << 2; + msg[1] = IPMI_GET_DEVICE_ID_CMD; + + /* + * The specification is all messed up dealing with sending + * multi-part messages. Per what the specification says, it + * is impossible to send a message that is a multiple of 32 + * bytes, except for 32 itself. It talks about a "start" + * transaction (cmd=6) that must be 32 bytes, "middle" + * transaction (cmd=7) that must be 32 bytes, and an "end" + * transaction. The "end" transaction is shown as cmd=7 in + * the text, but if that's the case there is no way to + * differentiate between a middle and end part except the + * length being less than 32. But there is a table at the far + * end of the section (that I had never noticed until someone + * pointed it out to me) that mentions it as cmd=8. + * + * After some thought, I think the example is wrong and the + * end transaction should be cmd=8. But some systems don't + * implement cmd=8, they use a zero-length end transaction, + * even though that violates the SMBus specification. + * + * So, to work around this, this code tests if cmd=8 works. + * If it does, then we use that. If not, it tests zero- + * byte end transactions. If that works, good. If not, + * we only allow 63-byte transactions max. + */ + + ret = start_multipart_test(client, msg, do_middle); + if (ret) + goto out_no_multi_part; + + ret = i2c_smbus_write_block_data(client, + SSIF_IPMI_MULTI_PART_REQUEST_END, + 1, msg + 64); + + if (!ret) + ret = read_response(client, resp); + + if (ret > 0) { + /* End transactions work, we are good. */ + ssif_info->cmd8_works = true; + return; + } + + ret = start_multipart_test(client, msg, do_middle); + if (ret) { + dev_err(&client->dev, "Second multipart test failed.\n"); + goto out_no_multi_part; + } + + ret = i2c_smbus_write_block_data(client, + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, + 0, msg + 64); + if (!ret) + ret = read_response(client, resp); + if (ret > 0) + /* Zero-size end parts work, use those. */ + return; + + /* Limit to 63 bytes and use a short middle command to mark the end. */ + if (ssif_info->max_xmit_msg_size > 63) + ssif_info->max_xmit_msg_size = 63; + return; + +out_no_multi_part: + ssif_info->max_xmit_msg_size = 32; + return; +} + /* * Global enables we care about. */ @@ -1475,26 +1601,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) break; case SSIF_MULTI_n_PART: - /* - * The specification is rather confusing at - * this point, but I think I understand what - * is meant. At least I have a workable - * solution. With multi-part messages, you - * cannot send a message that is a multiple of - * 32-bytes in length, because the start and - * middle messages are 32-bytes and the end - * message must be at least one byte. You - * can't fudge on an extra byte, that would - * screw up things like fru data writes. So - * we limit the length to 63 bytes. That way - * a 32-byte message gets sent as a single - * part. A larger message will be a 32-byte - * start and the next message is always going - * to be 1-31 bytes in length. Not ideal, but - * it should work. - */ - if (ssif_info->max_xmit_msg_size > 63) - ssif_info->max_xmit_msg_size = 63; + /* We take whatever size given, but do some testing. */ break; default: @@ -1513,6 +1620,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) ssif_info->supports_pec = 0; } + test_multipart_messages(client, ssif_info, resp); + /* Make sure the NMI timeout is cleared. */ msg[0] = IPMI_NETFN_APP_REQUEST << 2; msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; From 0711e8c1b4572d076264e71b0002d223f2666ed7 Mon Sep 17 00:00:00 2001 From: Jan Glauber Date: Thu, 11 Oct 2018 12:13:01 +0200 Subject: [PATCH 21/21] ipmi: Fix timer race with module unload Please note that below oops is from an older kernel, but the same race seems to be present in the upstream kernel too. ---8<--- The following panic was encountered during removing the ipmi_ssif module: [ 526.352555] Unable to handle kernel paging request at virtual address ffff000006923090 [ 526.360464] Mem abort info: [ 526.363257] ESR = 0x86000007 [ 526.366304] Exception class = IABT (current EL), IL = 32 bits [ 526.372221] SET = 0, FnV = 0 [ 526.375269] EA = 0, S1PTW = 0 [ 526.378405] swapper pgtable: 4k pages, 48-bit VAs, pgd = 000000008ae60416 [ 526.385185] [ffff000006923090] *pgd=000000bffcffe803, *pud=000000bffcffd803, *pmd=0000009f4731a003, *pte=0000000000000000 [ 526.396141] Internal error: Oops: 86000007 [#1] SMP [ 526.401008] Modules linked in: nls_iso8859_1 ipmi_devintf joydev input_leds ipmi_msghandler shpchp sch_fq_codel ib_iser rdma_cm iw_cm ib_cm ib_core iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi ip_tables x_tables autofs4 btrfs zstd_compress raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq libcrc32c raid1 raid0 multipath linear i2c_smbus hid_generic usbhid uas hid usb_storage ast aes_ce_blk i2c_algo_bit aes_ce_cipher qede ttm crc32_ce ptp crct10dif_ce drm_kms_helper ghash_ce syscopyarea sha2_ce sysfillrect sysimgblt pps_core fb_sys_fops sha256_arm64 sha1_ce mpt3sas qed drm raid_class ahci scsi_transport_sas libahci gpio_xlp i2c_xlp9xx aes_neon_bs aes_neon_blk crypto_simd cryptd aes_arm64 [last unloaded: ipmi_ssif] [ 526.468085] CPU: 125 PID: 0 Comm: swapper/125 Not tainted 4.15.0-35-generic #38~lp1775396+build.1 [ 526.476942] Hardware name: To be filled by O.E.M. Saber/Saber, BIOS 0ACKL022 08/14/2018 [ 526.484932] pstate: 00400009 (nzcv daif +PAN -UAO) [ 526.489713] pc : 0xffff000006923090 [ 526.493198] lr : call_timer_fn+0x34/0x178 [ 526.497194] sp : ffff000009b0bdd0 [ 526.500496] x29: ffff000009b0bdd0 x28: 0000000000000082 [ 526.505796] x27: 0000000000000002 x26: ffff000009515188 [ 526.511096] x25: ffff000009515180 x24: ffff0000090f1018 [ 526.516396] x23: ffff000009519660 x22: dead000000000200 [ 526.521696] x21: ffff000006923090 x20: 0000000000000100 [ 526.526995] x19: ffff809eeb466a40 x18: 0000000000000000 [ 526.532295] x17: 000000000000000e x16: 0000000000000007 [ 526.537594] x15: 0000000000000000 x14: 071c71c71c71c71c [ 526.542894] x13: 0000000000000000 x12: 0000000000000000 [ 526.548193] x11: 0000000000000001 x10: ffff000009b0be88 [ 526.553493] x9 : 0000000000000000 x8 : 0000000000000005 [ 526.558793] x7 : ffff80befc1f8528 x6 : 0000000000000020 [ 526.564092] x5 : 0000000000000040 x4 : 0000000020001b20 [ 526.569392] x3 : 0000000000000000 x2 : ffff809eeb466a40 [ 526.574692] x1 : ffff000006923090 x0 : ffff809eeb466a40 [ 526.579992] Process swapper/125 (pid: 0, stack limit = 0x000000002eb50acc) [ 526.586854] Call trace: [ 526.589289] 0xffff000006923090 [ 526.592419] expire_timers+0xc8/0x130 [ 526.596070] run_timer_softirq+0xec/0x1b0 [ 526.600070] __do_softirq+0x134/0x328 [ 526.603726] irq_exit+0xc8/0xe0 [ 526.606857] __handle_domain_irq+0x6c/0xc0 [ 526.610941] gic_handle_irq+0x84/0x188 [ 526.614679] el1_irq+0xe8/0x180 [ 526.617822] cpuidle_enter_state+0xa0/0x328 [ 526.621993] cpuidle_enter+0x34/0x48 [ 526.625564] call_cpuidle+0x44/0x70 [ 526.629040] do_idle+0x1b8/0x1f0 [ 526.632256] cpu_startup_entry+0x2c/0x30 [ 526.636174] secondary_start_kernel+0x11c/0x130 [ 526.640694] Code: bad PC value [ 526.643800] ---[ end trace d020b0b8417c2498 ]--- [ 526.648404] Kernel panic - not syncing: Fatal exception in interrupt [ 526.654778] SMP: stopping secondary CPUs [ 526.658734] Kernel Offset: disabled [ 526.662211] CPU features: 0x5800c38 [ 526.665688] Memory Limit: none [ 526.668768] ---[ end Kernel panic - not syncing: Fatal exception in interrupt Prevent mod_timer from arming a timer that was already removed by del_timer during module unload. Signed-off-by: Jan Glauber Cc: # 3.19 Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_ssif.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 137b03892806..ca9528c4f183 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -608,8 +608,9 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, flags = ipmi_ssif_lock_cond(ssif_info, &oflags); ssif_info->waiting_alert = true; ssif_info->rtc_us_timer = SSIF_MSG_USEC; - mod_timer(&ssif_info->retry_timer, - jiffies + SSIF_MSG_JIFFIES); + if (!ssif_info->stopping) + mod_timer(&ssif_info->retry_timer, + jiffies + SSIF_MSG_JIFFIES); ipmi_ssif_unlock_cond(ssif_info, flags); return; } @@ -940,8 +941,9 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result, ssif_info->waiting_alert = true; ssif_info->retries_left = SSIF_RECV_RETRIES; ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC; - mod_timer(&ssif_info->retry_timer, - jiffies + SSIF_MSG_PART_JIFFIES); + if (!ssif_info->stopping) + mod_timer(&ssif_info->retry_timer, + jiffies + SSIF_MSG_PART_JIFFIES); ipmi_ssif_unlock_cond(ssif_info, flags); } }