From patchwork Fri Apr 3 15:58:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 6157351 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A3939BF4A6 for ; Fri, 3 Apr 2015 16:01:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D146F203DA for ; Fri, 3 Apr 2015 16:01:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E333A203B6 for ; Fri, 3 Apr 2015 16:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753316AbbDCQAK (ORCPT ); Fri, 3 Apr 2015 12:00:10 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:59783 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbbDCP6d (ORCPT ); Fri, 3 Apr 2015 11:58:33 -0400 Received: from pps.filterd (m0044008 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t33FtxLp014959; Fri, 3 Apr 2015 08:58:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=RjrwE6Dnr0alOnap/yBXstKAJcjthPv36GuUPZ6m4YM=; b=XkUlDhtgpVIXFz2g3BC7dn5xeOvMwTLOdkn4eaQViUiwm/tcqo/WmWNIMZ2L+aFHRgfH Gp4fE3j1AYJQ/lKYbNiFtECTqukPDMUopRVk9khv68DLHvFl8sY0fPrqDh8dAaMKcJKJ WFO60eScSdLLVzH8KY74X1dvUcQhx/1T/J4= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1thrr8ghdy-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 03 Apr 2015 08:58:30 -0700 Received: from lenny.thefacebook.com (192.168.52.13) by mail.thefacebook.com (192.168.16.22) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 3 Apr 2015 08:58:28 -0700 From: Jens Axboe To: , , CC: , Jens Axboe Subject: [PATCH 5/7] scsi: add host template init/exit_command hooks Date: Fri, 3 Apr 2015 09:58:21 -0600 Message-ID: <1428076703-31014-6-git-send-email-axboe@fb.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428076703-31014-1-git-send-email-axboe@fb.com> References: <1428076703-31014-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.52.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68, 1.0.33, 0.0.0000 definitions=2015-04-03_06:2015-04-03, 2015-04-03, 1970-01-01 signatures=0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a LLD has hardware commands in the request pdu, then we need some helper hooks to help the driver initialize state at load time, and potentially to tear down state at rmmod time. Add a host template ->init_command() and ->exit_command() hook to help with that. Signed-off-by: Jens Axboe --- drivers/scsi/scsi_lib.c | 16 ++++++++++++++++ include/scsi/scsi_host.h | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 87a4c53c8b48..d8f03526b836 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2081,11 +2081,23 @@ static int scsi_init_request(void *data, struct request *rq, unsigned int numa_node) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); + struct Scsi_Host *shost = data; cmd->sense_buffer = kzalloc_node(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL, numa_node); if (!cmd->sense_buffer) return -ENOMEM; + + if (shost->hostt->init_command) { + int ret; + + ret = shost->hostt->init_command(shost, cmd, request_idx); + if (ret) { + kfree(cmd->sense_buffer); + return ret; + } + } + return 0; } @@ -2093,8 +2105,12 @@ static void scsi_exit_request(void *data, struct request *rq, unsigned int hctx_idx, unsigned int request_idx) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); + struct Scsi_Host *shost = data; kfree(cmd->sense_buffer); + + if (shost->hostt->exit_command) + shost->hostt->exit_command(shost, cmd); } static u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost) diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index e113c757d555..baaa7a2fc07d 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -496,10 +496,14 @@ struct scsi_host_template { u64 vendor_id; /* - * Additional per-command data allocated for the driver. + * Additional per-command data allocated for the driver, along + * with init/exit helper hooks. */ unsigned int cmd_size; struct scsi_host_cmd_pool *cmd_pool; + int (*init_command)(struct Scsi_Host *, struct scsi_cmnd *, + unsigned int); + void (*exit_command)(struct Scsi_Host *, struct scsi_cmnd *); /* temporary flag to disable blk-mq I/O path */ bool disable_blk_mq;