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