mcdi_mac.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2009-2010 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include "net_driver.h"
  10. #include "efx.h"
  11. #include "mcdi.h"
  12. #include "mcdi_pcol.h"
  13. int efx_mcdi_set_mac(struct efx_nic *efx)
  14. {
  15. u32 reject, fcntl;
  16. u8 cmdbytes[MC_CMD_SET_MAC_IN_LEN];
  17. memcpy(cmdbytes + MC_CMD_SET_MAC_IN_ADDR_OFST,
  18. efx->net_dev->dev_addr, ETH_ALEN);
  19. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
  20. EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
  21. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
  22. /* The MCDI command provides for controlling accept/reject
  23. * of broadcast packets too, but the driver doesn't currently
  24. * expose this. */
  25. reject = (efx->promiscuous) ? 0 :
  26. (1 << MC_CMD_SET_MAC_IN_REJECT_UNCST_LBN);
  27. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_REJECT, reject);
  28. switch (efx->wanted_fc) {
  29. case EFX_FC_RX | EFX_FC_TX:
  30. fcntl = MC_CMD_FCNTL_BIDIR;
  31. break;
  32. case EFX_FC_RX:
  33. fcntl = MC_CMD_FCNTL_RESPOND;
  34. break;
  35. default:
  36. fcntl = MC_CMD_FCNTL_OFF;
  37. break;
  38. }
  39. if (efx->wanted_fc & EFX_FC_AUTO)
  40. fcntl = MC_CMD_FCNTL_AUTO;
  41. if (efx->fc_disable)
  42. fcntl = MC_CMD_FCNTL_OFF;
  43. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
  44. return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
  45. NULL, 0, NULL);
  46. }
  47. bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
  48. {
  49. u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
  50. size_t outlength;
  51. int rc;
  52. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  53. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  54. outbuf, sizeof(outbuf), &outlength);
  55. if (rc) {
  56. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  57. __func__, rc);
  58. return true;
  59. }
  60. return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
  61. }
  62. int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
  63. u32 dma_len, int enable, int clear)
  64. {
  65. u8 inbuf[MC_CMD_MAC_STATS_IN_LEN];
  66. int rc;
  67. efx_dword_t *cmd_ptr;
  68. int period = enable ? 1000 : 0;
  69. u32 addr_hi;
  70. u32 addr_lo;
  71. BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
  72. addr_lo = ((u64)dma_addr) >> 0;
  73. addr_hi = ((u64)dma_addr) >> 32;
  74. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_LO, addr_lo);
  75. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_HI, addr_hi);
  76. cmd_ptr = (efx_dword_t *)MCDI_PTR(inbuf, MAC_STATS_IN_CMD);
  77. EFX_POPULATE_DWORD_7(*cmd_ptr,
  78. MC_CMD_MAC_STATS_IN_DMA, !!enable,
  79. MC_CMD_MAC_STATS_IN_CLEAR, clear,
  80. MC_CMD_MAC_STATS_IN_PERIODIC_CHANGE, 1,
  81. MC_CMD_MAC_STATS_IN_PERIODIC_ENABLE, !!enable,
  82. MC_CMD_MAC_STATS_IN_PERIODIC_CLEAR, 0,
  83. MC_CMD_MAC_STATS_IN_PERIODIC_NOEVENT, 1,
  84. MC_CMD_MAC_STATS_IN_PERIOD_MS, period);
  85. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
  86. rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
  87. NULL, 0, NULL);
  88. if (rc)
  89. goto fail;
  90. return 0;
  91. fail:
  92. netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n",
  93. __func__, enable ? "enable" : "disable", rc);
  94. return rc;
  95. }
  96. int efx_mcdi_mac_reconfigure(struct efx_nic *efx)
  97. {
  98. int rc;
  99. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  100. rc = efx_mcdi_set_mac(efx);
  101. if (rc != 0)
  102. return rc;
  103. return efx_mcdi_rpc(efx, MC_CMD_SET_MCAST_HASH,
  104. efx->multicast_hash.byte,
  105. sizeof(efx->multicast_hash),
  106. NULL, 0, NULL);
  107. }