aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-10-22 18:30:04 -0400
committerKees Cook <keescook@chromium.org>2017-11-01 14:27:08 -0400
commitc251a7be46b0ee64d02b321081e24ea51fae2cfe (patch)
tree4e740714f59d9e2de54fe08bd874d73504dcc3b3
parentf22eb4d31c21ac2be001fa7bcd079e2d7d02a8f1 (diff)
scsi: megaraid: Convert timers to use timer_setup()
In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Also consolidates the timer setup functions arguments, which are all identical, and corrects on-stack timer usage. Cc: Kashyap Desai <kashyap.desai@broadcom.com> Cc: Sumit Saxena <sumit.saxena@broadcom.com> Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com> Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com> Cc: "Martin K. Petersen" <martin.petersen@oracle.com> Cc: megaraidlinux.pdl@broadcom.com Cc: linux-scsi@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/megaraid/megaraid_ioctl.h6
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c26
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c27
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c35
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c15
5 files changed, 47 insertions, 62 deletions
diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h b/drivers/scsi/megaraid/megaraid_ioctl.h
index 05f6e4ec3453..eedcbde46459 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -19,6 +19,7 @@
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/semaphore.h> 21#include <linux/semaphore.h>
22#include <linux/timer.h>
22 23
23#include "mbox_defs.h" 24#include "mbox_defs.h"
24 25
@@ -153,6 +154,11 @@ typedef struct uioc {
153 154
154} __attribute__ ((aligned(1024),packed)) uioc_t; 155} __attribute__ ((aligned(1024),packed)) uioc_t;
155 156
157/* For on-stack uioc timers. */
158struct uioc_timeout {
159 struct timer_list timer;
160 uioc_t *uioc;
161};
156 162
157/** 163/**
158 * struct mraid_hba_info - information about the controller 164 * struct mraid_hba_info - information about the controller
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index ec3c43854978..530358cdcb39 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -3904,19 +3904,19 @@ megaraid_sysfs_get_ldmap_done(uioc_t *uioc)
3904 wake_up(&raid_dev->sysfs_wait_q); 3904 wake_up(&raid_dev->sysfs_wait_q);
3905} 3905}
3906 3906
3907
3908/** 3907/**
3909 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap 3908 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3910 * @data : timed out packet 3909 * @t : timed out timer
3911 * 3910 *
3912 * Timeout routine to recover and return to application, in case the adapter 3911 * Timeout routine to recover and return to application, in case the adapter
3913 * has stopped responding. A timeout of 60 seconds for this command seems like 3912 * has stopped responding. A timeout of 60 seconds for this command seems like
3914 * a good value. 3913 * a good value.
3915 */ 3914 */
3916static void 3915static void
3917megaraid_sysfs_get_ldmap_timeout(unsigned long data) 3916megaraid_sysfs_get_ldmap_timeout(struct timer_list *t)
3918{ 3917{
3919 uioc_t *uioc = (uioc_t *)data; 3918 struct uioc_timeout *timeout = from_timer(timeout, t, timer);
3919 uioc_t *uioc = timeout->uioc;
3920 adapter_t *adapter = (adapter_t *)uioc->buf_vaddr; 3920 adapter_t *adapter = (adapter_t *)uioc->buf_vaddr;
3921 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter); 3921 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter);
3922 3922
@@ -3951,8 +3951,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)
3951 mbox64_t *mbox64; 3951 mbox64_t *mbox64;
3952 mbox_t *mbox; 3952 mbox_t *mbox;
3953 char *raw_mbox; 3953 char *raw_mbox;
3954 struct timer_list sysfs_timer; 3954 struct uioc_timeout timeout;
3955 struct timer_list *timerp;
3956 caddr_t ldmap; 3955 caddr_t ldmap;
3957 int rval = 0; 3956 int rval = 0;
3958 3957
@@ -3988,14 +3987,12 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)
3988 /* 3987 /*
3989 * Setup a timer to recover from a non-responding controller 3988 * Setup a timer to recover from a non-responding controller
3990 */ 3989 */
3991 timerp = &sysfs_timer; 3990 timeout.uioc = uioc;
3992 init_timer(timerp); 3991 timer_setup_on_stack(&timeout.timer,
3993 3992 megaraid_sysfs_get_ldmap_timeout, 0);
3994 timerp->function = megaraid_sysfs_get_ldmap_timeout;
3995 timerp->data = (unsigned long)uioc;
3996 timerp->expires = jiffies + 60 * HZ;
3997 3993
3998 add_timer(timerp); 3994 timeout.timer.expires = jiffies + 60 * HZ;
3995 add_timer(&timeout.timer);
3999 3996
4000 /* 3997 /*
4001 * Send the command to the firmware 3998 * Send the command to the firmware
@@ -4033,7 +4030,8 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)
4033 } 4030 }
4034 4031
4035 4032
4036 del_timer_sync(timerp); 4033 del_timer_sync(&timeout.timer);
4034 destroy_timer_on_stack(&timeout.timer);
4037 4035
4038 mutex_unlock(&raid_dev->sysfs_mtx); 4036 mutex_unlock(&raid_dev->sysfs_mtx);
4039 4037
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index 65b6f6ace3a5..bb802b0c12b8 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -35,7 +35,7 @@ static int kioc_to_mimd(uioc_t *, mimd_t __user *);
35static int handle_drvrcmd(void __user *, uint8_t, int *); 35static int handle_drvrcmd(void __user *, uint8_t, int *);
36static int lld_ioctl(mraid_mmadp_t *, uioc_t *); 36static int lld_ioctl(mraid_mmadp_t *, uioc_t *);
37static void ioctl_done(uioc_t *); 37static void ioctl_done(uioc_t *);
38static void lld_timedout(unsigned long); 38static void lld_timedout(struct timer_list *);
39static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *); 39static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *);
40static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *); 40static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *);
41static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *); 41static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *);
@@ -686,8 +686,7 @@ static int
686lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) 686lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
687{ 687{
688 int rval; 688 int rval;
689 struct timer_list timer; 689 struct uioc_timeout timeout = { };
690 struct timer_list *tp = NULL;
691 690
692 kioc->status = -ENODATA; 691 kioc->status = -ENODATA;
693 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE); 692 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE);
@@ -698,14 +697,12 @@ lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
698 * Start the timer 697 * Start the timer
699 */ 698 */
700 if (adp->timeout > 0) { 699 if (adp->timeout > 0) {
701 tp = &timer; 700 timeout.uioc = kioc;
702 init_timer(tp); 701 timer_setup_on_stack(&timeout.timer, lld_timedout, 0);
703 702
704 tp->function = lld_timedout; 703 timeout.timer.expires = jiffies + adp->timeout * HZ;
705 tp->data = (unsigned long)kioc;
706 tp->expires = jiffies + adp->timeout * HZ;
707 704
708 add_timer(tp); 705 add_timer(&timeout.timer);
709 } 706 }
710 707
711 /* 708 /*
@@ -713,8 +710,9 @@ lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
713 * call, the ioctl either completed successfully or timedout. 710 * call, the ioctl either completed successfully or timedout.
714 */ 711 */
715 wait_event(wait_q, (kioc->status != -ENODATA)); 712 wait_event(wait_q, (kioc->status != -ENODATA));
716 if (tp) { 713 if (timeout.timer.function) {
717 del_timer_sync(tp); 714 del_timer_sync(&timeout.timer);
715 destroy_timer_on_stack(&timeout.timer);
718 } 716 }
719 717
720 /* 718 /*
@@ -783,12 +781,13 @@ ioctl_done(uioc_t *kioc)
783 781
784/** 782/**
785 * lld_timedout - callback from the expired timer 783 * lld_timedout - callback from the expired timer
786 * @ptr : ioctl packet that timed out 784 * @t : timer that timed out
787 */ 785 */
788static void 786static void
789lld_timedout(unsigned long ptr) 787lld_timedout(struct timer_list *t)
790{ 788{
791 uioc_t *kioc = (uioc_t *)ptr; 789 struct uioc_timeout *timeout = from_timer(timeout, t, timer);
790 uioc_t *kioc = timeout->uioc;
792 791
793 kioc->status = -ETIME; 792 kioc->status = -ETIME;
794 kioc->timedout = 1; 793 kioc->timedout = 1;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index e518dadc8161..a36e18156e49 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2114,22 +2114,19 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr)
2114 megasas_check_and_restore_queue_depth(instance); 2114 megasas_check_and_restore_queue_depth(instance);
2115} 2115}
2116 2116
2117static void megasas_sriov_heartbeat_handler(struct timer_list *t);
2118
2117/** 2119/**
2118 * megasas_start_timer - Initializes a timer object 2120 * megasas_start_timer - Initializes sriov heartbeat timer object
2119 * @instance: Adapter soft state 2121 * @instance: Adapter soft state
2120 * @timer: timer object to be initialized
2121 * @fn: timer function
2122 * @interval: time interval between timer function call
2123 * 2122 *
2124 */ 2123 */
2125void megasas_start_timer(struct megasas_instance *instance, 2124void megasas_start_timer(struct megasas_instance *instance)
2126 struct timer_list *timer, 2125{
2127 void *fn, unsigned long interval) 2126 struct timer_list *timer = &instance->sriov_heartbeat_timer;
2128{ 2127
2129 init_timer(timer); 2128 timer_setup(timer, megasas_sriov_heartbeat_handler, 0);
2130 timer->expires = jiffies + interval; 2129 timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF;
2131 timer->data = (unsigned long)instance;
2132 timer->function = fn;
2133 add_timer(timer); 2130 add_timer(timer);
2134} 2131}
2135 2132
@@ -2515,10 +2512,10 @@ out:
2515} 2512}
2516 2513
2517/* Handler for SR-IOV heartbeat */ 2514/* Handler for SR-IOV heartbeat */
2518void megasas_sriov_heartbeat_handler(unsigned long instance_addr) 2515static void megasas_sriov_heartbeat_handler(struct timer_list *t)
2519{ 2516{
2520 struct megasas_instance *instance = 2517 struct megasas_instance *instance =
2521 (struct megasas_instance *)instance_addr; 2518 from_timer(instance, t, sriov_heartbeat_timer);
2522 2519
2523 if (instance->hb_host_mem->HB.fwCounter != 2520 if (instance->hb_host_mem->HB.fwCounter !=
2524 instance->hb_host_mem->HB.driverCounter) { 2521 instance->hb_host_mem->HB.driverCounter) {
@@ -5493,10 +5490,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
5493 /* Launch SR-IOV heartbeat timer */ 5490 /* Launch SR-IOV heartbeat timer */
5494 if (instance->requestorId) { 5491 if (instance->requestorId) {
5495 if (!megasas_sriov_start_heartbeat(instance, 1)) 5492 if (!megasas_sriov_start_heartbeat(instance, 1))
5496 megasas_start_timer(instance, 5493 megasas_start_timer(instance);
5497 &instance->sriov_heartbeat_timer,
5498 megasas_sriov_heartbeat_handler,
5499 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
5500 else 5494 else
5501 instance->skip_heartbeat_timer_del = 1; 5495 instance->skip_heartbeat_timer_del = 1;
5502 } 5496 }
@@ -6507,10 +6501,7 @@ megasas_resume(struct pci_dev *pdev)
6507 /* Re-launch SR-IOV heartbeat timer */ 6501 /* Re-launch SR-IOV heartbeat timer */
6508 if (instance->requestorId) { 6502 if (instance->requestorId) {
6509 if (!megasas_sriov_start_heartbeat(instance, 0)) 6503 if (!megasas_sriov_start_heartbeat(instance, 0))
6510 megasas_start_timer(instance, 6504 megasas_start_timer(instance);
6511 &instance->sriov_heartbeat_timer,
6512 megasas_sriov_heartbeat_handler,
6513 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
6514 else { 6505 else {
6515 instance->skip_heartbeat_timer_del = 1; 6506 instance->skip_heartbeat_timer_del = 1;
6516 goto fail_init_mfi; 6507 goto fail_init_mfi;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 11bd2e698b84..3c399e7b3fe1 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -85,12 +85,9 @@ int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
85void megaraid_sas_kill_hba(struct megasas_instance *instance); 85void megaraid_sas_kill_hba(struct megasas_instance *instance);
86 86
87extern u32 megasas_dbg_lvl; 87extern u32 megasas_dbg_lvl;
88void megasas_sriov_heartbeat_handler(unsigned long instance_addr);
89int megasas_sriov_start_heartbeat(struct megasas_instance *instance, 88int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
90 int initial); 89 int initial);
91void megasas_start_timer(struct megasas_instance *instance, 90void megasas_start_timer(struct megasas_instance *instance);
92 struct timer_list *timer,
93 void *fn, unsigned long interval);
94extern struct megasas_mgmt_info megasas_mgmt_info; 91extern struct megasas_mgmt_info megasas_mgmt_info;
95extern unsigned int resetwaittime; 92extern unsigned int resetwaittime;
96extern unsigned int dual_qdepth_disable; 93extern unsigned int dual_qdepth_disable;
@@ -4369,10 +4366,7 @@ transition_to_ready:
4369 /* Restart SR-IOV heartbeat */ 4366 /* Restart SR-IOV heartbeat */
4370 if (instance->requestorId) { 4367 if (instance->requestorId) {
4371 if (!megasas_sriov_start_heartbeat(instance, 0)) 4368 if (!megasas_sriov_start_heartbeat(instance, 0))
4372 megasas_start_timer(instance, 4369 megasas_start_timer(instance);
4373 &instance->sriov_heartbeat_timer,
4374 megasas_sriov_heartbeat_handler,
4375 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
4376 else 4370 else
4377 instance->skip_heartbeat_timer_del = 1; 4371 instance->skip_heartbeat_timer_del = 1;
4378 } 4372 }
@@ -4404,10 +4398,7 @@ fail_kill_adapter:
4404 } else { 4398 } else {
4405 /* For VF: Restart HB timer if we didn't OCR */ 4399 /* For VF: Restart HB timer if we didn't OCR */
4406 if (instance->requestorId) { 4400 if (instance->requestorId) {
4407 megasas_start_timer(instance, 4401 megasas_start_timer(instance);
4408 &instance->sriov_heartbeat_timer,
4409 megasas_sriov_heartbeat_handler,
4410 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
4411 } 4402 }
4412 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); 4403 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4413 instance->instancet->enable_intr(instance); 4404 instance->instancet->enable_intr(instance);