From patchwork Wed Jan 17 14:57:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10169429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F56C603ED for ; Wed, 17 Jan 2018 14:58:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4DB8283C8 for ; Wed, 17 Jan 2018 14:58:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8B5E28590; Wed, 17 Jan 2018 14:58:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C9E8283C8 for ; Wed, 17 Jan 2018 14:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753368AbeAQO6c (ORCPT ); Wed, 17 Jan 2018 09:58:32 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:59062 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753142AbeAQO6b (ORCPT ); Wed, 17 Jan 2018 09:58:31 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lj7Eo-1f7JhC1vFG-00dIDz; Wed, 17 Jan 2018 15:57:56 +0100 From: Arnd Bergmann To: Adaptec OEM Raid Solutions , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Rasmus Villemoes , Yang Hongyang , Hannes Reinecke , Finn Thain , Mike Christie , Christoph Hellwig , Arnd Bergmann , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [RESEND] scsi: ips: fix firmware timestamps for 32-bit Date: Wed, 17 Jan 2018 15:57:36 +0100 Message-Id: <20180117145749.2712957-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:fXkyKjdPGZKZflywBQ8M7+d8Q5zXn1fgUDKAmQT6rWwr+/w79jc 61ZgNjRUmwQBywSpTO1p8V3sTIPit9ycncz77eOTOkFZbgXgur+uHaS+X437XXWeaFdjNp2 I6KkVRALby/3QQa1FZcUe9GrrdKhfJ3q6Grc25wleuQUMKtd2yzfO5zN0n9eQKESpjznBL4 VC9Q3EaD93BabVlWxCMtg== X-UI-Out-Filterresults: notjunk:1; V01:K0:KvPhmVWOcng=:mRKwtRQoftNNS0uh08YNwd t13wx3RX0PwhfWS62w+gvxt2Hl2BE65JLWTWlh5hZfyrdZIzLCBD2gJXUtN0rHuIYfgcUOkce p/ik6xm/CLeO5cLzZZPpkUQ7QHvgYpudw+7R8tzWwIMfg+iIlXCYAKvVxkRyJh7lycvzQQRWn rL6+0b839exlI5E3pg891WgiXxxOxndNnFJK32UtGLsoyzbFY6uVe3Sys7qHI/djR5VAfzDQp F6OJMv94v/iA+yiqqL/GNDbOZ57KZVVCENRoUiG8EXNgxb4mXBY/othmzIpPeNktDZVb91D2l 57WWyao3vV/1V9s/j22d15AGvx/ufzp8YrNGDILh7hbm6q+nxaAqNVLFuxN+r3PvTJZZDjJPK xkmG1tZjj6ImPjYm3CgqiUp9B1Qq/zhrgrtPYl3jf/U/aigh3JUYpImHz9QdR98IOMON/iC4p oJ6aZMbcxuQrrP3g6p5mVHNrwSDb7X4fGxIRKQ7ppKvbuRYYzSAwWfsc4YwTrkKy5U4SSvsZ/ fVW5KcMQ0GlGmqiLtsQmHSI+gQ/ZIDD0KbrQb96OckYDZ+KITINw9l6afz02CNZDzGzbPXY1S UtzS53/6IR5eX/iV9MRqE9mSBuZcEzo7EtfTw2lVqUf+MDVV3HMcB7Tz8nKvynz22GvAammKG a53i95EoXNTSwewNhaqFM0iU/ZphhSruzIb6AO8u8gDkREnaeYm8Rrk/wZkmfF6pFNhyEEQjE a3ckrBzwgQJ4M8thQw280N8gu+qBLKjk3XesDQ== Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Submitted originally in November 2017. The aacraid@adaptec.com apparently bounced. Trying again now with a few people on Cc that previously reviewed patches to this driver. --- drivers/scsi/ips.c | 78 +++++++++++------------------------------------------- drivers/scsi/ips.h | 2 +- 2 files changed, 17 insertions(+), 63 deletions(-) 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*/