drivers/infiniband/hw/hns/hns_roce_qp.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_qp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_qp.c- Extension
.c- Size
- 43177 bytes
- Lines
- 1631
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
rdma/ib_addr.hrdma/ib_umem.hrdma/uverbs_ioctl.hhns_roce_common.hhns_roce_device.hhns_roce_hem.h
Detected Declarations
function Copyrightfunction flush_work_handlefunction init_flush_workfunction flush_cqefunction hns_roce_qp_eventfunction hns_roce_flush_cqefunction hns_roce_ib_qp_eventfunction get_affinity_cq_bankfunction get_least_load_bankid_for_qpfunction alloc_qpn_with_bankidfunction use_ext_sgefunction select_qp_bankidfunction alloc_qpnfunction add_qp_to_listfunction hns_roce_qp_storefunction alloc_qpcfunction qp_user_mmap_entry_removefunction hns_roce_qp_removefunction free_qpcfunction get_qp_bankidfunction free_qpnfunction proc_rq_sgefunction set_rq_sizefunction get_max_inline_datafunction update_inline_datafunction get_sge_num_from_max_send_sgefunction get_sge_num_from_max_inl_datafunction set_ext_sge_paramfunction check_sq_size_with_integrityfunction set_user_sq_sizefunction set_wqe_buf_attrfunction set_kernel_sq_sizefunction hns_roce_qp_has_sqfunction hns_roce_qp_has_rqfunction alloc_qp_buffunction free_qp_buffunction user_qp_has_sdbfunction user_qp_has_rdbfunction kernel_qp_has_rdbfunction qp_mmap_entryfunction alloc_user_qp_dbfunction alloc_kernel_qp_dbfunction alloc_qp_dbfunction free_qp_dbfunction alloc_kernel_wridfunction free_kernel_wridfunction default_congest_typefunction set_congest_type
Annotated Snippet
switch (type) {
case HNS_ROCE_EVENT_TYPE_PATH_MIG:
event.event = IB_EVENT_PATH_MIG;
break;
case HNS_ROCE_EVENT_TYPE_COMM_EST:
event.event = IB_EVENT_COMM_EST;
break;
case HNS_ROCE_EVENT_TYPE_SQ_DRAINED:
event.event = IB_EVENT_SQ_DRAINED;
break;
case HNS_ROCE_EVENT_TYPE_SRQ_LAST_WQE_REACH:
event.event = IB_EVENT_QP_LAST_WQE_REACHED;
break;
case HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR:
event.event = IB_EVENT_QP_FATAL;
break;
case HNS_ROCE_EVENT_TYPE_PATH_MIG_FAILED:
event.event = IB_EVENT_PATH_MIG_ERR;
break;
case HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR:
event.event = IB_EVENT_QP_REQ_ERR;
break;
case HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR:
case HNS_ROCE_EVENT_TYPE_XRCD_VIOLATION:
case HNS_ROCE_EVENT_TYPE_INVALID_XRCETH:
event.event = IB_EVENT_QP_ACCESS_ERR;
break;
default:
dev_dbg(ibqp->device->dev.parent, "roce_ib: Unexpected event type %d on QP %06lx\n",
type, hr_qp->qpn);
return;
}
ibqp->event_handler(&event, ibqp->qp_context);
}
}
static u8 get_affinity_cq_bank(u8 qp_bank)
{
return (qp_bank >> 1) & CQ_BANKID_MASK;
}
static u8 get_least_load_bankid_for_qp(struct hns_roce_bank *bank, u8 valid_qp_bank_mask)
{
#define INVALID_LOAD_QPNUM 0xFFFFFFFF
u32 least_load = INVALID_LOAD_QPNUM;
u8 bankid = 0;
u32 bankcnt;
u8 i;
for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) {
if (!(valid_qp_bank_mask & BIT(i)))
continue;
bankcnt = bank[i].inuse;
if (bankcnt < least_load) {
least_load = bankcnt;
bankid = i;
}
}
return bankid;
}
static int alloc_qpn_with_bankid(struct hns_roce_bank *bank, u8 bankid,
unsigned long *qpn)
{
int id;
id = ida_alloc_range(&bank->ida, bank->next, bank->max, GFP_KERNEL);
if (id < 0) {
id = ida_alloc_range(&bank->ida, bank->min, bank->max,
GFP_KERNEL);
if (id < 0)
return id;
}
/* the QPN should keep increasing until the max value is reached. */
bank->next = (id + 1) > bank->max ? bank->min : id + 1;
/* the lower 3 bits is bankid */
*qpn = (id << 3) | bankid;
return 0;
}
static bool use_ext_sge(struct ib_qp_init_attr *init_attr)
{
return init_attr->cap.max_send_sge > HNS_ROCE_SGE_IN_WQE ||
init_attr->qp_type == IB_QPT_UD ||
init_attr->qp_type == IB_QPT_GSI;
Annotation
- Immediate include surface: `rdma/ib_addr.h`, `rdma/ib_umem.h`, `rdma/uverbs_ioctl.h`, `hns_roce_common.h`, `hns_roce_device.h`, `hns_roce_hem.h`.
- Detected declarations: `function Copyright`, `function flush_work_handle`, `function init_flush_work`, `function flush_cqe`, `function hns_roce_qp_event`, `function hns_roce_flush_cqe`, `function hns_roce_ib_qp_event`, `function get_affinity_cq_bank`, `function get_least_load_bankid_for_qp`, `function alloc_qpn_with_bankid`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.