drivers/net/phy/marvell.c

Source file repositories/reference/linux-study-clean/drivers/net/phy/marvell.c

File Facts

System
Linux kernel
Corpus path
drivers/net/phy/marvell.c
Extension
.c
Size
107953 bytes
Lines
4206
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct marvell_hw_stat {
	const char *string;
	u8 page;
	u8 reg;
	u8 bits;
};

static const struct marvell_hw_stat marvell_hw_stats[] = {
	{ "phy_receive_errors_copper", 0, 21, 16},
	{ "phy_idle_errors", 0, 10, 8 },
	{ "phy_receive_errors_fiber", 1, 21, 16},
};

static_assert(ARRAY_SIZE(marvell_hw_stats) <= NB_STAT_MAX);

/* "simple" stat list + corresponding marvell_get_*_simple functions are used
 * on PHYs without a page register
 */
struct marvell_hw_stat_simple {
	const char *string;
	u8 reg;
	u8 bits;
};

static const struct marvell_hw_stat_simple marvell_hw_stats_simple[] = {
	{ "phy_receive_errors", 21, 16},
};

static_assert(ARRAY_SIZE(marvell_hw_stats_simple) <= NB_STAT_MAX);

enum {
	M88E3082_VCT_OFF,
	M88E3082_VCT_PHASE1,
	M88E3082_VCT_PHASE2,
};

struct marvell_priv {
	u64 stats[NB_STAT_MAX];
	char *hwmon_name;
	struct device *hwmon_dev;
	bool cable_test_tdr;
	u32 first;
	u32 last;
	u32 step;
	s8 pair;
	u8 vct_phase;
};

static int marvell_read_page(struct phy_device *phydev)
{
	return __phy_read(phydev, MII_MARVELL_PHY_PAGE);
}

static int marvell_write_page(struct phy_device *phydev, int page)
{
	return __phy_write(phydev, MII_MARVELL_PHY_PAGE, page);
}

static int marvell_set_page(struct phy_device *phydev, int page)
{
	return phy_write(phydev, MII_MARVELL_PHY_PAGE, page);
}

static int marvell_ack_interrupt(struct phy_device *phydev)
{
	int err;

	/* Clear the interrupts by reading the reg */
	err = phy_read(phydev, MII_M1011_IEVENT);

	if (err < 0)
		return err;

	return 0;
}

static int marvell_config_intr(struct phy_device *phydev)
{
	int err;

	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
		err = marvell_ack_interrupt(phydev);
		if (err)
			return err;

		err = phy_write(phydev, MII_M1011_IMASK,
				MII_M1011_IMASK_INIT);
	} else {
		err = phy_write(phydev, MII_M1011_IMASK,
				MII_M1011_IMASK_CLEAR);

Annotation

Implementation Notes