Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2204840imu; Sat, 26 Jan 2019 23:09:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN5XxIyhkaxNMr5jDaQN74cwLd9lwaH0QYAtdLhbKzwF0OV2OUe5HCFXT0NObNr24M4cpTTA X-Received: by 2002:a62:35c7:: with SMTP id c190mr17921754pfa.76.1548572946237; Sat, 26 Jan 2019 23:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548572946; cv=none; d=google.com; s=arc-20160816; b=s5y5xlbx05lx4zti/gq+78SgSIV2sLh5QiDDUjW9GOtSdvrYj5TBjMB0zSD1CdzZl8 1BgcfkC81dfLNrpgYkQH7JiCSVK0jptvoppP4Qk36f4Ej5TccZ091KOHNKYXTTb385HA +rgIcLHdn7B9BVvtU4mX3R0TL6VDpPV0hA9fYRnFQBpeXH+E/Y803H+RFrXStx4jFT00 jqlDnUa1RoOpPlj4T2hW6v6x36sppde5vZYXyev4b9WpQLXM5n6qP4eWqYAnHgZmqltg G6BXE+fNHtiHuHmSR2MqMX1W6AGWqQBk5MtWw7nijZ7UvXlYG+v4P/cQlpaeOPWYsb0O s+JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XSm9520HNV7+kgb0s50mBRJOLYkV6AewPLorW+hI5hY=; b=KQdwgRUDT+8cA416RrKY2+53gkLGFQ4i9K2ihcGWlzu/yyBvEoxXFeS8ATd5SiF8Be OxacroydAzTQsif5jZvAHsyalMsy6dx8RvqDS7ec3lsnLpoouAAxADI8iItrx2JPvSH9 CexWHAWA8okRRDs60e6sukoIkDyADH4Wux0TtZvhwKW2XTCAYCDKhObnbfTpUfY0WFqu hasQrI/7MOZf8yDH/XI/JGHZpRQ/FqRq/SoZwzp+BwWlAsdZuVyLK9LO8g2WvFnAJzwa /RXSS6h3/CvCSp38fljmMVdnPaddso5R4g7ep90K3PoC+mst1jbFOQ+JBDgVQhQnjQym 3WUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=P5pfRmbc; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si29681247plt.93.2019.01.26.23.08.36; Sat, 26 Jan 2019 23:09:06 -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; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=P5pfRmbc; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726607AbfA0HIS (ORCPT + 99 others); Sun, 27 Jan 2019 02:08:18 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:37256 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbfA0HIS (ORCPT ); Sun, 27 Jan 2019 02:08:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1548572898; x=1580108898; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=HWsqQY9kZkceBww9unbKzePKnY/h5AHjL+2bSqvP+KU=; b=P5pfRmbcxp1CLfE3eRMnjbd5FYROG7Io0X/7fU1M/3QNivnnmYjq6nKF FLVkKTgbptMg5GDqIqJfRKYvSWR4F1xJtNHDoDFStijn4jShclDiwt6EQ F3UVhhA+VbpbB99Fcc9WSOcUgzlSTUK1jz7f7eyt5BxZokHseg4QxuhK+ WLaXoKC4eE9tVLRixgt+C4tyeC/kxRwaQHY07zCqFBt6zD5BJDelLjC5L fNY4JeIxkPgISIH3TKqhqhqwiIRTn1+B6dS7T1nDgLYdR6mwItLT8DtMP z3SYqj2tmMwS02nsVDjJK+lgVGdqKOTlPnAlXOhpHLy+Xxr2lKsWx1Cv3 A==; X-IronPort-AV: E=Sophos;i="5.56,529,1539619200"; d="scan'208";a="101125467" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 27 Jan 2019 15:08:18 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 26 Jan 2019 22:49:20 -0800 Received: from kfae422988.sdcorp.global.sandisk.com ([10.0.230.227]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Jan 2019 23:08:15 -0800 From: Avri Altman To: "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Evan Green Cc: Avi Shchislowski , Alex Lemberg , Avri Altman Subject: [PATCH v4 1/3] scsi: ufs-bsg: Change the calling convention for write descriptor Date: Sun, 27 Jan 2019 09:07:46 +0200 Message-Id: <1548572868-12589-2-git-send-email-avri.altman@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1548572868-12589-1-git-send-email-avri.altman@wdc.com> References: <1548572868-12589-1-git-send-email-avri.altman@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we had a write descriptor query upiu, we appended the descriptor right after the bsg request. This was fine as the bsg driver allows to allocate whatever buffer we needed in its job request. Still, the proper way to deliver payload, however small (we only write config descriptors of 144 bytes), is by using the job request payload data buffer. So change this ABI now, while ufs-bsg is still new, and nobody is actually using it. Signed-off-by: Avri Altman Reviewed-by: Evan Green --- Documentation/scsi/ufs.txt | 6 ++++++ drivers/scsi/ufs/ufs_bsg.c | 47 +++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Documentation/scsi/ufs.txt b/Documentation/scsi/ufs.txt index 520b5b0..78fe7cb 100644 --- a/Documentation/scsi/ufs.txt +++ b/Documentation/scsi/ufs.txt @@ -147,6 +147,12 @@ send SG_IO with the applicable sg_io_v4: io_hdr_v4.max_response_len = reply_len; io_hdr_v4.request_len = request_len; io_hdr_v4.request = (__u64)request_upiu; + if (dir == SG_DXFER_TO_DEV) { + io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt; + io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff; + } + +If you wish to write a descriptor, use the dout_xferp sg_io_v4. UFS Specifications can be found at, UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf diff --git a/drivers/scsi/ufs/ufs_bsg.c b/drivers/scsi/ufs/ufs_bsg.c index 775bb4e..2fd0769 100644 --- a/drivers/scsi/ufs/ufs_bsg.c +++ b/drivers/scsi/ufs/ufs_bsg.c @@ -27,15 +27,11 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, static int ufs_bsg_verify_query_size(struct ufs_hba *hba, unsigned int request_len, - unsigned int reply_len, - int desc_len, enum query_opcode desc_op) + unsigned int reply_len) { int min_req_len = sizeof(struct ufs_bsg_request); int min_rsp_len = sizeof(struct ufs_bsg_reply); - if (desc_op == UPIU_QUERY_OPCODE_WRITE_DESC) - min_req_len += desc_len; - if (min_req_len > request_len || min_rsp_len > reply_len) { dev_err(hba->dev, "not enough space assigned\n"); return -EINVAL; @@ -44,14 +40,13 @@ static int ufs_bsg_verify_query_size(struct ufs_hba *hba, return 0; } -static int ufs_bsg_verify_query_params(struct ufs_hba *hba, - struct ufs_bsg_request *bsg_request, - unsigned int request_len, - unsigned int reply_len, - uint8_t *desc_buff, int *desc_len, - enum query_opcode desc_op) +static int ufs_bsg_alloc_desc_buffer(struct ufs_hba *hba, struct bsg_job *job, + uint8_t **desc_buff, int *desc_len, + enum query_opcode desc_op) { + struct ufs_bsg_request *bsg_request = job->request; struct utp_upiu_query *qr; + u8 *descp; if (desc_op == UPIU_QUERY_OPCODE_READ_DESC) { dev_err(hba->dev, "unsupported opcode %d\n", desc_op); @@ -67,11 +62,19 @@ static int ufs_bsg_verify_query_params(struct ufs_hba *hba, return -EINVAL; } - if (ufs_bsg_verify_query_size(hba, request_len, reply_len, *desc_len, - desc_op)) + if (*desc_len > job->request_payload.payload_len) { + dev_err(hba->dev, "Illegal desc size\n"); return -EINVAL; + } + + descp = kzalloc(*desc_len, GFP_KERNEL); + if (!descp) + return -ENOMEM; - desc_buff = (uint8_t *)(bsg_request + 1); + sg_copy_to_buffer(job->request_payload.sg_list, + job->request_payload.sg_cnt, descp, *desc_len); + + *desc_buff = descp; out: return 0; @@ -91,7 +94,7 @@ static int ufs_bsg_request(struct bsg_job *job) enum query_opcode desc_op = UPIU_QUERY_OPCODE_NOP; int ret; - ret = ufs_bsg_verify_query_size(hba, req_len, reply_len, 0, desc_op); + ret = ufs_bsg_verify_query_size(hba, req_len, reply_len); if (ret) goto out; @@ -101,9 +104,8 @@ static int ufs_bsg_request(struct bsg_job *job) switch (msgcode) { case UPIU_TRANSACTION_QUERY_REQ: desc_op = bsg_request->upiu_req.qr.opcode; - ret = ufs_bsg_verify_query_params(hba, bsg_request, req_len, - reply_len, desc_buff, - &desc_len, desc_op); + ret = ufs_bsg_alloc_desc_buffer(hba, job, &desc_buff, + &desc_len, desc_op); if (ret) goto out; @@ -135,11 +137,14 @@ static int ufs_bsg_request(struct bsg_job *job) break; } + if (!desc_buff) + goto out; + + kfree(desc_buff); + out: bsg_reply->result = ret; - job->reply_len = sizeof(struct ufs_bsg_reply) + - bsg_reply->reply_payload_rcv_len; - + job->reply_len = sizeof(struct ufs_bsg_reply); bsg_job_done(job, ret, bsg_reply->reply_payload_rcv_len); return ret; -- 1.9.1