Lines Matching +full:msi +full:- +full:x
1 // SPDX-License-Identifier: GPL-2.0
14 #include <linux/pci-epc.h>
15 #include <linux/pci-epf.h>
16 #include <linux/pci-ep-cfs.h>
35 * pci_epc_put() - release the PCI endpoint controller
45 module_put(epc->ops->owner); in pci_epc_put()
46 put_device(&epc->dev); in pci_epc_put()
51 * pci_epc_get() - get the PCI endpoint controller
59 int ret = -EINVAL; in pci_epc_get()
70 if (!try_module_get(epc->ops->owner)) { in pci_epc_get()
71 ret = -EINVAL; in pci_epc_get()
76 get_device(&epc->dev); in pci_epc_get()
87 * pci_epc_get_first_free_bar() - helper to get first unreserved BAR
101 free_bar = ffz(epc_features->reserved_bar); in pci_epc_get_first_free_bar()
110 * pci_epc_get_features() - get the features supported by EPC
124 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_get_features()
127 if (!epc->ops->get_features) in pci_epc_get_features()
130 mutex_lock(&epc->lock); in pci_epc_get_features()
131 epc_features = epc->ops->get_features(epc, func_no); in pci_epc_get_features()
132 mutex_unlock(&epc->lock); in pci_epc_get_features()
139 * pci_epc_stop() - stop the PCI link
146 if (IS_ERR(epc) || !epc->ops->stop) in pci_epc_stop()
149 mutex_lock(&epc->lock); in pci_epc_stop()
150 epc->ops->stop(epc); in pci_epc_stop()
151 mutex_unlock(&epc->lock); in pci_epc_stop()
156 * pci_epc_start() - start the PCI link
166 return -EINVAL; in pci_epc_start()
168 if (!epc->ops->start) in pci_epc_start()
171 mutex_lock(&epc->lock); in pci_epc_start()
172 ret = epc->ops->start(epc); in pci_epc_start()
173 mutex_unlock(&epc->lock); in pci_epc_start()
180 * pci_epc_raise_irq() - interrupt the host system
183 * @type: specify the type of interrupt; legacy, MSI or MSI-X
184 * @interrupt_num: the MSI or MSI-X interrupt number
186 * Invoke to raise an legacy, MSI or MSI-X interrupt
193 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_raise_irq()
194 return -EINVAL; in pci_epc_raise_irq()
196 if (!epc->ops->raise_irq) in pci_epc_raise_irq()
199 mutex_lock(&epc->lock); in pci_epc_raise_irq()
200 ret = epc->ops->raise_irq(epc, func_no, type, interrupt_num); in pci_epc_raise_irq()
201 mutex_unlock(&epc->lock); in pci_epc_raise_irq()
208 * pci_epc_get_msi() - get the number of MSI interrupt numbers allocated
209 * @epc: the EPC device to which MSI interrupts was requested
212 * Invoke to get the number of MSI interrupts allocated by the RC
218 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_get_msi()
221 if (!epc->ops->get_msi) in pci_epc_get_msi()
224 mutex_lock(&epc->lock); in pci_epc_get_msi()
225 interrupt = epc->ops->get_msi(epc, func_no); in pci_epc_get_msi()
226 mutex_unlock(&epc->lock); in pci_epc_get_msi()
238 * pci_epc_set_msi() - set the number of MSI interrupt numbers required
239 * @epc: the EPC device on which MSI has to be configured
241 * @interrupts: number of MSI interrupts required by the EPF
243 * Invoke to set the required number of MSI interrupts.
250 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions || in pci_epc_set_msi()
252 return -EINVAL; in pci_epc_set_msi()
254 if (!epc->ops->set_msi) in pci_epc_set_msi()
259 mutex_lock(&epc->lock); in pci_epc_set_msi()
260 ret = epc->ops->set_msi(epc, func_no, encode_int); in pci_epc_set_msi()
261 mutex_unlock(&epc->lock); in pci_epc_set_msi()
268 * pci_epc_get_msix() - get the number of MSI-X interrupt numbers allocated
269 * @epc: the EPC device to which MSI-X interrupts was requested
272 * Invoke to get the number of MSI-X interrupts allocated by the RC
278 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_get_msix()
281 if (!epc->ops->get_msix) in pci_epc_get_msix()
284 mutex_lock(&epc->lock); in pci_epc_get_msix()
285 interrupt = epc->ops->get_msix(epc, func_no); in pci_epc_get_msix()
286 mutex_unlock(&epc->lock); in pci_epc_get_msix()
296 * pci_epc_set_msix() - set the number of MSI-X interrupt numbers required
297 * @epc: the EPC device on which MSI-X has to be configured
299 * @interrupts: number of MSI-X interrupts required by the EPF
300 * @bir: BAR where the MSI-X table resides
301 * @offset: Offset pointing to the start of MSI-X table
303 * Invoke to set the required number of MSI-X interrupts.
310 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions || in pci_epc_set_msix()
312 return -EINVAL; in pci_epc_set_msix()
314 if (!epc->ops->set_msix) in pci_epc_set_msix()
317 mutex_lock(&epc->lock); in pci_epc_set_msix()
318 ret = epc->ops->set_msix(epc, func_no, interrupts - 1, bir, offset); in pci_epc_set_msix()
319 mutex_unlock(&epc->lock); in pci_epc_set_msix()
326 * pci_epc_unmap_addr() - unmap CPU address from PCI address
336 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_unmap_addr()
339 if (!epc->ops->unmap_addr) in pci_epc_unmap_addr()
342 mutex_lock(&epc->lock); in pci_epc_unmap_addr()
343 epc->ops->unmap_addr(epc, func_no, phys_addr); in pci_epc_unmap_addr()
344 mutex_unlock(&epc->lock); in pci_epc_unmap_addr()
349 * pci_epc_map_addr() - map CPU address to PCI address
363 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_map_addr()
364 return -EINVAL; in pci_epc_map_addr()
366 if (!epc->ops->map_addr) in pci_epc_map_addr()
369 mutex_lock(&epc->lock); in pci_epc_map_addr()
370 ret = epc->ops->map_addr(epc, func_no, phys_addr, pci_addr, size); in pci_epc_map_addr()
371 mutex_unlock(&epc->lock); in pci_epc_map_addr()
378 * pci_epc_clear_bar() - reset the BAR
388 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions || in pci_epc_clear_bar()
389 (epf_bar->barno == BAR_5 && in pci_epc_clear_bar()
390 epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)) in pci_epc_clear_bar()
393 if (!epc->ops->clear_bar) in pci_epc_clear_bar()
396 mutex_lock(&epc->lock); in pci_epc_clear_bar()
397 epc->ops->clear_bar(epc, func_no, epf_bar); in pci_epc_clear_bar()
398 mutex_unlock(&epc->lock); in pci_epc_clear_bar()
403 * pci_epc_set_bar() - configure BAR in order for host to assign PCI addr space
414 int flags = epf_bar->flags; in pci_epc_set_bar()
416 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions || in pci_epc_set_bar()
417 (epf_bar->barno == BAR_5 && in pci_epc_set_bar()
421 (upper_32_bits(epf_bar->size) && in pci_epc_set_bar()
423 return -EINVAL; in pci_epc_set_bar()
425 if (!epc->ops->set_bar) in pci_epc_set_bar()
428 mutex_lock(&epc->lock); in pci_epc_set_bar()
429 ret = epc->ops->set_bar(epc, func_no, epf_bar); in pci_epc_set_bar()
430 mutex_unlock(&epc->lock); in pci_epc_set_bar()
437 * pci_epc_write_header() - write standard configuration header
452 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) in pci_epc_write_header()
453 return -EINVAL; in pci_epc_write_header()
455 if (!epc->ops->write_header) in pci_epc_write_header()
458 mutex_lock(&epc->lock); in pci_epc_write_header()
459 ret = epc->ops->write_header(epc, func_no, header); in pci_epc_write_header()
460 mutex_unlock(&epc->lock); in pci_epc_write_header()
467 * pci_epc_add_epf() - bind PCI endpoint function to an endpoint controller
480 if (epf->epc) in pci_epc_add_epf()
481 return -EBUSY; in pci_epc_add_epf()
484 return -EINVAL; in pci_epc_add_epf()
486 mutex_lock(&epc->lock); in pci_epc_add_epf()
487 func_no = find_first_zero_bit(&epc->function_num_map, in pci_epc_add_epf()
490 ret = -EINVAL; in pci_epc_add_epf()
494 if (func_no > epc->max_functions - 1) { in pci_epc_add_epf()
495 dev_err(&epc->dev, "Exceeding max supported Function Number\n"); in pci_epc_add_epf()
496 ret = -EINVAL; in pci_epc_add_epf()
500 set_bit(func_no, &epc->function_num_map); in pci_epc_add_epf()
501 epf->func_no = func_no; in pci_epc_add_epf()
502 epf->epc = epc; in pci_epc_add_epf()
504 list_add_tail(&epf->list, &epc->pci_epf); in pci_epc_add_epf()
507 mutex_unlock(&epc->lock); in pci_epc_add_epf()
514 * pci_epc_remove_epf() - remove PCI endpoint function from endpoint controller
525 mutex_lock(&epc->lock); in pci_epc_remove_epf()
526 clear_bit(epf->func_no, &epc->function_num_map); in pci_epc_remove_epf()
527 list_del(&epf->list); in pci_epc_remove_epf()
528 epf->epc = NULL; in pci_epc_remove_epf()
529 mutex_unlock(&epc->lock); in pci_epc_remove_epf()
534 * pci_epc_linkup() - Notify the EPF device that EPC device has established a
546 atomic_notifier_call_chain(&epc->notifier, LINK_UP, NULL); in pci_epc_linkup()
551 * pci_epc_init_notify() - Notify the EPF device that EPC device's core
563 atomic_notifier_call_chain(&epc->notifier, CORE_INIT, NULL); in pci_epc_init_notify()
568 * pci_epc_destroy() - destroy the EPC device
575 pci_ep_cfs_remove_epc_group(epc->group); in pci_epc_destroy()
576 device_unregister(&epc->dev); in pci_epc_destroy()
582 * devm_pci_epc_destroy() - destroy the EPC device
600 * __pci_epc_create() - create a new endpoint controller (EPC) device
615 ret = -EINVAL; in __pci_epc_create()
621 ret = -ENOMEM; in __pci_epc_create()
625 mutex_init(&epc->lock); in __pci_epc_create()
626 INIT_LIST_HEAD(&epc->pci_epf); in __pci_epc_create()
627 ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier); in __pci_epc_create()
629 device_initialize(&epc->dev); in __pci_epc_create()
630 epc->dev.class = pci_epc_class; in __pci_epc_create()
631 epc->dev.parent = dev; in __pci_epc_create()
632 epc->ops = ops; in __pci_epc_create()
634 ret = dev_set_name(&epc->dev, "%s", dev_name(dev)); in __pci_epc_create()
638 ret = device_add(&epc->dev); in __pci_epc_create()
642 epc->group = pci_ep_cfs_add_epc_group(dev_name(dev)); in __pci_epc_create()
647 put_device(&epc->dev); in __pci_epc_create()
656 * __devm_pci_epc_create() - create a new endpoint controller (EPC) device
674 return ERR_PTR(-ENOMEM); in __devm_pci_epc_create()
692 pr_err("failed to create pci epc class --> %ld\n", in pci_epc_init()