1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Contact Information:
19 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
20 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 ******************************************************************************/
24 #include "i40e_type.h"
25 #include "i40e_adminq.h"
26 #include "i40e_prototype.h"
27 #include "i40e_virtchnl.h"
30 * i40e_set_mac_type - Sets MAC type
31 * @hw: pointer to the HW structure
33 * This function sets the mac type of the adapter based on the
34 * vendor ID and device ID stored in the hw structure.
36 i40e_status i40e_set_mac_type(struct i40e_hw *hw)
38 i40e_status status = 0;
40 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
41 switch (hw->device_id) {
42 case I40E_DEV_ID_SFP_XL710:
43 case I40E_DEV_ID_SFP_X710:
44 case I40E_DEV_ID_QEMU:
45 case I40E_DEV_ID_KX_A:
46 case I40E_DEV_ID_KX_B:
47 case I40E_DEV_ID_KX_C:
48 case I40E_DEV_ID_KX_D:
49 case I40E_DEV_ID_QSFP_A:
50 case I40E_DEV_ID_QSFP_B:
51 case I40E_DEV_ID_QSFP_C:
52 hw->mac.type = I40E_MAC_XL710;
55 case I40E_DEV_ID_VF_HV:
56 hw->mac.type = I40E_MAC_VF;
59 hw->mac.type = I40E_MAC_GENERIC;
63 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
66 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
67 hw->mac.type, status);
73 * @hw: debug mask related to admin queue
75 * @desc: pointer to admin queue descriptor
76 * @buffer: pointer to command buffer
78 * Dumps debug log about adminq command with descriptor contents.
80 void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
83 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
84 u8 *aq_buffer = (u8 *)buffer;
88 if ((!(mask & hw->debug_mask)) || (desc == NULL))
92 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
93 aq_desc->opcode, aq_desc->flags, aq_desc->datalen,
95 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
96 aq_desc->cookie_high, aq_desc->cookie_low);
97 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
98 aq_desc->params.internal.param0,
99 aq_desc->params.internal.param1);
100 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
101 aq_desc->params.external.addr_high,
102 aq_desc->params.external.addr_low);
104 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
105 memset(data, 0, sizeof(data));
106 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
107 for (i = 0; i < le16_to_cpu(aq_desc->datalen); i++) {
108 data[((i % 16) / 4)] |=
109 ((u32)aq_buffer[i]) << (8 * (i % 4));
110 if ((i % 16) == 15) {
112 "\t0x%04X %08X %08X %08X %08X\n",
113 i - 15, data[0], data[1], data[2],
115 memset(data, 0, sizeof(data));
119 i40e_debug(hw, mask, "\t0x%04X %08X %08X %08X %08X\n",
120 i - (i % 16), data[0], data[1], data[2],
126 * i40evf_check_asq_alive
127 * @hw: pointer to the hw struct
129 * Returns true if Queue is enabled else false.
131 bool i40evf_check_asq_alive(struct i40e_hw *hw)
133 return !!(rd32(hw, hw->aq.asq.len) & I40E_PF_ATQLEN_ATQENABLE_MASK);
137 * i40evf_aq_queue_shutdown
138 * @hw: pointer to the hw struct
139 * @unloading: is the driver unloading itself
141 * Tell the Firmware that we're shutting down the AdminQ and whether
142 * or not the driver is unloading as well.
144 i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
147 struct i40e_aq_desc desc;
148 struct i40e_aqc_queue_shutdown *cmd =
149 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
152 i40evf_fill_default_direct_cmd_desc(&desc,
153 i40e_aqc_opc_queue_shutdown);
156 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
157 status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
164 * i40e_aq_send_msg_to_pf
165 * @hw: pointer to the hardware structure
166 * @v_opcode: opcodes for VF-PF communication
167 * @v_retval: return error code
168 * @msg: pointer to the msg buffer
169 * @msglen: msg length
170 * @cmd_details: pointer to command details
172 * Send message to PF driver using admin queue. By default, this message
173 * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
174 * completion before returning.
176 i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
177 enum i40e_virtchnl_ops v_opcode,
178 i40e_status v_retval,
180 struct i40e_asq_cmd_details *cmd_details)
182 struct i40e_aq_desc desc;
185 i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
186 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
187 desc.cookie_high = cpu_to_le32(v_opcode);
188 desc.cookie_low = cpu_to_le32(v_retval);
190 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
192 if (msglen > I40E_AQ_LARGE_BUF)
193 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
194 desc.datalen = cpu_to_le16(msglen);
197 struct i40e_asq_cmd_details details;
198 memset(&details, 0, sizeof(details));
199 details.async = true;
200 cmd_details = &details;
202 status = i40evf_asq_send_command(hw, (struct i40e_aq_desc *)&desc, msg,
203 msglen, cmd_details);
208 * i40e_vf_parse_hw_config
209 * @hw: pointer to the hardware structure
210 * @msg: pointer to the virtual channel VF resource structure
212 * Given a VF resource message from the PF, populate the hw struct
213 * with appropriate information.
215 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
216 struct i40e_virtchnl_vf_resource *msg)
218 struct i40e_virtchnl_vsi_resource *vsi_res;
221 vsi_res = &msg->vsi_res[0];
223 hw->dev_caps.num_vsis = msg->num_vsis;
224 hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
225 hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
226 hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
227 hw->dev_caps.dcb = msg->vf_offload_flags &
228 I40E_VIRTCHNL_VF_OFFLOAD_L2;
229 hw->dev_caps.fcoe = (msg->vf_offload_flags &
230 I40E_VIRTCHNL_VF_OFFLOAD_FCOE) ? 1 : 0;
231 for (i = 0; i < msg->num_vsis; i++) {
232 if (vsi_res->vsi_type == I40E_VSI_SRIOV) {
233 memcpy(hw->mac.perm_addr, vsi_res->default_mac_addr,
235 memcpy(hw->mac.addr, vsi_res->default_mac_addr,
244 * @hw: pointer to the hardware structure
246 * Send a VF_RESET message to the PF. Does not wait for response from PF
247 * as none will be forthcoming. Immediately after calling this function,
248 * the admin queue should be shut down and (optionally) reinitialized.
250 i40e_status i40e_vf_reset(struct i40e_hw *hw)
252 return i40e_aq_send_msg_to_pf(hw, I40E_VIRTCHNL_OP_RESET_VF,