1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore * Copyright (c) 2012-2015 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore * All rights reserved.
4*49ef7e06SGarrett D'Amore *
5*49ef7e06SGarrett D'Amore * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore *
8*49ef7e06SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore * this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore * this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore * and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore *
14*49ef7e06SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore *
26*49ef7e06SGarrett D'Amore * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore */
30*49ef7e06SGarrett D'Amore
31*49ef7e06SGarrett D'Amore #include "efx.h"
32*49ef7e06SGarrett D'Amore #include "efx_impl.h"
33*49ef7e06SGarrett D'Amore
34*49ef7e06SGarrett D'Amore #if EFSYS_OPT_SIENA && EFSYS_OPT_MCDI
35*49ef7e06SGarrett D'Amore
36*49ef7e06SGarrett D'Amore #define SIENA_MCDI_PDU(_emip) \
37*49ef7e06SGarrett D'Amore (((emip)->emi_port == 1) \
38*49ef7e06SGarrett D'Amore ? MC_SMEM_P0_PDU_OFST >> 2 \
39*49ef7e06SGarrett D'Amore : MC_SMEM_P1_PDU_OFST >> 2)
40*49ef7e06SGarrett D'Amore
41*49ef7e06SGarrett D'Amore #define SIENA_MCDI_DOORBELL(_emip) \
42*49ef7e06SGarrett D'Amore (((emip)->emi_port == 1) \
43*49ef7e06SGarrett D'Amore ? MC_SMEM_P0_DOORBELL_OFST >> 2 \
44*49ef7e06SGarrett D'Amore : MC_SMEM_P1_DOORBELL_OFST >> 2)
45*49ef7e06SGarrett D'Amore
46*49ef7e06SGarrett D'Amore #define SIENA_MCDI_STATUS(_emip) \
47*49ef7e06SGarrett D'Amore (((emip)->emi_port == 1) \
48*49ef7e06SGarrett D'Amore ? MC_SMEM_P0_STATUS_OFST >> 2 \
49*49ef7e06SGarrett D'Amore : MC_SMEM_P1_STATUS_OFST >> 2)
50*49ef7e06SGarrett D'Amore
51*49ef7e06SGarrett D'Amore
52*49ef7e06SGarrett D'Amore void
siena_mcdi_send_request(__in efx_nic_t * enp,__in void * hdrp,__in size_t hdr_len,__in void * sdup,__in size_t sdu_len)53*49ef7e06SGarrett D'Amore siena_mcdi_send_request(
54*49ef7e06SGarrett D'Amore __in efx_nic_t *enp,
55*49ef7e06SGarrett D'Amore __in void *hdrp,
56*49ef7e06SGarrett D'Amore __in size_t hdr_len,
57*49ef7e06SGarrett D'Amore __in void *sdup,
58*49ef7e06SGarrett D'Amore __in size_t sdu_len)
59*49ef7e06SGarrett D'Amore {
60*49ef7e06SGarrett D'Amore efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
61*49ef7e06SGarrett D'Amore efx_dword_t dword;
62*49ef7e06SGarrett D'Amore unsigned int pdur;
63*49ef7e06SGarrett D'Amore unsigned int dbr;
64*49ef7e06SGarrett D'Amore unsigned int pos;
65*49ef7e06SGarrett D'Amore
66*49ef7e06SGarrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
67*49ef7e06SGarrett D'Amore
68*49ef7e06SGarrett D'Amore EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
69*49ef7e06SGarrett D'Amore pdur = SIENA_MCDI_PDU(emip);
70*49ef7e06SGarrett D'Amore dbr = SIENA_MCDI_DOORBELL(emip);
71*49ef7e06SGarrett D'Amore
72*49ef7e06SGarrett D'Amore /* Write the header */
73*49ef7e06SGarrett D'Amore EFSYS_ASSERT3U(hdr_len, ==, sizeof (efx_dword_t));
74*49ef7e06SGarrett D'Amore dword = *(efx_dword_t *)hdrp;
75*49ef7e06SGarrett D'Amore EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, pdur, &dword, B_TRUE);
76*49ef7e06SGarrett D'Amore
77*49ef7e06SGarrett D'Amore /* Write the payload */
78*49ef7e06SGarrett D'Amore for (pos = 0; pos < sdu_len; pos += sizeof (efx_dword_t)) {
79*49ef7e06SGarrett D'Amore dword = *(efx_dword_t *)((uint8_t *)sdup + pos);
80*49ef7e06SGarrett D'Amore EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM,
81*49ef7e06SGarrett D'Amore pdur + 1 + (pos >> 2), &dword, B_FALSE);
82*49ef7e06SGarrett D'Amore }
83*49ef7e06SGarrett D'Amore
84*49ef7e06SGarrett D'Amore /* Ring the doorbell */
85*49ef7e06SGarrett D'Amore EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xd004be11);
86*49ef7e06SGarrett D'Amore EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, dbr, &dword, B_FALSE);
87*49ef7e06SGarrett D'Amore }
88*49ef7e06SGarrett D'Amore
89*49ef7e06SGarrett D'Amore efx_rc_t
siena_mcdi_poll_reboot(__in efx_nic_t * enp)90*49ef7e06SGarrett D'Amore siena_mcdi_poll_reboot(
91*49ef7e06SGarrett D'Amore __in efx_nic_t *enp)
92*49ef7e06SGarrett D'Amore {
93*49ef7e06SGarrett D'Amore #if 1
94*49ef7e06SGarrett D'Amore /*
95*49ef7e06SGarrett D'Amore * XXX Bug 25922, bug 26099: This function is not being used
96*49ef7e06SGarrett D'Amore * properly. Until its callers are fixed, it should always
97*49ef7e06SGarrett D'Amore * return 0.
98*49ef7e06SGarrett D'Amore */
99*49ef7e06SGarrett D'Amore _NOTE(ARGUNUSED(enp))
100*49ef7e06SGarrett D'Amore return (0);
101*49ef7e06SGarrett D'Amore #else
102*49ef7e06SGarrett D'Amore efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
103*49ef7e06SGarrett D'Amore unsigned int rebootr;
104*49ef7e06SGarrett D'Amore efx_dword_t dword;
105*49ef7e06SGarrett D'Amore uint32_t value;
106*49ef7e06SGarrett D'Amore
107*49ef7e06SGarrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
108*49ef7e06SGarrett D'Amore EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
109*49ef7e06SGarrett D'Amore rebootr = SIENA_MCDI_STATUS(emip);
110*49ef7e06SGarrett D'Amore
111*49ef7e06SGarrett D'Amore EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
112*49ef7e06SGarrett D'Amore value = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
113*49ef7e06SGarrett D'Amore
114*49ef7e06SGarrett D'Amore if (value == 0)
115*49ef7e06SGarrett D'Amore return (0);
116*49ef7e06SGarrett D'Amore
117*49ef7e06SGarrett D'Amore EFX_ZERO_DWORD(dword);
118*49ef7e06SGarrett D'Amore EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
119*49ef7e06SGarrett D'Amore
120*49ef7e06SGarrett D'Amore if (value == MC_STATUS_DWORD_ASSERT)
121*49ef7e06SGarrett D'Amore return (EINTR);
122*49ef7e06SGarrett D'Amore else
123*49ef7e06SGarrett D'Amore return (EIO);
124*49ef7e06SGarrett D'Amore #endif
125*49ef7e06SGarrett D'Amore }
126*49ef7e06SGarrett D'Amore
127*49ef7e06SGarrett D'Amore extern __checkReturn boolean_t
siena_mcdi_poll_response(__in efx_nic_t * enp)128*49ef7e06SGarrett D'Amore siena_mcdi_poll_response(
129*49ef7e06SGarrett D'Amore __in efx_nic_t *enp)
130*49ef7e06SGarrett D'Amore {
131*49ef7e06SGarrett D'Amore efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
132*49ef7e06SGarrett D'Amore efx_dword_t hdr;
133*49ef7e06SGarrett D'Amore unsigned int pdur;
134*49ef7e06SGarrett D'Amore
135*49ef7e06SGarrett D'Amore EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
136*49ef7e06SGarrett D'Amore pdur = SIENA_MCDI_PDU(emip);
137*49ef7e06SGarrett D'Amore
138*49ef7e06SGarrett D'Amore EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, pdur, &hdr, B_FALSE);
139*49ef7e06SGarrett D'Amore return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
140*49ef7e06SGarrett D'Amore }
141*49ef7e06SGarrett D'Amore
142*49ef7e06SGarrett D'Amore void
siena_mcdi_read_response(__in efx_nic_t * enp,__out_bcount (length)void * bufferp,__in size_t offset,__in size_t length)143*49ef7e06SGarrett D'Amore siena_mcdi_read_response(
144*49ef7e06SGarrett D'Amore __in efx_nic_t *enp,
145*49ef7e06SGarrett D'Amore __out_bcount(length) void *bufferp,
146*49ef7e06SGarrett D'Amore __in size_t offset,
147*49ef7e06SGarrett D'Amore __in size_t length)
148*49ef7e06SGarrett D'Amore {
149*49ef7e06SGarrett D'Amore efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
150*49ef7e06SGarrett D'Amore unsigned int pdur;
151*49ef7e06SGarrett D'Amore unsigned int pos;
152*49ef7e06SGarrett D'Amore efx_dword_t data;
153*49ef7e06SGarrett D'Amore
154*49ef7e06SGarrett D'Amore EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
155*49ef7e06SGarrett D'Amore pdur = SIENA_MCDI_PDU(emip);
156*49ef7e06SGarrett D'Amore
157*49ef7e06SGarrett D'Amore for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
158*49ef7e06SGarrett D'Amore EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM,
159*49ef7e06SGarrett D'Amore pdur + ((offset + pos) >> 2), &data, B_FALSE);
160*49ef7e06SGarrett D'Amore (void) memcpy((uint8_t *)bufferp + pos, &data,
161*49ef7e06SGarrett D'Amore MIN(sizeof (data), length - pos));
162*49ef7e06SGarrett D'Amore }
163*49ef7e06SGarrett D'Amore }
164*49ef7e06SGarrett D'Amore
165*49ef7e06SGarrett D'Amore __checkReturn efx_rc_t
siena_mcdi_init(__in efx_nic_t * enp,__in const efx_mcdi_transport_t * mtp)166*49ef7e06SGarrett D'Amore siena_mcdi_init(
167*49ef7e06SGarrett D'Amore __in efx_nic_t *enp,
168*49ef7e06SGarrett D'Amore __in const efx_mcdi_transport_t *mtp)
169*49ef7e06SGarrett D'Amore {
170*49ef7e06SGarrett D'Amore efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
171*49ef7e06SGarrett D'Amore efx_oword_t oword;
172*49ef7e06SGarrett D'Amore unsigned int portnum;
173*49ef7e06SGarrett D'Amore efx_rc_t rc;
174*49ef7e06SGarrett D'Amore
175*49ef7e06SGarrett D'Amore _NOTE(ARGUNUSED(mtp));
176*49ef7e06SGarrett D'Amore
177*49ef7e06SGarrett D'Amore EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
178*49ef7e06SGarrett D'Amore
179*49ef7e06SGarrett D'Amore /* Determine the port number to use for MCDI */
180*49ef7e06SGarrett D'Amore EFX_BAR_READO(enp, FR_AZ_CS_DEBUG_REG, &oword);
181*49ef7e06SGarrett D'Amore portnum = EFX_OWORD_FIELD(oword, FRF_CZ_CS_PORT_NUM);
182*49ef7e06SGarrett D'Amore
183*49ef7e06SGarrett D'Amore if (portnum == 0) {
184*49ef7e06SGarrett D'Amore /* Presumably booted from ROM; only MCDI port 1 will work */
185*49ef7e06SGarrett D'Amore emip->emi_port = 1;
186*49ef7e06SGarrett D'Amore } else if (portnum <= 2) {
187*49ef7e06SGarrett D'Amore emip->emi_port = portnum;
188*49ef7e06SGarrett D'Amore } else {
189*49ef7e06SGarrett D'Amore rc = EINVAL;
190*49ef7e06SGarrett D'Amore goto fail1;
191*49ef7e06SGarrett D'Amore }
192*49ef7e06SGarrett D'Amore
193*49ef7e06SGarrett D'Amore /* Siena BootROM and firmware only support MCDIv1 */
194*49ef7e06SGarrett D'Amore emip->emi_max_version = 1;
195*49ef7e06SGarrett D'Amore
196*49ef7e06SGarrett D'Amore /*
197*49ef7e06SGarrett D'Amore * Wipe the atomic reboot status so subsequent MCDI requests succeed.
198*49ef7e06SGarrett D'Amore * BOOT_STATUS is preserved so eno_nic_probe() can boot out of the
199*49ef7e06SGarrett D'Amore * assertion handler.
200*49ef7e06SGarrett D'Amore */
201*49ef7e06SGarrett D'Amore (void) siena_mcdi_poll_reboot(enp);
202*49ef7e06SGarrett D'Amore
203*49ef7e06SGarrett D'Amore return (0);
204*49ef7e06SGarrett D'Amore
205*49ef7e06SGarrett D'Amore fail1:
206*49ef7e06SGarrett D'Amore EFSYS_PROBE1(fail1, efx_rc_t, rc);
207*49ef7e06SGarrett D'Amore
208*49ef7e06SGarrett D'Amore return (rc);
209*49ef7e06SGarrett D'Amore }
210*49ef7e06SGarrett D'Amore
211*49ef7e06SGarrett D'Amore void
siena_mcdi_fini(__in efx_nic_t * enp)212*49ef7e06SGarrett D'Amore siena_mcdi_fini(
213*49ef7e06SGarrett D'Amore __in efx_nic_t *enp)
214*49ef7e06SGarrett D'Amore {
215*49ef7e06SGarrett D'Amore _NOTE(ARGUNUSED(enp));
216*49ef7e06SGarrett D'Amore }
217*49ef7e06SGarrett D'Amore
218*49ef7e06SGarrett D'Amore __checkReturn efx_rc_t
siena_mcdi_feature_supported(__in efx_nic_t * enp,__in efx_mcdi_feature_id_t id,__out boolean_t * supportedp)219*49ef7e06SGarrett D'Amore siena_mcdi_feature_supported(
220*49ef7e06SGarrett D'Amore __in efx_nic_t *enp,
221*49ef7e06SGarrett D'Amore __in efx_mcdi_feature_id_t id,
222*49ef7e06SGarrett D'Amore __out boolean_t *supportedp)
223*49ef7e06SGarrett D'Amore {
224*49ef7e06SGarrett D'Amore efx_rc_t rc;
225*49ef7e06SGarrett D'Amore
226*49ef7e06SGarrett D'Amore EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
227*49ef7e06SGarrett D'Amore
228*49ef7e06SGarrett D'Amore switch (id) {
229*49ef7e06SGarrett D'Amore case EFX_MCDI_FEATURE_FW_UPDATE:
230*49ef7e06SGarrett D'Amore case EFX_MCDI_FEATURE_LINK_CONTROL:
231*49ef7e06SGarrett D'Amore case EFX_MCDI_FEATURE_MACADDR_CHANGE:
232*49ef7e06SGarrett D'Amore case EFX_MCDI_FEATURE_MAC_SPOOFING:
233*49ef7e06SGarrett D'Amore *supportedp = B_TRUE;
234*49ef7e06SGarrett D'Amore break;
235*49ef7e06SGarrett D'Amore default:
236*49ef7e06SGarrett D'Amore rc = ENOTSUP;
237*49ef7e06SGarrett D'Amore goto fail1;
238*49ef7e06SGarrett D'Amore }
239*49ef7e06SGarrett D'Amore
240*49ef7e06SGarrett D'Amore return (0);
241*49ef7e06SGarrett D'Amore
242*49ef7e06SGarrett D'Amore fail1:
243*49ef7e06SGarrett D'Amore EFSYS_PROBE1(fail1, efx_rc_t, rc);
244*49ef7e06SGarrett D'Amore
245*49ef7e06SGarrett D'Amore return (rc);
246*49ef7e06SGarrett D'Amore }
247*49ef7e06SGarrett D'Amore
248*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_SIENA && EFSYS_OPT_MCDI */
249