From patchwork Fri Apr 21 10:08:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 753254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w8Wfl31WHz9s03 for ; Fri, 21 Apr 2017 20:09:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="lW1yLVxg"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 501A1C21C5E; Fri, 21 Apr 2017 10:08:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3AC01C21C29; Fri, 21 Apr 2017 10:08:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B529BC21C29; Fri, 21 Apr 2017 10:08:53 +0000 (UTC) Received: from fllnx210.ext.ti.com (fllnx210.ext.ti.com [198.47.19.17]) by lists.denx.de (Postfix) with ESMTPS id 162B7C21BE5 for ; Fri, 21 Apr 2017 10:08:52 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id v3LA8ofj002270; Fri, 21 Apr 2017 05:08:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1492769330; bh=tHywPYF0Uf2v7bTsir0+KoI8XoZ1JEK3o0YpRplgtmI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lW1yLVxggm4prHLfjIqn4GZDZeZBPK/mvT1kPbtxtQo4wZGcddDp2n6eiBOVxyTNE bravpO/2nAz0otzaYCSvxPVi1NbYdtYbmvFw2CbpN8KGdSolf66fM9hDxpYkvoZBS+ E/QhKV3XP5VrtY2JIAf8VkKTkyscJ5Z7AZSTZzKM= Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3LA8oBl025018; Fri, 21 Apr 2017 05:08:50 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Fri, 21 Apr 2017 05:08:49 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3LA8nZl002469; Fri, 21 Apr 2017 05:08:49 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 21 Apr 2017 12:08:45 +0200 Message-ID: <1492769331-5891-2-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1492769331-5891-1-git-send-email-jjhiblot@ti.com> References: <1492769331-5891-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 1/7] scsi: dm: split scsi_scan() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The DM version of scsi_scan() is becoming a bit long, it can be split: scsi_scan() iterates over the IDs and LUNs and for each id/lun pair calls do_scsi_scan_one() to do the work of: - detecting an attached drive - creating the associated block device if a drive is found. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Simon Glass --- common/scsi.c | 102 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/common/scsi.c b/common/scsi.c index d37222c..c456f5a 100644 --- a/common/scsi.c +++ b/common/scsi.c @@ -549,6 +549,52 @@ removable: * to the user if mode = 1 */ #if defined(CONFIG_DM_SCSI) +static int do_scsi_scan_one(struct udevice *dev, int id, int lun, int mode) +{ + int ret; + struct udevice *bdev; + struct blk_desc bd; + struct blk_desc *bdesc; + char str[10]; + + /* + * detect the scsi driver to get information about its geometry (block + * size, number of blocks) and other parameters (ids, type, ...) + */ + scsi_init_dev_desc_priv(&bd); + if (scsi_detect_dev(id, lun, &bd)) + return -ENODEV; + + /* + * Create only one block device and do detection + * to make sure that there won't be a lot of + * block devices created + */ + snprintf(str, sizeof(str), "id%dlun%d", id, lun); + ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1, + bd.blksz, bd.blksz * bd.lba, &bdev); + if (ret) { + debug("Can't create device\n"); + return ret; + } + + bdesc = dev_get_uclass_platdata(bdev); + bdesc->target = id; + bdesc->lun = lun; + bdesc->removable = bd.removable; + bdesc->type = bd.type; + memcpy(&bdesc->vendor, &bd.vendor, sizeof(bd.vendor)); + memcpy(&bdesc->product, &bd.product, sizeof(bd.product)); + memcpy(&bdesc->revision, &bd.revision, sizeof(bd.revision)); + part_init(bdesc); + + if (mode == 1) { + printf(" Device %d: ", 0); + dev_print(bdesc); + } + return 0; +} + int scsi_scan(int mode) { unsigned char i, lun; @@ -576,59 +622,9 @@ int scsi_scan(int mode) /* Get controller platdata */ plat = dev_get_platdata(dev); - for (i = 0; i < plat->max_id; i++) { - for (lun = 0; lun < plat->max_lun; lun++) { - struct udevice *bdev; /* block device */ - /* block device description */ - struct blk_desc _bd; - struct blk_desc *bdesc; - char str[10]; - - scsi_init_dev_desc_priv(&_bd); - ret = scsi_detect_dev(i, lun, &_bd); - if (ret) - /* - * no device detected? - * check the next lun. - */ - continue; - - /* - * Create only one block device and do detection - * to make sure that there won't be a lot of - * block devices created - */ - snprintf(str, sizeof(str), "id%dlun%d", i, lun); - ret = blk_create_devicef(dev, "scsi_blk", - str, IF_TYPE_SCSI, - -1, - _bd.blksz, - _bd.blksz * _bd.lba, - &bdev); - if (ret) { - debug("Can't create device\n"); - return ret; - } - - bdesc = dev_get_uclass_platdata(bdev); - bdesc->target = i; - bdesc->lun = lun; - bdesc->removable = _bd.removable; - bdesc->type = _bd.type; - memcpy(&bdesc->vendor, &_bd.vendor, - sizeof(_bd.vendor)); - memcpy(&bdesc->product, &_bd.product, - sizeof(_bd.product)); - memcpy(&bdesc->revision, &_bd.revision, - sizeof(_bd.revision)); - part_init(bdesc); - - if (mode == 1) { - printf(" Device %d: ", 0); - dev_print(bdesc); - } /* if mode */ - } /* next LUN */ - } + for (i = 0; i < plat->max_id; i++) + for (lun = 0; lun < plat->max_lun; lun++) + do_scsi_scan_one(dev, i, lun, mode); } return 0;