Skip to content

Commit

Permalink
qlcnic: Add support for configuring eswitch and npars
Browse files Browse the repository at this point in the history
Following changes are made:
1.Obtain capabilities of Nic partition.
2.Configure tx bandwidth of particular Nic partition.
3.Configure the eswitch for setting port mirroring, enable mac
learning, promiscous mode.

Signed-off-by: Rajesh K Borundia <rajesh.borundia@qlogic.com>
Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Rajesh K Borundia authored and David S. Miller committed Jun 29, 2010
1 parent 45918e2 commit 346fe76
Show file tree
Hide file tree
Showing 3 changed files with 542 additions and 75 deletions.
77 changes: 72 additions & 5 deletions drivers/net/qlcnic/qlcnic.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,6 @@ struct qlcnic_adapter {
u16 switch_mode;
u16 max_tx_ques;
u16 max_rx_ques;
u16 min_tx_bw;
u16 max_tx_bw;
u16 max_mtu;

u32 fw_hal_version;
Expand All @@ -984,7 +982,7 @@ struct qlcnic_adapter {

u64 dev_rst_time;

struct qlcnic_pci_info *npars;
struct qlcnic_npar_info *npars;
struct qlcnic_eswitch *eswitch;
struct qlcnic_nic_template *nic_ops;

Expand Down Expand Up @@ -1042,6 +1040,18 @@ struct qlcnic_pci_info {
u8 reserved2[106];
};

struct qlcnic_npar_info {
u16 vlan_id;
u8 phy_port;
u8 type;
u8 active;
u8 enable_pm;
u8 dest_npar;
u8 host_vlan_tag;
u8 promisc_mode;
u8 discard_tagged;
u8 mac_learning;
};
struct qlcnic_eswitch {
u8 port;
u8 active_vports;
Expand All @@ -1057,6 +1067,63 @@ struct qlcnic_eswitch {
#define QLCNIC_SWITCH_PORT_MIRRORING BIT_4
};


/* Return codes for Error handling */
#define QL_STATUS_INVALID_PARAM -1

#define MAX_BW 10000
#define MIN_BW 100
#define MAX_VLAN_ID 4095
#define MIN_VLAN_ID 2
#define MAX_TX_QUEUES 1
#define MAX_RX_QUEUES 4
#define DEFAULT_MAC_LEARN 1

#define IS_VALID_VLAN(vlan) (vlan >= MIN_VLAN_ID && vlan <= MAX_VLAN_ID)
#define IS_VALID_BW(bw) (bw >= MIN_BW && bw <= MAX_BW \
&& (bw % 100) == 0)
#define IS_VALID_TX_QUEUES(que) (que > 0 && que <= MAX_TX_QUEUES)
#define IS_VALID_RX_QUEUES(que) (que > 0 && que <= MAX_RX_QUEUES)
#define IS_VALID_MODE(mode) (mode == 0 || mode == 1)

struct qlcnic_pci_func_cfg {
u16 func_type;
u16 min_bw;
u16 max_bw;
u16 port_num;
u8 pci_func;
u8 func_state;
u8 def_mac_addr[6];
};

struct qlcnic_npar_func_cfg {
u32 fw_capab;
u16 port_num;
u16 min_bw;
u16 max_bw;
u16 max_tx_queues;
u16 max_rx_queues;
u8 pci_func;
u8 op_mode;
};

struct qlcnic_pm_func_cfg {
u8 pci_func;
u8 action;
u8 dest_npar;
u8 reserved[5];
};

struct qlcnic_esw_func_cfg {
u16 vlan_id;
u8 pci_func;
u8 host_vlan_tag;
u8 promisc_mode;
u8 discard_tagged;
u8 mac_learning;
u8 reserved;
};

int qlcnic_fw_cmd_query_phy(struct qlcnic_adapter *adapter, u32 reg, u32 *val);
int qlcnic_fw_cmd_set_phy(struct qlcnic_adapter *adapter, u32 reg, u32 val);

Expand Down Expand Up @@ -1169,9 +1236,9 @@ void qlcnic_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring);
/* Management functions */
int qlcnic_set_mac_address(struct qlcnic_adapter *, u8*);
int qlcnic_get_mac_address(struct qlcnic_adapter *, u8*);
int qlcnic_get_nic_info(struct qlcnic_adapter *, u8);
int qlcnic_get_nic_info(struct qlcnic_adapter *, struct qlcnic_info *, u8);
int qlcnic_set_nic_info(struct qlcnic_adapter *, struct qlcnic_info *);
int qlcnic_get_pci_info(struct qlcnic_adapter *);
int qlcnic_get_pci_info(struct qlcnic_adapter *, struct qlcnic_pci_info*);
int qlcnic_reset_partition(struct qlcnic_adapter *, u8);

/* eSwitch management functions */
Expand Down
90 changes: 25 additions & 65 deletions drivers/net/qlcnic/qlcnic_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ int qlcnic_get_mac_address(struct qlcnic_adapter *adapter, u8 *mac)
}

