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