2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include "qlcnic_sriov.h"
10 #include "qlcnic_83xx_hw.h"
11 #include <linux/types.h>
13 #define QLC_BC_COMMAND 0
14 #define QLC_BC_RESPONSE 1
16 #define QLC_MBOX_RESP_TIMEOUT (10 * HZ)
17 #define QLC_MBOX_CH_FREE_TIMEOUT (10 * HZ)
20 #define QLC_BC_CFREE 1
22 #define QLC_BC_HDR_SZ 16
23 #define QLC_BC_PAYLOAD_SZ (1024 - QLC_BC_HDR_SZ)
25 #define QLC_DEFAULT_RCV_DESCRIPTORS_SRIOV_VF 2048
26 #define QLC_DEFAULT_JUMBO_RCV_DESCRIPTORS_SRIOV_VF 512
28 #define QLC_83XX_VF_RESET_FAIL_THRESH 8
29 #define QLC_BC_CMD_MAX_RETRY_CNT 5
31 static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter
*);
32 static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args
*, u32
);
33 static void qlcnic_sriov_vf_poll_dev_state(struct work_struct
*);
34 static void qlcnic_sriov_vf_cancel_fw_work(struct qlcnic_adapter
*);
35 static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans
*);
36 static int qlcnic_sriov_issue_cmd(struct qlcnic_adapter
*,
37 struct qlcnic_cmd_args
*);
38 static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter
*, u8
);
39 static void qlcnic_sriov_process_bc_cmd(struct work_struct
*);
40 static int qlcnic_sriov_vf_shutdown(struct pci_dev
*);
41 static int qlcnic_sriov_vf_resume(struct qlcnic_adapter
*);
42 static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter
*,
43 struct qlcnic_cmd_args
*);
45 static struct qlcnic_hardware_ops qlcnic_sriov_vf_hw_ops
= {
46 .read_crb
= qlcnic_83xx_read_crb
,
47 .write_crb
= qlcnic_83xx_write_crb
,
48 .read_reg
= qlcnic_83xx_rd_reg_indirect
,
49 .write_reg
= qlcnic_83xx_wrt_reg_indirect
,
50 .get_mac_address
= qlcnic_83xx_get_mac_address
,
51 .setup_intr
= qlcnic_83xx_setup_intr
,
52 .alloc_mbx_args
= qlcnic_83xx_alloc_mbx_args
,
53 .mbx_cmd
= qlcnic_sriov_issue_cmd
,
54 .get_func_no
= qlcnic_83xx_get_func_no
,
55 .api_lock
= qlcnic_83xx_cam_lock
,
56 .api_unlock
= qlcnic_83xx_cam_unlock
,
57 .process_lb_rcv_ring_diag
= qlcnic_83xx_process_rcv_ring_diag
,
58 .create_rx_ctx
= qlcnic_83xx_create_rx_ctx
,
59 .create_tx_ctx
= qlcnic_83xx_create_tx_ctx
,
60 .del_rx_ctx
= qlcnic_83xx_del_rx_ctx
,
61 .del_tx_ctx
= qlcnic_83xx_del_tx_ctx
,
62 .setup_link_event
= qlcnic_83xx_setup_link_event
,
63 .get_nic_info
= qlcnic_83xx_get_nic_info
,
64 .get_pci_info
= qlcnic_83xx_get_pci_info
,
65 .set_nic_info
= qlcnic_83xx_set_nic_info
,
66 .change_macvlan
= qlcnic_83xx_sre_macaddr_change
,
67 .napi_enable
= qlcnic_83xx_napi_enable
,
68 .napi_disable
= qlcnic_83xx_napi_disable
,
69 .config_intr_coal
= qlcnic_83xx_config_intr_coal
,
70 .config_rss
= qlcnic_83xx_config_rss
,
71 .config_hw_lro
= qlcnic_83xx_config_hw_lro
,
72 .config_promisc_mode
= qlcnic_83xx_nic_set_promisc
,
73 .change_l2_filter
= qlcnic_83xx_change_l2_filter
,
74 .get_board_info
= qlcnic_83xx_get_port_info
,
75 .free_mac_list
= qlcnic_sriov_vf_free_mac_list
,
76 .enable_sds_intr
= qlcnic_83xx_enable_sds_intr
,
77 .disable_sds_intr
= qlcnic_83xx_disable_sds_intr
,
80 static struct qlcnic_nic_template qlcnic_sriov_vf_ops
= {
81 .config_bridged_mode
= qlcnic_config_bridged_mode
,
82 .config_led
= qlcnic_config_led
,
83 .cancel_idc_work
= qlcnic_sriov_vf_cancel_fw_work
,
84 .napi_add
= qlcnic_83xx_napi_add
,
85 .napi_del
= qlcnic_83xx_napi_del
,
86 .shutdown
= qlcnic_sriov_vf_shutdown
,
87 .resume
= qlcnic_sriov_vf_resume
,
88 .config_ipaddr
= qlcnic_83xx_config_ipaddr
,
89 .clear_legacy_intr
= qlcnic_83xx_clear_legacy_intr
,
92 static const struct qlcnic_mailbox_metadata qlcnic_sriov_bc_mbx_tbl
[] = {
93 {QLCNIC_BC_CMD_CHANNEL_INIT
, 2, 2},
94 {QLCNIC_BC_CMD_CHANNEL_TERM
, 2, 2},
95 {QLCNIC_BC_CMD_GET_ACL
, 3, 14},
96 {QLCNIC_BC_CMD_CFG_GUEST_VLAN
, 2, 2},
99 static inline bool qlcnic_sriov_bc_msg_check(u32 val
)
101 return (val
& (1 << QLC_BC_MSG
)) ? true : false;
104 static inline bool qlcnic_sriov_channel_free_check(u32 val
)
106 return (val
& (1 << QLC_BC_CFREE
)) ? true : false;
109 static inline bool qlcnic_sriov_flr_check(u32 val
)
111 return (val
& (1 << QLC_BC_FLR
)) ? true : false;
114 static inline u8
qlcnic_sriov_target_func_id(u32 val
)
116 return (val
>> 4) & 0xff;
119 static int qlcnic_sriov_virtid_fn(struct qlcnic_adapter
*adapter
, int vf_id
)
121 struct pci_dev
*dev
= adapter
->pdev
;
125 if (qlcnic_sriov_vf_check(adapter
))
128 pos
= pci_find_ext_capability(dev
, PCI_EXT_CAP_ID_SRIOV
);
129 pci_read_config_word(dev
, pos
+ PCI_SRIOV_VF_OFFSET
, &offset
);
130 pci_read_config_word(dev
, pos
+ PCI_SRIOV_VF_STRIDE
, &stride
);
132 return (dev
->devfn
+ offset
+ stride
* vf_id
) & 0xff;
135 int qlcnic_sriov_init(struct qlcnic_adapter
*adapter
, int num_vfs
)
137 struct qlcnic_sriov
*sriov
;
138 struct qlcnic_back_channel
*bc
;
139 struct workqueue_struct
*wq
;
140 struct qlcnic_vport
*vp
;
141 struct qlcnic_vf_info
*vf
;
144 if (!qlcnic_sriov_enable_check(adapter
))
147 sriov
= kzalloc(sizeof(struct qlcnic_sriov
), GFP_KERNEL
);
151 adapter
->ahw
->sriov
= sriov
;
152 sriov
->num_vfs
= num_vfs
;
154 sriov
->vf_info
= kzalloc(sizeof(struct qlcnic_vf_info
) *
155 num_vfs
, GFP_KERNEL
);
156 if (!sriov
->vf_info
) {
158 goto qlcnic_free_sriov
;
161 wq
= create_singlethread_workqueue("bc-trans");
164 dev_err(&adapter
->pdev
->dev
,
165 "Cannot create bc-trans workqueue\n");
166 goto qlcnic_free_vf_info
;
169 bc
->bc_trans_wq
= wq
;
171 wq
= create_singlethread_workqueue("async");
174 dev_err(&adapter
->pdev
->dev
, "Cannot create async workqueue\n");
175 goto qlcnic_destroy_trans_wq
;
178 bc
->bc_async_wq
= wq
;
179 INIT_LIST_HEAD(&bc
->async_list
);
181 for (i
= 0; i
< num_vfs
; i
++) {
182 vf
= &sriov
->vf_info
[i
];
183 vf
->adapter
= adapter
;
184 vf
->pci_func
= qlcnic_sriov_virtid_fn(adapter
, i
);
185 mutex_init(&vf
->send_cmd_lock
);
186 spin_lock_init(&vf
->vlan_list_lock
);
187 INIT_LIST_HEAD(&vf
->rcv_act
.wait_list
);
188 INIT_LIST_HEAD(&vf
->rcv_pend
.wait_list
);
189 spin_lock_init(&vf
->rcv_act
.lock
);
190 spin_lock_init(&vf
->rcv_pend
.lock
);
191 init_completion(&vf
->ch_free_cmpl
);
193 INIT_WORK(&vf
->trans_work
, qlcnic_sriov_process_bc_cmd
);
195 if (qlcnic_sriov_pf_check(adapter
)) {
196 vp
= kzalloc(sizeof(struct qlcnic_vport
), GFP_KERNEL
);
199 goto qlcnic_destroy_async_wq
;
201 sriov
->vf_info
[i
].vp
= vp
;
202 vp
->vlan_mode
= QLC_GUEST_VLAN_MODE
;
203 vp
->max_tx_bw
= MAX_BW
;
204 vp
->spoofchk
= false;
205 random_ether_addr(vp
->mac
);
206 dev_info(&adapter
->pdev
->dev
,
207 "MAC Address %pM is configured for VF %d\n",
214 qlcnic_destroy_async_wq
:
215 destroy_workqueue(bc
->bc_async_wq
);
217 qlcnic_destroy_trans_wq
:
218 destroy_workqueue(bc
->bc_trans_wq
);
221 kfree(sriov
->vf_info
);
224 kfree(adapter
->ahw
->sriov
);
228 void qlcnic_sriov_cleanup_list(struct qlcnic_trans_list
*t_list
)
230 struct qlcnic_bc_trans
*trans
;
231 struct qlcnic_cmd_args cmd
;
234 spin_lock_irqsave(&t_list
->lock
, flags
);
236 while (!list_empty(&t_list
->wait_list
)) {
237 trans
= list_first_entry(&t_list
->wait_list
,
238 struct qlcnic_bc_trans
, list
);
239 list_del(&trans
->list
);
241 cmd
.req
.arg
= (u32
*)trans
->req_pay
;
242 cmd
.rsp
.arg
= (u32
*)trans
->rsp_pay
;
243 qlcnic_free_mbx_args(&cmd
);
244 qlcnic_sriov_cleanup_transaction(trans
);
247 spin_unlock_irqrestore(&t_list
->lock
, flags
);
250 void __qlcnic_sriov_cleanup(struct qlcnic_adapter
*adapter
)
252 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
253 struct qlcnic_back_channel
*bc
= &sriov
->bc
;
254 struct qlcnic_vf_info
*vf
;
257 if (!qlcnic_sriov_enable_check(adapter
))
260 qlcnic_sriov_cleanup_async_list(bc
);
261 destroy_workqueue(bc
->bc_async_wq
);
263 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
264 vf
= &sriov
->vf_info
[i
];
265 qlcnic_sriov_cleanup_list(&vf
->rcv_pend
);
266 cancel_work_sync(&vf
->trans_work
);
267 qlcnic_sriov_cleanup_list(&vf
->rcv_act
);
270 destroy_workqueue(bc
->bc_trans_wq
);
272 for (i
= 0; i
< sriov
->num_vfs
; i
++)
273 kfree(sriov
->vf_info
[i
].vp
);
275 kfree(sriov
->vf_info
);
276 kfree(adapter
->ahw
->sriov
);
279 static void qlcnic_sriov_vf_cleanup(struct qlcnic_adapter
*adapter
)
281 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
282 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
283 __qlcnic_sriov_cleanup(adapter
);
286 void qlcnic_sriov_cleanup(struct qlcnic_adapter
*adapter
)
288 if (!test_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
))
291 qlcnic_sriov_free_vlans(adapter
);
293 if (qlcnic_sriov_pf_check(adapter
))
294 qlcnic_sriov_pf_cleanup(adapter
);
296 if (qlcnic_sriov_vf_check(adapter
))
297 qlcnic_sriov_vf_cleanup(adapter
);
300 static int qlcnic_sriov_post_bc_msg(struct qlcnic_adapter
*adapter
, u32
*hdr
,
301 u32
*pay
, u8 pci_func
, u8 size
)
303 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
304 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
305 struct qlcnic_cmd_args cmd
;
306 unsigned long timeout
;
309 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
313 cmd
.func_num
= pci_func
;
314 cmd
.op_type
= QLC_83XX_MBX_POST_BC_OP
;
315 cmd
.cmd_op
= ((struct qlcnic_bc_hdr
*)hdr
)->cmd_op
;
317 err
= mbx
->ops
->enqueue_cmd(adapter
, &cmd
, &timeout
);
319 dev_err(&adapter
->pdev
->dev
,
320 "%s: Mailbox not available, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n",
321 __func__
, cmd
.cmd_op
, cmd
.type
, ahw
->pci_func
,
326 if (!wait_for_completion_timeout(&cmd
.completion
, timeout
)) {
327 dev_err(&adapter
->pdev
->dev
,
328 "%s: Mailbox command timed out, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n",
329 __func__
, cmd
.cmd_op
, cmd
.type
, ahw
->pci_func
,
331 flush_workqueue(mbx
->work_q
);
334 return cmd
.rsp_opcode
;
337 static void qlcnic_sriov_vf_cfg_buff_desc(struct qlcnic_adapter
*adapter
)
339 adapter
->num_rxd
= QLC_DEFAULT_RCV_DESCRIPTORS_SRIOV_VF
;
340 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
341 adapter
->num_jumbo_rxd
= QLC_DEFAULT_JUMBO_RCV_DESCRIPTORS_SRIOV_VF
;
342 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
343 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
344 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
347 int qlcnic_sriov_get_vf_vport_info(struct qlcnic_adapter
*adapter
,
348 struct qlcnic_info
*npar_info
, u16 vport_id
)
350 struct device
*dev
= &adapter
->pdev
->dev
;
351 struct qlcnic_cmd_args cmd
;
355 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_GET_NIC_INFO
);
359 cmd
.req
.arg
[1] = vport_id
<< 16 | 0x1;
360 err
= qlcnic_issue_cmd(adapter
, &cmd
);
362 dev_err(&adapter
->pdev
->dev
,
363 "Failed to get vport info, err=%d\n", err
);
364 qlcnic_free_mbx_args(&cmd
);
368 status
= cmd
.rsp
.arg
[2] & 0xffff;
370 npar_info
->min_tx_bw
= MSW(cmd
.rsp
.arg
[2]);
372 npar_info
->max_tx_bw
= LSW(cmd
.rsp
.arg
[3]);
374 npar_info
->max_tx_ques
= MSW(cmd
.rsp
.arg
[3]);
376 npar_info
->max_tx_mac_filters
= LSW(cmd
.rsp
.arg
[4]);
378 npar_info
->max_rx_mcast_mac_filters
= MSW(cmd
.rsp
.arg
[4]);
380 npar_info
->max_rx_ucast_mac_filters
= LSW(cmd
.rsp
.arg
[5]);
382 npar_info
->max_rx_ip_addr
= MSW(cmd
.rsp
.arg
[5]);
384 npar_info
->max_rx_lro_flow
= LSW(cmd
.rsp
.arg
[6]);
386 npar_info
->max_rx_status_rings
= MSW(cmd
.rsp
.arg
[6]);
388 npar_info
->max_rx_buf_rings
= LSW(cmd
.rsp
.arg
[7]);
390 npar_info
->max_rx_ques
= MSW(cmd
.rsp
.arg
[7]);
391 npar_info
->max_tx_vlan_keys
= LSW(cmd
.rsp
.arg
[8]);
392 npar_info
->max_local_ipv6_addrs
= MSW(cmd
.rsp
.arg
[8]);
393 npar_info
->max_remote_ipv6_addrs
= LSW(cmd
.rsp
.arg
[9]);
395 dev_info(dev
, "\n\tmin_tx_bw: %d, max_tx_bw: %d max_tx_ques: %d,\n"
396 "\tmax_tx_mac_filters: %d max_rx_mcast_mac_filters: %d,\n"
397 "\tmax_rx_ucast_mac_filters: 0x%x, max_rx_ip_addr: %d,\n"
398 "\tmax_rx_lro_flow: %d max_rx_status_rings: %d,\n"
399 "\tmax_rx_buf_rings: %d, max_rx_ques: %d, max_tx_vlan_keys %d\n"
400 "\tlocal_ipv6_addr: %d, remote_ipv6_addr: %d\n",
401 npar_info
->min_tx_bw
, npar_info
->max_tx_bw
,
402 npar_info
->max_tx_ques
, npar_info
->max_tx_mac_filters
,
403 npar_info
->max_rx_mcast_mac_filters
,
404 npar_info
->max_rx_ucast_mac_filters
, npar_info
->max_rx_ip_addr
,
405 npar_info
->max_rx_lro_flow
, npar_info
->max_rx_status_rings
,
406 npar_info
->max_rx_buf_rings
, npar_info
->max_rx_ques
,
407 npar_info
->max_tx_vlan_keys
, npar_info
->max_local_ipv6_addrs
,
408 npar_info
->max_remote_ipv6_addrs
);
410 qlcnic_free_mbx_args(&cmd
);
414 static int qlcnic_sriov_set_pvid_mode(struct qlcnic_adapter
*adapter
,
415 struct qlcnic_cmd_args
*cmd
)
417 adapter
->rx_pvid
= MSW(cmd
->rsp
.arg
[1]) & 0xffff;
418 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
422 static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter
*adapter
,
423 struct qlcnic_cmd_args
*cmd
)
425 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
429 if (sriov
->allowed_vlans
)
432 sriov
->any_vlan
= cmd
->rsp
.arg
[2] & 0xf;
433 sriov
->num_allowed_vlans
= cmd
->rsp
.arg
[2] >> 16;
434 dev_info(&adapter
->pdev
->dev
, "Number of allowed Guest VLANs = %d\n",
435 sriov
->num_allowed_vlans
);
437 qlcnic_sriov_alloc_vlans(adapter
);
439 if (!sriov
->any_vlan
)
442 num_vlans
= sriov
->num_allowed_vlans
;
443 sriov
->allowed_vlans
= kzalloc(sizeof(u16
) * num_vlans
, GFP_KERNEL
);
444 if (!sriov
->allowed_vlans
)
447 vlans
= (u16
*)&cmd
->rsp
.arg
[3];
448 for (i
= 0; i
< num_vlans
; i
++)
449 sriov
->allowed_vlans
[i
] = vlans
[i
];
454 static int qlcnic_sriov_get_vf_acl(struct qlcnic_adapter
*adapter
)
456 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
457 struct qlcnic_cmd_args cmd
;
460 ret
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
, QLCNIC_BC_CMD_GET_ACL
);
464 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
466 dev_err(&adapter
->pdev
->dev
, "Failed to get ACL, err=%d\n",
469 sriov
->vlan_mode
= cmd
.rsp
.arg
[1] & 0x3;
470 switch (sriov
->vlan_mode
) {
471 case QLC_GUEST_VLAN_MODE
:
472 ret
= qlcnic_sriov_set_guest_vlan_mode(adapter
, &cmd
);
475 ret
= qlcnic_sriov_set_pvid_mode(adapter
, &cmd
);
480 qlcnic_free_mbx_args(&cmd
);
484 static int qlcnic_sriov_vf_init_driver(struct qlcnic_adapter
*adapter
)
486 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
487 struct qlcnic_info nic_info
;
490 err
= qlcnic_sriov_get_vf_vport_info(adapter
, &nic_info
, 0);
494 ahw
->max_mc_count
= nic_info
.max_rx_mcast_mac_filters
;
496 err
= qlcnic_get_nic_info(adapter
, &nic_info
, ahw
->pci_func
);
500 if (qlcnic_83xx_get_port_info(adapter
))
503 qlcnic_sriov_vf_cfg_buff_desc(adapter
);
504 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
505 dev_info(&adapter
->pdev
->dev
, "HAL Version: %d\n",
506 adapter
->ahw
->fw_hal_version
);
508 ahw
->physical_port
= (u8
) nic_info
.phys_port
;
509 ahw
->switch_mode
= nic_info
.switch_mode
;
510 ahw
->max_mtu
= nic_info
.max_mtu
;
511 ahw
->op_mode
= nic_info
.op_mode
;
512 ahw
->capabilities
= nic_info
.capabilities
;
516 static int qlcnic_sriov_setup_vf(struct qlcnic_adapter
*adapter
,
521 adapter
->flags
|= QLCNIC_VLAN_FILTERING
;
522 adapter
->ahw
->total_nic_func
= 1;
523 INIT_LIST_HEAD(&adapter
->vf_mc_list
);
524 if (!qlcnic_use_msi_x
&& !!qlcnic_use_msi
)
525 dev_warn(&adapter
->pdev
->dev
,
526 "Device does not support MSI interrupts\n");
528 /* compute and set default and max tx/sds rings */
529 qlcnic_set_tx_ring_count(adapter
, QLCNIC_SINGLE_RING
);
530 qlcnic_set_sds_ring_count(adapter
, QLCNIC_SINGLE_RING
);
532 err
= qlcnic_setup_intr(adapter
);
534 dev_err(&adapter
->pdev
->dev
, "Failed to setup interrupt\n");
535 goto err_out_disable_msi
;
538 err
= qlcnic_83xx_setup_mbx_intr(adapter
);
540 goto err_out_disable_msi
;
542 err
= qlcnic_sriov_init(adapter
, 1);
544 goto err_out_disable_mbx_intr
;
546 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
548 goto err_out_cleanup_sriov
;
550 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
552 goto err_out_disable_bc_intr
;
554 err
= qlcnic_sriov_vf_init_driver(adapter
);
556 goto err_out_send_channel_term
;
558 err
= qlcnic_sriov_get_vf_acl(adapter
);
560 goto err_out_send_channel_term
;
562 err
= qlcnic_setup_netdev(adapter
, adapter
->netdev
, pci_using_dac
);
564 goto err_out_send_channel_term
;
566 pci_set_drvdata(adapter
->pdev
, adapter
);
567 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
568 adapter
->netdev
->name
);
570 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
571 adapter
->ahw
->idc
.delay
);
574 err_out_send_channel_term
:
575 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
577 err_out_disable_bc_intr
:
578 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
580 err_out_cleanup_sriov
:
581 __qlcnic_sriov_cleanup(adapter
);
583 err_out_disable_mbx_intr
:
584 qlcnic_83xx_free_mbx_intr(adapter
);
587 qlcnic_teardown_intr(adapter
);
591 static int qlcnic_sriov_check_dev_ready(struct qlcnic_adapter
*adapter
)
597 if (++adapter
->fw_fail_cnt
> QLC_BC_CMD_MAX_RETRY_CNT
)
599 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
600 } while (state
!= QLC_83XX_IDC_DEV_READY
);
605 int qlcnic_sriov_vf_init(struct qlcnic_adapter
*adapter
, int pci_using_dac
)
607 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
610 set_bit(QLC_83XX_MODULE_LOADED
, &ahw
->idc
.status
);
611 ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
612 ahw
->reset_context
= 0;
613 adapter
->fw_fail_cnt
= 0;
614 ahw
->msix_supported
= 1;
615 adapter
->need_fw_reset
= 0;
616 adapter
->flags
|= QLCNIC_TX_INTR_SHARED
;
618 err
= qlcnic_sriov_check_dev_ready(adapter
);
622 err
= qlcnic_sriov_setup_vf(adapter
, pci_using_dac
);
626 if (qlcnic_read_mac_addr(adapter
))
627 dev_warn(&adapter
->pdev
->dev
, "failed to read mac addr\n");
629 INIT_DELAYED_WORK(&adapter
->idc_aen_work
, qlcnic_83xx_idc_aen_work
);
631 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
635 void qlcnic_sriov_vf_set_ops(struct qlcnic_adapter
*adapter
)
637 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
639 ahw
->op_mode
= QLCNIC_SRIOV_VF_FUNC
;
640 dev_info(&adapter
->pdev
->dev
,
641 "HAL Version: %d Non Privileged SRIOV function\n",
642 ahw
->fw_hal_version
);
643 adapter
->nic_ops
= &qlcnic_sriov_vf_ops
;
644 set_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
);
648 void qlcnic_sriov_vf_register_map(struct qlcnic_hardware_context
*ahw
)
650 ahw
->hw_ops
= &qlcnic_sriov_vf_hw_ops
;
651 ahw
->reg_tbl
= (u32
*)qlcnic_83xx_reg_tbl
;
652 ahw
->ext_reg_tbl
= (u32
*)qlcnic_83xx_ext_reg_tbl
;
655 static u32
qlcnic_sriov_get_bc_paysize(u32 real_pay_size
, u8 curr_frag
)
659 pay_size
= real_pay_size
/ ((curr_frag
+ 1) * QLC_BC_PAYLOAD_SZ
);
662 pay_size
= QLC_BC_PAYLOAD_SZ
;
664 pay_size
= real_pay_size
% QLC_BC_PAYLOAD_SZ
;
669 int qlcnic_sriov_func_to_index(struct qlcnic_adapter
*adapter
, u8 pci_func
)
671 struct qlcnic_vf_info
*vf_info
= adapter
->ahw
->sriov
->vf_info
;
674 if (qlcnic_sriov_vf_check(adapter
))
677 for (i
= 0; i
< adapter
->ahw
->sriov
->num_vfs
; i
++) {
678 if (vf_info
[i
].pci_func
== pci_func
)
685 static inline int qlcnic_sriov_alloc_bc_trans(struct qlcnic_bc_trans
**trans
)
687 *trans
= kzalloc(sizeof(struct qlcnic_bc_trans
), GFP_ATOMIC
);
691 init_completion(&(*trans
)->resp_cmpl
);
695 static inline int qlcnic_sriov_alloc_bc_msg(struct qlcnic_bc_hdr
**hdr
,
698 *hdr
= kzalloc(sizeof(struct qlcnic_bc_hdr
) * size
, GFP_ATOMIC
);
705 static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args
*mbx
, u32 type
)
707 const struct qlcnic_mailbox_metadata
*mbx_tbl
;
710 mbx_tbl
= qlcnic_sriov_bc_mbx_tbl
;
711 size
= ARRAY_SIZE(qlcnic_sriov_bc_mbx_tbl
);
713 for (i
= 0; i
< size
; i
++) {
714 if (type
== mbx_tbl
[i
].cmd
) {
715 mbx
->op_type
= QLC_BC_CMD
;
716 mbx
->req
.num
= mbx_tbl
[i
].in_args
;
717 mbx
->rsp
.num
= mbx_tbl
[i
].out_args
;
718 mbx
->req
.arg
= kcalloc(mbx
->req
.num
, sizeof(u32
),
722 mbx
->rsp
.arg
= kcalloc(mbx
->rsp
.num
, sizeof(u32
),
729 memset(mbx
->req
.arg
, 0, sizeof(u32
) * mbx
->req
.num
);
730 memset(mbx
->rsp
.arg
, 0, sizeof(u32
) * mbx
->rsp
.num
);
731 mbx
->req
.arg
[0] = (type
| (mbx
->req
.num
<< 16) |
733 mbx
->rsp
.arg
[0] = (type
& 0xffff) | mbx
->rsp
.num
<< 16;
740 static int qlcnic_sriov_prepare_bc_hdr(struct qlcnic_bc_trans
*trans
,
741 struct qlcnic_cmd_args
*cmd
,
742 u16 seq
, u8 msg_type
)
744 struct qlcnic_bc_hdr
*hdr
;
746 u32 num_regs
, bc_pay_sz
;
748 u8 cmd_op
, num_frags
, t_num_frags
;
750 bc_pay_sz
= QLC_BC_PAYLOAD_SZ
;
751 if (msg_type
== QLC_BC_COMMAND
) {
752 trans
->req_pay
= (struct qlcnic_bc_payload
*)cmd
->req
.arg
;
753 trans
->rsp_pay
= (struct qlcnic_bc_payload
*)cmd
->rsp
.arg
;
754 num_regs
= cmd
->req
.num
;
755 trans
->req_pay_size
= (num_regs
* 4);
756 num_regs
= cmd
->rsp
.num
;
757 trans
->rsp_pay_size
= (num_regs
* 4);
758 cmd_op
= cmd
->req
.arg
[0] & 0xff;
759 remainder
= (trans
->req_pay_size
) % (bc_pay_sz
);
760 num_frags
= (trans
->req_pay_size
) / (bc_pay_sz
);
763 t_num_frags
= num_frags
;
764 if (qlcnic_sriov_alloc_bc_msg(&trans
->req_hdr
, num_frags
))
766 remainder
= (trans
->rsp_pay_size
) % (bc_pay_sz
);
767 num_frags
= (trans
->rsp_pay_size
) / (bc_pay_sz
);
770 if (qlcnic_sriov_alloc_bc_msg(&trans
->rsp_hdr
, num_frags
))
772 num_frags
= t_num_frags
;
773 hdr
= trans
->req_hdr
;
775 cmd
->req
.arg
= (u32
*)trans
->req_pay
;
776 cmd
->rsp
.arg
= (u32
*)trans
->rsp_pay
;
777 cmd_op
= cmd
->req
.arg
[0] & 0xff;
778 cmd
->cmd_op
= cmd_op
;
779 remainder
= (trans
->rsp_pay_size
) % (bc_pay_sz
);
780 num_frags
= (trans
->rsp_pay_size
) / (bc_pay_sz
);
783 cmd
->req
.num
= trans
->req_pay_size
/ 4;
784 cmd
->rsp
.num
= trans
->rsp_pay_size
/ 4;
785 hdr
= trans
->rsp_hdr
;
786 cmd
->op_type
= trans
->req_hdr
->op_type
;
789 trans
->trans_id
= seq
;
790 trans
->cmd_id
= cmd_op
;
791 for (i
= 0; i
< num_frags
; i
++) {
793 hdr
[i
].msg_type
= msg_type
;
794 hdr
[i
].op_type
= cmd
->op_type
;
796 hdr
[i
].num_frags
= num_frags
;
797 hdr
[i
].frag_num
= i
+ 1;
798 hdr
[i
].cmd_op
= cmd_op
;
804 static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans
*trans
)
808 kfree(trans
->req_hdr
);
809 kfree(trans
->rsp_hdr
);
813 static int qlcnic_sriov_clear_trans(struct qlcnic_vf_info
*vf
,
814 struct qlcnic_bc_trans
*trans
, u8 type
)
816 struct qlcnic_trans_list
*t_list
;
820 if (type
== QLC_BC_RESPONSE
) {
821 t_list
= &vf
->rcv_act
;
822 spin_lock_irqsave(&t_list
->lock
, flags
);
824 list_del(&trans
->list
);
825 if (t_list
->count
> 0)
827 spin_unlock_irqrestore(&t_list
->lock
, flags
);
829 if (type
== QLC_BC_COMMAND
) {
830 while (test_and_set_bit(QLC_BC_VF_SEND
, &vf
->state
))
833 clear_bit(QLC_BC_VF_SEND
, &vf
->state
);
838 static void qlcnic_sriov_schedule_bc_cmd(struct qlcnic_sriov
*sriov
,
839 struct qlcnic_vf_info
*vf
,
842 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
) ||
843 vf
->adapter
->need_fw_reset
)
846 queue_work(sriov
->bc
.bc_trans_wq
, &vf
->trans_work
);
849 static inline void qlcnic_sriov_wait_for_resp(struct qlcnic_bc_trans
*trans
)
851 struct completion
*cmpl
= &trans
->resp_cmpl
;
853 if (wait_for_completion_timeout(cmpl
, QLC_MBOX_RESP_TIMEOUT
))
854 trans
->trans_state
= QLC_END
;
856 trans
->trans_state
= QLC_ABORT
;
861 static void qlcnic_sriov_handle_multi_frags(struct qlcnic_bc_trans
*trans
,
864 if (type
== QLC_BC_RESPONSE
) {
865 trans
->curr_rsp_frag
++;
866 if (trans
->curr_rsp_frag
< trans
->rsp_hdr
->num_frags
)
867 trans
->trans_state
= QLC_INIT
;
869 trans
->trans_state
= QLC_END
;
871 trans
->curr_req_frag
++;
872 if (trans
->curr_req_frag
< trans
->req_hdr
->num_frags
)
873 trans
->trans_state
= QLC_INIT
;
875 trans
->trans_state
= QLC_WAIT_FOR_RESP
;
879 static void qlcnic_sriov_wait_for_channel_free(struct qlcnic_bc_trans
*trans
,
882 struct qlcnic_vf_info
*vf
= trans
->vf
;
883 struct completion
*cmpl
= &vf
->ch_free_cmpl
;
885 if (!wait_for_completion_timeout(cmpl
, QLC_MBOX_CH_FREE_TIMEOUT
)) {
886 trans
->trans_state
= QLC_ABORT
;
890 clear_bit(QLC_BC_VF_CHANNEL
, &vf
->state
);
891 qlcnic_sriov_handle_multi_frags(trans
, type
);
894 static void qlcnic_sriov_pull_bc_msg(struct qlcnic_adapter
*adapter
,
895 u32
*hdr
, u32
*pay
, u32 size
)
897 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
899 u8 i
, max
= 2, hdr_size
, j
;
901 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
902 max
= (size
/ sizeof(u32
)) + hdr_size
;
904 fw_mbx
= readl(QLCNIC_MBX_FW(ahw
, 0));
905 for (i
= 2, j
= 0; j
< hdr_size
; i
++, j
++)
906 *(hdr
++) = readl(QLCNIC_MBX_FW(ahw
, i
));
907 for (; j
< max
; i
++, j
++)
908 *(pay
++) = readl(QLCNIC_MBX_FW(ahw
, i
));
911 static int __qlcnic_sriov_issue_bc_post(struct qlcnic_vf_info
*vf
)
917 if (!test_and_set_bit(QLC_BC_VF_CHANNEL
, &vf
->state
)) {
927 static int qlcnic_sriov_issue_bc_post(struct qlcnic_bc_trans
*trans
, u8 type
)
929 struct qlcnic_vf_info
*vf
= trans
->vf
;
930 u32 pay_size
, hdr_size
;
933 u8 pci_func
= trans
->func_id
;
935 if (__qlcnic_sriov_issue_bc_post(vf
))
938 if (type
== QLC_BC_COMMAND
) {
939 hdr
= (u32
*)(trans
->req_hdr
+ trans
->curr_req_frag
);
940 pay
= (u32
*)(trans
->req_pay
+ trans
->curr_req_frag
);
941 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
942 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
943 trans
->curr_req_frag
);
944 pay_size
= (pay_size
/ sizeof(u32
));
946 hdr
= (u32
*)(trans
->rsp_hdr
+ trans
->curr_rsp_frag
);
947 pay
= (u32
*)(trans
->rsp_pay
+ trans
->curr_rsp_frag
);
948 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
949 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->rsp_pay_size
,
950 trans
->curr_rsp_frag
);
951 pay_size
= (pay_size
/ sizeof(u32
));
954 ret
= qlcnic_sriov_post_bc_msg(vf
->adapter
, hdr
, pay
,
959 static int __qlcnic_sriov_send_bc_msg(struct qlcnic_bc_trans
*trans
,
960 struct qlcnic_vf_info
*vf
, u8 type
)
966 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
) ||
967 vf
->adapter
->need_fw_reset
)
968 trans
->trans_state
= QLC_ABORT
;
970 switch (trans
->trans_state
) {
972 trans
->trans_state
= QLC_WAIT_FOR_CHANNEL_FREE
;
973 if (qlcnic_sriov_issue_bc_post(trans
, type
))
974 trans
->trans_state
= QLC_ABORT
;
976 case QLC_WAIT_FOR_CHANNEL_FREE
:
977 qlcnic_sriov_wait_for_channel_free(trans
, type
);
979 case QLC_WAIT_FOR_RESP
:
980 qlcnic_sriov_wait_for_resp(trans
);
989 clear_bit(QLC_BC_VF_CHANNEL
, &vf
->state
);
999 static int qlcnic_sriov_send_bc_cmd(struct qlcnic_adapter
*adapter
,
1000 struct qlcnic_bc_trans
*trans
, int pci_func
)
1002 struct qlcnic_vf_info
*vf
;
1003 int err
, index
= qlcnic_sriov_func_to_index(adapter
, pci_func
);
1008 vf
= &adapter
->ahw
->sriov
->vf_info
[index
];
1010 trans
->func_id
= pci_func
;
1012 if (!test_bit(QLC_BC_VF_STATE
, &vf
->state
)) {
1013 if (qlcnic_sriov_pf_check(adapter
))
1015 if (qlcnic_sriov_vf_check(adapter
) &&
1016 trans
->cmd_id
!= QLCNIC_BC_CMD_CHANNEL_INIT
)
1020 mutex_lock(&vf
->send_cmd_lock
);
1021 vf
->send_cmd
= trans
;
1022 err
= __qlcnic_sriov_send_bc_msg(trans
, vf
, QLC_BC_COMMAND
);
1023 qlcnic_sriov_clear_trans(vf
, trans
, QLC_BC_COMMAND
);
1024 mutex_unlock(&vf
->send_cmd_lock
);
1028 static void __qlcnic_sriov_process_bc_cmd(struct qlcnic_adapter
*adapter
,
1029 struct qlcnic_bc_trans
*trans
,
1030 struct qlcnic_cmd_args
*cmd
)
1032 #ifdef CONFIG_QLCNIC_SRIOV
1033 if (qlcnic_sriov_pf_check(adapter
)) {
1034 qlcnic_sriov_pf_process_bc_cmd(adapter
, trans
, cmd
);
1038 cmd
->rsp
.arg
[0] |= (0x9 << 25);
1042 static void qlcnic_sriov_process_bc_cmd(struct work_struct
*work
)
1044 struct qlcnic_vf_info
*vf
= container_of(work
, struct qlcnic_vf_info
,
1046 struct qlcnic_bc_trans
*trans
= NULL
;
1047 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1048 struct qlcnic_cmd_args cmd
;
1051 if (adapter
->need_fw_reset
)
1054 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
))
1057 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
1058 trans
= list_first_entry(&vf
->rcv_act
.wait_list
,
1059 struct qlcnic_bc_trans
, list
);
1060 adapter
= vf
->adapter
;
1062 if (qlcnic_sriov_prepare_bc_hdr(trans
, &cmd
, trans
->req_hdr
->seq_id
,
1066 __qlcnic_sriov_process_bc_cmd(adapter
, trans
, &cmd
);
1067 trans
->trans_state
= QLC_INIT
;
1068 __qlcnic_sriov_send_bc_msg(trans
, vf
, QLC_BC_RESPONSE
);
1071 qlcnic_free_mbx_args(&cmd
);
1072 req
= qlcnic_sriov_clear_trans(vf
, trans
, QLC_BC_RESPONSE
);
1073 qlcnic_sriov_cleanup_transaction(trans
);
1075 qlcnic_sriov_schedule_bc_cmd(adapter
->ahw
->sriov
, vf
,
1076 qlcnic_sriov_process_bc_cmd
);
1079 static void qlcnic_sriov_handle_bc_resp(struct qlcnic_bc_hdr
*hdr
,
1080 struct qlcnic_vf_info
*vf
)
1082 struct qlcnic_bc_trans
*trans
;
1085 if (test_and_set_bit(QLC_BC_VF_SEND
, &vf
->state
))
1088 trans
= vf
->send_cmd
;
1093 if (trans
->trans_id
!= hdr
->seq_id
)
1096 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->rsp_pay_size
,
1097 trans
->curr_rsp_frag
);
1098 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1099 (u32
*)(trans
->rsp_hdr
+ trans
->curr_rsp_frag
),
1100 (u32
*)(trans
->rsp_pay
+ trans
->curr_rsp_frag
),
1102 if (++trans
->curr_rsp_frag
< trans
->rsp_hdr
->num_frags
)
1105 complete(&trans
->resp_cmpl
);
1108 clear_bit(QLC_BC_VF_SEND
, &vf
->state
);
1111 int __qlcnic_sriov_add_act_list(struct qlcnic_sriov
*sriov
,
1112 struct qlcnic_vf_info
*vf
,
1113 struct qlcnic_bc_trans
*trans
)
1115 struct qlcnic_trans_list
*t_list
= &vf
->rcv_act
;
1118 list_add_tail(&trans
->list
, &t_list
->wait_list
);
1119 if (t_list
->count
== 1)
1120 qlcnic_sriov_schedule_bc_cmd(sriov
, vf
,
1121 qlcnic_sriov_process_bc_cmd
);
1125 static int qlcnic_sriov_add_act_list(struct qlcnic_sriov
*sriov
,
1126 struct qlcnic_vf_info
*vf
,
1127 struct qlcnic_bc_trans
*trans
)
1129 struct qlcnic_trans_list
*t_list
= &vf
->rcv_act
;
1131 spin_lock(&t_list
->lock
);
1133 __qlcnic_sriov_add_act_list(sriov
, vf
, trans
);
1135 spin_unlock(&t_list
->lock
);
1139 static void qlcnic_sriov_handle_pending_trans(struct qlcnic_sriov
*sriov
,
1140 struct qlcnic_vf_info
*vf
,
1141 struct qlcnic_bc_hdr
*hdr
)
1143 struct qlcnic_bc_trans
*trans
= NULL
;
1144 struct list_head
*node
;
1145 u32 pay_size
, curr_frag
;
1146 u8 found
= 0, active
= 0;
1148 spin_lock(&vf
->rcv_pend
.lock
);
1149 if (vf
->rcv_pend
.count
> 0) {
1150 list_for_each(node
, &vf
->rcv_pend
.wait_list
) {
1151 trans
= list_entry(node
, struct qlcnic_bc_trans
, list
);
1152 if (trans
->trans_id
== hdr
->seq_id
) {
1160 curr_frag
= trans
->curr_req_frag
;
1161 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
1163 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1164 (u32
*)(trans
->req_hdr
+ curr_frag
),
1165 (u32
*)(trans
->req_pay
+ curr_frag
),
1167 trans
->curr_req_frag
++;
1168 if (trans
->curr_req_frag
>= hdr
->num_frags
) {
1169 vf
->rcv_pend
.count
--;
1170 list_del(&trans
->list
);
1174 spin_unlock(&vf
->rcv_pend
.lock
);
1177 if (qlcnic_sriov_add_act_list(sriov
, vf
, trans
))
1178 qlcnic_sriov_cleanup_transaction(trans
);
1183 static void qlcnic_sriov_handle_bc_cmd(struct qlcnic_sriov
*sriov
,
1184 struct qlcnic_bc_hdr
*hdr
,
1185 struct qlcnic_vf_info
*vf
)
1187 struct qlcnic_bc_trans
*trans
;
1188 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1189 struct qlcnic_cmd_args cmd
;
1194 if (adapter
->need_fw_reset
)
1197 if (!test_bit(QLC_BC_VF_STATE
, &vf
->state
) &&
1198 hdr
->op_type
!= QLC_BC_CMD
&&
1199 hdr
->cmd_op
!= QLCNIC_BC_CMD_CHANNEL_INIT
)
1202 if (hdr
->frag_num
> 1) {
1203 qlcnic_sriov_handle_pending_trans(sriov
, vf
, hdr
);
1207 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
1208 cmd_op
= hdr
->cmd_op
;
1209 if (qlcnic_sriov_alloc_bc_trans(&trans
))
1212 if (hdr
->op_type
== QLC_BC_CMD
)
1213 err
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
, cmd_op
);
1215 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, cmd_op
);
1218 qlcnic_sriov_cleanup_transaction(trans
);
1222 cmd
.op_type
= hdr
->op_type
;
1223 if (qlcnic_sriov_prepare_bc_hdr(trans
, &cmd
, hdr
->seq_id
,
1225 qlcnic_free_mbx_args(&cmd
);
1226 qlcnic_sriov_cleanup_transaction(trans
);
1230 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
1231 trans
->curr_req_frag
);
1232 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1233 (u32
*)(trans
->req_hdr
+ trans
->curr_req_frag
),
1234 (u32
*)(trans
->req_pay
+ trans
->curr_req_frag
),
1236 trans
->func_id
= vf
->pci_func
;
1238 trans
->trans_id
= hdr
->seq_id
;
1239 trans
->curr_req_frag
++;
1241 if (qlcnic_sriov_soft_flr_check(adapter
, trans
, vf
))
1244 if (trans
->curr_req_frag
== trans
->req_hdr
->num_frags
) {
1245 if (qlcnic_sriov_add_act_list(sriov
, vf
, trans
)) {
1246 qlcnic_free_mbx_args(&cmd
);
1247 qlcnic_sriov_cleanup_transaction(trans
);
1250 spin_lock(&vf
->rcv_pend
.lock
);
1251 list_add_tail(&trans
->list
, &vf
->rcv_pend
.wait_list
);
1252 vf
->rcv_pend
.count
++;
1253 spin_unlock(&vf
->rcv_pend
.lock
);
1257 static void qlcnic_sriov_handle_msg_event(struct qlcnic_sriov
*sriov
,
1258 struct qlcnic_vf_info
*vf
)
1260 struct qlcnic_bc_hdr hdr
;
1261 u32
*ptr
= (u32
*)&hdr
;
1264 for (i
= 2; i
< 6; i
++)
1265 ptr
[i
- 2] = readl(QLCNIC_MBX_FW(vf
->adapter
->ahw
, i
));
1266 msg_type
= hdr
.msg_type
;
1269 case QLC_BC_COMMAND
:
1270 qlcnic_sriov_handle_bc_cmd(sriov
, &hdr
, vf
);
1272 case QLC_BC_RESPONSE
:
1273 qlcnic_sriov_handle_bc_resp(&hdr
, vf
);
1278 static void qlcnic_sriov_handle_flr_event(struct qlcnic_sriov
*sriov
,
1279 struct qlcnic_vf_info
*vf
)
1281 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1283 if (qlcnic_sriov_pf_check(adapter
))
1284 qlcnic_sriov_pf_handle_flr(sriov
, vf
);
1286 dev_err(&adapter
->pdev
->dev
,
1287 "Invalid event to VF. VF should not get FLR event\n");
1290 void qlcnic_sriov_handle_bc_event(struct qlcnic_adapter
*adapter
, u32 event
)
1292 struct qlcnic_vf_info
*vf
;
1293 struct qlcnic_sriov
*sriov
;
1297 sriov
= adapter
->ahw
->sriov
;
1298 pci_func
= qlcnic_sriov_target_func_id(event
);
1299 index
= qlcnic_sriov_func_to_index(adapter
, pci_func
);
1304 vf
= &sriov
->vf_info
[index
];
1305 vf
->pci_func
= pci_func
;
1307 if (qlcnic_sriov_channel_free_check(event
))
1308 complete(&vf
->ch_free_cmpl
);
1310 if (qlcnic_sriov_flr_check(event
)) {
1311 qlcnic_sriov_handle_flr_event(sriov
, vf
);
1315 if (qlcnic_sriov_bc_msg_check(event
))
1316 qlcnic_sriov_handle_msg_event(sriov
, vf
);
1319 int qlcnic_sriov_cfg_bc_intr(struct qlcnic_adapter
*adapter
, u8 enable
)
1321 struct qlcnic_cmd_args cmd
;
1324 if (!test_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
))
1327 if (qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_BC_EVENT_SETUP
))
1331 cmd
.req
.arg
[1] = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);
1333 err
= qlcnic_83xx_issue_cmd(adapter
, &cmd
);
1335 if (err
!= QLCNIC_RCODE_SUCCESS
) {
1336 dev_err(&adapter
->pdev
->dev
,
1337 "Failed to %s bc events, err=%d\n",
1338 (enable
? "enable" : "disable"), err
);
1341 qlcnic_free_mbx_args(&cmd
);
1345 static int qlcnic_sriov_retry_bc_cmd(struct qlcnic_adapter
*adapter
,
1346 struct qlcnic_bc_trans
*trans
)
1348 u8 max
= QLC_BC_CMD_MAX_RETRY_CNT
;
1351 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1352 if (state
== QLC_83XX_IDC_DEV_READY
) {
1354 clear_bit(QLC_BC_VF_CHANNEL
, &trans
->vf
->state
);
1355 trans
->trans_state
= QLC_INIT
;
1356 if (++adapter
->fw_fail_cnt
> max
)
1365 static int __qlcnic_sriov_issue_cmd(struct qlcnic_adapter
*adapter
,
1366 struct qlcnic_cmd_args
*cmd
)
1368 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1369 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
1370 struct device
*dev
= &adapter
->pdev
->dev
;
1371 struct qlcnic_bc_trans
*trans
;
1373 u32 rsp_data
, opcode
, mbx_err_code
, rsp
;
1374 u16 seq
= ++adapter
->ahw
->sriov
->bc
.trans_counter
;
1375 u8 func
= ahw
->pci_func
;
1377 rsp
= qlcnic_sriov_alloc_bc_trans(&trans
);
1381 rsp
= qlcnic_sriov_prepare_bc_hdr(trans
, cmd
, seq
, QLC_BC_COMMAND
);
1383 goto cleanup_transaction
;
1386 if (!test_bit(QLC_83XX_MBX_READY
, &mbx
->status
)) {
1388 QLCDB(adapter
, DRV
, "MBX not Ready!(cmd 0x%x) for VF 0x%x\n",
1389 QLCNIC_MBX_RSP(cmd
->req
.arg
[0]), func
);
1393 err
= qlcnic_sriov_send_bc_cmd(adapter
, trans
, func
);
1395 dev_err(dev
, "MBX command 0x%x timed out for VF %d\n",
1396 (cmd
->req
.arg
[0] & 0xffff), func
);
1397 rsp
= QLCNIC_RCODE_TIMEOUT
;
1399 /* After adapter reset PF driver may take some time to
1400 * respond to VF's request. Retry request till maximum retries.
1402 if ((trans
->req_hdr
->cmd_op
== QLCNIC_BC_CMD_CHANNEL_INIT
) &&
1403 !qlcnic_sriov_retry_bc_cmd(adapter
, trans
))
1409 rsp_data
= cmd
->rsp
.arg
[0];
1410 mbx_err_code
= QLCNIC_MBX_STATUS(rsp_data
);
1411 opcode
= QLCNIC_MBX_RSP(cmd
->req
.arg
[0]);
1413 if ((mbx_err_code
== QLCNIC_MBX_RSP_OK
) ||
1414 (mbx_err_code
== QLCNIC_MBX_PORT_RSP_OK
)) {
1415 rsp
= QLCNIC_RCODE_SUCCESS
;
1417 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
) {
1418 rsp
= QLCNIC_RCODE_SUCCESS
;
1425 "MBX command 0x%x failed with err:0x%x for VF %d\n",
1426 opcode
, mbx_err_code
, func
);
1431 if (rsp
== QLCNIC_RCODE_TIMEOUT
) {
1432 ahw
->reset_context
= 1;
1433 adapter
->need_fw_reset
= 1;
1434 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1437 cleanup_transaction
:
1438 qlcnic_sriov_cleanup_transaction(trans
);
1441 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
) {
1442 qlcnic_free_mbx_args(cmd
);
1450 static int qlcnic_sriov_issue_cmd(struct qlcnic_adapter
*adapter
,
1451 struct qlcnic_cmd_args
*cmd
)
1453 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
)
1454 return qlcnic_sriov_async_issue_cmd(adapter
, cmd
);
1456 return __qlcnic_sriov_issue_cmd(adapter
, cmd
);
1459 static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter
*adapter
, u8 cmd_op
)
1461 struct qlcnic_cmd_args cmd
;
1462 struct qlcnic_vf_info
*vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1465 if (qlcnic_sriov_alloc_bc_mbx_args(&cmd
, cmd_op
))
1468 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
1470 dev_err(&adapter
->pdev
->dev
,
1471 "Failed bc channel %s %d\n", cmd_op
? "term" : "init",
1476 cmd_op
= (cmd
.rsp
.arg
[0] & 0xff);
1477 if (cmd
.rsp
.arg
[0] >> 25 == 2)
1479 if (cmd_op
== QLCNIC_BC_CMD_CHANNEL_INIT
)
1480 set_bit(QLC_BC_VF_STATE
, &vf
->state
);
1482 clear_bit(QLC_BC_VF_STATE
, &vf
->state
);
1485 qlcnic_free_mbx_args(&cmd
);
1489 static void qlcnic_vf_add_mc_list(struct net_device
*netdev
, const u8
*mac
)
1491 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1492 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
1493 struct qlcnic_vf_info
*vf
;
1497 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1499 if (!qlcnic_sriov_check_any_vlan(vf
)) {
1500 qlcnic_nic_add_mac(adapter
, mac
, 0);
1502 spin_lock(&vf
->vlan_list_lock
);
1503 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1504 vlan_id
= vf
->sriov_vlans
[i
];
1506 qlcnic_nic_add_mac(adapter
, mac
, vlan_id
);
1508 spin_unlock(&vf
->vlan_list_lock
);
1509 if (qlcnic_84xx_check(adapter
))
1510 qlcnic_nic_add_mac(adapter
, mac
, 0);
1514 void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel
*bc
)
1516 struct list_head
*head
= &bc
->async_list
;
1517 struct qlcnic_async_work_list
*entry
;
1519 flush_workqueue(bc
->bc_async_wq
);
1520 while (!list_empty(head
)) {
1521 entry
= list_entry(head
->next
, struct qlcnic_async_work_list
,
1523 cancel_work_sync(&entry
->work
);
1524 list_del(&entry
->list
);
1529 void qlcnic_sriov_vf_set_multi(struct net_device
*netdev
)
1531 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1532 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1533 static const u8 bcast_addr
[ETH_ALEN
] = {
1534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1536 struct netdev_hw_addr
*ha
;
1537 u32 mode
= VPORT_MISS_MODE_DROP
;
1539 if (!test_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
))
1542 if (netdev
->flags
& IFF_PROMISC
) {
1543 if (!(adapter
->flags
& QLCNIC_PROMISC_DISABLED
))
1544 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
1545 } else if ((netdev
->flags
& IFF_ALLMULTI
) ||
1546 (netdev_mc_count(netdev
) > ahw
->max_mc_count
)) {
1547 mode
= VPORT_MISS_MODE_ACCEPT_MULTI
;
1549 qlcnic_vf_add_mc_list(netdev
, bcast_addr
);
1550 if (!netdev_mc_empty(netdev
)) {
1551 netdev_for_each_mc_addr(ha
, netdev
)
1552 qlcnic_vf_add_mc_list(netdev
, ha
->addr
);
1556 /* configure unicast MAC address, if there is not sufficient space
1557 * to store all the unicast addresses then enable promiscuous mode
1559 if (netdev_uc_count(netdev
) > ahw
->max_uc_count
) {
1560 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
1561 } else if (!netdev_uc_empty(netdev
)) {
1562 netdev_for_each_uc_addr(ha
, netdev
)
1563 qlcnic_vf_add_mc_list(netdev
, ha
->addr
);
1566 if (adapter
->pdev
->is_virtfn
) {
1567 if (mode
== VPORT_MISS_MODE_ACCEPT_ALL
&&
1568 !adapter
->fdb_mac_learn
) {
1569 qlcnic_alloc_lb_filters_mem(adapter
);
1570 adapter
->drv_mac_learn
= 1;
1571 adapter
->rx_mac_learn
= true;
1573 adapter
->drv_mac_learn
= 0;
1574 adapter
->rx_mac_learn
= false;
1578 qlcnic_nic_set_promisc(adapter
, mode
);
1581 static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct
*work
)
1583 struct qlcnic_async_work_list
*entry
;
1584 struct qlcnic_adapter
*adapter
;
1585 struct qlcnic_cmd_args
*cmd
;
1587 entry
= container_of(work
, struct qlcnic_async_work_list
, work
);
1588 adapter
= entry
->ptr
;
1590 __qlcnic_sriov_issue_cmd(adapter
, cmd
);
1594 static struct qlcnic_async_work_list
*
1595 qlcnic_sriov_get_free_node_async_work(struct qlcnic_back_channel
*bc
)
1597 struct list_head
*node
;
1598 struct qlcnic_async_work_list
*entry
= NULL
;
1601 list_for_each(node
, &bc
->async_list
) {
1602 entry
= list_entry(node
, struct qlcnic_async_work_list
, list
);
1603 if (!work_pending(&entry
->work
)) {
1610 entry
= kzalloc(sizeof(struct qlcnic_async_work_list
),
1614 list_add_tail(&entry
->list
, &bc
->async_list
);
1620 static void qlcnic_sriov_schedule_async_cmd(struct qlcnic_back_channel
*bc
,
1621 work_func_t func
, void *data
,
1622 struct qlcnic_cmd_args
*cmd
)
1624 struct qlcnic_async_work_list
*entry
= NULL
;
1626 entry
= qlcnic_sriov_get_free_node_async_work(bc
);
1632 INIT_WORK(&entry
->work
, func
);
1633 queue_work(bc
->bc_async_wq
, &entry
->work
);
1636 static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter
*adapter
,
1637 struct qlcnic_cmd_args
*cmd
)
1640 struct qlcnic_back_channel
*bc
= &adapter
->ahw
->sriov
->bc
;
1642 if (adapter
->need_fw_reset
)
1645 qlcnic_sriov_schedule_async_cmd(bc
, qlcnic_sriov_handle_async_issue_cmd
,
1650 static int qlcnic_sriov_vf_reinit_driver(struct qlcnic_adapter
*adapter
)
1654 adapter
->need_fw_reset
= 0;
1655 qlcnic_83xx_reinit_mbx_work(adapter
->ahw
->mailbox
);
1656 qlcnic_83xx_enable_mbx_interrupt(adapter
);
1658 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
1662 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
1664 goto err_out_cleanup_bc_intr
;
1666 err
= qlcnic_sriov_vf_init_driver(adapter
);
1668 goto err_out_term_channel
;
1672 err_out_term_channel
:
1673 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
1675 err_out_cleanup_bc_intr
:
1676 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
1680 static void qlcnic_sriov_vf_attach(struct qlcnic_adapter
*adapter
)
1682 struct net_device
*netdev
= adapter
->netdev
;
1684 if (netif_running(netdev
)) {
1685 if (!qlcnic_up(adapter
, netdev
))
1686 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1689 netif_device_attach(netdev
);
1692 static void qlcnic_sriov_vf_detach(struct qlcnic_adapter
*adapter
)
1694 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1695 struct qlcnic_intrpt_config
*intr_tbl
= ahw
->intr_tbl
;
1696 struct net_device
*netdev
= adapter
->netdev
;
1697 u8 i
, max_ints
= ahw
->num_msix
- 1;
1699 netif_device_detach(netdev
);
1700 qlcnic_83xx_detach_mailbox_work(adapter
);
1701 qlcnic_83xx_disable_mbx_intr(adapter
);
1703 if (netif_running(netdev
))
1704 qlcnic_down(adapter
, netdev
);
1706 for (i
= 0; i
< max_ints
; i
++) {
1708 intr_tbl
[i
].enabled
= 0;
1709 intr_tbl
[i
].src
= 0;
1711 ahw
->reset_context
= 0;
1714 static int qlcnic_sriov_vf_handle_dev_ready(struct qlcnic_adapter
*adapter
)
1716 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1717 struct device
*dev
= &adapter
->pdev
->dev
;
1718 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
1719 u8 func
= ahw
->pci_func
;
1722 if ((idc
->prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) ||
1723 (idc
->prev_state
== QLC_83XX_IDC_DEV_INIT
)) {
1724 if (!qlcnic_sriov_vf_reinit_driver(adapter
)) {
1725 qlcnic_sriov_vf_attach(adapter
);
1726 adapter
->fw_fail_cnt
= 0;
1728 "%s: Reinitialization of VF 0x%x done after FW reset\n",
1732 "%s: Reinitialization of VF 0x%x failed after FW reset\n",
1734 state
= QLCRDX(ahw
, QLC_83XX_IDC_DEV_STATE
);
1735 dev_info(dev
, "Current state 0x%x after FW reset\n",
1743 static int qlcnic_sriov_vf_handle_context_reset(struct qlcnic_adapter
*adapter
)
1745 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1746 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
1747 struct device
*dev
= &adapter
->pdev
->dev
;
1748 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
1749 u8 func
= ahw
->pci_func
;
1752 adapter
->reset_ctx_cnt
++;
1754 /* Skip the context reset and check if FW is hung */
1755 if (adapter
->reset_ctx_cnt
< 3) {
1756 adapter
->need_fw_reset
= 1;
1757 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1759 "Resetting context, wait here to check if FW is in failed state\n");
1763 /* Check if number of resets exceed the threshold.
1764 * If it exceeds the threshold just fail the VF.
1766 if (adapter
->reset_ctx_cnt
> QLC_83XX_VF_RESET_FAIL_THRESH
) {
1767 clear_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
1768 adapter
->tx_timeo_cnt
= 0;
1769 adapter
->fw_fail_cnt
= 0;
1770 adapter
->reset_ctx_cnt
= 0;
1771 qlcnic_sriov_vf_detach(adapter
);
1773 "Device context resets have exceeded the threshold, device interface will be shutdown\n");
1777 dev_info(dev
, "Resetting context of VF 0x%x\n", func
);
1778 dev_info(dev
, "%s: Context reset count %d for VF 0x%x\n",
1779 __func__
, adapter
->reset_ctx_cnt
, func
);
1780 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1781 adapter
->need_fw_reset
= 1;
1782 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1783 qlcnic_sriov_vf_detach(adapter
);
1784 adapter
->need_fw_reset
= 0;
1786 if (!qlcnic_sriov_vf_reinit_driver(adapter
)) {
1787 qlcnic_sriov_vf_attach(adapter
);
1788 adapter
->tx_timeo_cnt
= 0;
1789 adapter
->reset_ctx_cnt
= 0;
1790 adapter
->fw_fail_cnt
= 0;
1791 dev_info(dev
, "Done resetting context for VF 0x%x\n", func
);
1793 dev_err(dev
, "%s: Reinitialization of VF 0x%x failed\n",
1795 state
= QLCRDX(ahw
, QLC_83XX_IDC_DEV_STATE
);
1796 dev_info(dev
, "%s: Current state 0x%x\n", __func__
, state
);
1802 static int qlcnic_sriov_vf_idc_ready_state(struct qlcnic_adapter
*adapter
)
1804 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1807 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_READY
)
1808 ret
= qlcnic_sriov_vf_handle_dev_ready(adapter
);
1809 else if (ahw
->reset_context
)
1810 ret
= qlcnic_sriov_vf_handle_context_reset(adapter
);
1812 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1816 static int qlcnic_sriov_vf_idc_failed_state(struct qlcnic_adapter
*adapter
)
1818 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1820 dev_err(&adapter
->pdev
->dev
, "Device is in failed state\n");
1821 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
)
1822 qlcnic_sriov_vf_detach(adapter
);
1824 clear_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
1825 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1830 qlcnic_sriov_vf_idc_need_quiescent_state(struct qlcnic_adapter
*adapter
)
1832 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
1833 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1835 dev_info(&adapter
->pdev
->dev
, "Device is in quiescent state\n");
1836 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
) {
1837 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1838 adapter
->tx_timeo_cnt
= 0;
1839 adapter
->reset_ctx_cnt
= 0;
1840 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1841 qlcnic_sriov_vf_detach(adapter
);
1847 static int qlcnic_sriov_vf_idc_init_reset_state(struct qlcnic_adapter
*adapter
)
1849 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
1850 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1851 u8 func
= adapter
->ahw
->pci_func
;
1853 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
) {
1854 dev_err(&adapter
->pdev
->dev
,
1855 "Firmware hang detected by VF 0x%x\n", func
);
1856 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1857 adapter
->tx_timeo_cnt
= 0;
1858 adapter
->reset_ctx_cnt
= 0;
1859 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1860 qlcnic_sriov_vf_detach(adapter
);
1865 static int qlcnic_sriov_vf_idc_unknown_state(struct qlcnic_adapter
*adapter
)
1867 dev_err(&adapter
->pdev
->dev
, "%s: Device in unknown state\n", __func__
);
1871 static void qlcnic_sriov_vf_periodic_tasks(struct qlcnic_adapter
*adapter
)
1873 if (adapter
->fhash
.fnum
)
1874 qlcnic_prune_lb_filters(adapter
);
1877 static void qlcnic_sriov_vf_poll_dev_state(struct work_struct
*work
)
1879 struct qlcnic_adapter
*adapter
;
1880 struct qlc_83xx_idc
*idc
;
1883 adapter
= container_of(work
, struct qlcnic_adapter
, fw_work
.work
);
1884 idc
= &adapter
->ahw
->idc
;
1885 idc
->curr_state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1887 switch (idc
->curr_state
) {
1888 case QLC_83XX_IDC_DEV_READY
:
1889 ret
= qlcnic_sriov_vf_idc_ready_state(adapter
);
1891 case QLC_83XX_IDC_DEV_NEED_RESET
:
1892 case QLC_83XX_IDC_DEV_INIT
:
1893 ret
= qlcnic_sriov_vf_idc_init_reset_state(adapter
);
1895 case QLC_83XX_IDC_DEV_NEED_QUISCENT
:
1896 ret
= qlcnic_sriov_vf_idc_need_quiescent_state(adapter
);
1898 case QLC_83XX_IDC_DEV_FAILED
:
1899 ret
= qlcnic_sriov_vf_idc_failed_state(adapter
);
1901 case QLC_83XX_IDC_DEV_QUISCENT
:
1904 ret
= qlcnic_sriov_vf_idc_unknown_state(adapter
);
1907 idc
->prev_state
= idc
->curr_state
;
1908 qlcnic_sriov_vf_periodic_tasks(adapter
);
1910 if (!ret
&& test_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
))
1911 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
1915 static void qlcnic_sriov_vf_cancel_fw_work(struct qlcnic_adapter
*adapter
)
1917 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1920 clear_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1921 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1922 cancel_delayed_work_sync(&adapter
->fw_work
);
1925 static int qlcnic_sriov_check_vlan_id(struct qlcnic_sriov
*sriov
,
1926 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
1928 int i
, err
= -EINVAL
;
1930 if (!vf
->sriov_vlans
)
1933 spin_lock_bh(&vf
->vlan_list_lock
);
1935 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1936 if (vf
->sriov_vlans
[i
] == vlan_id
) {
1942 spin_unlock_bh(&vf
->vlan_list_lock
);
1946 static int qlcnic_sriov_validate_num_vlans(struct qlcnic_sriov
*sriov
,
1947 struct qlcnic_vf_info
*vf
)
1951 spin_lock_bh(&vf
->vlan_list_lock
);
1953 if (vf
->num_vlan
>= sriov
->num_allowed_vlans
)
1956 spin_unlock_bh(&vf
->vlan_list_lock
);
1960 static int qlcnic_sriov_validate_vlan_cfg(struct qlcnic_adapter
*adapter
,
1963 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
1964 struct qlcnic_vf_info
*vf
;
1969 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1970 vlan_exist
= qlcnic_sriov_check_any_vlan(vf
);
1971 if (sriov
->vlan_mode
!= QLC_GUEST_VLAN_MODE
)
1975 if (qlcnic_83xx_vf_check(adapter
) && vlan_exist
)
1978 if (qlcnic_sriov_validate_num_vlans(sriov
, vf
))
1981 if (sriov
->any_vlan
) {
1982 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1983 if (sriov
->allowed_vlans
[i
] == vid
)
1991 if (!vlan_exist
|| qlcnic_sriov_check_vlan_id(sriov
, vf
, vid
))
1998 static void qlcnic_sriov_vlan_operation(struct qlcnic_vf_info
*vf
, u16 vlan_id
,
1999 enum qlcnic_vlan_operations opcode
)
2001 struct qlcnic_adapter
*adapter
= vf
->adapter
;
2002 struct qlcnic_sriov
*sriov
;
2004 sriov
= adapter
->ahw
->sriov
;
2006 if (!vf
->sriov_vlans
)
2009 spin_lock_bh(&vf
->vlan_list_lock
);
2013 qlcnic_sriov_add_vlan_id(sriov
, vf
, vlan_id
);
2015 case QLC_VLAN_DELETE
:
2016 qlcnic_sriov_del_vlan_id(sriov
, vf
, vlan_id
);
2019 netdev_err(adapter
->netdev
, "Invalid VLAN operation\n");
2022 spin_unlock_bh(&vf
->vlan_list_lock
);
2026 int qlcnic_sriov_cfg_vf_guest_vlan(struct qlcnic_adapter
*adapter
,
2029 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2030 struct net_device
*netdev
= adapter
->netdev
;
2031 struct qlcnic_vf_info
*vf
;
2032 struct qlcnic_cmd_args cmd
;
2038 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
2039 ret
= qlcnic_sriov_validate_vlan_cfg(adapter
, vid
, enable
);
2043 ret
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
,
2044 QLCNIC_BC_CMD_CFG_GUEST_VLAN
);
2048 cmd
.req
.arg
[1] = (enable
& 1) | vid
<< 16;
2050 qlcnic_sriov_cleanup_async_list(&sriov
->bc
);
2051 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
2053 dev_err(&adapter
->pdev
->dev
,
2054 "Failed to configure guest VLAN, err=%d\n", ret
);
2056 netif_addr_lock_bh(netdev
);
2057 qlcnic_free_mac_list(adapter
);
2058 netif_addr_unlock_bh(netdev
);
2061 qlcnic_sriov_vlan_operation(vf
, vid
, QLC_VLAN_ADD
);
2063 qlcnic_sriov_vlan_operation(vf
, vid
, QLC_VLAN_DELETE
);
2065 netif_addr_lock_bh(netdev
);
2066 qlcnic_set_multi(netdev
);
2067 netif_addr_unlock_bh(netdev
);
2070 qlcnic_free_mbx_args(&cmd
);
2074 static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter
*adapter
)
2076 struct list_head
*head
= &adapter
->mac_list
;
2077 struct qlcnic_mac_vlan_list
*cur
;
2079 while (!list_empty(head
)) {
2080 cur
= list_entry(head
->next
, struct qlcnic_mac_vlan_list
, list
);
2081 qlcnic_sre_macaddr_change(adapter
, cur
->mac_addr
, cur
->vlan_id
,
2083 list_del(&cur
->list
);
2089 static int qlcnic_sriov_vf_shutdown(struct pci_dev
*pdev
)
2091 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2092 struct net_device
*netdev
= adapter
->netdev
;
2095 netif_device_detach(netdev
);
2096 qlcnic_cancel_idc_work(adapter
);
2098 if (netif_running(netdev
))
2099 qlcnic_down(adapter
, netdev
);
2101 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
2102 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
2103 qlcnic_83xx_disable_mbx_intr(adapter
);
2104 cancel_delayed_work_sync(&adapter
->idc_aen_work
);
2106 retval
= pci_save_state(pdev
);
2113 static int qlcnic_sriov_vf_resume(struct qlcnic_adapter
*adapter
)
2115 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
2116 struct net_device
*netdev
= adapter
->netdev
;
2119 set_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
2120 qlcnic_83xx_enable_mbx_interrupt(adapter
);
2121 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
2125 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
2127 if (netif_running(netdev
)) {
2128 err
= qlcnic_up(adapter
, netdev
);
2130 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
2134 netif_device_attach(netdev
);
2135 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
2140 void qlcnic_sriov_alloc_vlans(struct qlcnic_adapter
*adapter
)
2142 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2143 struct qlcnic_vf_info
*vf
;
2146 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
2147 vf
= &sriov
->vf_info
[i
];
2148 vf
->sriov_vlans
= kcalloc(sriov
->num_allowed_vlans
,
2149 sizeof(*vf
->sriov_vlans
), GFP_KERNEL
);
2153 void qlcnic_sriov_free_vlans(struct qlcnic_adapter
*adapter
)
2155 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2156 struct qlcnic_vf_info
*vf
;
2159 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
2160 vf
= &sriov
->vf_info
[i
];
2161 kfree(vf
->sriov_vlans
);
2162 vf
->sriov_vlans
= NULL
;
2166 void qlcnic_sriov_add_vlan_id(struct qlcnic_sriov
*sriov
,
2167 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
2171 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
2172 if (!vf
->sriov_vlans
[i
]) {
2173 vf
->sriov_vlans
[i
] = vlan_id
;
2180 void qlcnic_sriov_del_vlan_id(struct qlcnic_sriov
*sriov
,
2181 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
2185 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
2186 if (vf
->sriov_vlans
[i
] == vlan_id
) {
2187 vf
->sriov_vlans
[i
] = 0;
2194 bool qlcnic_sriov_check_any_vlan(struct qlcnic_vf_info
*vf
)
2198 spin_lock_bh(&vf
->vlan_list_lock
);
2203 spin_unlock_bh(&vf
->vlan_list_lock
);