/*
* Copyright (c) 2014-2015 Hisilicon Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/acpi.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_mdio.h>
#include <linux/phy.h>
#include <linux/platform_device.h>
#include "hns_dsaf_main.h"
#include "hns_dsaf_misc.h"
#include "hns_dsaf_rcb.h"
#define MAC_EN_FLAG_V 0xada0328
static const u16 mac_phy_to_speed[] = {
[PHY_INTERFACE_MODE_MII] = MAC_SPEED_100,
[PHY_INTERFACE_MODE_GMII] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_SGMII] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_TBI] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_RMII] = MAC_SPEED_100,
[PHY_INTERFACE_MODE_RGMII] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_RGMII_ID] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_RGMII_RXID] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_RGMII_TXID] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_RTBI] = MAC_SPEED_1000,
[PHY_INTERFACE_MODE_XGMII] = MAC_SPEED_10000
};
static const enum mac_mode g_mac_mode_100[] = {
[PHY_INTERFACE_MODE_MII] = MAC_MODE_MII_100,
[PHY_INTERFACE_MODE_RMII] = MAC_MODE_RMII_100
};
static const enum mac_mode g_mac_mode_1000[] = {
[PHY_INTERFACE_MODE_GMII] = MAC_MODE_GMII_1000,
[PHY_INTERFACE_MODE_SGMII] = MAC_MODE_SGMII_1000,
[PHY_INTERFACE_MODE_TBI] = MAC_MODE_TBI_1000,
[PHY_INTERFACE_MODE_RGMII] = MAC_MODE_RGMII_1000,
[PHY_INTERFACE_MODE_RGMII_ID] = MAC_MODE_RGMII_1000,
[PHY_INTERFACE_MODE_RGMII_RXID] = MAC_MODE_RGMII_1000,
[PHY_INTERFACE_MODE_RGMII_TXID] = MAC_MODE_RGMII_1000,
[PHY_INTERFACE_MODE_RTBI] = MAC_MODE_RTBI_1000
};
static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
{
switch (mac_cb->max_speed) {
case MAC_SPEED_100:
return g_mac_mode_100[mac_cb->phy_if];
case MAC_SPEED_1000:
return g_mac_mode_1000[mac_cb->phy_if];
case MAC_SPEED_10000:
return MAC_MODE_XGMII_10000;
default:
return MAC_MODE_MII_100;
}
}
void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status)
{
struct mac_driver *mac_ctrl_drv;
int ret, sfp_prsnt;
mac_ctrl_drv = hns_mac_get_drv(mac_cb);
if (mac_ctrl_drv->get_link_status)
mac_ctrl_drv->get_link_status(mac_ctrl_drv, link_status);
else
*link_status = 0;
ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb, &sfp_prsnt);
if (!ret)
*link_status = *link_status && sfp_prsnt;
mac_cb->link = *link_status;
}
int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
u8 *auto_neg, u16 *speed, u8 *duplex)
{
struct mac_driver *mac_ctrl_drv;
struct mac_info info;
mac_ctrl_drv = hns_mac_get_drv(mac_cb);
if (!mac_ctrl_drv->get_info)
return -ENODEV;
mac_ctrl_drv->get_info(mac_ctrl_drv, &info);
if (auto_neg)
*auto_neg = info.auto_neg;
if (speed)
*speed = info.speed;
if (duplex)
*duplex = info.duplex;
return 0;
}
void hns_mac_adjust_link(struct hns_mac_cb *mac_cb