Lines Matching +full:msi +full:- +full:1
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
6 #include <linux/msi.h>
19 * ntb_msi_init() - Initialize the MSI context
23 * It initializes the context for MSI operations and maps
43 return -EINVAL; in ntb_msi_init()
45 ntb->msi = devm_kzalloc(&ntb->dev, struct_size(ntb->msi, peer_mws, peers), in ntb_msi_init()
47 if (!ntb->msi) in ntb_msi_init()
48 return -ENOMEM; in ntb_msi_init()
50 ntb->msi->desc_changed = desc_changed; in ntb_msi_init()
53 peer_widx = ntb_peer_mw_count(ntb) - 1 - i; in ntb_msi_init()
60 ntb->msi->peer_mws[i] = devm_ioremap(&ntb->dev, mw_phys_addr, in ntb_msi_init()
62 if (!ntb->msi->peer_mws[i]) { in ntb_msi_init()
63 ret = -EFAULT; in ntb_msi_init()
72 if (ntb->msi->peer_mws[i]) in ntb_msi_init()
73 devm_iounmap(&ntb->dev, ntb->msi->peer_mws[i]); in ntb_msi_init()
75 devm_kfree(&ntb->dev, ntb->msi); in ntb_msi_init()
76 ntb->msi = NULL; in ntb_msi_init()
82 * ntb_msi_setup_mws() - Initialize the MSI inbound memory windows
106 if (!ntb->msi) in ntb_msi_setup_mws()
107 return -EINVAL; in ntb_msi_setup_mws()
109 msi_lock_descs(&ntb->pdev->dev); in ntb_msi_setup_mws()
110 desc = msi_first_desc(&ntb->pdev->dev, MSI_DESC_ASSOCIATED); in ntb_msi_setup_mws()
111 addr = desc->msg.address_lo + ((uint64_t)desc->msg.address_hi << 32); in ntb_msi_setup_mws()
112 msi_unlock_descs(&ntb->pdev->dev); in ntb_msi_setup_mws()
124 addr &= ~(addr_align - 1); in ntb_msi_setup_mws()
150 ntb->msi->base_addr = addr; in ntb_msi_setup_mws()
151 ntb->msi->end_addr = addr + mw_min_size; in ntb_msi_setup_mws()
169 * ntb_msi_clear_mws() - Clear all inbound memory windows
200 addr = entry->msg.address_lo + in ntb_msi_set_desc()
201 ((uint64_t)entry->msg.address_hi << 32); in ntb_msi_set_desc()
203 if (addr < ntb->msi->base_addr || addr >= ntb->msi->end_addr) { in ntb_msi_set_desc()
204 dev_warn_once(&ntb->dev, in ntb_msi_set_desc()
205 "IRQ %d: MSI Address not within the memory window (%llx, [%llx %llx])\n", in ntb_msi_set_desc()
206 entry->irq, addr, ntb->msi->base_addr, in ntb_msi_set_desc()
207 ntb->msi->end_addr); in ntb_msi_set_desc()
208 return -EFAULT; in ntb_msi_set_desc()
211 msi_desc->addr_offset = addr - ntb->msi->base_addr; in ntb_msi_set_desc()
212 msi_desc->data = entry->msg.data; in ntb_msi_set_desc()
221 WARN_ON(ntb_msi_set_desc(dr->ntb, entry, dr->msi_desc)); in ntb_msi_write_msg()
223 if (dr->ntb->msi->desc_changed) in ntb_msi_write_msg()
224 dr->ntb->msi->desc_changed(dr->ntb->ctx); in ntb_msi_write_msg()
231 dr->entry->write_msi_msg = NULL; in ntbm_msi_callback_release()
232 dr->entry->write_msi_msg_data = NULL; in ntbm_msi_callback_release()
243 return -ENOMEM; in ntbm_msi_setup_callback()
245 dr->ntb = ntb; in ntbm_msi_setup_callback()
246 dr->entry = entry; in ntbm_msi_setup_callback()
247 dr->msi_desc = msi_desc; in ntbm_msi_setup_callback()
249 devres_add(&ntb->dev, dr); in ntbm_msi_setup_callback()
251 dr->entry->write_msi_msg = ntb_msi_write_msg; in ntbm_msi_setup_callback()
252 dr->entry->write_msi_msg_data = dr; in ntbm_msi_setup_callback()
258 * ntbm_msi_request_threaded_irq() - allocate an MSI interrupt
265 * @msi_desc: MSI descriptor data which triggers the interrupt
268 * MSI interrupt and returns the descriptor used to trigger
285 struct device *dev = &ntb->pdev->dev; in ntbm_msi_request_threaded_irq()
289 if (!ntb->msi) in ntbm_msi_request_threaded_irq()
290 return -EINVAL; in ntbm_msi_request_threaded_irq()
294 if (irq_has_action(entry->irq)) in ntbm_msi_request_threaded_irq()
297 ret = devm_request_threaded_irq(&ntb->dev, entry->irq, handler, in ntbm_msi_request_threaded_irq()
303 devm_free_irq(&ntb->dev, entry->irq, dev_id); in ntbm_msi_request_threaded_irq()
309 devm_free_irq(&ntb->dev, entry->irq, dev_id); in ntbm_msi_request_threaded_irq()
313 ret = entry->irq; in ntbm_msi_request_threaded_irq()
316 ret = -ENODEV; in ntbm_msi_request_threaded_irq()
329 return dr->ntb == ntb && dr->entry == data; in ntbm_msi_callback_match()
333 * ntbm_msi_free_irq() - free an interrupt
345 entry->write_msi_msg = NULL; in ntbm_msi_free_irq()
346 entry->write_msi_msg_data = NULL; in ntbm_msi_free_irq()
348 WARN_ON(devres_destroy(&ntb->dev, ntbm_msi_callback_release, in ntbm_msi_free_irq()
351 devm_free_irq(&ntb->dev, irq, dev_id); in ntbm_msi_free_irq()
356 * ntb_msi_peer_trigger() - Trigger an interrupt handler on a peer
359 * @desc: MSI descriptor data which triggers the interrupt
372 if (!ntb->msi) in ntb_msi_peer_trigger()
373 return -EINVAL; in ntb_msi_peer_trigger()
375 idx = desc->addr_offset / sizeof(*ntb->msi->peer_mws[peer]); in ntb_msi_peer_trigger()
377 iowrite32(desc->data, &ntb->msi->peer_mws[peer][idx]); in ntb_msi_peer_trigger()
384 * ntb_msi_peer_addr() - Get the DMA address to trigger a peer's MSI interrupt
387 * @desc: MSI descriptor data which triggers the interrupt
401 int peer_widx = ntb_peer_mw_count(ntb) - 1 - peer; in ntb_msi_peer_addr()
410 *msi_addr = mw_phys_addr + desc->addr_offset; in ntb_msi_peer_addr()