2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
11 static int qlcnic_83xx_enable_vnic_mode(struct qlcnic_adapter
*adapter
, int lock
)
14 if (qlcnic_83xx_lock_driver(adapter
))
17 QLCWRX(adapter
->ahw
, QLC_83XX_VNIC_STATE
, QLCNIC_DEV_NPAR_OPER
);
19 qlcnic_83xx_unlock_driver(adapter
);
24 int qlcnic_83xx_disable_vnic_mode(struct qlcnic_adapter
*adapter
, int lock
)
26 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
29 if (qlcnic_83xx_lock_driver(adapter
))
33 QLCWRX(adapter
->ahw
, QLC_83XX_VNIC_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
34 ahw
->idc
.vnic_state
= QLCNIC_DEV_NPAR_NON_OPER
;
37 qlcnic_83xx_unlock_driver(adapter
);
42 int qlcnic_83xx_set_vnic_opmode(struct qlcnic_adapter
*adapter
)
46 u32 data
= QLCNIC_MGMT_FUNC
;
47 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
49 if (qlcnic_83xx_lock_driver(adapter
))
53 data
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_OP_MODE
);
54 data
= (data
& ~QLC_83XX_SET_FUNC_OPMODE(0x3, id
)) |
55 QLC_83XX_SET_FUNC_OPMODE(QLCNIC_MGMT_FUNC
, id
);
57 QLCWRX(adapter
->ahw
, QLC_83XX_DRV_OP_MODE
, data
);
59 qlcnic_83xx_unlock_driver(adapter
);
65 qlcnic_83xx_config_vnic_buff_descriptors(struct qlcnic_adapter
*adapter
)
67 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
69 if (ahw
->port_type
== QLCNIC_XGBE
) {
70 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
71 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
72 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
73 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
75 } else if (ahw
->port_type
== QLCNIC_GBE
) {
76 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
77 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
78 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
79 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
81 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
82 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
87 * qlcnic_83xx_init_mgmt_vnic
89 * @adapter: adapter structure
90 * Management virtual NIC sets the operational mode of other vNIC's and
91 * configures embedded switch (ESWITCH).
92 * Returns: Success(0) or error code.
95 static int qlcnic_83xx_init_mgmt_vnic(struct qlcnic_adapter
*adapter
)
97 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
98 struct device
*dev
= &adapter
->pdev
->dev
;
99 struct qlcnic_npar_info
*npar
;
102 qlcnic_83xx_get_minidump_template(adapter
);
104 if (!(adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)) {
105 if (qlcnic_init_pci_info(adapter
))
108 npar
= adapter
->npars
;
110 for (i
= 0; i
< ahw
->total_nic_func
; i
++, npar
++) {
111 dev_info(dev
, "id:%d active:%d type:%d port:%d min_bw:%d max_bw:%d mac_addr:%pM\n",
112 npar
->pci_func
, npar
->active
, npar
->type
,
113 npar
->phy_port
, npar
->min_bw
, npar
->max_bw
,
117 dev_info(dev
, "Max functions = %d, active functions = %d\n",
118 ahw
->max_pci_func
, ahw
->total_nic_func
);
120 if (qlcnic_83xx_set_vnic_opmode(adapter
))
123 if (qlcnic_set_default_offload_settings(adapter
))
126 if (qlcnic_reset_npar_config(adapter
))
130 if (qlcnic_83xx_get_port_info(adapter
))
133 qlcnic_83xx_config_vnic_buff_descriptors(adapter
);
134 ahw
->msix_supported
= qlcnic_use_msi_x
? 1 : 0;
135 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
136 qlcnic_83xx_enable_vnic_mode(adapter
, 1);
138 dev_info(dev
, "HAL Version: %d, Management function\n",
139 ahw
->fw_hal_version
);
144 static int qlcnic_83xx_init_privileged_vnic(struct qlcnic_adapter
*adapter
)
148 qlcnic_83xx_get_minidump_template(adapter
);
149 if (qlcnic_83xx_get_port_info(adapter
))
152 qlcnic_83xx_config_vnic_buff_descriptors(adapter
);
153 adapter
->ahw
->msix_supported
= !!qlcnic_use_msi_x
;
154 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
156 dev_info(&adapter
->pdev
->dev
,
157 "HAL Version: %d, Privileged function\n",
158 adapter
->ahw
->fw_hal_version
);
162 static int qlcnic_83xx_init_non_privileged_vnic(struct qlcnic_adapter
*adapter
)
166 qlcnic_83xx_get_fw_version(adapter
);
167 if (qlcnic_set_eswitch_port_config(adapter
))
170 if (qlcnic_83xx_get_port_info(adapter
))
173 qlcnic_83xx_config_vnic_buff_descriptors(adapter
);
174 adapter
->ahw
->msix_supported
= !!qlcnic_use_msi_x
;
175 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
177 dev_info(&adapter
->pdev
->dev
, "HAL Version: %d, Virtual function\n",
178 adapter
->ahw
->fw_hal_version
);
184 * qlcnic_83xx_vnic_opmode
186 * @adapter: adapter structure
187 * Identify virtual NIC operational modes.
189 * Returns: Success(0) or error code.
192 int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter
*adapter
)
194 u32 op_mode
, priv_level
;
195 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
196 struct qlcnic_nic_template
*nic_ops
= adapter
->nic_ops
;
198 qlcnic_get_func_no(adapter
);
199 op_mode
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_OP_MODE
);
201 if (op_mode
== QLC_83XX_DEFAULT_OPMODE
)
202 priv_level
= QLCNIC_MGMT_FUNC
;
204 priv_level
= QLC_83XX_GET_FUNC_PRIVILEGE(op_mode
,
206 switch (priv_level
) {
207 case QLCNIC_NON_PRIV_FUNC
:
208 ahw
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
209 ahw
->idc
.state_entry
= qlcnic_83xx_idc_ready_state_entry
;
210 nic_ops
->init_driver
= qlcnic_83xx_init_non_privileged_vnic
;
212 case QLCNIC_PRIV_FUNC
:
213 ahw
->op_mode
= QLCNIC_PRIV_FUNC
;
214 ahw
->idc
.state_entry
= qlcnic_83xx_idc_vnic_pf_entry
;
215 nic_ops
->init_driver
= qlcnic_83xx_init_privileged_vnic
;
217 case QLCNIC_MGMT_FUNC
:
218 ahw
->op_mode
= QLCNIC_MGMT_FUNC
;
219 ahw
->idc
.state_entry
= qlcnic_83xx_idc_ready_state_entry
;
220 nic_ops
->init_driver
= qlcnic_83xx_init_mgmt_vnic
;
223 dev_err(&adapter
->pdev
->dev
, "Invalid Virtual NIC opmode\n");
227 if (ahw
->capabilities
& QLC_83XX_ESWITCH_CAPABILITY
) {
228 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
229 if (adapter
->drv_mac_learn
)
230 adapter
->rx_mac_learn
= true;
232 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
233 adapter
->rx_mac_learn
= false;
236 ahw
->idc
.vnic_state
= QLCNIC_DEV_NPAR_NON_OPER
;
237 ahw
->idc
.vnic_wait_limit
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
242 int qlcnic_83xx_check_vnic_state(struct qlcnic_adapter
*adapter
)
244 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
245 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
248 state
= QLCRDX(ahw
, QLC_83XX_VNIC_STATE
);
249 while (state
!= QLCNIC_DEV_NPAR_OPER
&& idc
->vnic_wait_limit
) {
250 idc
->vnic_wait_limit
--;
252 state
= QLCRDX(ahw
, QLC_83XX_VNIC_STATE
);
255 if (state
!= QLCNIC_DEV_NPAR_OPER
) {
256 dev_err(&adapter
->pdev
->dev
,
257 "vNIC mode not operational, state check timed out.\n");
264 int qlcnic_83xx_set_port_eswitch_status(struct qlcnic_adapter
*adapter
,
265 int func
, int *port_id
)
267 struct qlcnic_info nic_info
;
270 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
272 err
= qlcnic_get_nic_info(adapter
, &nic_info
, func
);
276 if (nic_info
.capabilities
& QLC_83XX_ESWITCH_CAPABILITY
)
277 *port_id
= nic_info
.phys_port
;
282 adapter
->eswitch
[*port_id
].flags
|= QLCNIC_SWITCH_ENABLE
;