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