xref: /onnv-gate/usr/src/uts/common/io/igb/igb_manage.c (revision 12111:a462ebfcbf99)
15779Sxy150489 /*
25779Sxy150489  * CDDL HEADER START
35779Sxy150489  *
45779Sxy150489  * The contents of this file are subject to the terms of the
55779Sxy150489  * Common Development and Distribution License (the "License").
65779Sxy150489  * You may not use this file except in compliance with the License.
75779Sxy150489  *
8*12111SGuoqing.Zhu@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12111SGuoqing.Zhu@Sun.COM  * or http://www.opensolaris.org/os/licensing.
105779Sxy150489  * See the License for the specific language governing permissions
115779Sxy150489  * and limitations under the License.
125779Sxy150489  *
13*12111SGuoqing.Zhu@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12111SGuoqing.Zhu@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155779Sxy150489  * If applicable, add the following below this CDDL HEADER, with the
165779Sxy150489  * fields enclosed by brackets "[]" replaced with your own identifying
175779Sxy150489  * information: Portions Copyright [yyyy] [name of copyright owner]
185779Sxy150489  *
195779Sxy150489  * CDDL HEADER END
205779Sxy150489  */
215779Sxy150489 
225779Sxy150489 /*
23*12111SGuoqing.Zhu@Sun.COM  * Copyright(c) 2007-2010 Intel Corporation. All rights reserved.
245779Sxy150489  */
255779Sxy150489 
26*12111SGuoqing.Zhu@Sun.COM /*
27*12111SGuoqing.Zhu@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28*12111SGuoqing.Zhu@Sun.COM  */
29*12111SGuoqing.Zhu@Sun.COM 
30*12111SGuoqing.Zhu@Sun.COM /* IntelVersion: 1.27 v3_3_14_3_BHSW1 */
315779Sxy150489 
325779Sxy150489 #include "igb_api.h"
335779Sxy150489 
345779Sxy150489 static u8 e1000_calculate_checksum(u8 *buffer, u32 length);
355779Sxy150489 
365779Sxy150489 /*
375779Sxy150489  * e1000_calculate_checksum - Calculate checksum for buffer
385779Sxy150489  * @buffer: pointer to EEPROM
395779Sxy150489  * @length: size of EEPROM to calculate a checksum for
405779Sxy150489  *
415779Sxy150489  * Calculates the checksum for some buffer on a specified length.  The
425779Sxy150489  * checksum calculated is returned.
435779Sxy150489  */
e1000_calculate_checksum(u8 * buffer,u32 length)445779Sxy150489 static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
455779Sxy150489 {
465779Sxy150489 	u32 i;
475779Sxy150489 	u8  sum = 0;
485779Sxy150489 
495779Sxy150489 	DEBUGFUNC("e1000_calculate_checksum");
505779Sxy150489 
515779Sxy150489 	if (!buffer)
525779Sxy150489 		return (0);
535779Sxy150489 
545779Sxy150489 	for (i = 0; i < length; i++)
555779Sxy150489 		sum += buffer[i];
565779Sxy150489 
575779Sxy150489 	return (u8) (0 - sum);
585779Sxy150489 }
595779Sxy150489 
605779Sxy150489 /*
615779Sxy150489  * e1000_mng_enable_host_if_generic - Checks host interface is enabled
625779Sxy150489  * @hw: pointer to the HW structure
635779Sxy150489  *
645779Sxy150489  * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
655779Sxy150489  *
668571SChenlu.Chen@Sun.COM  * This function checks whether the HOST IF is enabled for command operation
675779Sxy150489  * and also checks whether the previous command is completed.  It busy waits
685779Sxy150489  * in case of previous command is not completed.
695779Sxy150489  */
705779Sxy150489 s32
e1000_mng_enable_host_if_generic(struct e1000_hw * hw)715779Sxy150489 e1000_mng_enable_host_if_generic(struct e1000_hw *hw)
725779Sxy150489 {
735779Sxy150489 	u32 hicr;
745779Sxy150489 	s32 ret_val = E1000_SUCCESS;
755779Sxy150489 	u8  i;
765779Sxy150489 
775779Sxy150489 	DEBUGFUNC("e1000_mng_enable_host_if_generic");
785779Sxy150489 
795779Sxy150489 	/* Check that the host interface is enabled. */
805779Sxy150489 	hicr = E1000_READ_REG(hw, E1000_HICR);
815779Sxy150489 	if ((hicr & E1000_HICR_EN) == 0) {
825779Sxy150489 		DEBUGOUT("E1000_HOST_EN bit disabled.\n");
835779Sxy150489 		ret_val = -E1000_ERR_HOST_INTERFACE_COMMAND;
845779Sxy150489 		goto out;
855779Sxy150489 	}
865779Sxy150489 	/* check the previous command is completed */
875779Sxy150489 	for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
885779Sxy150489 		hicr = E1000_READ_REG(hw, E1000_HICR);
895779Sxy150489 		if (!(hicr & E1000_HICR_C))
905779Sxy150489 			break;
915779Sxy150489 		msec_delay_irq(1);
925779Sxy150489 	}
935779Sxy150489 
945779Sxy150489 	if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
955779Sxy150489 		DEBUGOUT("Previous command timeout failed .\n");
965779Sxy150489 		ret_val = -E1000_ERR_HOST_INTERFACE_COMMAND;
975779Sxy150489 		goto out;
985779Sxy150489 	}
995779Sxy150489 
1005779Sxy150489 out:
1015779Sxy150489 	return (ret_val);
1025779Sxy150489 }
1035779Sxy150489 
1045779Sxy150489 /*
1058571SChenlu.Chen@Sun.COM  * e1000_check_mng_mode_generic - Generic check management mode
1065779Sxy150489  * @hw: pointer to the HW structure
1075779Sxy150489  *
1085779Sxy150489  * Reads the firmware semaphore register and returns true (>0) if
1095779Sxy150489  * manageability is enabled, else false (0).
1105779Sxy150489  */
1115779Sxy150489 bool
e1000_check_mng_mode_generic(struct e1000_hw * hw)1125779Sxy150489 e1000_check_mng_mode_generic(struct e1000_hw *hw)
1135779Sxy150489 {
1145779Sxy150489 	u32 fwsm;
1155779Sxy150489 
1165779Sxy150489 	DEBUGFUNC("e1000_check_mng_mode_generic");
1175779Sxy150489 
1185779Sxy150489 	fwsm = E1000_READ_REG(hw, E1000_FWSM);
1195779Sxy150489 
1205779Sxy150489 	return ((fwsm & E1000_FWSM_MODE_MASK) ==
1215779Sxy150489 	    (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1225779Sxy150489 }
1235779Sxy150489 
1245779Sxy150489 /*
1255779Sxy150489  * e1000_enable_tx_pkt_filtering_generic - Enable packet filtering on TX
1265779Sxy150489  * @hw: pointer to the HW structure
1275779Sxy150489  *
1285779Sxy150489  * Enables packet filtering on transmit packets if manageability is enabled
1295779Sxy150489  * and host interface is enabled.
1305779Sxy150489  */
1315779Sxy150489 bool
e1000_enable_tx_pkt_filtering_generic(struct e1000_hw * hw)1325779Sxy150489 e1000_enable_tx_pkt_filtering_generic(struct e1000_hw *hw)
1335779Sxy150489 {
1345779Sxy150489 	struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
1355779Sxy150489 	u32 *buffer = (u32 *)&hw->mng_cookie;
1365779Sxy150489 	u32 offset;
1375779Sxy150489 	s32 ret_val, hdr_csum, csum;
1385779Sxy150489 	u8 i, len;
1398571SChenlu.Chen@Sun.COM 	bool tx_filter = true;
1405779Sxy150489 
1415779Sxy150489 	DEBUGFUNC("e1000_enable_tx_pkt_filtering_generic");
1425779Sxy150489 
1435779Sxy150489 	/* No manageability, no filtering */
1448571SChenlu.Chen@Sun.COM 	if (!hw->mac.ops.check_mng_mode(hw)) {
1458571SChenlu.Chen@Sun.COM 		tx_filter = false;
1465779Sxy150489 		goto out;
1475779Sxy150489 	}
1485779Sxy150489 
1495779Sxy150489 	/*
1505779Sxy150489 	 * If we can't read from the host interface for whatever
1515779Sxy150489 	 * reason, disable filtering.
1525779Sxy150489 	 */
1538571SChenlu.Chen@Sun.COM 	ret_val = hw->mac.ops.mng_enable_host_if(hw);
1545779Sxy150489 	if (ret_val != E1000_SUCCESS) {
1558571SChenlu.Chen@Sun.COM 		tx_filter = false;
1565779Sxy150489 		goto out;
1575779Sxy150489 	}
1585779Sxy150489 
1595779Sxy150489 	/* Read in the header.  Length and offset are in dwords. */
1605779Sxy150489 	len    = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
1615779Sxy150489 	offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
1625779Sxy150489 	for (i = 0; i < len; i++) {
1635779Sxy150489 		*(buffer + i) = E1000_READ_REG_ARRAY_DWORD(hw,
1645779Sxy150489 		    E1000_HOST_IF, offset + i);
1655779Sxy150489 	}
1665779Sxy150489 	hdr_csum = hdr->checksum;
1675779Sxy150489 	hdr->checksum = 0;
1685779Sxy150489 	csum = e1000_calculate_checksum((u8 *)hdr,
1695779Sxy150489 	    E1000_MNG_DHCP_COOKIE_LENGTH);
1705779Sxy150489 	/*
1715779Sxy150489 	 * If either the checksums or signature don't match, then
1725779Sxy150489 	 * the cookie area isn't considered valid, in which case we
1735779Sxy150489 	 * take the safe route of assuming Tx filtering is enabled.
1745779Sxy150489 	 */
1755779Sxy150489 	if (hdr_csum != csum)
1765779Sxy150489 		goto out;
1775779Sxy150489 	if (hdr->signature != E1000_IAMT_SIGNATURE)
1785779Sxy150489 		goto out;
1795779Sxy150489 
1805779Sxy150489 	/* Cookie area is valid, make the final check for filtering. */
1815779Sxy150489 	if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING))
1828571SChenlu.Chen@Sun.COM 		tx_filter = false;
1835779Sxy150489 
1845779Sxy150489 out:
1855779Sxy150489 	hw->mac.tx_pkt_filtering = tx_filter;
1865779Sxy150489 	return (tx_filter);
1875779Sxy150489 }
1885779Sxy150489 
1895779Sxy150489 /*
1905779Sxy150489  * e1000_mng_write_dhcp_info_generic - Writes DHCP info to host interface
1915779Sxy150489  * @hw: pointer to the HW structure
1925779Sxy150489  * @buffer: pointer to the host interface
1935779Sxy150489  * @length: size of the buffer
1945779Sxy150489  *
1955779Sxy150489  * Writes the DHCP information to the host interface.
1965779Sxy150489  */
1975779Sxy150489 s32
e1000_mng_write_dhcp_info_generic(struct e1000_hw * hw,u8 * buffer,u16 length)1985779Sxy150489 e1000_mng_write_dhcp_info_generic(struct e1000_hw *hw, u8 *buffer,
1995779Sxy150489     u16 length)
2005779Sxy150489 {
2015779Sxy150489 	struct e1000_host_mng_command_header hdr;
2025779Sxy150489 	s32 ret_val;
2035779Sxy150489 	u32 hicr;
2045779Sxy150489 
2055779Sxy150489 	DEBUGFUNC("e1000_mng_write_dhcp_info_generic");
2065779Sxy150489 
2075779Sxy150489 	hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
2085779Sxy150489 	hdr.command_length = length;
2095779Sxy150489 	hdr.reserved1 = 0;
2105779Sxy150489 	hdr.reserved2 = 0;
2115779Sxy150489 	hdr.checksum = 0;
2125779Sxy150489 
2135779Sxy150489 	/* Enable the host interface */
2148571SChenlu.Chen@Sun.COM 	ret_val = hw->mac.ops.mng_enable_host_if(hw);
2155779Sxy150489 	if (ret_val)
2165779Sxy150489 		goto out;
2175779Sxy150489 
2185779Sxy150489 	/* Populate the host interface with the contents of "buffer". */
2198571SChenlu.Chen@Sun.COM 	ret_val = hw->mac.ops.mng_host_if_write(hw, buffer, length,
2205779Sxy150489 	    sizeof (hdr), &(hdr.checksum));
2215779Sxy150489 	if (ret_val)
2225779Sxy150489 		goto out;
2235779Sxy150489 
2245779Sxy150489 	/* Write the manageability command header */
2258571SChenlu.Chen@Sun.COM 	ret_val = hw->mac.ops.mng_write_cmd_header(hw, &hdr);
2265779Sxy150489 	if (ret_val)
2275779Sxy150489 		goto out;
2285779Sxy150489 
2295779Sxy150489 	/* Tell the ARC a new command is pending. */
2305779Sxy150489 	hicr = E1000_READ_REG(hw, E1000_HICR);
2315779Sxy150489 	E1000_WRITE_REG(hw, E1000_HICR, hicr | E1000_HICR_C);
2325779Sxy150489 
2335779Sxy150489 out:
2345779Sxy150489 	return (ret_val);
2355779Sxy150489 }
2365779Sxy150489 
2375779Sxy150489 /*
2385779Sxy150489  * e1000_mng_write_cmd_header_generic - Writes manageability command header
2395779Sxy150489  * @hw: pointer to the HW structure
2405779Sxy150489  * @hdr: pointer to the host interface command header
2415779Sxy150489  *
2425779Sxy150489  * Writes the command header after does the checksum calculation.
2435779Sxy150489  */
2445779Sxy150489 s32
e1000_mng_write_cmd_header_generic(struct e1000_hw * hw,struct e1000_host_mng_command_header * hdr)2455779Sxy150489 e1000_mng_write_cmd_header_generic(struct e1000_hw *hw,
2465779Sxy150489     struct e1000_host_mng_command_header *hdr)
2475779Sxy150489 {
2485779Sxy150489 	u16 i, length = sizeof (struct e1000_host_mng_command_header);
2495779Sxy150489 
2505779Sxy150489 	DEBUGFUNC("e1000_mng_write_cmd_header_generic");
2515779Sxy150489 
2525779Sxy150489 	/* Write the whole command header structure with new checksum. */
2535779Sxy150489 
2545779Sxy150489 	hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
2555779Sxy150489 
2565779Sxy150489 	length >>= 2;
2575779Sxy150489 	/* Write the relevant command block into the ram area. */
2585779Sxy150489 	for (i = 0; i < length; i++) {
2595779Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF, i,
2605779Sxy150489 		    *((u32 *)(uintptr_t)hdr + i));
2615779Sxy150489 		E1000_WRITE_FLUSH(hw);
2625779Sxy150489 	}
2635779Sxy150489 
2645779Sxy150489 	return (E1000_SUCCESS);
2655779Sxy150489 }
2665779Sxy150489 
2675779Sxy150489 /*
2685779Sxy150489  * e1000_mng_host_if_write_generic - Write to the manageability host interface
2695779Sxy150489  * @hw: pointer to the HW structure
2705779Sxy150489  * @buffer: pointer to the host interface buffer
2715779Sxy150489  * @length: size of the buffer
2725779Sxy150489  * @offset: location in the buffer to write to
2735779Sxy150489  * @sum: sum of the data (not checksum)
2745779Sxy150489  *
2755779Sxy150489  * This function writes the buffer content at the offset given on the host if.
2765779Sxy150489  * It also does alignment considerations to do the writes in most efficient
2775779Sxy150489  * way.  Also fills up the sum of the buffer in *buffer parameter.
2785779Sxy150489  */
2795779Sxy150489 s32
e1000_mng_host_if_write_generic(struct e1000_hw * hw,u8 * buffer,u16 length,u16 offset,u8 * sum)2805779Sxy150489 e1000_mng_host_if_write_generic(struct e1000_hw *hw, u8 *buffer,
2815779Sxy150489     u16 length, u16 offset, u8 *sum)
2825779Sxy150489 {
2835779Sxy150489 	u8 *tmp;
2845779Sxy150489 	u8 *bufptr = buffer;
2855779Sxy150489 	u32 data = 0;
2865779Sxy150489 	s32 ret_val = E1000_SUCCESS;
2875779Sxy150489 	u16 remaining, i, j, prev_bytes;
2885779Sxy150489 
2895779Sxy150489 	DEBUGFUNC("e1000_mng_host_if_write_generic");
2905779Sxy150489 
2915779Sxy150489 	/* sum = only sum of the data and it is not checksum */
2925779Sxy150489 
2935779Sxy150489 	if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
2945779Sxy150489 		ret_val = -E1000_ERR_PARAM;
2955779Sxy150489 		goto out;
2965779Sxy150489 	}
2975779Sxy150489 
2985779Sxy150489 	tmp = (u8 *)&data;
2995779Sxy150489 	prev_bytes = offset & 0x3;
3005779Sxy150489 	offset >>= 2;
3015779Sxy150489 
3025779Sxy150489 	if (prev_bytes) {
3035779Sxy150489 		data = E1000_READ_REG_ARRAY_DWORD(hw, E1000_HOST_IF, offset);
3045779Sxy150489 		for (j = prev_bytes; j < sizeof (u32); j++) {
3055779Sxy150489 			*(tmp + j) = *bufptr++;
3065779Sxy150489 			*sum += *(tmp + j);
3075779Sxy150489 		}
3085779Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF, offset, data);
3095779Sxy150489 		length -= j - prev_bytes;
3105779Sxy150489 		offset++;
3115779Sxy150489 	}
3125779Sxy150489 
3135779Sxy150489 	remaining = length & 0x3;
3145779Sxy150489 	length -= remaining;
3155779Sxy150489 
3165779Sxy150489 	/* Calculate length in DWORDs */
3175779Sxy150489 	length >>= 2;
3185779Sxy150489 
3195779Sxy150489 	/*
3205779Sxy150489 	 * The device driver writes the relevant command block into the
3215779Sxy150489 	 * ram area.
3225779Sxy150489 	 */
3235779Sxy150489 	for (i = 0; i < length; i++) {
3245779Sxy150489 		for (j = 0; j < sizeof (u32); j++) {
3255779Sxy150489 			*(tmp + j) = *bufptr++;
3265779Sxy150489 			*sum += *(tmp + j);
3275779Sxy150489 		}
3285779Sxy150489 
3295779Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF,
3305779Sxy150489 		    offset + i, data);
3315779Sxy150489 	}
3325779Sxy150489 	if (remaining) {
3335779Sxy150489 		for (j = 0; j < sizeof (u32); j++) {
3345779Sxy150489 			if (j < remaining)
3355779Sxy150489 				*(tmp + j) = *bufptr++;
3365779Sxy150489 			else
3375779Sxy150489 				*(tmp + j) = 0;
3385779Sxy150489 
3395779Sxy150489 			*sum += *(tmp + j);
3405779Sxy150489 		}
3415779Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF,
3425779Sxy150489 		    offset + i, data);
3435779Sxy150489 	}
3445779Sxy150489 
3455779Sxy150489 out:
3465779Sxy150489 	return (ret_val);
3475779Sxy150489 }
3485779Sxy150489 
3495779Sxy150489 /*
3505779Sxy150489  * e1000_enable_mng_pass_thru - Enable processing of ARP's
3515779Sxy150489  * @hw: pointer to the HW structure
3525779Sxy150489  *
3535779Sxy150489  * Verifies the hardware needs to allow ARPs to be processed by the host.
3545779Sxy150489  */
3555779Sxy150489 bool
e1000_enable_mng_pass_thru(struct e1000_hw * hw)3565779Sxy150489 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
3575779Sxy150489 {
3585779Sxy150489 	u32 manc;
3595779Sxy150489 	u32 fwsm, factps;
3608571SChenlu.Chen@Sun.COM 	bool ret_val = false;
3615779Sxy150489 
3625779Sxy150489 	DEBUGFUNC("e1000_enable_mng_pass_thru");
3635779Sxy150489 
3645779Sxy150489 	if (!hw->mac.asf_firmware_present)
3655779Sxy150489 		goto out;
3665779Sxy150489 
3675779Sxy150489 	manc = E1000_READ_REG(hw, E1000_MANC);
3685779Sxy150489 
3695779Sxy150489 	if (!(manc & E1000_MANC_RCV_TCO_EN) ||
3705779Sxy150489 	    !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
3715779Sxy150489 		goto out;
3725779Sxy150489 
3735779Sxy150489 	if (hw->mac.arc_subsystem_valid) {
3745779Sxy150489 		fwsm = E1000_READ_REG(hw, E1000_FWSM);
3755779Sxy150489 		factps = E1000_READ_REG(hw, E1000_FACTPS);
3765779Sxy150489 
3775779Sxy150489 		if (!(factps & E1000_FACTPS_MNGCG) &&
3785779Sxy150489 		    ((fwsm & E1000_FWSM_MODE_MASK) ==
3795779Sxy150489 		    (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
3808571SChenlu.Chen@Sun.COM 			ret_val = true;
3815779Sxy150489 			goto out;
3825779Sxy150489 		}
3835779Sxy150489 	} else {
3845779Sxy150489 		if ((manc & E1000_MANC_SMBUS_EN) &&
3855779Sxy150489 		    !(manc & E1000_MANC_ASF_EN)) {
3868571SChenlu.Chen@Sun.COM 			ret_val = true;
3875779Sxy150489 			goto out;
3885779Sxy150489 		}
3895779Sxy150489 	}
3905779Sxy150489 
3915779Sxy150489 out:
3925779Sxy150489 	return (ret_val);
3935779Sxy150489 }
394