1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2013 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
32 * e1000_calculate_checksum - Calculate checksum for buffer
33 * @buffer: pointer to EEPROM
34 * @length: size of EEPROM to calculate a checksum for
36 * Calculates the checksum for some buffer on a specified length. The
37 * checksum calculated is returned.
39 static u8
e1000_calculate_checksum(u8
*buffer
, u32 length
)
47 for (i
= 0; i
< length
; i
++)
54 * e1000_mng_enable_host_if - Checks host interface is enabled
55 * @hw: pointer to the HW structure
57 * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
59 * This function checks whether the HOST IF is enabled for command operation
60 * and also checks whether the previous command is completed. It busy waits
61 * in case of previous command is not completed.
63 static s32
e1000_mng_enable_host_if(struct e1000_hw
*hw
)
68 if (!hw
->mac
.arc_subsystem_valid
) {
69 e_dbg("ARC subsystem not valid.\n");
70 return -E1000_ERR_HOST_INTERFACE_COMMAND
;
73 /* Check that the host interface is enabled. */
75 if (!(hicr
& E1000_HICR_EN
)) {
76 e_dbg("E1000_HOST_EN bit disabled.\n");
77 return -E1000_ERR_HOST_INTERFACE_COMMAND
;
79 /* check the previous command is completed */
80 for (i
= 0; i
< E1000_MNG_DHCP_COMMAND_TIMEOUT
; i
++) {
82 if (!(hicr
& E1000_HICR_C
))
87 if (i
== E1000_MNG_DHCP_COMMAND_TIMEOUT
) {
88 e_dbg("Previous command timeout failed .\n");
89 return -E1000_ERR_HOST_INTERFACE_COMMAND
;
96 * e1000e_check_mng_mode_generic - Generic check management mode
97 * @hw: pointer to the HW structure
99 * Reads the firmware semaphore register and returns true (>0) if
100 * manageability is enabled, else false (0).
102 bool e1000e_check_mng_mode_generic(struct e1000_hw
*hw
)
104 u32 fwsm
= er32(FWSM
);
106 return (fwsm
& E1000_FWSM_MODE_MASK
) ==
107 (E1000_MNG_IAMT_MODE
<< E1000_FWSM_MODE_SHIFT
);
111 * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx
112 * @hw: pointer to the HW structure
114 * Enables packet filtering on transmit packets if manageability is enabled
115 * and host interface is enabled.
117 bool e1000e_enable_tx_pkt_filtering(struct e1000_hw
*hw
)
119 struct e1000_host_mng_dhcp_cookie
*hdr
= &hw
->mng_cookie
;
120 u32
*buffer
= (u32
*)&hw
->mng_cookie
;
122 s32 ret_val
, hdr_csum
, csum
;
125 hw
->mac
.tx_pkt_filtering
= true;
127 /* No manageability, no filtering */
128 if (!hw
->mac
.ops
.check_mng_mode(hw
)) {
129 hw
->mac
.tx_pkt_filtering
= false;
130 return hw
->mac
.tx_pkt_filtering
;
133 /* If we can't read from the host interface for whatever
134 * reason, disable filtering.
136 ret_val
= e1000_mng_enable_host_if(hw
);
138 hw
->mac
.tx_pkt_filtering
= false;
139 return hw
->mac
.tx_pkt_filtering
;
142 /* Read in the header. Length and offset are in dwords. */
143 len
= E1000_MNG_DHCP_COOKIE_LENGTH
>> 2;
144 offset
= E1000_MNG_DHCP_COOKIE_OFFSET
>> 2;
145 for (i
= 0; i
< len
; i
++)
146 *(buffer
+ i
) = E1000_READ_REG_ARRAY(hw
, E1000_HOST_IF
,
148 hdr_csum
= hdr
->checksum
;
150 csum
= e1000_calculate_checksum((u8
*)hdr
,
151 E1000_MNG_DHCP_COOKIE_LENGTH
);
152 /* If either the checksums or signature don't match, then
153 * the cookie area isn't considered valid, in which case we
154 * take the safe route of assuming Tx filtering is enabled.
156 if ((hdr_csum
!= csum
) || (hdr
->signature
!= E1000_IAMT_SIGNATURE
)) {
157 hw
->mac
.tx_pkt_filtering
= true;
158 return hw
->mac
.tx_pkt_filtering
;
161 /* Cookie area is valid, make the final check for filtering. */
162 if (!(hdr
->status
& E1000_MNG_DHCP_COOKIE_STATUS_PARSING
))
163 hw
->mac
.tx_pkt_filtering
= false;
165 return hw
->mac
.tx_pkt_filtering
;
169 * e1000_mng_write_cmd_header - Writes manageability command header
170 * @hw: pointer to the HW structure
171 * @hdr: pointer to the host interface command header
173 * Writes the command header after does the checksum calculation.
175 static s32
e1000_mng_write_cmd_header(struct e1000_hw
*hw
,
176 struct e1000_host_mng_command_header
*hdr
)
178 u16 i
, length
= sizeof(struct e1000_host_mng_command_header
);
180 /* Write the whole command header structure with new checksum. */
182 hdr
->checksum
= e1000_calculate_checksum((u8
*)hdr
, length
);
185 /* Write the relevant command block into the ram area. */
186 for (i
= 0; i
< length
; i
++) {
187 E1000_WRITE_REG_ARRAY(hw
, E1000_HOST_IF
, i
, *((u32
*)hdr
+ i
));
195 * e1000_mng_host_if_write - Write to the manageability host interface
196 * @hw: pointer to the HW structure
197 * @buffer: pointer to the host interface buffer
198 * @length: size of the buffer
199 * @offset: location in the buffer to write to
200 * @sum: sum of the data (not checksum)
202 * This function writes the buffer content at the offset given on the host if.
203 * It also does alignment considerations to do the writes in most efficient
204 * way. Also fills up the sum of the buffer in *buffer parameter.
206 static s32
e1000_mng_host_if_write(struct e1000_hw
*hw
, u8
*buffer
,
207 u16 length
, u16 offset
, u8
*sum
)
212 u16 remaining
, i
, j
, prev_bytes
;
214 /* sum = only sum of the data and it is not checksum */
216 if (length
== 0 || offset
+ length
> E1000_HI_MAX_MNG_DATA_LENGTH
)
217 return -E1000_ERR_PARAM
;
220 prev_bytes
= offset
& 0x3;
224 data
= E1000_READ_REG_ARRAY(hw
, E1000_HOST_IF
, offset
);
225 for (j
= prev_bytes
; j
< sizeof(u32
); j
++) {
226 *(tmp
+ j
) = *bufptr
++;
229 E1000_WRITE_REG_ARRAY(hw
, E1000_HOST_IF
, offset
, data
);
230 length
-= j
- prev_bytes
;
234 remaining
= length
& 0x3;
237 /* Calculate length in DWORDs */
240 /* The device driver writes the relevant command block into the
243 for (i
= 0; i
< length
; i
++) {
244 for (j
= 0; j
< sizeof(u32
); j
++) {
245 *(tmp
+ j
) = *bufptr
++;
249 E1000_WRITE_REG_ARRAY(hw
, E1000_HOST_IF
, offset
+ i
, data
);
252 for (j
= 0; j
< sizeof(u32
); j
++) {
254 *(tmp
+ j
) = *bufptr
++;
260 E1000_WRITE_REG_ARRAY(hw
, E1000_HOST_IF
, offset
+ i
, data
);
267 * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
268 * @hw: pointer to the HW structure
269 * @buffer: pointer to the host interface
270 * @length: size of the buffer
272 * Writes the DHCP information to the host interface.
274 s32
e1000e_mng_write_dhcp_info(struct e1000_hw
*hw
, u8
*buffer
, u16 length
)
276 struct e1000_host_mng_command_header hdr
;
280 hdr
.command_id
= E1000_MNG_DHCP_TX_PAYLOAD_CMD
;
281 hdr
.command_length
= length
;
286 /* Enable the host interface */
287 ret_val
= e1000_mng_enable_host_if(hw
);
291 /* Populate the host interface with the contents of "buffer". */
292 ret_val
= e1000_mng_host_if_write(hw
, buffer
, length
,
293 sizeof(hdr
), &(hdr
.checksum
));
297 /* Write the manageability command header */
298 ret_val
= e1000_mng_write_cmd_header(hw
, &hdr
);
302 /* Tell the ARC a new command is pending. */
304 ew32(HICR
, hicr
| E1000_HICR_C
);
310 * e1000e_enable_mng_pass_thru - Check if management passthrough is needed
311 * @hw: pointer to the HW structure
313 * Verifies the hardware needs to leave interface enabled so that frames can
314 * be directed to and from the management interface.
316 bool e1000e_enable_mng_pass_thru(struct e1000_hw
*hw
)
323 if (!(manc
& E1000_MANC_RCV_TCO_EN
))
326 if (hw
->mac
.has_fwsm
) {
328 factps
= er32(FACTPS
);
330 if (!(factps
& E1000_FACTPS_MNGCG
) &&
331 ((fwsm
& E1000_FWSM_MODE_MASK
) ==
332 (e1000_mng_mode_pt
<< E1000_FWSM_MODE_SHIFT
)))
334 } else if ((hw
->mac
.type
== e1000_82574
) ||
335 (hw
->mac
.type
== e1000_82583
)) {
338 factps
= er32(FACTPS
);
339 e1000_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &data
);
341 if (!(factps
& E1000_FACTPS_MNGCG
) &&
342 ((data
& E1000_NVM_INIT_CTRL2_MNGM
) ==
343 (e1000_mng_mode_pt
<< 13)))
345 } else if ((manc
& E1000_MANC_SMBUS_EN
) &&
346 !(manc
& E1000_MANC_ASF_EN
)) {