mcdi_port.c 3.0 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2
/****************************************************************************
B
Ben Hutchings 已提交
3 4
 * Driver for Solarflare network controllers and boards
 * Copyright 2009-2013 Solarflare Communications Inc.
5 6 7 8 9 10
 */

/*
 * Driver for PHY related operations via MCDI.
 */

11
#include <linux/slab.h>
12
#include "efx.h"
13
#include "mcdi_port.h"
14 15
#include "mcdi.h"
#include "mcdi_pcol.h"
16 17
#include "nic.h"
#include "selftest.h"
18
#include "mcdi_port_common.h"
19

20 21
static int efx_mcdi_mdio_read(struct net_device *net_dev,
			      int prtad, int devad, u16 addr)
22
{
23
	struct efx_nic *efx = efx_netdev_priv(net_dev);
24 25
	MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN);
	MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN);
26 27 28
	size_t outlen;
	int rc;

29
	MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, efx->mdio_bus);
30 31 32 33 34 35 36
	MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad);
	MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad);
	MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr);

	rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf),
			  outbuf, sizeof(outbuf), &outlen);
	if (rc)
E
Edward Cree 已提交
37
		return rc;
38

39 40 41 42 43
	if (MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS) !=
	    MC_CMD_MDIO_STATUS_GOOD)
		return -EIO;

	return (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE);
44 45
}

46 47
static int efx_mcdi_mdio_write(struct net_device *net_dev,
			       int prtad, int devad, u16 addr, u16 value)
48
{
49
	struct efx_nic *efx = efx_netdev_priv(net_dev);
50 51
	MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN);
	MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN);
52 53 54
	size_t outlen;
	int rc;

55
	MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, efx->mdio_bus);
56 57 58 59 60 61 62 63
	MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad);
	MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad);
	MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr);
	MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value);

	rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf),
			  outbuf, sizeof(outbuf), &outlen);
	if (rc)
E
Edward Cree 已提交
64
		return rc;
65

66 67 68 69
	if (MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS) !=
	    MC_CMD_MDIO_STATUS_GOOD)
		return -EIO;

70 71 72
	return 0;
}

73 74 75 76 77 78 79
u32 efx_mcdi_phy_get_caps(struct efx_nic *efx)
{
	struct efx_mcdi_phy_data *phy_data = efx->phy_data;

	return phy_data->supported_cap;
}

80 81 82 83 84 85 86 87 88 89
bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
{
	MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
	size_t outlength;
	int rc;

	BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);

	rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
			  outbuf, sizeof(outbuf), &outlength);
E
Edward Cree 已提交
90
	if (rc)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
		return true;

	return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
}

int efx_mcdi_port_probe(struct efx_nic *efx)
{
	int rc;

	/* Set up MDIO structure for PHY */
	efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
	efx->mdio.mdio_read = efx_mcdi_mdio_read;
	efx->mdio.mdio_write = efx_mcdi_mdio_write;

	/* Fill out MDIO structure, loopback modes, and initial link state */
E
Edward Cree 已提交
106
	rc = efx_mcdi_phy_probe(efx);
107 108 109
	if (rc != 0)
		return rc;

110
	return efx_mcdi_mac_init_stats(efx);
111 112 113 114
}

void efx_mcdi_port_remove(struct efx_nic *efx)
{
E
Edward Cree 已提交
115
	efx_mcdi_phy_remove(efx);
116
	efx_mcdi_mac_fini_stats(efx);
117
}