From patchwork Tue Aug 4 02:13:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 11700037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A29016C1 for ; Tue, 4 Aug 2020 09:07:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BEFE722B45 for ; Tue, 4 Aug 2020 09:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="fnMXglto" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730067AbgHDJHp (ORCPT ); Tue, 4 Aug 2020 05:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729959AbgHDJHo (ORCPT ); Tue, 4 Aug 2020 05:07:44 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1A7C06174A for ; Tue, 4 Aug 2020 02:07:44 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id j10so11972489qvo.13 for ; Tue, 04 Aug 2020 02:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f9Q4PjJiivNWg48RkDjis164deuVXADKQZbcPn0oHoY=; b=fnMXgltob3V8ee88/ZlgPdVC1j5xb97VnsTFA0s5hUR+Fh784FILT/SW/mzIIq2MeR LKDC04zHqQnKei1jhnr28TWtgl1VBHR7RifQdNdePmktQl3CXOmJ/eu027wtaMN6XcyB o+D0v+Q/4kq4zuwloQhWvFbygXOPzMvxMR5CQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=f9Q4PjJiivNWg48RkDjis164deuVXADKQZbcPn0oHoY=; b=PrlBcEY50EPt6l3Sbd8rIDSyhBWHUsA2sUcVKYv4fFpFXVSJ02O2iPAA6eF5ODm5zW pMGLgZD5k1lE9sebnjwLXvUUp5I+un2H3qu+BM4zHEyV4Y+eBi6Jt3J/uwmB48+ETB25 Hp0/Nt2bbUNi5+4542H32Kc4bZy17Xxm9s/zLnGP9fYply8TUEifFhieBDOw4lKhONlZ oL9IjtzPM24fUWAzeYAUIE+jPBt50OGv/ab0g1+cyIQBoV5n94ErQE4QFyt8aBvIZ80r fviZh+bVujEfkUVabMseF/z7/xV/0pPjCpB/8GE3uCPvv6NtbtX9x9WmfA9gcbY4cdv0 /drA== X-Gm-Message-State: AOAM533sM5nzaokclr1Sn/FEkojt8pBBLTt+urBeoKJ94242bX1ZpG58 Pqt52YMAsvR6Zr1mIoMRdojQiy5Vb8wFJMyYHbBylbKTbHOpv54vknuYXzWGpvfNqSasL+qy9bT JwwZtIA6RS2QLeyKia8I3oVv4RUxb2RB45+SwU7k7WaU6+/tHn6mEGMHUukmmKPxsSQHa2SWZkm 5v6sYJ/3c= X-Google-Smtp-Source: ABdhPJyZVNn9mMA4ujChESU/er1Q2/o/b5opHMM8HmC6XgvxR5kOgfq7d7CLg5nVpGDbg8heukw20g== X-Received: by 2002:ad4:4984:: with SMTP id t4mr146050qvx.110.1596532062845; Tue, 04 Aug 2020 02:07:42 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 65sm19989407qkn.103.2020.08.04.02.07.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2020 02:07:42 -0700 (PDT) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org Cc: pbonzini@redhat.com, emilne@redhat.com, mkumar@redhat.com, Gaurav Srivastava , James Smart , Muneendra Subject: [RFC 11/16] lpfc: vmid: Functions to manage vmids Date: Tue, 4 Aug 2020 07:43:11 +0530 Message-Id: <1596507196-27417-12-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596507196-27417-1-git-send-email-muneendra.kumar@broadcom.com> References: <1596507196-27417-1-git-send-email-muneendra.kumar@broadcom.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gaurav Srivastava This patch contains the routines to save, retrieve and remove the vmids from the data structure. A hash table is used to save the vmids and the corresponding UUIDs associated with the application/VMs. Signed-off-by: Gaurav Srivastava Signed-off-by: James Smart Signed-off-by: Muneendra --- drivers/scsi/lpfc/lpfc_scsi.c | 139 ++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c index 7bc1fd69b715..e5a1056cc575 100644 --- a/drivers/scsi/lpfc/lpfc_scsi.c +++ b/drivers/scsi/lpfc/lpfc_scsi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -4485,6 +4486,144 @@ void lpfc_poll_timeout(struct timer_list *t) } } +/* + * lpfc_get_vmid_from_hastable - search the UUID in the hash table + * @vport: The virtual port for which this call is being executed. + * @hash: calculated hash value + * @buf: uuid associated with the VE + * Returns the vmid entry associated with the UUID + * Make sure to acquire the appropriate lock before invoking this routine. + */ +struct lpfc_vmid *lpfc_get_vmid_from_hastable(struct lpfc_vport *vport, + u32 hash, u8 *buf) +{ + struct lpfc_vmid *vmp; + u16 count = 0; + + while (count < LPFC_VMID_HASH_SIZE) { + vmp = vport->hash_table[hash]; + if (vmp) { + if (strncmp(&vmp->host_vmid[0], buf, 16) == 0) + return vmp; + } else { + return NULL; + } + /* search the next available slot and continue till entry */ + /* is found */ + count++; + hash++; + + /* or the end is reached */ + if (hash == LPFC_VMID_HASH_SIZE) + hash = 0; + } + return NULL; +} + +/* + * lpfc_put_vmid_from_hastable - put the VMID in the hash table + * @vport: The virtual port for which this call is being executed. + * @hash - calculated hash value + * @vmp: Pointer to a VMID entry representing a VM sending IO + * + * This routine will insert the newly acquired vmid entity in the hash table. + * Make sure to acquire the appropriate lock before invoking this routine. + */ +int +lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash, + struct lpfc_vmid *vmp) +{ + int count = 0; + + while (count < LPFC_VMID_HASH_SIZE) { + if (!vport->hash_table[hash]) { + vport->hash_table[hash] = vmp; + vmp->hash_index = hash; + return 1; + } + /* if the slot is already occupied, a collision has occurred. */ + /* Store in the next available slot */ + count++; + hash++; + /* table is full */ + if (hash == LPFC_VMID_HASH_SIZE) + hash = 0; + } + return 0; +} + +/* + * lpfc_vmid_hash_fn- creates a hash value of the UUID + * @uuid: uuid associated with the VE + * @len: length of the UUID + * Returns the calculated hash value + */ +int lpfc_vmid_hash_fn(char *vmid, int len) +{ + int c; + int hash = 0; + + if (len == 0) + return 0; + while (len--) { + c = *vmid++; + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + + hash = (hash + (c << LPFC_VMID_HASH_SHIFT) + + (c >> LPFC_VMID_HASH_SHIFT)) * 19; + } + + return hash & LPFC_VMID_HASH_MASK; +} + +/* + * lpfc_vmid_update_entry - update the vmid entry in the hash table + * @vport: The virtual port for which this call is being executed. + * @cmd: address of scsi cmmd descriptor + * @vmp: Pointer to a VMID entry representing a VM sending IO + * @tag: VMID tag + */ +void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd + *cmd, struct lpfc_vmid *vmp, + union lpfc_vmid_io_tag *tag) +{ + u64 *lta; + + if (vport->vmid_priority_tagging) + tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid; + else + tag->app_id = vmp->un.app_id; + + if (cmd->sc_data_direction == DMA_TO_DEVICE) + vmp->io_wr_cnt++; + else + vmp->io_rd_cnt++; + + /* update the last access timestamp in the table */ + lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id()); + *lta = jiffies; +} + +void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid) +{ + u32 hash; + struct lpfc_vmid *pvmid; + + if (vport->port_type == LPFC_PHYSICAL_PORT) { + vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); + } else { + hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len); + pvmid = + lpfc_get_vmid_from_hastable(vport->phba->pport, hash, + vmid->host_vmid); + if (!pvmid) + vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid; + else + vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); + } +} + /** * lpfc_queuecommand - scsi_host_template queuecommand entry point * @cmnd: Pointer to scsi_cmnd data structure.