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
->min_tx_bw
= MIN_BW
;
205 vp
->spoofchk
= false;
206 random_ether_addr(vp
->mac
);
207 dev_info(&adapter
->pdev
->dev
,
208 "MAC Address %pM is configured for VF %d\n",
215 qlcnic_destroy_async_wq
:
216 destroy_workqueue(bc
->bc_async_wq
);
218 qlcnic_destroy_trans_wq
:
219 destroy_workqueue(bc
->bc_trans_wq
);
222 kfree(sriov
->vf_info
);
225 kfree(adapter
->ahw
->sriov
);
229 void qlcnic_sriov_cleanup_list(struct qlcnic_trans_list
*t_list
)
231 struct qlcnic_bc_trans
*trans
;
232 struct qlcnic_cmd_args cmd
;
235 spin_lock_irqsave(&t_list
->lock
, flags
);
237 while (!list_empty(&t_list
->wait_list
)) {
238 trans
= list_first_entry(&t_list
->wait_list
,
239 struct qlcnic_bc_trans
, list
);
240 list_del(&trans
->list
);
242 cmd
.req
.arg
= (u32
*)trans
->req_pay
;
243 cmd
.rsp
.arg
= (u32
*)trans
->rsp_pay
;
244 qlcnic_free_mbx_args(&cmd
);
245 qlcnic_sriov_cleanup_transaction(trans
);
248 spin_unlock_irqrestore(&t_list
->lock
, flags
);
251 void __qlcnic_sriov_cleanup(struct qlcnic_adapter
*adapter
)
253 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
254 struct qlcnic_back_channel
*bc
= &sriov
->bc
;
255 struct qlcnic_vf_info
*vf
;
258 if (!qlcnic_sriov_enable_check(adapter
))
261 qlcnic_sriov_cleanup_async_list(bc
);
262 destroy_workqueue(bc
->bc_async_wq
);
264 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
265 vf
= &sriov
->vf_info
[i
];
266 qlcnic_sriov_cleanup_list(&vf
->rcv_pend
);
267 cancel_work_sync(&vf
->trans_work
);
268 qlcnic_sriov_cleanup_list(&vf
->rcv_act
);
271 destroy_workqueue(bc
->bc_trans_wq
);
273 for (i
= 0; i
< sriov
->num_vfs
; i
++)
274 kfree(sriov
->vf_info
[i
].vp
);
276 kfree(sriov
->vf_info
);
277 kfree(adapter
->ahw
->sriov
);
280 static void qlcnic_sriov_vf_cleanup(struct qlcnic_adapter
*adapter
)
282 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
283 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
284 __qlcnic_sriov_cleanup(adapter
);
287 void qlcnic_sriov_cleanup(struct qlcnic_adapter
*adapter
)
289 if (!test_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
))
292 qlcnic_sriov_free_vlans(adapter
);
294 if (qlcnic_sriov_pf_check(adapter
))
295 qlcnic_sriov_pf_cleanup(adapter
);
297 if (qlcnic_sriov_vf_check(adapter
))
298 qlcnic_sriov_vf_cleanup(adapter
);
301 static int qlcnic_sriov_post_bc_msg(struct qlcnic_adapter
*adapter
, u32
*hdr
,
302 u32
*pay
, u8 pci_func
, u8 size
)
304 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
305 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
306 struct qlcnic_cmd_args cmd
;
307 unsigned long timeout
;
310 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
314 cmd
.func_num
= pci_func
;
315 cmd
.op_type
= QLC_83XX_MBX_POST_BC_OP
;
316 cmd
.cmd_op
= ((struct qlcnic_bc_hdr
*)hdr
)->cmd_op
;
318 err
= mbx
->ops
->enqueue_cmd(adapter
, &cmd
, &timeout
);
320 dev_err(&adapter
->pdev
->dev
,
321 "%s: Mailbox not available, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n",
322 __func__
, cmd
.cmd_op
, cmd
.type
, ahw
->pci_func
,
327 if (!wait_for_completion_timeout(&cmd
.completion
, timeout
)) {
328 dev_err(&adapter
->pdev
->dev
,
329 "%s: Mailbox command timed out, cmd_op=0x%x, cmd_type=0x%x, pci_func=0x%x, op_mode=0x%x\n",
330 __func__
, cmd
.cmd_op
, cmd
.type
, ahw
->pci_func
,
332 flush_workqueue(mbx
->work_q
);
335 return cmd
.rsp_opcode
;
338 static void qlcnic_sriov_vf_cfg_buff_desc(struct qlcnic_adapter
*adapter
)
340 adapter
->num_rxd
= QLC_DEFAULT_RCV_DESCRIPTORS_SRIOV_VF
;
341 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
342 adapter
->num_jumbo_rxd
= QLC_DEFAULT_JUMBO_RCV_DESCRIPTORS_SRIOV_VF
;
343 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
344 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
345 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
348 int qlcnic_sriov_get_vf_vport_info(struct qlcnic_adapter
*adapter
,
349 struct qlcnic_info
*npar_info
, u16 vport_id
)
351 struct device
*dev
= &adapter
->pdev
->dev
;
352 struct qlcnic_cmd_args cmd
;
356 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_GET_NIC_INFO
);
360 cmd
.req
.arg
[1] = vport_id
<< 16 | 0x1;
361 err
= qlcnic_issue_cmd(adapter
, &cmd
);
363 dev_err(&adapter
->pdev
->dev
,
364 "Failed to get vport info, err=%d\n", err
);
365 qlcnic_free_mbx_args(&cmd
);
369 status
= cmd
.rsp
.arg
[2] & 0xffff;
371 npar_info
->min_tx_bw
= MSW(cmd
.rsp
.arg
[2]);
373 npar_info
->max_tx_bw
= LSW(cmd
.rsp
.arg
[3]);
375 npar_info
->max_tx_ques
= MSW(cmd
.rsp
.arg
[3]);
377 npar_info
->max_tx_mac_filters
= LSW(cmd
.rsp
.arg
[4]);
379 npar_info
->max_rx_mcast_mac_filters
= MSW(cmd
.rsp
.arg
[4]);
381 npar_info
->max_rx_ucast_mac_filters
= LSW(cmd
.rsp
.arg
[5]);
383 npar_info
->max_rx_ip_addr
= MSW(cmd
.rsp
.arg
[5]);
385 npar_info
->max_rx_lro_flow
= LSW(cmd
.rsp
.arg
[6]);
387 npar_info
->max_rx_status_rings
= MSW(cmd
.rsp
.arg
[6]);
389 npar_info
->max_rx_buf_rings
= LSW(cmd
.rsp
.arg
[7]);
391 npar_info
->max_rx_ques
= MSW(cmd
.rsp
.arg
[7]);
392 npar_info
->max_tx_vlan_keys
= LSW(cmd
.rsp
.arg
[8]);
393 npar_info
->max_local_ipv6_addrs
= MSW(cmd
.rsp
.arg
[8]);
394 npar_info
->max_remote_ipv6_addrs
= LSW(cmd
.rsp
.arg
[9]);
396 dev_info(dev
, "\n\tmin_tx_bw: %d, max_tx_bw: %d max_tx_ques: %d,\n"
397 "\tmax_tx_mac_filters: %d max_rx_mcast_mac_filters: %d,\n"
398 "\tmax_rx_ucast_mac_filters: 0x%x, max_rx_ip_addr: %d,\n"
399 "\tmax_rx_lro_flow: %d max_rx_status_rings: %d,\n"
400 "\tmax_rx_buf_rings: %d, max_rx_ques: %d, max_tx_vlan_keys %d\n"
401 "\tlocal_ipv6_addr: %d, remote_ipv6_addr: %d\n",
402 npar_info
->min_tx_bw
, npar_info
->max_tx_bw
,
403 npar_info
->max_tx_ques
, npar_info
->max_tx_mac_filters
,
404 npar_info
->max_rx_mcast_mac_filters
,
405 npar_info
->max_rx_ucast_mac_filters
, npar_info
->max_rx_ip_addr
,
406 npar_info
->max_rx_lro_flow
, npar_info
->max_rx_status_rings
,
407 npar_info
->max_rx_buf_rings
, npar_info
->max_rx_ques
,
408 npar_info
->max_tx_vlan_keys
, npar_info
->max_local_ipv6_addrs
,
409 npar_info
->max_remote_ipv6_addrs
);
411 qlcnic_free_mbx_args(&cmd
);
415 static int qlcnic_sriov_set_pvid_mode(struct qlcnic_adapter
*adapter
,
416 struct qlcnic_cmd_args
*cmd
)
418 adapter
->rx_pvid
= MSW(cmd
->rsp
.arg
[1]) & 0xffff;
419 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
423 static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter
*adapter
,
424 struct qlcnic_cmd_args
*cmd
)
426 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
430 if (sriov
->allowed_vlans
)
433 sriov
->any_vlan
= cmd
->rsp
.arg
[2] & 0xf;
434 sriov
->num_allowed_vlans
= cmd
->rsp
.arg
[2] >> 16;
435 dev_info(&adapter
->pdev
->dev
, "Number of allowed Guest VLANs = %d\n",
436 sriov
->num_allowed_vlans
);
438 qlcnic_sriov_alloc_vlans(adapter
);
440 if (!sriov
->any_vlan
)
443 num_vlans
= sriov
->num_allowed_vlans
;
444 sriov
->allowed_vlans
= kzalloc(sizeof(u16
) * num_vlans
, GFP_KERNEL
);
445 if (!sriov
->allowed_vlans
)
448 vlans
= (u16
*)&cmd
->rsp
.arg
[3];
449 for (i
= 0; i
< num_vlans
; i
++)
450 sriov
->allowed_vlans
[i
] = vlans
[i
];
455 static int qlcnic_sriov_get_vf_acl(struct qlcnic_adapter
*adapter
)
457 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
458 struct qlcnic_cmd_args cmd
;
461 memset(&cmd
, 0, sizeof(cmd
));
462 ret
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
, QLCNIC_BC_CMD_GET_ACL
);
466 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
468 dev_err(&adapter
->pdev
->dev
, "Failed to get ACL, err=%d\n",
471 sriov
->vlan_mode
= cmd
.rsp
.arg
[1] & 0x3;
472 switch (sriov
->vlan_mode
) {
473 case QLC_GUEST_VLAN_MODE
:
474 ret
= qlcnic_sriov_set_guest_vlan_mode(adapter
, &cmd
);
477 ret
= qlcnic_sriov_set_pvid_mode(adapter
, &cmd
);
482 qlcnic_free_mbx_args(&cmd
);
486 static int qlcnic_sriov_vf_init_driver(struct qlcnic_adapter
*adapter
)
488 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
489 struct qlcnic_info nic_info
;
492 err
= qlcnic_sriov_get_vf_vport_info(adapter
, &nic_info
, 0);
496 ahw
->max_mc_count
= nic_info
.max_rx_mcast_mac_filters
;
498 err
= qlcnic_get_nic_info(adapter
, &nic_info
, ahw
->pci_func
);
502 if (qlcnic_83xx_get_port_info(adapter
))
505 qlcnic_sriov_vf_cfg_buff_desc(adapter
);
506 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
507 dev_info(&adapter
->pdev
->dev
, "HAL Version: %d\n",
508 adapter
->ahw
->fw_hal_version
);
510 ahw
->physical_port
= (u8
) nic_info
.phys_port
;
511 ahw
->switch_mode
= nic_info
.switch_mode
;
512 ahw
->max_mtu
= nic_info
.max_mtu
;
513 ahw
->op_mode
= nic_info
.op_mode
;
514 ahw
->capabilities
= nic_info
.capabilities
;
518 static int qlcnic_sriov_setup_vf(struct qlcnic_adapter
*adapter
,
523 adapter
->flags
|= QLCNIC_VLAN_FILTERING
;
524 adapter
->ahw
->total_nic_func
= 1;
525 INIT_LIST_HEAD(&adapter
->vf_mc_list
);
526 if (!qlcnic_use_msi_x
&& !!qlcnic_use_msi
)
527 dev_warn(&adapter
->pdev
->dev
,
528 "Device does not support MSI interrupts\n");
530 /* compute and set default and max tx/sds rings */
531 qlcnic_set_tx_ring_count(adapter
, QLCNIC_SINGLE_RING
);
532 qlcnic_set_sds_ring_count(adapter
, QLCNIC_SINGLE_RING
);
534 err
= qlcnic_setup_intr(adapter
);
536 dev_err(&adapter
->pdev
->dev
, "Failed to setup interrupt\n");
537 goto err_out_disable_msi
;
540 err
= qlcnic_83xx_setup_mbx_intr(adapter
);
542 goto err_out_disable_msi
;
544 err
= qlcnic_sriov_init(adapter
, 1);
546 goto err_out_disable_mbx_intr
;
548 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
550 goto err_out_cleanup_sriov
;
552 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
554 goto err_out_disable_bc_intr
;
556 err
= qlcnic_sriov_vf_init_driver(adapter
);
558 goto err_out_send_channel_term
;
560 err
= qlcnic_sriov_get_vf_acl(adapter
);
562 goto err_out_send_channel_term
;
564 err
= qlcnic_setup_netdev(adapter
, adapter
->netdev
, pci_using_dac
);
566 goto err_out_send_channel_term
;
568 pci_set_drvdata(adapter
->pdev
, adapter
);
569 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
570 adapter
->netdev
->name
);
572 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
573 adapter
->ahw
->idc
.delay
);
576 err_out_send_channel_term
:
577 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
579 err_out_disable_bc_intr
:
580 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
582 err_out_cleanup_sriov
:
583 __qlcnic_sriov_cleanup(adapter
);
585 err_out_disable_mbx_intr
:
586 qlcnic_83xx_free_mbx_intr(adapter
);
589 qlcnic_teardown_intr(adapter
);
593 static int qlcnic_sriov_check_dev_ready(struct qlcnic_adapter
*adapter
)
599 if (++adapter
->fw_fail_cnt
> QLC_BC_CMD_MAX_RETRY_CNT
)
601 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
602 } while (state
!= QLC_83XX_IDC_DEV_READY
);
607 int qlcnic_sriov_vf_init(struct qlcnic_adapter
*adapter
, int pci_using_dac
)
609 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
612 set_bit(QLC_83XX_MODULE_LOADED
, &ahw
->idc
.status
);
613 ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
614 ahw
->reset_context
= 0;
615 adapter
->fw_fail_cnt
= 0;
616 ahw
->msix_supported
= 1;
617 adapter
->need_fw_reset
= 0;
618 adapter
->flags
|= QLCNIC_TX_INTR_SHARED
;
620 err
= qlcnic_sriov_check_dev_ready(adapter
);
624 err
= qlcnic_sriov_setup_vf(adapter
, pci_using_dac
);
628 if (qlcnic_read_mac_addr(adapter
))
629 dev_warn(&adapter
->pdev
->dev
, "failed to read mac addr\n");
631 INIT_DELAYED_WORK(&adapter
->idc_aen_work
, qlcnic_83xx_idc_aen_work
);
633 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
637 void qlcnic_sriov_vf_set_ops(struct qlcnic_adapter
*adapter
)
639 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
641 ahw
->op_mode
= QLCNIC_SRIOV_VF_FUNC
;
642 dev_info(&adapter
->pdev
->dev
,
643 "HAL Version: %d Non Privileged SRIOV function\n",
644 ahw
->fw_hal_version
);
645 adapter
->nic_ops
= &qlcnic_sriov_vf_ops
;
646 set_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
);
650 void qlcnic_sriov_vf_register_map(struct qlcnic_hardware_context
*ahw
)
652 ahw
->hw_ops
= &qlcnic_sriov_vf_hw_ops
;
653 ahw
->reg_tbl
= (u32
*)qlcnic_83xx_reg_tbl
;
654 ahw
->ext_reg_tbl
= (u32
*)qlcnic_83xx_ext_reg_tbl
;
657 static u32
qlcnic_sriov_get_bc_paysize(u32 real_pay_size
, u8 curr_frag
)
661 pay_size
= real_pay_size
/ ((curr_frag
+ 1) * QLC_BC_PAYLOAD_SZ
);
664 pay_size
= QLC_BC_PAYLOAD_SZ
;
666 pay_size
= real_pay_size
% QLC_BC_PAYLOAD_SZ
;
671 int qlcnic_sriov_func_to_index(struct qlcnic_adapter
*adapter
, u8 pci_func
)
673 struct qlcnic_vf_info
*vf_info
= adapter
->ahw
->sriov
->vf_info
;
676 if (qlcnic_sriov_vf_check(adapter
))
679 for (i
= 0; i
< adapter
->ahw
->sriov
->num_vfs
; i
++) {
680 if (vf_info
[i
].pci_func
== pci_func
)
687 static inline int qlcnic_sriov_alloc_bc_trans(struct qlcnic_bc_trans
**trans
)
689 *trans
= kzalloc(sizeof(struct qlcnic_bc_trans
), GFP_ATOMIC
);
693 init_completion(&(*trans
)->resp_cmpl
);
697 static inline int qlcnic_sriov_alloc_bc_msg(struct qlcnic_bc_hdr
**hdr
,
700 *hdr
= kzalloc(sizeof(struct qlcnic_bc_hdr
) * size
, GFP_ATOMIC
);
707 static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args
*mbx
, u32 type
)
709 const struct qlcnic_mailbox_metadata
*mbx_tbl
;
712 mbx_tbl
= qlcnic_sriov_bc_mbx_tbl
;
713 size
= ARRAY_SIZE(qlcnic_sriov_bc_mbx_tbl
);
715 for (i
= 0; i
< size
; i
++) {
716 if (type
== mbx_tbl
[i
].cmd
) {
717 mbx
->op_type
= QLC_BC_CMD
;
718 mbx
->req
.num
= mbx_tbl
[i
].in_args
;
719 mbx
->rsp
.num
= mbx_tbl
[i
].out_args
;
720 mbx
->req
.arg
= kcalloc(mbx
->req
.num
, sizeof(u32
),
724 mbx
->rsp
.arg
= kcalloc(mbx
->rsp
.num
, sizeof(u32
),
731 memset(mbx
->req
.arg
, 0, sizeof(u32
) * mbx
->req
.num
);
732 memset(mbx
->rsp
.arg
, 0, sizeof(u32
) * mbx
->rsp
.num
);
733 mbx
->req
.arg
[0] = (type
| (mbx
->req
.num
<< 16) |
735 mbx
->rsp
.arg
[0] = (type
& 0xffff) | mbx
->rsp
.num
<< 16;
742 static int qlcnic_sriov_prepare_bc_hdr(struct qlcnic_bc_trans
*trans
,
743 struct qlcnic_cmd_args
*cmd
,
744 u16 seq
, u8 msg_type
)
746 struct qlcnic_bc_hdr
*hdr
;
748 u32 num_regs
, bc_pay_sz
;
750 u8 cmd_op
, num_frags
, t_num_frags
;
752 bc_pay_sz
= QLC_BC_PAYLOAD_SZ
;
753 if (msg_type
== QLC_BC_COMMAND
) {
754 trans
->req_pay
= (struct qlcnic_bc_payload
*)cmd
->req
.arg
;
755 trans
->rsp_pay
= (struct qlcnic_bc_payload
*)cmd
->rsp
.arg
;
756 num_regs
= cmd
->req
.num
;
757 trans
->req_pay_size
= (num_regs
* 4);
758 num_regs
= cmd
->rsp
.num
;
759 trans
->rsp_pay_size
= (num_regs
* 4);
760 cmd_op
= cmd
->req
.arg
[0] & 0xff;
761 remainder
= (trans
->req_pay_size
) % (bc_pay_sz
);
762 num_frags
= (trans
->req_pay_size
) / (bc_pay_sz
);
765 t_num_frags
= num_frags
;
766 if (qlcnic_sriov_alloc_bc_msg(&trans
->req_hdr
, num_frags
))
768 remainder
= (trans
->rsp_pay_size
) % (bc_pay_sz
);
769 num_frags
= (trans
->rsp_pay_size
) / (bc_pay_sz
);
772 if (qlcnic_sriov_alloc_bc_msg(&trans
->rsp_hdr
, num_frags
))
774 num_frags
= t_num_frags
;
775 hdr
= trans
->req_hdr
;
777 cmd
->req
.arg
= (u32
*)trans
->req_pay
;
778 cmd
->rsp
.arg
= (u32
*)trans
->rsp_pay
;
779 cmd_op
= cmd
->req
.arg
[0] & 0xff;
780 cmd
->cmd_op
= cmd_op
;
781 remainder
= (trans
->rsp_pay_size
) % (bc_pay_sz
);
782 num_frags
= (trans
->rsp_pay_size
) / (bc_pay_sz
);
785 cmd
->req
.num
= trans
->req_pay_size
/ 4;
786 cmd
->rsp
.num
= trans
->rsp_pay_size
/ 4;
787 hdr
= trans
->rsp_hdr
;
788 cmd
->op_type
= trans
->req_hdr
->op_type
;
791 trans
->trans_id
= seq
;
792 trans
->cmd_id
= cmd_op
;
793 for (i
= 0; i
< num_frags
; i
++) {
795 hdr
[i
].msg_type
= msg_type
;
796 hdr
[i
].op_type
= cmd
->op_type
;
798 hdr
[i
].num_frags
= num_frags
;
799 hdr
[i
].frag_num
= i
+ 1;
800 hdr
[i
].cmd_op
= cmd_op
;
806 static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans
*trans
)
810 kfree(trans
->req_hdr
);
811 kfree(trans
->rsp_hdr
);
815 static int qlcnic_sriov_clear_trans(struct qlcnic_vf_info
*vf
,
816 struct qlcnic_bc_trans
*trans
, u8 type
)
818 struct qlcnic_trans_list
*t_list
;
822 if (type
== QLC_BC_RESPONSE
) {
823 t_list
= &vf
->rcv_act
;
824 spin_lock_irqsave(&t_list
->lock
, flags
);
826 list_del(&trans
->list
);
827 if (t_list
->count
> 0)
829 spin_unlock_irqrestore(&t_list
->lock
, flags
);
831 if (type
== QLC_BC_COMMAND
) {
832 while (test_and_set_bit(QLC_BC_VF_SEND
, &vf
->state
))
835 clear_bit(QLC_BC_VF_SEND
, &vf
->state
);
840 static void qlcnic_sriov_schedule_bc_cmd(struct qlcnic_sriov
*sriov
,
841 struct qlcnic_vf_info
*vf
,
844 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
) ||
845 vf
->adapter
->need_fw_reset
)
848 queue_work(sriov
->bc
.bc_trans_wq
, &vf
->trans_work
);
851 static inline void qlcnic_sriov_wait_for_resp(struct qlcnic_bc_trans
*trans
)
853 struct completion
*cmpl
= &trans
->resp_cmpl
;
855 if (wait_for_completion_timeout(cmpl
, QLC_MBOX_RESP_TIMEOUT
))
856 trans
->trans_state
= QLC_END
;
858 trans
->trans_state
= QLC_ABORT
;
863 static void qlcnic_sriov_handle_multi_frags(struct qlcnic_bc_trans
*trans
,
866 if (type
== QLC_BC_RESPONSE
) {
867 trans
->curr_rsp_frag
++;
868 if (trans
->curr_rsp_frag
< trans
->rsp_hdr
->num_frags
)
869 trans
->trans_state
= QLC_INIT
;
871 trans
->trans_state
= QLC_END
;
873 trans
->curr_req_frag
++;
874 if (trans
->curr_req_frag
< trans
->req_hdr
->num_frags
)
875 trans
->trans_state
= QLC_INIT
;
877 trans
->trans_state
= QLC_WAIT_FOR_RESP
;
881 static void qlcnic_sriov_wait_for_channel_free(struct qlcnic_bc_trans
*trans
,
884 struct qlcnic_vf_info
*vf
= trans
->vf
;
885 struct completion
*cmpl
= &vf
->ch_free_cmpl
;
887 if (!wait_for_completion_timeout(cmpl
, QLC_MBOX_CH_FREE_TIMEOUT
)) {
888 trans
->trans_state
= QLC_ABORT
;
892 clear_bit(QLC_BC_VF_CHANNEL
, &vf
->state
);
893 qlcnic_sriov_handle_multi_frags(trans
, type
);
896 static void qlcnic_sriov_pull_bc_msg(struct qlcnic_adapter
*adapter
,
897 u32
*hdr
, u32
*pay
, u32 size
)
899 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
901 u8 i
, max
= 2, hdr_size
, j
;
903 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
904 max
= (size
/ sizeof(u32
)) + hdr_size
;
906 fw_mbx
= readl(QLCNIC_MBX_FW(ahw
, 0));
907 for (i
= 2, j
= 0; j
< hdr_size
; i
++, j
++)
908 *(hdr
++) = readl(QLCNIC_MBX_FW(ahw
, i
));
909 for (; j
< max
; i
++, j
++)
910 *(pay
++) = readl(QLCNIC_MBX_FW(ahw
, i
));
913 static int __qlcnic_sriov_issue_bc_post(struct qlcnic_vf_info
*vf
)
919 if (!test_and_set_bit(QLC_BC_VF_CHANNEL
, &vf
->state
)) {
929 static int qlcnic_sriov_issue_bc_post(struct qlcnic_bc_trans
*trans
, u8 type
)
931 struct qlcnic_vf_info
*vf
= trans
->vf
;
932 u32 pay_size
, hdr_size
;
935 u8 pci_func
= trans
->func_id
;
937 if (__qlcnic_sriov_issue_bc_post(vf
))
940 if (type
== QLC_BC_COMMAND
) {
941 hdr
= (u32
*)(trans
->req_hdr
+ trans
->curr_req_frag
);
942 pay
= (u32
*)(trans
->req_pay
+ trans
->curr_req_frag
);
943 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
944 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
945 trans
->curr_req_frag
);
946 pay_size
= (pay_size
/ sizeof(u32
));
948 hdr
= (u32
*)(trans
->rsp_hdr
+ trans
->curr_rsp_frag
);
949 pay
= (u32
*)(trans
->rsp_pay
+ trans
->curr_rsp_frag
);
950 hdr_size
= (sizeof(struct qlcnic_bc_hdr
) / sizeof(u32
));
951 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->rsp_pay_size
,
952 trans
->curr_rsp_frag
);
953 pay_size
= (pay_size
/ sizeof(u32
));
956 ret
= qlcnic_sriov_post_bc_msg(vf
->adapter
, hdr
, pay
,
961 static int __qlcnic_sriov_send_bc_msg(struct qlcnic_bc_trans
*trans
,
962 struct qlcnic_vf_info
*vf
, u8 type
)
968 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
) ||
969 vf
->adapter
->need_fw_reset
)
970 trans
->trans_state
= QLC_ABORT
;
972 switch (trans
->trans_state
) {
974 trans
->trans_state
= QLC_WAIT_FOR_CHANNEL_FREE
;
975 if (qlcnic_sriov_issue_bc_post(trans
, type
))
976 trans
->trans_state
= QLC_ABORT
;
978 case QLC_WAIT_FOR_CHANNEL_FREE
:
979 qlcnic_sriov_wait_for_channel_free(trans
, type
);
981 case QLC_WAIT_FOR_RESP
:
982 qlcnic_sriov_wait_for_resp(trans
);
991 clear_bit(QLC_BC_VF_CHANNEL
, &vf
->state
);
1001 static int qlcnic_sriov_send_bc_cmd(struct qlcnic_adapter
*adapter
,
1002 struct qlcnic_bc_trans
*trans
, int pci_func
)
1004 struct qlcnic_vf_info
*vf
;
1005 int err
, index
= qlcnic_sriov_func_to_index(adapter
, pci_func
);
1010 vf
= &adapter
->ahw
->sriov
->vf_info
[index
];
1012 trans
->func_id
= pci_func
;
1014 if (!test_bit(QLC_BC_VF_STATE
, &vf
->state
)) {
1015 if (qlcnic_sriov_pf_check(adapter
))
1017 if (qlcnic_sriov_vf_check(adapter
) &&
1018 trans
->cmd_id
!= QLCNIC_BC_CMD_CHANNEL_INIT
)
1022 mutex_lock(&vf
->send_cmd_lock
);
1023 vf
->send_cmd
= trans
;
1024 err
= __qlcnic_sriov_send_bc_msg(trans
, vf
, QLC_BC_COMMAND
);
1025 qlcnic_sriov_clear_trans(vf
, trans
, QLC_BC_COMMAND
);
1026 mutex_unlock(&vf
->send_cmd_lock
);
1030 static void __qlcnic_sriov_process_bc_cmd(struct qlcnic_adapter
*adapter
,
1031 struct qlcnic_bc_trans
*trans
,
1032 struct qlcnic_cmd_args
*cmd
)
1034 #ifdef CONFIG_QLCNIC_SRIOV
1035 if (qlcnic_sriov_pf_check(adapter
)) {
1036 qlcnic_sriov_pf_process_bc_cmd(adapter
, trans
, cmd
);
1040 cmd
->rsp
.arg
[0] |= (0x9 << 25);
1044 static void qlcnic_sriov_process_bc_cmd(struct work_struct
*work
)
1046 struct qlcnic_vf_info
*vf
= container_of(work
, struct qlcnic_vf_info
,
1048 struct qlcnic_bc_trans
*trans
= NULL
;
1049 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1050 struct qlcnic_cmd_args cmd
;
1053 if (adapter
->need_fw_reset
)
1056 if (test_bit(QLC_BC_VF_FLR
, &vf
->state
))
1059 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
1060 trans
= list_first_entry(&vf
->rcv_act
.wait_list
,
1061 struct qlcnic_bc_trans
, list
);
1062 adapter
= vf
->adapter
;
1064 if (qlcnic_sriov_prepare_bc_hdr(trans
, &cmd
, trans
->req_hdr
->seq_id
,
1068 __qlcnic_sriov_process_bc_cmd(adapter
, trans
, &cmd
);
1069 trans
->trans_state
= QLC_INIT
;
1070 __qlcnic_sriov_send_bc_msg(trans
, vf
, QLC_BC_RESPONSE
);
1073 qlcnic_free_mbx_args(&cmd
);
1074 req
= qlcnic_sriov_clear_trans(vf
, trans
, QLC_BC_RESPONSE
);
1075 qlcnic_sriov_cleanup_transaction(trans
);
1077 qlcnic_sriov_schedule_bc_cmd(adapter
->ahw
->sriov
, vf
,
1078 qlcnic_sriov_process_bc_cmd
);
1081 static void qlcnic_sriov_handle_bc_resp(struct qlcnic_bc_hdr
*hdr
,
1082 struct qlcnic_vf_info
*vf
)
1084 struct qlcnic_bc_trans
*trans
;
1087 if (test_and_set_bit(QLC_BC_VF_SEND
, &vf
->state
))
1090 trans
= vf
->send_cmd
;
1095 if (trans
->trans_id
!= hdr
->seq_id
)
1098 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->rsp_pay_size
,
1099 trans
->curr_rsp_frag
);
1100 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1101 (u32
*)(trans
->rsp_hdr
+ trans
->curr_rsp_frag
),
1102 (u32
*)(trans
->rsp_pay
+ trans
->curr_rsp_frag
),
1104 if (++trans
->curr_rsp_frag
< trans
->rsp_hdr
->num_frags
)
1107 complete(&trans
->resp_cmpl
);
1110 clear_bit(QLC_BC_VF_SEND
, &vf
->state
);
1113 int __qlcnic_sriov_add_act_list(struct qlcnic_sriov
*sriov
,
1114 struct qlcnic_vf_info
*vf
,
1115 struct qlcnic_bc_trans
*trans
)
1117 struct qlcnic_trans_list
*t_list
= &vf
->rcv_act
;
1120 list_add_tail(&trans
->list
, &t_list
->wait_list
);
1121 if (t_list
->count
== 1)
1122 qlcnic_sriov_schedule_bc_cmd(sriov
, vf
,
1123 qlcnic_sriov_process_bc_cmd
);
1127 static int qlcnic_sriov_add_act_list(struct qlcnic_sriov
*sriov
,
1128 struct qlcnic_vf_info
*vf
,
1129 struct qlcnic_bc_trans
*trans
)
1131 struct qlcnic_trans_list
*t_list
= &vf
->rcv_act
;
1133 spin_lock(&t_list
->lock
);
1135 __qlcnic_sriov_add_act_list(sriov
, vf
, trans
);
1137 spin_unlock(&t_list
->lock
);
1141 static void qlcnic_sriov_handle_pending_trans(struct qlcnic_sriov
*sriov
,
1142 struct qlcnic_vf_info
*vf
,
1143 struct qlcnic_bc_hdr
*hdr
)
1145 struct qlcnic_bc_trans
*trans
= NULL
;
1146 struct list_head
*node
;
1147 u32 pay_size
, curr_frag
;
1148 u8 found
= 0, active
= 0;
1150 spin_lock(&vf
->rcv_pend
.lock
);
1151 if (vf
->rcv_pend
.count
> 0) {
1152 list_for_each(node
, &vf
->rcv_pend
.wait_list
) {
1153 trans
= list_entry(node
, struct qlcnic_bc_trans
, list
);
1154 if (trans
->trans_id
== hdr
->seq_id
) {
1162 curr_frag
= trans
->curr_req_frag
;
1163 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
1165 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1166 (u32
*)(trans
->req_hdr
+ curr_frag
),
1167 (u32
*)(trans
->req_pay
+ curr_frag
),
1169 trans
->curr_req_frag
++;
1170 if (trans
->curr_req_frag
>= hdr
->num_frags
) {
1171 vf
->rcv_pend
.count
--;
1172 list_del(&trans
->list
);
1176 spin_unlock(&vf
->rcv_pend
.lock
);
1179 if (qlcnic_sriov_add_act_list(sriov
, vf
, trans
))
1180 qlcnic_sriov_cleanup_transaction(trans
);
1185 static void qlcnic_sriov_handle_bc_cmd(struct qlcnic_sriov
*sriov
,
1186 struct qlcnic_bc_hdr
*hdr
,
1187 struct qlcnic_vf_info
*vf
)
1189 struct qlcnic_bc_trans
*trans
;
1190 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1191 struct qlcnic_cmd_args cmd
;
1196 if (adapter
->need_fw_reset
)
1199 if (!test_bit(QLC_BC_VF_STATE
, &vf
->state
) &&
1200 hdr
->op_type
!= QLC_BC_CMD
&&
1201 hdr
->cmd_op
!= QLCNIC_BC_CMD_CHANNEL_INIT
)
1204 if (hdr
->frag_num
> 1) {
1205 qlcnic_sriov_handle_pending_trans(sriov
, vf
, hdr
);
1209 memset(&cmd
, 0, sizeof(struct qlcnic_cmd_args
));
1210 cmd_op
= hdr
->cmd_op
;
1211 if (qlcnic_sriov_alloc_bc_trans(&trans
))
1214 if (hdr
->op_type
== QLC_BC_CMD
)
1215 err
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
, cmd_op
);
1217 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, cmd_op
);
1220 qlcnic_sriov_cleanup_transaction(trans
);
1224 cmd
.op_type
= hdr
->op_type
;
1225 if (qlcnic_sriov_prepare_bc_hdr(trans
, &cmd
, hdr
->seq_id
,
1227 qlcnic_free_mbx_args(&cmd
);
1228 qlcnic_sriov_cleanup_transaction(trans
);
1232 pay_size
= qlcnic_sriov_get_bc_paysize(trans
->req_pay_size
,
1233 trans
->curr_req_frag
);
1234 qlcnic_sriov_pull_bc_msg(vf
->adapter
,
1235 (u32
*)(trans
->req_hdr
+ trans
->curr_req_frag
),
1236 (u32
*)(trans
->req_pay
+ trans
->curr_req_frag
),
1238 trans
->func_id
= vf
->pci_func
;
1240 trans
->trans_id
= hdr
->seq_id
;
1241 trans
->curr_req_frag
++;
1243 if (qlcnic_sriov_soft_flr_check(adapter
, trans
, vf
))
1246 if (trans
->curr_req_frag
== trans
->req_hdr
->num_frags
) {
1247 if (qlcnic_sriov_add_act_list(sriov
, vf
, trans
)) {
1248 qlcnic_free_mbx_args(&cmd
);
1249 qlcnic_sriov_cleanup_transaction(trans
);
1252 spin_lock(&vf
->rcv_pend
.lock
);
1253 list_add_tail(&trans
->list
, &vf
->rcv_pend
.wait_list
);
1254 vf
->rcv_pend
.count
++;
1255 spin_unlock(&vf
->rcv_pend
.lock
);
1259 static void qlcnic_sriov_handle_msg_event(struct qlcnic_sriov
*sriov
,
1260 struct qlcnic_vf_info
*vf
)
1262 struct qlcnic_bc_hdr hdr
;
1263 u32
*ptr
= (u32
*)&hdr
;
1266 for (i
= 2; i
< 6; i
++)
1267 ptr
[i
- 2] = readl(QLCNIC_MBX_FW(vf
->adapter
->ahw
, i
));
1268 msg_type
= hdr
.msg_type
;
1271 case QLC_BC_COMMAND
:
1272 qlcnic_sriov_handle_bc_cmd(sriov
, &hdr
, vf
);
1274 case QLC_BC_RESPONSE
:
1275 qlcnic_sriov_handle_bc_resp(&hdr
, vf
);
1280 static void qlcnic_sriov_handle_flr_event(struct qlcnic_sriov
*sriov
,
1281 struct qlcnic_vf_info
*vf
)
1283 struct qlcnic_adapter
*adapter
= vf
->adapter
;
1285 if (qlcnic_sriov_pf_check(adapter
))
1286 qlcnic_sriov_pf_handle_flr(sriov
, vf
);
1288 dev_err(&adapter
->pdev
->dev
,
1289 "Invalid event to VF. VF should not get FLR event\n");
1292 void qlcnic_sriov_handle_bc_event(struct qlcnic_adapter
*adapter
, u32 event
)
1294 struct qlcnic_vf_info
*vf
;
1295 struct qlcnic_sriov
*sriov
;
1299 sriov
= adapter
->ahw
->sriov
;
1300 pci_func
= qlcnic_sriov_target_func_id(event
);
1301 index
= qlcnic_sriov_func_to_index(adapter
, pci_func
);
1306 vf
= &sriov
->vf_info
[index
];
1307 vf
->pci_func
= pci_func
;
1309 if (qlcnic_sriov_channel_free_check(event
))
1310 complete(&vf
->ch_free_cmpl
);
1312 if (qlcnic_sriov_flr_check(event
)) {
1313 qlcnic_sriov_handle_flr_event(sriov
, vf
);
1317 if (qlcnic_sriov_bc_msg_check(event
))
1318 qlcnic_sriov_handle_msg_event(sriov
, vf
);
1321 int qlcnic_sriov_cfg_bc_intr(struct qlcnic_adapter
*adapter
, u8 enable
)
1323 struct qlcnic_cmd_args cmd
;
1326 if (!test_bit(__QLCNIC_SRIOV_ENABLE
, &adapter
->state
))
1329 if (qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_BC_EVENT_SETUP
))
1333 cmd
.req
.arg
[1] = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);
1335 err
= qlcnic_83xx_issue_cmd(adapter
, &cmd
);
1337 if (err
!= QLCNIC_RCODE_SUCCESS
) {
1338 dev_err(&adapter
->pdev
->dev
,
1339 "Failed to %s bc events, err=%d\n",
1340 (enable
? "enable" : "disable"), err
);
1343 qlcnic_free_mbx_args(&cmd
);
1347 static int qlcnic_sriov_retry_bc_cmd(struct qlcnic_adapter
*adapter
,
1348 struct qlcnic_bc_trans
*trans
)
1350 u8 max
= QLC_BC_CMD_MAX_RETRY_CNT
;
1353 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1354 if (state
== QLC_83XX_IDC_DEV_READY
) {
1356 clear_bit(QLC_BC_VF_CHANNEL
, &trans
->vf
->state
);
1357 trans
->trans_state
= QLC_INIT
;
1358 if (++adapter
->fw_fail_cnt
> max
)
1367 static int __qlcnic_sriov_issue_cmd(struct qlcnic_adapter
*adapter
,
1368 struct qlcnic_cmd_args
*cmd
)
1370 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1371 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
1372 struct device
*dev
= &adapter
->pdev
->dev
;
1373 struct qlcnic_bc_trans
*trans
;
1375 u32 rsp_data
, opcode
, mbx_err_code
, rsp
;
1376 u16 seq
= ++adapter
->ahw
->sriov
->bc
.trans_counter
;
1377 u8 func
= ahw
->pci_func
;
1379 rsp
= qlcnic_sriov_alloc_bc_trans(&trans
);
1383 rsp
= qlcnic_sriov_prepare_bc_hdr(trans
, cmd
, seq
, QLC_BC_COMMAND
);
1385 goto cleanup_transaction
;
1388 if (!test_bit(QLC_83XX_MBX_READY
, &mbx
->status
)) {
1390 QLCDB(adapter
, DRV
, "MBX not Ready!(cmd 0x%x) for VF 0x%x\n",
1391 QLCNIC_MBX_RSP(cmd
->req
.arg
[0]), func
);
1395 err
= qlcnic_sriov_send_bc_cmd(adapter
, trans
, func
);
1397 dev_err(dev
, "MBX command 0x%x timed out for VF %d\n",
1398 (cmd
->req
.arg
[0] & 0xffff), func
);
1399 rsp
= QLCNIC_RCODE_TIMEOUT
;
1401 /* After adapter reset PF driver may take some time to
1402 * respond to VF's request. Retry request till maximum retries.
1404 if ((trans
->req_hdr
->cmd_op
== QLCNIC_BC_CMD_CHANNEL_INIT
) &&
1405 !qlcnic_sriov_retry_bc_cmd(adapter
, trans
))
1411 rsp_data
= cmd
->rsp
.arg
[0];
1412 mbx_err_code
= QLCNIC_MBX_STATUS(rsp_data
);
1413 opcode
= QLCNIC_MBX_RSP(cmd
->req
.arg
[0]);
1415 if ((mbx_err_code
== QLCNIC_MBX_RSP_OK
) ||
1416 (mbx_err_code
== QLCNIC_MBX_PORT_RSP_OK
)) {
1417 rsp
= QLCNIC_RCODE_SUCCESS
;
1419 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
) {
1420 rsp
= QLCNIC_RCODE_SUCCESS
;
1427 "MBX command 0x%x failed with err:0x%x for VF %d\n",
1428 opcode
, mbx_err_code
, func
);
1433 if (rsp
== QLCNIC_RCODE_TIMEOUT
) {
1434 ahw
->reset_context
= 1;
1435 adapter
->need_fw_reset
= 1;
1436 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1439 cleanup_transaction
:
1440 qlcnic_sriov_cleanup_transaction(trans
);
1443 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
) {
1444 qlcnic_free_mbx_args(cmd
);
1452 static int qlcnic_sriov_issue_cmd(struct qlcnic_adapter
*adapter
,
1453 struct qlcnic_cmd_args
*cmd
)
1455 if (cmd
->type
== QLC_83XX_MBX_CMD_NO_WAIT
)
1456 return qlcnic_sriov_async_issue_cmd(adapter
, cmd
);
1458 return __qlcnic_sriov_issue_cmd(adapter
, cmd
);
1461 static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter
*adapter
, u8 cmd_op
)
1463 struct qlcnic_cmd_args cmd
;
1464 struct qlcnic_vf_info
*vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1467 memset(&cmd
, 0, sizeof(cmd
));
1468 if (qlcnic_sriov_alloc_bc_mbx_args(&cmd
, cmd_op
))
1471 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
1473 dev_err(&adapter
->pdev
->dev
,
1474 "Failed bc channel %s %d\n", cmd_op
? "term" : "init",
1479 cmd_op
= (cmd
.rsp
.arg
[0] & 0xff);
1480 if (cmd
.rsp
.arg
[0] >> 25 == 2)
1482 if (cmd_op
== QLCNIC_BC_CMD_CHANNEL_INIT
)
1483 set_bit(QLC_BC_VF_STATE
, &vf
->state
);
1485 clear_bit(QLC_BC_VF_STATE
, &vf
->state
);
1488 qlcnic_free_mbx_args(&cmd
);
1492 static void qlcnic_vf_add_mc_list(struct net_device
*netdev
, const u8
*mac
)
1494 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1495 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
1496 struct qlcnic_vf_info
*vf
;
1500 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1502 if (!qlcnic_sriov_check_any_vlan(vf
)) {
1503 qlcnic_nic_add_mac(adapter
, mac
, 0);
1505 spin_lock(&vf
->vlan_list_lock
);
1506 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1507 vlan_id
= vf
->sriov_vlans
[i
];
1509 qlcnic_nic_add_mac(adapter
, mac
, vlan_id
);
1511 spin_unlock(&vf
->vlan_list_lock
);
1512 if (qlcnic_84xx_check(adapter
))
1513 qlcnic_nic_add_mac(adapter
, mac
, 0);
1517 void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel
*bc
)
1519 struct list_head
*head
= &bc
->async_list
;
1520 struct qlcnic_async_work_list
*entry
;
1522 flush_workqueue(bc
->bc_async_wq
);
1523 while (!list_empty(head
)) {
1524 entry
= list_entry(head
->next
, struct qlcnic_async_work_list
,
1526 cancel_work_sync(&entry
->work
);
1527 list_del(&entry
->list
);
1532 void qlcnic_sriov_vf_set_multi(struct net_device
*netdev
)
1534 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1535 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1536 static const u8 bcast_addr
[ETH_ALEN
] = {
1537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1539 struct netdev_hw_addr
*ha
;
1540 u32 mode
= VPORT_MISS_MODE_DROP
;
1542 if (!test_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
))
1545 if (netdev
->flags
& IFF_PROMISC
) {
1546 if (!(adapter
->flags
& QLCNIC_PROMISC_DISABLED
))
1547 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
1548 } else if ((netdev
->flags
& IFF_ALLMULTI
) ||
1549 (netdev_mc_count(netdev
) > ahw
->max_mc_count
)) {
1550 mode
= VPORT_MISS_MODE_ACCEPT_MULTI
;
1552 qlcnic_vf_add_mc_list(netdev
, bcast_addr
);
1553 if (!netdev_mc_empty(netdev
)) {
1554 netdev_for_each_mc_addr(ha
, netdev
)
1555 qlcnic_vf_add_mc_list(netdev
, ha
->addr
);
1559 /* configure unicast MAC address, if there is not sufficient space
1560 * to store all the unicast addresses then enable promiscuous mode
1562 if (netdev_uc_count(netdev
) > ahw
->max_uc_count
) {
1563 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
1564 } else if (!netdev_uc_empty(netdev
)) {
1565 netdev_for_each_uc_addr(ha
, netdev
)
1566 qlcnic_vf_add_mc_list(netdev
, ha
->addr
);
1569 if (adapter
->pdev
->is_virtfn
) {
1570 if (mode
== VPORT_MISS_MODE_ACCEPT_ALL
&&
1571 !adapter
->fdb_mac_learn
) {
1572 qlcnic_alloc_lb_filters_mem(adapter
);
1573 adapter
->drv_mac_learn
= 1;
1574 adapter
->rx_mac_learn
= true;
1576 adapter
->drv_mac_learn
= 0;
1577 adapter
->rx_mac_learn
= false;
1581 qlcnic_nic_set_promisc(adapter
, mode
);
1584 static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct
*work
)
1586 struct qlcnic_async_work_list
*entry
;
1587 struct qlcnic_adapter
*adapter
;
1588 struct qlcnic_cmd_args
*cmd
;
1590 entry
= container_of(work
, struct qlcnic_async_work_list
, work
);
1591 adapter
= entry
->ptr
;
1593 __qlcnic_sriov_issue_cmd(adapter
, cmd
);
1597 static struct qlcnic_async_work_list
*
1598 qlcnic_sriov_get_free_node_async_work(struct qlcnic_back_channel
*bc
)
1600 struct list_head
*node
;
1601 struct qlcnic_async_work_list
*entry
= NULL
;
1604 list_for_each(node
, &bc
->async_list
) {
1605 entry
= list_entry(node
, struct qlcnic_async_work_list
, list
);
1606 if (!work_pending(&entry
->work
)) {
1613 entry
= kzalloc(sizeof(struct qlcnic_async_work_list
),
1617 list_add_tail(&entry
->list
, &bc
->async_list
);
1623 static void qlcnic_sriov_schedule_async_cmd(struct qlcnic_back_channel
*bc
,
1624 work_func_t func
, void *data
,
1625 struct qlcnic_cmd_args
*cmd
)
1627 struct qlcnic_async_work_list
*entry
= NULL
;
1629 entry
= qlcnic_sriov_get_free_node_async_work(bc
);
1635 INIT_WORK(&entry
->work
, func
);
1636 queue_work(bc
->bc_async_wq
, &entry
->work
);
1639 static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter
*adapter
,
1640 struct qlcnic_cmd_args
*cmd
)
1643 struct qlcnic_back_channel
*bc
= &adapter
->ahw
->sriov
->bc
;
1645 if (adapter
->need_fw_reset
)
1648 qlcnic_sriov_schedule_async_cmd(bc
, qlcnic_sriov_handle_async_issue_cmd
,
1653 static int qlcnic_sriov_vf_reinit_driver(struct qlcnic_adapter
*adapter
)
1657 adapter
->need_fw_reset
= 0;
1658 qlcnic_83xx_reinit_mbx_work(adapter
->ahw
->mailbox
);
1659 qlcnic_83xx_enable_mbx_interrupt(adapter
);
1661 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
1665 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
1667 goto err_out_cleanup_bc_intr
;
1669 err
= qlcnic_sriov_vf_init_driver(adapter
);
1671 goto err_out_term_channel
;
1675 err_out_term_channel
:
1676 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
1678 err_out_cleanup_bc_intr
:
1679 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
1683 static void qlcnic_sriov_vf_attach(struct qlcnic_adapter
*adapter
)
1685 struct net_device
*netdev
= adapter
->netdev
;
1687 if (netif_running(netdev
)) {
1688 if (!qlcnic_up(adapter
, netdev
))
1689 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1692 netif_device_attach(netdev
);
1695 static void qlcnic_sriov_vf_detach(struct qlcnic_adapter
*adapter
)
1697 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1698 struct qlcnic_intrpt_config
*intr_tbl
= ahw
->intr_tbl
;
1699 struct net_device
*netdev
= adapter
->netdev
;
1700 u8 i
, max_ints
= ahw
->num_msix
- 1;
1702 netif_device_detach(netdev
);
1703 qlcnic_83xx_detach_mailbox_work(adapter
);
1704 qlcnic_83xx_disable_mbx_intr(adapter
);
1706 if (netif_running(netdev
))
1707 qlcnic_down(adapter
, netdev
);
1709 for (i
= 0; i
< max_ints
; i
++) {
1711 intr_tbl
[i
].enabled
= 0;
1712 intr_tbl
[i
].src
= 0;
1714 ahw
->reset_context
= 0;
1717 static int qlcnic_sriov_vf_handle_dev_ready(struct qlcnic_adapter
*adapter
)
1719 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1720 struct device
*dev
= &adapter
->pdev
->dev
;
1721 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
1722 u8 func
= ahw
->pci_func
;
1725 if ((idc
->prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) ||
1726 (idc
->prev_state
== QLC_83XX_IDC_DEV_INIT
)) {
1727 if (!qlcnic_sriov_vf_reinit_driver(adapter
)) {
1728 qlcnic_sriov_vf_attach(adapter
);
1729 adapter
->fw_fail_cnt
= 0;
1731 "%s: Reinitialization of VF 0x%x done after FW reset\n",
1735 "%s: Reinitialization of VF 0x%x failed after FW reset\n",
1737 state
= QLCRDX(ahw
, QLC_83XX_IDC_DEV_STATE
);
1738 dev_info(dev
, "Current state 0x%x after FW reset\n",
1746 static int qlcnic_sriov_vf_handle_context_reset(struct qlcnic_adapter
*adapter
)
1748 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1749 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
1750 struct device
*dev
= &adapter
->pdev
->dev
;
1751 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
1752 u8 func
= ahw
->pci_func
;
1755 adapter
->reset_ctx_cnt
++;
1757 /* Skip the context reset and check if FW is hung */
1758 if (adapter
->reset_ctx_cnt
< 3) {
1759 adapter
->need_fw_reset
= 1;
1760 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1762 "Resetting context, wait here to check if FW is in failed state\n");
1766 /* Check if number of resets exceed the threshold.
1767 * If it exceeds the threshold just fail the VF.
1769 if (adapter
->reset_ctx_cnt
> QLC_83XX_VF_RESET_FAIL_THRESH
) {
1770 clear_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
1771 adapter
->tx_timeo_cnt
= 0;
1772 adapter
->fw_fail_cnt
= 0;
1773 adapter
->reset_ctx_cnt
= 0;
1774 qlcnic_sriov_vf_detach(adapter
);
1776 "Device context resets have exceeded the threshold, device interface will be shutdown\n");
1780 dev_info(dev
, "Resetting context of VF 0x%x\n", func
);
1781 dev_info(dev
, "%s: Context reset count %d for VF 0x%x\n",
1782 __func__
, adapter
->reset_ctx_cnt
, func
);
1783 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1784 adapter
->need_fw_reset
= 1;
1785 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1786 qlcnic_sriov_vf_detach(adapter
);
1787 adapter
->need_fw_reset
= 0;
1789 if (!qlcnic_sriov_vf_reinit_driver(adapter
)) {
1790 qlcnic_sriov_vf_attach(adapter
);
1791 adapter
->tx_timeo_cnt
= 0;
1792 adapter
->reset_ctx_cnt
= 0;
1793 adapter
->fw_fail_cnt
= 0;
1794 dev_info(dev
, "Done resetting context for VF 0x%x\n", func
);
1796 dev_err(dev
, "%s: Reinitialization of VF 0x%x failed\n",
1798 state
= QLCRDX(ahw
, QLC_83XX_IDC_DEV_STATE
);
1799 dev_info(dev
, "%s: Current state 0x%x\n", __func__
, state
);
1805 static int qlcnic_sriov_vf_idc_ready_state(struct qlcnic_adapter
*adapter
)
1807 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1810 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_READY
)
1811 ret
= qlcnic_sriov_vf_handle_dev_ready(adapter
);
1812 else if (ahw
->reset_context
)
1813 ret
= qlcnic_sriov_vf_handle_context_reset(adapter
);
1815 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1819 static int qlcnic_sriov_vf_idc_failed_state(struct qlcnic_adapter
*adapter
)
1821 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1823 dev_err(&adapter
->pdev
->dev
, "Device is in failed state\n");
1824 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
)
1825 qlcnic_sriov_vf_detach(adapter
);
1827 clear_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
1828 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1833 qlcnic_sriov_vf_idc_need_quiescent_state(struct qlcnic_adapter
*adapter
)
1835 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
1836 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1838 dev_info(&adapter
->pdev
->dev
, "Device is in quiescent state\n");
1839 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
) {
1840 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1841 adapter
->tx_timeo_cnt
= 0;
1842 adapter
->reset_ctx_cnt
= 0;
1843 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1844 qlcnic_sriov_vf_detach(adapter
);
1850 static int qlcnic_sriov_vf_idc_init_reset_state(struct qlcnic_adapter
*adapter
)
1852 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
1853 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
1854 u8 func
= adapter
->ahw
->pci_func
;
1856 if (idc
->prev_state
== QLC_83XX_IDC_DEV_READY
) {
1857 dev_err(&adapter
->pdev
->dev
,
1858 "Firmware hang detected by VF 0x%x\n", func
);
1859 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1860 adapter
->tx_timeo_cnt
= 0;
1861 adapter
->reset_ctx_cnt
= 0;
1862 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
1863 qlcnic_sriov_vf_detach(adapter
);
1868 static int qlcnic_sriov_vf_idc_unknown_state(struct qlcnic_adapter
*adapter
)
1870 dev_err(&adapter
->pdev
->dev
, "%s: Device in unknown state\n", __func__
);
1874 static void qlcnic_sriov_vf_periodic_tasks(struct qlcnic_adapter
*adapter
)
1876 if (adapter
->fhash
.fnum
)
1877 qlcnic_prune_lb_filters(adapter
);
1880 static void qlcnic_sriov_vf_poll_dev_state(struct work_struct
*work
)
1882 struct qlcnic_adapter
*adapter
;
1883 struct qlc_83xx_idc
*idc
;
1886 adapter
= container_of(work
, struct qlcnic_adapter
, fw_work
.work
);
1887 idc
= &adapter
->ahw
->idc
;
1888 idc
->curr_state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1890 switch (idc
->curr_state
) {
1891 case QLC_83XX_IDC_DEV_READY
:
1892 ret
= qlcnic_sriov_vf_idc_ready_state(adapter
);
1894 case QLC_83XX_IDC_DEV_NEED_RESET
:
1895 case QLC_83XX_IDC_DEV_INIT
:
1896 ret
= qlcnic_sriov_vf_idc_init_reset_state(adapter
);
1898 case QLC_83XX_IDC_DEV_NEED_QUISCENT
:
1899 ret
= qlcnic_sriov_vf_idc_need_quiescent_state(adapter
);
1901 case QLC_83XX_IDC_DEV_FAILED
:
1902 ret
= qlcnic_sriov_vf_idc_failed_state(adapter
);
1904 case QLC_83XX_IDC_DEV_QUISCENT
:
1907 ret
= qlcnic_sriov_vf_idc_unknown_state(adapter
);
1910 idc
->prev_state
= idc
->curr_state
;
1911 qlcnic_sriov_vf_periodic_tasks(adapter
);
1913 if (!ret
&& test_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
))
1914 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
1918 static void qlcnic_sriov_vf_cancel_fw_work(struct qlcnic_adapter
*adapter
)
1920 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1923 clear_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1924 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1925 cancel_delayed_work_sync(&adapter
->fw_work
);
1928 static int qlcnic_sriov_check_vlan_id(struct qlcnic_sriov
*sriov
,
1929 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
1931 int i
, err
= -EINVAL
;
1933 if (!vf
->sriov_vlans
)
1936 spin_lock_bh(&vf
->vlan_list_lock
);
1938 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1939 if (vf
->sriov_vlans
[i
] == vlan_id
) {
1945 spin_unlock_bh(&vf
->vlan_list_lock
);
1949 static int qlcnic_sriov_validate_num_vlans(struct qlcnic_sriov
*sriov
,
1950 struct qlcnic_vf_info
*vf
)
1954 spin_lock_bh(&vf
->vlan_list_lock
);
1956 if (vf
->num_vlan
>= sriov
->num_allowed_vlans
)
1959 spin_unlock_bh(&vf
->vlan_list_lock
);
1963 static int qlcnic_sriov_validate_vlan_cfg(struct qlcnic_adapter
*adapter
,
1966 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
1967 struct qlcnic_vf_info
*vf
;
1972 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
1973 vlan_exist
= qlcnic_sriov_check_any_vlan(vf
);
1974 if (sriov
->vlan_mode
!= QLC_GUEST_VLAN_MODE
)
1978 if (qlcnic_83xx_vf_check(adapter
) && vlan_exist
)
1981 if (qlcnic_sriov_validate_num_vlans(sriov
, vf
))
1984 if (sriov
->any_vlan
) {
1985 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
1986 if (sriov
->allowed_vlans
[i
] == vid
)
1994 if (!vlan_exist
|| qlcnic_sriov_check_vlan_id(sriov
, vf
, vid
))
2001 static void qlcnic_sriov_vlan_operation(struct qlcnic_vf_info
*vf
, u16 vlan_id
,
2002 enum qlcnic_vlan_operations opcode
)
2004 struct qlcnic_adapter
*adapter
= vf
->adapter
;
2005 struct qlcnic_sriov
*sriov
;
2007 sriov
= adapter
->ahw
->sriov
;
2009 if (!vf
->sriov_vlans
)
2012 spin_lock_bh(&vf
->vlan_list_lock
);
2016 qlcnic_sriov_add_vlan_id(sriov
, vf
, vlan_id
);
2018 case QLC_VLAN_DELETE
:
2019 qlcnic_sriov_del_vlan_id(sriov
, vf
, vlan_id
);
2022 netdev_err(adapter
->netdev
, "Invalid VLAN operation\n");
2025 spin_unlock_bh(&vf
->vlan_list_lock
);
2029 int qlcnic_sriov_cfg_vf_guest_vlan(struct qlcnic_adapter
*adapter
,
2032 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2033 struct net_device
*netdev
= adapter
->netdev
;
2034 struct qlcnic_vf_info
*vf
;
2035 struct qlcnic_cmd_args cmd
;
2038 memset(&cmd
, 0, sizeof(cmd
));
2042 vf
= &adapter
->ahw
->sriov
->vf_info
[0];
2043 ret
= qlcnic_sriov_validate_vlan_cfg(adapter
, vid
, enable
);
2047 ret
= qlcnic_sriov_alloc_bc_mbx_args(&cmd
,
2048 QLCNIC_BC_CMD_CFG_GUEST_VLAN
);
2052 cmd
.req
.arg
[1] = (enable
& 1) | vid
<< 16;
2054 qlcnic_sriov_cleanup_async_list(&sriov
->bc
);
2055 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
2057 dev_err(&adapter
->pdev
->dev
,
2058 "Failed to configure guest VLAN, err=%d\n", ret
);
2060 netif_addr_lock_bh(netdev
);
2061 qlcnic_free_mac_list(adapter
);
2062 netif_addr_unlock_bh(netdev
);
2065 qlcnic_sriov_vlan_operation(vf
, vid
, QLC_VLAN_ADD
);
2067 qlcnic_sriov_vlan_operation(vf
, vid
, QLC_VLAN_DELETE
);
2069 netif_addr_lock_bh(netdev
);
2070 qlcnic_set_multi(netdev
);
2071 netif_addr_unlock_bh(netdev
);
2074 qlcnic_free_mbx_args(&cmd
);
2078 static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter
*adapter
)
2080 struct list_head
*head
= &adapter
->mac_list
;
2081 struct qlcnic_mac_vlan_list
*cur
;
2083 while (!list_empty(head
)) {
2084 cur
= list_entry(head
->next
, struct qlcnic_mac_vlan_list
, list
);
2085 qlcnic_sre_macaddr_change(adapter
, cur
->mac_addr
, cur
->vlan_id
,
2087 list_del(&cur
->list
);
2093 static int qlcnic_sriov_vf_shutdown(struct pci_dev
*pdev
)
2095 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2096 struct net_device
*netdev
= adapter
->netdev
;
2099 netif_device_detach(netdev
);
2100 qlcnic_cancel_idc_work(adapter
);
2102 if (netif_running(netdev
))
2103 qlcnic_down(adapter
, netdev
);
2105 qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_TERM
);
2106 qlcnic_sriov_cfg_bc_intr(adapter
, 0);
2107 qlcnic_83xx_disable_mbx_intr(adapter
);
2108 cancel_delayed_work_sync(&adapter
->idc_aen_work
);
2110 retval
= pci_save_state(pdev
);
2117 static int qlcnic_sriov_vf_resume(struct qlcnic_adapter
*adapter
)
2119 struct qlc_83xx_idc
*idc
= &adapter
->ahw
->idc
;
2120 struct net_device
*netdev
= adapter
->netdev
;
2123 set_bit(QLC_83XX_MODULE_LOADED
, &idc
->status
);
2124 qlcnic_83xx_enable_mbx_interrupt(adapter
);
2125 err
= qlcnic_sriov_cfg_bc_intr(adapter
, 1);
2129 err
= qlcnic_sriov_channel_cfg_cmd(adapter
, QLCNIC_BC_CMD_CHANNEL_INIT
);
2131 if (netif_running(netdev
)) {
2132 err
= qlcnic_up(adapter
, netdev
);
2134 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
2138 netif_device_attach(netdev
);
2139 qlcnic_schedule_work(adapter
, qlcnic_sriov_vf_poll_dev_state
,
2144 void qlcnic_sriov_alloc_vlans(struct qlcnic_adapter
*adapter
)
2146 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2147 struct qlcnic_vf_info
*vf
;
2150 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
2151 vf
= &sriov
->vf_info
[i
];
2152 vf
->sriov_vlans
= kcalloc(sriov
->num_allowed_vlans
,
2153 sizeof(*vf
->sriov_vlans
), GFP_KERNEL
);
2157 void qlcnic_sriov_free_vlans(struct qlcnic_adapter
*adapter
)
2159 struct qlcnic_sriov
*sriov
= adapter
->ahw
->sriov
;
2160 struct qlcnic_vf_info
*vf
;
2163 for (i
= 0; i
< sriov
->num_vfs
; i
++) {
2164 vf
= &sriov
->vf_info
[i
];
2165 kfree(vf
->sriov_vlans
);
2166 vf
->sriov_vlans
= NULL
;
2170 void qlcnic_sriov_add_vlan_id(struct qlcnic_sriov
*sriov
,
2171 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
2175 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
2176 if (!vf
->sriov_vlans
[i
]) {
2177 vf
->sriov_vlans
[i
] = vlan_id
;
2184 void qlcnic_sriov_del_vlan_id(struct qlcnic_sriov
*sriov
,
2185 struct qlcnic_vf_info
*vf
, u16 vlan_id
)
2189 for (i
= 0; i
< sriov
->num_allowed_vlans
; i
++) {
2190 if (vf
->sriov_vlans
[i
] == vlan_id
) {
2191 vf
->sriov_vlans
[i
] = 0;
2198 bool qlcnic_sriov_check_any_vlan(struct qlcnic_vf_info
*vf
)
2202 spin_lock_bh(&vf
->vlan_list_lock
);
2207 spin_unlock_bh(&vf
->vlan_list_lock
);