1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2020, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include "ice_common.h"
34 #include "ice_adminq_cmd.h"
35 #include "ice_sriov.h"
38 * ice_aq_send_msg_to_vf
39 * @hw: pointer to the hardware structure
40 * @vfid: VF ID to send msg
41 * @v_opcode: opcodes for VF-PF communication
42 * @v_retval: return error code
43 * @msg: pointer to the msg buffer
45 * @cd: pointer to command details
47 * Send message to VF driver (0x0802) using mailbox
48 * queue and asynchronously sending message via
49 * ice_sq_send_cmd() function
52 ice_aq_send_msg_to_vf(struct ice_hw *hw, u16 vfid, u32 v_opcode, u32 v_retval,
53 u8 *msg, u16 msglen, struct ice_sq_cd *cd)
55 struct ice_aqc_pf_vf_msg *cmd;
56 struct ice_aq_desc desc;
58 ice_fill_dflt_direct_cmd_desc(&desc, ice_mbx_opc_send_msg_to_vf);
60 cmd = &desc.params.virt;
61 cmd->id = CPU_TO_LE32(vfid);
63 desc.cookie_high = CPU_TO_LE32(v_opcode);
64 desc.cookie_low = CPU_TO_LE32(v_retval);
67 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
69 return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
73 * ice_aq_send_msg_to_pf
74 * @hw: pointer to the hardware structure
75 * @v_opcode: opcodes for VF-PF communication
76 * @v_retval: return error code
77 * @msg: pointer to the msg buffer
79 * @cd: pointer to command details
81 * Send message to PF driver using mailbox queue. By default, this
82 * message is sent asynchronously, i.e. ice_sq_send_cmd()
83 * does not wait for completion before returning.
86 ice_aq_send_msg_to_pf(struct ice_hw *hw, enum virtchnl_ops v_opcode,
87 enum ice_status v_retval, u8 *msg, u16 msglen,
90 struct ice_aq_desc desc;
92 ice_fill_dflt_direct_cmd_desc(&desc, ice_mbx_opc_send_msg_to_pf);
93 desc.cookie_high = CPU_TO_LE32(v_opcode);
94 desc.cookie_low = CPU_TO_LE32(v_retval);
97 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
99 return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
103 * ice_conv_link_speed_to_virtchnl
104 * @adv_link_support: determines the format of the returned link speed
105 * @link_speed: variable containing the link_speed to be converted
107 * Convert link speed supported by HW to link speed supported by virtchnl.
108 * If adv_link_support is true, then return link speed in Mbps. Else return
109 * link speed as a VIRTCHNL_LINK_SPEED_* casted to a u32. Note that the caller
110 * needs to cast back to an enum virtchnl_link_speed in the case where
111 * adv_link_support is false, but when adv_link_support is true the caller can
112 * expect the speed in Mbps.
114 u32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed)
118 if (adv_link_support)
119 switch (link_speed) {
120 case ICE_AQ_LINK_SPEED_10MB:
121 speed = ICE_LINK_SPEED_10MBPS;
123 case ICE_AQ_LINK_SPEED_100MB:
124 speed = ICE_LINK_SPEED_100MBPS;
126 case ICE_AQ_LINK_SPEED_1000MB:
127 speed = ICE_LINK_SPEED_1000MBPS;
129 case ICE_AQ_LINK_SPEED_2500MB:
130 speed = ICE_LINK_SPEED_2500MBPS;
132 case ICE_AQ_LINK_SPEED_5GB:
133 speed = ICE_LINK_SPEED_5000MBPS;
135 case ICE_AQ_LINK_SPEED_10GB:
136 speed = ICE_LINK_SPEED_10000MBPS;
138 case ICE_AQ_LINK_SPEED_20GB:
139 speed = ICE_LINK_SPEED_20000MBPS;
141 case ICE_AQ_LINK_SPEED_25GB:
142 speed = ICE_LINK_SPEED_25000MBPS;
144 case ICE_AQ_LINK_SPEED_40GB:
145 speed = ICE_LINK_SPEED_40000MBPS;
147 case ICE_AQ_LINK_SPEED_50GB:
148 speed = ICE_LINK_SPEED_50000MBPS;
150 case ICE_AQ_LINK_SPEED_100GB:
151 speed = ICE_LINK_SPEED_100000MBPS;
154 speed = ICE_LINK_SPEED_UNKNOWN;
158 /* Virtchnl speeds are not defined for every speed supported in
159 * the hardware. To maintain compatibility with older AVF
160 * drivers, while reporting the speed the new speed values are
161 * resolved to the closest known virtchnl speeds
163 switch (link_speed) {
164 case ICE_AQ_LINK_SPEED_10MB:
165 case ICE_AQ_LINK_SPEED_100MB:
166 speed = (u32)VIRTCHNL_LINK_SPEED_100MB;
168 case ICE_AQ_LINK_SPEED_1000MB:
169 case ICE_AQ_LINK_SPEED_2500MB:
170 case ICE_AQ_LINK_SPEED_5GB:
171 speed = (u32)VIRTCHNL_LINK_SPEED_1GB;
173 case ICE_AQ_LINK_SPEED_10GB:
174 speed = (u32)VIRTCHNL_LINK_SPEED_10GB;
176 case ICE_AQ_LINK_SPEED_20GB:
177 speed = (u32)VIRTCHNL_LINK_SPEED_20GB;
179 case ICE_AQ_LINK_SPEED_25GB:
180 speed = (u32)VIRTCHNL_LINK_SPEED_25GB;
182 case ICE_AQ_LINK_SPEED_40GB:
183 case ICE_AQ_LINK_SPEED_50GB:
184 case ICE_AQ_LINK_SPEED_100GB:
185 speed = (u32)VIRTCHNL_LINK_SPEED_40GB;
188 speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN;