Skip to content

Commit

Permalink
liquidio: fix VF incorrectly indicating that it successfully set its …
Browse files Browse the repository at this point in the history
…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: Felix Manlunas <felix.manlunas@cavium.com>
Signed-off-by: Derek Chickles <derek.chickles@cavium.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Felix Manlunas authored and David S. Miller committed Apr 8, 2017
1 parent bffb184 commit 0c26458
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
11 changes: 11 additions & 0 deletions drivers/net/ethernet/cavium/liquidio/lio_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
struct octeon_device *oct = lio->oct_dev;
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) {
case OCTNET_CMD_CHANGE_DEVFLAGS:
case OCTNET_CMD_SET_MULTI_LIST:
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/ethernet/cavium/liquidio/lio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl;
int ret = 0;

memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));

nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.param1 = rx_cmd;
Expand Down Expand Up @@ -3532,6 +3534,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl;
int ret = 0;

memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));

nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.more = vxlan_cmd_bit;
Expand Down
19 changes: 18 additions & 1 deletion drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,8 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev,
struct lio *lio = GET_LIO(netdev);
struct octeon_device *oct = lio->oct_dev;
struct octnic_ctrl_pkt nctrl;
struct completion compl;
u16 response_code;
int ret = 0;

memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
Expand All @@ -2495,14 +2497,25 @@ liquidio_vlan_rx_add_vid(struct net_device *netdev,
nctrl.wait_time = 100;
nctrl.netpndev = (u64)netdev;
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);
if (ret < 0) {
dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
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
Expand Down Expand Up @@ -2547,6 +2560,8 @@ static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl;
int ret = 0;

memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));

nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.param1 = rx_cmd;
Expand Down Expand Up @@ -2579,6 +2594,8 @@ static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
struct octnic_ctrl_pkt nctrl;
int ret = 0;

memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));

nctrl.ncmd.u64 = 0;
nctrl.ncmd.s.cmd = command;
nctrl.ncmd.s.more = vxlan_cmd_bit;
Expand Down
10 changes: 6 additions & 4 deletions drivers/net/ethernet/cavium/liquidio/octeon_nic.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ static void octnet_link_ctrl_callback(struct octeon_device *oct,

nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;

/* Call the callback function if status is OK.
* Status is OK only if a response was expected and core returned
* success.
/* Call the callback function if status is zero (meaning OK) or status
* contains a firmware status code bigger than zero (meaning the
* firmware is reporting an error).
* If no response was expected, status is OK if the command was posted
* successfully.
*/
if (!status && nctrl->cb_fn)
if ((!status || status > FIRMWARE_STATUS_CODE(0)) && nctrl->cb_fn) {
nctrl->status = status;
nctrl->cb_fn(nctrl);
}

octeon_free_soft_command(oct, sc);
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/ethernet/cavium/liquidio/octeon_nic.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ struct octnic_ctrl_pkt {

/** Callback function called when the command has been fetched */
octnic_ctrl_pkt_cb_fn_t cb_fn;

u32 status;
u16 *response_code;
struct completion *completion;
};

#define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
Expand Down

0 comments on commit 0c26458

Please sign in to comment.