From patchwork Thu Jun 9 02:24:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 581390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE7AAC43334 for ; Thu, 9 Jun 2022 02:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236692AbiFICZE (ORCPT ); Wed, 8 Jun 2022 22:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbiFICZD (ORCPT ); Wed, 8 Jun 2022 22:25:03 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1701F132748 for ; Wed, 8 Jun 2022 19:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654741502; x=1686277502; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=B6RxOZNJHpIgyDZa6jg9+HlCsfHX6UqUtcLq+JIMyT0=; b=eipuxLi/kK5pCqHjqK2we6cCnOrNSQBcLAGaarjB+hbAcz+nBpK5czJ+ Yn+Xqlln/wHJvmrerRRgAMv51ygNz1Yp/z7NUKfEEbx16j79ylgmnIvZk 7BfxZYWdaEQBrbSoobIQHU68vlBHcmfpgul/kZBsROGWLMWMupB49fU6H fiW/P35/gMYwdVl2Vl6/Jxe8FXaApOqwAb9DXtw5rg9OSmfns2eIIKxUD dVUMLTBIPbd2Kl8uv4L73mEB5qYlA4PUv87Wze7A32/C2l8A+AWlQwiRz /ZSHig0SOZ4zXszAhZoZ0w3xhKukNRQepm8ynnNZCOC/3h+eKvQObP/yb g==; X-IronPort-AV: E=Sophos;i="5.91,287,1647273600"; d="scan'208";a="314703266" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jun 2022 10:25:00 +0800 IronPort-SDR: 5Q4Aiy6kaqr/uJ87BBW8T0Breh6qKxJn4+DKyJ9glySX9NGDbBAwC+8i2KHrwNg1mbaw5t7woM NLBjv18BKJCof1Kcx++msaKgAsIQbohoGe0AWczUYJqqG12tZD3db+lHUuX5GPH+cmXZc49yWY /ptONrUGpCoX47eO73uxYOHvX0BIoIt6tjxNn2R6WX/QRPKX85Ekzj5fj24paWRP98hCAf9P7j 3FrSMGoVDcctz++6clWBjr3fprRGZ3NnmuFRIJAMtTtC2uvhIQIYu1SAHbFlU+iYx7VZWoxdhs 433rcebnwg1K4QZWzfd+9rGu Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 18:43:48 -0700 IronPort-SDR: Jyz48sjwwZp7asMfi2oUUc9JtSI4na3eo1Twj/+OO/J6Qata2G5pPDzc7kcdkIrZo3k1nXH6wA tQXEoEtbMrfATLBYeA1rLkJlf78FcVG/NxygKTCVp1qSoJP8IcGUVT0bRt8+jk9x91offWgVky GdIIonGiFcPmzI3VPCL9IalhLiY3T0OldK3ngigjZa7XJutMl2xCXqrBw7B6O2RqLX6HtnfYXV eQ6vxfNV73u20SCNXUq0UhGYYklN5Wbz9zYRvrZzGfLA9MDn3CbBlec5i40wtATC7ZXaUElwXg +T4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 19:25:00 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LJSbw1CBCz1Rwrw for ; Wed, 8 Jun 2022 19:25:00 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1654741499; x=1657333500; bh=B6RxOZN JHpIgyDZa6jg9+HlCsfHX6UqUtcLq+JIMyT0=; b=JkEOeytooNO/ieMlQOxW0Ab BOg15X3Sz0kLPW68ZZJPMuPUCvoQWZsziRdbRIAplhYt+0gFTzSEg2VrHxJzLUHO kJUrGl3NgDIZQLrBRRKcvlfiWzRI9IzKCDCAHBkRgKPKPb7+SvVfOV3PKCQm32sN 2ozTRq+EqdhI9WzeTOX8Q40/KXY5AGZGLS4IswwfT5YOHEE2aS9l8fgbTKT3nOcO KeXfQAFNj2w7ka2rG6gs4gnr9et80xbGXfiN5etFPIYJViG1VlGeQLVaOtyPViK/ dOv5L75eM/lj/4ewy0va+s9sB8pUOh5whaxjlTFerF8gbC33MQMhhZuXxR9+kCA= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UM0ezZJW7Yzb for ; Wed, 8 Jun 2022 19:24:59 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LJSbv0Tvcz1Rvlx; Wed, 8 Jun 2022 19:24:58 -0700 (PDT) From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry Subject: [PATCH 1/3] scsi: libsas: introduce struct smp_disc_resp Date: Thu, 9 Jun 2022 11:24:54 +0900 Message-Id: <20220609022456.409087-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> References: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When compiling with gcc 12, several warnings are thrown by gcc when compiling drivers/scsi/libsas/sas_expander.c, e.g.: In function ‘sas_get_phy_change_count’, inlined from ‘sas_find_bcast_phy.constprop’ at drivers/scsi/libsas/sas_expander.c:1737:9: drivers/scsi/libsas/sas_expander.c:1697:39: warning: array subscript ‘struct smp_resp[0]’ is partly outside array bounds of ‘unsigned char[56]’ [-Warray-bounds] 1697 | *pcc = disc_resp->disc.change_count; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~ This is due to the use of the struct smp_resp to aggregate all possible response types using a union but allocating a response buffer with a size exactly equal to the size of the response type needed. This leads to access to fields of struct smp_resp from an allocated memory area that is smaller than the size of struct smp_resp. Fix this by defining struct smp_disc_resp for sas discovery operations. Since this structure and the generic struct smp_resp are identical for the little endian and big endian archs, move the definition of these structures at the end of include/scsi/sas.h to avoid repeating their definition. Signed-off-by: Damien Le Moal --- drivers/scsi/libsas/sas_expander.c | 32 +++++++++++++----------------- include/scsi/sas.h | 28 +++++++++++--------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 260e735d06fa..fb998a8a7d3b 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -175,13 +175,13 @@ static enum sas_device_type to_dev_type(struct discover_resp *dr) return dr->attached_dev_type; } -static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp) +static void sas_set_ex_phy(struct domain_device *dev, int phy_id, + struct smp_disc_resp *disc_resp) { enum sas_device_type dev_type; enum sas_linkrate linkrate; u8 sas_addr[SAS_ADDR_SIZE]; - struct smp_resp *resp = rsp; - struct discover_resp *dr = &resp->disc; + struct discover_resp *dr = &disc_resp->disc; struct sas_ha_struct *ha = dev->port->ha; struct expander_device *ex = &dev->ex_dev; struct ex_phy *phy = &ex->ex_phy[phy_id]; @@ -198,7 +198,7 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp) BUG_ON(!phy->phy); } - switch (resp->result) { + switch (disc_resp->result) { case SMP_RESP_PHY_VACANT: phy->phy_state = PHY_VACANT; break; @@ -347,12 +347,13 @@ struct domain_device *sas_ex_to_ata(struct domain_device *ex_dev, int phy_id) } #define DISCOVER_REQ_SIZE 16 -#define DISCOVER_RESP_SIZE 56 +#define DISCOVER_RESP_SIZE sizeof(struct smp_disc_resp) static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req, - u8 *disc_resp, int single) + struct smp_disc_resp *disc_resp, + int single) { - struct discover_resp *dr; + struct discover_resp *dr = &disc_resp->disc; int res; disc_req[9] = single; @@ -361,7 +362,6 @@ static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req, disc_resp, DISCOVER_RESP_SIZE); if (res) return res; - dr = &((struct smp_resp *)disc_resp)->disc; if (memcmp(dev->sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE) == 0) { pr_notice("Found loopback topology, just ignore it!\n"); return 0; @@ -375,7 +375,7 @@ int sas_ex_phy_discover(struct domain_device *dev, int single) struct expander_device *ex = &dev->ex_dev; int res = 0; u8 *disc_req; - u8 *disc_resp; + struct smp_disc_resp *disc_resp; disc_req = alloc_smp_req(DISCOVER_REQ_SIZE); if (!disc_req) @@ -1657,7 +1657,7 @@ int sas_discover_root_expander(struct domain_device *dev) /* ---------- Domain revalidation ---------- */ static int sas_get_phy_discover(struct domain_device *dev, - int phy_id, struct smp_resp *disc_resp) + int phy_id, struct smp_disc_resp *disc_resp) { int res; u8 *disc_req; @@ -1673,10 +1673,8 @@ static int sas_get_phy_discover(struct domain_device *dev, disc_resp, DISCOVER_RESP_SIZE); if (res) goto out; - else if (disc_resp->result != SMP_RESP_FUNC_ACC) { + if (disc_resp->result != SMP_RESP_FUNC_ACC) res = disc_resp->result; - goto out; - } out: kfree(disc_req); return res; @@ -1686,7 +1684,7 @@ static int sas_get_phy_change_count(struct domain_device *dev, int phy_id, int *pcc) { int res; - struct smp_resp *disc_resp; + struct smp_disc_resp *disc_resp; disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE); if (!disc_resp) @@ -1704,19 +1702,17 @@ static int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id, u8 *sas_addr, enum sas_device_type *type) { int res; - struct smp_resp *disc_resp; - struct discover_resp *dr; + struct smp_disc_resp *disc_resp; disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE); if (!disc_resp) return -ENOMEM; - dr = &disc_resp->disc; res = sas_get_phy_discover(dev, phy_id, disc_resp); if (res == 0) { memcpy(sas_addr, disc_resp->disc.attached_sas_addr, SAS_ADDR_SIZE); - *type = to_dev_type(dr); + *type = to_dev_type(&disc_resp->disc); if (*type == 0) memset(sas_addr, 0, SAS_ADDR_SIZE); } diff --git a/include/scsi/sas.h b/include/scsi/sas.h index acfc69fd72d0..b3ee9bd63277 100644 --- a/include/scsi/sas.h +++ b/include/scsi/sas.h @@ -471,18 +471,6 @@ struct report_phy_sata_resp { __be32 crc; } __attribute__ ((packed)); -struct smp_resp { - u8 frame_type; - u8 function; - u8 result; - u8 reserved; - union { - struct report_general_resp rg; - struct discover_resp disc; - struct report_phy_sata_resp rps; - }; -} __attribute__ ((packed)); - #elif defined(__BIG_ENDIAN_BITFIELD) struct sas_identify_frame { /* Byte 0 */ @@ -704,6 +692,18 @@ struct report_phy_sata_resp { __be32 crc; } __attribute__ ((packed)); +#else +#error "Bitfield order not defined!" +#endif + +struct smp_disc_resp { + u8 frame_type; + u8 function; + u8 result; + u8 reserved; + struct discover_resp disc; +} __attribute__ ((packed)); + struct smp_resp { u8 frame_type; u8 function; @@ -716,8 +716,4 @@ struct smp_resp { }; } __attribute__ ((packed)); -#else -#error "Bitfield order not defined!" -#endif - #endif /* _SAS_H_ */ From patchwork Thu Jun 9 02:24:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 580554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39DC3C433EF for ; Thu, 9 Jun 2022 02:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236698AbiFICZH (ORCPT ); Wed, 8 Jun 2022 22:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231775AbiFICZD (ORCPT ); Wed, 8 Jun 2022 22:25:03 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639EC172C23 for ; Wed, 8 Jun 2022 19:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654741502; x=1686277502; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=e/BNs8n1k0NTyuVT86TYgovEtWjZrcs5wJJYRUSQWu4=; b=j9Kq1ewtpSe/beZeMlaIvCOJhs19EJJvEWsJK7u+EZfdPEBlQQ1B+WyO HYQmv9XfSnxsQykPDxh8BevGXA3A38m+S5jHWj2Si/4JcBhckHkV8ChrZ TU9tkIShTL2prGiTNTaaXOdrPm1lNwP39EpckKpE2kcdS4QVDSGnC37kS yx2xfL6RszKccdM5ur0kku5r9cj2Sp0cB+xOSgCYwwqDbd5pkQyqAvkJi K2yJHyYaWC/4h6my9L9x/AvXyQ9xonVNtBM65qGQ4FDXhX/KmHDx2GbSC gg2/bPs4+4+S+/2LTWZiOB4+LHx8tn+3qqsa0mc2/eIJU1J+k8fhLARy7 Q==; X-IronPort-AV: E=Sophos;i="5.91,287,1647273600"; d="scan'208";a="314703269" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jun 2022 10:25:01 +0800 IronPort-SDR: QTS0aBcT1BTJfSkwt0QBnXJbrDbrW2U7OMILKK6HabjYyzt5tDql1pD8cEU6knvifum85AWYrg cAftNynLwTMKM5AJxWFD1ZUsQ1pwx01gKYstz3UrRCZTYNEKqf4d473xfJxDpys149lDJNdbgC DI854RAwkyyyVPTjI7PtJJPUqMrd9Gk9nbTJl/C+1MOBr5AD/rfxCHaf5ypBL1O3lilH2DFzbQ 16F9tRR7srvEuW98kn4+CmN7e9RVfg/zUB++VVovkWV9hhnHVfuuCp+f4uOP1kd4JF464CWWem BRmllnFZtKCg3Tvj1Bxypu1V Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 18:43:50 -0700 IronPort-SDR: s6AEbd4aMgSNwmxQ7MRjcitGhESgxIOyZ6NqUoTom1ZkSQFTS3cHR1xJQuHPYF2aCIi+zH2iHD IXhK5l/wLGUnO76nqvj7V9ALDs7YuSjwXfmPsaDVe4AI17wvd/UofqeoEKekexqWqasu+5nULa b6JIsiwwBONPk2mRnv4LbKRCnOq7gQCtmXRRJBr30Ct9O9eLwrT9bUIKGTnLw96EWawrcsk6W7 ZV6vRKqE6dB9sIXYEySxeYmyYKvhj/QbYBqO17N+NQmvKix9dDIVX6B1IjuZSFK1eLT+0ccM/M 83I= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 19:25:01 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LJSbx30DTz1Rwrw for ; Wed, 8 Jun 2022 19:25:01 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1654741500; x=1657333501; bh=e/BNs8n 1k0NTyuVT86TYgovEtWjZrcs5wJJYRUSQWu4=; b=doptkXtPqxvAdr65biUsbSU axhXduJiRNVrj2UczmLx0RK9UajiHTkVs9r24xRMLmsABlzROpjyGGgqYp1cJULE K6mpSwOLufLhUwv5b/yIv3lLIUIuc1ltCsU54ZyJcR0np7wHdJ1UWWaW8RHu0Wqo wpQiYh/sqXVoLwXs4N/b2INto2qmkQzVHWvfTOmcOJoa5HxVMD9yY107JJkN3ht/ 1mlM+KlpNyAdRH9XPY8kcr6mEypQX4UKSCe7FK6HYRfdPQEqodv5k9jhkb4Bagk3 fSq0RYVub2+K2MtBqxcbrd8gBuTr2Ga8mxEBQcfsLTk3fyuTAOzOgdLEuX67avA= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id MJHjuQTbEIjy for ; Wed, 8 Jun 2022 19:25:00 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LJSbv6cRpz1Rvlc; Wed, 8 Jun 2022 19:24:59 -0700 (PDT) From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry Subject: [PATCH 2/3] scsi: libsas: introduce struct smp_rg_resp Date: Thu, 9 Jun 2022 11:24:55 +0900 Message-Id: <20220609022456.409087-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> References: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When compiling with gcc 12, several warnings are thrown by gcc when compiling drivers/scsi/libsas/sas_expander.c, e.g.: In function ‘sas_get_ex_change_count’, inlined from ‘sas_find_bcast_dev’ at drivers/scsi/libsas/sas_expander.c:1816:8: drivers/scsi/libsas/sas_expander.c:1781:20: warning: array subscript ‘struct smp_resp[0]’ is partly outside array bounds of ‘unsigned char[32]’ [-Warray-bounds] 1781 | if (rg_resp->result != SMP_RESP_FUNC_ACC) { | ~~~~~~~^~~~~~~~ This is due to the use of the struct smp_resp to aggregate all possible response types using a union but allocating a response buffer with a size exactly equal to the size of the response type needed. This leads to access to fields of struct smp_resp from an allocated memory area that is smaller than the size of struct smp_resp. Fix this by defining struct smp_rg_resp for sas report general responses. Signed-off-by: Damien Le Moal --- drivers/scsi/libsas/sas_expander.c | 31 +++++++++++++----------------- include/scsi/sas.h | 8 ++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index fb998a8a7d3b..78a38980636e 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -429,27 +429,14 @@ static int sas_expander_discover(struct domain_device *dev) #define MAX_EXPANDER_PHYS 128 -static void ex_assign_report_general(struct domain_device *dev, - struct smp_resp *resp) -{ - struct report_general_resp *rg = &resp->rg; - - dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count); - dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes); - dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS); - dev->ex_dev.t2t_supp = rg->t2t_supp; - dev->ex_dev.conf_route_table = rg->conf_route_table; - dev->ex_dev.configuring = rg->configuring; - memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8); -} - #define RG_REQ_SIZE 8 -#define RG_RESP_SIZE 32 +#define RG_RESP_SIZE sizeof(struct smp_rg_resp) static int sas_ex_general(struct domain_device *dev) { u8 *rg_req; - struct smp_resp *rg_resp; + struct smp_rg_resp *rg_resp; + struct report_general_resp *rg; int res; int i; @@ -480,7 +467,15 @@ static int sas_ex_general(struct domain_device *dev) goto out; } - ex_assign_report_general(dev, rg_resp); + rg = &rg_resp->rg; + dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count); + dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes); + dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS); + dev->ex_dev.t2t_supp = rg->t2t_supp; + dev->ex_dev.conf_route_table = rg->conf_route_table; + dev->ex_dev.configuring = rg->configuring; + memcpy(dev->ex_dev.enclosure_logical_id, + rg->enclosure_logical_id, 8); if (dev->ex_dev.configuring) { pr_debug("RG: ex %016llx self-configuring...\n", @@ -1756,7 +1751,7 @@ static int sas_get_ex_change_count(struct domain_device *dev, int *ecc) { int res; u8 *rg_req; - struct smp_resp *rg_resp; + struct smp_rg_resp *rg_resp; rg_req = alloc_smp_req(RG_REQ_SIZE); if (!rg_req) diff --git a/include/scsi/sas.h b/include/scsi/sas.h index b3ee9bd63277..a8f9743ed6fc 100644 --- a/include/scsi/sas.h +++ b/include/scsi/sas.h @@ -696,6 +696,14 @@ struct report_phy_sata_resp { #error "Bitfield order not defined!" #endif +struct smp_rg_resp { + u8 frame_type; + u8 function; + u8 result; + u8 reserved; + struct report_general_resp rg; +} __attribute__ ((packed)); + struct smp_disc_resp { u8 frame_type; u8 function; From patchwork Thu Jun 9 02:24:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 581389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0985BC43334 for ; Thu, 9 Jun 2022 02:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236703AbiFICZJ (ORCPT ); Wed, 8 Jun 2022 22:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236634AbiFICZD (ORCPT ); Wed, 8 Jun 2022 22:25:03 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2044F1D81B7 for ; Wed, 8 Jun 2022 19:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654741503; x=1686277503; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0JQQvXQ5K3VvZl36WY/dYo6dIIQ+Ya7q+dJvDPmd6Kc=; b=aIT1uaZNPhbiNaZAOcmVOHK/7J83+bD+UJpsrj+aWEzzQ6s22zJ+/7gI 78yIx3eQ6aLhxkCgC6eTVWB5cvqtpW56Elln2081+zIdKiAeOZEn7ZZAy neRO2hUF+sf/tPUKvJOXWmyDLcO/2R05C4AoCCyuqAzUCa90CyfFYU3oo BC9aut49aGEef38T6ZmZ5a+IPzLC16p27sP0RL1hc2kkSvIkixCZf9AqI Rd1OsnXfXpihQsX0+SskEiV+9olkYBKDg6XYOOl+7h7HQp1Bd1G5s0AN0 d6bN2HUhPSs24gGP7y9i5MWrdLj1qxwQ//zv6SRceDTr5ECzdMEYyqFMT g==; X-IronPort-AV: E=Sophos;i="5.91,287,1647273600"; d="scan'208";a="314703271" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jun 2022 10:25:02 +0800 IronPort-SDR: Fue2kXVPy/TnJQAGQcB1sDbj9XMGA8MbCuIXx+GXnw1nA6rdicX3vhb+T0WjuE0MqrkIHFC7dT hi4Roigo4gDd8HtwZJXKjsPV4/KPYJFa5Nl+rBXBO014vGPeQ5tYsZwJuW1xjbljOsZ9AQoxU4 MsZfef3Jk+xS8MeR1Ic5w7rOmlPbRDecQlxt5LyKj/vVkC1owmu+51mLHYmVP9g6uRvfc89lSo cP1ciMbBd0843ImL6q6Yegk3UHztr7E/H7khFcnDUBXdJ3yg2t1hYOn86oguzHnnE+uNKlc5I2 Butr2nMCIbZBvCE2B9Ga/uCT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 18:43:51 -0700 IronPort-SDR: 1DmiNJa7aZGeKEJsjvqhBgSHvGQvlbKZKEDP/WepTWG9ARyIjFRfoAQFVbrDcCCggwSIRNo9jw V/rWWfB8RrRus3iZbXa0rM1l/+P5xAqV5u+y6ES46Y0dRAojRoghoVdhl6I2Bpps7kLlfmJEVb RLUk86ds87mDeSmHpiqbDLLP3YyI/EPmQksbsr2AUeZp4f2v5IM6Hi5bnDjHrxvw5YyQPZ/CMA tFHAl1z36uHw0DGfib5eohWfM89p+Nu0H0L0sjJvuXG8gk+EMNgRnvz7gFS+6HUPBgzTsbWDGC OHg= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Jun 2022 19:25:02 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LJSbx592Mz1Rvlc for ; Wed, 8 Jun 2022 19:25:01 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1654741501; x=1657333502; bh=0JQQvXQ5K3VvZl36WY /dYo6dIIQ+Ya7q+dJvDPmd6Kc=; b=AopHRzSVIvnnE8MWTrnYvnJkuceJAcp1F6 SatWID95BQAfmeRJemMF9CGispFdZ9Uey72r7dYzy0/XtYp1hWQxk/voHCkQc9T6 syhaX6wDbN+mHMem29jFhABb+LC4SeWaZj/zeKon2D9uHI19iPf9TqbSX7tSeSt2 7pFwMbpWZ6sTOPAa0AnmEN+Gs/RqE3gxe4YyNiNxElmBEOeqcYQrTBsf8ZKYN9em AsUTLpe43pIWcPTx/Bb4EIAF0IHyAihdTtRFrJKw0Bb9HmpbHLiUVTPyqzetst7J hKlxW7lsBgh7IuzfXux8GB3wxef+2Y594ua5IZVxqUdbZZWUBuDQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NKYqSiJ87zXr for ; Wed, 8 Jun 2022 19:25:01 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LJSbw5Sckz1Rvlx; Wed, 8 Jun 2022 19:25:00 -0700 (PDT) From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry Subject: [PATCH 3/3] scsi: libsas: introduce struct smp_rps_resp Date: Thu, 9 Jun 2022 11:24:56 +0900 Message-Id: <20220609022456.409087-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> References: <20220609022456.409087-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Similarly to sas report general and discovery responses, define the structure struct smp_rps_resp to handle SATA PHY report responses using a structure with a size that is exactly equal to the sas defined response size. With this change, struct smp_resp becomes unused and is removed. Signed-off-by: Damien Le Moal --- drivers/scsi/aic94xx/aic94xx_dev.c | 2 +- drivers/scsi/libsas/sas_expander.c | 4 ++-- drivers/scsi/libsas/sas_internal.h | 2 +- include/scsi/libsas.h | 2 +- include/scsi/sas.h | 8 ++------ 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/aic94xx/aic94xx_dev.c b/drivers/scsi/aic94xx/aic94xx_dev.c index 73506a459bf8..91d196f26b76 100644 --- a/drivers/scsi/aic94xx/aic94xx_dev.c +++ b/drivers/scsi/aic94xx/aic94xx_dev.c @@ -159,7 +159,7 @@ static int asd_init_target_ddb(struct domain_device *dev) flags |= OPEN_REQUIRED; if ((dev->dev_type == SAS_SATA_DEV) || (dev->tproto & SAS_PROTOCOL_STP)) { - struct smp_resp *rps_resp = &dev->sata_dev.rps_resp; + struct smp_rps_resp *rps_resp = &dev->sata_dev.rps_resp; if (rps_resp->frame_type == SMP_RESPONSE && rps_resp->function == SMP_REPORT_PHY_SATA && rps_resp->result == SMP_RESP_FUNC_ACC) { diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 78a38980636e..fa2209080cc2 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -676,10 +676,10 @@ int sas_smp_get_phy_events(struct sas_phy *phy) #ifdef CONFIG_SCSI_SAS_ATA #define RPS_REQ_SIZE 16 -#define RPS_RESP_SIZE 60 +#define RPS_RESP_SIZE sizeof(struct smp_rps_resp) int sas_get_report_phy_sata(struct domain_device *dev, int phy_id, - struct smp_resp *rps_resp) + struct smp_rps_resp *rps_resp) { int res; u8 *rps_req = alloc_smp_req(RPS_REQ_SIZE); diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h index 13d0ffaada93..8d0ad3abc7b5 100644 --- a/drivers/scsi/libsas/sas_internal.h +++ b/drivers/scsi/libsas/sas_internal.h @@ -83,7 +83,7 @@ struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy); struct domain_device *sas_ex_to_ata(struct domain_device *ex_dev, int phy_id); int sas_ex_phy_discover(struct domain_device *dev, int single); int sas_get_report_phy_sata(struct domain_device *dev, int phy_id, - struct smp_resp *rps_resp); + struct smp_rps_resp *rps_resp); int sas_try_ata_reset(struct asd_sas_phy *phy); void sas_hae_reset(struct work_struct *work); diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index ff04eb6d250b..2dbead74a2af 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -145,7 +145,7 @@ struct sata_device { struct ata_port *ap; struct ata_host *ata_host; - struct smp_resp rps_resp ____cacheline_aligned; /* report_phy_sata_resp */ + struct smp_rps_resp rps_resp ____cacheline_aligned; /* report_phy_sata_resp */ u8 fis[ATA_RESP_FIS_SIZE]; }; diff --git a/include/scsi/sas.h b/include/scsi/sas.h index a8f9743ed6fc..71b749bed3b0 100644 --- a/include/scsi/sas.h +++ b/include/scsi/sas.h @@ -712,16 +712,12 @@ struct smp_disc_resp { struct discover_resp disc; } __attribute__ ((packed)); -struct smp_resp { +struct smp_rps_resp { u8 frame_type; u8 function; u8 result; u8 reserved; - union { - struct report_general_resp rg; - struct discover_resp disc; - struct report_phy_sata_resp rps; - }; + struct report_phy_sata_resp rps; } __attribute__ ((packed)); #endif /* _SAS_H_ */