Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5411446ybi; Tue, 4 Jun 2019 06:21:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx01rfoglSS3ioeJN3TLv1AF85bUsBdL2NAq7UES3rHtaOpxFf1PML5DI1uDhK+ItjgCYLs X-Received: by 2002:a65:418d:: with SMTP id a13mr35869878pgq.332.1559654470264; Tue, 04 Jun 2019 06:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559654470; cv=none; d=google.com; s=arc-20160816; b=pBvxmL/gpls/DDZGCLtvN8O2FFTcoS8IMsJaws+IKYK9z+lOZ/+8dlOKAgI2ok9FRN zhcOBU6SgcjKVydTxQVkrd+Csmaq7fRqhgQBZuMFKvs9O/QaymkyZUxzNv3bOtOpvQ0C ZOxzxZEF/KTkGaTs0j0xaYQ6q56e90+gccp1x72fl5BkN/PoQMlh9ODmZ3zZuX4z7Dfb F6mPEnOZJ7KDCnZ+v47t1kbj+DDL9KW9Y9RPVxDft7cL5qPc09WGV8TmOBVbPraIN8nS PWJFPudi7E/6sPhDBRXn/Jdw+AIv6sIe7AMexSqoyw59ELhp320cDaKyv9oak7a0KpJl aY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=iGGz8aJS305f8zkEMQQLmC9ZNt7J1jEUCbTcSQRPp8c=; b=sx6d6Ogp9Egfiv8ofMucbITKhfzdAzWJSvTAV5Jq0/kZ655bwLT4cJ+vtbcqoMG06w 8QIdtwOeoWuLsHeaTwf6TIJ8NlWmBzqu+AgvpmI3k3/eX3R52PZRRsxLrt5Em8mibyFR BriUseoDyerRONDjzQ4jCnhUzAvMmZ+lvI9ShKOjOzAROE+rWoIsutTz29JnEHOQLFES TrW98uUTnGspvVMbFmUCM/mB1mQQk4cxS+n3jLEXLjq1icJdIvn59L8BOdsTrTN2+b54 DTg/WZMxq0i3Vm/s1OI9DPQTPi6XkT6EmGpvPNUDwPgFkGbnoz5HEbMLAkhKBUaVrbym qmWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=N8jkDEwp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si1887201pff.266.2019.06.04.06.20.52; Tue, 04 Jun 2019 06:21:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=N8jkDEwp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbfFDNTH (ORCPT + 99 others); Tue, 4 Jun 2019 09:19:07 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:39376 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727458AbfFDNTC (ORCPT ); Tue, 4 Jun 2019 09:19:02 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x54DIEoq119974; Tue, 4 Jun 2019 08:18:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1559654294; bh=iGGz8aJS305f8zkEMQQLmC9ZNt7J1jEUCbTcSQRPp8c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=N8jkDEwpWuoOdA9t6AYdQYMuDLTffL+VUteLJp1OVzUM3ExXPoBOaemiDe1fXwRLR Glb+o8SJQmgSkmPXTcE5fy+Tosxatv+/DcmsyY7omogGVF2OYIUCZp5iShHHYCT7rO lpwRrvi1TP5cLGxqyTOADGGeWmDgY/RHw4XiW754= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x54DIENZ009122 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2019 08:18:14 -0500 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 4 Jun 2019 08:18:14 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 4 Jun 2019 08:18:14 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x54DGdGW098972; Tue, 4 Jun 2019 08:18:09 -0500 From: Kishon Vijay Abraham I To: Tom Joseph , Bjorn Helgaas , Rob Herring , Mark Rutland , Lorenzo Pieralisi , Arnd Bergmann , Gustavo Pimentel CC: Greg Kroah-Hartman , Frank Rowand , Jingoo Han , , , , , , , Kishon Vijay Abraham I Subject: [RFC PATCH 16/30] PCI: endpoint: Assign function number of each PF in EPC core Date: Tue, 4 Jun 2019 18:45:02 +0530 Message-ID: <20190604131516.13596-17-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604131516.13596-1-kishon@ti.com> References: <20190604131516.13596-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The endpoint core relies on the drivers that invoke the API to bind a controller driver with a function driver to allocate and assign a function number to each physical function. Ideally the function numbers should be assinged by EPC core for each of the physical function that is bound to the EPC. Assign function number of each PF in EPC core and remove function number allocation in endpoint configfs. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-ep-cfs.c | 27 +++++---------------------- drivers/pci/endpoint/pci-epc-core.c | 12 +++++++++++- include/linux/pci-epc.h | 2 ++ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index d1288a0bd530..e7e8367eead1 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -29,7 +29,6 @@ struct pci_epc_group { struct config_group group; struct pci_epc *epc; bool start; - unsigned long function_num_map; }; static inline struct pci_epf_group *to_pci_epf_group(struct config_item *item) @@ -89,37 +88,22 @@ static int pci_epc_epf_link(struct config_item *epc_item, struct config_item *epf_item) { int ret; - u32 func_no = 0; struct pci_epf_group *epf_group = to_pci_epf_group(epf_item); struct pci_epc_group *epc_group = to_pci_epc_group(epc_item); struct pci_epc *epc = epc_group->epc; struct pci_epf *epf = epf_group->epf; - func_no = find_first_zero_bit(&epc_group->function_num_map, - BITS_PER_LONG); - if (func_no >= BITS_PER_LONG) - return -EINVAL; - - set_bit(func_no, &epc_group->function_num_map); - epf->func_no = func_no; - ret = pci_epc_add_epf(epc, epf); if (ret) - goto err_add_epf; + return ret; ret = pci_epf_bind(epf); - if (ret) - goto err_epf_bind; + if (ret) { + pci_epc_remove_epf(epc, epf); + return ret; + } return 0; - -err_epf_bind: - pci_epc_remove_epf(epc, epf); - -err_add_epf: - clear_bit(func_no, &epc_group->function_num_map); - - return ret; } static void pci_epc_epf_unlink(struct config_item *epc_item, @@ -134,7 +118,6 @@ static void pci_epc_epf_unlink(struct config_item *epc_item, epc = epc_group->epc; epf = epf_group->epf; - clear_bit(epf->func_no, &epc_group->function_num_map); pci_epf_unbind(epf); pci_epc_remove_epf(epc, epf); } diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index eea07f9ec5ff..e5d8d8370686 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -471,6 +471,8 @@ EXPORT_SYMBOL_GPL(pci_epc_write_header); */ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf) { + u32 func_no = 0; + if (epf->epc) return -EBUSY; @@ -480,9 +482,16 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf) if (epf->func_no > epc->max_functions - 1) return -EINVAL; + mutex_lock(&epc->lock); + func_no = find_first_zero_bit(&epc->function_num_map, + BITS_PER_LONG); + if (func_no >= BITS_PER_LONG) + return -EINVAL; + + set_bit(func_no, &epc->function_num_map); + epf->func_no = func_no; epf->epc = epc; - mutex_lock(&epc->lock); list_add_tail(&epf->list, &epc->pci_epf); mutex_unlock(&epc->lock); @@ -503,6 +512,7 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf) return; mutex_lock(&epc->lock); + clear_bit(epf->func_no, &epc->function_num_map); list_del(&epf->list); mutex_unlock(&epc->lock); } diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index a430d02aa1ff..ad118a3f1330 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -89,6 +89,7 @@ struct pci_epc_mem { * @max_functions: max number of functions that can be configured in this EPC * @group: configfs group representing the PCI EPC device * @lock: mutex to protect pci_epc ops + * @function_num_map: bitmap to manage physical function number * @notifier: used to notify EPF of any EPC events (like linkup) */ struct pci_epc { @@ -100,6 +101,7 @@ struct pci_epc { struct config_group *group; /* mutex to protect against concurrent access of EP controller */ struct mutex lock; + unsigned long function_num_map; struct atomic_notifier_head notifier; }; -- 2.17.1