Jeff Kirsher | ae06c70 | 2018-03-22 10:08:48 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jacob Keller | 59e331e | 2017-06-07 05:43:03 -0400 | [diff] [blame] | 5 | * Copyright(c) 2013 - 2017 Intel Corporation. |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms and conditions of the GNU General Public License, |
| 9 | * version 2, as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * The full GNU General Public License is included in this distribution in |
| 20 | * the file called "COPYING". |
| 21 | * |
| 22 | * Contact Information: |
| 23 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | * |
| 26 | ******************************************************************************/ |
| 27 | |
| 28 | #include <linux/list.h> |
| 29 | #include <linux/errno.h> |
| 30 | |
| 31 | #include "i40e.h" |
| 32 | #include "i40e_prototype.h" |
| 33 | #include "i40e_client.h" |
| 34 | |
| 35 | static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 36 | static struct i40e_client *registered_client; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 37 | static LIST_HEAD(i40e_devices); |
| 38 | static DEFINE_MUTEX(i40e_device_mutex); |
| 39 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 40 | static int i40e_client_virtchnl_send(struct i40e_info *ldev, |
| 41 | struct i40e_client *client, |
| 42 | u32 vf_id, u8 *msg, u16 len); |
| 43 | |
| 44 | static int i40e_client_setup_qvlist(struct i40e_info *ldev, |
| 45 | struct i40e_client *client, |
| 46 | struct i40e_qvlist_info *qvlist_info); |
| 47 | |
| 48 | static void i40e_client_request_reset(struct i40e_info *ldev, |
| 49 | struct i40e_client *client, |
| 50 | u32 reset_level); |
| 51 | |
| 52 | static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev, |
| 53 | struct i40e_client *client, |
| 54 | bool is_vf, u32 vf_id, |
| 55 | u32 flag, u32 valid_flag); |
| 56 | |
| 57 | static struct i40e_ops i40e_lan_ops = { |
| 58 | .virtchnl_send = i40e_client_virtchnl_send, |
| 59 | .setup_qvlist = i40e_client_setup_qvlist, |
| 60 | .request_reset = i40e_client_request_reset, |
| 61 | .update_vsi_ctxt = i40e_client_update_vsi_ctxt, |
| 62 | }; |
| 63 | |
| 64 | /** |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 65 | * i40e_client_get_params - Get the params that can change at runtime |
| 66 | * @vsi: the VSI with the message |
| 67 | * @param: clinet param struct |
| 68 | * |
| 69 | **/ |
| 70 | static |
| 71 | int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params) |
| 72 | { |
| 73 | struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config; |
| 74 | int i = 0; |
| 75 | |
| 76 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 77 | u8 tc = dcb_cfg->etscfg.prioritytable[i]; |
| 78 | u16 qs_handle; |
| 79 | |
| 80 | /* If TC is not enabled for VSI use TC0 for UP */ |
| 81 | if (!(vsi->tc_config.enabled_tc & BIT(tc))) |
| 82 | tc = 0; |
| 83 | |
| 84 | qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]); |
| 85 | params->qos.prio_qos[i].tc = tc; |
| 86 | params->qos.prio_qos[i].qs_handle = qs_handle; |
| 87 | if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) { |
| 88 | dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n", |
| 89 | tc, vsi->id); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | params->mtu = vsi->netdev->mtu; |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * i40e_notify_client_of_vf_msg - call the client vf message callback |
| 100 | * @vsi: the VSI with the message |
| 101 | * @vf_id: the absolute VF id that sent the message |
| 102 | * @msg: message buffer |
| 103 | * @len: length of the message |
| 104 | * |
| 105 | * If there is a client to this VSI, call the client |
| 106 | **/ |
| 107 | void |
| 108 | i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len) |
| 109 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 110 | struct i40e_pf *pf = vsi->back; |
| 111 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 112 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 113 | if (!cdev || !cdev->client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 114 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 115 | if (!cdev->client->ops || !cdev->client->ops->virtchnl_receive) { |
| 116 | dev_dbg(&pf->pdev->dev, |
| 117 | "Cannot locate client instance virtual channel receive routine\n"); |
| 118 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 119 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 120 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { |
| 121 | dev_dbg(&pf->pdev->dev, "Client is not open, abort virtchnl_receive\n"); |
| 122 | return; |
| 123 | } |
| 124 | cdev->client->ops->virtchnl_receive(&cdev->lan_info, cdev->client, |
| 125 | vf_id, msg, len); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * i40e_notify_client_of_l2_param_changes - call the client notify callback |
| 130 | * @vsi: the VSI with l2 param changes |
| 131 | * |
| 132 | * If there is a client to this VSI, call the client |
| 133 | **/ |
| 134 | void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi) |
| 135 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 136 | struct i40e_pf *pf = vsi->back; |
| 137 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 138 | struct i40e_params params; |
| 139 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 140 | if (!cdev || !cdev->client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 141 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 142 | if (!cdev->client->ops || !cdev->client->ops->l2_param_change) { |
| 143 | dev_dbg(&vsi->back->pdev->dev, |
| 144 | "Cannot locate client instance l2_param_change routine\n"); |
| 145 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 146 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 147 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { |
| 148 | dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n"); |
| 149 | return; |
| 150 | } |
Jacob Keller | 7be147d | 2017-03-20 16:45:35 -0700 | [diff] [blame] | 151 | memset(¶ms, 0, sizeof(params)); |
| 152 | i40e_client_get_params(vsi, ¶ms); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 153 | memcpy(&cdev->lan_info.params, ¶ms, sizeof(struct i40e_params)); |
| 154 | cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client, |
| 155 | ¶ms); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 159 | * i40e_client_release_qvlist - release MSI-X vector mapping for client |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 160 | * @ldev: pointer to L2 context. |
| 161 | * |
| 162 | **/ |
| 163 | static void i40e_client_release_qvlist(struct i40e_info *ldev) |
| 164 | { |
| 165 | struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info; |
| 166 | u32 i; |
| 167 | |
| 168 | if (!ldev->qvlist_info) |
| 169 | return; |
| 170 | |
| 171 | for (i = 0; i < qvlist_info->num_vectors; i++) { |
| 172 | struct i40e_pf *pf = ldev->pf; |
| 173 | struct i40e_qv_info *qv_info; |
| 174 | u32 reg_idx; |
| 175 | |
| 176 | qv_info = &qvlist_info->qv_info[i]; |
| 177 | if (!qv_info) |
| 178 | continue; |
| 179 | reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1); |
| 180 | wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK); |
| 181 | } |
| 182 | kfree(ldev->qvlist_info); |
| 183 | ldev->qvlist_info = NULL; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * i40e_notify_client_of_netdev_close - call the client close callback |
| 188 | * @vsi: the VSI with netdev closed |
| 189 | * @reset: true when close called due to a reset pending |
| 190 | * |
| 191 | * If there is a client to this netdev, call the client with close |
| 192 | **/ |
| 193 | void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset) |
| 194 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 195 | struct i40e_pf *pf = vsi->back; |
| 196 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 197 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 198 | if (!cdev || !cdev->client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 199 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 200 | if (!cdev->client->ops || !cdev->client->ops->close) { |
| 201 | dev_dbg(&vsi->back->pdev->dev, |
| 202 | "Cannot locate client instance close routine\n"); |
| 203 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 204 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 205 | cdev->client->ops->close(&cdev->lan_info, cdev->client, reset); |
| 206 | clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); |
| 207 | i40e_client_release_qvlist(&cdev->lan_info); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
| 211 | * i40e_notify_client_of_vf_reset - call the client vf reset callback |
| 212 | * @pf: PF device pointer |
| 213 | * @vf_id: asolute id of VF being reset |
| 214 | * |
| 215 | * If there is a client attached to this PF, notify when a VF is reset |
| 216 | **/ |
| 217 | void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id) |
| 218 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 219 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 220 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 221 | if (!cdev || !cdev->client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 222 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 223 | if (!cdev->client->ops || !cdev->client->ops->vf_reset) { |
| 224 | dev_dbg(&pf->pdev->dev, |
| 225 | "Cannot locate client instance VF reset routine\n"); |
| 226 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 227 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 228 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { |
| 229 | dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n"); |
| 230 | return; |
| 231 | } |
| 232 | cdev->client->ops->vf_reset(&cdev->lan_info, cdev->client, vf_id); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
| 236 | * i40e_notify_client_of_vf_enable - call the client vf notification callback |
| 237 | * @pf: PF device pointer |
| 238 | * @num_vfs: the number of VFs currently enabled, 0 for disable |
| 239 | * |
| 240 | * If there is a client attached to this PF, call its VF notification routine |
| 241 | **/ |
| 242 | void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs) |
| 243 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 244 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 245 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 246 | if (!cdev || !cdev->client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 247 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 248 | if (!cdev->client->ops || !cdev->client->ops->vf_enable) { |
| 249 | dev_dbg(&pf->pdev->dev, |
| 250 | "Cannot locate client instance VF enable routine\n"); |
| 251 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 252 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 253 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, |
| 254 | &cdev->state)) { |
| 255 | dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n"); |
| 256 | return; |
| 257 | } |
| 258 | cdev->client->ops->vf_enable(&cdev->lan_info, cdev->client, num_vfs); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * i40e_vf_client_capable - ask the client if it likes the specified VF |
| 263 | * @pf: PF device pointer |
| 264 | * @vf_id: the VF in question |
| 265 | * |
| 266 | * If there is a client of the specified type attached to this PF, call |
| 267 | * its vf_capable routine |
| 268 | **/ |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 269 | int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 270 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 271 | struct i40e_client_instance *cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 272 | int capable = false; |
| 273 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 274 | if (!cdev || !cdev->client) |
| 275 | goto out; |
| 276 | if (!cdev->client->ops || !cdev->client->ops->vf_capable) { |
Jacob Keller | 59e331e | 2017-06-07 05:43:03 -0400 | [diff] [blame] | 277 | dev_dbg(&pf->pdev->dev, |
| 278 | "Cannot locate client instance VF capability routine\n"); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 279 | goto out; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 280 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 281 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) |
| 282 | goto out; |
| 283 | |
| 284 | capable = cdev->client->ops->vf_capable(&cdev->lan_info, |
| 285 | cdev->client, |
| 286 | vf_id); |
| 287 | out: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 288 | return capable; |
| 289 | } |
| 290 | |
Shiraz Saleem | ddbb8d5 | 2018-03-19 09:28:03 -0700 | [diff] [blame] | 291 | void i40e_client_update_msix_info(struct i40e_pf *pf) |
| 292 | { |
| 293 | struct i40e_client_instance *cdev = pf->cinst; |
| 294 | |
| 295 | if (!cdev || !cdev->client) |
| 296 | return; |
| 297 | |
| 298 | cdev->lan_info.msix_count = pf->num_iwarp_msix; |
| 299 | cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector]; |
| 300 | } |
| 301 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 302 | /** |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 303 | * i40e_client_add_instance - add a client instance struct to the instance list |
| 304 | * @pf: pointer to the board struct |
| 305 | * @client: pointer to a client struct in the client list. |
Anjali Singhai Jain | f38ff2e | 2016-08-24 17:51:53 -0700 | [diff] [blame] | 306 | * @existing: if there was already an existing instance |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 307 | * |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 308 | **/ |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 309 | static void i40e_client_add_instance(struct i40e_pf *pf) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 310 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 311 | struct i40e_client_instance *cdev = NULL; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 312 | struct netdev_hw_addr *mac = NULL; |
| 313 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 314 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 315 | if (!registered_client || pf->cinst) |
| 316 | return; |
| 317 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 318 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 319 | if (!cdev) |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 320 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 321 | |
| 322 | cdev->lan_info.pf = (void *)pf; |
| 323 | cdev->lan_info.netdev = vsi->netdev; |
| 324 | cdev->lan_info.pcidev = pf->pdev; |
| 325 | cdev->lan_info.fid = pf->hw.pf_id; |
| 326 | cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF; |
| 327 | cdev->lan_info.hw_addr = pf->hw.hw_addr; |
| 328 | cdev->lan_info.ops = &i40e_lan_ops; |
| 329 | cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR; |
| 330 | cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR; |
| 331 | cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD; |
| 332 | cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver; |
| 333 | cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver; |
| 334 | cdev->lan_info.fw_build = pf->hw.aq.fw_build; |
| 335 | set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state); |
| 336 | |
| 337 | if (i40e_client_get_params(vsi, &cdev->lan_info.params)) { |
| 338 | kfree(cdev); |
| 339 | cdev = NULL; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 340 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 341 | } |
| 342 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 343 | mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list, |
| 344 | struct netdev_hw_addr, list); |
| 345 | if (mac) |
| 346 | ether_addr_copy(cdev->lan_info.lanmac, mac->addr); |
| 347 | else |
| 348 | dev_err(&pf->pdev->dev, "MAC address list is empty!\n"); |
| 349 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 350 | cdev->client = registered_client; |
| 351 | pf->cinst = cdev; |
Shiraz Saleem | ddbb8d5 | 2018-03-19 09:28:03 -0700 | [diff] [blame] | 352 | |
| 353 | i40e_client_update_msix_info(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /** |
| 357 | * i40e_client_del_instance - removes a client instance from the list |
| 358 | * @pf: pointer to the board struct |
| 359 | * |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 360 | **/ |
| 361 | static |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 362 | void i40e_client_del_instance(struct i40e_pf *pf) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 363 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 364 | kfree(pf->cinst); |
| 365 | pf->cinst = NULL; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
| 369 | * i40e_client_subtask - client maintenance work |
| 370 | * @pf: board private structure |
| 371 | **/ |
| 372 | void i40e_client_subtask(struct i40e_pf *pf) |
| 373 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 374 | struct i40e_client *client = registered_client; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 375 | struct i40e_client_instance *cdev; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 376 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 377 | int ret = 0; |
| 378 | |
Jacob Keller | 5f76a70 | 2018-03-16 01:26:34 -0700 | [diff] [blame] | 379 | if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state)) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 380 | return; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 381 | cdev = pf->cinst; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 382 | |
| 383 | /* If we're down or resetting, just bail */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 384 | if (test_bit(__I40E_DOWN, pf->state) || |
| 385 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 386 | return; |
| 387 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 388 | if (!client || !cdev) |
| 389 | return; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 390 | |
Shiraz Saleem | 7b0b1a6 | 2017-12-18 05:18:22 -0500 | [diff] [blame] | 391 | /* Here we handle client opens. If the client is down, and |
| 392 | * the netdev is registered, then open the client. |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 393 | */ |
| 394 | if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { |
Shiraz Saleem | 7b0b1a6 | 2017-12-18 05:18:22 -0500 | [diff] [blame] | 395 | if (vsi->netdev_registered && |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 396 | client->ops && client->ops->open) { |
| 397 | set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); |
| 398 | ret = client->ops->open(&cdev->lan_info, client); |
| 399 | if (ret) { |
| 400 | /* Remove failed client instance */ |
| 401 | clear_bit(__I40E_CLIENT_INSTANCE_OPENED, |
| 402 | &cdev->state); |
| 403 | i40e_client_del_instance(pf); |
Carolyn Wyborny | c73d2e8 | 2016-09-14 16:24:31 -0700 | [diff] [blame] | 404 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 405 | } |
| 406 | } |
Shiraz Saleem | 7b0b1a6 | 2017-12-18 05:18:22 -0500 | [diff] [blame] | 407 | |
| 408 | /* enable/disable PE TCP_ENA flag based on netdev down/up |
| 409 | */ |
| 410 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
| 411 | i40e_client_update_vsi_ctxt(&cdev->lan_info, client, |
| 412 | 0, 0, 0, |
| 413 | I40E_CLIENT_VSI_FLAG_TCP_ENABLE); |
| 414 | else |
| 415 | i40e_client_update_vsi_ctxt(&cdev->lan_info, client, |
| 416 | 0, 0, |
| 417 | I40E_CLIENT_VSI_FLAG_TCP_ENABLE, |
| 418 | I40E_CLIENT_VSI_FLAG_TCP_ENABLE); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /** |
| 422 | * i40e_lan_add_device - add a lan device struct to the list of lan devices |
| 423 | * @pf: pointer to the board struct |
| 424 | * |
| 425 | * Returns 0 on success or none 0 on error |
| 426 | **/ |
| 427 | int i40e_lan_add_device(struct i40e_pf *pf) |
| 428 | { |
| 429 | struct i40e_device *ldev; |
| 430 | int ret = 0; |
| 431 | |
| 432 | mutex_lock(&i40e_device_mutex); |
| 433 | list_for_each_entry(ldev, &i40e_devices, list) { |
| 434 | if (ldev->pf == pf) { |
| 435 | ret = -EEXIST; |
| 436 | goto out; |
| 437 | } |
| 438 | } |
| 439 | ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); |
| 440 | if (!ldev) { |
| 441 | ret = -ENOMEM; |
| 442 | goto out; |
| 443 | } |
| 444 | ldev->pf = pf; |
| 445 | INIT_LIST_HEAD(&ldev->list); |
| 446 | list_add(&ldev->list, &i40e_devices); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 447 | dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n", |
| 448 | pf->hw.pf_id, pf->hw.bus.bus_id, |
| 449 | pf->hw.bus.device, pf->hw.bus.func); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 450 | |
Mitch Williams | 8090f61 | 2017-03-30 00:46:07 -0700 | [diff] [blame] | 451 | /* If a client has already been registered, we need to add an instance |
| 452 | * of it to our new LAN device. |
| 453 | */ |
| 454 | if (registered_client) |
| 455 | i40e_client_add_instance(pf); |
| 456 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 457 | /* Since in some cases register may have happened before a device gets |
Anjali Singhai Jain | f38ff2e | 2016-08-24 17:51:53 -0700 | [diff] [blame] | 458 | * added, we can schedule a subtask to go initiate the clients if |
| 459 | * they can be launched at probe time. |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 460 | */ |
Jacob Keller | 5f76a70 | 2018-03-16 01:26:34 -0700 | [diff] [blame] | 461 | set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 462 | i40e_service_event_schedule(pf); |
| 463 | |
| 464 | out: |
| 465 | mutex_unlock(&i40e_device_mutex); |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * i40e_lan_del_device - removes a lan device from the device list |
| 471 | * @pf: pointer to the board struct |
| 472 | * |
| 473 | * Returns 0 on success or non-0 on error |
| 474 | **/ |
| 475 | int i40e_lan_del_device(struct i40e_pf *pf) |
| 476 | { |
| 477 | struct i40e_device *ldev, *tmp; |
| 478 | int ret = -ENODEV; |
| 479 | |
Mitch Williams | 295c0a5 | 2017-03-30 00:46:06 -0700 | [diff] [blame] | 480 | /* First, remove any client instance. */ |
| 481 | i40e_client_del_instance(pf); |
| 482 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 483 | mutex_lock(&i40e_device_mutex); |
| 484 | list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) { |
| 485 | if (ldev->pf == pf) { |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 486 | dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n", |
| 487 | pf->hw.pf_id, pf->hw.bus.bus_id, |
| 488 | pf->hw.bus.device, pf->hw.bus.func); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 489 | list_del(&ldev->list); |
| 490 | kfree(ldev); |
| 491 | ret = 0; |
| 492 | break; |
| 493 | } |
| 494 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 495 | mutex_unlock(&i40e_device_mutex); |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * i40e_client_release - release client specific resources |
| 501 | * @client: pointer to the registered client |
| 502 | * |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 503 | **/ |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 504 | static void i40e_client_release(struct i40e_client *client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 505 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 506 | struct i40e_client_instance *cdev; |
| 507 | struct i40e_device *ldev; |
Harshitha Ramamurthy | 682d11d | 2016-08-15 14:17:19 -0700 | [diff] [blame] | 508 | struct i40e_pf *pf; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 509 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 510 | mutex_lock(&i40e_device_mutex); |
| 511 | list_for_each_entry(ldev, &i40e_devices, list) { |
| 512 | pf = ldev->pf; |
| 513 | cdev = pf->cinst; |
| 514 | if (!cdev) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 515 | continue; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 516 | |
| 517 | while (test_and_set_bit(__I40E_SERVICE_SCHED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 518 | pf->state)) |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 519 | usleep_range(500, 1000); |
| 520 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 521 | if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 522 | if (client->ops && client->ops->close) |
| 523 | client->ops->close(&cdev->lan_info, client, |
| 524 | false); |
| 525 | i40e_client_release_qvlist(&cdev->lan_info); |
| 526 | clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); |
| 527 | |
| 528 | dev_warn(&pf->pdev->dev, |
| 529 | "Client %s instance for PF id %d closed\n", |
| 530 | client->name, pf->hw.pf_id); |
| 531 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 532 | /* delete the client instance */ |
| 533 | i40e_client_del_instance(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 534 | dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n", |
| 535 | client->name); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 536 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 537 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 538 | mutex_unlock(&i40e_device_mutex); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
| 542 | * i40e_client_prepare - prepare client specific resources |
| 543 | * @client: pointer to the registered client |
| 544 | * |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 545 | **/ |
Mitch Williams | 3bb83ba | 2017-02-09 23:46:50 -0800 | [diff] [blame] | 546 | static void i40e_client_prepare(struct i40e_client *client) |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 547 | { |
| 548 | struct i40e_device *ldev; |
| 549 | struct i40e_pf *pf; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 550 | |
| 551 | mutex_lock(&i40e_device_mutex); |
| 552 | list_for_each_entry(ldev, &i40e_devices, list) { |
| 553 | pf = ldev->pf; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 554 | i40e_client_add_instance(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 555 | /* Start the client subtask */ |
Jacob Keller | 5f76a70 | 2018-03-16 01:26:34 -0700 | [diff] [blame] | 556 | set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 557 | i40e_service_event_schedule(pf); |
| 558 | } |
| 559 | mutex_unlock(&i40e_device_mutex); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /** |
| 563 | * i40e_client_virtchnl_send - TBD |
| 564 | * @ldev: pointer to L2 context |
| 565 | * @client: Client pointer |
| 566 | * @vf_id: absolute VF identifier |
| 567 | * @msg: message buffer |
| 568 | * @len: length of message buffer |
| 569 | * |
| 570 | * Return 0 on success or < 0 on error |
| 571 | **/ |
| 572 | static int i40e_client_virtchnl_send(struct i40e_info *ldev, |
| 573 | struct i40e_client *client, |
| 574 | u32 vf_id, u8 *msg, u16 len) |
| 575 | { |
| 576 | struct i40e_pf *pf = ldev->pf; |
| 577 | struct i40e_hw *hw = &pf->hw; |
| 578 | i40e_status err; |
| 579 | |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 580 | err = i40e_aq_send_msg_to_vf(hw, vf_id, VIRTCHNL_OP_IWARP, |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 581 | 0, msg, len, NULL); |
| 582 | if (err) |
| 583 | dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n", |
| 584 | err, hw->aq.asq_last_status); |
| 585 | |
| 586 | return err; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * i40e_client_setup_qvlist |
| 591 | * @ldev: pointer to L2 context. |
| 592 | * @client: Client pointer. |
| 593 | * @qv_info: queue and vector list |
| 594 | * |
| 595 | * Return 0 on success or < 0 on error |
| 596 | **/ |
| 597 | static int i40e_client_setup_qvlist(struct i40e_info *ldev, |
| 598 | struct i40e_client *client, |
| 599 | struct i40e_qvlist_info *qvlist_info) |
| 600 | { |
| 601 | struct i40e_pf *pf = ldev->pf; |
| 602 | struct i40e_hw *hw = &pf->hw; |
| 603 | struct i40e_qv_info *qv_info; |
| 604 | u32 v_idx, i, reg_idx, reg; |
| 605 | u32 size; |
| 606 | |
| 607 | size = sizeof(struct i40e_qvlist_info) + |
| 608 | (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1)); |
| 609 | ldev->qvlist_info = kzalloc(size, GFP_KERNEL); |
Christophe Jaillet | 0a4ecc2 | 2017-05-05 21:29:13 +0200 | [diff] [blame] | 610 | if (!ldev->qvlist_info) |
| 611 | return -ENOMEM; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 612 | ldev->qvlist_info->num_vectors = qvlist_info->num_vectors; |
| 613 | |
| 614 | for (i = 0; i < qvlist_info->num_vectors; i++) { |
| 615 | qv_info = &qvlist_info->qv_info[i]; |
| 616 | if (!qv_info) |
| 617 | continue; |
| 618 | v_idx = qv_info->v_idx; |
| 619 | |
| 620 | /* Validate vector id belongs to this client */ |
| 621 | if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) || |
| 622 | (v_idx < pf->iwarp_base_vector)) |
| 623 | goto err; |
| 624 | |
| 625 | ldev->qvlist_info->qv_info[i] = *qv_info; |
| 626 | reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1); |
| 627 | |
| 628 | if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) { |
| 629 | /* Special case - No CEQ mapped on this vector */ |
| 630 | wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK); |
| 631 | } else { |
| 632 | reg = (qv_info->ceq_idx & |
| 633 | I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | |
| 634 | (I40E_QUEUE_TYPE_PE_CEQ << |
| 635 | I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT); |
| 636 | wr32(hw, reg_idx, reg); |
| 637 | |
| 638 | reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK | |
| 639 | (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) | |
| 640 | (qv_info->itr_idx << |
| 641 | I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) | |
| 642 | (I40E_QUEUE_END_OF_LIST << |
| 643 | I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT)); |
| 644 | wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg); |
| 645 | } |
| 646 | if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) { |
| 647 | reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK | |
| 648 | (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) | |
| 649 | (qv_info->itr_idx << |
| 650 | I40E_PFINT_AEQCTL_ITR_INDX_SHIFT)); |
| 651 | |
| 652 | wr32(hw, I40E_PFINT_AEQCTL, reg); |
| 653 | } |
| 654 | } |
Avinash Dayanand | 70df973 | 2016-07-27 12:02:36 -0700 | [diff] [blame] | 655 | /* Mitigate sync problems with iwarp VF driver */ |
| 656 | i40e_flush(hw); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 657 | return 0; |
| 658 | err: |
| 659 | kfree(ldev->qvlist_info); |
| 660 | ldev->qvlist_info = NULL; |
| 661 | return -EINVAL; |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * i40e_client_request_reset |
| 666 | * @ldev: pointer to L2 context. |
| 667 | * @client: Client pointer. |
| 668 | * @level: reset level |
| 669 | **/ |
| 670 | static void i40e_client_request_reset(struct i40e_info *ldev, |
| 671 | struct i40e_client *client, |
| 672 | u32 reset_level) |
| 673 | { |
| 674 | struct i40e_pf *pf = ldev->pf; |
| 675 | |
| 676 | switch (reset_level) { |
| 677 | case I40E_CLIENT_RESET_LEVEL_PF: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 678 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 679 | break; |
| 680 | case I40E_CLIENT_RESET_LEVEL_CORE: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 681 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 682 | break; |
| 683 | default: |
| 684 | dev_warn(&pf->pdev->dev, |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 685 | "Client for PF id %d requested an unsupported reset: %d.\n", |
| 686 | pf->hw.pf_id, reset_level); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 687 | break; |
| 688 | } |
| 689 | |
| 690 | i40e_service_event_schedule(pf); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * i40e_client_update_vsi_ctxt |
| 695 | * @ldev: pointer to L2 context. |
| 696 | * @client: Client pointer. |
| 697 | * @is_vf: if this for the VF |
| 698 | * @vf_id: if is_vf true this carries the vf_id |
| 699 | * @flag: Any device level setting that needs to be done for PE |
| 700 | * @valid_flag: Bits in this match up and enable changing of flag bits |
| 701 | * |
| 702 | * Return 0 on success or < 0 on error |
| 703 | **/ |
| 704 | static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev, |
| 705 | struct i40e_client *client, |
| 706 | bool is_vf, u32 vf_id, |
| 707 | u32 flag, u32 valid_flag) |
| 708 | { |
| 709 | struct i40e_pf *pf = ldev->pf; |
| 710 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 711 | struct i40e_vsi_context ctxt; |
| 712 | bool update = true; |
| 713 | i40e_status err; |
| 714 | |
| 715 | /* TODO: for now do not allow setting VF's VSI setting */ |
| 716 | if (is_vf) |
| 717 | return -EINVAL; |
| 718 | |
| 719 | ctxt.seid = pf->main_vsi_seid; |
| 720 | ctxt.pf_num = pf->hw.pf_id; |
| 721 | err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 722 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 723 | if (err) { |
| 724 | dev_info(&pf->pdev->dev, |
| 725 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 726 | i40e_stat_str(&pf->hw, err), |
| 727 | i40e_aq_str(&pf->hw, |
| 728 | pf->hw.aq.asq_last_status)); |
| 729 | return -ENOENT; |
| 730 | } |
| 731 | |
Shiraz Saleem | 7b0b1a6 | 2017-12-18 05:18:22 -0500 | [diff] [blame] | 732 | if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) && |
| 733 | (flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 734 | ctxt.info.valid_sections = |
| 735 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 736 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
Shiraz Saleem | 7b0b1a6 | 2017-12-18 05:18:22 -0500 | [diff] [blame] | 737 | } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) && |
| 738 | !(flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 739 | ctxt.info.valid_sections = |
| 740 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 741 | ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 742 | } else { |
| 743 | update = false; |
| 744 | dev_warn(&pf->pdev->dev, |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 745 | "Client for PF id %d request an unsupported Config: %x.\n", |
| 746 | pf->hw.pf_id, flag); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | if (update) { |
| 750 | err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 751 | if (err) { |
| 752 | dev_info(&pf->pdev->dev, |
| 753 | "update VSI ctxt for PE failed, err %s aq_err %s\n", |
| 754 | i40e_stat_str(&pf->hw, err), |
| 755 | i40e_aq_str(&pf->hw, |
| 756 | pf->hw.aq.asq_last_status)); |
| 757 | } |
| 758 | } |
| 759 | return err; |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * i40e_register_client - Register a i40e client driver with the L2 driver |
| 764 | * @client: pointer to the i40e_client struct |
| 765 | * |
| 766 | * Returns 0 on success or non-0 on error |
| 767 | **/ |
| 768 | int i40e_register_client(struct i40e_client *client) |
| 769 | { |
| 770 | int ret = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 771 | |
| 772 | if (!client) { |
| 773 | ret = -EIO; |
| 774 | goto out; |
| 775 | } |
| 776 | |
| 777 | if (strlen(client->name) == 0) { |
| 778 | pr_info("i40e: Failed to register client with no name\n"); |
| 779 | ret = -EIO; |
| 780 | goto out; |
| 781 | } |
| 782 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 783 | if (registered_client) { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 784 | pr_info("i40e: Client %s has already been registered!\n", |
| 785 | client->name); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 786 | ret = -EEXIST; |
| 787 | goto out; |
| 788 | } |
| 789 | |
| 790 | if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) || |
| 791 | (client->version.minor != I40E_CLIENT_VERSION_MINOR)) { |
| 792 | pr_info("i40e: Failed to register client %s due to mismatched client interface version\n", |
| 793 | client->name); |
| 794 | pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n", |
| 795 | client->version.major, client->version.minor, |
| 796 | client->version.build, |
| 797 | i40e_client_interface_version_str); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 798 | ret = -EIO; |
| 799 | goto out; |
| 800 | } |
| 801 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 802 | registered_client = client; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 803 | |
Mitch Williams | 3bb83ba | 2017-02-09 23:46:50 -0800 | [diff] [blame] | 804 | i40e_client_prepare(client); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 805 | |
Mitch Williams | 3bb83ba | 2017-02-09 23:46:50 -0800 | [diff] [blame] | 806 | pr_info("i40e: Registered client %s\n", client->name); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 807 | out: |
| 808 | return ret; |
| 809 | } |
| 810 | EXPORT_SYMBOL(i40e_register_client); |
| 811 | |
| 812 | /** |
| 813 | * i40e_unregister_client - Unregister a i40e client driver with the L2 driver |
| 814 | * @client: pointer to the i40e_client struct |
| 815 | * |
| 816 | * Returns 0 on success or non-0 on error |
| 817 | **/ |
| 818 | int i40e_unregister_client(struct i40e_client *client) |
| 819 | { |
| 820 | int ret = 0; |
| 821 | |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 822 | if (registered_client != client) { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 823 | pr_info("i40e: Client %s has not been registered\n", |
| 824 | client->name); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 825 | ret = -ENODEV; |
| 826 | goto out; |
| 827 | } |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 828 | registered_client = NULL; |
| 829 | /* When a unregister request comes through we would have to send |
| 830 | * a close for each of the client instances that were opened. |
| 831 | * client_release function is called to handle this. |
| 832 | */ |
| 833 | i40e_client_release(client); |
| 834 | |
| 835 | pr_info("i40e: Unregistered client %s\n", client->name); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 836 | out: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 837 | return ret; |
| 838 | } |
| 839 | EXPORT_SYMBOL(i40e_unregister_client); |