1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2009-2010 Solarflare Communications Inc.
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.
10 #include "net_driver.h"
13 #include "mcdi_pcol.h"
15 static int efx_mcdi_set_mac(struct efx_nic *efx)
18 u8 cmdbytes[MC_CMD_SET_MAC_IN_LEN];
20 memcpy(cmdbytes + MC_CMD_SET_MAC_IN_ADDR_OFST,
21 efx->net_dev->dev_addr, ETH_ALEN);
23 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
24 EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
25 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
27 /* The MCDI command provides for controlling accept/reject
28 * of broadcast packets too, but the driver doesn't currently
30 reject = (efx->promiscuous) ? 0 :
31 (1 << MC_CMD_SET_MAC_IN_REJECT_UNCST_LBN);
32 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_REJECT, reject);
34 switch (efx->wanted_fc) {
35 case EFX_FC_RX | EFX_FC_TX:
36 fcntl = MC_CMD_FCNTL_BIDIR;
39 fcntl = MC_CMD_FCNTL_RESPOND;
42 fcntl = MC_CMD_FCNTL_OFF;
45 if (efx->wanted_fc & EFX_FC_AUTO)
46 fcntl = MC_CMD_FCNTL_AUTO;
48 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
50 return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
54 static int efx_mcdi_get_mac_faults(struct efx_nic *efx, u32 *faults)
56 u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
60 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
62 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
63 outbuf, sizeof(outbuf), &outlength);
67 *faults = MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT);
71 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
76 int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
77 u32 dma_len, int enable, int clear)
79 u8 inbuf[MC_CMD_MAC_STATS_IN_LEN];
82 int period = enable ? 1000 : 0;
86 BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
88 addr_lo = ((u64)dma_addr) >> 0;
89 addr_hi = ((u64)dma_addr) >> 32;
91 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_LO, addr_lo);
92 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_HI, addr_hi);
93 cmd_ptr = (efx_dword_t *)MCDI_PTR(inbuf, MAC_STATS_IN_CMD);
94 EFX_POPULATE_DWORD_7(*cmd_ptr,
95 MC_CMD_MAC_STATS_IN_DMA, !!enable,
96 MC_CMD_MAC_STATS_IN_CLEAR, clear,
97 MC_CMD_MAC_STATS_IN_PERIODIC_CHANGE, 1,
98 MC_CMD_MAC_STATS_IN_PERIODIC_ENABLE, !!enable,
99 MC_CMD_MAC_STATS_IN_PERIODIC_CLEAR, 0,
100 MC_CMD_MAC_STATS_IN_PERIODIC_NOEVENT, 1,
101 MC_CMD_MAC_STATS_IN_PERIOD_MS, period);
102 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
104 rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
112 netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n",
113 __func__, enable ? "enable" : "disable", rc);
117 int efx_mcdi_mac_reconfigure(struct efx_nic *efx)
121 rc = efx_mcdi_set_mac(efx);
125 /* Restore the multicast hash registers. */
126 efx->type->push_multicast_hash(efx);
132 bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
135 int rc = efx_mcdi_get_mac_faults(efx, &faults);
136 return (rc != 0) || (faults != 0);