/* * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet * driver for Linux. * * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <linux/ethtool.h> #include <linux/pci.h> #include "t4vf_common.h" #include "t4vf_defs.h" #include "../cxgb4/t4_regs.h" #include "../cxgb4/t4_values.h" #include "../cxgb4/t4fw_api.h" /* * Wait for the device to become ready (signified by our "who am I" register * returning a value other than all 1's). Return an error if it doesn't * become ready ... */ int t4vf_wait_dev_ready(struct adapter *adapter) { … } /* * Get the reply to a mailbox command and store it in @rpl in big-endian order * (since the firmware data structures are specified in a big-endian layout). */ static void get_mbox_rpl(struct adapter *adapter, __be64 *rpl, int size, u32 mbox_data) { … } /** * t4vf_record_mbox - record a Firmware Mailbox Command/Reply in the log * @adapter: the adapter * @cmd: the Firmware Mailbox Command or Reply * @size: command length in bytes * @access: the time (ms) needed to access the Firmware Mailbox * @execute: the time (ms) the command spent being executed */ static void t4vf_record_mbox(struct adapter *adapter, const __be64 *cmd, int size, int access, int execute) { … } /** * t4vf_wr_mbox_core - send a command to FW through the mailbox * @adapter: the adapter * @cmd: the command to write * @size: command length in bytes * @rpl: where to optionally store the reply * @sleep_ok: if true we may sleep while awaiting command completion * * Sends the given command to FW through the mailbox and waits for the * FW to execute the command. If @rpl is not %NULL it is used to store * the FW's reply to the command. The command and its optional reply * are of the same length. FW can take up to 500 ms to respond. * @sleep_ok determines whether we may sleep while awaiting the response. * If sleeping is allowed we use progressive backoff otherwise we spin. * * The return value is 0 on success or a negative errno on failure. A * failure can happen either because we are not able to execute the * command or FW executes it but signals an error. In the latter case * the return value is the error code indicated by FW (negated). */ int t4vf_wr_mbox_core(struct adapter *adapter, const void *cmd, int size, void *rpl, bool sleep_ok) { … } /* In the Physical Function Driver Common Code, the ADVERT_MASK is used to * mask out bits in the Advertised Port Capabilities which are managed via * separate controls, like Pause Frames and Forward Error Correction. In the * Virtual Function Common Code, since we never perform L1 Configuration on * the Link, the only things we really need to filter out are things which * we decode and report separately like Speed. */ #define ADVERT_MASK … /** * fwcaps16_to_caps32 - convert 16-bit Port Capabilities to 32-bits * @caps16: a 16-bit Port Capabilities value * * Returns the equivalent 32-bit Port Capabilities value. */ static fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16) { … } /* Translate Firmware Pause specification to Common Code */ static inline enum cc_pause fwcap_to_cc_pause(fw_port_cap32_t fw_pause) { … } /* Translate Firmware Forward Error Correction specification to Common Code */ static inline enum cc_fec fwcap_to_cc_fec(fw_port_cap32_t fw_fec) { … } /* Return the highest speed set in the port capabilities, in Mb/s. */ static unsigned int fwcap_to_speed(fw_port_cap32_t caps) { … } /** * fwcap_to_fwspeed - return highest speed in Port Capabilities * @acaps: advertised Port Capabilities * * Get the highest speed for the port from the advertised Port * Capabilities. It will be either the highest speed from the list of * speeds or whatever user has set using ethtool. */ static fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps) { … } /* * init_link_config - initialize a link's SW state * @lc: structure holding the link state * @pcaps: link Port Capabilities * @acaps: link current Advertised Port Capabilities * * Initializes the SW state maintained for each link, including the link's * capabilities and default speed/flow-control/autonegotiation settings. */ static void init_link_config(struct link_config *lc, fw_port_cap32_t pcaps, fw_port_cap32_t acaps) { … } /** * t4vf_port_init - initialize port hardware/software state * @adapter: the adapter * @pidx: the adapter port index */ int t4vf_port_init(struct adapter *adapter, int pidx) { … } /** * t4vf_fw_reset - issue a reset to FW * @adapter: the adapter * * Issues a reset command to FW. For a Physical Function this would * result in the Firmware resetting all of its state. For a Virtual * Function this just resets the state associated with the VF. */ int t4vf_fw_reset(struct adapter *adapter) { … } /** * t4vf_query_params - query FW or device parameters * @adapter: the adapter * @nparams: the number of parameters * @params: the parameter names * @vals: the parameter values * * Reads the values of firmware or device parameters. Up to 7 parameters * can be queried at once. */ static int t4vf_query_params(struct adapter *adapter, unsigned int nparams, const u32 *params, u32 *vals) { … } /** * t4vf_set_params - sets FW or device parameters * @adapter: the adapter * @nparams: the number of parameters * @params: the parameter names * @vals: the parameter values * * Sets the values of firmware or device parameters. Up to 7 parameters * can be specified at once. */ int t4vf_set_params(struct adapter *adapter, unsigned int nparams, const u32 *params, const u32 *vals) { … } /** * t4vf_fl_pkt_align - return the fl packet alignment * @adapter: the adapter * * T4 has a single field to specify the packing and padding boundary. * T5 onwards has separate fields for this and hence the alignment for * next packet offset is maximum of these two. And T6 changes the * Ingress Padding Boundary Shift, so it's all a mess and it's best * if we put this in low-level Common Code ... * */ int t4vf_fl_pkt_align(struct adapter *adapter) { … } /** * t4vf_bar2_sge_qregs - return BAR2 SGE Queue register information * @adapter: the adapter * @qid: the Queue ID * @qtype: the Ingress or Egress type for @qid * @pbar2_qoffset: BAR2 Queue Offset * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues * * Returns the BAR2 SGE Queue Registers information associated with the * indicated Absolute Queue ID. These are passed back in return value * pointers. @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue * and T4_BAR2_QTYPE_INGRESS for Ingress Queues. * * This may return an error which indicates that BAR2 SGE Queue * registers aren't available. If an error is not returned, then the * following values are returned: * * *@pbar2_qoffset: the BAR2 Offset of the @qid Registers * *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid * * If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which * require the "Inferred Queue ID" ability may be used. E.g. the * Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0, * then these "Inferred Queue ID" register may not be used. */ int t4vf_bar2_sge_qregs(struct adapter *adapter, unsigned int qid, enum t4_bar2_qtype qtype, u64 *pbar2_qoffset, unsigned int *pbar2_qid) { … } unsigned int t4vf_get_pf_from_vf(struct adapter *adapter) { … } /** * t4vf_get_sge_params - retrieve adapter Scatter gather Engine parameters * @adapter: the adapter * * Retrieves various core SGE parameters in the form of hardware SGE * register values. The caller is responsible for decoding these as * needed. The SGE parameters are stored in @adapter->params.sge. */ int t4vf_get_sge_params(struct adapter *adapter) { … } /** * t4vf_get_vpd_params - retrieve device VPD paremeters * @adapter: the adapter * * Retrives various device Vital Product Data parameters. The parameters * are stored in @adapter->params.vpd. */ int t4vf_get_vpd_params(struct adapter *adapter) { … } /** * t4vf_get_dev_params - retrieve device paremeters * @adapter: the adapter * * Retrives various device parameters. The parameters are stored in * @adapter->params.dev. */ int t4vf_get_dev_params(struct adapter *adapter) { … } /** * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration * @adapter: the adapter * * Retrieves global RSS mode and parameters with which we have to live * and stores them in the @adapter's RSS parameters. */ int t4vf_get_rss_glb_config(struct adapter *adapter) { … } /** * t4vf_get_vfres - retrieve VF resource limits * @adapter: the adapter * * Retrieves configured resource limits and capabilities for a virtual * function. The results are stored in @adapter->vfres. */ int t4vf_get_vfres(struct adapter *adapter) { … } /** * t4vf_read_rss_vi_config - read a VI's RSS configuration * @adapter: the adapter * @viid: Virtual Interface ID * @config: pointer to host-native VI RSS Configuration buffer * * Reads the Virtual Interface's RSS configuration information and * translates it into CPU-native format. */ int t4vf_read_rss_vi_config(struct adapter *adapter, unsigned int viid, union rss_vi_config *config) { … } /** * t4vf_write_rss_vi_config - write a VI's RSS configuration * @adapter: the adapter * @viid: Virtual Interface ID * @config: pointer to host-native VI RSS Configuration buffer * * Write the Virtual Interface's RSS configuration information * (translating it into firmware-native format before writing). */ int t4vf_write_rss_vi_config(struct adapter *adapter, unsigned int viid, union rss_vi_config *config) { … } /** * t4vf_config_rss_range - configure a portion of the RSS mapping table * @adapter: the adapter * @viid: Virtual Interface of RSS Table Slice * @start: starting entry in the table to write * @n: how many table entries to write * @rspq: values for the "Response Queue" (Ingress Queue) lookup table * @nrspq: number of values in @rspq * * Programs the selected part of the VI's RSS mapping table with the * provided values. If @nrspq < @n the supplied values are used repeatedly * until the full table range is populated. * * The caller must ensure the values in @rspq are in the range 0..1023. */ int t4vf_config_rss_range(struct adapter *adapter, unsigned int viid, int start, int n, const u16 *rspq, int nrspq) { … } /** * t4vf_alloc_vi - allocate a virtual interface on a port * @adapter: the adapter * @port_id: physical port associated with the VI * * Allocate a new Virtual Interface and bind it to the indicated * physical port. Return the new Virtual Interface Identifier on * success, or a [negative] error number on failure. */ int t4vf_alloc_vi(struct adapter *adapter, int port_id) { … } /** * t4vf_free_vi -- free a virtual interface * @adapter: the adapter * @viid: the virtual interface identifier * * Free a previously allocated Virtual Interface. Return an error on * failure. */ int t4vf_free_vi(struct adapter *adapter, int viid) { … } /** * t4vf_enable_vi - enable/disable a virtual interface * @adapter: the adapter * @viid: the Virtual Interface ID * @rx_en: 1=enable Rx, 0=disable Rx * @tx_en: 1=enable Tx, 0=disable Tx * * Enables/disables a virtual interface. */ int t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en, bool tx_en) { … } /** * t4vf_enable_pi - enable/disable a Port's virtual interface * @adapter: the adapter * @pi: the Port Information structure * @rx_en: 1=enable Rx, 0=disable Rx * @tx_en: 1=enable Tx, 0=disable Tx * * Enables/disables a Port's virtual interface. If the Virtual * Interface enable/disable operation is successful, we notify the * OS-specific code of a potential Link Status change via the OS Contract * API t4vf_os_link_changed(). */ int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en, bool tx_en) { … } /** * t4vf_identify_port - identify a VI's port by blinking its LED * @adapter: the adapter * @viid: the Virtual Interface ID * @nblinks: how many times to blink LED at 2.5 Hz * * Identifies a VI's port by blinking its LED. */ int t4vf_identify_port(struct adapter *adapter, unsigned int viid, unsigned int nblinks) { … } /** * t4vf_set_rxmode - set Rx properties of a virtual interface * @adapter: the adapter * @viid: the VI id * @mtu: the new MTU or -1 for no change * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change * @vlanex: 1 to enable hardware VLAN Tag extraction, 0 to disable it, * -1 no change * @sleep_ok: call is allowed to sleep * * Sets Rx properties of a virtual interface. */ int t4vf_set_rxmode(struct adapter *adapter, unsigned int viid, int mtu, int promisc, int all_multi, int bcast, int vlanex, bool sleep_ok) { … } /** * t4vf_alloc_mac_filt - allocates exact-match filters for MAC addresses * @adapter: the adapter * @viid: the Virtual Interface Identifier * @free: if true any existing filters for this VI id are first removed * @naddr: the number of MAC addresses to allocate filters for (up to 7) * @addr: the MAC address(es) * @idx: where to store the index of each allocated filter * @hash: pointer to hash address filter bitmap * @sleep_ok: call is allowed to sleep * * Allocates an exact-match filter for each of the supplied addresses and * sets it to the corresponding address. If @idx is not %NULL it should * have at least @naddr entries, each of which will be set to the index of * the filter allocated for the corresponding MAC address. If a filter * could not be allocated for an address its index is set to 0xffff. * If @hash is not %NULL addresses that fail to allocate an exact filter * are hashed and update the hash filter bitmap pointed at by @hash. * * Returns a negative error number or the number of filters allocated. */ int t4vf_alloc_mac_filt(struct adapter *adapter, unsigned int viid, bool free, unsigned int naddr, const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok) { … } /** * t4vf_free_mac_filt - frees exact-match filters of given MAC addresses * @adapter: the adapter * @viid: the VI id * @naddr: the number of MAC addresses to allocate filters for (up to 7) * @addr: the MAC address(es) * @sleep_ok: call is allowed to sleep * * Frees the exact-match filter for each of the supplied addresses * * Returns a negative error number or the number of filters freed. */ int t4vf_free_mac_filt(struct adapter *adapter, unsigned int viid, unsigned int naddr, const u8 **addr, bool sleep_ok) { … } /** * t4vf_change_mac - modifies the exact-match filter for a MAC address * @adapter: the adapter * @viid: the Virtual Interface ID * @idx: index of existing filter for old value of MAC address, or -1 * @addr: the new MAC address value * @persist: if idx < 0, the new MAC allocation should be persistent * * Modifies an exact-match filter and sets it to the new MAC address. * Note that in general it is not possible to modify the value of a given * filter so the generic way to modify an address filter is to free the * one being used by the old address value and allocate a new filter for * the new address value. @idx can be -1 if the address is a new * addition. * * Returns a negative error number or the index of the filter with the new * MAC value. */ int t4vf_change_mac(struct adapter *adapter, unsigned int viid, int idx, const u8 *addr, bool persist) { … } /** * t4vf_set_addr_hash - program the MAC inexact-match hash filter * @adapter: the adapter * @viid: the Virtual Interface Identifier * @ucast: whether the hash filter should also match unicast addresses * @vec: the value to be written to the hash filter * @sleep_ok: call is allowed to sleep * * Sets the 64-bit inexact-match hash filter for a virtual interface. */ int t4vf_set_addr_hash(struct adapter *adapter, unsigned int viid, bool ucast, u64 vec, bool sleep_ok) { … } /** * t4vf_get_port_stats - collect "port" statistics * @adapter: the adapter * @pidx: the port index * @s: the stats structure to fill * * Collect statistics for the "port"'s Virtual Interface. */ int t4vf_get_port_stats(struct adapter *adapter, int pidx, struct t4vf_port_stats *s) { … } /** * t4vf_iq_free - free an ingress queue and its free lists * @adapter: the adapter * @iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.) * @iqid: ingress queue ID * @fl0id: FL0 queue ID or 0xffff if no attached FL0 * @fl1id: FL1 queue ID or 0xffff if no attached FL1 * * Frees an ingress queue and its associated free lists, if any. */ int t4vf_iq_free(struct adapter *adapter, unsigned int iqtype, unsigned int iqid, unsigned int fl0id, unsigned int fl1id) { … } /** * t4vf_eth_eq_free - free an Ethernet egress queue * @adapter: the adapter * @eqid: egress queue ID * * Frees an Ethernet egress queue. */ int t4vf_eth_eq_free(struct adapter *adapter, unsigned int eqid) { … } /** * t4vf_link_down_rc_str - return a string for a Link Down Reason Code * @link_down_rc: Link Down Reason Code * * Returns a string representation of the Link Down Reason Code. */ static const char *t4vf_link_down_rc_str(unsigned char link_down_rc) { … } /** * t4vf_handle_get_port_info - process a FW reply message * @pi: the port info * @cmd: start of the FW message * * Processes a GET_PORT_INFO FW reply message. */ static void t4vf_handle_get_port_info(struct port_info *pi, const struct fw_port_cmd *cmd) { … } /** * t4vf_update_port_info - retrieve and update port information if changed * @pi: the port_info * * We issue a Get Port Information Command to the Firmware and, if * successful, we check to see if anything is different from what we * last recorded and update things accordingly. */ int t4vf_update_port_info(struct port_info *pi) { … } /** * t4vf_handle_fw_rpl - process a firmware reply message * @adapter: the adapter * @rpl: start of the firmware message * * Processes a firmware message, such as link state change messages. */ int t4vf_handle_fw_rpl(struct adapter *adapter, const __be64 *rpl) { … } int t4vf_prep_adapter(struct adapter *adapter) { … } /** * t4vf_get_vf_mac_acl - Get the MAC address to be set to * the VI of this VF. * @adapter: The adapter * @port: The port associated with vf * @naddr: the number of ACL MAC addresses returned in addr * @addr: Placeholder for MAC addresses * * Find the MAC address to be set to the VF's VI. The requested MAC address * is from the host OS via callback in the PF driver. */ int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int port, unsigned int *naddr, u8 *addr) { … } /** * t4vf_get_vf_vlan_acl - Get the VLAN ID to be set to * the VI of this VF. * @adapter: The adapter * * Find the VLAN ID to be set to the VF's VI. The requested VLAN ID * is from the host OS via callback in the PF driver. */ int t4vf_get_vf_vlan_acl(struct adapter *adapter) { … }