drivers/infiniband/core/mad.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/core/mad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/core/mad.c- Extension
.c- Size
- 98139 bytes
- Lines
- 3419
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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
linux/dma-mapping.hlinux/slab.hlinux/module.hlinux/security.hlinux/xarray.hrdma/ib_cache.hmad_priv.hcore_priv.hmad_rmpp.hsmi.hopa_smi.hagent.htrace/events/ib_mad.h
Detected Declarations
function Copyrightfunction __ib_get_mad_portfunction list_for_each_entryfunction ib_get_mad_portfunction convert_mgmt_classfunction get_spl_qp_indexfunction vendor_class_indexfunction is_vendor_classfunction is_vendor_ouifunction is_vendor_method_in_usefunction ib_response_madfunction get_sol_fc_max_outstandingfunction deref_mad_agentfunction unregister_mad_agentfunction ib_unregister_mad_agentfunction dequeue_madfunction build_smp_wcfunction mad_priv_sizefunction port_mad_sizefunction mad_priv_dma_sizefunction locallyfunction get_pad_sizefunction free_send_rmpp_listfunction list_for_each_entry_safefunction alloc_send_rmpp_listfunction ib_mad_kernel_rmpp_agentfunction ib_get_mad_data_offsetfunction ib_is_mad_class_rmppfunction ib_free_send_madfunction ib_send_madfunction handle_queued_statefunction handle_send_statefunction handle_wait_statefunction handle_early_resp_statefunction handle_canceled_statefunction handle_done_statefunction change_mad_statefunction is_solicited_fc_madfunction mad_is_for_backlogfunction ib_post_send_madfunction ib_free_recv_madfunction list_for_each_entry_safefunction method_in_usefunction for_each_set_bitfunction allocate_method_tablefunction check_method_tablefunction check_class_tablefunction check_vendor_class
Annotated Snippet
if (!memcmp(vendor_class->oui[i], mad_reg_req->oui, 3)) {
method = vendor_class->method_table[i];
if (method) {
if (method_in_use(&method, mad_reg_req))
return 1;
else
break;
}
}
}
return 0;
}
int ib_response_mad(const struct ib_mad_hdr *hdr)
{
return ((hdr->method & IB_MGMT_METHOD_RESP) ||
(hdr->method == IB_MGMT_METHOD_TRAP_REPRESS) ||
((hdr->mgmt_class == IB_MGMT_CLASS_BM) &&
(hdr->attr_mod & IB_BM_ATTR_MOD_RESP)));
}
EXPORT_SYMBOL(ib_response_mad);
#define SOL_FC_MAX_DEFAULT_FRAC 4
#define SOL_FC_MAX_SA_FRAC 32
static int get_sol_fc_max_outstanding(struct ib_mad_reg_req *mad_reg_req)
{
if (!mad_reg_req)
/* Send only agent */
return mad_recvq_size / SOL_FC_MAX_DEFAULT_FRAC;
switch (mad_reg_req->mgmt_class) {
case IB_MGMT_CLASS_CM:
return mad_recvq_size / SOL_FC_MAX_DEFAULT_FRAC;
case IB_MGMT_CLASS_SUBN_ADM:
return mad_recvq_size / SOL_FC_MAX_SA_FRAC;
case IB_MGMT_CLASS_SUBN_LID_ROUTED:
case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
return min(mad_recvq_size, IB_MAD_QP_RECV_SIZE) /
SOL_FC_MAX_DEFAULT_FRAC;
default:
return 0;
}
}
/*
* ib_register_mad_agent - Register to send/receive MADs
*
* Context: Process context.
*/
struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
u32 port_num,
enum ib_qp_type qp_type,
struct ib_mad_reg_req *mad_reg_req,
u8 rmpp_version,
ib_mad_send_handler send_handler,
ib_mad_recv_handler recv_handler,
void *context,
u32 registration_flags)
{
struct ib_mad_port_private *port_priv;
struct ib_mad_agent *ret = ERR_PTR(-EINVAL);
struct ib_mad_agent_private *mad_agent_priv;
struct ib_mad_reg_req *reg_req = NULL;
struct ib_mad_mgmt_class_table *class;
struct ib_mad_mgmt_vendor_class_table *vendor;
struct ib_mad_mgmt_vendor_class *vendor_class;
struct ib_mad_mgmt_method_table *method;
int ret2, qpn;
u8 mgmt_class, vclass;
if ((qp_type == IB_QPT_SMI && !rdma_cap_ib_smi(device, port_num)) ||
(qp_type == IB_QPT_GSI && !rdma_cap_ib_cm(device, port_num)))
return ERR_PTR(-EPROTONOSUPPORT);
/* Validate parameters */
qpn = get_spl_qp_index(qp_type);
if (qpn == -1) {
dev_dbg_ratelimited(&device->dev, "%s: invalid QP Type %d\n",
__func__, qp_type);
goto error1;
}
if (rmpp_version && rmpp_version != IB_MGMT_RMPP_VERSION) {
dev_dbg_ratelimited(&device->dev,
"%s: invalid RMPP Version %u\n",
__func__, rmpp_version);
goto error1;
}
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/slab.h`, `linux/module.h`, `linux/security.h`, `linux/xarray.h`, `rdma/ib_cache.h`, `mad_priv.h`, `core_priv.h`.
- Detected declarations: `function Copyright`, `function __ib_get_mad_port`, `function list_for_each_entry`, `function ib_get_mad_port`, `function convert_mgmt_class`, `function get_spl_qp_index`, `function vendor_class_index`, `function is_vendor_class`, `function is_vendor_oui`, `function is_vendor_method_in_use`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.