net/smc/smc_ib.c
Source file repositories/reference/linux-study-clean/net/smc/smc_ib.c
File Facts
- System
- Linux kernel
- Corpus path
net/smc/smc_ib.c- Extension
.c- Size
- 28021 bytes
- Lines
- 1026
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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/etherdevice.hlinux/if_vlan.hlinux/random.hlinux/workqueue.hlinux/scatterlist.hlinux/wait.hlinux/mutex.hlinux/inetdevice.hrdma/ib_verbs.hrdma/ib_cache.hsmc_pnet.hsmc_ib.hsmc_core.hsmc_wr.hsmc.hsmc_netlink.h
Detected Declarations
function smc_ib_modify_qp_initfunction smc_ib_modify_qp_rtrfunction smc_ib_modify_qp_rtsfunction smc_ib_modify_qp_errorfunction smc_ib_ready_linkfunction smc_ib_fill_macfunction smc_ib_define_local_systemidfunction smc_ib_is_valid_local_systemidfunction smc_ib_init_local_systemidfunction smc_ib_port_activefunction smc_ib_find_routefunction smc_ib_determine_gid_rcufunction smc_ib_gid_to_ipv4function in_dev_for_each_ifa_rcufunction smc_ib_determine_gidfunction smc_ib_check_link_gidfunction smc_ib_gid_checkfunction smc_ib_remember_port_attrfunction smc_ib_port_event_workfunction for_each_set_bitfunction smc_ib_global_event_handlerfunction smc_ib_dealloc_protection_domainfunction smc_ib_create_protection_domainfunction smcr_diag_is_dev_criticalfunction smc_nl_handle_dev_portfunction smc_nl_handle_pci_valuesfunction smc_nl_handle_smcr_devfunction smc_nl_prep_smcr_devfunction smcr_nl_get_devicefunction smc_ib_qp_event_handlerfunction smc_ib_destroy_queue_pairfunction smc_ib_create_queue_pairfunction smc_ib_put_memory_regionfunction smc_ib_map_mr_sgfunction smc_ib_get_memory_regionfunction smc_ib_is_sg_need_syncfunction smc_ib_sync_sg_for_cpufunction smc_ib_sync_sg_for_devicefunction smc_ib_buf_map_sgfunction smc_ib_buf_unmap_sgfunction smc_ib_setup_per_ibdevfunction smc_ib_cleanup_per_ibdevfunction smc_copy_netdev_ifindexfunction smc_ib_ndev_changefunction smc_ib_add_devfunction smc_ib_remove_devfunction smc_ib_register_clientfunction smc_ib_unregister_client
Annotated Snippet
smc_ib_gid_to_ipv4((u8 *)&attr->gid) != cpu_to_be32(INADDR_NONE)) {
struct in_device *in_dev = __in_dev_get_rcu(ndev);
struct net *net = dev_net(ndev);
const struct in_ifaddr *ifa;
bool subnet_match = false;
if (!in_dev)
goto out;
in_dev_for_each_ifa_rcu(ifa, in_dev) {
if (!inet_ifa_match(smcrv2->saddr, ifa))
continue;
subnet_match = true;
break;
}
if (!subnet_match)
goto out;
if (smcrv2->daddr && smc_ib_find_route(net, smcrv2->saddr,
smcrv2->daddr,
smcrv2->nexthop_mac,
&smcrv2->uses_gateway))
goto out;
if (gid)
memcpy(gid, &attr->gid, SMC_GID_SIZE);
if (sgid_index)
*sgid_index = attr->index;
return 0;
}
out:
return -ENODEV;
}
/* determine the gid for an ib-device port and vlan id */
int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
unsigned short vlan_id, u8 gid[], u8 *sgid_index,
struct smc_init_info_smcrv2 *smcrv2)
{
const struct ib_gid_attr *attr;
const struct net_device *ndev;
int i;
for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
if (IS_ERR(attr))
continue;
rcu_read_lock();
ndev = rdma_read_gid_attr_ndev_rcu(attr);
if (!IS_ERR(ndev) &&
((!vlan_id && !is_vlan_dev(ndev)) ||
(vlan_id && is_vlan_dev(ndev) &&
vlan_dev_vlan_id(ndev) == vlan_id))) {
if (!smc_ib_determine_gid_rcu(ndev, attr, gid,
sgid_index, smcrv2)) {
rcu_read_unlock();
rdma_put_gid_attr(attr);
return 0;
}
}
rcu_read_unlock();
rdma_put_gid_attr(attr);
}
return -ENODEV;
}
/* check if gid is still defined on smcibdev */
static bool smc_ib_check_link_gid(u8 gid[SMC_GID_SIZE], bool smcrv2,
struct smc_ib_device *smcibdev, u8 ibport)
{
const struct ib_gid_attr *attr;
bool rc = false;
int i;
for (i = 0; !rc && i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
if (IS_ERR(attr))
continue;
rcu_read_lock();
if ((!smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE) ||
(smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP &&
!(ipv6_addr_type((const struct in6_addr *)&attr->gid)
& IPV6_ADDR_LINKLOCAL)))
if (!memcmp(gid, &attr->gid, SMC_GID_SIZE))
rc = true;
rcu_read_unlock();
rdma_put_gid_attr(attr);
}
return rc;
}
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/if_vlan.h`, `linux/random.h`, `linux/workqueue.h`, `linux/scatterlist.h`, `linux/wait.h`, `linux/mutex.h`, `linux/inetdevice.h`.
- Detected declarations: `function smc_ib_modify_qp_init`, `function smc_ib_modify_qp_rtr`, `function smc_ib_modify_qp_rts`, `function smc_ib_modify_qp_error`, `function smc_ib_ready_link`, `function smc_ib_fill_mac`, `function smc_ib_define_local_systemid`, `function smc_ib_is_valid_local_systemid`, `function smc_ib_init_local_systemid`, `function smc_ib_port_active`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.