From patchwork Thu Jan 26 03:41:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9538349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7FB3360429 for ; Thu, 26 Jan 2017 03:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E02B27F94 for ; Thu, 26 Jan 2017 03:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62ADD28047; Thu, 26 Jan 2017 03:41:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C4327F94 for ; Thu, 26 Jan 2017 03:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752788AbdAZDlj (ORCPT ); Wed, 25 Jan 2017 22:41:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60802 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752692AbdAZDli (ORCPT ); Wed, 25 Jan 2017 22:41:38 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C45347FB67; Thu, 26 Jan 2017 03:41:33 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-30.pek2.redhat.com [10.72.8.30]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0Q3fBT9010067; Wed, 25 Jan 2017 22:41:27 -0500 From: Fam Zheng To: linux-kernel@vger.kernel.org Cc: Paolo Bonzini , famz@redhat.com, linux-scsi@vger.kernel.org, "James E.J. Bottomley" , "Michael S. Tsirkin" , Jason Wang , "Martin K. Petersen" , stefanha@redhat.com, virtualization@lists.linux-foundation.org Subject: [PATCH v2 2/2] virtio_scsi: Implement fc_host Date: Thu, 26 Jan 2017 11:41:09 +0800 Message-Id: <20170126034109.16144-3-famz@redhat.com> In-Reply-To: <20170126034109.16144-1-famz@redhat.com> References: <20170126034109.16144-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 26 Jan 2017 03:41:33 +0000 (UTC) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration. Signed-off-by: Fam Zheng --- drivers/scsi/virtio_scsi.c | 60 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index ec91bd0..1bb330c 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #define VIRTIO_SCSI_MEMPOOL_SZ 64 @@ -795,6 +796,15 @@ static struct scsi_host_template virtscsi_host_template_multi = { .track_queue_depth = 1, }; +static struct fc_function_template virtscsi_fc_template = { + .show_host_node_name = 1, + .show_host_port_name = 1, + .show_host_port_type = 1, + .show_host_port_state = 1, +}; + +static struct scsi_transport_template *virtscsi_fc_transport_template; + #define virtscsi_config_get(vdev, fld) \ ({ \ typeof(((struct virtio_scsi_config *)0)->fld) __val; \ @@ -956,15 +966,42 @@ static int virtscsi_init(struct virtio_device *vdev, return err; } +static void virtscsi_update_fc_host_attrs(struct virtio_device *vdev) +{ + struct Scsi_Host *shost = vdev->priv; + u8 node_name[8], port_name[8]; + + if (virtscsi_config_get(vdev, primary_active)) { + virtio_cread_bytes(vdev, + offsetof(struct virtio_scsi_config, primary_wwnn), + &node_name, 8); + virtio_cread_bytes(vdev, + offsetof(struct virtio_scsi_config, primary_wwpn), + &port_name, 8); + } else { + virtio_cread_bytes(vdev, + offsetof(struct virtio_scsi_config, secondary_wwnn), + &node_name, 8); + virtio_cread_bytes(vdev, + offsetof(struct virtio_scsi_config, secondary_wwpn), + &port_name, 8); + } + fc_host_node_name(shost) = wwn_to_u64(node_name); + fc_host_port_name(shost) = wwn_to_u64(port_name); + fc_host_port_type(shost) = FC_PORTTYPE_NPORT; + fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; +} + static int virtscsi_probe(struct virtio_device *vdev) { - struct Scsi_Host *shost; + struct Scsi_Host *shost = NULL; struct virtio_scsi *vscsi; int err; u32 sg_elems, num_targets; u32 cmd_per_lun; u32 num_queues; struct scsi_host_template *hostt; + bool fc_host_enabled; if (!vdev->config->get) { dev_err(&vdev->dev, "%s failure: config access disabled\n", @@ -987,6 +1024,9 @@ static int virtscsi_probe(struct virtio_device *vdev) if (!shost) return -ENOMEM; + fc_host_enabled = virtio_has_feature(vdev, VIRTIO_SCSI_F_FC_HOST); + if (fc_host_enabled) + shost->transportt = virtscsi_fc_transport_template; sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1; shost->sg_tablesize = sg_elems; vscsi = shost_priv(shost); @@ -1032,6 +1072,9 @@ static int virtscsi_probe(struct virtio_device *vdev) if (err) goto scsi_add_host_failed; + if (fc_host_enabled) + virtscsi_update_fc_host_attrs(vdev); + virtio_device_ready(vdev); if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) @@ -1098,6 +1141,11 @@ static int virtscsi_restore(struct virtio_device *vdev) } #endif +static void virtscsi_config_changed(struct virtio_device *vdev) +{ + virtscsi_update_fc_host_attrs(vdev); +} + static struct virtio_device_id id_table[] = { { VIRTIO_ID_SCSI, VIRTIO_DEV_ANY_ID }, { 0 }, @@ -1109,6 +1157,7 @@ static unsigned int features[] = { #ifdef CONFIG_BLK_DEV_INTEGRITY VIRTIO_SCSI_F_T10_PI, #endif + VIRTIO_SCSI_F_FC_HOST, }; static struct virtio_driver virtio_scsi_driver = { @@ -1123,12 +1172,20 @@ static struct virtio_driver virtio_scsi_driver = { .restore = virtscsi_restore, #endif .remove = virtscsi_remove, + .config_changed = virtscsi_config_changed, }; static int __init init(void) { int ret = -ENOMEM; + virtscsi_fc_transport_template = + fc_attach_transport(&virtscsi_fc_template); + if (!virtscsi_fc_transport_template) { + pr_err("fc_attach_transport() failed\n"); + goto error; + } + virtscsi_cmd_cache = KMEM_CACHE(virtio_scsi_cmd, 0); if (!virtscsi_cmd_cache) { pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n"); @@ -1176,6 +1233,7 @@ static int __init init(void) static void __exit fini(void) { + fc_release_transport(virtscsi_fc_transport_template); unregister_virtio_driver(&virtio_scsi_driver); cpuhp_remove_multi_state(virtioscsi_online); cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD);