Lines Matching +full:reserved +full:- +full:cpu +full:- +full:vectors

1 // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
3 * Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
50 ibdev_err(&dev->ibdev, in unimplemented_aenq_handler()
58 atomic64_inc(&dev->stats.keep_alive_rcvd); in efa_keep_alive()
70 struct pci_dev *pdev = dev->pdev; in efa_release_bars()
79 u16 cqn = eqe->u.comp_event.cqn; in efa_process_comp_eqe()
83 cq = xa_load(&dev->cqs_xa, cqn); in efa_process_comp_eqe()
85 ibdev_err_ratelimited(&dev->ibdev, in efa_process_comp_eqe()
86 "Completion event on non-existent CQ[%u]", in efa_process_comp_eqe()
91 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context); in efa_process_comp_eqe()
96 struct efa_dev *dev = container_of(eeq->edev, struct efa_dev, edev); in efa_process_eqe()
98 if (likely(EFA_GET(&eqe->common, EFA_ADMIN_EQE_EVENT_TYPE) == in efa_process_eqe()
102 ibdev_err_ratelimited(&dev->ibdev, in efa_process_eqe()
104 EFA_GET(&eqe->common, in efa_process_eqe()
111 struct efa_com_dev *edev = eq->eeq.edev; in efa_intr_msix_comp()
113 efa_com_eq_comp_intr_handler(edev, &eq->eeq); in efa_intr_msix_comp()
122 efa_com_admin_q_comp_intr_handler(&dev->edev); in efa_intr_msix_mgmnt()
123 efa_com_aenq_intr_handler(&dev->edev, data); in efa_intr_msix_mgmnt()
132 err = request_irq(irq->irqn, irq->handler, 0, irq->name, irq->data); in efa_request_irq()
134 dev_err(&dev->pdev->dev, "Failed to request irq %s (%d)\n", in efa_request_irq()
135 irq->name, err); in efa_request_irq()
139 irq_set_affinity_hint(irq->irqn, &irq->affinity_hint_mask); in efa_request_irq()
147 u32 cpu; in efa_setup_comp_irq() local
149 cpu = vector - EFA_COMP_EQS_VEC_BASE; in efa_setup_comp_irq()
150 snprintf(eq->irq.name, EFA_IRQNAME_SIZE, "efa-comp%d@pci:%s", cpu, in efa_setup_comp_irq()
151 pci_name(dev->pdev)); in efa_setup_comp_irq()
152 eq->irq.handler = efa_intr_msix_comp; in efa_setup_comp_irq()
153 eq->irq.data = eq; in efa_setup_comp_irq()
154 eq->irq.vector = vector; in efa_setup_comp_irq()
155 eq->irq.irqn = pci_irq_vector(dev->pdev, vector); in efa_setup_comp_irq()
156 cpumask_set_cpu(cpu, &eq->irq.affinity_hint_mask); in efa_setup_comp_irq()
161 irq_set_affinity_hint(irq->irqn, NULL); in efa_free_irq()
162 free_irq(irq->irqn, irq->data); in efa_free_irq()
167 u32 cpu; in efa_setup_mgmnt_irq() local
169 snprintf(dev->admin_irq.name, EFA_IRQNAME_SIZE, in efa_setup_mgmnt_irq()
170 "efa-mgmnt@pci:%s", pci_name(dev->pdev)); in efa_setup_mgmnt_irq()
171 dev->admin_irq.handler = efa_intr_msix_mgmnt; in efa_setup_mgmnt_irq()
172 dev->admin_irq.data = dev; in efa_setup_mgmnt_irq()
173 dev->admin_irq.vector = dev->admin_msix_vector_idx; in efa_setup_mgmnt_irq()
174 dev->admin_irq.irqn = pci_irq_vector(dev->pdev, in efa_setup_mgmnt_irq()
175 dev->admin_msix_vector_idx); in efa_setup_mgmnt_irq()
176 cpu = cpumask_first(cpu_online_mask); in efa_setup_mgmnt_irq()
177 cpumask_set_cpu(cpu, in efa_setup_mgmnt_irq()
178 &dev->admin_irq.affinity_hint_mask); in efa_setup_mgmnt_irq()
179 dev_info(&dev->pdev->dev, "Setup irq:%d name:%s\n", in efa_setup_mgmnt_irq()
180 dev->admin_irq.irqn, in efa_setup_mgmnt_irq()
181 dev->admin_irq.name); in efa_setup_mgmnt_irq()
188 return efa_request_irq(dev, &dev->admin_irq); in efa_set_mgmnt_irq()
193 u8 db_bar_idx = dev->dev_attr.db_bar; in efa_request_doorbell_bar()
194 struct pci_dev *pdev = dev->pdev; in efa_request_doorbell_bar()
203 dev_err(&pdev->dev, in efa_request_doorbell_bar()
206 return -ENODEV; in efa_request_doorbell_bar()
211 dev_err(&pdev->dev, in efa_request_doorbell_bar()
218 dev->db_bar_addr = pci_resource_start(dev->pdev, db_bar_idx); in efa_request_doorbell_bar()
219 dev->db_bar_len = pci_resource_len(dev->pdev, db_bar_idx); in efa_request_doorbell_bar()
226 if (!(BIT(dev->dev_attr.db_bar) & EFA_BASE_BAR_MASK)) in efa_release_doorbell_bar()
227 efa_release_bars(dev, BIT(dev->dev_attr.db_bar)); in efa_release_doorbell_bar()
233 struct efa_com_dev *edev = &dev->edev; in efa_update_hw_hints()
235 if (hw_hints->mmio_read_timeout) in efa_update_hw_hints()
236 edev->mmio_read.mmio_read_timeout = in efa_update_hw_hints()
237 hw_hints->mmio_read_timeout * 1000; in efa_update_hw_hints()
239 if (hw_hints->poll_interval) in efa_update_hw_hints()
240 edev->aq.poll_interval = hw_hints->poll_interval; in efa_update_hw_hints()
242 if (hw_hints->admin_completion_timeout) in efa_update_hw_hints()
243 edev->aq.completion_timeout = in efa_update_hw_hints()
244 hw_hints->admin_completion_timeout; in efa_update_hw_hints()
249 atomic64_t *s = (atomic64_t *)&dev->stats; in efa_stats_init()
252 for (i = 0; i < sizeof(dev->stats) / sizeof(*s); i++, s++) in efa_stats_init()
264 if (!efa_com_check_supported_feature_id(&dev->edev, in efa_set_host_info()
269 hinf = dma_alloc_coherent(&dev->pdev->dev, bufsz, &hinf_dma, in efa_set_host_info()
274 strscpy(hinf->os_dist_str, utsname()->release, in efa_set_host_info()
275 sizeof(hinf->os_dist_str)); in efa_set_host_info()
276 hinf->os_type = EFA_ADMIN_OS_LINUX; in efa_set_host_info()
277 strscpy(hinf->kernel_ver_str, utsname()->version, in efa_set_host_info()
278 sizeof(hinf->kernel_ver_str)); in efa_set_host_info()
279 hinf->kernel_ver = LINUX_VERSION_CODE; in efa_set_host_info()
280 EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MAJOR, 0); in efa_set_host_info()
281 EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MINOR, 0); in efa_set_host_info()
282 EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_SUB_MINOR, 0); in efa_set_host_info()
283 EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MODULE_TYPE, 0); in efa_set_host_info()
284 EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_BUS, dev->pdev->bus->number); in efa_set_host_info()
285 EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_DEVICE, in efa_set_host_info()
286 PCI_SLOT(dev->pdev->devfn)); in efa_set_host_info()
287 EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_FUNCTION, in efa_set_host_info()
288 PCI_FUNC(dev->pdev->devfn)); in efa_set_host_info()
289 EFA_SET(&hinf->spec_ver, EFA_ADMIN_HOST_INFO_SPEC_MAJOR, in efa_set_host_info()
291 EFA_SET(&hinf->spec_ver, EFA_ADMIN_HOST_INFO_SPEC_MINOR, in efa_set_host_info()
293 EFA_SET(&hinf->flags, EFA_ADMIN_HOST_INFO_INTREE, 1); in efa_set_host_info()
294 EFA_SET(&hinf->flags, EFA_ADMIN_HOST_INFO_GDR, 0); in efa_set_host_info()
296 efa_com_set_feature_ex(&dev->edev, &resp, &cmd, EFA_ADMIN_HOST_INFO, in efa_set_host_info()
299 dma_free_coherent(&dev->pdev->dev, bufsz, hinf, hinf_dma); in efa_set_host_info()
304 efa_com_eq_destroy(&dev->edev, &eq->eeq); in efa_destroy_eq()
305 efa_free_irq(dev, &eq->irq); in efa_destroy_eq()
313 err = efa_request_irq(dev, &eq->irq); in efa_create_eq()
317 err = efa_com_eq_init(&dev->edev, &eq->eeq, efa_process_eqe, in efa_create_eq()
318 dev->dev_attr.max_eq_depth, msix_vec); in efa_create_eq()
325 efa_free_irq(dev, &eq->irq); in efa_create_eq()
331 unsigned int neqs = dev->dev_attr.max_eq; in efa_create_eqs()
336 dev->num_irq_vectors - EFA_COMP_EQS_VEC_BASE); in efa_create_eqs()
338 dev->neqs = neqs; in efa_create_eqs()
339 dev->eqs = kcalloc(neqs, sizeof(*dev->eqs), GFP_KERNEL); in efa_create_eqs()
340 if (!dev->eqs) in efa_create_eqs()
341 return -ENOMEM; in efa_create_eqs()
344 err = efa_create_eq(dev, &dev->eqs[i], in efa_create_eqs()
353 for (i--; i >= 0; i--) in efa_create_eqs()
354 efa_destroy_eq(dev, &dev->eqs[i]); in efa_create_eqs()
355 kfree(dev->eqs); in efa_create_eqs()
364 for (i = 0; i < dev->neqs; i++) in efa_destroy_eqs()
365 efa_destroy_eq(dev, &dev->eqs[i]); in efa_destroy_eqs()
367 kfree(dev->eqs); in efa_destroy_eqs()
412 struct pci_dev *pdev = dev->pdev; in efa_ib_device_add()
417 err = efa_com_get_device_attr(&dev->edev, &dev->dev_attr); in efa_ib_device_add()
421 dev_dbg(&dev->pdev->dev, "Doorbells bar (%d)\n", dev->dev_attr.db_bar); in efa_ib_device_add()
426 err = efa_com_get_hw_hints(&dev->edev, &hw_hints); in efa_ib_device_add()
433 err = efa_com_set_aenq_config(&dev->edev, EFA_AENQ_ENABLED_GROUPS); in efa_ib_device_add()
443 dev->ibdev.node_type = RDMA_NODE_UNSPECIFIED; in efa_ib_device_add()
444 dev->ibdev.node_guid = dev->dev_attr.guid; in efa_ib_device_add()
445 dev->ibdev.phys_port_cnt = 1; in efa_ib_device_add()
446 dev->ibdev.num_comp_vectors = dev->neqs ?: 1; in efa_ib_device_add()
447 dev->ibdev.dev.parent = &pdev->dev; in efa_ib_device_add()
449 ib_set_device_ops(&dev->ibdev, &efa_dev_ops); in efa_ib_device_add()
451 dev->ibdev.driver_def = efa_uapi_defs; in efa_ib_device_add()
453 err = ib_register_device(&dev->ibdev, "efa_%d", &pdev->dev); in efa_ib_device_add()
457 ibdev_info(&dev->ibdev, "IB device registered\n"); in efa_ib_device_add()
470 ibdev_info(&dev->ibdev, "Unregister ib device\n"); in efa_ib_device_remove()
471 ib_unregister_device(&dev->ibdev); in efa_ib_device_remove()
473 efa_com_dev_reset(&dev->edev, EFA_REGS_RESET_NORMAL); in efa_ib_device_remove()
479 pci_free_irq_vectors(dev->pdev); in efa_disable_msix()
487 * Reserve the max msix vectors we might need, one vector is reserved in efa_enable_msix()
490 max_vecs = min_t(int, pci_msix_vec_count(dev->pdev), in efa_enable_msix()
492 dev_dbg(&dev->pdev->dev, "Trying to enable MSI-X, vectors %d\n", in efa_enable_msix()
495 dev->admin_msix_vector_idx = EFA_MGMNT_MSIX_VEC_IDX; in efa_enable_msix()
496 num_vecs = pci_alloc_irq_vectors(dev->pdev, 1, in efa_enable_msix()
500 dev_err(&dev->pdev->dev, "Failed to enable MSI-X. error %d\n", in efa_enable_msix()
502 return -ENOSPC; in efa_enable_msix()
505 dev_dbg(&dev->pdev->dev, "Allocated %d MSI-X vectors\n", num_vecs); in efa_enable_msix()
507 dev->num_irq_vectors = num_vecs; in efa_enable_msix()
531 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(dma_width)); in efa_device_init()
533 dev_err(&pdev->dev, "dma_set_mask_and_coherent failed %d\n", err); in efa_device_init()
537 dma_set_max_seg_size(&pdev->dev, UINT_MAX); in efa_device_init()
550 dev_err(&pdev->dev, "pci_enable_device_mem() failed!\n"); in efa_probe_device()
558 dev_err(&pdev->dev, "Device alloc failed\n"); in efa_probe_device()
559 err = -ENOMEM; in efa_probe_device()
564 edev = &dev->edev; in efa_probe_device()
565 edev->efa_dev = dev; in efa_probe_device()
566 edev->dmadev = &pdev->dev; in efa_probe_device()
567 dev->pdev = pdev; in efa_probe_device()
568 xa_init(&dev->cqs_xa); in efa_probe_device()
572 dev_err(&pdev->dev, "BARs unavailable. Requested %#x, available %#x\n", in efa_probe_device()
574 err = -ENODEV; in efa_probe_device()
579 dev_err(&pdev->dev, "pci_request_selected_regions failed %d\n", in efa_probe_device()
584 dev->reg_bar_addr = pci_resource_start(pdev, EFA_REG_BAR); in efa_probe_device()
585 dev->reg_bar_len = pci_resource_len(pdev, EFA_REG_BAR); in efa_probe_device()
586 dev->mem_bar_addr = pci_resource_start(pdev, EFA_MEM_BAR); in efa_probe_device()
587 dev->mem_bar_len = pci_resource_len(pdev, EFA_MEM_BAR); in efa_probe_device()
589 edev->reg_bar = devm_ioremap(&pdev->dev, in efa_probe_device()
590 dev->reg_bar_addr, in efa_probe_device()
591 dev->reg_bar_len); in efa_probe_device()
592 if (!edev->reg_bar) { in efa_probe_device()
593 dev_err(&pdev->dev, "Failed to remap register bar\n"); in efa_probe_device()
594 err = -EFAULT; in efa_probe_device()
600 dev_err(&pdev->dev, "Failed to init readless MMIO\n"); in efa_probe_device()
606 dev_err(&pdev->dev, "EFA device init failed\n"); in efa_probe_device()
607 if (err == -ETIME) in efa_probe_device()
608 err = -EPROBE_DEFER; in efa_probe_device()
616 edev->aq.msix_vector_idx = dev->admin_msix_vector_idx; in efa_probe_device()
617 edev->aenq.msix_vector_idx = dev->admin_msix_vector_idx; in efa_probe_device()
630 efa_free_irq(dev, &dev->admin_irq); in efa_probe_device()
636 devm_iounmap(&pdev->dev, edev->reg_bar); in efa_probe_device()
640 ib_dealloc_device(&dev->ibdev); in efa_probe_device()
651 edev = &dev->edev; in efa_remove_device()
653 efa_free_irq(dev, &dev->admin_irq); in efa_remove_device()
656 devm_iounmap(&pdev->dev, edev->reg_bar); in efa_remove_device()
658 xa_destroy(&dev->cqs_xa); in efa_remove_device()
659 ib_dealloc_device(&dev->ibdev); in efa_remove_device()
696 efa_com_dev_reset(&dev->edev, EFA_REGS_RESET_SHUTDOWN); in efa_shutdown()
697 efa_free_irq(dev, &dev->admin_irq); in efa_shutdown()