drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
Extension
.c
Size
236092 bytes
Lines
8436
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct net_device_ops stmmac_netdev_ops;
static void stmmac_init_fs(struct net_device *dev);
static void stmmac_exit_fs(struct net_device *dev);
#endif

#define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC))

struct stmmac_devlink_priv {
	struct stmmac_priv *stmmac_priv;
};

enum stmmac_dl_param_id {
	STMMAC_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
	STMMAC_DEVLINK_PARAM_ID_TS_COARSE,
};

/**
 * stmmac_set_clk_tx_rate() - set the clock rate for the MAC transmit clock
 * @bsp_priv: BSP private data structure (unused)
 * @clk_tx_i: the transmit clock
 * @interface: the selected interface mode
 * @speed: the speed that the MAC will be operating at
 *
 * Set the transmit clock rate for the MAC, normally 2.5MHz for 10Mbps,
 * 25MHz for 100Mbps and 125MHz for 1Gbps. This is suitable for at least
 * MII, GMII, RGMII and RMII interface modes. Platforms can hook this into
 * the plat_data->set_clk_tx_rate method directly, call it via their own
 * implementation, or implement their own method should they have more
 * complex requirements. It is intended to only be used in this method.
 *
 * plat_data->clk_tx_i must be filled in.
 */
int stmmac_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i,
			   phy_interface_t interface, int speed)
{
	long rate = rgmii_clock(speed);

	/* Silently ignore unsupported speeds as rgmii_clock() only
	 * supports 10, 100 and 1000Mbps. We do not want to spit
	 * errors for 2500 and higher speeds here.
	 */
	if (rate < 0)
		return 0;

	return clk_set_rate(clk_tx_i, rate);
}
EXPORT_SYMBOL_GPL(stmmac_set_clk_tx_rate);

/**
 * stmmac_axi_blen_to_mask() - convert a burst length array to reg value
 * @regval: pointer to a u32 for the resulting register value
 * @blen: pointer to an array of u32 containing the burst length values in bytes
 * @len: the number of entries in the @blen array
 */
void stmmac_axi_blen_to_mask(u32 *regval, const u32 *blen, size_t len)
{
	size_t i;
	u32 val;

	for (val = i = 0; i < len; i++) {
		u32 burst = blen[i];

		/* Burst values of zero must be skipped. */
		if (!burst)
			continue;

		/* The valid range for the burst length is 4 to 256 inclusive,
		 * and it must be a power of two.
		 */
		if (burst < 4 || burst > 256 || !is_power_of_2(burst)) {
			pr_err("stmmac: invalid burst length %u at index %zu\n",
			       burst, i);
			continue;
		}

		/* Since burst is a power of two, and the register field starts
		 * with burst = 4, shift right by two bits so bit 0 of the field
		 * corresponds with the minimum value.
		 */
		val |= burst >> 2;
	}

	*regval = FIELD_PREP(DMA_AXI_BLEN_MASK, val);
}
EXPORT_SYMBOL_GPL(stmmac_axi_blen_to_mask);

/**
 * stmmac_verify_args - verify the driver parameters.
 * Description: it checks the driver parameters and set a default in case of
 * errors.

Annotation

Implementation Notes