]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ice/ice_sriov.c
Merge OpenSSL 1.1.1h.
[FreeBSD/FreeBSD.git] / sys / dev / ice / ice_sriov.c
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2020, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  */
31 /*$FreeBSD$*/
32
33 #include "ice_common.h"
34 #include "ice_adminq_cmd.h"
35 #include "ice_sriov.h"
36
37 /**
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
44  * @msglen: msg length
45  * @cd: pointer to command details
46  *
47  * Send message to VF driver (0x0802) using mailbox
48  * queue and asynchronously sending message via
49  * ice_sq_send_cmd() function
50  */
51 enum ice_status
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)
54 {
55         struct ice_aqc_pf_vf_msg *cmd;
56         struct ice_aq_desc desc;
57
58         ice_fill_dflt_direct_cmd_desc(&desc, ice_mbx_opc_send_msg_to_vf);
59
60         cmd = &desc.params.virt;
61         cmd->id = CPU_TO_LE32(vfid);
62
63         desc.cookie_high = CPU_TO_LE32(v_opcode);
64         desc.cookie_low = CPU_TO_LE32(v_retval);
65
66         if (msglen)
67                 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
68
69         return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
70 }
71
72 /**
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
78  * @msglen: msg length
79  * @cd: pointer to command details
80  *
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.
84  */
85 enum ice_status
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,
88                       struct ice_sq_cd *cd)
89 {
90         struct ice_aq_desc desc;
91
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);
95
96         if (msglen)
97                 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
98
99         return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
100 }
101
102 /**
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
106  *
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.
113  */
114 u32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed)
115 {
116         u32 speed;
117
118         if (adv_link_support)
119                 switch (link_speed) {
120                 case ICE_AQ_LINK_SPEED_10MB:
121                         speed = ICE_LINK_SPEED_10MBPS;
122                         break;
123                 case ICE_AQ_LINK_SPEED_100MB:
124                         speed = ICE_LINK_SPEED_100MBPS;
125                         break;
126                 case ICE_AQ_LINK_SPEED_1000MB:
127                         speed = ICE_LINK_SPEED_1000MBPS;
128                         break;
129                 case ICE_AQ_LINK_SPEED_2500MB:
130                         speed = ICE_LINK_SPEED_2500MBPS;
131                         break;
132                 case ICE_AQ_LINK_SPEED_5GB:
133                         speed = ICE_LINK_SPEED_5000MBPS;
134                         break;
135                 case ICE_AQ_LINK_SPEED_10GB:
136                         speed = ICE_LINK_SPEED_10000MBPS;
137                         break;
138                 case ICE_AQ_LINK_SPEED_20GB:
139                         speed = ICE_LINK_SPEED_20000MBPS;
140                         break;
141                 case ICE_AQ_LINK_SPEED_25GB:
142                         speed = ICE_LINK_SPEED_25000MBPS;
143                         break;
144                 case ICE_AQ_LINK_SPEED_40GB:
145                         speed = ICE_LINK_SPEED_40000MBPS;
146                         break;
147                 case ICE_AQ_LINK_SPEED_50GB:
148                         speed = ICE_LINK_SPEED_50000MBPS;
149                         break;
150                 case ICE_AQ_LINK_SPEED_100GB:
151                         speed = ICE_LINK_SPEED_100000MBPS;
152                         break;
153                 default:
154                         speed = ICE_LINK_SPEED_UNKNOWN;
155                         break;
156                 }
157         else
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
162                  */
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;
167                         break;
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;
172                         break;
173                 case ICE_AQ_LINK_SPEED_10GB:
174                         speed = (u32)VIRTCHNL_LINK_SPEED_10GB;
175                         break;
176                 case ICE_AQ_LINK_SPEED_20GB:
177                         speed = (u32)VIRTCHNL_LINK_SPEED_20GB;
178                         break;
179                 case ICE_AQ_LINK_SPEED_25GB:
180                         speed = (u32)VIRTCHNL_LINK_SPEED_25GB;
181                         break;
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;
186                         break;
187                 default:
188                         speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN;
189                         break;
190                 }
191
192         return speed;
193 }