2 * Copyright 2009 Solarflare Communications Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
31 #include "efx_types.h"
40 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
43 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
44 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
45 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_WOL));
47 if (~(encp->enc_features) & EFX_FEATURE_WOL) {
52 /* Current implementation is Siena specific */
53 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
55 enp->en_mod_flags |= EFX_MOD_WOL;
60 EFSYS_PROBE1(fail1, int, rc);
70 uint8_t payload[MC_CMD_WOL_FILTER_RESET_IN_LEN];
73 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
74 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
76 req.emr_cmd = MC_CMD_WOL_FILTER_RESET;
77 req.emr_in_buf = payload;
78 req.emr_in_length = MC_CMD_WOL_FILTER_RESET_IN_LEN;
79 req.emr_out_buf = NULL;
80 req.emr_out_length = 0;
82 MCDI_IN_SET_DWORD(req, WOL_FILTER_RESET_IN_MASK,
83 MC_CMD_WOL_FILTER_RESET_IN_WAKE_FILTERS |
84 MC_CMD_WOL_FILTER_RESET_IN_LIGHTSOUT_OFFLOADS);
86 efx_mcdi_execute(enp, &req);
88 if (req.emr_rc != 0) {
96 EFSYS_PROBE1(fail1, int, rc);
104 __in efx_wol_type_t type,
105 __in efx_wol_param_t *paramp,
106 __out uint32_t *filter_idp)
109 uint8_t payload[MAX(MC_CMD_WOL_FILTER_SET_IN_LEN,
110 MC_CMD_WOL_FILTER_SET_OUT_LEN)];
111 efx_byte_t link_mask;
114 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
115 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
117 req.emr_cmd = MC_CMD_WOL_FILTER_SET;
118 (void) memset(payload, '\0', sizeof (payload));
119 req.emr_in_buf = payload;
120 req.emr_in_length = MC_CMD_WOL_FILTER_SET_IN_LEN;
121 req.emr_out_buf = payload;
122 req.emr_out_length = MC_CMD_WOL_FILTER_SET_OUT_LEN;
125 case EFX_WOL_TYPE_MAGIC:
126 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_FILTER_MODE,
127 MC_CMD_FILTER_MODE_SIMPLE);
128 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_WOL_TYPE,
129 MC_CMD_WOL_TYPE_MAGIC);
131 MCDI_IN2(req, uint8_t, WOL_FILTER_SET_IN_MAGIC_MAC),
132 paramp->ewp_magic.mac_addr);
135 case EFX_WOL_TYPE_BITMAP: {
136 uint32_t swapped = 0;
138 unsigned int pos, bit;
140 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_FILTER_MODE,
141 MC_CMD_FILTER_MODE_SIMPLE);
142 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_WOL_TYPE,
143 MC_CMD_WOL_TYPE_BITMAP);
146 * MC bitmask is supposed to be bit swapped
147 * amongst 32 bit words(!)
150 dwordp = MCDI_IN2(req, efx_dword_t,
151 WOL_FILTER_SET_IN_BITMAP_MASK);
153 EFSYS_ASSERT3U(EFX_WOL_BITMAP_MASK_SIZE % 4, ==, 0);
155 for (pos = 0; pos < EFX_WOL_BITMAP_MASK_SIZE; ++pos) {
156 uint8_t native = paramp->ewp_bitmap.mask[pos];
158 for (bit = 0; bit < 8; ++bit) {
160 swapped |= (native & 0x1);
164 if ((pos & 3) == 3) {
165 EFX_POPULATE_DWORD_1(dwordp[pos >> 2],
166 EFX_DWORD_0, swapped);
171 memcpy(MCDI_IN2(req, uint8_t, WOL_FILTER_SET_IN_BITMAP_BITMAP),
172 paramp->ewp_bitmap.value,
173 sizeof (paramp->ewp_bitmap.value));
175 EFSYS_ASSERT3U(paramp->ewp_bitmap.value_len, <=,
176 sizeof (paramp->ewp_bitmap.value));
177 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_BITMAP_LEN,
178 paramp->ewp_bitmap.value_len);
182 case EFX_WOL_TYPE_LINK:
183 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_FILTER_MODE,
184 MC_CMD_FILTER_MODE_SIMPLE);
185 MCDI_IN_SET_DWORD(req, WOL_FILTER_SET_IN_WOL_TYPE,
186 MC_CMD_WOL_TYPE_LINK);
188 EFX_ZERO_BYTE(link_mask);
189 EFX_SET_BYTE_FIELD(link_mask, MC_CMD_WOL_FILTER_SET_IN_LINK_UP,
191 MCDI_IN_SET_BYTE(req, WOL_FILTER_SET_IN_LINK_MASK,
196 EFSYS_ASSERT3U(type, !=, type);
199 efx_mcdi_execute(enp, &req);
201 if (req.emr_rc != 0) {
206 if (req.emr_out_length_used < MC_CMD_WOL_FILTER_SET_OUT_LEN) {
211 *filter_idp = MCDI_OUT_DWORD(req, WOL_FILTER_SET_OUT_FILTER_ID);
218 EFSYS_PROBE1(fail1, int, rc);
224 efx_wol_filter_remove(
226 __in uint32_t filter_id)
229 uint8_t payload[MC_CMD_WOL_FILTER_REMOVE_IN_LEN];
232 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
233 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
235 req.emr_cmd = MC_CMD_WOL_FILTER_REMOVE;
236 req.emr_in_buf = payload;
237 req.emr_in_length = MC_CMD_WOL_FILTER_REMOVE_IN_LEN;
238 EFX_STATIC_ASSERT(MC_CMD_WOL_FILTER_REMOVE_OUT_LEN == 0);
239 req.emr_out_buf = NULL;
240 req.emr_out_length = 0;
242 MCDI_IN_SET_DWORD(req, WOL_FILTER_REMOVE_IN_FILTER_ID, filter_id);
244 efx_mcdi_execute(enp, &req);
246 if (req.emr_rc != 0) {
254 EFSYS_PROBE1(fail1, int, rc);
261 efx_lightsout_offload_add(
263 __in efx_lightsout_offload_type_t type,
264 __in efx_lightsout_offload_param_t *paramp,
265 __out uint32_t *filter_idp)
268 uint8_t payload[MAX(MAX(MC_CMD_ADD_LIGHTSOUT_OFFLOAD_IN_ARP_LEN,
269 MC_CMD_ADD_LIGHTSOUT_OFFLOAD_IN_NS_LEN),
270 MC_CMD_ADD_LIGHTSOUT_OFFLOAD_OUT_LEN)];
273 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
274 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
276 req.emr_cmd = MC_CMD_ADD_LIGHTSOUT_OFFLOAD;
277 req.emr_in_buf = payload;
278 req.emr_in_length = sizeof (type);
279 req.emr_out_buf = payload;
280 req.emr_out_length = MC_CMD_ADD_LIGHTSOUT_OFFLOAD_OUT_LEN;
283 case EFX_LIGHTSOUT_OFFLOAD_TYPE_ARP:
284 req.emr_in_length = MC_CMD_ADD_LIGHTSOUT_OFFLOAD_IN_ARP_LEN;
285 MCDI_IN_SET_DWORD(req, ADD_LIGHTSOUT_OFFLOAD_IN_PROTOCOL,
286 MC_CMD_LIGHTSOUT_OFFLOAD_PROTOCOL_ARP);
287 EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t,
288 ADD_LIGHTSOUT_OFFLOAD_IN_ARP_MAC),
289 paramp->elop_arp.mac_addr);
290 MCDI_IN_SET_DWORD(req, ADD_LIGHTSOUT_OFFLOAD_IN_ARP_IP,
291 paramp->elop_arp.ip);
293 case EFX_LIGHTSOUT_OFFLOAD_TYPE_NS:
294 req.emr_in_length = MC_CMD_ADD_LIGHTSOUT_OFFLOAD_IN_NS_LEN;
295 MCDI_IN_SET_DWORD(req, ADD_LIGHTSOUT_OFFLOAD_IN_PROTOCOL,
296 MC_CMD_LIGHTSOUT_OFFLOAD_PROTOCOL_NS);
297 EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t,
298 ADD_LIGHTSOUT_OFFLOAD_IN_NS_MAC),
299 paramp->elop_ns.mac_addr);
300 memcpy(MCDI_IN2(req, uint8_t,
301 ADD_LIGHTSOUT_OFFLOAD_IN_NS_SNIPV6),
302 paramp->elop_ns.solicited_node,
303 sizeof (paramp->elop_ns.solicited_node));
304 memcpy(MCDI_IN2(req, uint8_t, ADD_LIGHTSOUT_OFFLOAD_IN_NS_IPV6),
305 paramp->elop_ns.ip, sizeof (paramp->elop_ns.ip));
308 EFSYS_ASSERT3U(type, !=, type);
311 efx_mcdi_execute(enp, &req);
313 if (req.emr_rc != 0) {
318 if (req.emr_out_length_used < MC_CMD_ADD_LIGHTSOUT_OFFLOAD_OUT_LEN) {
323 *filter_idp = MCDI_OUT_DWORD(req, ADD_LIGHTSOUT_OFFLOAD_OUT_FILTER_ID);
330 EFSYS_PROBE1(fail1, int, rc);
337 efx_lightsout_offload_remove(
339 __in efx_lightsout_offload_type_t type,
340 __in uint32_t filter_id)
343 uint8_t payload[MC_CMD_REMOVE_LIGHTSOUT_OFFLOAD_IN_LEN];
346 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
347 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
349 req.emr_cmd = MC_CMD_REMOVE_LIGHTSOUT_OFFLOAD;
350 req.emr_in_buf = payload;
351 req.emr_in_length = sizeof (payload);
352 EFX_STATIC_ASSERT(MC_CMD_REMOVE_LIGHTSOUT_OFFLOAD_OUT_LEN == 0);
353 req.emr_out_buf = NULL;
354 req.emr_out_length = 0;
357 case EFX_LIGHTSOUT_OFFLOAD_TYPE_ARP:
358 MCDI_IN_SET_DWORD(req, REMOVE_LIGHTSOUT_OFFLOAD_IN_PROTOCOL,
359 MC_CMD_LIGHTSOUT_OFFLOAD_PROTOCOL_ARP);
361 case EFX_LIGHTSOUT_OFFLOAD_TYPE_NS:
362 MCDI_IN_SET_DWORD(req, REMOVE_LIGHTSOUT_OFFLOAD_IN_PROTOCOL,
363 MC_CMD_LIGHTSOUT_OFFLOAD_PROTOCOL_NS);
366 EFSYS_ASSERT3U(type, !=, type);
369 MCDI_IN_SET_DWORD(req, REMOVE_LIGHTSOUT_OFFLOAD_IN_FILTER_ID,
372 efx_mcdi_execute(enp, &req);
374 if (req.emr_rc != 0) {
382 EFSYS_PROBE1(fail1, int, rc);
392 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
393 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
394 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_WOL);
396 enp->en_mod_flags &= ~EFX_MOD_WOL;
399 #endif /* EFSYS_OPT_WOL */