Commit 0c264588 authored by Felix Manlunas's avatar Felix Manlunas Committed by David S. Miller

liquidio: fix VF incorrectly indicating that it successfully set its VLAN

For security reasons, NIC firmware does not allow VF to set its VLAN if PF
set it already.  Firmware allows VF to set its VLAN if PF did not set it.
After the VF instructs the firmware to set the VLAN, VF always indicates
(via return 0) that the operation is successful--even for the times when it
isn't.

Put in a mechanism for the VF's set VLAN function to receive the firmware
response code, then make that function return -EPERM if the firmware
forbids the operation.

Make that mechanism available for other functions that may, in the future,
be interested in receiving the response code from the firmware.  That
mechanism involves adding new fields to struct octnic_ctrl_pkt, so make all
users of struct octnic_ctrl_pkt initialize the struct to zero before using
it; otherwise, the mechanism might act on uninitialized garbage.
Signed-off-by: default avatarFelix Manlunas <felix.manlunas@cavium.com>
Signed-off-by: default avatarDerek Chickles <derek.chickles@cavium.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bffb1842
...@@ -127,6 +127,17 @@ void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr) ...@@ -127,6 +127,17 @@ void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
struct octeon_device *oct = lio->oct_dev; struct octeon_device *oct = lio->oct_dev;
u8 *mac; u8 *mac;
if (nctrl->completion && nctrl->response_code) {
/* Signal whoever is interested that the response code from the
* firmware has arrived.
*/
WRITE_ONCE(*nctrl->response_code, nctrl->status);
complete(nctrl->completion);
}
if (nctrl->status)
return;
switch (nctrl->ncmd.s.cmd) { switch (nctrl->ncmd.s.cmd) {
case OCTNET_CMD_CHANGE_DEVFLAGS: case OCTNET_CMD_CHANGE_DEVFLAGS:
case OCTNET_CMD_SET_MULTI_LIST: case OCTNET_CMD_SET_MULTI_LIST:
......
...@@ -3499,6 +3499,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command, ...@@ -3499,6 +3499,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl; struct octnic_ctrl_pkt nctrl;
int ret = 0; int ret = 0;
memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
nctrl.ncmd.u64 = 0; nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command; nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.param1 = rx_cmd; nctrl.ncmd.s.param1 = rx_cmd;
...@@ -3532,6 +3534,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command, ...@@ -3532,6 +3534,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl; struct octnic_ctrl_pkt nctrl;
int ret = 0; int ret = 0;
memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
nctrl.ncmd.u64 = 0; nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command; nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.more = vxlan_cmd_bit; nctrl.ncmd.s.more = vxlan_cmd_bit;
......
...@@ -2484,6 +2484,8 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev, ...@@ -2484,6 +2484,8 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev,
struct lio *lio = GET_LIO(netdev); struct lio *lio = GET_LIO(netdev);
struct octeon_device *oct = lio->oct_dev; struct octeon_device *oct = lio->oct_dev;
struct octnic_ctrl_pkt nctrl; struct octnic_ctrl_pkt nctrl;
struct completion compl;
u16 response_code;
int ret = 0; int ret = 0;
memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
...@@ -2495,14 +2497,25 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev, ...@@ -2495,14 +2497,25 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev,
nctrl.wait_time = 100; nctrl.wait_time = 100;
nctrl.netpndev = (u64)netdev; nctrl.netpndev = (u64)netdev;
nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
init_completion(&compl);
nctrl.completion = &compl;
nctrl.response_code = &response_code;
ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
if (ret < 0) { if (ret < 0) {
dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n", dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
ret); ret);
return -EIO;
} }
return ret; if (!wait_for_completion_timeout(&compl,
msecs_to_jiffies(nctrl.wait_time)))
return -EPERM;
if (READ_ONCE(response_code))
return -EPERM;
return 0;
} }
static int static int
...@@ -2547,6 +2560,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command, ...@@ -2547,6 +2560,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl; struct octnic_ctrl_pkt nctrl;
int ret = 0; int ret = 0;
memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
nctrl.ncmd.u64 = 0; nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command; nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.param1 = rx_cmd; nctrl.ncmd.s.param1 = rx_cmd;
...@@ -2579,6 +2594,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command, ...@@ -2579,6 +2594,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl; struct octnic_ctrl_pkt nctrl;
int ret = 0; int ret = 0;
memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
nctrl.ncmd.u64 = 0; nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command; nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.more = vxlan_cmd_bit; nctrl.ncmd.s.more = vxlan_cmd_bit;
......
...@@ -100,14 +100,16 @@ static void octnet_link_ctrl_callback(struct octeon_device *oct, ...@@ -100,14 +100,16 @@ static void octnet_link_ctrl_callback(struct octeon_device *oct,
nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr; nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;
/* Call the callback function if status is OK. /* Call the callback function if status is zero (meaning OK) or status
* Status is OK only if a response was expected and core returned * contains a firmware status code bigger than zero (meaning the
* success. * firmware is reporting an error).
* If no response was expected, status is OK if the command was posted * If no response was expected, status is OK if the command was posted
* successfully. * successfully.
*/ */
if (!status && nctrl->cb_fn) if ((!status || status > FIRMWARE_STATUS_CODE(0)) && nctrl->cb_fn) {
nctrl->status = status;
nctrl->cb_fn(nctrl); nctrl->cb_fn(nctrl);
}
octeon_free_soft_command(oct, sc); octeon_free_soft_command(oct, sc);
} }
......
...@@ -62,6 +62,10 @@ struct octnic_ctrl_pkt { ...@@ -62,6 +62,10 @@ struct octnic_ctrl_pkt {
/** Callback function called when the command has been fetched */ /** Callback function called when the command has been fetched */
octnic_ctrl_pkt_cb_fn_t cb_fn; octnic_ctrl_pkt_cb_fn_t cb_fn;
u32 status;
u16 *response_code;
struct completion *completion;
}; };
#define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd)) #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
......
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