Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pw1Q6-0000Jb-EL for mharc-grub-devel@gnu.org; Mon, 08 May 2023 10:00:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pw1Q2-0008R2-TD for grub-devel@gnu.org; Mon, 08 May 2023 10:00:50 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pw1Q0-0006LD-2Y for grub-devel@gnu.org; Mon, 08 May 2023 10:00:50 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 348DovDT029623 for ; Mon, 8 May 2023 14:00:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=KdfgQIDt5ZCTdYxKzOiniocNvn17gKsNynfGbOC9XQo=; b=i2Jn1u9myQy/EUMSnWOoGXuWkcYwU5RAbn4Ch+xyZnxEb7JJ5JFRYuNyNxPI0INg2gjl AjRCJsORfrfQXBZYebFfE+FcHK0CvDJlIQ20oscRvBhM8ZQ2uzuepz/9BctkbBs2Vw69 rXNmsAvCImdUgRqTMOpByR4ZlzjGFb8EaGD33bDWT71zejwXYP1x/tW7Z1MOX2SJ9erX RXgGAcMNw8yURMvrIkDTZq2ASxdFqVVPTs5/0OcMAJCiZEkr294niU8XvyBYxPjZhMIK mEivaz54RLvGqqHE1EkkwKvabJfB4/yzfhtLHqwMgLQpnsxMKJvQJ8LgT1FPW5cil7GA BQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qf1xss5q5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 08 May 2023 14:00:40 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 348E0YOS015777 for ; Mon, 8 May 2023 14:00:39 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qf1xss5mm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 May 2023 14:00:39 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3484EYDr020931; Mon, 8 May 2023 14:00:36 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qde5fgxt5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 May 2023 14:00:36 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 348E0WO627198004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 May 2023 14:00:32 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 674DC2004E; Mon, 8 May 2023 14:00:32 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F00F20063; Mon, 8 May 2023 14:00:29 +0000 (GMT) Received: from li-5fd77d4c-2a67-11b2-a85c-de894c326bed.ibm.com.com (unknown [9.43.93.74]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 8 May 2023 14:00:28 +0000 (GMT) From: Avnish Chouhan To: grub-devel@gnu.org Cc: meghanaprakash@in.ibm.com, brking@linux.vnet.ibm.com, mchauras@linux.vnet.ibm.com, mamatha4@linux.vnet.ibm.com, rharwood@redhat.com, mlewando@redhat.com, Avnish Chouhan , Diego Domingos Subject: [PATCH 5/6] ieee1275: add support for NVMeoFC Date: Mon, 8 May 2023 19:28:39 +0530 Message-Id: <20230508135840.47765-6-avnish@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230508135840.47765-1-avnish@linux.vnet.ibm.com> References: <20230508135840.47765-1-avnish@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bMmtnJ3TXodMsLEVKGsduzIMiSMEKdvU X-Proofpoint-GUID: vGYjsqXWmH2TXwdmdBu7H6gk0s5U_0IP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-08_10,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 suspectscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305080091 Received-SPF: none client-ip=148.163.158.5; envelope-from=avnish@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 May 2023 14:00:51 -0000 This patch implements the functions to scan and discovery of NVMeoFC. Signed-off-by: Diego Domingos Signed-off-by: Avnish Chouhan --- grub-core/disk/ieee1275/ofdisk.c | 390 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 296 insertions(+), 94 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index afdc272..cea10e1 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -24,6 +24,8 @@ #include #include #include +#define EXTEND_PATH_64 64 +#define EXTEND_PATH_512 512 static char *last_devpath; static grub_ieee1275_ihandle_t last_ihandle; @@ -207,116 +209,316 @@ dev_iterate_real (const char *name, const char *path) } static void -dev_iterate (const struct grub_ieee1275_devalias *alias) +dev_iterate_fcp_disks(const struct grub_ieee1275_devalias *alias) { - if (grub_strcmp (alias->type, "fcp") == 0) + /* + * If we are dealing with fcp devices, we need + * to find the WWPNs and LUNs to iterate them + */ + grub_ieee1275_ihandle_t ihandle; + grub_uint64_t *ptr_targets, *ptr_luns, k, l; + unsigned int i, j, pos; + char *buf, *bufptr; + struct set_fcp_targets_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t nentries; + grub_ieee1275_cell_t table; + } args_targets; + + struct set_fcp_luns_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t wwpn_h; + grub_ieee1275_cell_t wwpn_l; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t nentries; + grub_ieee1275_cell_t table; + } args_luns; + + struct args_ret + { + grub_uint64_t addr; + grub_uint64_t len; + }; + struct args_ret *targets_table; + struct args_ret *luns_table; + + if (grub_ieee1275_open (alias->path, &ihandle)) { - /* - * If we are dealing with fcp devices, we need - * to find the WWPNs and LUNs to iterate them - */ - grub_ieee1275_ihandle_t ihandle; - grub_uint64_t *ptr_targets, *ptr_luns, k, l; - unsigned int i, j, pos; - char *buf, *bufptr; - struct set_fcp_targets_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t nentries; - grub_ieee1275_cell_t table; - } args_targets; - - struct set_fcp_luns_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t wwpn_h; - grub_ieee1275_cell_t wwpn_l; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t nentries; - grub_ieee1275_cell_t table; - } args_luns; - - struct args_ret - { - grub_uint64_t addr; - grub_uint64_t len; - }; + grub_dprintf("disk", "failed to open the disk while iterating FCP disk path=%s\n", alias->path); + return; + } + + /* Setup the fcp-targets method to call via pfw*/ + INIT_IEEE1275_COMMON (&args_targets.common, "call-method", 2, 3); + args_targets.method = (grub_ieee1275_cell_t) "fcp-targets"; + args_targets.ihandle = ihandle; - if(grub_ieee1275_open (alias->path, &ihandle)) + /* Setup the fcp-luns method to call via pfw */ + INIT_IEEE1275_COMMON (&args_luns.common, "call-method", 4, 3); + args_luns.method = (grub_ieee1275_cell_t) "fcp-luns"; + args_luns.ihandle = ihandle; + if (IEEE1275_CALL_ENTRY_FN (&args_targets) == -1) + { + grub_dprintf("disk", "failed to get the targets while iterating FCP disk path=%s\n", alias->path); + grub_ieee1275_close(ihandle); + return; + } + /* Allocate memory for building the path */ + buf = grub_malloc (grub_strlen (alias->path) + EXTEND_PATH_64); + if (!buf) + { + grub_ieee1275_close(ihandle); + return; + } + bufptr = grub_stpcpy (buf, alias->path); + + /* + * Iterate over entries returned by pfw. Each entry contains a + * pointer to wwpn table and his length. + */ + targets_table = (struct args_ret *)(args_targets.table); + for (i=0; i< args_targets.nentries; i++) + { + ptr_targets = (grub_uint64_t*) targets_table[i].addr; + /* Iterate over all wwpns in given table */ + for (k=0; kpath); - return; + args_luns.wwpn_l = (grub_ieee1275_cell_t) (*ptr_targets); + args_luns.wwpn_h = (grub_ieee1275_cell_t) (*ptr_targets >> 32); + pos = grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, + *ptr_targets++); + /* Get the luns for given wwpn target */ + if (IEEE1275_CALL_ENTRY_FN (&args_luns) == -1) + { + grub_dprintf("disk", "failed to get the LUNS while iterating FCP disk path=%s\n", buf); + grub_ieee1275_close (ihandle); + grub_free (buf); + return; + } + luns_table = (struct args_ret *)(args_luns.table); + + /* Iterate over all LUNs */ + for (j=0; jpath) + EXTEND_PATH_512); + if (!buf || !nvme_controllers_table) + { + grub_free(nvme_controllers_table); + grub_free(buf); + + return; + } + + /* Copy the alias->path to buf so we can work with */ + bufptr = grub_stpcpy (buf, alias->path); + grub_snprintf (bufptr, 32, "/nvme-of"); + + /* + * Open the nvme-of layer + * Ex. /pci@bus/fibre-channel@@dev,func/nvme-of + */ + if (grub_ieee1275_open (buf, &ihandle)) + { + grub_dprintf("disk", "failed to open the disk while iterating FCP disk path=%s\n", buf); + grub_free(nvme_controllers_table); + grub_free(buf); + return; + } + + /* + * Call to nvme-discovery-controllers method from the nvme-of layer + * to get a list of the NVMe discovery controllers per the binding + */ + INIT_IEEE1275_COMMON (&nvme_discovery_controllers_args.common, "call-method", 2, 2); + nvme_discovery_controllers_args.method = (grub_ieee1275_cell_t) "nvme-discovery-controllers"; + nvme_discovery_controllers_args.ihandle = ihandle; + if (IEEE1275_CALL_ENTRY_FN (&nvme_discovery_controllers_args) == -1) + { + grub_dprintf("disk", "failed to get the targets while iterating FCP disk path=%s\n", buf); + grub_free(nvme_controllers_table); + grub_free(buf); + grub_ieee1275_close(ihandle); + return; + } + + /* After closing the device, the info is lost. So lets copy each buffer in the buffers table */ + discovery_controllers_table.len = (grub_uint32_t) nvme_discovery_controllers_args.nentries; + + for (i = 0; i < discovery_controllers_table.len; i++) + { + discovery_controllers_table.table[i] = ((grub_uint64_t*)nvme_discovery_controllers_args.table)[i]; + } - /* Setup the fcp-targets method to call via pfw*/ - INIT_IEEE1275_COMMON (&args_targets.common, "call-method", 2, 3); - args_targets.method = (grub_ieee1275_cell_t) "fcp-targets"; - args_targets.ihandle = ihandle; + grub_ieee1275_close(ihandle); + grub_dprintf("ofdisk","NVMeoF: Found %d discovery controllers\n", discovery_controllers_table.len); - /* Setup the fcp-luns method to call via pfw */ - INIT_IEEE1275_COMMON (&args_luns.common, "call-method", 4, 3); - args_luns.method = (grub_ieee1275_cell_t) "fcp-luns"; - args_luns.ihandle = ihandle; - if (IEEE1275_CALL_ENTRY_FN (&args_targets) == -1) + /* For each nvme discovery controller */ + for (current_buffer_index = 0; current_buffer_index < (int) discovery_controllers_table.len; current_buffer_index++) + { + grub_snprintf (bufptr, 64, "/nvme-of/controller@%" PRIxGRUB_UINT64_T ",ffff", + discovery_controllers_table.table[current_buffer_index]); + grub_dprintf("ofdisk", "nvmeof controller=%s\n", buf); + if (grub_ieee1275_open (buf, &ihandle)) { - grub_dprintf("disk", "failed to get the targets while iterating FCP disk path=%s\n", alias->path); - grub_ieee1275_close(ihandle); - return; + grub_dprintf("ofdisk", "failed to open the disk while getting nvme-controllers path=%s\n", buf); + continue; } - buf = grub_malloc (grub_strlen (alias->path) + 32 + 32); - if (!buf) + INIT_IEEE1275_COMMON (&nvme_controllers_args.common, "call-method", 2, 2); + nvme_controllers_args.method = (grub_ieee1275_cell_t) "nvme-controllers"; + nvme_controllers_args.ihandle = ihandle; + nvme_controllers_args.catch_result = 0; + + if (IEEE1275_CALL_ENTRY_FN (&nvme_controllers_args) == -1) { + grub_dprintf("ofdisk", "failed to get the nvme-controllers while iterating FCP disk path\n"); grub_ieee1275_close(ihandle); - return; + continue; } - bufptr = grub_stpcpy (buf, alias->path); - /* - * Iterate over entries returned by pfw. Each entry contains a - * pointer to wwpn table and his length. - */ - struct args_ret *targets_table = (struct args_ret *)(args_targets.table); - for (i=0; i< args_targets.nentries; i++) + /* Copy the buffer list to nvme_controllers_table */ + nvme_controllers_table_entries = ((grub_uint32_t) nvme_controllers_args.nentries); + nvme_controllers_table_buf = (struct nvme_controllers_table_entry*) nvme_controllers_args.table; + for (i = 0; i < nvme_controllers_table_entries; i++) { - ptr_targets = (grub_uint64_t*)(grub_uint32_t) targets_table[i].addr; - /* Iterate over all wwpns in given table */ - for(k=0;k> 32); - pos = grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, - *ptr_targets++); - /* Get the luns for given wwpn target */ - if (IEEE1275_CALL_ENTRY_FN (&args_luns) == -1) - { - grub_dprintf("disk", "failed to get the LUNS while iterating FCP disk path=%s\n", buf); - grub_ieee1275_close (ihandle); - grub_free (buf); - return; - } - struct args_ret *luns_table = (struct args_ret *)(args_luns.table); + nvme_controllers_table[i].id = (grub_uint16_t) nvme_controllers_table_buf[i].id; + grub_strcpy(nvme_controllers_table[i].wwpn, nvme_controllers_table_buf[i].wwpn); + grub_strcpy(nvme_controllers_table[i].nqn, nvme_controllers_table_buf[i].nqn); + } + grub_ieee1275_close(ihandle); + grub_dprintf("ofdisk", "NVMeoF: found %d nvme controllers\n", (int) nvme_controllers_args.nentries); - /* Iterate over all LUNs */ - for(j=0;jtype, "fcp") == 0) + { + /* Iterate disks */ + dev_iterate_fcp_disks(alias); + /* Iterate NVMeoF */ + dev_iterate_fcp_nvmeof(alias); } else if (grub_strcmp (alias->type, "vscsi") == 0) { -- 2.31.1