/* Get info of a NIC partition */
int qlcnic_get_nic_info(struct qlcnic_adapter *adapter, u8 func_id)
int qlcnic_get_nic_info(struct qlcnic_adapter *adapter,
struct qlcnic_info *npar_info, u8 func_id)
{
int err;
dma_addr_t nic_dma_t;
Expand All @@ -635,29 +636,23 @@ int qlcnic_get_nic_info(struct qlcnic_adapter *adapter, u8 func_id)
QLCNIC_CDRP_CMD_GET_NIC_INFO);

if (err == QLCNIC_RCODE_SUCCESS) {
adapter->physical_port = le16_to_cpu(nic_info->phys_port);
adapter->switch_mode = le16_to_cpu(nic_info->switch_mode);
adapter->max_tx_ques = le16_to_cpu(nic_info->max_tx_ques);
adapter->max_rx_ques = le16_to_cpu(nic_info->max_rx_ques);
adapter->min_tx_bw = le16_to_cpu(nic_info->min_tx_bw);
adapter->max_tx_bw = le16_to_cpu(nic_info->max_tx_bw);
adapter->max_mtu = le16_to_cpu(nic_info->max_mtu);
adapter->capabilities = le32_to_cpu(nic_info->capabilities);
adapter->max_mac_filters = nic_info->max_mac_filters;

if (adapter->capabilities & BIT_6)
adapter->flags |= QLCNIC_ESWITCH_ENABLED;
else
adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
npar_info->phys_port = le16_to_cpu(nic_info->phys_port);
npar_info->switch_mode = le16_to_cpu(nic_info->switch_mode);
npar_info->max_tx_ques = le16_to_cpu(nic_info->max_tx_ques);
npar_info->max_rx_ques = le16_to_cpu(nic_info->max_rx_ques);
npar_info->min_tx_bw = le16_to_cpu(nic_info->min_tx_bw);
npar_info->max_tx_bw = le16_to_cpu(nic_info->max_tx_bw);
npar_info->capabilities = le32_to_cpu(nic_info->capabilities);
npar_info->max_mtu = le16_to_cpu(nic_info->max_mtu);

dev_info(&adapter->pdev->dev,
"phy port: %d switch_mode: %d,\n"
"\tmax_tx_q: %d max_rx_q: %d min_tx_bw: 0x%x,\n"
"\tmax_tx_bw: 0x%x max_mtu:0x%x, capabilities: 0x%x\n",
adapter->physical_port, adapter->switch_mode,
adapter->max_tx_ques, adapter->max_rx_ques,
adapter->min_tx_bw, adapter->max_tx_bw,
adapter->max_mtu, adapter->capabilities);
npar_info->phys_port, npar_info->switch_mode,
npar_info->max_tx_ques, npar_info->max_rx_ques,
npar_info->min_tx_bw, npar_info->max_tx_bw,
npar_info->max_mtu, npar_info->capabilities);
} else {
dev_err(&adapter->pdev->dev,
"Failed to get nic info%d\n", err);
Expand All @@ -672,7 +667,6 @@ int qlcnic_get_nic_info(struct qlcnic_adapter *adapter, u8 func_id)
int qlcnic_set_nic_info(struct qlcnic_adapter *adapter, struct qlcnic_info *nic)
{
int err = -EIO;
u32 func_state;
dma_addr_t nic_dma_t;
void *nic_info_addr;
struct qlcnic_info *nic_info;
Expand All @@ -681,17 +675,6 @@ int qlcnic_set_nic_info(struct qlcnic_adapter *adapter, struct qlcnic_info *nic)
if (adapter->op_mode != QLCNIC_MGMT_FUNC)
return err;

if (qlcnic_api_lock(adapter))
return err;

func_state = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT);
if (QLC_DEV_CHECK_ACTIVE(func_state, nic->pci_func)) {
qlcnic_api_unlock(adapter);
return err;
}

qlcnic_api_unlock(adapter);

nic_info_addr = pci_alloc_consistent(adapter->pdev, nic_size,
&nic_dma_t);
if (!nic_info_addr)
Expand All @@ -716,7 +699,7 @@ int qlcnic_set_nic_info(struct qlcnic_adapter *adapter, struct qlcnic_info *nic)
adapter->fw_hal_version,
MSD(nic_dma_t),
LSD(nic_dma_t),
nic_size,
((nic->pci_func << 16) | nic_size),
QLCNIC_CDRP_CMD_SET_NIC_INFO);

