Commit d91abf90 authored by Jitendra Kalsaria's avatar Jitendra Kalsaria Committed by David S. Miller

qlcnic: Updates to QLogic application/driver interface for virtual NIC configuration

Qlogic application interface in the driver which has larger than 8 vNIC
configuration support has been updated to handle the following cases:

o Only 8 or lower total vNICs were enabled within the vNIC 0-7 range
o vNICs were enabled in the vNIC 0-15 range such that enabled vNICs were
  not contiguous and only 8 or lower number of total VNICs were enabled
o Disconnect in the vNIC mapping between application and driver when the
  enabled VNICs were dis contiguous
Signed-off-by: default avatarJitendra Kalsaria <jitendra.kalsaria@qlogic.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 225837a0
...@@ -350,33 +350,15 @@ static ssize_t qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, ...@@ -350,33 +350,15 @@ static ssize_t qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
return size; return size;
} }
static u32 qlcnic_get_pci_func_count(struct qlcnic_adapter *adapter)
{
struct qlcnic_hardware_context *ahw = adapter->ahw;
u32 count = 0;
if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
return ahw->total_nic_func;
if (ahw->total_pci_func <= QLC_DEFAULT_VNIC_COUNT)
count = QLC_DEFAULT_VNIC_COUNT;
else
count = ahw->max_vnic_func;
return count;
}
int qlcnic_is_valid_nic_func(struct qlcnic_adapter *adapter, u8 pci_func) int qlcnic_is_valid_nic_func(struct qlcnic_adapter *adapter, u8 pci_func)
{ {
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
int i; int i;
for (i = 0; i < pci_func_count; i++) { for (i = 0; i < adapter->ahw->max_vnic_func; i++) {
if (adapter->npars[i].pci_func == pci_func) if (adapter->npars[i].pci_func == pci_func)
return i; return i;
} }
return -EINVAL;
return -1;
} }
static int validate_pm_config(struct qlcnic_adapter *adapter, static int validate_pm_config(struct qlcnic_adapter *adapter,
...@@ -464,23 +446,21 @@ static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp, ...@@ -464,23 +446,21 @@ static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_pm_func_cfg *pm_cfg; struct qlcnic_pm_func_cfg *pm_cfg;
int i, pm_cfg_size;
u8 pci_func; u8 pci_func;
u32 count;
int i;
pm_cfg_size = pci_func_count * sizeof(*pm_cfg); memset(buf, 0, size);
if (size != pm_cfg_size)
return QL_STATUS_INVALID_PARAM;
memset(buf, 0, pm_cfg_size);
pm_cfg = (struct qlcnic_pm_func_cfg *)buf; pm_cfg = (struct qlcnic_pm_func_cfg *)buf;
count = size / sizeof(struct qlcnic_pm_func_cfg);
for (i = 0; i < pci_func_count; i++) { for (i = 0; i < adapter->ahw->total_nic_func; i++) {
pci_func = adapter->npars[i].pci_func; pci_func = adapter->npars[i].pci_func;
if (!adapter->npars[i].active) if (pci_func >= count) {
dev_dbg(dev, "%s: Total nic functions[%d], App sent function count[%d]\n",
__func__, adapter->ahw->total_nic_func, count);
continue; continue;
}
if (!adapter->npars[i].eswitch_status) if (!adapter->npars[i].eswitch_status)
continue; continue;
...@@ -494,7 +474,6 @@ static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp, ...@@ -494,7 +474,6 @@ static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp,
static int validate_esw_config(struct qlcnic_adapter *adapter, static int validate_esw_config(struct qlcnic_adapter *adapter,
struct qlcnic_esw_func_cfg *esw_cfg, int count) struct qlcnic_esw_func_cfg *esw_cfg, int count)
{ {
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_hardware_context *ahw = adapter->ahw; struct qlcnic_hardware_context *ahw = adapter->ahw;
int i, ret; int i, ret;
u32 op_mode; u32 op_mode;
...@@ -507,7 +486,7 @@ static int validate_esw_config(struct qlcnic_adapter *adapter, ...@@ -507,7 +486,7 @@ static int validate_esw_config(struct qlcnic_adapter *adapter,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
pci_func = esw_cfg[i].pci_func; pci_func = esw_cfg[i].pci_func;
if (pci_func >= pci_func_count) if (pci_func >= ahw->max_vnic_func)
return QL_STATUS_INVALID_PARAM; return QL_STATUS_INVALID_PARAM;
if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
...@@ -642,23 +621,21 @@ static ssize_t qlcnic_sysfs_read_esw_config(struct file *file, ...@@ -642,23 +621,21 @@ static ssize_t qlcnic_sysfs_read_esw_config(struct file *file,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_esw_func_cfg *esw_cfg; struct qlcnic_esw_func_cfg *esw_cfg;
size_t esw_cfg_size; u8 pci_func;
u8 i, pci_func; u32 count;
int i;
esw_cfg_size = pci_func_count * sizeof(*esw_cfg);
if (size != esw_cfg_size)
return QL_STATUS_INVALID_PARAM;
memset(buf, 0, esw_cfg_size); memset(buf, 0, size);
esw_cfg = (struct qlcnic_esw_func_cfg *)buf; esw_cfg = (struct qlcnic_esw_func_cfg *)buf;
count = size / sizeof(struct qlcnic_esw_func_cfg);
for (i = 0; i < pci_func_count; i++) { for (i = 0; i < adapter->ahw->total_nic_func; i++) {
pci_func = adapter->npars[i].pci_func; pci_func = adapter->npars[i].pci_func;
if (!adapter->npars[i].active) if (pci_func >= count) {
dev_dbg(dev, "%s: Total nic functions[%d], App sent function count[%d]\n",
__func__, adapter->ahw->total_nic_func, count);
continue; continue;
}
if (!adapter->npars[i].eswitch_status) if (!adapter->npars[i].eswitch_status)
continue; continue;
...@@ -741,23 +718,24 @@ static ssize_t qlcnic_sysfs_read_npar_config(struct file *file, ...@@ -741,23 +718,24 @@ static ssize_t qlcnic_sysfs_read_npar_config(struct file *file,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_npar_func_cfg *np_cfg; struct qlcnic_npar_func_cfg *np_cfg;
struct qlcnic_info nic_info; struct qlcnic_info nic_info;
size_t np_cfg_size;
int i, ret; int i, ret;
u32 count;
np_cfg_size = pci_func_count * sizeof(*np_cfg);
if (size != np_cfg_size)
return QL_STATUS_INVALID_PARAM;
memset(&nic_info, 0, sizeof(struct qlcnic_info)); memset(&nic_info, 0, sizeof(struct qlcnic_info));
memset(buf, 0, np_cfg_size); memset(buf, 0, size);
np_cfg = (struct qlcnic_npar_func_cfg *)buf; np_cfg = (struct qlcnic_npar_func_cfg *)buf;
for (i = 0; i < pci_func_count; i++) { count = size / sizeof(struct qlcnic_npar_func_cfg);
for (i = 0; i < adapter->ahw->total_nic_func; i++) {
if (qlcnic_is_valid_nic_func(adapter, i) < 0) if (qlcnic_is_valid_nic_func(adapter, i) < 0)
continue; continue;
if (adapter->npars[i].pci_func >= count) {
dev_dbg(dev, "%s: Total nic functions[%d], App sent function count[%d]\n",
__func__, adapter->ahw->total_nic_func, count);
continue;
}
ret = qlcnic_get_nic_info(adapter, &nic_info, i); ret = qlcnic_get_nic_info(adapter, &nic_info, i);
if (ret) if (ret)
return ret; return ret;
...@@ -783,7 +761,6 @@ static ssize_t qlcnic_sysfs_get_port_stats(struct file *file, ...@@ -783,7 +761,6 @@ static ssize_t qlcnic_sysfs_get_port_stats(struct file *file,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_esw_statistics port_stats; struct qlcnic_esw_statistics port_stats;
int ret; int ret;
...@@ -793,7 +770,7 @@ static ssize_t qlcnic_sysfs_get_port_stats(struct file *file, ...@@ -793,7 +770,7 @@ static ssize_t qlcnic_sysfs_get_port_stats(struct file *file,
if (size != sizeof(struct qlcnic_esw_statistics)) if (size != sizeof(struct qlcnic_esw_statistics))
return QL_STATUS_INVALID_PARAM; return QL_STATUS_INVALID_PARAM;
if (offset >= pci_func_count) if (offset >= adapter->ahw->max_vnic_func)
return QL_STATUS_INVALID_PARAM; return QL_STATUS_INVALID_PARAM;
memset(&port_stats, 0, size); memset(&port_stats, 0, size);
...@@ -884,13 +861,12 @@ static ssize_t qlcnic_sysfs_clear_port_stats(struct file *file, ...@@ -884,13 +861,12 @@ static ssize_t qlcnic_sysfs_clear_port_stats(struct file *file,
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
int ret; int ret;
if (qlcnic_83xx_check(adapter)) if (qlcnic_83xx_check(adapter))
return QLC_STATUS_UNSUPPORTED_CMD; return QLC_STATUS_UNSUPPORTED_CMD;
if (offset >= pci_func_count) if (offset >= adapter->ahw->max_vnic_func)
return QL_STATUS_INVALID_PARAM; return QL_STATUS_INVALID_PARAM;
ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
...@@ -914,17 +890,12 @@ static ssize_t qlcnic_sysfs_read_pci_config(struct file *file, ...@@ -914,17 +890,12 @@ static ssize_t qlcnic_sysfs_read_pci_config(struct file *file,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
struct qlcnic_pci_func_cfg *pci_cfg; struct qlcnic_pci_func_cfg *pci_cfg;
struct qlcnic_pci_info *pci_info; struct qlcnic_pci_info *pci_info;
size_t pci_cfg_sz;
int i, ret; int i, ret;
u32 count;
pci_cfg_sz = pci_func_count * sizeof(*pci_cfg); pci_info = kcalloc(size, sizeof(*pci_info), GFP_KERNEL);
if (size != pci_cfg_sz)
return QL_STATUS_INVALID_PARAM;
pci_info = kcalloc(pci_func_count, sizeof(*pci_info), GFP_KERNEL);
if (!pci_info) if (!pci_info)
return -ENOMEM; return -ENOMEM;
...@@ -935,7 +906,8 @@ static ssize_t qlcnic_sysfs_read_pci_config(struct file *file, ...@@ -935,7 +906,8 @@ static ssize_t qlcnic_sysfs_read_pci_config(struct file *file,
} }
pci_cfg = (struct qlcnic_pci_func_cfg *)buf; pci_cfg = (struct qlcnic_pci_func_cfg *)buf;
for (i = 0; i < pci_func_count; i++) { count = size / sizeof(struct qlcnic_pci_func_cfg);
for (i = 0; i < count; i++) {
pci_cfg[i].pci_func = pci_info[i].id; pci_cfg[i].pci_func = pci_info[i].id;
pci_cfg[i].func_type = pci_info[i].type; pci_cfg[i].func_type = pci_info[i].type;
pci_cfg[i].func_state = 0; pci_cfg[i].func_state = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment