fp@2546: /******************************************************************************* fp@2546: fp@2546: Intel PRO/1000 Linux driver fp@2546: Copyright(c) 1999 - 2012 Intel Corporation. fp@2546: fp@2546: This program is free software; you can redistribute it and/or modify it fp@2546: under the terms and conditions of the GNU General Public License, fp@2546: version 2, as published by the Free Software Foundation. fp@2546: fp@2546: This program is distributed in the hope it will be useful, but WITHOUT fp@2546: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or fp@2546: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for fp@2546: more details. fp@2546: fp@2546: You should have received a copy of the GNU General Public License along with fp@2546: this program; if not, write to the Free Software Foundation, Inc., fp@2546: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. fp@2546: fp@2546: The full GNU General Public License is included in this distribution in fp@2546: the file called "COPYING". fp@2546: fp@2546: Contact Information: fp@2546: Linux NICS fp@2546: e1000-devel Mailing List fp@2546: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 fp@2546: fp@2546: *******************************************************************************/ fp@2546: fp@2546: #include "e1000.h" fp@2546: fp@2546: enum e1000_mng_mode { fp@2546: e1000_mng_mode_none = 0, fp@2546: e1000_mng_mode_asf, fp@2546: e1000_mng_mode_pt, fp@2546: e1000_mng_mode_ipmi, fp@2546: e1000_mng_mode_host_if_only fp@2546: }; fp@2546: fp@2546: #define E1000_FACTPS_MNGCG 0x20000000 fp@2546: fp@2546: /* Intel(R) Active Management Technology signature */ fp@2546: #define E1000_IAMT_SIGNATURE 0x544D4149 fp@2546: fp@2546: /** fp@2546: * e1000_calculate_checksum - Calculate checksum for buffer fp@2546: * @buffer: pointer to EEPROM fp@2546: * @length: size of EEPROM to calculate a checksum for fp@2546: * fp@2546: * Calculates the checksum for some buffer on a specified length. The fp@2546: * checksum calculated is returned. fp@2546: **/ fp@2546: static u8 e1000_calculate_checksum(u8 *buffer, u32 length) fp@2546: { fp@2546: u32 i; fp@2546: u8 sum = 0; fp@2546: fp@2546: if (!buffer) fp@2546: return 0; fp@2546: fp@2546: for (i = 0; i < length; i++) fp@2546: sum += buffer[i]; fp@2546: fp@2546: return (u8)(0 - sum); fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000_mng_enable_host_if - Checks host interface is enabled fp@2546: * @hw: pointer to the HW structure fp@2546: * fp@2546: * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND fp@2546: * fp@2546: * This function checks whether the HOST IF is enabled for command operation fp@2546: * and also checks whether the previous command is completed. It busy waits fp@2546: * in case of previous command is not completed. fp@2546: **/ fp@2546: static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) fp@2546: { fp@2546: u32 hicr; fp@2546: u8 i; fp@2546: fp@2546: if (!hw->mac.arc_subsystem_valid) { fp@2546: e_dbg("ARC subsystem not valid.\n"); fp@2546: return -E1000_ERR_HOST_INTERFACE_COMMAND; fp@2546: } fp@2546: fp@2546: /* Check that the host interface is enabled. */ fp@2546: hicr = er32(HICR); fp@2546: if (!(hicr & E1000_HICR_EN)) { fp@2546: e_dbg("E1000_HOST_EN bit disabled.\n"); fp@2546: return -E1000_ERR_HOST_INTERFACE_COMMAND; fp@2546: } fp@2546: /* check the previous command is completed */ fp@2546: for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { fp@2546: hicr = er32(HICR); fp@2546: if (!(hicr & E1000_HICR_C)) fp@2546: break; fp@2546: mdelay(1); fp@2546: } fp@2546: fp@2546: if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { fp@2546: e_dbg("Previous command timeout failed .\n"); fp@2546: return -E1000_ERR_HOST_INTERFACE_COMMAND; fp@2546: } fp@2546: fp@2546: return 0; fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000e_check_mng_mode_generic - Generic check management mode fp@2546: * @hw: pointer to the HW structure fp@2546: * fp@2546: * Reads the firmware semaphore register and returns true (>0) if fp@2546: * manageability is enabled, else false (0). fp@2546: **/ fp@2546: bool e1000e_check_mng_mode_generic(struct e1000_hw *hw) fp@2546: { fp@2546: u32 fwsm = er32(FWSM); fp@2546: fp@2546: return (fwsm & E1000_FWSM_MODE_MASK) == fp@2546: (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT); fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx fp@2546: * @hw: pointer to the HW structure fp@2546: * fp@2546: * Enables packet filtering on transmit packets if manageability is enabled fp@2546: * and host interface is enabled. fp@2546: **/ fp@2546: bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw) fp@2546: { fp@2546: struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie; fp@2546: u32 *buffer = (u32 *)&hw->mng_cookie; fp@2546: u32 offset; fp@2546: s32 ret_val, hdr_csum, csum; fp@2546: u8 i, len; fp@2546: fp@2546: hw->mac.tx_pkt_filtering = true; fp@2546: fp@2546: /* No manageability, no filtering */ fp@2546: if (!hw->mac.ops.check_mng_mode(hw)) { fp@2546: hw->mac.tx_pkt_filtering = false; fp@2546: return hw->mac.tx_pkt_filtering; fp@2546: } fp@2546: fp@2546: /* fp@2546: * If we can't read from the host interface for whatever fp@2546: * reason, disable filtering. fp@2546: */ fp@2546: ret_val = e1000_mng_enable_host_if(hw); fp@2546: if (ret_val) { fp@2546: hw->mac.tx_pkt_filtering = false; fp@2546: return hw->mac.tx_pkt_filtering; fp@2546: } fp@2546: fp@2546: /* Read in the header. Length and offset are in dwords. */ fp@2546: len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2; fp@2546: offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2; fp@2546: for (i = 0; i < len; i++) fp@2546: *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, fp@2546: offset + i); fp@2546: hdr_csum = hdr->checksum; fp@2546: hdr->checksum = 0; fp@2546: csum = e1000_calculate_checksum((u8 *)hdr, fp@2546: E1000_MNG_DHCP_COOKIE_LENGTH); fp@2546: /* fp@2546: * If either the checksums or signature don't match, then fp@2546: * the cookie area isn't considered valid, in which case we fp@2546: * take the safe route of assuming Tx filtering is enabled. fp@2546: */ fp@2546: if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) { fp@2546: hw->mac.tx_pkt_filtering = true; fp@2546: return hw->mac.tx_pkt_filtering; fp@2546: } fp@2546: fp@2546: /* Cookie area is valid, make the final check for filtering. */ fp@2546: if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) fp@2546: hw->mac.tx_pkt_filtering = false; fp@2546: fp@2546: return hw->mac.tx_pkt_filtering; fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000_mng_write_cmd_header - Writes manageability command header fp@2546: * @hw: pointer to the HW structure fp@2546: * @hdr: pointer to the host interface command header fp@2546: * fp@2546: * Writes the command header after does the checksum calculation. fp@2546: **/ fp@2546: static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, fp@2546: struct e1000_host_mng_command_header *hdr) fp@2546: { fp@2546: u16 i, length = sizeof(struct e1000_host_mng_command_header); fp@2546: fp@2546: /* Write the whole command header structure with new checksum. */ fp@2546: fp@2546: hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length); fp@2546: fp@2546: length >>= 2; fp@2546: /* Write the relevant command block into the ram area. */ fp@2546: for (i = 0; i < length; i++) { fp@2546: E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, *((u32 *)hdr + i)); fp@2546: e1e_flush(); fp@2546: } fp@2546: fp@2546: return 0; fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000_mng_host_if_write - Write to the manageability host interface fp@2546: * @hw: pointer to the HW structure fp@2546: * @buffer: pointer to the host interface buffer fp@2546: * @length: size of the buffer fp@2546: * @offset: location in the buffer to write to fp@2546: * @sum: sum of the data (not checksum) fp@2546: * fp@2546: * This function writes the buffer content at the offset given on the host if. fp@2546: * It also does alignment considerations to do the writes in most efficient fp@2546: * way. Also fills up the sum of the buffer in *buffer parameter. fp@2546: **/ fp@2546: static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, fp@2546: u16 length, u16 offset, u8 *sum) fp@2546: { fp@2546: u8 *tmp; fp@2546: u8 *bufptr = buffer; fp@2546: u32 data = 0; fp@2546: u16 remaining, i, j, prev_bytes; fp@2546: fp@2546: /* sum = only sum of the data and it is not checksum */ fp@2546: fp@2546: if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) fp@2546: return -E1000_ERR_PARAM; fp@2546: fp@2546: tmp = (u8 *)&data; fp@2546: prev_bytes = offset & 0x3; fp@2546: offset >>= 2; fp@2546: fp@2546: if (prev_bytes) { fp@2546: data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset); fp@2546: for (j = prev_bytes; j < sizeof(u32); j++) { fp@2546: *(tmp + j) = *bufptr++; fp@2546: *sum += *(tmp + j); fp@2546: } fp@2546: E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data); fp@2546: length -= j - prev_bytes; fp@2546: offset++; fp@2546: } fp@2546: fp@2546: remaining = length & 0x3; fp@2546: length -= remaining; fp@2546: fp@2546: /* Calculate length in DWORDs */ fp@2546: length >>= 2; fp@2546: fp@2546: /* fp@2546: * The device driver writes the relevant command block into the fp@2546: * ram area. fp@2546: */ fp@2546: for (i = 0; i < length; i++) { fp@2546: for (j = 0; j < sizeof(u32); j++) { fp@2546: *(tmp + j) = *bufptr++; fp@2546: *sum += *(tmp + j); fp@2546: } fp@2546: fp@2546: E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); fp@2546: } fp@2546: if (remaining) { fp@2546: for (j = 0; j < sizeof(u32); j++) { fp@2546: if (j < remaining) fp@2546: *(tmp + j) = *bufptr++; fp@2546: else fp@2546: *(tmp + j) = 0; fp@2546: fp@2546: *sum += *(tmp + j); fp@2546: } fp@2546: E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); fp@2546: } fp@2546: fp@2546: return 0; fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface fp@2546: * @hw: pointer to the HW structure fp@2546: * @buffer: pointer to the host interface fp@2546: * @length: size of the buffer fp@2546: * fp@2546: * Writes the DHCP information to the host interface. fp@2546: **/ fp@2546: s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) fp@2546: { fp@2546: struct e1000_host_mng_command_header hdr; fp@2546: s32 ret_val; fp@2546: u32 hicr; fp@2546: fp@2546: hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; fp@2546: hdr.command_length = length; fp@2546: hdr.reserved1 = 0; fp@2546: hdr.reserved2 = 0; fp@2546: hdr.checksum = 0; fp@2546: fp@2546: /* Enable the host interface */ fp@2546: ret_val = e1000_mng_enable_host_if(hw); fp@2546: if (ret_val) fp@2546: return ret_val; fp@2546: fp@2546: /* Populate the host interface with the contents of "buffer". */ fp@2546: ret_val = e1000_mng_host_if_write(hw, buffer, length, fp@2546: sizeof(hdr), &(hdr.checksum)); fp@2546: if (ret_val) fp@2546: return ret_val; fp@2546: fp@2546: /* Write the manageability command header */ fp@2546: ret_val = e1000_mng_write_cmd_header(hw, &hdr); fp@2546: if (ret_val) fp@2546: return ret_val; fp@2546: fp@2546: /* Tell the ARC a new command is pending. */ fp@2546: hicr = er32(HICR); fp@2546: ew32(HICR, hicr | E1000_HICR_C); fp@2546: fp@2546: return 0; fp@2546: } fp@2546: fp@2546: /** fp@2546: * e1000e_enable_mng_pass_thru - Check if management passthrough is needed fp@2546: * @hw: pointer to the HW structure fp@2546: * fp@2546: * Verifies the hardware needs to leave interface enabled so that frames can fp@2546: * be directed to and from the management interface. fp@2546: **/ fp@2546: bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw) fp@2546: { fp@2546: u32 manc; fp@2546: u32 fwsm, factps; fp@2546: fp@2546: manc = er32(MANC); fp@2546: fp@2546: if (!(manc & E1000_MANC_RCV_TCO_EN)) fp@2546: return false; fp@2546: fp@2546: if (hw->mac.has_fwsm) { fp@2546: fwsm = er32(FWSM); fp@2546: factps = er32(FACTPS); fp@2546: fp@2546: if (!(factps & E1000_FACTPS_MNGCG) && fp@2546: ((fwsm & E1000_FWSM_MODE_MASK) == fp@2546: (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) fp@2546: return true; fp@2546: } else if ((hw->mac.type == e1000_82574) || fp@2546: (hw->mac.type == e1000_82583)) { fp@2546: u16 data; fp@2546: fp@2546: factps = er32(FACTPS); fp@2546: e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data); fp@2546: fp@2546: if (!(factps & E1000_FACTPS_MNGCG) && fp@2546: ((data & E1000_NVM_INIT_CTRL2_MNGM) == fp@2546: (e1000_mng_mode_pt << 13))) fp@2546: return true; fp@2546: } else if ((manc & E1000_MANC_SMBUS_EN) && fp@2546: !(manc & E1000_MANC_ASF_EN)) { fp@2546: return true; fp@2546: } fp@2546: fp@2546: return false; fp@2546: }