From patchwork Tue Jan 5 12:40:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 7954581 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 60BC0BEEE5 for ; Tue, 5 Jan 2016 12:41:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89525202EC for ; Tue, 5 Jan 2016 12:41:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A34E202E5 for ; Tue, 5 Jan 2016 12:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751716AbcAEMk6 (ORCPT ); Tue, 5 Jan 2016 07:40:58 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34432 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751440AbcAEMk5 (ORCPT ); Tue, 5 Jan 2016 07:40:57 -0500 Received: by mail-pa0-f54.google.com with SMTP id uo6so195499575pac.1; Tue, 05 Jan 2016 04:40:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=+DTnjwbxpwMaGte1l7mxXIZOtNBXk/xhCs3r0IyI2Hk=; b=MtNcB7ywdTG9dkqzbZ91PztN3Bm9Rie13mVYhq40NjP0VJ8JwjcJG9Mg59keimacJD OlPlKnqIn0fTNYI7pDNEd/YsDDcQA9i8/AjnQ5PUcv5moL73nG3LYhliVRisbUareM0O Ft2fC5/tgRi9kibMCiNpyKCQX9lY148xzv0+FuPlRN4amEekVYya2VXCF/8REVgZs6mY 0OpsQXxLwXa800IiFNxm6DaE7RNCdz8OKQCJ68tlHSHabjyRe0qVyxXb2NfTUi8r/sZ9 AGbxYHno+ip0vOyGccc5RjlaMEsD7GKnR9tyUruB2ob2WrWYVfTrqlLBk5IypoJ/LL3+ oN2Q== X-Received: by 10.66.150.37 with SMTP id uf5mr136160307pab.30.1451997657450; Tue, 05 Jan 2016 04:40:57 -0800 (PST) Received: from sudip-pc.vectortproxy.org ([183.82.228.160]) by smtp.gmail.com with ESMTPSA id m1sm128106336pfi.27.2016.01.05.04.40.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Jan 2016 04:40:56 -0800 (PST) From: Sudip Mukherjee To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Sudip Mukherjee Subject: [PATCH] scsi: imm: use new parport device model Date: Tue, 5 Jan 2016 18:10:50 +0530 Message-Id: <1451997650-10573-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Modify imm driver to use the new parallel port device model. Signed-off-by: Sudip Mukherjee Reviewed-by: Matthew R. Ochs --- I usually submit checkpatch cleanup and other modifications while converting a driver to use parport device model. For this driver i hesitated. If you want I can send a series with this modification and checkpatch fix. Same for scsi/ppa.c. drivers/scsi/imm.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c index 4e1a632..f8b88fa 100644 --- a/drivers/scsi/imm.c +++ b/drivers/scsi/imm.c @@ -43,6 +43,7 @@ typedef struct { unsigned dp:1; /* Data phase present */ unsigned rd:1; /* Read data in data phase */ unsigned wanted:1; /* Parport sharing busy flag */ + unsigned int dev_no; /* Device number */ wait_queue_head_t *waiting; struct Scsi_Host *host; struct list_head list; @@ -1120,15 +1121,40 @@ static struct scsi_host_template imm_template = { static LIST_HEAD(imm_hosts); +/* + * Finds the first available device number that can be alloted to the + * new imm device and returns the address of the previous node so that + * we can add to the tail and have a list in the ascending order. + */ + +static inline imm_struct *find_parent(void) +{ + imm_struct *dev, *par = NULL; + unsigned int cnt = 0; + + if (list_empty(&imm_hosts)) + return NULL; + + list_for_each_entry(dev, &imm_hosts, list) { + if (dev->dev_no != cnt) + return par; + cnt++; + par = dev; + } + + return par; +} + static int __imm_attach(struct parport *pb) { struct Scsi_Host *host; - imm_struct *dev; + imm_struct *dev, *temp; DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting); DEFINE_WAIT(wait); int ports; int modes, ppb; int err = -ENOMEM; + struct pardev_cb imm_cb; init_waitqueue_head(&waiting); @@ -1141,9 +1167,15 @@ static int __imm_attach(struct parport *pb) dev->mode = IMM_AUTODETECT; INIT_LIST_HEAD(&dev->list); - dev->dev = parport_register_device(pb, "imm", NULL, imm_wakeup, - NULL, 0, dev); + temp = find_parent(); + if (temp) + dev->dev_no = temp->dev_no + 1; + + memset(&imm_cb, 0, sizeof(imm_cb)); + imm_cb.private = dev; + imm_cb.wakeup = imm_wakeup; + dev->dev = parport_register_dev_model(pb, "imm", &imm_cb, dev->dev_no); if (!dev->dev) goto out; @@ -1207,7 +1239,10 @@ static int __imm_attach(struct parport *pb) host->unique_id = pb->number; *(imm_struct **)&host->hostdata = dev; dev->host = host; - list_add_tail(&dev->list, &imm_hosts); + if (!temp) + list_add_tail(&dev->list, &imm_hosts); + else + list_add_tail(&dev->list, &temp->list); err = scsi_add_host(host, NULL); if (err) goto out2; @@ -1245,9 +1280,10 @@ static void imm_detach(struct parport *pb) } static struct parport_driver imm_driver = { - .name = "imm", - .attach = imm_attach, - .detach = imm_detach, + .name = "imm", + .match_port = imm_attach, + .detach = imm_detach, + .devmodel = true, }; static int __init imm_driver_init(void)