Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 3 | * Copyright 2009-2010 Solarflare Communications Inc. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 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 | |
| 10 | #include "net_driver.h" |
| 11 | #include "efx.h" |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 12 | #include "mcdi.h" |
| 13 | #include "mcdi_pcol.h" |
| 14 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 15 | int efx_mcdi_set_mac(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 16 | { |
| 17 | u32 reject, fcntl; |
| 18 | u8 cmdbytes[MC_CMD_SET_MAC_IN_LEN]; |
| 19 | |
| 20 | memcpy(cmdbytes + MC_CMD_SET_MAC_IN_ADDR_OFST, |
| 21 | efx->net_dev->dev_addr, ETH_ALEN); |
| 22 | |
| 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); |
| 26 | |
| 27 | /* The MCDI command provides for controlling accept/reject |
| 28 | * of broadcast packets too, but the driver doesn't currently |
| 29 | * expose this. */ |
| 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); |
| 33 | |
| 34 | switch (efx->wanted_fc) { |
| 35 | case EFX_FC_RX | EFX_FC_TX: |
| 36 | fcntl = MC_CMD_FCNTL_BIDIR; |
| 37 | break; |
| 38 | case EFX_FC_RX: |
| 39 | fcntl = MC_CMD_FCNTL_RESPOND; |
| 40 | break; |
| 41 | default: |
| 42 | fcntl = MC_CMD_FCNTL_OFF; |
| 43 | break; |
| 44 | } |
| 45 | if (efx->wanted_fc & EFX_FC_AUTO) |
| 46 | fcntl = MC_CMD_FCNTL_AUTO; |
Steve Hodgson | a606f43 | 2011-05-23 12:18:45 +0100 | [diff] [blame] | 47 | if (efx->fc_disable) |
| 48 | fcntl = MC_CMD_FCNTL_OFF; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 49 | |
| 50 | MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl); |
| 51 | |
| 52 | return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes), |
| 53 | NULL, 0, NULL); |
| 54 | } |
| 55 | |
Ben Hutchings | 1daf417 | 2011-09-08 02:09:42 +0100 | [diff] [blame] | 56 | bool efx_mcdi_mac_check_fault(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 57 | { |
| 58 | u8 outbuf[MC_CMD_GET_LINK_OUT_LEN]; |
| 59 | size_t outlength; |
| 60 | int rc; |
| 61 | |
| 62 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 63 | |
| 64 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 65 | outbuf, sizeof(outbuf), &outlength); |
Ben Hutchings | 1daf417 | 2011-09-08 02:09:42 +0100 | [diff] [blame] | 66 | if (rc) { |
| 67 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 68 | __func__, rc); |
| 69 | return true; |
| 70 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 71 | |
Ben Hutchings | 1daf417 | 2011-09-08 02:09:42 +0100 | [diff] [blame] | 72 | return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr, |
| 76 | u32 dma_len, int enable, int clear) |
| 77 | { |
| 78 | u8 inbuf[MC_CMD_MAC_STATS_IN_LEN]; |
| 79 | int rc; |
| 80 | efx_dword_t *cmd_ptr; |
Steve Hodgson | 3a59510 | 2010-04-28 09:29:32 +0000 | [diff] [blame] | 81 | int period = enable ? 1000 : 0; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 82 | u32 addr_hi; |
| 83 | u32 addr_lo; |
| 84 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 85 | BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 86 | |
| 87 | addr_lo = ((u64)dma_addr) >> 0; |
| 88 | addr_hi = ((u64)dma_addr) >> 32; |
| 89 | |
| 90 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_LO, addr_lo); |
| 91 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_HI, addr_hi); |
| 92 | cmd_ptr = (efx_dword_t *)MCDI_PTR(inbuf, MAC_STATS_IN_CMD); |
Steve Hodgson | 3a59510 | 2010-04-28 09:29:32 +0000 | [diff] [blame] | 93 | EFX_POPULATE_DWORD_7(*cmd_ptr, |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 94 | MC_CMD_MAC_STATS_IN_DMA, !!enable, |
| 95 | MC_CMD_MAC_STATS_IN_CLEAR, clear, |
| 96 | MC_CMD_MAC_STATS_IN_PERIODIC_CHANGE, 1, |
| 97 | MC_CMD_MAC_STATS_IN_PERIODIC_ENABLE, !!enable, |
| 98 | MC_CMD_MAC_STATS_IN_PERIODIC_CLEAR, 0, |
| 99 | MC_CMD_MAC_STATS_IN_PERIODIC_NOEVENT, 1, |
| 100 | MC_CMD_MAC_STATS_IN_PERIOD_MS, period); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 101 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
| 102 | |
| 103 | rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), |
| 104 | NULL, 0, NULL); |
| 105 | if (rc) |
| 106 | goto fail; |
| 107 | |
| 108 | return 0; |
| 109 | |
| 110 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 111 | netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n", |
| 112 | __func__, enable ? "enable" : "disable", rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 113 | return rc; |
| 114 | } |
| 115 | |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 116 | int efx_mcdi_mac_reconfigure(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 117 | { |
| 118 | int rc; |
| 119 | |
Ben Hutchings | 30b81cd | 2011-09-13 19:47:48 +0100 | [diff] [blame] | 120 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 121 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 122 | rc = efx_mcdi_set_mac(efx); |
| 123 | if (rc != 0) |
| 124 | return rc; |
| 125 | |
Ben Hutchings | 30b81cd | 2011-09-13 19:47:48 +0100 | [diff] [blame] | 126 | return efx_mcdi_rpc(efx, MC_CMD_SET_MCAST_HASH, |
| 127 | efx->multicast_hash.byte, |
| 128 | sizeof(efx->multicast_hash), |
| 129 | NULL, 0, NULL); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 130 | } |