xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000_manage.c (revision 11020:e0feef27b61a)
14919Sxy150489 /*
24919Sxy150489  * This file is provided under a CDDLv1 license.  When using or
34919Sxy150489  * redistributing this file, you may do so under this license.
44919Sxy150489  * In redistributing this file this license must be included
54919Sxy150489  * and no other modification of this header file is permitted.
64919Sxy150489  *
74919Sxy150489  * CDDL LICENSE SUMMARY
84919Sxy150489  *
98479SChenlu.Chen@Sun.COM  * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
104919Sxy150489  *
114919Sxy150489  * The contents of this file are subject to the terms of Version
124919Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
134919Sxy150489  *
144919Sxy150489  * You should have received a copy of the License with this software.
154919Sxy150489  * You can obtain a copy of the License at
164919Sxy150489  *	http://www.opensolaris.org/os/licensing.
174919Sxy150489  * See the License for the specific language governing permissions
184919Sxy150489  * and limitations under the License.
194919Sxy150489  */
204919Sxy150489 
214919Sxy150489 /*
228479SChenlu.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
234919Sxy150489  * Use is subject to license terms of the CDDLv1.
244919Sxy150489  */
254919Sxy150489 
264919Sxy150489 /*
27*11020SMin.Xu@Sun.COM  * IntelVersion: 1.27 v3-1-10-1_2009-9-18_Release14-6
284919Sxy150489  */
296735Scc210113 
304919Sxy150489 #include "e1000_api.h"
314919Sxy150489 
324919Sxy150489 static u8 e1000_calculate_checksum(u8 *buffer, u32 length);
334919Sxy150489 
344919Sxy150489 /*
354919Sxy150489  * e1000_calculate_checksum - Calculate checksum for buffer
364919Sxy150489  * @buffer: pointer to EEPROM
374919Sxy150489  * @length: size of EEPROM to calculate a checksum for
384919Sxy150489  *
394919Sxy150489  * Calculates the checksum for some buffer on a specified length.  The
404919Sxy150489  * checksum calculated is returned.
414919Sxy150489  */
424919Sxy150489 static u8
e1000_calculate_checksum(u8 * buffer,u32 length)434919Sxy150489 e1000_calculate_checksum(u8 *buffer, u32 length)
444919Sxy150489 {
454919Sxy150489 	u32 i;
464919Sxy150489 	u8 sum = 0;
474919Sxy150489 
484919Sxy150489 	DEBUGFUNC("e1000_calculate_checksum");
494919Sxy150489 
504919Sxy150489 	if (!buffer)
514919Sxy150489 		return (0);
524919Sxy150489 
534919Sxy150489 	for (i = 0; i < length; i++)
544919Sxy150489 		sum += buffer[i];
554919Sxy150489 
564919Sxy150489 	return (u8)(0 - sum);
574919Sxy150489 }
584919Sxy150489 
594919Sxy150489 /*
604919Sxy150489  * e1000_mng_enable_host_if_generic - Checks host interface is enabled
614919Sxy150489  * @hw: pointer to the HW structure
624919Sxy150489  *
634919Sxy150489  * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
644919Sxy150489  *
656735Scc210113  * This function checks whether the HOST IF is enabled for command operation
664919Sxy150489  * and also checks whether the previous command is completed.  It busy waits
674919Sxy150489  * in case of previous command is not completed.
684919Sxy150489  */
694919Sxy150489 s32
e1000_mng_enable_host_if_generic(struct e1000_hw * hw)704919Sxy150489 e1000_mng_enable_host_if_generic(struct e1000_hw *hw)
714919Sxy150489 {
724919Sxy150489 	u32 hicr;
734919Sxy150489 	s32 ret_val = E1000_SUCCESS;
744919Sxy150489 	u8 i;
754919Sxy150489 
764919Sxy150489 	DEBUGFUNC("e1000_mng_enable_host_if_generic");
774919Sxy150489 
784919Sxy150489 	/* Check that the host interface is enabled. */
794919Sxy150489 	hicr = E1000_READ_REG(hw, E1000_HICR);
804919Sxy150489 	if ((hicr & E1000_HICR_EN) == 0) {
814919Sxy150489 		DEBUGOUT("E1000_HOST_EN bit disabled.\n");
824919Sxy150489 		ret_val = -E1000_ERR_HOST_INTERFACE_COMMAND;
834919Sxy150489 		goto out;
844919Sxy150489 	}
854919Sxy150489 	/* check the previous command is completed */
864919Sxy150489 	for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
874919Sxy150489 		hicr = E1000_READ_REG(hw, E1000_HICR);
884919Sxy150489 		if (!(hicr & E1000_HICR_C))
894919Sxy150489 			break;
904919Sxy150489 		msec_delay_irq(1);
914919Sxy150489 	}
924919Sxy150489 
934919Sxy150489 	if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
944919Sxy150489 		DEBUGOUT("Previous command timeout failed .\n");
954919Sxy150489 		ret_val = -E1000_ERR_HOST_INTERFACE_COMMAND;
964919Sxy150489 		goto out;
974919Sxy150489 	}
984919Sxy150489 out:
994919Sxy150489 	return (ret_val);
1004919Sxy150489 }
1014919Sxy150489 
1024919Sxy150489 /*
1036735Scc210113  * e1000_check_mng_mode_generic - Generic check management mode
1044919Sxy150489  * @hw: pointer to the HW structure
1054919Sxy150489  *
1064919Sxy150489  * Reads the firmware semaphore register and returns true (>0) if
1074919Sxy150489  * manageability is enabled, else false (0).
1084919Sxy150489  */
1096735Scc210113 bool
e1000_check_mng_mode_generic(struct e1000_hw * hw)1104919Sxy150489 e1000_check_mng_mode_generic(struct e1000_hw *hw)
1114919Sxy150489 {
1124919Sxy150489 	u32 fwsm;
1134919Sxy150489 
1144919Sxy150489 	DEBUGFUNC("e1000_check_mng_mode_generic");
1154919Sxy150489 
1164919Sxy150489 	fwsm = E1000_READ_REG(hw, E1000_FWSM);
1174919Sxy150489 
1184919Sxy150489 	return ((fwsm & E1000_FWSM_MODE_MASK) ==
1194919Sxy150489 	    (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1204919Sxy150489 }
1214919Sxy150489 
1224919Sxy150489 /*
1234919Sxy150489  * e1000_enable_tx_pkt_filtering_generic - Enable packet filtering on TX
1244919Sxy150489  * @hw: pointer to the HW structure
1254919Sxy150489  *
1264919Sxy150489  * Enables packet filtering on transmit packets if manageability is enabled
1274919Sxy150489  * and host interface is enabled.
1284919Sxy150489  */
1296735Scc210113 bool
e1000_enable_tx_pkt_filtering_generic(struct e1000_hw * hw)1304919Sxy150489 e1000_enable_tx_pkt_filtering_generic(struct e1000_hw *hw)
1314919Sxy150489 {
1324919Sxy150489 	struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
1334919Sxy150489 	u32 *buffer = (u32 *)&hw->mng_cookie;
1344919Sxy150489 	u32 offset;
1354919Sxy150489 	s32 ret_val, hdr_csum, csum;
1364919Sxy150489 	u8 i, len;
1377607STed.You@Sun.COM 	bool tx_filter = true;
1384919Sxy150489 
1394919Sxy150489 	DEBUGFUNC("e1000_enable_tx_pkt_filtering_generic");
1404919Sxy150489 
1414919Sxy150489 	/* No manageability, no filtering */
1426735Scc210113 	if (!hw->mac.ops.check_mng_mode(hw)) {
1437607STed.You@Sun.COM 		tx_filter = false;
1444919Sxy150489 		goto out;
1454919Sxy150489 	}
1464919Sxy150489 
1474919Sxy150489 	/*
1484919Sxy150489 	 * If we can't read from the host interface for whatever reason,
1494919Sxy150489 	 * disable filtering.
1504919Sxy150489 	 */
1516735Scc210113 	ret_val = hw->mac.ops.mng_enable_host_if(hw);
1524919Sxy150489 	if (ret_val != E1000_SUCCESS) {
1537607STed.You@Sun.COM 		tx_filter = false;
1544919Sxy150489 		goto out;
1554919Sxy150489 	}
1564919Sxy150489 
1574919Sxy150489 	/* Read in the header.  Length and offset are in dwords. */
1584919Sxy150489 	len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
1594919Sxy150489 	offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
1604919Sxy150489 	for (i = 0; i < len; i++) {
1614919Sxy150489 		*(buffer + i) = E1000_READ_REG_ARRAY_DWORD(hw,
1624919Sxy150489 		    E1000_HOST_IF,
1634919Sxy150489 		    offset + i);
1644919Sxy150489 	}
1654919Sxy150489 	hdr_csum = hdr->checksum;
1664919Sxy150489 	hdr->checksum = 0;
1674919Sxy150489 	csum = e1000_calculate_checksum((u8 *)hdr,
1684919Sxy150489 	    E1000_MNG_DHCP_COOKIE_LENGTH);
1694919Sxy150489 	/*
1704919Sxy150489 	 * If either the checksums or signature don't match, then the cookie
1714919Sxy150489 	 * area isn't considered valid, in which case we take the safe route
1724919Sxy150489 	 * of assuming Tx filtering is enabled.
1734919Sxy150489 	 */
1744919Sxy150489 	if (hdr_csum != csum)
1754919Sxy150489 		goto out;
1764919Sxy150489 	if (hdr->signature != E1000_IAMT_SIGNATURE)
1774919Sxy150489 		goto out;
1784919Sxy150489 
1794919Sxy150489 	/* Cookie area is valid, make the final check for filtering. */
1804919Sxy150489 	if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING))
1817607STed.You@Sun.COM 		tx_filter = false;
1824919Sxy150489 
1834919Sxy150489 out:
1844919Sxy150489 	hw->mac.tx_pkt_filtering = tx_filter;
1854919Sxy150489 	return (tx_filter);
1864919Sxy150489 }
1874919Sxy150489 
1884919Sxy150489 /*
1894919Sxy150489  * e1000_mng_write_dhcp_info_generic - Writes DHCP info to host interface
1904919Sxy150489  * @hw: pointer to the HW structure
1914919Sxy150489  * @buffer: pointer to the host interface
1924919Sxy150489  * @length: size of the buffer
1934919Sxy150489  *
1944919Sxy150489  * Writes the DHCP information to the host interface.
1954919Sxy150489  */
1964919Sxy150489 s32
e1000_mng_write_dhcp_info_generic(struct e1000_hw * hw,u8 * buffer,u16 length)1974919Sxy150489 e1000_mng_write_dhcp_info_generic(struct e1000_hw *hw, u8 *buffer,
1984919Sxy150489     u16 length)
1994919Sxy150489 {
2004919Sxy150489 	struct e1000_host_mng_command_header hdr;
2014919Sxy150489 	s32 ret_val;
2024919Sxy150489 	u32 hicr;
2034919Sxy150489 
2044919Sxy150489 	DEBUGFUNC("e1000_mng_write_dhcp_info_generic");
2054919Sxy150489 
2064919Sxy150489 	hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
2074919Sxy150489 	hdr.command_length = length;
2084919Sxy150489 	hdr.reserved1 = 0;
2094919Sxy150489 	hdr.reserved2 = 0;
2104919Sxy150489 	hdr.checksum = 0;
2114919Sxy150489 
2124919Sxy150489 	/* Enable the host interface */
2136735Scc210113 	ret_val = hw->mac.ops.mng_enable_host_if(hw);
2144919Sxy150489 	if (ret_val)
2154919Sxy150489 		goto out;
2164919Sxy150489 
2174919Sxy150489 	/* Populate the host interface with the contents of "buffer". */
2186735Scc210113 	ret_val = hw->mac.ops.mng_host_if_write(hw, buffer, length,
2194919Sxy150489 	    sizeof (hdr), &(hdr.checksum));
2204919Sxy150489 	if (ret_val)
2214919Sxy150489 		goto out;
2224919Sxy150489 
2234919Sxy150489 	/* Write the manageability command header */
2246735Scc210113 	ret_val = hw->mac.ops.mng_write_cmd_header(hw, &hdr);
2254919Sxy150489 	if (ret_val)
2264919Sxy150489 		goto out;
2274919Sxy150489 
2284919Sxy150489 	/* Tell the ARC a new command is pending. */
2294919Sxy150489 	hicr = E1000_READ_REG(hw, E1000_HICR);
2304919Sxy150489 	E1000_WRITE_REG(hw, E1000_HICR, hicr | E1000_HICR_C);
2314919Sxy150489 
2324919Sxy150489 out:
2334919Sxy150489 	return (ret_val);
2344919Sxy150489 }
2354919Sxy150489 
2364919Sxy150489 /*
2374919Sxy150489  * e1000_mng_write_cmd_header_generic - Writes manageability command header
2384919Sxy150489  * @hw: pointer to the HW structure
2394919Sxy150489  * @hdr: pointer to the host interface command header
2404919Sxy150489  *
2414919Sxy150489  * Writes the command header after does the checksum calculation.
2424919Sxy150489  */
2434919Sxy150489 s32
e1000_mng_write_cmd_header_generic(struct e1000_hw * hw,struct e1000_host_mng_command_header * hdr)2444919Sxy150489 e1000_mng_write_cmd_header_generic(struct e1000_hw *hw,
2454919Sxy150489     struct e1000_host_mng_command_header *hdr)
2464919Sxy150489 {
2474919Sxy150489 	u16 i, length = sizeof (struct e1000_host_mng_command_header);
2484919Sxy150489 
2494919Sxy150489 	DEBUGFUNC("e1000_mng_write_cmd_header_generic");
2504919Sxy150489 
2514919Sxy150489 	/* Write the whole command header structure with new checksum. */
2524919Sxy150489 
2534919Sxy150489 	hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
2544919Sxy150489 
2554919Sxy150489 	length >>= 2;
2564919Sxy150489 	/* Write the relevant command block into the ram area. */
2574919Sxy150489 	for (i = 0; i < length; i++) {
2584919Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF, i,
2597426SChenliang.Xu@Sun.COM 		    *((u32 *)(uintptr_t)hdr + i));
2604919Sxy150489 		E1000_WRITE_FLUSH(hw);
2614919Sxy150489 	}
2624919Sxy150489 
2634919Sxy150489 	return (E1000_SUCCESS);
2644919Sxy150489 }
2654919Sxy150489 
2664919Sxy150489 /*
2676735Scc210113  * e1000_mng_host_if_write_generic - Write to the manageability host interface
2684919Sxy150489  * @hw: pointer to the HW structure
2694919Sxy150489  * @buffer: pointer to the host interface buffer
2704919Sxy150489  * @length: size of the buffer
2714919Sxy150489  * @offset: location in the buffer to write to
2724919Sxy150489  * @sum: sum of the data (not checksum)
2734919Sxy150489  *
2744919Sxy150489  * This function writes the buffer content at the offset given on the host if.
2754919Sxy150489  * It also does alignment considerations to do the writes in most efficient
2764919Sxy150489  * way.  Also fills up the sum of the buffer in *buffer parameter.
2774919Sxy150489  */
2784919Sxy150489 s32
e1000_mng_host_if_write_generic(struct e1000_hw * hw,u8 * buffer,u16 length,u16 offset,u8 * sum)2794919Sxy150489 e1000_mng_host_if_write_generic(struct e1000_hw *hw, u8 *buffer,
2804919Sxy150489     u16 length, u16 offset, u8 *sum)
2814919Sxy150489 {
2824919Sxy150489 	u8 *tmp;
2834919Sxy150489 	u8 *bufptr = buffer;
2844919Sxy150489 	u32 data = 0;
2854919Sxy150489 	s32 ret_val = E1000_SUCCESS;
2864919Sxy150489 	u16 remaining, i, j, prev_bytes;
2874919Sxy150489 
2884919Sxy150489 	DEBUGFUNC("e1000_mng_host_if_write_generic");
2894919Sxy150489 
2904919Sxy150489 	/* sum = only sum of the data and it is not checksum */
2914919Sxy150489 
2924919Sxy150489 	if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
2934919Sxy150489 		ret_val = -E1000_ERR_PARAM;
2944919Sxy150489 		goto out;
2954919Sxy150489 	}
2964919Sxy150489 
2974919Sxy150489 	tmp = (u8 *)&data;
2984919Sxy150489 	prev_bytes = offset & 0x3;
2994919Sxy150489 	offset >>= 2;
3004919Sxy150489 
3014919Sxy150489 	if (prev_bytes) {
3024919Sxy150489 		data = E1000_READ_REG_ARRAY_DWORD(hw, E1000_HOST_IF, offset);
3034919Sxy150489 		for (j = prev_bytes; j < sizeof (u32); j++) {
3044919Sxy150489 			*(tmp + j) = *bufptr++;
3054919Sxy150489 			*sum += *(tmp + j);
3064919Sxy150489 		}
3074919Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF, offset, data);
3084919Sxy150489 		length -= j - prev_bytes;
3094919Sxy150489 		offset++;
3104919Sxy150489 	}
3114919Sxy150489 
3124919Sxy150489 	remaining = length & 0x3;
3134919Sxy150489 	length -= remaining;
3144919Sxy150489 
3154919Sxy150489 	/* Calculate length in DWORDs */
3164919Sxy150489 	length >>= 2;
3174919Sxy150489 
3184919Sxy150489 	/*
3194919Sxy150489 	 * The device driver writes the relevant command block into the ram
3204919Sxy150489 	 * area.
3214919Sxy150489 	 */
3224919Sxy150489 	for (i = 0; i < length; i++) {
3234919Sxy150489 		for (j = 0; j < sizeof (u32); j++) {
3244919Sxy150489 			*(tmp + j) = *bufptr++;
3254919Sxy150489 			*sum += *(tmp + j);
3264919Sxy150489 		}
3274919Sxy150489 
3284919Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF,
3294919Sxy150489 		    offset + i, data);
3304919Sxy150489 	}
3314919Sxy150489 	if (remaining) {
3324919Sxy150489 		for (j = 0; j < sizeof (u32); j++) {
3334919Sxy150489 			if (j < remaining)
3344919Sxy150489 				*(tmp + j) = *bufptr++;
3354919Sxy150489 			else
3364919Sxy150489 				*(tmp + j) = 0;
3374919Sxy150489 
3384919Sxy150489 			*sum += *(tmp + j);
3394919Sxy150489 		}
3404919Sxy150489 		E1000_WRITE_REG_ARRAY_DWORD(hw, E1000_HOST_IF,
3414919Sxy150489 		    offset + i, data);
3424919Sxy150489 	}
3434919Sxy150489 out:
3444919Sxy150489 	return (ret_val);
3454919Sxy150489 }
3464919Sxy150489 
3474919Sxy150489 /*
3484919Sxy150489  * e1000_enable_mng_pass_thru - Enable processing of ARP's
3494919Sxy150489  * @hw: pointer to the HW structure
3504919Sxy150489  *
3514919Sxy150489  * Verifies the hardware needs to allow ARPs to be processed by the host.
3524919Sxy150489  */
3536735Scc210113 bool
e1000_enable_mng_pass_thru(struct e1000_hw * hw)3544919Sxy150489 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
3554919Sxy150489 {
3564919Sxy150489 	u32 manc;
3574919Sxy150489 	u32 fwsm, factps;
3587607STed.You@Sun.COM 	bool ret_val = false;
3594919Sxy150489 
3604919Sxy150489 	DEBUGFUNC("e1000_enable_mng_pass_thru");
3614919Sxy150489 
3624919Sxy150489 	if (!hw->mac.asf_firmware_present)
3634919Sxy150489 		goto out;
3644919Sxy150489 
3654919Sxy150489 	manc = E1000_READ_REG(hw, E1000_MANC);
3664919Sxy150489 
3674919Sxy150489 	if (!(manc & E1000_MANC_RCV_TCO_EN) ||
3684919Sxy150489 	    !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
3694919Sxy150489 		goto out;
3704919Sxy150489 
3714919Sxy150489 	if (hw->mac.arc_subsystem_valid) {
3724919Sxy150489 		fwsm = E1000_READ_REG(hw, E1000_FWSM);
3734919Sxy150489 		factps = E1000_READ_REG(hw, E1000_FACTPS);
3744919Sxy150489 
3754919Sxy150489 		if (!(factps & E1000_FACTPS_MNGCG) &&
3764919Sxy150489 		    ((fwsm & E1000_FWSM_MODE_MASK) ==
3774919Sxy150489 		    (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
3787607STed.You@Sun.COM 			ret_val = true;
3794919Sxy150489 			goto out;
3804919Sxy150489 		}
3814919Sxy150489 	} else {
3824919Sxy150489 		if ((manc & E1000_MANC_SMBUS_EN) &&
3834919Sxy150489 		    !(manc & E1000_MANC_ASF_EN)) {
3847607STed.You@Sun.COM 			ret_val = true;
3854919Sxy150489 			goto out;
3864919Sxy150489 		}
3874919Sxy150489 	}
3884919Sxy150489 
3894919Sxy150489 out:
3904919Sxy150489 	return (ret_val);
3914919Sxy150489 }
392