drivers/infiniband/hw/mlx5/gsi.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mlx5/gsi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/mlx5/gsi.c- Extension
.c- Size
- 12226 bytes
- Lines
- 492
- 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
mlx5_ib.h
Detected Declarations
struct mlx5_ib_gsi_wrfunction mlx5_ib_deth_sqpn_capfunction generate_completionsfunction handle_single_completionfunction mlx5_ib_create_gsifunction mlx5_ib_destroy_gsifunction modify_to_rtsfunction setup_qpfunction mlx5_ib_gsi_modify_qpfunction mlx5_ib_gsi_query_qpfunction mlx5_ib_add_outstanding_wrfunction mlx5_ib_gsi_silent_dropfunction mlx5_ib_gsi_post_sendfunction mlx5_ib_gsi_post_recvfunction mlx5_ib_gsi_pkey_change
Annotated Snippet
struct mlx5_ib_gsi_wr {
struct ib_cqe cqe;
struct ib_wc wc;
bool completed:1;
};
static bool mlx5_ib_deth_sqpn_cap(struct mlx5_ib_dev *dev)
{
return MLX5_CAP_GEN(dev->mdev, set_deth_sqpn);
}
/* Call with gsi->lock locked */
static void generate_completions(struct mlx5_ib_qp *mqp)
{
struct mlx5_ib_gsi_qp *gsi = &mqp->gsi;
struct ib_cq *gsi_cq = mqp->ibqp.send_cq;
struct mlx5_ib_gsi_wr *wr;
u32 index;
for (index = gsi->outstanding_ci; index != gsi->outstanding_pi;
index++) {
wr = &gsi->outstanding_wrs[index % gsi->cap.max_send_wr];
if (!wr->completed)
break;
WARN_ON_ONCE(mlx5_ib_generate_wc(gsi_cq, &wr->wc));
wr->completed = false;
}
gsi->outstanding_ci = index;
}
static void handle_single_completion(struct ib_cq *cq, struct ib_wc *wc)
{
struct mlx5_ib_gsi_qp *gsi = cq->cq_context;
struct mlx5_ib_gsi_wr *wr =
container_of(wc->wr_cqe, struct mlx5_ib_gsi_wr, cqe);
struct mlx5_ib_qp *mqp = container_of(gsi, struct mlx5_ib_qp, gsi);
u64 wr_id;
unsigned long flags;
spin_lock_irqsave(&gsi->lock, flags);
wr->completed = true;
wr_id = wr->wc.wr_id;
wr->wc = *wc;
wr->wc.wr_id = wr_id;
wr->wc.qp = &mqp->ibqp;
generate_completions(mqp);
spin_unlock_irqrestore(&gsi->lock, flags);
}
int mlx5_ib_create_gsi(struct ib_pd *pd, struct mlx5_ib_qp *mqp,
struct ib_qp_init_attr *attr)
{
struct mlx5_ib_dev *dev = to_mdev(pd->device);
struct mlx5_ib_gsi_qp *gsi;
struct ib_qp_init_attr hw_init_attr = *attr;
const u8 port_num = attr->port_num;
int num_qps = 0;
int ret;
if (mlx5_ib_deth_sqpn_cap(dev)) {
if (MLX5_CAP_GEN(dev->mdev,
port_type) == MLX5_CAP_PORT_TYPE_IB)
num_qps = pd->device->attrs.max_pkeys;
else if (dev->lag_active)
num_qps = dev->lag_ports;
}
gsi = &mqp->gsi;
gsi->tx_qps = kzalloc_objs(*gsi->tx_qps, num_qps);
if (!gsi->tx_qps)
return -ENOMEM;
gsi->outstanding_wrs =
kzalloc_objs(*gsi->outstanding_wrs, attr->cap.max_send_wr);
if (!gsi->outstanding_wrs) {
ret = -ENOMEM;
goto err_free_tx;
}
if (dev->devr.ports[port_num - 1].gsi) {
mlx5_ib_warn(dev, "GSI QP already exists on port %d\n",
port_num);
ret = -EBUSY;
goto err_free_wrs;
}
gsi->num_qps = num_qps;
Annotation
- Immediate include surface: `mlx5_ib.h`.
- Detected declarations: `struct mlx5_ib_gsi_wr`, `function mlx5_ib_deth_sqpn_cap`, `function generate_completions`, `function handle_single_completion`, `function mlx5_ib_create_gsi`, `function mlx5_ib_destroy_gsi`, `function modify_to_rts`, `function setup_qp`, `function mlx5_ib_gsi_modify_qp`, `function mlx5_ib_gsi_query_qp`.
- 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.