Skip to content

Commit 88936e3

Browse files
321lipengdavem330
authored andcommitted
net: hns3: refactor out hclge_set_vf_vlan_common()
To improve code readability and maintainability, separate the command handling part and the status parsing part from bloated hclge_set_vf_vlan_common(). Signed-off-by: Peng Li <[email protected]> Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent eaede83 commit 88936e3

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8786,32 +8786,16 @@ static void hclge_enable_vlan_filter(struct hnae3_handle *handle, bool enable)
87868786
handle->netdev_flags &= ~HNAE3_VLAN_FLTR;
87878787
}
87888788

8789-
static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, u16 vfid,
8790-
bool is_kill, u16 vlan,
8791-
__be16 proto)
8789+
static int hclge_set_vf_vlan_filter_cmd(struct hclge_dev *hdev, u16 vfid,
8790+
bool is_kill, u16 vlan,
8791+
struct hclge_desc *desc)
87928792
{
8793-
struct hclge_vport *vport = &hdev->vport[vfid];
87948793
struct hclge_vlan_filter_vf_cfg_cmd *req0;
87958794
struct hclge_vlan_filter_vf_cfg_cmd *req1;
8796-
struct hclge_desc desc[2];
87978795
u8 vf_byte_val;
87988796
u8 vf_byte_off;
87998797
int ret;
88008798

8801-
/* if vf vlan table is full, firmware will close vf vlan filter, it
8802-
* is unable and unnecessary to add new vlan id to vf vlan filter.
8803-
* If spoof check is enable, and vf vlan is full, it shouldn't add
8804-
* new vlan, because tx packets with these vlan id will be dropped.
8805-
*/
8806-
if (test_bit(vfid, hdev->vf_vlan_full) && !is_kill) {
8807-
if (vport->vf_info.spoofchk && vlan) {
8808-
dev_err(&hdev->pdev->dev,
8809-
"Can't add vlan due to spoof check is on and vf vlan table is full\n");
8810-
return -EPERM;
8811-
}
8812-
return 0;
8813-
}
8814-
88158799
hclge_cmd_setup_basic_desc(&desc[0],
88168800
HCLGE_OPC_VLAN_FILTER_VF_CFG, false);
88178801
hclge_cmd_setup_basic_desc(&desc[1],
@@ -8841,12 +8825,22 @@ static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, u16 vfid,
88418825
return ret;
88428826
}
88438827

8828+
return 0;
8829+
}
8830+
8831+
static int hclge_check_vf_vlan_cmd_status(struct hclge_dev *hdev, u16 vfid,
8832+
bool is_kill, struct hclge_desc *desc)
8833+
{
8834+
struct hclge_vlan_filter_vf_cfg_cmd *req;
8835+
8836+
req = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[0].data;
8837+
88448838
if (!is_kill) {
88458839
#define HCLGE_VF_VLAN_NO_ENTRY 2
8846-
if (!req0->resp_code || req0->resp_code == 1)
8840+
if (!req->resp_code || req->resp_code == 1)
88478841
return 0;
88488842

8849-
if (req0->resp_code == HCLGE_VF_VLAN_NO_ENTRY) {
8843+
if (req->resp_code == HCLGE_VF_VLAN_NO_ENTRY) {
88508844
set_bit(vfid, hdev->vf_vlan_full);
88518845
dev_warn(&hdev->pdev->dev,
88528846
"vf vlan table is full, vf vlan filter is disabled\n");
@@ -8855,28 +8849,57 @@ static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, u16 vfid,
88558849

88568850
dev_err(&hdev->pdev->dev,
88578851
"Add vf vlan filter fail, ret =%u.\n",
8858-
req0->resp_code);
8852+
req->resp_code);
88598853
} else {
88608854
#define HCLGE_VF_VLAN_DEL_NO_FOUND 1
8861-
if (!req0->resp_code)
8855+
if (!req->resp_code)
88628856
return 0;
88638857

88648858
/* vf vlan filter is disabled when vf vlan table is full,
88658859
* then new vlan id will not be added into vf vlan table.
88668860
* Just return 0 without warning, avoid massive verbose
88678861
* print logs when unload.
88688862
*/
8869-
if (req0->resp_code == HCLGE_VF_VLAN_DEL_NO_FOUND)
8863+
if (req->resp_code == HCLGE_VF_VLAN_DEL_NO_FOUND)
88708864
return 0;
88718865

88728866
dev_err(&hdev->pdev->dev,
88738867
"Kill vf vlan filter fail, ret =%u.\n",
8874-
req0->resp_code);
8868+
req->resp_code);
88758869
}
88768870

88778871
return -EIO;
88788872
}
88798873

8874+
static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, u16 vfid,
8875+
bool is_kill, u16 vlan,
8876+
__be16 proto)
8877+
{
8878+
struct hclge_vport *vport = &hdev->vport[vfid];
8879+
struct hclge_desc desc[2];
8880+
int ret;
8881+
8882+
/* if vf vlan table is full, firmware will close vf vlan filter, it
8883+
* is unable and unnecessary to add new vlan id to vf vlan filter.
8884+
* If spoof check is enable, and vf vlan is full, it shouldn't add
8885+
* new vlan, because tx packets with these vlan id will be dropped.
8886+
*/
8887+
if (test_bit(vfid, hdev->vf_vlan_full) && !is_kill) {
8888+
if (vport->vf_info.spoofchk && vlan) {
8889+
dev_err(&hdev->pdev->dev,
8890+
"Can't add vlan due to spoof check is on and vf vlan table is full\n");
8891+
return -EPERM;
8892+
}
8893+
return 0;
8894+
}
8895+
8896+
ret = hclge_set_vf_vlan_filter_cmd(hdev, vfid, is_kill, vlan, desc);
8897+
if (ret)
8898+
return ret;
8899+
8900+
return hclge_check_vf_vlan_cmd_status(hdev, vfid, is_kill, desc);
8901+
}
8902+
88808903
static int hclge_set_port_vlan_filter(struct hclge_dev *hdev, __be16 proto,
88818904
u16 vlan_id, bool is_kill)
88828905
{

0 commit comments

Comments
 (0)