1
1
/****************************************************************************
2
2
* Driver for Solarflare Solarstorm network controllers and boards
3
* Copyright 2008-2009 Solarflare Communications Inc.
3
* Copyright 2008-2011 Solarflare Communications Inc.
5
5
* This program is free software; you can redistribute it and/or modify it
6
6
* under the terms of the GNU General Public License version 2 as published
50
50
return &nic_data->mcdi;
54
efx_mcdi_readd(struct efx_nic *efx, efx_dword_t *value, unsigned reg)
56
struct siena_nic_data *nic_data = efx->nic_data;
57
value->u32[0] = (__force __le32)__raw_readl(nic_data->mcdi_smem + reg);
61
efx_mcdi_writed(struct efx_nic *efx, const efx_dword_t *value, unsigned reg)
63
struct siena_nic_data *nic_data = efx->nic_data;
64
__raw_writel((__force u32)value->u32[0], nic_data->mcdi_smem + reg);
53
67
void efx_mcdi_init(struct efx_nic *efx)
55
69
struct efx_mcdi_iface *mcdi;
70
84
const u8 *inbuf, size_t inlen)
72
86
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
73
unsigned pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
74
unsigned doorbell = FR_CZ_MC_TREG_SMEM + MCDI_DOORBELL(efx);
87
unsigned pdu = MCDI_PDU(efx);
88
unsigned doorbell = MCDI_DOORBELL(efx);
92
106
MCDI_HEADER_SEQ, seqno,
93
107
MCDI_HEADER_XFLAGS, xflags);
95
efx_writed(efx, &hdr, pdu);
109
efx_mcdi_writed(efx, &hdr, pdu);
97
111
for (i = 0; i < inlen; i += 4)
98
_efx_writed(efx, *((__le32 *)(inbuf + i)), pdu + 4 + i);
100
/* Ensure the payload is written out before the header */
112
efx_mcdi_writed(efx, (const efx_dword_t *)(inbuf + i),
103
115
/* ring the doorbell with a distinctive value */
104
_efx_writed(efx, (__force __le32) 0x45789abc, doorbell);
116
EFX_POPULATE_DWORD_1(hdr, EFX_DWORD_0, 0x45789abc);
117
efx_mcdi_writed(efx, &hdr, doorbell);
107
120
static void efx_mcdi_copyout(struct efx_nic *efx, u8 *outbuf, size_t outlen)
109
122
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
110
unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
123
unsigned int pdu = MCDI_PDU(efx);
113
126
BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
114
127
BUG_ON(outlen & 3 || outlen >= 0x100);
116
129
for (i = 0; i < outlen; i += 4)
117
*((__le32 *)(outbuf + i)) = _efx_readd(efx, pdu + 4 + i);
130
efx_mcdi_readd(efx, (efx_dword_t *)(outbuf + i), pdu + 4 + i);
120
133
static int efx_mcdi_poll(struct efx_nic *efx)
122
135
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
123
136
unsigned int time, finish;
124
137
unsigned int respseq, respcmd, error;
125
unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
138
unsigned int pdu = MCDI_PDU(efx);
126
139
unsigned int rc, spins;
149
162
time = get_seconds();
152
efx_readd(efx, ®, pdu);
164
efx_mcdi_readd(efx, ®, pdu);
154
166
/* All 1's indicates that shared memory is in reset (and is
155
167
* not a valid header). Wait for it to come out reset before
176
188
respseq, mcdi->seqno);
178
190
} else if (error) {
179
efx_readd(efx, ®, pdu + 4);
191
efx_mcdi_readd(efx, ®, pdu + 4);
180
192
switch (EFX_DWORD_FIELD(reg, EFX_DWORD_0)) {
181
193
#define TRANSLATE_ERROR(name) \
182
194
case MC_CMD_ERR_ ## name: \
210
222
/* Test and clear MC-rebooted flag for this port/function */
211
223
int efx_mcdi_poll_reboot(struct efx_nic *efx)
213
unsigned int addr = FR_CZ_MC_TREG_SMEM + MCDI_REBOOT_FLAG(efx);
225
unsigned int addr = MCDI_REBOOT_FLAG(efx);
217
229
if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
220
efx_readd(efx, ®, addr);
232
efx_mcdi_readd(efx, ®, addr);
221
233
value = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
226
238
EFX_ZERO_DWORD(reg);
227
efx_writed(efx, ®, addr);
239
efx_mcdi_writed(efx, ®, addr);
229
241
if (value == MC_STATUS_DWORD_ASSERT)
453
465
* There's a race here with efx_mcdi_rpc(), because we might receive
454
466
* a REBOOT event *before* the request has been copied out. In polled
455
* mode (during startup) this is irrelevent, because efx_mcdi_complete()
467
* mode (during startup) this is irrelevant, because efx_mcdi_complete()
456
468
* is ignored. In event mode, this condition is just an edge-case of
457
469
* receiving a REBOOT event after posting the MCDI request. Did the mc
458
470
* reboot before or after the copyout? The best we can do always is
602
614
**************************************************************************
605
int efx_mcdi_fwver(struct efx_nic *efx, u64 *version, u32 *build)
617
void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len)
607
619
u8 outbuf[ALIGN(MC_CMD_GET_VERSION_V1_OUT_LEN, 4)];
608
620
size_t outlength;
619
if (outlength == MC_CMD_GET_VERSION_V0_OUT_LEN) {
621
*build = MCDI_DWORD(outbuf, GET_VERSION_OUT_FIRMWARE);
625
631
if (outlength < MC_CMD_GET_VERSION_V1_OUT_LEN) {
630
636
ver_words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_OUT_VERSION);
631
*version = (((u64)le16_to_cpu(ver_words[0]) << 48) |
632
((u64)le16_to_cpu(ver_words[1]) << 32) |
633
((u64)le16_to_cpu(ver_words[2]) << 16) |
634
le16_to_cpu(ver_words[3]));
635
*build = MCDI_DWORD(outbuf, GET_VERSION_OUT_FIRMWARE);
637
snprintf(buf, len, "%u.%u.%u.%u",
638
le16_to_cpu(ver_words[0]), le16_to_cpu(ver_words[1]),
639
le16_to_cpu(ver_words[2]), le16_to_cpu(ver_words[3]));
640
643
netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
644
647
int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,