enet.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Applied Micro X-Gene SoC Ethernet v2 Driver
  3. *
  4. * Copyright (c) 2017, Applied Micro Circuits Corporation
  5. * Author(s): Iyappan Subramanian <isubramanian@apm.com>
  6. * Keyur Chudgar <kchudgar@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "main.h"
  22. void xge_wr_csr(struct xge_pdata *pdata, u32 offset, u32 val)
  23. {
  24. void __iomem *addr = pdata->resources.base_addr + offset;
  25. iowrite32(val, addr);
  26. }
  27. u32 xge_rd_csr(struct xge_pdata *pdata, u32 offset)
  28. {
  29. void __iomem *addr = pdata->resources.base_addr + offset;
  30. return ioread32(addr);
  31. }
  32. int xge_port_reset(struct net_device *ndev)
  33. {
  34. struct xge_pdata *pdata = netdev_priv(ndev);
  35. struct device *dev = &pdata->pdev->dev;
  36. u32 data, wait = 10;
  37. xge_wr_csr(pdata, ENET_CLKEN, 0x3);
  38. xge_wr_csr(pdata, ENET_SRST, 0xf);
  39. xge_wr_csr(pdata, ENET_SRST, 0);
  40. xge_wr_csr(pdata, CFG_MEM_RAM_SHUTDOWN, 1);
  41. xge_wr_csr(pdata, CFG_MEM_RAM_SHUTDOWN, 0);
  42. do {
  43. usleep_range(100, 110);
  44. data = xge_rd_csr(pdata, BLOCK_MEM_RDY);
  45. } while (data != MEM_RDY && wait--);
  46. if (data != MEM_RDY) {
  47. dev_err(dev, "ECC init failed: %x\n", data);
  48. return -ETIMEDOUT;
  49. }
  50. xge_wr_csr(pdata, ENET_SHIM, DEVM_ARAUX_COH | DEVM_AWAUX_COH);
  51. return 0;
  52. }
  53. static void xge_traffic_resume(struct net_device *ndev)
  54. {
  55. struct xge_pdata *pdata = netdev_priv(ndev);
  56. xge_wr_csr(pdata, CFG_FORCE_LINK_STATUS_EN, 1);
  57. xge_wr_csr(pdata, FORCE_LINK_STATUS, 1);
  58. xge_wr_csr(pdata, CFG_LINK_AGGR_RESUME, 1);
  59. xge_wr_csr(pdata, RX_DV_GATE_REG, 1);
  60. }
  61. void xge_port_init(struct net_device *ndev)
  62. {
  63. struct xge_pdata *pdata = netdev_priv(ndev);
  64. pdata->phy_speed = SPEED_1000;
  65. xge_mac_init(pdata);
  66. xge_traffic_resume(ndev);
  67. }