drivers/infiniband/hw/hns/hns_roce_main.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_main.c- Extension
.c- Size
- 35088 bytes
- Lines
- 1298
- 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.
- 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/acpi.hlinux/module.hrdma/ib_addr.hrdma/ib_smi.hrdma/ib_user_verbs.hrdma/ib_cache.hrdma/uverbs_ioctl.hhns_roce_common.hhns_roce_device.hhns_roce_hem.hhns_roce_hw_v2.hhns_roce_bond.h
Detected Declarations
function Copyrightfunction hns_roce_add_gidfunction hns_roce_del_gidfunction hns_roce_get_port_statefunction handle_en_eventfunction hns_roce_netdev_eventfunction hns_roce_setup_mtu_macfunction hns_roce_query_devicefunction hns_roce_query_portfunction hns_roce_get_link_layerfunction hns_roce_query_pkeyfunction hns_roce_modify_devicefunction hns_roce_user_mmap_entry_insertfunction hns_roce_dealloc_uar_entryfunction hns_roce_alloc_uar_entryfunction hns_roce_alloc_ucontextfunction hns_roce_dealloc_ucontextfunction hns_roce_mmapfunction hns_roce_free_mmapfunction hns_roce_port_immutablefunction hns_roce_disassociate_ucontextfunction hns_roce_get_hw_statsfunction hns_roce_unregister_bond_cleanupfunction hns_roce_unregister_devicefunction hns_roce_register_devicefunction hns_roce_init_hemfunction hns_roce_teardown_hcafunction hns_roce_setup_hcafunction check_and_get_armed_cqfunction hns_roce_handle_device_errfunction hns_roce_alloc_dfx_cntfunction hns_roce_dealloc_dfx_cntfunction hns_roce_initfunction hns_roce_exit
Annotated Snippet
if (bond_grp) {
*state = ib_get_curr_port_state(bond_grp->upper_dev);
goto out;
}
}
*state = ib_get_curr_port_state(net_dev);
out:
dev_put(net_dev);
return 0;
}
static int handle_en_event(struct net_device *netdev,
struct hns_roce_dev *hr_dev,
u32 port, unsigned long event)
{
struct ib_device *ibdev = &hr_dev->ib_dev;
struct device *dev = hr_dev->dev;
enum ib_port_state curr_state;
struct ib_event ibevent;
int ret = 0;
if (!netdev) {
dev_err(dev, "can't find netdev on port(%u)!\n", port);
return -ENODEV;
}
switch (event) {
case NETDEV_REGISTER:
case NETDEV_CHANGEADDR:
ret = hns_roce_set_mac(hr_dev, port, netdev->dev_addr);
break;
case NETDEV_UP:
case NETDEV_CHANGE:
ret = hns_roce_set_mac(hr_dev, port, netdev->dev_addr);
if (ret)
return ret;
fallthrough;
case NETDEV_DOWN:
if (!netif_is_lag_master(netdev))
break;
curr_state = ib_get_curr_port_state(netdev);
write_lock_irq(&ibdev->cache_lock);
if (ibdev->port_data[port].cache.last_port_state == curr_state) {
write_unlock_irq(&ibdev->cache_lock);
return 0;
}
ibdev->port_data[port].cache.last_port_state = curr_state;
write_unlock_irq(&ibdev->cache_lock);
ibevent.event = (curr_state == IB_PORT_DOWN) ?
IB_EVENT_PORT_ERR : IB_EVENT_PORT_ACTIVE;
ibevent.device = ibdev;
ibevent.element.port_num = port + 1;
ib_dispatch_event(&ibevent);
break;
default:
dev_dbg(dev, "NETDEV event = 0x%x!\n", (u32)(event));
break;
}
return ret;
}
static int hns_roce_netdev_event(struct notifier_block *self,
unsigned long event, void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct hns_roce_bond_group *bond_grp;
struct hns_roce_ib_iboe *iboe = NULL;
struct hns_roce_dev *hr_dev = NULL;
struct net_device *upper = NULL;
int ret;
u32 port;
hr_dev = container_of(self, struct hns_roce_dev, iboe.nb);
iboe = &hr_dev->iboe;
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_BOND) {
bond_grp = hns_roce_get_bond_grp(get_hr_netdev(hr_dev, 0),
get_hr_bus_num(hr_dev));
upper = bond_grp ? bond_grp->upper_dev : NULL;
}
for (port = 0; port < hr_dev->caps.num_ports; port++) {
if ((!upper && dev == iboe->netdevs[port]) ||
(upper && dev == upper)) {
ret = handle_en_event(dev, hr_dev, port, event);
if (ret)
return NOTIFY_DONE;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/module.h`, `rdma/ib_addr.h`, `rdma/ib_smi.h`, `rdma/ib_user_verbs.h`, `rdma/ib_cache.h`, `rdma/uverbs_ioctl.h`, `hns_roce_common.h`.
- Detected declarations: `function Copyright`, `function hns_roce_add_gid`, `function hns_roce_del_gid`, `function hns_roce_get_port_state`, `function handle_en_event`, `function hns_roce_netdev_event`, `function hns_roce_setup_mtu_mac`, `function hns_roce_query_device`, `function hns_roce_query_port`, `function hns_roce_get_link_layer`.
- 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.
- 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.