Commit | Line | Data |
---|---|---|
afd4aea0 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | |
0a6f40c6 | 3 | * Copyright 2009-2010 Solarflare Communications Inc. |
afd4aea0 BH |
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" | |
afd4aea0 BH |
12 | #include "mcdi.h" |
13 | #include "mcdi_pcol.h" | |
14 | ||
15 | static int efx_mcdi_set_mac(struct efx_nic *efx) | |
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; | |
47 | ||
48 | MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl); | |
49 | ||
50 | return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes), | |
51 | NULL, 0, NULL); | |
52 | } | |
53 | ||
1daf4170 | 54 | bool efx_mcdi_mac_check_fault(struct efx_nic *efx) |
afd4aea0 BH |
55 | { |
56 | u8 outbuf[MC_CMD_GET_LINK_OUT_LEN]; | |
57 | size_t outlength; | |
58 | int rc; | |
59 | ||
60 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); | |
61 | ||
62 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, | |
63 | outbuf, sizeof(outbuf), &outlength); | |
1daf4170 BH |
64 | if (rc) { |
65 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", | |
66 | __func__, rc); | |
67 | return true; | |
68 | } | |
afd4aea0 | 69 | |
1daf4170 | 70 | return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0; |
afd4aea0 BH |
71 | } |
72 | ||
73 | int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr, | |
74 | u32 dma_len, int enable, int clear) | |
75 | { | |
76 | u8 inbuf[MC_CMD_MAC_STATS_IN_LEN]; | |
77 | int rc; | |
78 | efx_dword_t *cmd_ptr; | |
3a595102 | 79 | int period = enable ? 1000 : 0; |
afd4aea0 BH |
80 | u32 addr_hi; |
81 | u32 addr_lo; | |
82 | ||
05a9320f | 83 | BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0); |
afd4aea0 BH |
84 | |
85 | addr_lo = ((u64)dma_addr) >> 0; | |
86 | addr_hi = ((u64)dma_addr) >> 32; | |
87 | ||
88 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_LO, addr_lo); | |
89 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_HI, addr_hi); | |
90 | cmd_ptr = (efx_dword_t *)MCDI_PTR(inbuf, MAC_STATS_IN_CMD); | |
3a595102 | 91 | EFX_POPULATE_DWORD_7(*cmd_ptr, |
05a9320f BH |
92 | MC_CMD_MAC_STATS_IN_DMA, !!enable, |
93 | MC_CMD_MAC_STATS_IN_CLEAR, clear, | |
94 | MC_CMD_MAC_STATS_IN_PERIODIC_CHANGE, 1, | |
95 | MC_CMD_MAC_STATS_IN_PERIODIC_ENABLE, !!enable, | |
96 | MC_CMD_MAC_STATS_IN_PERIODIC_CLEAR, 0, | |
97 | MC_CMD_MAC_STATS_IN_PERIODIC_NOEVENT, 1, | |
98 | MC_CMD_MAC_STATS_IN_PERIOD_MS, period); | |
afd4aea0 BH |
99 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
100 | ||
101 | rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), | |
102 | NULL, 0, NULL); | |
103 | if (rc) | |
104 | goto fail; | |
105 | ||
106 | return 0; | |
107 | ||
108 | fail: | |
62776d03 BH |
109 | netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n", |
110 | __func__, enable ? "enable" : "disable", rc); | |
afd4aea0 BH |
111 | return rc; |
112 | } | |
113 | ||
710b208d | 114 | int efx_mcdi_mac_reconfigure(struct efx_nic *efx) |
afd4aea0 BH |
115 | { |
116 | int rc; | |
117 | ||
30b81cda BH |
118 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
119 | ||
afd4aea0 BH |
120 | rc = efx_mcdi_set_mac(efx); |
121 | if (rc != 0) | |
122 | return rc; | |
123 | ||
30b81cda BH |
124 | return efx_mcdi_rpc(efx, MC_CMD_SET_MCAST_HASH, |
125 | efx->multicast_hash.byte, | |
126 | sizeof(efx->multicast_hash), | |
127 | NULL, 0, NULL); | |
afd4aea0 | 128 | } |