if (err != QLCNIC_RCODE_SUCCESS) {
Expand All @@ -730,7 +713,8 @@ int qlcnic_set_nic_info(struct qlcnic_adapter *adapter, struct qlcnic_info *nic)
}

/* Get PCI Info of a partition */
int qlcnic_get_pci_info(struct qlcnic_adapter *adapter)
int qlcnic_get_pci_info(struct qlcnic_adapter *adapter,
struct qlcnic_pci_info *pci_info)
{
int err = 0, i;
dma_addr_t pci_info_dma_t;
Expand All @@ -745,21 +729,6 @@ int qlcnic_get_pci_info(struct qlcnic_adapter *adapter)
return -ENOMEM;
memset(pci_info_addr, 0, pci_size);

if (!adapter->npars)
adapter->npars = kzalloc(pci_size, GFP_KERNEL);
if (!adapter->npars) {
err = -ENOMEM;
goto err_npar;
}

if (!adapter->eswitch)
adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
if (!adapter->eswitch) {
err = -ENOMEM;
goto err_eswitch;
}

npar = (struct qlcnic_pci_info *) pci_info_addr;
err = qlcnic_issue_cmd(adapter,
adapter->ahw.pci_func,
Expand All @@ -770,31 +739,24 @@ int qlcnic_get_pci_info(struct qlcnic_adapter *adapter)
QLCNIC_CDRP_CMD_GET_PCI_INFO);

if (err == QLCNIC_RCODE_SUCCESS) {
for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++, npar++) {
adapter->npars[i].id = le32_to_cpu(npar->id);
adapter->npars[i].active = le32_to_cpu(npar->active);
adapter->npars[i].type = le32_to_cpu(npar->type);
adapter->npars[i].default_port =
for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++, npar++, pci_info++) {
pci_info->id = le32_to_cpu(npar->id);
pci_info->active = le32_to_cpu(npar->active);
pci_info->type = le32_to_cpu(npar->type);
pci_info->default_port =
le32_to_cpu(npar->default_port);
adapter->npars[i].tx_min_bw =
pci_info->tx_min_bw =
le32_to_cpu(npar->tx_min_bw);
adapter->npars[i].tx_max_bw =
pci_info->tx_max_bw =
le32_to_cpu(npar->tx_max_bw);
memcpy(adapter->npars[i].mac, npar->mac, ETH_ALEN);
memcpy(pci_info->mac, npar->mac, ETH_ALEN);
}
} else {
dev_err(&adapter->pdev->dev,
"Failed to get PCI Info%d\n", err);
kfree(adapter->npars);
err = -EIO;
}
goto err_npar;

err_eswitch:
kfree(adapter->npars);
adapter->npars = NULL;

err_npar:
pci_free_consistent(adapter->pdev, pci_size, pci_info_addr,
pci_info_dma_t);
return err;
Expand Down Expand Up @@ -1012,9 +974,7 @@ int qlcnic_config_switch_port(struct qlcnic_adapter *adapter, u8 id,
if (err != QLCNIC_RCODE_SUCCESS) {
dev_err(&adapter->pdev->dev,
"Failed to configure eswitch port%d\n", eswitch->port);
eswitch->flags |= QLCNIC_SWITCH_ENABLE;
} else {
eswitch->flags &= ~QLCNIC_SWITCH_ENABLE;
dev_info(&adapter->pdev->dev,
"Configured eSwitch for port %d\n", eswitch->port);
}
Expand Down
Loading

0 comments on commit 346fe76

Please sign in to comment.