From patchwork Fri Nov 10 15:40:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118583 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp8081946qgn; Fri, 10 Nov 2017 07:40:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMaaPcsT/g5qy/KT+1uVJtLGwwuMWhQl4M4rvNAfGVjIXYkhavV8syt7WZtCcJd0DJyf+/UH X-Received: by 10.99.185.18 with SMTP id z18mr757540pge.212.1510328447619; Fri, 10 Nov 2017 07:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510328447; cv=none; d=google.com; s=arc-20160816; b=XxjG5qMV2iO6Y24OrcKhg68klha6S6USGVeChKBQyI6odOUTVFMzhBKBM4mAVHjVXS 7b0LQVQxVIHzwaq5cj/gNmL02whNAuj1rudg2T7eDpULIZKA1+S/W4IWSbyOv7g30au1 x2rMHtR6mjCW/e3IK5ZJK+QXGLC8mj8si4foLMzPEct9piZk1oZ//cS7+/+yo7xTMbID /qAJ1CuTxyTdIp8RTXhUd+QYncOzLyf4h3WyWl86SyPgGjw8AYw966Q9Ty3wQvbdtD6H ggTEsznzH1hRTjYbB+Nce+P5dwIIHzJ8qeHCN47IgYkP/2lmEyuEoElkdTEZaIZJ5I3M 82hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1j83HkQ2YK6c0uZrDJ1/WwANof5acPjtfiMIftQiH/M=; b=Sz8Rv9q9Cni6S2wCg7KAAgRXE+GIfKBdydXOZesJGbcSs6rMf3JF6RhzXyUermjVdC fw4MnPSfrGWKUfcgzvi+LeXSzWRq3+vaSMUzPkS9aw2dWzSOIVhY7WbLZRQWBVyygQLz oxM/LfJRl5Hst5WRFm8xRyHEMkg5Kpb2cATWWkWbhAl03mzr8AQs0ydMPzej8lwuqQv9 H23h5+YGJLBlDWmrZU/CbfSzyq98D94kv97Dbzl/kU2YyPurAR0AZ7KpOOsVXlKwXxbL KTnK3NJzaaQx8nMxcE/O/Q+JL+u3dVoS5KbYwgEAlO9UrlaPUv3KwVkAesyilsLaPNH2 21jA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h123si8780445pgc.605.2017.11.10.07.40.47; Fri, 10 Nov 2017 07:40:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300AbdKJPkp (ORCPT + 23 others); Fri, 10 Nov 2017 10:40:45 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:58423 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751142AbdKJPkn (ORCPT ); Fri, 10 Nov 2017 10:40:43 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0Mfpbg-1eY2Bn3rAi-00NAF7; Fri, 10 Nov 2017 16:40:24 +0100 From: Arnd Bergmann To: Adaptec OEM Raid Solutions , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: ips: fix firmware timestamps for 32-bit Date: Fri, 10 Nov 2017 16:40:10 +0100 Message-Id: <20171110154022.1933558-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:GuCezZJyrl/wn5G7OQwDQ1xHV3sOe/frGraA9rjMSxiwdV78oep Ut3tSGbbPV03S0Mutfdf3vnXNowgOpF7e0cl1LrrvM81Q6eNO9sb5ITxAXzDIolxvOM4SK0 z9QubWNswHw8nML/diaajRjHOi/HyWVkebxlv/VpdQl+FgG232ThQy1Jl8ai3FYLpV2J+QE QZRfFoIFa5Vb2zFQevSbQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:nkIbauhWTuU=:dNltWwiTagQ1ZGKRGp8hbg ZXswe8QAFh3bMb02enEer0Lnj7AAcBTacfiK2U0js8FceTf+Nd/GR6pWyTn/Clv9oUiQXFyA0 opLGX1gYSpE3A1hoahW9NdG+iy7Q5NmKaKNrfaHqi1jB2DE0Zq/F4EZc6riwV2wUr1Fr8wOqe tcAbzi9lTwkKteDm7ERtn7gId02A109H07aQ2hlGc898TGpK6XGAtxLVpSSMrNjl+c5YaTlY8 lHw5z5GyyWxJrRMJ1pCk/bgPQgc/NY1uRY5bzwF+2W55OiUtvopqBnFh3OEzBHtUHhdOAOqgI kHjgR618GsJe/4cXxolwOwkfxL3CROKIJkLv9lKMjmzmMthjxWF3KDNd863h761GZjRYqp40r 76HFcGtcIwGRZ+DGZ1XuWnD1Uj6McvGIa0wf0aSH3VcjLxMWNCIm9RGhIwuvXyxqoqgamOGaR BISI3WkWMkFC9TN3Yxuac/SXtHMqhqi8GdjP4Zwi1s995a9wx6SQDEBg2qCL3sB0rU2hqu4Ea ug796BjwL+2R5fqVs2vXboHORzdmjnpeApk1sWPXBeP+LSkjM2fS0MjobhME1QIvBnebJ0cwe 6TtRJgLtP2k3AdoElTmoFOOP2Lvq/VcmI9De2wZ+iWGYuwGQybO1FLqIXpxpplEMSZmBd9GfE q/ubfBwT3nT15y/LEx8Uoz5JFi4EnRZKuFh0z/6cBuwYiyd73RRXa+mNaWs6/8rSUPNF+qKXB kx1E3LrPiJa4nET+2CCmK+1zOjJlSFF43IoctQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org do_gettimeofday() is deprecated since it will stop working in 2038 on 32-bit platforms. The firmware interface here actually supports times until year 25500, so we should use longer timestamps. Using ktime_get_real_seconds() to get a 64-bit seconds value and time64_to_tm() to convert it into the right format also has the advantage of greatly simplifying the time management code. Signed-off-by: Arnd Bergmann --- drivers/scsi/ips.c | 78 +++++++++++------------------------------------------- drivers/scsi/ips.h | 2 +- 2 files changed, 17 insertions(+), 63 deletions(-) -- 2.9.0 diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c index 67621308eb9c..887843a465e1 100644 --- a/drivers/scsi/ips.c +++ b/drivers/scsi/ips.c @@ -293,7 +293,7 @@ static void ips_freescb(ips_ha_t *, ips_scb_t *); static void ips_setup_funclist(ips_ha_t *); static void ips_statinit(ips_ha_t *); static void ips_statinit_memio(ips_ha_t *); -static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t); +static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time64_t); static void ips_ffdc_reset(ips_ha_t *, int); static void ips_ffdc_time(ips_ha_t *); static uint32_t ips_statupd_copperhead(ips_ha_t *); @@ -989,10 +989,7 @@ static int __ips_eh_reset(struct scsi_cmnd *SC) /* FFDC */ if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) { - struct timeval tv; - - do_gettimeofday(&tv); - ha->last_ffdc = tv.tv_sec; + ha->last_ffdc = ktime_get_real_seconds(); ha->reset_count++; ips_ffdc_reset(ha, IPS_INTR_IORL); } @@ -2396,7 +2393,6 @@ static int ips_hainit(ips_ha_t * ha) { int i; - struct timeval tv; METHOD_TRACE("ips_hainit", 1); @@ -2411,8 +2407,7 @@ ips_hainit(ips_ha_t * ha) /* Send FFDC */ ha->reset_count = 1; - do_gettimeofday(&tv); - ha->last_ffdc = tv.tv_sec; + ha->last_ffdc = ktime_get_real_seconds(); ips_ffdc_reset(ha, IPS_INTR_IORL); if (!ips_read_config(ha, IPS_INTR_IORL)) { @@ -2552,12 +2547,9 @@ ips_next(ips_ha_t * ha, int intr) if ((ha->subsys->param[3] & 0x300000) && (ha->scb_activelist.count == 0)) { - struct timeval tv; - - do_gettimeofday(&tv); - - if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) { - ha->last_ffdc = tv.tv_sec; + time64_t now = ktime_get_real_seconds(); + if (now - ha->last_ffdc > IPS_SECS_8HOURS) { + ha->last_ffdc = now; ips_ffdc_time(ha); } } @@ -5992,59 +5984,21 @@ ips_ffdc_time(ips_ha_t * ha) /* */ /****************************************************************************/ static void -ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time) +ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time64_t current_time) { - long days; - long rem; - int i; - int year; - int yleap; - int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR }; - int month_lengths[12][2] = { {31, 31}, - {28, 29}, - {31, 31}, - {30, 30}, - {31, 31}, - {30, 30}, - {31, 31}, - {31, 31}, - {30, 30}, - {31, 31}, - {30, 30}, - {31, 31} - }; + struct tm tm; METHOD_TRACE("ips_fix_ffdc_time", 1); - days = current_time / IPS_SECS_DAY; - rem = current_time % IPS_SECS_DAY; - - scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR); - rem = rem % IPS_SECS_HOUR; - scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN); - scb->cmd.ffdc.second = (rem % IPS_SECS_MIN); - - year = IPS_EPOCH_YEAR; - while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) { - int newy; - - newy = year + (days / IPS_DAYS_NORMAL_YEAR); - if (days < 0) - --newy; - days -= (newy - year) * IPS_DAYS_NORMAL_YEAR + - IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) - - IPS_NUM_LEAP_YEARS_THROUGH(year - 1); - year = newy; - } - - scb->cmd.ffdc.yearH = year / 100; - scb->cmd.ffdc.yearL = year % 100; - - for (i = 0; days >= month_lengths[i][yleap]; ++i) - days -= month_lengths[i][yleap]; + time64_to_tm(current_time, 0, &tm); - scb->cmd.ffdc.month = i + 1; - scb->cmd.ffdc.day = days + 1; + scb->cmd.ffdc.hour = tm.tm_hour; + scb->cmd.ffdc.minute = tm.tm_min; + scb->cmd.ffdc.second = tm.tm_sec; + scb->cmd.ffdc.yearH = tm.tm_year / 100 + 1900; + scb->cmd.ffdc.yearL = tm.tm_year % 100; + scb->cmd.ffdc.month = tm.tm_mon + 1; + scb->cmd.ffdc.day = tm.tm_mday; } /**************************************************************************** diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h index 366be3b2f9b4..b43a1ae75660 100644 --- a/drivers/scsi/ips.h +++ b/drivers/scsi/ips.h @@ -1054,7 +1054,7 @@ typedef struct ips_ha { uint8_t active; int ioctl_reset; /* IOCTL Requested Reset Flag */ uint16_t reset_count; /* number of resets */ - time_t last_ffdc; /* last time we sent ffdc info*/ + time64_t last_ffdc; /* last time we sent ffdc info*/ uint8_t slot_num; /* PCI Slot Number */ int ioctl_len; /* size of ioctl buffer */ dma_addr_t ioctl_busaddr; /* dma address of ioctl buffer*/