2018-01-26 18:50:27 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2021-07-03 15:13:02 +00:00
|
|
|
/*
|
2017-04-10 13:55:10 +00:00
|
|
|
* PCI Endpoint *Function* (EPF) header file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Texas Instruments
|
|
|
|
* Author: Kishon Vijay Abraham I <kishon@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_PCI_EPF_H
|
|
|
|
#define __LINUX_PCI_EPF_H
|
|
|
|
|
2021-02-01 19:58:02 +00:00
|
|
|
#include <linux/configfs.h>
|
2017-04-10 13:55:10 +00:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/mod_devicetable.h>
|
2017-08-15 19:02:16 +00:00
|
|
|
#include <linux/pci.h>
|
2017-04-10 13:55:10 +00:00
|
|
|
|
|
|
|
struct pci_epf;
|
2021-02-01 19:57:58 +00:00
|
|
|
enum pci_epc_interface_type;
|
2017-04-10 13:55:10 +00:00
|
|
|
|
|
|
|
enum pci_barno {
|
2021-02-01 19:57:56 +00:00
|
|
|
NO_BAR = -1,
|
2017-04-10 13:55:10 +00:00
|
|
|
BAR_0,
|
|
|
|
BAR_1,
|
|
|
|
BAR_2,
|
|
|
|
BAR_3,
|
|
|
|
BAR_4,
|
|
|
|
BAR_5,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct pci_epf_header - represents standard configuration header
|
|
|
|
* @vendorid: identifies device manufacturer
|
|
|
|
* @deviceid: identifies a particular device
|
|
|
|
* @revid: specifies a device-specific revision identifier
|
|
|
|
* @progif_code: identifies a specific register-level programming interface
|
|
|
|
* @subclass_code: identifies more specifically the function of the device
|
|
|
|
* @baseclass_code: broadly classifies the type of function the device performs
|
|
|
|
* @cache_line_size: specifies the system cacheline size in units of DWORDs
|
|
|
|
* @subsys_vendor_id: vendor of the add-in card or subsystem
|
|
|
|
* @subsys_id: id specific to vendor
|
|
|
|
* @interrupt_pin: interrupt pin the device (or device function) uses
|
|
|
|
*/
|
|
|
|
struct pci_epf_header {
|
|
|
|
u16 vendorid;
|
|
|
|
u16 deviceid;
|
|
|
|
u8 revid;
|
|
|
|
u8 progif_code;
|
|
|
|
u8 subclass_code;
|
|
|
|
u8 baseclass_code;
|
|
|
|
u8 cache_line_size;
|
|
|
|
u16 subsys_vendor_id;
|
|
|
|
u16 subsys_id;
|
|
|
|
enum pci_interrupt_pin interrupt_pin;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct pci_epf_ops - set of function pointers for performing EPF operations
|
|
|
|
* @bind: ops to perform when a EPC device has been bound to EPF device
|
|
|
|
* @unbind: ops to perform when a binding has been lost between a EPC device
|
|
|
|
* and EPF device
|
2021-02-01 19:58:01 +00:00
|
|
|
* @add_cfs: ops to initialize function specific configfs attributes
|
2017-04-10 13:55:10 +00:00
|
|
|
*/
|
|
|
|
struct pci_epf_ops {
|
|
|
|
int (*bind)(struct pci_epf *epf);
|
|
|
|
void (*unbind)(struct pci_epf *epf);
|
2021-02-01 19:58:01 +00:00
|
|
|
struct config_group *(*add_cfs)(struct pci_epf *epf,
|
|
|
|
struct config_group *group);
|
2017-04-10 13:55:10 +00:00
|
|
|
};
|
|
|
|
|
PCI: endpoint: Use callback mechanism for passing events from EPC to EPF
Instead of using the notifiers for passing the events from EPC to EPF,
let's introduce a callback based mechanism where the EPF drivers can
populate relevant callbacks for EPC events they want to subscribe.
The use of notifiers in kernel is not recommended if there is a real link
between the sender and receiver, like in this case. Also, the existing
atomic notifier forces the notification functions to be in atomic context
while the caller may be in non-atomic context. For instance, the two
in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are
calling the notifier functions in non-atomic context (from threaded IRQ
handlers). This creates a sleeping in atomic context issue with the
existing EPF_TEST driver that calls the EPC APIs that may sleep.
For all these reasons, let's get rid of the notifier chains and use the
simple callback mechanism for signalling the events from EPC to EPF
drivers. This preserves the context of the caller and avoids the latency
of going through a separate interface for triggering the notifications.
As a first step of the transition, the core_init() callback is introduced
in this commit, that'll replace the existing CORE_INIT notifier used for
signalling the init complete event from EPC.
During the occurrence of the event, EPC will go over the list of EPF
drivers attached to it and will call the core_init() callback if available.
Link: https://lore.kernel.org/linux-pci/20230124071158.5503-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Acked-by: Kishon Vijay Abraham I <kishon@kernel.org>
2023-01-24 07:11:57 +00:00
|
|
|
/**
|
|
|
|
* struct pci_epf_event_ops - Callbacks for capturing the EPC events
|
|
|
|
* @core_init: Callback for the EPC initialization complete event
|
2023-01-24 07:11:58 +00:00
|
|
|
* @link_up: Callback for the EPC link up event
|
PCI: endpoint: Use callback mechanism for passing events from EPC to EPF
Instead of using the notifiers for passing the events from EPC to EPF,
let's introduce a callback based mechanism where the EPF drivers can
populate relevant callbacks for EPC events they want to subscribe.
The use of notifiers in kernel is not recommended if there is a real link
between the sender and receiver, like in this case. Also, the existing
atomic notifier forces the notification functions to be in atomic context
while the caller may be in non-atomic context. For instance, the two
in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are
calling the notifier functions in non-atomic context (from threaded IRQ
handlers). This creates a sleeping in atomic context issue with the
existing EPF_TEST driver that calls the EPC APIs that may sleep.
For all these reasons, let's get rid of the notifier chains and use the
simple callback mechanism for signalling the events from EPC to EPF
drivers. This preserves the context of the caller and avoids the latency
of going through a separate interface for triggering the notifications.
As a first step of the transition, the core_init() callback is introduced
in this commit, that'll replace the existing CORE_INIT notifier used for
signalling the init complete event from EPC.
During the occurrence of the event, EPC will go over the list of EPF
drivers attached to it and will call the core_init() callback if available.
Link: https://lore.kernel.org/linux-pci/20230124071158.5503-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Acked-by: Kishon Vijay Abraham I <kishon@kernel.org>
2023-01-24 07:11:57 +00:00
|
|
|
*/
|
|
|
|
struct pci_epc_event_ops {
|
|
|
|
int (*core_init)(struct pci_epf *epf);
|
2023-01-24 07:11:58 +00:00
|
|
|
int (*link_up)(struct pci_epf *epf);
|
PCI: endpoint: Use callback mechanism for passing events from EPC to EPF
Instead of using the notifiers for passing the events from EPC to EPF,
let's introduce a callback based mechanism where the EPF drivers can
populate relevant callbacks for EPC events they want to subscribe.
The use of notifiers in kernel is not recommended if there is a real link
between the sender and receiver, like in this case. Also, the existing
atomic notifier forces the notification functions to be in atomic context
while the caller may be in non-atomic context. For instance, the two
in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are
calling the notifier functions in non-atomic context (from threaded IRQ
handlers). This creates a sleeping in atomic context issue with the
existing EPF_TEST driver that calls the EPC APIs that may sleep.
For all these reasons, let's get rid of the notifier chains and use the
simple callback mechanism for signalling the events from EPC to EPF
drivers. This preserves the context of the caller and avoids the latency
of going through a separate interface for triggering the notifications.
As a first step of the transition, the core_init() callback is introduced
in this commit, that'll replace the existing CORE_INIT notifier used for
signalling the init complete event from EPC.
During the occurrence of the event, EPC will go over the list of EPF
drivers attached to it and will call the core_init() callback if available.
Link: https://lore.kernel.org/linux-pci/20230124071158.5503-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Acked-by: Kishon Vijay Abraham I <kishon@kernel.org>
2023-01-24 07:11:57 +00:00
|
|
|
};
|
|
|
|
|
2017-04-10 13:55:10 +00:00
|
|
|
/**
|
|
|
|
* struct pci_epf_driver - represents the PCI EPF driver
|
|
|
|
* @probe: ops to perform when a new EPF device has been bound to the EPF driver
|
|
|
|
* @remove: ops to perform when the binding between the EPF device and EPF
|
|
|
|
* driver is broken
|
|
|
|
* @driver: PCI EPF driver
|
|
|
|
* @ops: set of function pointers for performing EPF operations
|
|
|
|
* @owner: the owner of the module that registers the PCI EPF driver
|
2018-04-02 13:29:35 +00:00
|
|
|
* @epf_group: list of configfs group corresponding to the PCI EPF driver
|
2017-04-10 13:55:10 +00:00
|
|
|
* @id_table: identifies EPF devices for probing
|
|
|
|
*/
|
|
|
|
struct pci_epf_driver {
|
|
|
|
int (*probe)(struct pci_epf *epf);
|
2021-07-13 19:35:18 +00:00
|
|
|
void (*remove)(struct pci_epf *epf);
|
2017-04-10 13:55:10 +00:00
|
|
|
|
|
|
|
struct device_driver driver;
|
|
|
|
struct pci_epf_ops *ops;
|
|
|
|
struct module *owner;
|
2018-04-02 13:29:35 +00:00
|
|
|
struct list_head epf_group;
|
2017-04-10 13:55:10 +00:00
|
|
|
const struct pci_epf_device_id *id_table;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
|
|
|
|
driver))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct pci_epf_bar - represents the BAR of EPF device
|
|
|
|
* @phys_addr: physical address that should be mapped to the BAR
|
2020-02-25 08:17:02 +00:00
|
|
|
* @addr: virtual address corresponding to the @phys_addr
|
2017-04-10 13:55:10 +00:00
|
|
|
* @size: the size of the address space present in BAR
|
2021-07-03 15:13:02 +00:00
|
|
|
* @barno: BAR number
|
|
|
|
* @flags: flags that are set for the BAR
|
2017-04-10 13:55:10 +00:00
|
|
|
*/
|
|
|
|
struct pci_epf_bar {
|
|
|
|
dma_addr_t phys_addr;
|
2020-02-25 08:17:02 +00:00
|
|
|
void *addr;
|
2017-04-10 13:55:10 +00:00
|
|
|
size_t size;
|
2018-03-28 11:50:07 +00:00
|
|
|
enum pci_barno barno;
|
|
|
|
int flags;
|
2017-04-10 13:55:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct pci_epf - represents the PCI EPF device
|
|
|
|
* @dev: the PCI EPF device
|
|
|
|
* @name: the name of the PCI EPF device
|
|
|
|
* @header: represents standard configuration header
|
|
|
|
* @bar: represents the BAR of EPF device
|
|
|
|
* @msi_interrupts: number of MSI interrupts required by this function
|
2021-07-03 15:13:02 +00:00
|
|
|
* @msix_interrupts: number of MSI-X interrupts required by this function
|
2021-08-19 12:33:37 +00:00
|
|
|
* @func_no: unique (physical) function number within this endpoint device
|
|
|
|
* @vfunc_no: unique virtual function number within a physical function
|
2017-04-10 13:55:10 +00:00
|
|
|
* @epc: the EPC device to which this EPF device is bound
|
2021-08-19 12:33:37 +00:00
|
|
|
* @epf_pf: the physical EPF device to which this virtual EPF device is bound
|
2017-04-10 13:55:10 +00:00
|
|
|
* @driver: the EPF driver to which this EPF device is bound
|
|
|
|
* @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
|
2020-02-24 09:53:37 +00:00
|
|
|
* @lock: mutex to protect pci_epf_ops
|
2021-02-01 19:57:58 +00:00
|
|
|
* @sec_epc: the secondary EPC device to which this EPF device is bound
|
|
|
|
* @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
|
|
|
|
* EPC device
|
|
|
|
* @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
|
|
|
|
* @sec_epc_func_no: unique (physical) function number within the secondary EPC
|
2021-02-01 19:58:02 +00:00
|
|
|
* @group: configfs group associated with the EPF device
|
2021-08-19 12:33:37 +00:00
|
|
|
* @is_bound: indicates if bind notification to function driver has been invoked
|
|
|
|
* @is_vf: true - virtual function, false - physical function
|
|
|
|
* @vfunction_num_map: bitmap to manage virtual function number
|
|
|
|
* @pci_vepf: list of virtual endpoint functions associated with this function
|
PCI: endpoint: Use callback mechanism for passing events from EPC to EPF
Instead of using the notifiers for passing the events from EPC to EPF,
let's introduce a callback based mechanism where the EPF drivers can
populate relevant callbacks for EPC events they want to subscribe.
The use of notifiers in kernel is not recommended if there is a real link
between the sender and receiver, like in this case. Also, the existing
atomic notifier forces the notification functions to be in atomic context
while the caller may be in non-atomic context. For instance, the two
in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are
calling the notifier functions in non-atomic context (from threaded IRQ
handlers). This creates a sleeping in atomic context issue with the
existing EPF_TEST driver that calls the EPC APIs that may sleep.
For all these reasons, let's get rid of the notifier chains and use the
simple callback mechanism for signalling the events from EPC to EPF
drivers. This preserves the context of the caller and avoids the latency
of going through a separate interface for triggering the notifications.
As a first step of the transition, the core_init() callback is introduced
in this commit, that'll replace the existing CORE_INIT notifier used for
signalling the init complete event from EPC.
During the occurrence of the event, EPC will go over the list of EPF
drivers attached to it and will call the core_init() callback if available.
Link: https://lore.kernel.org/linux-pci/20230124071158.5503-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Acked-by: Kishon Vijay Abraham I <kishon@kernel.org>
2023-01-24 07:11:57 +00:00
|
|
|
* @event_ops: Callbacks for capturing the EPC events
|
2017-04-10 13:55:10 +00:00
|
|
|
*/
|
|
|
|
struct pci_epf {
|
|
|
|
struct device dev;
|
|
|
|
const char *name;
|
|
|
|
struct pci_epf_header *header;
|
|
|
|
struct pci_epf_bar bar[6];
|
|
|
|
u8 msi_interrupts;
|
2018-07-19 08:32:12 +00:00
|
|
|
u16 msix_interrupts;
|
2017-04-10 13:55:10 +00:00
|
|
|
u8 func_no;
|
2021-08-19 12:33:37 +00:00
|
|
|
u8 vfunc_no;
|
2017-04-10 13:55:10 +00:00
|
|
|
|
|
|
|
struct pci_epc *epc;
|
2021-08-19 12:33:37 +00:00
|
|
|
struct pci_epf *epf_pf;
|
2017-04-10 13:55:10 +00:00
|
|
|
struct pci_epf_driver *driver;
|
|
|
|
struct list_head list;
|
2020-02-24 09:53:37 +00:00
|
|
|
/* mutex to protect against concurrent access of pci_epf_ops */
|
|
|
|
struct mutex lock;
|
2021-02-01 19:57:58 +00:00
|
|
|
|
|
|
|
/* Below members are to attach secondary EPC to an endpoint function */
|
|
|
|
struct pci_epc *sec_epc;
|
|
|
|
struct list_head sec_epc_list;
|
|
|
|
struct pci_epf_bar sec_epc_bar[6];
|
|
|
|
u8 sec_epc_func_no;
|
2021-02-01 19:58:02 +00:00
|
|
|
struct config_group *group;
|
2021-08-19 12:33:37 +00:00
|
|
|
unsigned int is_bound;
|
|
|
|
unsigned int is_vf;
|
|
|
|
unsigned long vfunction_num_map;
|
|
|
|
struct list_head pci_vepf;
|
PCI: endpoint: Use callback mechanism for passing events from EPC to EPF
Instead of using the notifiers for passing the events from EPC to EPF,
let's introduce a callback based mechanism where the EPF drivers can
populate relevant callbacks for EPC events they want to subscribe.
The use of notifiers in kernel is not recommended if there is a real link
between the sender and receiver, like in this case. Also, the existing
atomic notifier forces the notification functions to be in atomic context
while the caller may be in non-atomic context. For instance, the two
in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are
calling the notifier functions in non-atomic context (from threaded IRQ
handlers). This creates a sleeping in atomic context issue with the
existing EPF_TEST driver that calls the EPC APIs that may sleep.
For all these reasons, let's get rid of the notifier chains and use the
simple callback mechanism for signalling the events from EPC to EPF
drivers. This preserves the context of the caller and avoids the latency
of going through a separate interface for triggering the notifications.
As a first step of the transition, the core_init() callback is introduced
in this commit, that'll replace the existing CORE_INIT notifier used for
signalling the init complete event from EPC.
During the occurrence of the event, EPC will go over the list of EPF
drivers attached to it and will call the core_init() callback if available.
Link: https://lore.kernel.org/linux-pci/20230124071158.5503-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Acked-by: Kishon Vijay Abraham I <kishon@kernel.org>
2023-01-24 07:11:57 +00:00
|
|
|
const struct pci_epc_event_ops *event_ops;
|
2017-04-10 13:55:10 +00:00
|
|
|
};
|
|
|
|
|
2020-02-25 08:17:02 +00:00
|
|
|
/**
|
|
|
|
* struct pci_epf_msix_tbl - represents the MSIX table entry structure
|
|
|
|
* @msg_addr: Writes to this address will trigger MSIX interrupt in host
|
|
|
|
* @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
|
|
|
|
* @vector_ctrl: Identifies if the function is prohibited from sending a message
|
|
|
|
* using this MSIX table entry
|
|
|
|
*/
|
|
|
|
struct pci_epf_msix_tbl {
|
|
|
|
u64 msg_addr;
|
|
|
|
u32 msg_data;
|
|
|
|
u32 vector_ctrl;
|
|
|
|
};
|
|
|
|
|
2017-04-10 13:55:10 +00:00
|
|
|
#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
|
|
|
|
|
|
|
|
#define pci_epf_register_driver(driver) \
|
|
|
|
__pci_epf_register_driver((driver), THIS_MODULE)
|
|
|
|
|
|
|
|
static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
|
|
|
|
{
|
|
|
|
dev_set_drvdata(&epf->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *epf_get_drvdata(struct pci_epf *epf)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(&epf->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_epf *pci_epf_create(const char *name);
|
|
|
|
void pci_epf_destroy(struct pci_epf *epf);
|
|
|
|
int __pci_epf_register_driver(struct pci_epf_driver *driver,
|
|
|
|
struct module *owner);
|
|
|
|
void pci_epf_unregister_driver(struct pci_epf_driver *driver);
|
2019-03-25 09:39:39 +00:00
|
|
|
void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
|
2021-02-01 19:57:58 +00:00
|
|
|
size_t align, enum pci_epc_interface_type type);
|
|
|
|
void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
|
|
|
|
enum pci_epc_interface_type type);
|
2017-04-10 13:55:10 +00:00
|
|
|
int pci_epf_bind(struct pci_epf *epf);
|
|
|
|
void pci_epf_unbind(struct pci_epf *epf);
|
2021-02-01 19:58:01 +00:00
|
|
|
struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf,
|
|
|
|
struct config_group *group);
|
2021-08-19 12:33:37 +00:00
|
|
|
int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
|
|
|
|
void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
|
2017-04-10 13:55:10 +00:00
|
|
|
#endif /* __LINUX_PCI_EPF_H */
|