drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c- Extension
.c- Size
- 11982 bytes
- Lines
- 400
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/etherdevice.hlinux/ethtool.hlinux/if_vlan.hlinux/iopoll.hlinux/minmax.hhbg_common.hhbg_hw.hhbg_reg.h
Detected Declarations
function hbg_hw_spec_is_validfunction hbg_hw_event_notifyfunction hbg_hw_dev_specs_initfunction hbg_hw_get_irq_statusfunction hbg_hw_irq_clearfunction hbg_hw_irq_is_enabledfunction hbg_hw_irq_enablefunction hbg_hw_set_uc_addrfunction hbg_hw_set_pcu_max_frame_lenfunction hbg_hw_set_mac_max_frame_lenfunction hbg_hw_set_mtufunction hbg_hw_mac_enablefunction hbg_hw_get_fifo_used_numfunction hbg_hw_set_tx_descfunction hbg_hw_fill_bufferfunction hbg_hw_adjust_linkfunction hbg_hw_set_mac_filter_enablefunction hbg_hw_set_pause_enablefunction hbg_hw_get_pause_enablefunction hbg_hw_set_rx_pause_mac_addrfunction hbg_hw_set_fifo_thrsldfunction hbg_hw_set_cfg_fifo_thrsldfunction hbg_hw_init_transmit_ctrlfunction hbg_hw_init_rx_ctrlfunction hbg_hw_init_rx_controlfunction hbg_hw_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2024 Hisilicon Limited.
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/if_vlan.h>
#include <linux/iopoll.h>
#include <linux/minmax.h>
#include "hbg_common.h"
#include "hbg_hw.h"
#include "hbg_reg.h"
#define HBG_HW_EVENT_WAIT_TIMEOUT_US (2 * 1000 * 1000)
#define HBG_HW_EVENT_WAIT_INTERVAL_US (10 * 1000)
#define HBG_MAC_LINK_WAIT_TIMEOUT_US (500 * 1000)
#define HBG_MAC_LINK_WAIT_INTERVAL_US (5 * 1000)
/* little endian or big endian.
* ctrl means packet description, data means skb packet data
*/
#define HBG_ENDIAN_CTRL_LE_DATA_BE 0x0
#define HBG_PCU_FRAME_LEN_PLUS 4
#define HBG_FIFO_TX_FULL_THRSLD 0x3F0
#define HBG_FIFO_TX_EMPTY_THRSLD 0x1F0
#define HBG_FIFO_RX_FULL_THRSLD 0x240
#define HBG_FIFO_RX_EMPTY_THRSLD 0x190
#define HBG_CFG_FIFO_FULL_THRSLD 0x10
#define HBG_CFG_FIFO_EMPTY_THRSLD 0x01
static bool hbg_hw_spec_is_valid(struct hbg_priv *priv)
{
return hbg_reg_read(priv, HBG_REG_SPEC_VALID_ADDR) &&
!hbg_reg_read(priv, HBG_REG_EVENT_REQ_ADDR);
}
int hbg_hw_event_notify(struct hbg_priv *priv,
enum hbg_hw_event_type event_type)
{
bool is_valid;
int ret;
if (test_and_set_bit(HBG_NIC_STATE_EVENT_HANDLING, &priv->state))
return -EBUSY;
/* notify */
hbg_reg_write(priv, HBG_REG_EVENT_REQ_ADDR, event_type);
ret = read_poll_timeout(hbg_hw_spec_is_valid, is_valid, is_valid,
HBG_HW_EVENT_WAIT_INTERVAL_US,
HBG_HW_EVENT_WAIT_TIMEOUT_US,
HBG_HW_EVENT_WAIT_INTERVAL_US, priv);
clear_bit(HBG_NIC_STATE_EVENT_HANDLING, &priv->state);
if (ret)
dev_err(&priv->pdev->dev,
"event %d wait timeout\n", event_type);
return ret;
}
static int hbg_hw_dev_specs_init(struct hbg_priv *priv)
{
struct hbg_dev_specs *specs = &priv->dev_specs;
u64 mac_addr;
if (!hbg_hw_spec_is_valid(priv)) {
dev_err(&priv->pdev->dev, "dev_specs not init\n");
return -EINVAL;
}
specs->mac_id = hbg_reg_read(priv, HBG_REG_MAC_ID_ADDR);
specs->phy_addr = hbg_reg_read(priv, HBG_REG_PHY_ID_ADDR);
specs->mdio_frequency = hbg_reg_read(priv, HBG_REG_MDIO_FREQ_ADDR);
specs->max_mtu = hbg_reg_read(priv, HBG_REG_MAX_MTU_ADDR);
specs->min_mtu = hbg_reg_read(priv, HBG_REG_MIN_MTU_ADDR);
specs->vlan_layers = hbg_reg_read(priv, HBG_REG_VLAN_LAYERS_ADDR);
specs->rx_fifo_num = hbg_reg_read(priv, HBG_REG_RX_FIFO_NUM_ADDR);
specs->tx_fifo_num = hbg_reg_read(priv, HBG_REG_TX_FIFO_NUM_ADDR);
specs->uc_mac_num = hbg_reg_read(priv, HBG_REG_UC_MAC_NUM_ADDR);
mac_addr = hbg_reg_read64(priv, HBG_REG_MAC_ADDR_ADDR);
u64_to_ether_addr(mac_addr, (u8 *)specs->mac_addr.sa_data);
if (!is_valid_ether_addr((u8 *)specs->mac_addr.sa_data))
return -EADDRNOTAVAIL;
specs->max_frame_len = HBG_PCU_CACHE_LINE_SIZE + specs->max_mtu;
specs->rx_buf_size = HBG_PACKET_HEAD_SIZE + specs->max_frame_len;
return 0;
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/ethtool.h`, `linux/if_vlan.h`, `linux/iopoll.h`, `linux/minmax.h`, `hbg_common.h`, `hbg_hw.h`, `hbg_reg.h`.
- Detected declarations: `function hbg_hw_spec_is_valid`, `function hbg_hw_event_notify`, `function hbg_hw_dev_specs_init`, `function hbg_hw_get_irq_status`, `function hbg_hw_irq_clear`, `function hbg_hw_irq_is_enabled`, `function hbg_hw_irq_enable`, `function hbg_hw_set_uc_addr`, `function hbg_hw_set_pcu_max_frame_len`, `function hbg_hw_set_mac_max_frame_len`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.