| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* QLogic qlcnic NIC Driver |
| 4 |
* Copyright (c) 2009-2013 QLogic Corporation |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <linux/types.h> |
| 8 |
|
| 9 |
#include "qlcnic_sriov.h" |
| 10 |
#include "qlcnic.h" |
| 11 |
#include "qlcnic_83xx_hw.h" |
| 12 |
|
| 13 |
#define QLC_BC_COMMAND 0 |
| 14 |
#define QLC_BC_RESPONSE 1 |
| 15 |
|
| 16 |
#define QLC_MBOX_RESP_TIMEOUT (10 * HZ) |
| 17 |
#define QLC_MBOX_CH_FREE_TIMEOUT (10 * HZ) |
| 18 |
|
| 19 |
#define QLC_BC_MSG 0 |
| 20 |
#define QLC_BC_CFREE 1 |
| 21 |
#define QLC_BC_FLR 2 |
| 22 |
#define QLC_BC_HDR_SZ 16 |
| 23 |
#define QLC_BC_PAYLOAD_SZ (1024 - QLC_BC_HDR_SZ) |
| 24 |
|
| 25 |
#define QLC_DEFAULT_RCV_DESCRIPTORS_SRIOV_VF 2048 |
| 26 |
#define QLC_DEFAULT_JUMBO_RCV_DESCRIPTORS_SRIOV_VF 512 |
| 27 |
|
| 28 |
#define QLC_83XX_VF_RESET_FAIL_THRESH 8 |
| 29 |
#define QLC_BC_CMD_MAX_RETRY_CNT 5 |
| 30 |
|
| 31 |
static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct *work); |
| 32 |
static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter *); |
| 33 |
static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *, u32); |
| 34 |
static void qlcnic_sriov_vf_poll_dev_state(struct work_struct *); |
| 35 |
static void qlcnic_sriov_vf_cancel_fw_work(struct qlcnic_adapter *); |
| 36 |
static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans *); |
| 37 |
static int qlcnic_sriov_issue_cmd(struct qlcnic_adapter *, |
| 38 |
struct qlcnic_cmd_args *); |
| 39 |
static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter *, u8); |
| 40 |
static void qlcnic_sriov_process_bc_cmd(struct work_struct *); |
| 41 |
static int qlcnic_sriov_vf_shutdown(struct pci_dev *); |
| 42 |
static int qlcnic_sriov_vf_resume(struct qlcnic_adapter *); |
| 43 |
static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter *, |
| 44 |
struct qlcnic_cmd_args *); |
| 45 |
|
| 46 |
static struct qlcnic_hardware_ops qlcnic_sriov_vf_hw_ops = { |
| 47 |
.read_crb = qlcnic_83xx_read_crb, |
| 48 |
.write_crb = qlcnic_83xx_write_crb, |
| 49 |
.read_reg = qlcnic_83xx_rd_reg_indirect, |
| 50 |
.write_reg = qlcnic_83xx_wrt_reg_indirect, |
| 51 |
.get_mac_address = qlcnic_83xx_get_mac_address, |
| 52 |
.setup_intr = qlcnic_83xx_setup_intr, |
| 53 |
.alloc_mbx_args = qlcnic_83xx_alloc_mbx_args, |
| 54 |
.mbx_cmd = qlcnic_sriov_issue_cmd, |
| 55 |
.get_func_no = qlcnic_83xx_get_func_no, |
| 56 |
.api_lock = qlcnic_83xx_cam_lock, |
| 57 |
.api_unlock = qlcnic_83xx_cam_unlock, |
| 58 |
.process_lb_rcv_ring_diag = qlcnic_83xx_process_rcv_ring_diag, |
| 59 |
.create_rx_ctx = qlcnic_83xx_create_rx_ctx, |
| 60 |
.create_tx_ctx = qlcnic_83xx_create_tx_ctx, |
| 61 |
.del_rx_ctx = qlcnic_83xx_del_rx_ctx, |
| 62 |
.del_tx_ctx = qlcnic_83xx_del_tx_ctx, |
| 63 |
.setup_link_event = qlcnic_83xx_setup_link_event, |
| 64 |
.get_nic_info = qlcnic_83xx_get_nic_info, |
| 65 |
.get_pci_info = qlcnic_83xx_get_pci_info, |
| 66 |
.set_nic_info = qlcnic_83xx_set_nic_info, |
| 67 |
.change_macvlan = qlcnic_83xx_sre_macaddr_change, |
| 68 |
.napi_enable = qlcnic_83xx_napi_enable, |
| 69 |
.napi_disable = qlcnic_83xx_napi_disable, |
| 70 |
.config_intr_coal = qlcnic_83xx_config_intr_coal, |
| 71 |
.config_rss = qlcnic_83xx_config_rss, |
| 72 |
.config_hw_lro = qlcnic_83xx_config_hw_lro, |
| 73 |
.config_promisc_mode = qlcnic_83xx_nic_set_promisc, |
| 74 |
.change_l2_filter = qlcnic_83xx_change_l2_filter, |
| 75 |
.get_board_info = qlcnic_83xx_get_port_info, |
| 76 |
.free_mac_list = qlcnic_sriov_vf_free_mac_list, |
| 77 |
.enable_sds_intr = qlcnic_83xx_enable_sds_intr, |
| 78 |
.disable_sds_intr = qlcnic_83xx_disable_sds_intr, |
| 79 |
.encap_rx_offload = qlcnic_83xx_encap_rx_offload, |
| 80 |
.encap_tx_offload = qlcnic_83xx_encap_tx_offload, |
| 81 |
}; |
| 82 |
|
| 83 |
static struct qlcnic_nic_template qlcnic_sriov_vf_ops = { |
| 84 |
.config_bridged_mode = qlcnic_config_bridged_mode, |
| 85 |
.config_led = qlcnic_config_led, |
| 86 |
.cancel_idc_work = qlcnic_sriov_vf_cancel_fw_work, |
| 87 |
.napi_add = qlcnic_83xx_napi_add, |
| 88 |
.napi_del = qlcnic_83xx_napi_del, |
| 89 |
.shutdown = qlcnic_sriov_vf_shutdown, |
| 90 |
.resume = qlcnic_sriov_vf_resume, |
| 91 |
.config_ipaddr = qlcnic_83xx_config_ipaddr, |
| 92 |
.clear_legacy_intr = qlcnic_83xx_clear_legacy_intr, |
| 93 |
}; |
| 94 |
|
| 95 |
static const struct qlcnic_mailbox_metadata qlcnic_sriov_bc_mbx_tbl[] = { |
| 96 |
{QLCNIC_BC_CMD_CHANNEL_INIT, 2, 2}, |
| 97 |
{QLCNIC_BC_CMD_CHANNEL_TERM, 2, 2}, |
| 98 |
{QLCNIC_BC_CMD_GET_ACL, 3, 14}, |
| 99 |
{QLCNIC_BC_CMD_CFG_GUEST_VLAN, 2, 2}, |
| 100 |
}; |
| 101 |
|
| 102 |
static inline bool qlcnic_sriov_bc_msg_check(u32 val) |
| 103 |
{ |
| 104 |
return (val & (1 << QLC_BC_MSG)) ? true : false; |
| 105 |
} |
| 106 |
|
| 107 |
static inline bool qlcnic_sriov_channel_free_check(u32 val) |
| 108 |
{ |
| 109 |
return (val & (1 << QLC_BC_CFREE)) ? true : false; |
| 110 |
} |
| 111 |
|
| 112 |
static inline bool qlcnic_sriov_flr_check(u32 val) |
| 113 |
{ |
| 114 |
return (val & (1 << QLC_BC_FLR)) ? true : false; |
| 115 |
} |
| 116 |
|
| 117 |
static inline u8 qlcnic_sriov_target_func_id(u32 val) |
| 118 |
{ |
| 119 |
return (val >> 4) & 0xff; |
| 120 |
} |
| 121 |
|
| 122 |
static int qlcnic_sriov_virtid_fn(struct qlcnic_adapter *adapter, int vf_id) |
| 123 |
{ |
| 124 |
struct pci_dev *dev = adapter->pdev; |
| 125 |
int pos; |
| 126 |
u16 stride, offset; |
| 127 |
|
| 128 |
if (qlcnic_sriov_vf_check(adapter)) |
| 129 |
return 0; |
| 130 |
|
| 131 |
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV); |
| 132 |
if (!pos) |
| 133 |
return 0; |
| 134 |
pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &offset); |
| 135 |
pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &stride); |
| 136 |
|
| 137 |
return (dev->devfn + offset + stride * vf_id) & 0xff; |
| 138 |
} |
| 139 |
|
| 140 |
int qlcnic_sriov_init(struct qlcnic_adapter *adapter, int num_vfs) |
| 141 |
{ |
| 142 |
struct qlcnic_sriov *sriov; |
| 143 |
struct qlcnic_back_channel *bc; |
| 144 |
struct workqueue_struct *wq; |
| 145 |
struct qlcnic_vport *vp; |
| 146 |
struct qlcnic_vf_info *vf; |
| 147 |
int err, i; |
| 148 |
|
| 149 |
if (!qlcnic_sriov_enable_check(adapter)) |
| 150 |
return -EIO; |
| 151 |
|
| 152 |
sriov = kzalloc_obj(struct qlcnic_sriov); |
| 153 |
if (!sriov) |
| 154 |
return -ENOMEM; |
| 155 |
|
| 156 |
adapter->ahw->sriov = sriov; |
| 157 |
sriov->num_vfs = num_vfs; |
| 158 |
bc = &sriov->bc; |
| 159 |
sriov->vf_info = kzalloc_objs(struct qlcnic_vf_info, num_vfs); |
| 160 |
if (!sriov->vf_info) { |
| 161 |
err = -ENOMEM; |
| 162 |
goto qlcnic_free_sriov; |
| 163 |
} |
| 164 |
|
| 165 |
wq = create_singlethread_workqueue("bc-trans"); |
| 166 |
if (wq == NULL) { |
| 167 |
err = -ENOMEM; |
| 168 |
dev_err(&adapter->pdev->dev, |
| 169 |
"Cannot create bc-trans workqueue\n"); |
| 170 |
goto qlcnic_free_vf_info; |
| 171 |
} |
| 172 |
|
| 173 |
bc->bc_trans_wq = wq; |
| 174 |
|
| 175 |
wq = create_singlethread_workqueue("async"); |
| 176 |
if (wq == NULL) { |
| 177 |
err = -ENOMEM; |
| 178 |
dev_err(&adapter->pdev->dev, "Cannot create async workqueue\n"); |
| 179 |
goto qlcnic_destroy_trans_wq; |
| 180 |
} |
| 181 |
|
| 182 |
bc->bc_async_wq = wq; |
| 183 |
INIT_LIST_HEAD(&bc->async_cmd_list); |
| 184 |
INIT_WORK(&bc->vf_async_work, qlcnic_sriov_handle_async_issue_cmd); |
| 185 |
spin_lock_init(&bc->queue_lock); |
| 186 |
bc->adapter = adapter; |
| 187 |
|
| 188 |
for (i = 0; i < num_vfs; i++) { |
| 189 |
vf = &sriov->vf_info[i]; |
| 190 |
vf->adapter = adapter; |
| 191 |
vf->pci_func = qlcnic_sriov_virtid_fn(adapter, i); |
| 192 |
mutex_init(&vf->send_cmd_lock); |
| 193 |
spin_lock_init(&vf->vlan_list_lock); |
| 194 |
INIT_LIST_HEAD(&vf->rcv_act.wait_list); |
| 195 |
INIT_LIST_HEAD(&vf->rcv_pend.wait_list); |
| 196 |
spin_lock_init(&vf->rcv_act.lock); |
| 197 |
spin_lock_init(&vf->rcv_pend.lock); |
| 198 |
init_completion(&vf->ch_free_cmpl); |
| 199 |
|
| 200 |
INIT_WORK(&vf->trans_work, qlcnic_sriov_process_bc_cmd); |
| 201 |
|
| 202 |
if (qlcnic_sriov_pf_check(adapter)) { |
| 203 |
vp = kzalloc_obj(struct qlcnic_vport); |
| 204 |
if (!vp) { |
| 205 |
err = -ENOMEM; |
| 206 |
goto qlcnic_destroy_async_wq; |
| 207 |
} |
| 208 |
sriov->vf_info[i].vp = vp; |
| 209 |
vp->vlan_mode = QLC_GUEST_VLAN_MODE; |
| 210 |
vp->max_tx_bw = MAX_BW; |
| 211 |
vp->min_tx_bw = MIN_BW; |
| 212 |
vp->spoofchk = false; |
| 213 |
eth_random_addr(vp->mac); |
| 214 |
dev_info(&adapter->pdev->dev, |
| 215 |
"MAC Address %pM is configured for VF %d\n", |
| 216 |
vp->mac, i); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return 0; |
| 221 |
|
| 222 |
qlcnic_destroy_async_wq: |
| 223 |
while (i--) |
| 224 |
kfree(sriov->vf_info[i].vp); |
| 225 |
destroy_workqueue(bc->bc_async_wq); |
| 226 |
|
| 227 |
qlcnic_destroy_trans_wq: |
| 228 |
destroy_workqueue(bc->bc_trans_wq); |
| 229 |
|
| 230 |
qlcnic_free_vf_info: |
| 231 |
kfree(sriov->vf_info); |
| 232 |
|
| 233 |
qlcnic_free_sriov: |
| 234 |
kfree(adapter->ahw->sriov); |
| 235 |
return err; |
| 236 |
} |
| 237 |
|
| 238 |
void qlcnic_sriov_cleanup_list(struct qlcnic_trans_list *t_list) |
| 239 |
{ |
| 240 |
struct qlcnic_bc_trans *trans; |
| 241 |
struct qlcnic_cmd_args cmd; |
| 242 |
unsigned long flags; |
| 243 |
|
| 244 |
spin_lock_irqsave(&t_list->lock, flags); |
| 245 |
|
| 246 |
while (!list_empty(&t_list->wait_list)) { |
| 247 |
trans = list_first_entry(&t_list->wait_list, |
| 248 |
struct qlcnic_bc_trans, list); |
| 249 |
list_del(&trans->list); |
| 250 |
t_list->count--; |
| 251 |
cmd.req.arg = (u32 *)trans->req_pay; |
| 252 |
cmd.rsp.arg = (u32 *)trans->rsp_pay; |
| 253 |
qlcnic_free_mbx_args(&cmd); |
| 254 |
qlcnic_sriov_cleanup_transaction(trans); |
| 255 |
} |
| 256 |
|
| 257 |
spin_unlock_irqrestore(&t_list->lock, flags); |
| 258 |
} |
| 259 |
|
| 260 |
void __qlcnic_sriov_cleanup(struct qlcnic_adapter *adapter) |
| 261 |
{ |
| 262 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 263 |
struct qlcnic_back_channel *bc = &sriov->bc; |
| 264 |
struct qlcnic_vf_info *vf; |
| 265 |
int i; |
| 266 |
|
| 267 |
if (!qlcnic_sriov_enable_check(adapter)) |
| 268 |
return; |
| 269 |
|
| 270 |
qlcnic_sriov_cleanup_async_list(bc); |
| 271 |
destroy_workqueue(bc->bc_async_wq); |
| 272 |
|
| 273 |
for (i = 0; i < sriov->num_vfs; i++) { |
| 274 |
vf = &sriov->vf_info[i]; |
| 275 |
qlcnic_sriov_cleanup_list(&vf->rcv_pend); |
| 276 |
cancel_work_sync(&vf->trans_work); |
| 277 |
qlcnic_sriov_cleanup_list(&vf->rcv_act); |
| 278 |
} |
| 279 |
|
| 280 |
destroy_workqueue(bc->bc_trans_wq); |
| 281 |
|
| 282 |
for (i = 0; i < sriov->num_vfs; i++) |
| 283 |
kfree(sriov->vf_info[i].vp); |
| 284 |
|
| 285 |
kfree(sriov->vf_info); |
| 286 |
kfree(adapter->ahw->sriov); |
| 287 |
} |
| 288 |
|
| 289 |
static void qlcnic_sriov_vf_cleanup(struct qlcnic_adapter *adapter) |
| 290 |
{ |
| 291 |
qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_TERM); |
| 292 |
qlcnic_sriov_cfg_bc_intr(adapter, 0); |
| 293 |
__qlcnic_sriov_cleanup(adapter); |
| 294 |
} |
| 295 |
|
| 296 |
void qlcnic_sriov_cleanup(struct qlcnic_adapter *adapter) |
| 297 |
{ |
| 298 |
if (!test_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state)) |
| 299 |
return; |
| 300 |
|
| 301 |
qlcnic_sriov_free_vlans(adapter); |
| 302 |
|
| 303 |
if (qlcnic_sriov_pf_check(adapter)) |
| 304 |
qlcnic_sriov_pf_cleanup(adapter); |
| 305 |
|
| 306 |
if (qlcnic_sriov_vf_check(adapter)) |
| 307 |
qlcnic_sriov_vf_cleanup(adapter); |
| 308 |
} |
| 309 |
|
| 310 |
static int qlcnic_sriov_post_bc_msg(struct qlcnic_adapter *adapter, u32 *hdr, |
| 311 |
u32 *pay, u8 pci_func, u8 size) |
| 312 |
{ |
| 313 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 314 |
struct qlcnic_mailbox *mbx = ahw->mailbox; |
| 315 |
struct qlcnic_cmd_args cmd; |
| 316 |
unsigned long timeout; |
| 317 |
int err; |
| 318 |
|
| 319 |
memset(&cmd, 0, sizeof(struct qlcnic_cmd_args)); |
| 320 |
cmd.hdr = hdr; |
| 321 |
cmd.pay = pay; |
| 322 |
cmd.pay_size = size; |
| 323 |
cmd.func_num = pci_func; |
| 324 |
cmd.op_type = QLC_83XX_MBX_POST_BC_OP; |
| 325 |
cmd.cmd_op = ((struct qlcnic_bc_hdr *)hdr)->cmd_op; |
| 326 |
|
| 327 |
err = mbx->ops->enqueue_cmd(adapter, &cmd, &timeout); |
| 328 |
if (err) { |
| 329 |
dev_err(&adapter->pdev->dev, |
| 330 |
"%s: Mailbox not available, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n", |
| 331 |
__func__, cmd.cmd_op, cmd.type, ahw->pci_func, |
| 332 |
ahw->op_mode); |
| 333 |
return err; |
| 334 |
} |
| 335 |
|
| 336 |
if (!wait_for_completion_timeout(&cmd.completion, timeout)) { |
| 337 |
dev_err(&adapter->pdev->dev, |
| 338 |
"%s: Mailbox command timed out, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n", |
| 339 |
__func__, cmd.cmd_op, cmd.type, ahw->pci_func, |
| 340 |
ahw->op_mode); |
| 341 |
flush_workqueue(mbx->work_q); |
| 342 |
} |
| 343 |
|
| 344 |
return cmd.rsp_opcode; |
| 345 |
} |
| 346 |
|
| 347 |
static void qlcnic_sriov_vf_cfg_buff_desc(struct qlcnic_adapter *adapter) |
| 348 |
{ |
| 349 |
adapter->num_rxd = QLC_DEFAULT_RCV_DESCRIPTORS_SRIOV_VF; |
| 350 |
adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; |
| 351 |
adapter->num_jumbo_rxd = QLC_DEFAULT_JUMBO_RCV_DESCRIPTORS_SRIOV_VF; |
| 352 |
adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
| 353 |
adapter->num_txd = MAX_CMD_DESCRIPTORS; |
| 354 |
adapter->max_rds_rings = MAX_RDS_RINGS; |
| 355 |
} |
| 356 |
|
| 357 |
int qlcnic_sriov_get_vf_vport_info(struct qlcnic_adapter *adapter, |
| 358 |
struct qlcnic_info *npar_info, u16 vport_id) |
| 359 |
{ |
| 360 |
struct device *dev = &adapter->pdev->dev; |
| 361 |
struct qlcnic_cmd_args cmd; |
| 362 |
int err; |
| 363 |
u32 status; |
| 364 |
|
| 365 |
err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_GET_NIC_INFO); |
| 366 |
if (err) |
| 367 |
return err; |
| 368 |
|
| 369 |
cmd.req.arg[1] = vport_id << 16 | 0x1; |
| 370 |
err = qlcnic_issue_cmd(adapter, &cmd); |
| 371 |
if (err) { |
| 372 |
dev_err(&adapter->pdev->dev, |
| 373 |
"Failed to get vport info, err=%d\n", err); |
| 374 |
qlcnic_free_mbx_args(&cmd); |
| 375 |
return err; |
| 376 |
} |
| 377 |
|
| 378 |
status = cmd.rsp.arg[2] & 0xffff; |
| 379 |
if (status & BIT_0) |
| 380 |
npar_info->min_tx_bw = MSW(cmd.rsp.arg[2]); |
| 381 |
if (status & BIT_1) |
| 382 |
npar_info->max_tx_bw = LSW(cmd.rsp.arg[3]); |
| 383 |
if (status & BIT_2) |
| 384 |
npar_info->max_tx_ques = MSW(cmd.rsp.arg[3]); |
| 385 |
if (status & BIT_3) |
| 386 |
npar_info->max_tx_mac_filters = LSW(cmd.rsp.arg[4]); |
| 387 |
if (status & BIT_4) |
| 388 |
npar_info->max_rx_mcast_mac_filters = MSW(cmd.rsp.arg[4]); |
| 389 |
if (status & BIT_5) |
| 390 |
npar_info->max_rx_ucast_mac_filters = LSW(cmd.rsp.arg[5]); |
| 391 |
if (status & BIT_6) |
| 392 |
npar_info->max_rx_ip_addr = MSW(cmd.rsp.arg[5]); |
| 393 |
if (status & BIT_7) |
| 394 |
npar_info->max_rx_lro_flow = LSW(cmd.rsp.arg[6]); |
| 395 |
if (status & BIT_8) |
| 396 |
npar_info->max_rx_status_rings = MSW(cmd.rsp.arg[6]); |
| 397 |
if (status & BIT_9) |
| 398 |
npar_info->max_rx_buf_rings = LSW(cmd.rsp.arg[7]); |
| 399 |
|
| 400 |
npar_info->max_rx_ques = MSW(cmd.rsp.arg[7]); |
| 401 |
npar_info->max_tx_vlan_keys = LSW(cmd.rsp.arg[8]); |
| 402 |
npar_info->max_local_ipv6_addrs = MSW(cmd.rsp.arg[8]); |
| 403 |
npar_info->max_remote_ipv6_addrs = LSW(cmd.rsp.arg[9]); |
| 404 |
|
| 405 |
dev_info(dev, "\n\tmin_tx_bw: %d, max_tx_bw: %d max_tx_ques: %d,\n" |
| 406 |
"\tmax_tx_mac_filters: %d max_rx_mcast_mac_filters: %d,\n" |
| 407 |
"\tmax_rx_ucast_mac_filters: 0x%x, max_rx_ip_addr: %d,\n" |
| 408 |
"\tmax_rx_lro_flow: %d max_rx_status_rings: %d,\n" |
| 409 |
"\tmax_rx_buf_rings: %d, max_rx_ques: %d, max_tx_vlan_keys %d\n" |
| 410 |
"\tlocal_ipv6_addr: %d, remote_ipv6_addr: %d\n", |
| 411 |
npar_info->min_tx_bw, npar_info->max_tx_bw, |
| 412 |
npar_info->max_tx_ques, npar_info->max_tx_mac_filters, |
| 413 |
npar_info->max_rx_mcast_mac_filters, |
| 414 |
npar_info->max_rx_ucast_mac_filters, npar_info->max_rx_ip_addr, |
| 415 |
npar_info->max_rx_lro_flow, npar_info->max_rx_status_rings, |
| 416 |
npar_info->max_rx_buf_rings, npar_info->max_rx_ques, |
| 417 |
npar_info->max_tx_vlan_keys, npar_info->max_local_ipv6_addrs, |
| 418 |
npar_info->max_remote_ipv6_addrs); |
| 419 |
|
| 420 |
qlcnic_free_mbx_args(&cmd); |
| 421 |
return err; |
| 422 |
} |
| 423 |
|
| 424 |
static int qlcnic_sriov_set_pvid_mode(struct qlcnic_adapter *adapter, |
| 425 |
struct qlcnic_cmd_args *cmd) |
| 426 |
{ |
| 427 |
adapter->rx_pvid = MSW(cmd->rsp.arg[1]) & 0xffff; |
| 428 |
adapter->flags &= ~QLCNIC_TAGGING_ENABLED; |
| 429 |
return 0; |
| 430 |
} |
| 431 |
|
| 432 |
static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter, |
| 433 |
struct qlcnic_cmd_args *cmd) |
| 434 |
{ |
| 435 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 436 |
int i, num_vlans, ret; |
| 437 |
u16 *vlans; |
| 438 |
|
| 439 |
if (sriov->allowed_vlans) |
| 440 |
return 0; |
| 441 |
|
| 442 |
sriov->any_vlan = cmd->rsp.arg[2] & 0xf; |
| 443 |
sriov->num_allowed_vlans = cmd->rsp.arg[2] >> 16; |
| 444 |
dev_info(&adapter->pdev->dev, "Number of allowed Guest VLANs = %d\n", |
| 445 |
sriov->num_allowed_vlans); |
| 446 |
|
| 447 |
ret = qlcnic_sriov_alloc_vlans(adapter); |
| 448 |
if (ret) |
| 449 |
return ret; |
| 450 |
|
| 451 |
if (!sriov->any_vlan) |
| 452 |
return 0; |
| 453 |
|
| 454 |
num_vlans = sriov->num_allowed_vlans; |
| 455 |
sriov->allowed_vlans = kcalloc(num_vlans, sizeof(u16), GFP_KERNEL); |
| 456 |
if (!sriov->allowed_vlans) { |
| 457 |
qlcnic_sriov_free_vlans(adapter); |
| 458 |
return -ENOMEM; |
| 459 |
} |
| 460 |
|
| 461 |
vlans = (u16 *)&cmd->rsp.arg[3]; |
| 462 |
for (i = 0; i < num_vlans; i++) |
| 463 |
sriov->allowed_vlans[i] = vlans[i]; |
| 464 |
|
| 465 |
return 0; |
| 466 |
} |
| 467 |
|
| 468 |
static int qlcnic_sriov_get_vf_acl(struct qlcnic_adapter *adapter) |
| 469 |
{ |
| 470 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 471 |
struct qlcnic_cmd_args cmd; |
| 472 |
int ret = 0; |
| 473 |
|
| 474 |
memset(&cmd, 0, sizeof(cmd)); |
| 475 |
ret = qlcnic_sriov_alloc_bc_mbx_args(&cmd, QLCNIC_BC_CMD_GET_ACL); |
| 476 |
if (ret) |
| 477 |
return ret; |
| 478 |
|
| 479 |
ret = qlcnic_issue_cmd(adapter, &cmd); |
| 480 |
if (ret) { |
| 481 |
dev_err(&adapter->pdev->dev, "Failed to get ACL, err=%d\n", |
| 482 |
ret); |
| 483 |
} else { |
| 484 |
sriov->vlan_mode = cmd.rsp.arg[1] & 0x3; |
| 485 |
switch (sriov->vlan_mode) { |
| 486 |
case QLC_GUEST_VLAN_MODE: |
| 487 |
ret = qlcnic_sriov_set_guest_vlan_mode(adapter, &cmd); |
| 488 |
break; |
| 489 |
case QLC_PVID_MODE: |
| 490 |
ret = qlcnic_sriov_set_pvid_mode(adapter, &cmd); |
| 491 |
break; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
qlcnic_free_mbx_args(&cmd); |
| 496 |
return ret; |
| 497 |
} |
| 498 |
|
| 499 |
static int qlcnic_sriov_vf_init_driver(struct qlcnic_adapter *adapter) |
| 500 |
{ |
| 501 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 502 |
struct qlcnic_info nic_info; |
| 503 |
int err; |
| 504 |
|
| 505 |
err = qlcnic_sriov_get_vf_vport_info(adapter, &nic_info, 0); |
| 506 |
if (err) |
| 507 |
return err; |
| 508 |
|
| 509 |
ahw->max_mc_count = nic_info.max_rx_mcast_mac_filters; |
| 510 |
|
| 511 |
err = qlcnic_get_nic_info(adapter, &nic_info, ahw->pci_func); |
| 512 |
if (err) |
| 513 |
return -EIO; |
| 514 |
|
| 515 |
if (qlcnic_83xx_get_port_info(adapter)) |
| 516 |
return -EIO; |
| 517 |
|
| 518 |
qlcnic_sriov_vf_cfg_buff_desc(adapter); |
| 519 |
adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; |
| 520 |
dev_info(&adapter->pdev->dev, "HAL Version: %d\n", |
| 521 |
adapter->ahw->fw_hal_version); |
| 522 |
|
| 523 |
ahw->physical_port = (u8) nic_info.phys_port; |
| 524 |
ahw->switch_mode = nic_info.switch_mode; |
| 525 |
ahw->max_mtu = nic_info.max_mtu; |
| 526 |
ahw->op_mode = nic_info.op_mode; |
| 527 |
ahw->capabilities = nic_info.capabilities; |
| 528 |
return 0; |
| 529 |
} |
| 530 |
|
| 531 |
static int qlcnic_sriov_setup_vf(struct qlcnic_adapter *adapter) |
| 532 |
{ |
| 533 |
int err; |
| 534 |
|
| 535 |
adapter->flags |= QLCNIC_VLAN_FILTERING; |
| 536 |
adapter->ahw->total_nic_func = 1; |
| 537 |
INIT_LIST_HEAD(&adapter->vf_mc_list); |
| 538 |
if (!qlcnic_use_msi_x && !!qlcnic_use_msi) |
| 539 |
dev_warn(&adapter->pdev->dev, |
| 540 |
"Device does not support MSI interrupts\n"); |
| 541 |
|
| 542 |
/* compute and set default and max tx/sds rings */ |
| 543 |
qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING); |
| 544 |
qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING); |
| 545 |
|
| 546 |
err = qlcnic_setup_intr(adapter); |
| 547 |
if (err) { |
| 548 |
dev_err(&adapter->pdev->dev, "Failed to setup interrupt\n"); |
| 549 |
goto err_out_disable_msi; |
| 550 |
} |
| 551 |
|
| 552 |
err = qlcnic_83xx_setup_mbx_intr(adapter); |
| 553 |
if (err) |
| 554 |
goto err_out_disable_msi; |
| 555 |
|
| 556 |
err = qlcnic_sriov_init(adapter, 1); |
| 557 |
if (err) |
| 558 |
goto err_out_disable_mbx_intr; |
| 559 |
|
| 560 |
err = qlcnic_sriov_cfg_bc_intr(adapter, 1); |
| 561 |
if (err) |
| 562 |
goto err_out_cleanup_sriov; |
| 563 |
|
| 564 |
err = qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_INIT); |
| 565 |
if (err) |
| 566 |
goto err_out_disable_bc_intr; |
| 567 |
|
| 568 |
err = qlcnic_sriov_vf_init_driver(adapter); |
| 569 |
if (err) |
| 570 |
goto err_out_send_channel_term; |
| 571 |
|
| 572 |
err = qlcnic_sriov_get_vf_acl(adapter); |
| 573 |
if (err) |
| 574 |
goto err_out_send_channel_term; |
| 575 |
|
| 576 |
err = qlcnic_setup_netdev(adapter, adapter->netdev); |
| 577 |
if (err) |
| 578 |
goto err_out_send_channel_term; |
| 579 |
|
| 580 |
pci_set_drvdata(adapter->pdev, adapter); |
| 581 |
dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 582 |
adapter->netdev->name); |
| 583 |
|
| 584 |
qlcnic_schedule_work(adapter, qlcnic_sriov_vf_poll_dev_state, |
| 585 |
adapter->ahw->idc.delay); |
| 586 |
return 0; |
| 587 |
|
| 588 |
err_out_send_channel_term: |
| 589 |
qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_TERM); |
| 590 |
|
| 591 |
err_out_disable_bc_intr: |
| 592 |
qlcnic_sriov_cfg_bc_intr(adapter, 0); |
| 593 |
|
| 594 |
err_out_cleanup_sriov: |
| 595 |
__qlcnic_sriov_cleanup(adapter); |
| 596 |
|
| 597 |
err_out_disable_mbx_intr: |
| 598 |
qlcnic_83xx_free_mbx_intr(adapter); |
| 599 |
|
| 600 |
err_out_disable_msi: |
| 601 |
qlcnic_teardown_intr(adapter); |
| 602 |
return err; |
| 603 |
} |
| 604 |
|
| 605 |
static int qlcnic_sriov_check_dev_ready(struct qlcnic_adapter *adapter) |
| 606 |
{ |
| 607 |
u32 state; |
| 608 |
|
| 609 |
do { |
| 610 |
msleep(20); |
| 611 |
if (++adapter->fw_fail_cnt > QLC_BC_CMD_MAX_RETRY_CNT) |
| 612 |
return -EIO; |
| 613 |
state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE); |
| 614 |
} while (state != QLC_83XX_IDC_DEV_READY); |
| 615 |
|
| 616 |
return 0; |
| 617 |
} |
| 618 |
|
| 619 |
int qlcnic_sriov_vf_init(struct qlcnic_adapter *adapter) |
| 620 |
{ |
| 621 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 622 |
int err; |
| 623 |
|
| 624 |
set_bit(QLC_83XX_MODULE_LOADED, &ahw->idc.status); |
| 625 |
ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY; |
| 626 |
ahw->reset_context = 0; |
| 627 |
adapter->fw_fail_cnt = 0; |
| 628 |
ahw->msix_supported = 1; |
| 629 |
adapter->need_fw_reset = 0; |
| 630 |
adapter->flags |= QLCNIC_TX_INTR_SHARED; |
| 631 |
|
| 632 |
err = qlcnic_sriov_check_dev_ready(adapter); |
| 633 |
if (err) |
| 634 |
return err; |
| 635 |
|
| 636 |
err = qlcnic_sriov_setup_vf(adapter); |
| 637 |
if (err) |
| 638 |
return err; |
| 639 |
|
| 640 |
if (qlcnic_read_mac_addr(adapter)) |
| 641 |
dev_warn(&adapter->pdev->dev, "failed to read mac addr\n"); |
| 642 |
|
| 643 |
INIT_DELAYED_WORK(&adapter->idc_aen_work, qlcnic_83xx_idc_aen_work); |
| 644 |
|
| 645 |
clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 646 |
return 0; |
| 647 |
} |
| 648 |
|
| 649 |
void qlcnic_sriov_vf_set_ops(struct qlcnic_adapter *adapter) |
| 650 |
{ |
| 651 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 652 |
|
| 653 |
ahw->op_mode = QLCNIC_SRIOV_VF_FUNC; |
| 654 |
dev_info(&adapter->pdev->dev, |
| 655 |
"HAL Version: %d Non Privileged SRIOV function\n", |
| 656 |
ahw->fw_hal_version); |
| 657 |
adapter->nic_ops = &qlcnic_sriov_vf_ops; |
| 658 |
set_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state); |
| 659 |
return; |
| 660 |
} |
| 661 |
|
| 662 |
void qlcnic_sriov_vf_register_map(struct qlcnic_hardware_context *ahw) |
| 663 |
{ |
| 664 |
ahw->hw_ops = &qlcnic_sriov_vf_hw_ops; |
| 665 |
ahw->reg_tbl = (u32 *)qlcnic_83xx_reg_tbl; |
| 666 |
ahw->ext_reg_tbl = (u32 *)qlcnic_83xx_ext_reg_tbl; |
| 667 |
} |
| 668 |
|
| 669 |
static u32 qlcnic_sriov_get_bc_paysize(u32 real_pay_size, u8 curr_frag) |
| 670 |
{ |
| 671 |
u32 pay_size; |
| 672 |
|
| 673 |
pay_size = real_pay_size / ((curr_frag + 1) * QLC_BC_PAYLOAD_SZ); |
| 674 |
|
| 675 |
if (pay_size) |
| 676 |
pay_size = QLC_BC_PAYLOAD_SZ; |
| 677 |
else |
| 678 |
pay_size = real_pay_size % QLC_BC_PAYLOAD_SZ; |
| 679 |
|
| 680 |
return pay_size; |
| 681 |
} |
| 682 |
|
| 683 |
int qlcnic_sriov_func_to_index(struct qlcnic_adapter *adapter, u8 pci_func) |
| 684 |
{ |
| 685 |
struct qlcnic_vf_info *vf_info = adapter->ahw->sriov->vf_info; |
| 686 |
u8 i; |
| 687 |
|
| 688 |
if (qlcnic_sriov_vf_check(adapter)) |
| 689 |
return 0; |
| 690 |
|
| 691 |
for (i = 0; i < adapter->ahw->sriov->num_vfs; i++) { |
| 692 |
if (vf_info[i].pci_func == pci_func) |
| 693 |
return i; |
| 694 |
} |
| 695 |
|
| 696 |
return -EINVAL; |
| 697 |
} |
| 698 |
|
| 699 |
static inline int qlcnic_sriov_alloc_bc_trans(struct qlcnic_bc_trans **trans) |
| 700 |
{ |
| 701 |
*trans = kzalloc_obj(struct qlcnic_bc_trans, GFP_ATOMIC); |
| 702 |
if (!*trans) |
| 703 |
return -ENOMEM; |
| 704 |
|
| 705 |
init_completion(&(*trans)->resp_cmpl); |
| 706 |
return 0; |
| 707 |
} |
| 708 |
|
| 709 |
static inline int qlcnic_sriov_alloc_bc_msg(struct qlcnic_bc_hdr **hdr, |
| 710 |
u32 size) |
| 711 |
{ |
| 712 |
*hdr = kzalloc_objs(struct qlcnic_bc_hdr, size, GFP_ATOMIC); |
| 713 |
if (!*hdr) |
| 714 |
return -ENOMEM; |
| 715 |
|
| 716 |
return 0; |
| 717 |
} |
| 718 |
|
| 719 |
static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *mbx, u32 type) |
| 720 |
{ |
| 721 |
const struct qlcnic_mailbox_metadata *mbx_tbl; |
| 722 |
int i, size; |
| 723 |
|
| 724 |
mbx_tbl = qlcnic_sriov_bc_mbx_tbl; |
| 725 |
size = ARRAY_SIZE(qlcnic_sriov_bc_mbx_tbl); |
| 726 |
|
| 727 |
for (i = 0; i < size; i++) { |
| 728 |
if (type == mbx_tbl[i].cmd) { |
| 729 |
mbx->op_type = QLC_BC_CMD; |
| 730 |
mbx->req.num = mbx_tbl[i].in_args; |
| 731 |
mbx->rsp.num = mbx_tbl[i].out_args; |
| 732 |
mbx->req.arg = kcalloc(mbx->req.num, sizeof(u32), |
| 733 |
GFP_ATOMIC); |
| 734 |
if (!mbx->req.arg) |
| 735 |
return -ENOMEM; |
| 736 |
mbx->rsp.arg = kcalloc(mbx->rsp.num, sizeof(u32), |
| 737 |
GFP_ATOMIC); |
| 738 |
if (!mbx->rsp.arg) { |
| 739 |
kfree(mbx->req.arg); |
| 740 |
mbx->req.arg = NULL; |
| 741 |
return -ENOMEM; |
| 742 |
} |
| 743 |
mbx->req.arg[0] = (type | (mbx->req.num << 16) | |
| 744 |
(3 << 29)); |
| 745 |
mbx->rsp.arg[0] = (type & 0xffff) | mbx->rsp.num << 16; |
| 746 |
return 0; |
| 747 |
} |
| 748 |
} |
| 749 |
return -EINVAL; |
| 750 |
} |
| 751 |
|
| 752 |
static int qlcnic_sriov_prepare_bc_hdr(struct qlcnic_bc_trans *trans, |
| 753 |
struct qlcnic_cmd_args *cmd, |
| 754 |
u16 seq, u8 msg_type) |
| 755 |
{ |
| 756 |
struct qlcnic_bc_hdr *hdr; |
| 757 |
int i; |
| 758 |
u32 num_regs, bc_pay_sz; |
| 759 |
u16 remainder; |
| 760 |
u8 cmd_op, num_frags, t_num_frags; |
| 761 |
|
| 762 |
bc_pay_sz = QLC_BC_PAYLOAD_SZ; |
| 763 |
if (msg_type == QLC_BC_COMMAND) { |
| 764 |
trans->req_pay = (struct qlcnic_bc_payload *)cmd->req.arg; |
| 765 |
trans->rsp_pay = (struct qlcnic_bc_payload *)cmd->rsp.arg; |
| 766 |
num_regs = cmd->req.num; |
| 767 |
trans->req_pay_size = (num_regs * 4); |
| 768 |
num_regs = cmd->rsp.num; |
| 769 |
trans->rsp_pay_size = (num_regs * 4); |
| 770 |
cmd_op = cmd->req.arg[0] & 0xff; |
| 771 |
remainder = (trans->req_pay_size) % (bc_pay_sz); |
| 772 |
num_frags = (trans->req_pay_size) / (bc_pay_sz); |
| 773 |
if (remainder) |
| 774 |
num_frags++; |
| 775 |
t_num_frags = num_frags; |
| 776 |
if (qlcnic_sriov_alloc_bc_msg(&trans->req_hdr, num_frags)) |
| 777 |
return -ENOMEM; |
| 778 |
remainder = (trans->rsp_pay_size) % (bc_pay_sz); |
| 779 |
num_frags = (trans->rsp_pay_size) / (bc_pay_sz); |
| 780 |
if (remainder) |
| 781 |
num_frags++; |
| 782 |
if (qlcnic_sriov_alloc_bc_msg(&trans->rsp_hdr, num_frags)) |
| 783 |
return -ENOMEM; |
| 784 |
num_frags = t_num_frags; |
| 785 |
hdr = trans->req_hdr; |
| 786 |
} else { |
| 787 |
cmd->req.arg = (u32 *)trans->req_pay; |
| 788 |
cmd->rsp.arg = (u32 *)trans->rsp_pay; |
| 789 |
cmd_op = cmd->req.arg[0] & 0xff; |
| 790 |
cmd->cmd_op = cmd_op; |
| 791 |
remainder = (trans->rsp_pay_size) % (bc_pay_sz); |
| 792 |
num_frags = (trans->rsp_pay_size) / (bc_pay_sz); |
| 793 |
if (remainder) |
| 794 |
num_frags++; |
| 795 |
cmd->req.num = trans->req_pay_size / 4; |
| 796 |
cmd->rsp.num = trans->rsp_pay_size / 4; |
| 797 |
hdr = trans->rsp_hdr; |
| 798 |
cmd->op_type = trans->req_hdr->op_type; |
| 799 |
} |
| 800 |
|
| 801 |
trans->trans_id = seq; |
| 802 |
trans->cmd_id = cmd_op; |
| 803 |
for (i = 0; i < num_frags; i++) { |
| 804 |
hdr[i].version = 2; |
| 805 |
hdr[i].msg_type = msg_type; |
| 806 |
hdr[i].op_type = cmd->op_type; |
| 807 |
hdr[i].num_cmds = 1; |
| 808 |
hdr[i].num_frags = num_frags; |
| 809 |
hdr[i].frag_num = i + 1; |
| 810 |
hdr[i].cmd_op = cmd_op; |
| 811 |
hdr[i].seq_id = seq; |
| 812 |
} |
| 813 |
return 0; |
| 814 |
} |
| 815 |
|
| 816 |
static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans *trans) |
| 817 |
{ |
| 818 |
if (!trans) |
| 819 |
return; |
| 820 |
kfree(trans->req_hdr); |
| 821 |
kfree(trans->rsp_hdr); |
| 822 |
kfree(trans); |
| 823 |
} |
| 824 |
|
| 825 |
static int qlcnic_sriov_clear_trans(struct qlcnic_vf_info *vf, |
| 826 |
struct qlcnic_bc_trans *trans, u8 type) |
| 827 |
{ |
| 828 |
struct qlcnic_trans_list *t_list; |
| 829 |
unsigned long flags; |
| 830 |
int ret = 0; |
| 831 |
|
| 832 |
if (type == QLC_BC_RESPONSE) { |
| 833 |
t_list = &vf->rcv_act; |
| 834 |
spin_lock_irqsave(&t_list->lock, flags); |
| 835 |
t_list->count--; |
| 836 |
list_del(&trans->list); |
| 837 |
if (t_list->count > 0) |
| 838 |
ret = 1; |
| 839 |
spin_unlock_irqrestore(&t_list->lock, flags); |
| 840 |
} |
| 841 |
if (type == QLC_BC_COMMAND) { |
| 842 |
while (test_and_set_bit(QLC_BC_VF_SEND, &vf->state)) |
| 843 |
msleep(100); |
| 844 |
vf->send_cmd = NULL; |
| 845 |
clear_bit(QLC_BC_VF_SEND, &vf->state); |
| 846 |
} |
| 847 |
return ret; |
| 848 |
} |
| 849 |
|
| 850 |
static void qlcnic_sriov_schedule_bc_cmd(struct qlcnic_sriov *sriov, |
| 851 |
struct qlcnic_vf_info *vf, |
| 852 |
work_func_t func) |
| 853 |
{ |
| 854 |
if (test_bit(QLC_BC_VF_FLR, &vf->state) || |
| 855 |
vf->adapter->need_fw_reset) |
| 856 |
return; |
| 857 |
|
| 858 |
queue_work(sriov->bc.bc_trans_wq, &vf->trans_work); |
| 859 |
} |
| 860 |
|
| 861 |
static inline void qlcnic_sriov_wait_for_resp(struct qlcnic_bc_trans *trans) |
| 862 |
{ |
| 863 |
struct completion *cmpl = &trans->resp_cmpl; |
| 864 |
|
| 865 |
if (wait_for_completion_timeout(cmpl, QLC_MBOX_RESP_TIMEOUT)) |
| 866 |
trans->trans_state = QLC_END; |
| 867 |
else |
| 868 |
trans->trans_state = QLC_ABORT; |
| 869 |
|
| 870 |
return; |
| 871 |
} |
| 872 |
|
| 873 |
static void qlcnic_sriov_handle_multi_frags(struct qlcnic_bc_trans *trans, |
| 874 |
u8 type) |
| 875 |
{ |
| 876 |
if (type == QLC_BC_RESPONSE) { |
| 877 |
trans->curr_rsp_frag++; |
| 878 |
if (trans->curr_rsp_frag < trans->rsp_hdr->num_frags) |
| 879 |
trans->trans_state = QLC_INIT; |
| 880 |
else |
| 881 |
trans->trans_state = QLC_END; |
| 882 |
} else { |
| 883 |
trans->curr_req_frag++; |
| 884 |
if (trans->curr_req_frag < trans->req_hdr->num_frags) |
| 885 |
trans->trans_state = QLC_INIT; |
| 886 |
else |
| 887 |
trans->trans_state = QLC_WAIT_FOR_RESP; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
static void qlcnic_sriov_wait_for_channel_free(struct qlcnic_bc_trans *trans, |
| 892 |
u8 type) |
| 893 |
{ |
| 894 |
struct qlcnic_vf_info *vf = trans->vf; |
| 895 |
struct completion *cmpl = &vf->ch_free_cmpl; |
| 896 |
|
| 897 |
if (!wait_for_completion_timeout(cmpl, QLC_MBOX_CH_FREE_TIMEOUT)) { |
| 898 |
trans->trans_state = QLC_ABORT; |
| 899 |
return; |
| 900 |
} |
| 901 |
|
| 902 |
clear_bit(QLC_BC_VF_CHANNEL, &vf->state); |
| 903 |
qlcnic_sriov_handle_multi_frags(trans, type); |
| 904 |
} |
| 905 |
|
| 906 |
static void qlcnic_sriov_pull_bc_msg(struct qlcnic_adapter *adapter, |
| 907 |
u32 *hdr, u32 *pay, u32 size) |
| 908 |
{ |
| 909 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 910 |
u8 i, max = 2, hdr_size, j; |
| 911 |
|
| 912 |
hdr_size = (sizeof(struct qlcnic_bc_hdr) / sizeof(u32)); |
| 913 |
max = (size / sizeof(u32)) + hdr_size; |
| 914 |
|
| 915 |
for (i = 2, j = 0; j < hdr_size; i++, j++) |
| 916 |
*(hdr++) = readl(QLCNIC_MBX_FW(ahw, i)); |
| 917 |
for (; j < max; i++, j++) |
| 918 |
*(pay++) = readl(QLCNIC_MBX_FW(ahw, i)); |
| 919 |
} |
| 920 |
|
| 921 |
static int __qlcnic_sriov_issue_bc_post(struct qlcnic_vf_info *vf) |
| 922 |
{ |
| 923 |
int ret = -EBUSY; |
| 924 |
u32 timeout = 10000; |
| 925 |
|
| 926 |
do { |
| 927 |
if (!test_and_set_bit(QLC_BC_VF_CHANNEL, &vf->state)) { |
| 928 |
ret = 0; |
| 929 |
break; |
| 930 |
} |
| 931 |
mdelay(1); |
| 932 |
} while (--timeout); |
| 933 |
|
| 934 |
return ret; |
| 935 |
} |
| 936 |
|
| 937 |
static int qlcnic_sriov_issue_bc_post(struct qlcnic_bc_trans *trans, u8 type) |
| 938 |
{ |
| 939 |
struct qlcnic_vf_info *vf = trans->vf; |
| 940 |
u32 pay_size; |
| 941 |
u32 *hdr, *pay; |
| 942 |
int ret; |
| 943 |
u8 pci_func = trans->func_id; |
| 944 |
|
| 945 |
if (__qlcnic_sriov_issue_bc_post(vf)) |
| 946 |
return -EBUSY; |
| 947 |
|
| 948 |
if (type == QLC_BC_COMMAND) { |
| 949 |
hdr = (u32 *)(trans->req_hdr + trans->curr_req_frag); |
| 950 |
pay = (u32 *)(trans->req_pay + trans->curr_req_frag); |
| 951 |
pay_size = qlcnic_sriov_get_bc_paysize(trans->req_pay_size, |
| 952 |
trans->curr_req_frag); |
| 953 |
pay_size = (pay_size / sizeof(u32)); |
| 954 |
} else { |
| 955 |
hdr = (u32 *)(trans->rsp_hdr + trans->curr_rsp_frag); |
| 956 |
pay = (u32 *)(trans->rsp_pay + trans->curr_rsp_frag); |
| 957 |
pay_size = qlcnic_sriov_get_bc_paysize(trans->rsp_pay_size, |
| 958 |
trans->curr_rsp_frag); |
| 959 |
pay_size = (pay_size / sizeof(u32)); |
| 960 |
} |
| 961 |
|
| 962 |
ret = qlcnic_sriov_post_bc_msg(vf->adapter, hdr, pay, |
| 963 |
pci_func, pay_size); |
| 964 |
return ret; |
| 965 |
} |
| 966 |
|
| 967 |
static int __qlcnic_sriov_send_bc_msg(struct qlcnic_bc_trans *trans, |
| 968 |
struct qlcnic_vf_info *vf, u8 type) |
| 969 |
{ |
| 970 |
bool flag = true; |
| 971 |
int err = -EIO; |
| 972 |
|
| 973 |
while (flag) { |
| 974 |
if (test_bit(QLC_BC_VF_FLR, &vf->state) || |
| 975 |
vf->adapter->need_fw_reset) |
| 976 |
trans->trans_state = QLC_ABORT; |
| 977 |
|
| 978 |
switch (trans->trans_state) { |
| 979 |
case QLC_INIT: |
| 980 |
trans->trans_state = QLC_WAIT_FOR_CHANNEL_FREE; |
| 981 |
if (qlcnic_sriov_issue_bc_post(trans, type)) |
| 982 |
trans->trans_state = QLC_ABORT; |
| 983 |
break; |
| 984 |
case QLC_WAIT_FOR_CHANNEL_FREE: |
| 985 |
qlcnic_sriov_wait_for_channel_free(trans, type); |
| 986 |
break; |
| 987 |
case QLC_WAIT_FOR_RESP: |
| 988 |
qlcnic_sriov_wait_for_resp(trans); |
| 989 |
break; |
| 990 |
case QLC_END: |
| 991 |
err = 0; |
| 992 |
flag = false; |
| 993 |
break; |
| 994 |
case QLC_ABORT: |
| 995 |
err = -EIO; |
| 996 |
flag = false; |
| 997 |
clear_bit(QLC_BC_VF_CHANNEL, &vf->state); |
| 998 |
break; |
| 999 |
default: |
| 1000 |
err = -EIO; |
| 1001 |
flag = false; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
return err; |
| 1005 |
} |
| 1006 |
|
| 1007 |
static int qlcnic_sriov_send_bc_cmd(struct qlcnic_adapter *adapter, |
| 1008 |
struct qlcnic_bc_trans *trans, int pci_func) |
| 1009 |
{ |
| 1010 |
struct qlcnic_vf_info *vf; |
| 1011 |
int err, index = qlcnic_sriov_func_to_index(adapter, pci_func); |
| 1012 |
|
| 1013 |
if (index < 0) |
| 1014 |
return -EIO; |
| 1015 |
|
| 1016 |
vf = &adapter->ahw->sriov->vf_info[index]; |
| 1017 |
trans->vf = vf; |
| 1018 |
trans->func_id = pci_func; |
| 1019 |
|
| 1020 |
if (!test_bit(QLC_BC_VF_STATE, &vf->state)) { |
| 1021 |
if (qlcnic_sriov_pf_check(adapter)) |
| 1022 |
return -EIO; |
| 1023 |
if (qlcnic_sriov_vf_check(adapter) && |
| 1024 |
trans->cmd_id != QLCNIC_BC_CMD_CHANNEL_INIT) |
| 1025 |
return -EIO; |
| 1026 |
} |
| 1027 |
|
| 1028 |
mutex_lock(&vf->send_cmd_lock); |
| 1029 |
vf->send_cmd = trans; |
| 1030 |
err = __qlcnic_sriov_send_bc_msg(trans, vf, QLC_BC_COMMAND); |
| 1031 |
qlcnic_sriov_clear_trans(vf, trans, QLC_BC_COMMAND); |
| 1032 |
mutex_unlock(&vf->send_cmd_lock); |
| 1033 |
return err; |
| 1034 |
} |
| 1035 |
|
| 1036 |
static void __qlcnic_sriov_process_bc_cmd(struct qlcnic_adapter *adapter, |
| 1037 |
struct qlcnic_bc_trans *trans, |
| 1038 |
struct qlcnic_cmd_args *cmd) |
| 1039 |
{ |
| 1040 |
#ifdef CONFIG_QLCNIC_SRIOV |
| 1041 |
if (qlcnic_sriov_pf_check(adapter)) { |
| 1042 |
qlcnic_sriov_pf_process_bc_cmd(adapter, trans, cmd); |
| 1043 |
return; |
| 1044 |
} |
| 1045 |
#endif |
| 1046 |
cmd->rsp.arg[0] |= (0x9 << 25); |
| 1047 |
return; |
| 1048 |
} |
| 1049 |
|
| 1050 |
static void qlcnic_sriov_process_bc_cmd(struct work_struct *work) |
| 1051 |
{ |
| 1052 |
struct qlcnic_vf_info *vf = container_of(work, struct qlcnic_vf_info, |
| 1053 |
trans_work); |
| 1054 |
struct qlcnic_bc_trans *trans = NULL; |
| 1055 |
struct qlcnic_adapter *adapter = vf->adapter; |
| 1056 |
struct qlcnic_cmd_args cmd; |
| 1057 |
u8 req; |
| 1058 |
|
| 1059 |
if (adapter->need_fw_reset) |
| 1060 |
return; |
| 1061 |
|
| 1062 |
if (test_bit(QLC_BC_VF_FLR, &vf->state)) |
| 1063 |
return; |
| 1064 |
|
| 1065 |
memset(&cmd, 0, sizeof(struct qlcnic_cmd_args)); |
| 1066 |
trans = list_first_entry(&vf->rcv_act.wait_list, |
| 1067 |
struct qlcnic_bc_trans, list); |
| 1068 |
adapter = vf->adapter; |
| 1069 |
|
| 1070 |
if (qlcnic_sriov_prepare_bc_hdr(trans, &cmd, trans->req_hdr->seq_id, |
| 1071 |
QLC_BC_RESPONSE)) |
| 1072 |
goto cleanup_trans; |
| 1073 |
|
| 1074 |
__qlcnic_sriov_process_bc_cmd(adapter, trans, &cmd); |
| 1075 |
trans->trans_state = QLC_INIT; |
| 1076 |
__qlcnic_sriov_send_bc_msg(trans, vf, QLC_BC_RESPONSE); |
| 1077 |
|
| 1078 |
cleanup_trans: |
| 1079 |
qlcnic_free_mbx_args(&cmd); |
| 1080 |
req = qlcnic_sriov_clear_trans(vf, trans, QLC_BC_RESPONSE); |
| 1081 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1082 |
if (req) |
| 1083 |
qlcnic_sriov_schedule_bc_cmd(adapter->ahw->sriov, vf, |
| 1084 |
qlcnic_sriov_process_bc_cmd); |
| 1085 |
} |
| 1086 |
|
| 1087 |
static void qlcnic_sriov_handle_bc_resp(struct qlcnic_bc_hdr *hdr, |
| 1088 |
struct qlcnic_vf_info *vf) |
| 1089 |
{ |
| 1090 |
struct qlcnic_bc_trans *trans; |
| 1091 |
u32 pay_size; |
| 1092 |
|
| 1093 |
if (test_and_set_bit(QLC_BC_VF_SEND, &vf->state)) |
| 1094 |
return; |
| 1095 |
|
| 1096 |
trans = vf->send_cmd; |
| 1097 |
|
| 1098 |
if (trans == NULL) |
| 1099 |
goto clear_send; |
| 1100 |
|
| 1101 |
if (trans->trans_id != hdr->seq_id) |
| 1102 |
goto clear_send; |
| 1103 |
|
| 1104 |
pay_size = qlcnic_sriov_get_bc_paysize(trans->rsp_pay_size, |
| 1105 |
trans->curr_rsp_frag); |
| 1106 |
qlcnic_sriov_pull_bc_msg(vf->adapter, |
| 1107 |
(u32 *)(trans->rsp_hdr + trans->curr_rsp_frag), |
| 1108 |
(u32 *)(trans->rsp_pay + trans->curr_rsp_frag), |
| 1109 |
pay_size); |
| 1110 |
if (++trans->curr_rsp_frag < trans->rsp_hdr->num_frags) |
| 1111 |
goto clear_send; |
| 1112 |
|
| 1113 |
complete(&trans->resp_cmpl); |
| 1114 |
|
| 1115 |
clear_send: |
| 1116 |
clear_bit(QLC_BC_VF_SEND, &vf->state); |
| 1117 |
} |
| 1118 |
|
| 1119 |
int __qlcnic_sriov_add_act_list(struct qlcnic_sriov *sriov, |
| 1120 |
struct qlcnic_vf_info *vf, |
| 1121 |
struct qlcnic_bc_trans *trans) |
| 1122 |
{ |
| 1123 |
struct qlcnic_trans_list *t_list = &vf->rcv_act; |
| 1124 |
|
| 1125 |
t_list->count++; |
| 1126 |
list_add_tail(&trans->list, &t_list->wait_list); |
| 1127 |
if (t_list->count == 1) |
| 1128 |
qlcnic_sriov_schedule_bc_cmd(sriov, vf, |
| 1129 |
qlcnic_sriov_process_bc_cmd); |
| 1130 |
return 0; |
| 1131 |
} |
| 1132 |
|
| 1133 |
static int qlcnic_sriov_add_act_list(struct qlcnic_sriov *sriov, |
| 1134 |
struct qlcnic_vf_info *vf, |
| 1135 |
struct qlcnic_bc_trans *trans) |
| 1136 |
{ |
| 1137 |
struct qlcnic_trans_list *t_list = &vf->rcv_act; |
| 1138 |
|
| 1139 |
spin_lock(&t_list->lock); |
| 1140 |
|
| 1141 |
__qlcnic_sriov_add_act_list(sriov, vf, trans); |
| 1142 |
|
| 1143 |
spin_unlock(&t_list->lock); |
| 1144 |
return 0; |
| 1145 |
} |
| 1146 |
|
| 1147 |
static void qlcnic_sriov_handle_pending_trans(struct qlcnic_sriov *sriov, |
| 1148 |
struct qlcnic_vf_info *vf, |
| 1149 |
struct qlcnic_bc_hdr *hdr) |
| 1150 |
{ |
| 1151 |
struct qlcnic_bc_trans *trans = NULL; |
| 1152 |
struct list_head *node; |
| 1153 |
u32 pay_size, curr_frag; |
| 1154 |
u8 found = 0, active = 0; |
| 1155 |
|
| 1156 |
spin_lock(&vf->rcv_pend.lock); |
| 1157 |
if (vf->rcv_pend.count > 0) { |
| 1158 |
list_for_each(node, &vf->rcv_pend.wait_list) { |
| 1159 |
trans = list_entry(node, struct qlcnic_bc_trans, list); |
| 1160 |
if (trans->trans_id == hdr->seq_id) { |
| 1161 |
found = 1; |
| 1162 |
break; |
| 1163 |
} |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
if (found) { |
| 1168 |
curr_frag = trans->curr_req_frag; |
| 1169 |
pay_size = qlcnic_sriov_get_bc_paysize(trans->req_pay_size, |
| 1170 |
curr_frag); |
| 1171 |
qlcnic_sriov_pull_bc_msg(vf->adapter, |
| 1172 |
(u32 *)(trans->req_hdr + curr_frag), |
| 1173 |
(u32 *)(trans->req_pay + curr_frag), |
| 1174 |
pay_size); |
| 1175 |
trans->curr_req_frag++; |
| 1176 |
if (trans->curr_req_frag >= hdr->num_frags) { |
| 1177 |
vf->rcv_pend.count--; |
| 1178 |
list_del(&trans->list); |
| 1179 |
active = 1; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
spin_unlock(&vf->rcv_pend.lock); |
| 1183 |
|
| 1184 |
if (active) |
| 1185 |
if (qlcnic_sriov_add_act_list(sriov, vf, trans)) |
| 1186 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1187 |
|
| 1188 |
return; |
| 1189 |
} |
| 1190 |
|
| 1191 |
static void qlcnic_sriov_handle_bc_cmd(struct qlcnic_sriov *sriov, |
| 1192 |
struct qlcnic_bc_hdr *hdr, |
| 1193 |
struct qlcnic_vf_info *vf) |
| 1194 |
{ |
| 1195 |
struct qlcnic_bc_trans *trans; |
| 1196 |
struct qlcnic_adapter *adapter = vf->adapter; |
| 1197 |
struct qlcnic_cmd_args cmd; |
| 1198 |
u32 pay_size; |
| 1199 |
int err; |
| 1200 |
u8 cmd_op; |
| 1201 |
|
| 1202 |
if (adapter->need_fw_reset) |
| 1203 |
return; |
| 1204 |
|
| 1205 |
if (!test_bit(QLC_BC_VF_STATE, &vf->state) && |
| 1206 |
hdr->op_type != QLC_BC_CMD && |
| 1207 |
hdr->cmd_op != QLCNIC_BC_CMD_CHANNEL_INIT) |
| 1208 |
return; |
| 1209 |
|
| 1210 |
if (hdr->frag_num > 1) { |
| 1211 |
qlcnic_sriov_handle_pending_trans(sriov, vf, hdr); |
| 1212 |
return; |
| 1213 |
} |
| 1214 |
|
| 1215 |
memset(&cmd, 0, sizeof(struct qlcnic_cmd_args)); |
| 1216 |
cmd_op = hdr->cmd_op; |
| 1217 |
if (qlcnic_sriov_alloc_bc_trans(&trans)) |
| 1218 |
return; |
| 1219 |
|
| 1220 |
if (hdr->op_type == QLC_BC_CMD) |
| 1221 |
err = qlcnic_sriov_alloc_bc_mbx_args(&cmd, cmd_op); |
| 1222 |
else |
| 1223 |
err = qlcnic_alloc_mbx_args(&cmd, adapter, cmd_op); |
| 1224 |
|
| 1225 |
if (err) { |
| 1226 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1227 |
return; |
| 1228 |
} |
| 1229 |
|
| 1230 |
cmd.op_type = hdr->op_type; |
| 1231 |
if (qlcnic_sriov_prepare_bc_hdr(trans, &cmd, hdr->seq_id, |
| 1232 |
QLC_BC_COMMAND)) { |
| 1233 |
qlcnic_free_mbx_args(&cmd); |
| 1234 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1235 |
return; |
| 1236 |
} |
| 1237 |
|
| 1238 |
pay_size = qlcnic_sriov_get_bc_paysize(trans->req_pay_size, |
| 1239 |
trans->curr_req_frag); |
| 1240 |
qlcnic_sriov_pull_bc_msg(vf->adapter, |
| 1241 |
(u32 *)(trans->req_hdr + trans->curr_req_frag), |
| 1242 |
(u32 *)(trans->req_pay + trans->curr_req_frag), |
| 1243 |
pay_size); |
| 1244 |
trans->func_id = vf->pci_func; |
| 1245 |
trans->vf = vf; |
| 1246 |
trans->trans_id = hdr->seq_id; |
| 1247 |
trans->curr_req_frag++; |
| 1248 |
|
| 1249 |
if (qlcnic_sriov_soft_flr_check(adapter, trans, vf)) |
| 1250 |
return; |
| 1251 |
|
| 1252 |
if (trans->curr_req_frag == trans->req_hdr->num_frags) { |
| 1253 |
if (qlcnic_sriov_add_act_list(sriov, vf, trans)) { |
| 1254 |
qlcnic_free_mbx_args(&cmd); |
| 1255 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1256 |
} |
| 1257 |
} else { |
| 1258 |
spin_lock(&vf->rcv_pend.lock); |
| 1259 |
list_add_tail(&trans->list, &vf->rcv_pend.wait_list); |
| 1260 |
vf->rcv_pend.count++; |
| 1261 |
spin_unlock(&vf->rcv_pend.lock); |
| 1262 |
} |
| 1263 |
} |
| 1264 |
|
| 1265 |
static void qlcnic_sriov_handle_msg_event(struct qlcnic_sriov *sriov, |
| 1266 |
struct qlcnic_vf_info *vf) |
| 1267 |
{ |
| 1268 |
struct qlcnic_bc_hdr hdr; |
| 1269 |
u32 *ptr = (u32 *)&hdr; |
| 1270 |
u8 msg_type, i; |
| 1271 |
|
| 1272 |
for (i = 2; i < 6; i++) |
| 1273 |
ptr[i - 2] = readl(QLCNIC_MBX_FW(vf->adapter->ahw, i)); |
| 1274 |
msg_type = hdr.msg_type; |
| 1275 |
|
| 1276 |
switch (msg_type) { |
| 1277 |
case QLC_BC_COMMAND: |
| 1278 |
qlcnic_sriov_handle_bc_cmd(sriov, &hdr, vf); |
| 1279 |
break; |
| 1280 |
case QLC_BC_RESPONSE: |
| 1281 |
qlcnic_sriov_handle_bc_resp(&hdr, vf); |
| 1282 |
break; |
| 1283 |
} |
| 1284 |
} |
| 1285 |
|
| 1286 |
static void qlcnic_sriov_handle_flr_event(struct qlcnic_sriov *sriov, |
| 1287 |
struct qlcnic_vf_info *vf) |
| 1288 |
{ |
| 1289 |
struct qlcnic_adapter *adapter = vf->adapter; |
| 1290 |
|
| 1291 |
if (qlcnic_sriov_pf_check(adapter)) |
| 1292 |
qlcnic_sriov_pf_handle_flr(sriov, vf); |
| 1293 |
else |
| 1294 |
dev_err(&adapter->pdev->dev, |
| 1295 |
"Invalid event to VF. VF should not get FLR event\n"); |
| 1296 |
} |
| 1297 |
|
| 1298 |
void qlcnic_sriov_handle_bc_event(struct qlcnic_adapter *adapter, u32 event) |
| 1299 |
{ |
| 1300 |
struct qlcnic_vf_info *vf; |
| 1301 |
struct qlcnic_sriov *sriov; |
| 1302 |
int index; |
| 1303 |
u8 pci_func; |
| 1304 |
|
| 1305 |
sriov = adapter->ahw->sriov; |
| 1306 |
pci_func = qlcnic_sriov_target_func_id(event); |
| 1307 |
index = qlcnic_sriov_func_to_index(adapter, pci_func); |
| 1308 |
|
| 1309 |
if (index < 0) |
| 1310 |
return; |
| 1311 |
|
| 1312 |
vf = &sriov->vf_info[index]; |
| 1313 |
vf->pci_func = pci_func; |
| 1314 |
|
| 1315 |
if (qlcnic_sriov_channel_free_check(event)) |
| 1316 |
complete(&vf->ch_free_cmpl); |
| 1317 |
|
| 1318 |
if (qlcnic_sriov_flr_check(event)) { |
| 1319 |
qlcnic_sriov_handle_flr_event(sriov, vf); |
| 1320 |
return; |
| 1321 |
} |
| 1322 |
|
| 1323 |
if (qlcnic_sriov_bc_msg_check(event)) |
| 1324 |
qlcnic_sriov_handle_msg_event(sriov, vf); |
| 1325 |
} |
| 1326 |
|
| 1327 |
int qlcnic_sriov_cfg_bc_intr(struct qlcnic_adapter *adapter, u8 enable) |
| 1328 |
{ |
| 1329 |
struct qlcnic_cmd_args cmd; |
| 1330 |
int err; |
| 1331 |
|
| 1332 |
if (!test_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state)) |
| 1333 |
return 0; |
| 1334 |
|
| 1335 |
if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_BC_EVENT_SETUP)) |
| 1336 |
return -ENOMEM; |
| 1337 |
|
| 1338 |
if (enable) |
| 1339 |
cmd.req.arg[1] = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); |
| 1340 |
|
| 1341 |
err = qlcnic_83xx_issue_cmd(adapter, &cmd); |
| 1342 |
|
| 1343 |
if (err != QLCNIC_RCODE_SUCCESS) { |
| 1344 |
dev_err(&adapter->pdev->dev, |
| 1345 |
"Failed to %s bc events, err=%d\n", |
| 1346 |
(enable ? "enable" : "disable"), err); |
| 1347 |
} |
| 1348 |
|
| 1349 |
qlcnic_free_mbx_args(&cmd); |
| 1350 |
return err; |
| 1351 |
} |
| 1352 |
|
| 1353 |
static int qlcnic_sriov_retry_bc_cmd(struct qlcnic_adapter *adapter, |
| 1354 |
struct qlcnic_bc_trans *trans) |
| 1355 |
{ |
| 1356 |
u8 max = QLC_BC_CMD_MAX_RETRY_CNT; |
| 1357 |
u32 state; |
| 1358 |
|
| 1359 |
state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE); |
| 1360 |
if (state == QLC_83XX_IDC_DEV_READY) { |
| 1361 |
msleep(20); |
| 1362 |
clear_bit(QLC_BC_VF_CHANNEL, &trans->vf->state); |
| 1363 |
trans->trans_state = QLC_INIT; |
| 1364 |
if (++adapter->fw_fail_cnt > max) |
| 1365 |
return -EIO; |
| 1366 |
else |
| 1367 |
return 0; |
| 1368 |
} |
| 1369 |
|
| 1370 |
return -EIO; |
| 1371 |
} |
| 1372 |
|
| 1373 |
static int __qlcnic_sriov_issue_cmd(struct qlcnic_adapter *adapter, |
| 1374 |
struct qlcnic_cmd_args *cmd) |
| 1375 |
{ |
| 1376 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1377 |
struct qlcnic_mailbox *mbx = ahw->mailbox; |
| 1378 |
struct device *dev = &adapter->pdev->dev; |
| 1379 |
struct qlcnic_bc_trans *trans; |
| 1380 |
int err; |
| 1381 |
u32 rsp_data, opcode, mbx_err_code, rsp; |
| 1382 |
u16 seq = ++adapter->ahw->sriov->bc.trans_counter; |
| 1383 |
u8 func = ahw->pci_func; |
| 1384 |
|
| 1385 |
rsp = qlcnic_sriov_alloc_bc_trans(&trans); |
| 1386 |
if (rsp) |
| 1387 |
goto free_cmd; |
| 1388 |
|
| 1389 |
rsp = qlcnic_sriov_prepare_bc_hdr(trans, cmd, seq, QLC_BC_COMMAND); |
| 1390 |
if (rsp) |
| 1391 |
goto cleanup_transaction; |
| 1392 |
|
| 1393 |
retry: |
| 1394 |
if (!test_bit(QLC_83XX_MBX_READY, &mbx->status)) { |
| 1395 |
rsp = -EIO; |
| 1396 |
QLCDB(adapter, DRV, "MBX not Ready!(cmd 0x%x) for VF 0x%x\n", |
| 1397 |
QLCNIC_MBX_RSP(cmd->req.arg[0]), func); |
| 1398 |
goto err_out; |
| 1399 |
} |
| 1400 |
|
| 1401 |
err = qlcnic_sriov_send_bc_cmd(adapter, trans, func); |
| 1402 |
if (err) { |
| 1403 |
dev_err(dev, "MBX command 0x%x timed out for VF %d\n", |
| 1404 |
(cmd->req.arg[0] & 0xffff), func); |
| 1405 |
rsp = QLCNIC_RCODE_TIMEOUT; |
| 1406 |
|
| 1407 |
/* After adapter reset PF driver may take some time to |
| 1408 |
* respond to VF's request. Retry request till maximum retries. |
| 1409 |
*/ |
| 1410 |
if ((trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) && |
| 1411 |
!qlcnic_sriov_retry_bc_cmd(adapter, trans)) |
| 1412 |
goto retry; |
| 1413 |
|
| 1414 |
goto err_out; |
| 1415 |
} |
| 1416 |
|
| 1417 |
rsp_data = cmd->rsp.arg[0]; |
| 1418 |
mbx_err_code = QLCNIC_MBX_STATUS(rsp_data); |
| 1419 |
opcode = QLCNIC_MBX_RSP(cmd->req.arg[0]); |
| 1420 |
|
| 1421 |
if ((mbx_err_code == QLCNIC_MBX_RSP_OK) || |
| 1422 |
(mbx_err_code == QLCNIC_MBX_PORT_RSP_OK)) { |
| 1423 |
rsp = QLCNIC_RCODE_SUCCESS; |
| 1424 |
} else { |
| 1425 |
if (cmd->type == QLC_83XX_MBX_CMD_NO_WAIT) { |
| 1426 |
rsp = QLCNIC_RCODE_SUCCESS; |
| 1427 |
} else { |
| 1428 |
rsp = mbx_err_code; |
| 1429 |
if (!rsp) |
| 1430 |
rsp = 1; |
| 1431 |
|
| 1432 |
dev_err(dev, |
| 1433 |
"MBX command 0x%x failed with err:0x%x for VF %d\n", |
| 1434 |
opcode, mbx_err_code, func); |
| 1435 |
} |
| 1436 |
} |
| 1437 |
|
| 1438 |
err_out: |
| 1439 |
if (rsp == QLCNIC_RCODE_TIMEOUT) { |
| 1440 |
ahw->reset_context = 1; |
| 1441 |
adapter->need_fw_reset = 1; |
| 1442 |
clear_bit(QLC_83XX_MBX_READY, &mbx->status); |
| 1443 |
} |
| 1444 |
|
| 1445 |
cleanup_transaction: |
| 1446 |
qlcnic_sriov_cleanup_transaction(trans); |
| 1447 |
|
| 1448 |
free_cmd: |
| 1449 |
if (cmd->type == QLC_83XX_MBX_CMD_NO_WAIT) { |
| 1450 |
qlcnic_free_mbx_args(cmd); |
| 1451 |
kfree(cmd); |
| 1452 |
} |
| 1453 |
|
| 1454 |
return rsp; |
| 1455 |
} |
| 1456 |
|
| 1457 |
|
| 1458 |
static int qlcnic_sriov_issue_cmd(struct qlcnic_adapter *adapter, |
| 1459 |
struct qlcnic_cmd_args *cmd) |
| 1460 |
{ |
| 1461 |
if (cmd->type == QLC_83XX_MBX_CMD_NO_WAIT) |
| 1462 |
return qlcnic_sriov_async_issue_cmd(adapter, cmd); |
| 1463 |
else |
| 1464 |
return __qlcnic_sriov_issue_cmd(adapter, cmd); |
| 1465 |
} |
| 1466 |
|
| 1467 |
static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter *adapter, u8 cmd_op) |
| 1468 |
{ |
| 1469 |
struct qlcnic_cmd_args cmd; |
| 1470 |
struct qlcnic_vf_info *vf = &adapter->ahw->sriov->vf_info[0]; |
| 1471 |
int ret; |
| 1472 |
|
| 1473 |
memset(&cmd, 0, sizeof(cmd)); |
| 1474 |
if (qlcnic_sriov_alloc_bc_mbx_args(&cmd, cmd_op)) |
| 1475 |
return -ENOMEM; |
| 1476 |
|
| 1477 |
ret = qlcnic_issue_cmd(adapter, &cmd); |
| 1478 |
if (ret) { |
| 1479 |
dev_err(&adapter->pdev->dev, |
| 1480 |
"Failed bc channel %s %d\n", cmd_op ? "term" : "init", |
| 1481 |
ret); |
| 1482 |
goto out; |
| 1483 |
} |
| 1484 |
|
| 1485 |
cmd_op = (cmd.rsp.arg[0] & 0xff); |
| 1486 |
if (cmd.rsp.arg[0] >> 25 == 2) { |
| 1487 |
ret = 2; |
| 1488 |
goto out; |
| 1489 |
} |
| 1490 |
|
| 1491 |
if (cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) |
| 1492 |
set_bit(QLC_BC_VF_STATE, &vf->state); |
| 1493 |
else |
| 1494 |
clear_bit(QLC_BC_VF_STATE, &vf->state); |
| 1495 |
|
| 1496 |
out: |
| 1497 |
qlcnic_free_mbx_args(&cmd); |
| 1498 |
return ret; |
| 1499 |
} |
| 1500 |
|
| 1501 |
static void qlcnic_vf_add_mc_list(struct net_device *netdev, const u8 *mac, |
| 1502 |
enum qlcnic_mac_type mac_type) |
| 1503 |
{ |
| 1504 |
struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1505 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 1506 |
struct qlcnic_vf_info *vf; |
| 1507 |
u16 vlan_id; |
| 1508 |
int i; |
| 1509 |
|
| 1510 |
vf = &adapter->ahw->sriov->vf_info[0]; |
| 1511 |
|
| 1512 |
if (!qlcnic_sriov_check_any_vlan(vf)) { |
| 1513 |
qlcnic_nic_add_mac(adapter, mac, 0, mac_type); |
| 1514 |
} else { |
| 1515 |
spin_lock(&vf->vlan_list_lock); |
| 1516 |
for (i = 0; i < sriov->num_allowed_vlans; i++) { |
| 1517 |
vlan_id = vf->sriov_vlans[i]; |
| 1518 |
if (vlan_id) |
| 1519 |
qlcnic_nic_add_mac(adapter, mac, vlan_id, |
| 1520 |
mac_type); |
| 1521 |
} |
| 1522 |
spin_unlock(&vf->vlan_list_lock); |
| 1523 |
if (qlcnic_84xx_check(adapter)) |
| 1524 |
qlcnic_nic_add_mac(adapter, mac, 0, mac_type); |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel *bc) |
| 1529 |
{ |
| 1530 |
struct list_head *head = &bc->async_cmd_list; |
| 1531 |
struct qlcnic_async_cmd *entry; |
| 1532 |
|
| 1533 |
flush_workqueue(bc->bc_async_wq); |
| 1534 |
cancel_work_sync(&bc->vf_async_work); |
| 1535 |
|
| 1536 |
spin_lock(&bc->queue_lock); |
| 1537 |
while (!list_empty(head)) { |
| 1538 |
entry = list_entry(head->next, struct qlcnic_async_cmd, |
| 1539 |
list); |
| 1540 |
list_del(&entry->list); |
| 1541 |
kfree(entry->cmd); |
| 1542 |
kfree(entry); |
| 1543 |
} |
| 1544 |
spin_unlock(&bc->queue_lock); |
| 1545 |
} |
| 1546 |
|
| 1547 |
void qlcnic_sriov_vf_set_multi(struct net_device *netdev) |
| 1548 |
{ |
| 1549 |
struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1550 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1551 |
static const u8 bcast_addr[ETH_ALEN] = { |
| 1552 |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 1553 |
}; |
| 1554 |
struct netdev_hw_addr *ha; |
| 1555 |
u32 mode = VPORT_MISS_MODE_DROP; |
| 1556 |
|
| 1557 |
if (!test_bit(__QLCNIC_FW_ATTACHED, &adapter->state)) |
| 1558 |
return; |
| 1559 |
|
| 1560 |
if (netdev->flags & IFF_PROMISC) { |
| 1561 |
if (!(adapter->flags & QLCNIC_PROMISC_DISABLED)) |
| 1562 |
mode = VPORT_MISS_MODE_ACCEPT_ALL; |
| 1563 |
} else if ((netdev->flags & IFF_ALLMULTI) || |
| 1564 |
(netdev_mc_count(netdev) > ahw->max_mc_count)) { |
| 1565 |
mode = VPORT_MISS_MODE_ACCEPT_MULTI; |
| 1566 |
} else { |
| 1567 |
qlcnic_vf_add_mc_list(netdev, bcast_addr, QLCNIC_BROADCAST_MAC); |
| 1568 |
if (!netdev_mc_empty(netdev)) { |
| 1569 |
qlcnic_flush_mcast_mac(adapter); |
| 1570 |
netdev_for_each_mc_addr(ha, netdev) |
| 1571 |
qlcnic_vf_add_mc_list(netdev, ha->addr, |
| 1572 |
QLCNIC_MULTICAST_MAC); |
| 1573 |
} |
| 1574 |
} |
| 1575 |
|
| 1576 |
/* configure unicast MAC address, if there is not sufficient space |
| 1577 |
* to store all the unicast addresses then enable promiscuous mode |
| 1578 |
*/ |
| 1579 |
if (netdev_uc_count(netdev) > ahw->max_uc_count) { |
| 1580 |
mode = VPORT_MISS_MODE_ACCEPT_ALL; |
| 1581 |
} else if (!netdev_uc_empty(netdev)) { |
| 1582 |
netdev_for_each_uc_addr(ha, netdev) |
| 1583 |
qlcnic_vf_add_mc_list(netdev, ha->addr, |
| 1584 |
QLCNIC_UNICAST_MAC); |
| 1585 |
} |
| 1586 |
|
| 1587 |
if (adapter->pdev->is_virtfn) { |
| 1588 |
if (mode == VPORT_MISS_MODE_ACCEPT_ALL && |
| 1589 |
!adapter->fdb_mac_learn) { |
| 1590 |
qlcnic_alloc_lb_filters_mem(adapter); |
| 1591 |
adapter->drv_mac_learn = true; |
| 1592 |
adapter->rx_mac_learn = true; |
| 1593 |
} else { |
| 1594 |
adapter->drv_mac_learn = false; |
| 1595 |
adapter->rx_mac_learn = false; |
| 1596 |
} |
| 1597 |
} |
| 1598 |
|
| 1599 |
qlcnic_nic_set_promisc(adapter, mode); |
| 1600 |
} |
| 1601 |
|
| 1602 |
static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct *work) |
| 1603 |
{ |
| 1604 |
struct qlcnic_async_cmd *entry, *tmp; |
| 1605 |
struct qlcnic_back_channel *bc; |
| 1606 |
struct qlcnic_cmd_args *cmd; |
| 1607 |
struct list_head *head; |
| 1608 |
LIST_HEAD(del_list); |
| 1609 |
|
| 1610 |
bc = container_of(work, struct qlcnic_back_channel, vf_async_work); |
| 1611 |
head = &bc->async_cmd_list; |
| 1612 |
|
| 1613 |
spin_lock(&bc->queue_lock); |
| 1614 |
list_splice_init(head, &del_list); |
| 1615 |
spin_unlock(&bc->queue_lock); |
| 1616 |
|
| 1617 |
list_for_each_entry_safe(entry, tmp, &del_list, list) { |
| 1618 |
list_del(&entry->list); |
| 1619 |
cmd = entry->cmd; |
| 1620 |
__qlcnic_sriov_issue_cmd(bc->adapter, cmd); |
| 1621 |
kfree(entry); |
| 1622 |
} |
| 1623 |
|
| 1624 |
if (!list_empty(head)) |
| 1625 |
queue_work(bc->bc_async_wq, &bc->vf_async_work); |
| 1626 |
|
| 1627 |
return; |
| 1628 |
} |
| 1629 |
|
| 1630 |
static struct qlcnic_async_cmd * |
| 1631 |
qlcnic_sriov_alloc_async_cmd(struct qlcnic_back_channel *bc, |
| 1632 |
struct qlcnic_cmd_args *cmd) |
| 1633 |
{ |
| 1634 |
struct qlcnic_async_cmd *entry = NULL; |
| 1635 |
|
| 1636 |
entry = kzalloc_obj(*entry, GFP_ATOMIC); |
| 1637 |
if (!entry) |
| 1638 |
return NULL; |
| 1639 |
|
| 1640 |
entry->cmd = cmd; |
| 1641 |
|
| 1642 |
spin_lock(&bc->queue_lock); |
| 1643 |
list_add_tail(&entry->list, &bc->async_cmd_list); |
| 1644 |
spin_unlock(&bc->queue_lock); |
| 1645 |
|
| 1646 |
return entry; |
| 1647 |
} |
| 1648 |
|
| 1649 |
static void qlcnic_sriov_schedule_async_cmd(struct qlcnic_back_channel *bc, |
| 1650 |
struct qlcnic_cmd_args *cmd) |
| 1651 |
{ |
| 1652 |
struct qlcnic_async_cmd *entry = NULL; |
| 1653 |
|
| 1654 |
entry = qlcnic_sriov_alloc_async_cmd(bc, cmd); |
| 1655 |
if (!entry) { |
| 1656 |
qlcnic_free_mbx_args(cmd); |
| 1657 |
kfree(cmd); |
| 1658 |
return; |
| 1659 |
} |
| 1660 |
|
| 1661 |
queue_work(bc->bc_async_wq, &bc->vf_async_work); |
| 1662 |
} |
| 1663 |
|
| 1664 |
static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter *adapter, |
| 1665 |
struct qlcnic_cmd_args *cmd) |
| 1666 |
{ |
| 1667 |
|
| 1668 |
struct qlcnic_back_channel *bc = &adapter->ahw->sriov->bc; |
| 1669 |
|
| 1670 |
if (adapter->need_fw_reset) |
| 1671 |
return -EIO; |
| 1672 |
|
| 1673 |
qlcnic_sriov_schedule_async_cmd(bc, cmd); |
| 1674 |
|
| 1675 |
return 0; |
| 1676 |
} |
| 1677 |
|
| 1678 |
static int qlcnic_sriov_vf_reinit_driver(struct qlcnic_adapter *adapter) |
| 1679 |
{ |
| 1680 |
int err; |
| 1681 |
|
| 1682 |
adapter->need_fw_reset = 0; |
| 1683 |
qlcnic_83xx_reinit_mbx_work(adapter->ahw->mailbox); |
| 1684 |
qlcnic_83xx_enable_mbx_interrupt(adapter); |
| 1685 |
|
| 1686 |
err = qlcnic_sriov_cfg_bc_intr(adapter, 1); |
| 1687 |
if (err) |
| 1688 |
return err; |
| 1689 |
|
| 1690 |
err = qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_INIT); |
| 1691 |
if (err) |
| 1692 |
goto err_out_cleanup_bc_intr; |
| 1693 |
|
| 1694 |
err = qlcnic_sriov_vf_init_driver(adapter); |
| 1695 |
if (err) |
| 1696 |
goto err_out_term_channel; |
| 1697 |
|
| 1698 |
return 0; |
| 1699 |
|
| 1700 |
err_out_term_channel: |
| 1701 |
qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_TERM); |
| 1702 |
|
| 1703 |
err_out_cleanup_bc_intr: |
| 1704 |
qlcnic_sriov_cfg_bc_intr(adapter, 0); |
| 1705 |
return err; |
| 1706 |
} |
| 1707 |
|
| 1708 |
static void qlcnic_sriov_vf_attach(struct qlcnic_adapter *adapter) |
| 1709 |
{ |
| 1710 |
struct net_device *netdev = adapter->netdev; |
| 1711 |
|
| 1712 |
if (netif_running(netdev)) { |
| 1713 |
if (!qlcnic_up(adapter, netdev)) |
| 1714 |
qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
| 1715 |
} |
| 1716 |
|
| 1717 |
netif_device_attach(netdev); |
| 1718 |
} |
| 1719 |
|
| 1720 |
static void qlcnic_sriov_vf_detach(struct qlcnic_adapter *adapter) |
| 1721 |
{ |
| 1722 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1723 |
struct qlcnic_intrpt_config *intr_tbl = ahw->intr_tbl; |
| 1724 |
struct net_device *netdev = adapter->netdev; |
| 1725 |
u8 i, max_ints = ahw->num_msix - 1; |
| 1726 |
|
| 1727 |
netif_device_detach(netdev); |
| 1728 |
qlcnic_83xx_detach_mailbox_work(adapter); |
| 1729 |
qlcnic_83xx_disable_mbx_intr(adapter); |
| 1730 |
|
| 1731 |
if (netif_running(netdev)) |
| 1732 |
qlcnic_down(adapter, netdev); |
| 1733 |
|
| 1734 |
for (i = 0; i < max_ints; i++) { |
| 1735 |
intr_tbl[i].id = i; |
| 1736 |
intr_tbl[i].enabled = 0; |
| 1737 |
intr_tbl[i].src = 0; |
| 1738 |
} |
| 1739 |
ahw->reset_context = 0; |
| 1740 |
} |
| 1741 |
|
| 1742 |
static int qlcnic_sriov_vf_handle_dev_ready(struct qlcnic_adapter *adapter) |
| 1743 |
{ |
| 1744 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1745 |
struct device *dev = &adapter->pdev->dev; |
| 1746 |
struct qlc_83xx_idc *idc = &ahw->idc; |
| 1747 |
u8 func = ahw->pci_func; |
| 1748 |
u32 state; |
| 1749 |
|
| 1750 |
if ((idc->prev_state == QLC_83XX_IDC_DEV_NEED_RESET) || |
| 1751 |
(idc->prev_state == QLC_83XX_IDC_DEV_INIT)) { |
| 1752 |
if (!qlcnic_sriov_vf_reinit_driver(adapter)) { |
| 1753 |
qlcnic_sriov_vf_attach(adapter); |
| 1754 |
adapter->fw_fail_cnt = 0; |
| 1755 |
dev_info(dev, |
| 1756 |
"%s: Reinitialization of VF 0x%x done after FW reset\n", |
| 1757 |
__func__, func); |
| 1758 |
} else { |
| 1759 |
dev_err(dev, |
| 1760 |
"%s: Reinitialization of VF 0x%x failed after FW reset\n", |
| 1761 |
__func__, func); |
| 1762 |
state = QLCRDX(ahw, QLC_83XX_IDC_DEV_STATE); |
| 1763 |
dev_info(dev, "Current state 0x%x after FW reset\n", |
| 1764 |
state); |
| 1765 |
} |
| 1766 |
} |
| 1767 |
|
| 1768 |
return 0; |
| 1769 |
} |
| 1770 |
|
| 1771 |
static int qlcnic_sriov_vf_handle_context_reset(struct qlcnic_adapter *adapter) |
| 1772 |
{ |
| 1773 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1774 |
struct qlcnic_mailbox *mbx = ahw->mailbox; |
| 1775 |
struct device *dev = &adapter->pdev->dev; |
| 1776 |
struct qlc_83xx_idc *idc = &ahw->idc; |
| 1777 |
u8 func = ahw->pci_func; |
| 1778 |
u32 state; |
| 1779 |
|
| 1780 |
adapter->reset_ctx_cnt++; |
| 1781 |
|
| 1782 |
/* Skip the context reset and check if FW is hung */ |
| 1783 |
if (adapter->reset_ctx_cnt < 3) { |
| 1784 |
adapter->need_fw_reset = 1; |
| 1785 |
clear_bit(QLC_83XX_MBX_READY, &mbx->status); |
| 1786 |
dev_info(dev, |
| 1787 |
"Resetting context, wait here to check if FW is in failed state\n"); |
| 1788 |
return 0; |
| 1789 |
} |
| 1790 |
|
| 1791 |
/* Check if number of resets exceed the threshold. |
| 1792 |
* If it exceeds the threshold just fail the VF. |
| 1793 |
*/ |
| 1794 |
if (adapter->reset_ctx_cnt > QLC_83XX_VF_RESET_FAIL_THRESH) { |
| 1795 |
clear_bit(QLC_83XX_MODULE_LOADED, &idc->status); |
| 1796 |
adapter->tx_timeo_cnt = 0; |
| 1797 |
adapter->fw_fail_cnt = 0; |
| 1798 |
adapter->reset_ctx_cnt = 0; |
| 1799 |
qlcnic_sriov_vf_detach(adapter); |
| 1800 |
dev_err(dev, |
| 1801 |
"Device context resets have exceeded the threshold, device interface will be shutdown\n"); |
| 1802 |
return -EIO; |
| 1803 |
} |
| 1804 |
|
| 1805 |
dev_info(dev, "Resetting context of VF 0x%x\n", func); |
| 1806 |
dev_info(dev, "%s: Context reset count %d for VF 0x%x\n", |
| 1807 |
__func__, adapter->reset_ctx_cnt, func); |
| 1808 |
set_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1809 |
adapter->need_fw_reset = 1; |
| 1810 |
clear_bit(QLC_83XX_MBX_READY, &mbx->status); |
| 1811 |
qlcnic_sriov_vf_detach(adapter); |
| 1812 |
adapter->need_fw_reset = 0; |
| 1813 |
|
| 1814 |
if (!qlcnic_sriov_vf_reinit_driver(adapter)) { |
| 1815 |
qlcnic_sriov_vf_attach(adapter); |
| 1816 |
adapter->tx_timeo_cnt = 0; |
| 1817 |
adapter->reset_ctx_cnt = 0; |
| 1818 |
adapter->fw_fail_cnt = 0; |
| 1819 |
dev_info(dev, "Done resetting context for VF 0x%x\n", func); |
| 1820 |
} else { |
| 1821 |
dev_err(dev, "%s: Reinitialization of VF 0x%x failed\n", |
| 1822 |
__func__, func); |
| 1823 |
state = QLCRDX(ahw, QLC_83XX_IDC_DEV_STATE); |
| 1824 |
dev_info(dev, "%s: Current state 0x%x\n", __func__, state); |
| 1825 |
} |
| 1826 |
|
| 1827 |
return 0; |
| 1828 |
} |
| 1829 |
|
| 1830 |
static int qlcnic_sriov_vf_idc_ready_state(struct qlcnic_adapter *adapter) |
| 1831 |
{ |
| 1832 |
struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 1833 |
int ret = 0; |
| 1834 |
|
| 1835 |
if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_READY) |
| 1836 |
ret = qlcnic_sriov_vf_handle_dev_ready(adapter); |
| 1837 |
else if (ahw->reset_context) |
| 1838 |
ret = qlcnic_sriov_vf_handle_context_reset(adapter); |
| 1839 |
|
| 1840 |
clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1841 |
return ret; |
| 1842 |
} |
| 1843 |
|
| 1844 |
static int qlcnic_sriov_vf_idc_failed_state(struct qlcnic_adapter *adapter) |
| 1845 |
{ |
| 1846 |
struct qlc_83xx_idc *idc = &adapter->ahw->idc; |
| 1847 |
|
| 1848 |
dev_err(&adapter->pdev->dev, "Device is in failed state\n"); |
| 1849 |
if (idc->prev_state == QLC_83XX_IDC_DEV_READY) |
| 1850 |
qlcnic_sriov_vf_detach(adapter); |
| 1851 |
|
| 1852 |
clear_bit(QLC_83XX_MODULE_LOADED, &idc->status); |
| 1853 |
clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1854 |
return -EIO; |
| 1855 |
} |
| 1856 |
|
| 1857 |
static int |
| 1858 |
qlcnic_sriov_vf_idc_need_quiescent_state(struct qlcnic_adapter *adapter) |
| 1859 |
{ |
| 1860 |
struct qlcnic_mailbox *mbx = adapter->ahw->mailbox; |
| 1861 |
struct qlc_83xx_idc *idc = &adapter->ahw->idc; |
| 1862 |
|
| 1863 |
dev_info(&adapter->pdev->dev, "Device is in quiescent state\n"); |
| 1864 |
if (idc->prev_state == QLC_83XX_IDC_DEV_READY) { |
| 1865 |
set_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1866 |
adapter->tx_timeo_cnt = 0; |
| 1867 |
adapter->reset_ctx_cnt = 0; |
| 1868 |
clear_bit(QLC_83XX_MBX_READY, &mbx->status); |
| 1869 |
qlcnic_sriov_vf_detach(adapter); |
| 1870 |
} |
| 1871 |
|
| 1872 |
return 0; |
| 1873 |
} |
| 1874 |
|
| 1875 |
static int qlcnic_sriov_vf_idc_init_reset_state(struct qlcnic_adapter *adapter) |
| 1876 |
{ |
| 1877 |
struct qlcnic_mailbox *mbx = adapter->ahw->mailbox; |
| 1878 |
struct qlc_83xx_idc *idc = &adapter->ahw->idc; |
| 1879 |
u8 func = adapter->ahw->pci_func; |
| 1880 |
|
| 1881 |
if (idc->prev_state == QLC_83XX_IDC_DEV_READY) { |
| 1882 |
dev_err(&adapter->pdev->dev, |
| 1883 |
"Firmware hang detected by VF 0x%x\n", func); |
| 1884 |
set_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1885 |
adapter->tx_timeo_cnt = 0; |
| 1886 |
adapter->reset_ctx_cnt = 0; |
| 1887 |
clear_bit(QLC_83XX_MBX_READY, &mbx->status); |
| 1888 |
qlcnic_sriov_vf_detach(adapter); |
| 1889 |
} |
| 1890 |
return 0; |
| 1891 |
} |
| 1892 |
|
| 1893 |
static int qlcnic_sriov_vf_idc_unknown_state(struct qlcnic_adapter *adapter) |
| 1894 |
{ |
| 1895 |
dev_err(&adapter->pdev->dev, "%s: Device in unknown state\n", __func__); |
| 1896 |
return 0; |
| 1897 |
} |
| 1898 |
|
| 1899 |
static void qlcnic_sriov_vf_periodic_tasks(struct qlcnic_adapter *adapter) |
| 1900 |
{ |
| 1901 |
if (adapter->fhash.fnum) |
| 1902 |
qlcnic_prune_lb_filters(adapter); |
| 1903 |
} |
| 1904 |
|
| 1905 |
static void qlcnic_sriov_vf_poll_dev_state(struct work_struct *work) |
| 1906 |
{ |
| 1907 |
struct qlcnic_adapter *adapter; |
| 1908 |
struct qlc_83xx_idc *idc; |
| 1909 |
int ret = 0; |
| 1910 |
|
| 1911 |
adapter = container_of(work, struct qlcnic_adapter, fw_work.work); |
| 1912 |
idc = &adapter->ahw->idc; |
| 1913 |
idc->curr_state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE); |
| 1914 |
|
| 1915 |
switch (idc->curr_state) { |
| 1916 |
case QLC_83XX_IDC_DEV_READY: |
| 1917 |
ret = qlcnic_sriov_vf_idc_ready_state(adapter); |
| 1918 |
break; |
| 1919 |
case QLC_83XX_IDC_DEV_NEED_RESET: |
| 1920 |
case QLC_83XX_IDC_DEV_INIT: |
| 1921 |
ret = qlcnic_sriov_vf_idc_init_reset_state(adapter); |
| 1922 |
break; |
| 1923 |
case QLC_83XX_IDC_DEV_NEED_QUISCENT: |
| 1924 |
ret = qlcnic_sriov_vf_idc_need_quiescent_state(adapter); |
| 1925 |
break; |
| 1926 |
case QLC_83XX_IDC_DEV_FAILED: |
| 1927 |
ret = qlcnic_sriov_vf_idc_failed_state(adapter); |
| 1928 |
break; |
| 1929 |
case QLC_83XX_IDC_DEV_QUISCENT: |
| 1930 |
break; |
| 1931 |
default: |
| 1932 |
ret = qlcnic_sriov_vf_idc_unknown_state(adapter); |
| 1933 |
} |
| 1934 |
|
| 1935 |
idc->prev_state = idc->curr_state; |
| 1936 |
qlcnic_sriov_vf_periodic_tasks(adapter); |
| 1937 |
|
| 1938 |
if (!ret && test_bit(QLC_83XX_MODULE_LOADED, &idc->status)) |
| 1939 |
qlcnic_schedule_work(adapter, qlcnic_sriov_vf_poll_dev_state, |
| 1940 |
idc->delay); |
| 1941 |
} |
| 1942 |
|
| 1943 |
static void qlcnic_sriov_vf_cancel_fw_work(struct qlcnic_adapter *adapter) |
| 1944 |
{ |
| 1945 |
while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1946 |
msleep(20); |
| 1947 |
|
| 1948 |
clear_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status); |
| 1949 |
clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1950 |
cancel_delayed_work_sync(&adapter->fw_work); |
| 1951 |
} |
| 1952 |
|
| 1953 |
static int qlcnic_sriov_check_vlan_id(struct qlcnic_sriov *sriov, |
| 1954 |
struct qlcnic_vf_info *vf, u16 vlan_id) |
| 1955 |
{ |
| 1956 |
int i, err = -EINVAL; |
| 1957 |
|
| 1958 |
if (!vf->sriov_vlans) |
| 1959 |
return err; |
| 1960 |
|
| 1961 |
spin_lock_bh(&vf->vlan_list_lock); |
| 1962 |
|
| 1963 |
for (i = 0; i < sriov->num_allowed_vlans; i++) { |
| 1964 |
if (vf->sriov_vlans[i] == vlan_id) { |
| 1965 |
err = 0; |
| 1966 |
break; |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
spin_unlock_bh(&vf->vlan_list_lock); |
| 1971 |
return err; |
| 1972 |
} |
| 1973 |
|
| 1974 |
static int qlcnic_sriov_validate_num_vlans(struct qlcnic_sriov *sriov, |
| 1975 |
struct qlcnic_vf_info *vf) |
| 1976 |
{ |
| 1977 |
int err = 0; |
| 1978 |
|
| 1979 |
spin_lock_bh(&vf->vlan_list_lock); |
| 1980 |
|
| 1981 |
if (vf->num_vlan >= sriov->num_allowed_vlans) |
| 1982 |
err = -EINVAL; |
| 1983 |
|
| 1984 |
spin_unlock_bh(&vf->vlan_list_lock); |
| 1985 |
return err; |
| 1986 |
} |
| 1987 |
|
| 1988 |
static int qlcnic_sriov_validate_vlan_cfg(struct qlcnic_adapter *adapter, |
| 1989 |
u16 vid, u8 enable) |
| 1990 |
{ |
| 1991 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 1992 |
struct qlcnic_vf_info *vf; |
| 1993 |
bool vlan_exist; |
| 1994 |
u8 allowed = 0; |
| 1995 |
int i; |
| 1996 |
|
| 1997 |
vf = &adapter->ahw->sriov->vf_info[0]; |
| 1998 |
vlan_exist = qlcnic_sriov_check_any_vlan(vf); |
| 1999 |
if (sriov->vlan_mode != QLC_GUEST_VLAN_MODE) |
| 2000 |
return -EINVAL; |
| 2001 |
|
| 2002 |
if (enable) { |
| 2003 |
if (qlcnic_83xx_vf_check(adapter) && vlan_exist) |
| 2004 |
return -EINVAL; |
| 2005 |
|
| 2006 |
if (qlcnic_sriov_validate_num_vlans(sriov, vf)) |
| 2007 |
return -EINVAL; |
| 2008 |
|
| 2009 |
if (sriov->any_vlan) { |
| 2010 |
for (i = 0; i < sriov->num_allowed_vlans; i++) { |
| 2011 |
if (sriov->allowed_vlans[i] == vid) |
| 2012 |
allowed = 1; |
| 2013 |
} |
| 2014 |
|
| 2015 |
if (!allowed) |
| 2016 |
return -EINVAL; |
| 2017 |
} |
| 2018 |
} else { |
| 2019 |
if (!vlan_exist || qlcnic_sriov_check_vlan_id(sriov, vf, vid)) |
| 2020 |
return -EINVAL; |
| 2021 |
} |
| 2022 |
|
| 2023 |
return 0; |
| 2024 |
} |
| 2025 |
|
| 2026 |
static void qlcnic_sriov_vlan_operation(struct qlcnic_vf_info *vf, u16 vlan_id, |
| 2027 |
enum qlcnic_vlan_operations opcode) |
| 2028 |
{ |
| 2029 |
struct qlcnic_adapter *adapter = vf->adapter; |
| 2030 |
struct qlcnic_sriov *sriov; |
| 2031 |
|
| 2032 |
sriov = adapter->ahw->sriov; |
| 2033 |
|
| 2034 |
if (!vf->sriov_vlans) |
| 2035 |
return; |
| 2036 |
|
| 2037 |
spin_lock_bh(&vf->vlan_list_lock); |
| 2038 |
|
| 2039 |
switch (opcode) { |
| 2040 |
case QLC_VLAN_ADD: |
| 2041 |
qlcnic_sriov_add_vlan_id(sriov, vf, vlan_id); |
| 2042 |
break; |
| 2043 |
case QLC_VLAN_DELETE: |
| 2044 |
qlcnic_sriov_del_vlan_id(sriov, vf, vlan_id); |
| 2045 |
break; |
| 2046 |
default: |
| 2047 |
netdev_err(adapter->netdev, "Invalid VLAN operation\n"); |
| 2048 |
} |
| 2049 |
|
| 2050 |
spin_unlock_bh(&vf->vlan_list_lock); |
| 2051 |
return; |
| 2052 |
} |
| 2053 |
|
| 2054 |
int qlcnic_sriov_cfg_vf_guest_vlan(struct qlcnic_adapter *adapter, |
| 2055 |
u16 vid, u8 enable) |
| 2056 |
{ |
| 2057 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 2058 |
struct net_device *netdev = adapter->netdev; |
| 2059 |
struct qlcnic_vf_info *vf; |
| 2060 |
struct qlcnic_cmd_args cmd; |
| 2061 |
int ret; |
| 2062 |
|
| 2063 |
memset(&cmd, 0, sizeof(cmd)); |
| 2064 |
if (vid == 0) |
| 2065 |
return 0; |
| 2066 |
|
| 2067 |
vf = &adapter->ahw->sriov->vf_info[0]; |
| 2068 |
ret = qlcnic_sriov_validate_vlan_cfg(adapter, vid, enable); |
| 2069 |
if (ret) |
| 2070 |
return ret; |
| 2071 |
|
| 2072 |
ret = qlcnic_sriov_alloc_bc_mbx_args(&cmd, |
| 2073 |
QLCNIC_BC_CMD_CFG_GUEST_VLAN); |
| 2074 |
if (ret) |
| 2075 |
return ret; |
| 2076 |
|
| 2077 |
cmd.req.arg[1] = (enable & 1) | vid << 16; |
| 2078 |
|
| 2079 |
qlcnic_sriov_cleanup_async_list(&sriov->bc); |
| 2080 |
ret = qlcnic_issue_cmd(adapter, &cmd); |
| 2081 |
if (ret) { |
| 2082 |
dev_err(&adapter->pdev->dev, |
| 2083 |
"Failed to configure guest VLAN, err=%d\n", ret); |
| 2084 |
} else { |
| 2085 |
netif_addr_lock_bh(netdev); |
| 2086 |
qlcnic_free_mac_list(adapter); |
| 2087 |
netif_addr_unlock_bh(netdev); |
| 2088 |
|
| 2089 |
if (enable) |
| 2090 |
qlcnic_sriov_vlan_operation(vf, vid, QLC_VLAN_ADD); |
| 2091 |
else |
| 2092 |
qlcnic_sriov_vlan_operation(vf, vid, QLC_VLAN_DELETE); |
| 2093 |
|
| 2094 |
netif_addr_lock_bh(netdev); |
| 2095 |
qlcnic_set_multi(netdev); |
| 2096 |
netif_addr_unlock_bh(netdev); |
| 2097 |
} |
| 2098 |
|
| 2099 |
qlcnic_free_mbx_args(&cmd); |
| 2100 |
return ret; |
| 2101 |
} |
| 2102 |
|
| 2103 |
static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter *adapter) |
| 2104 |
{ |
| 2105 |
struct list_head *head = &adapter->mac_list; |
| 2106 |
struct qlcnic_mac_vlan_list *cur; |
| 2107 |
|
| 2108 |
while (!list_empty(head)) { |
| 2109 |
cur = list_entry(head->next, struct qlcnic_mac_vlan_list, list); |
| 2110 |
qlcnic_sre_macaddr_change(adapter, cur->mac_addr, cur->vlan_id, |
| 2111 |
QLCNIC_MAC_DEL); |
| 2112 |
list_del(&cur->list); |
| 2113 |
kfree(cur); |
| 2114 |
} |
| 2115 |
} |
| 2116 |
|
| 2117 |
|
| 2118 |
static int qlcnic_sriov_vf_shutdown(struct pci_dev *pdev) |
| 2119 |
{ |
| 2120 |
struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2121 |
struct net_device *netdev = adapter->netdev; |
| 2122 |
|
| 2123 |
netif_device_detach(netdev); |
| 2124 |
qlcnic_cancel_idc_work(adapter); |
| 2125 |
|
| 2126 |
if (netif_running(netdev)) |
| 2127 |
qlcnic_down(adapter, netdev); |
| 2128 |
|
| 2129 |
qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_TERM); |
| 2130 |
qlcnic_sriov_cfg_bc_intr(adapter, 0); |
| 2131 |
qlcnic_83xx_disable_mbx_intr(adapter); |
| 2132 |
cancel_delayed_work_sync(&adapter->idc_aen_work); |
| 2133 |
|
| 2134 |
return pci_save_state(pdev); |
| 2135 |
} |
| 2136 |
|
| 2137 |
static int qlcnic_sriov_vf_resume(struct qlcnic_adapter *adapter) |
| 2138 |
{ |
| 2139 |
struct qlc_83xx_idc *idc = &adapter->ahw->idc; |
| 2140 |
struct net_device *netdev = adapter->netdev; |
| 2141 |
int err; |
| 2142 |
|
| 2143 |
set_bit(QLC_83XX_MODULE_LOADED, &idc->status); |
| 2144 |
qlcnic_83xx_enable_mbx_interrupt(adapter); |
| 2145 |
err = qlcnic_sriov_cfg_bc_intr(adapter, 1); |
| 2146 |
if (err) |
| 2147 |
return err; |
| 2148 |
|
| 2149 |
err = qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_INIT); |
| 2150 |
if (!err) { |
| 2151 |
if (netif_running(netdev)) { |
| 2152 |
err = qlcnic_up(adapter, netdev); |
| 2153 |
if (!err) |
| 2154 |
qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
| 2155 |
} |
| 2156 |
} |
| 2157 |
|
| 2158 |
netif_device_attach(netdev); |
| 2159 |
qlcnic_schedule_work(adapter, qlcnic_sriov_vf_poll_dev_state, |
| 2160 |
idc->delay); |
| 2161 |
return err; |
| 2162 |
} |
| 2163 |
|
| 2164 |
int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter) |
| 2165 |
{ |
| 2166 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 2167 |
struct qlcnic_vf_info *vf; |
| 2168 |
int i; |
| 2169 |
|
| 2170 |
for (i = 0; i < sriov->num_vfs; i++) { |
| 2171 |
vf = &sriov->vf_info[i]; |
| 2172 |
vf->sriov_vlans = kcalloc(sriov->num_allowed_vlans, |
| 2173 |
sizeof(*vf->sriov_vlans), GFP_KERNEL); |
| 2174 |
if (!vf->sriov_vlans) { |
| 2175 |
qlcnic_sriov_free_vlans(adapter); |
| 2176 |
return -ENOMEM; |
| 2177 |
} |
| 2178 |
} |
| 2179 |
|
| 2180 |
return 0; |
| 2181 |
} |
| 2182 |
|
| 2183 |
void qlcnic_sriov_free_vlans(struct qlcnic_adapter *adapter) |
| 2184 |
{ |
| 2185 |
struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
| 2186 |
struct qlcnic_vf_info *vf; |
| 2187 |
int i; |
| 2188 |
|
| 2189 |
for (i = 0; i < sriov->num_vfs; i++) { |
| 2190 |
vf = &sriov->vf_info[i]; |
| 2191 |
kfree(vf->sriov_vlans); |
| 2192 |
vf->sriov_vlans = NULL; |
| 2193 |
} |
| 2194 |
} |
| 2195 |
|
| 2196 |
void qlcnic_sriov_add_vlan_id(struct qlcnic_sriov *sriov, |
| 2197 |
struct qlcnic_vf_info *vf, u16 vlan_id) |
| 2198 |
{ |
| 2199 |
int i; |
| 2200 |
|
| 2201 |
for (i = 0; i < sriov->num_allowed_vlans; i++) { |
| 2202 |
if (!vf->sriov_vlans[i]) { |
| 2203 |
vf->sriov_vlans[i] = vlan_id; |
| 2204 |
vf->num_vlan++; |
| 2205 |
return; |
| 2206 |
} |
| 2207 |
} |
| 2208 |
} |
| 2209 |
|
| 2210 |
void qlcnic_sriov_del_vlan_id(struct qlcnic_sriov *sriov, |
| 2211 |
struct qlcnic_vf_info *vf, u16 vlan_id) |
| 2212 |
{ |
| 2213 |
int i; |
| 2214 |
|
| 2215 |
for (i = 0; i < sriov->num_allowed_vlans; i++) { |
| 2216 |
if (vf->sriov_vlans[i] == vlan_id) { |
| 2217 |
vf->sriov_vlans[i] = 0; |
| 2218 |
vf->num_vlan--; |
| 2219 |
return; |
| 2220 |
} |
| 2221 |
} |
| 2222 |
} |
| 2223 |
|
| 2224 |
bool qlcnic_sriov_check_any_vlan(struct qlcnic_vf_info *vf) |
| 2225 |
{ |
| 2226 |
bool err = false; |
| 2227 |
|
| 2228 |
spin_lock_bh(&vf->vlan_list_lock); |
| 2229 |
|
| 2230 |
if (vf->num_vlan) |
| 2231 |
err = true; |
| 2232 |
|
| 2233 |
spin_unlock_bh(&vf->vlan_list_lock); |
| 2234 |
return err; |
| 2235 |
} |