Skip to content

Commit 741fca1

Browse files
IronShendavem330
authored andcommitted
net: hns3: modify VLAN initialization to be compatible with port based VLAN
Our hardware supports inserting a specified VLAN header for each function when sending packets. User can enable it with command "ip link set <devname> vf <vfid> vlan <vlan id>". For this VLAN header is inserted by hardware, not from stack, hardware also needs to strip it from received packets before sending to stack. In this case, driver needs to tell hardware which VLAN to insert or strip. The current VLAN initialization doesn't allow inserting VLAN header by hardware, this patch modifies it, in order be compatible with VLAN inserted base on port. Signed-off-by: Jian Shen <[email protected]> Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 81f2eeb commit 741fca1

File tree

3 files changed

+78
-30
lines changed

3 files changed

+78
-30
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ enum hnae3_flr_state {
147147
HNAE3_FLR_DONE,
148148
};
149149

150+
enum hnae3_port_base_vlan_state {
151+
HNAE3_PORT_BASE_VLAN_DISABLE,
152+
HNAE3_PORT_BASE_VLAN_ENABLE,
153+
HNAE3_PORT_BASE_VLAN_MODIFY,
154+
HNAE3_PORT_BASE_VLAN_NOCHANGE,
155+
};
156+
150157
struct hnae3_vector_info {
151158
u8 __iomem *io_addr;
152159
int vector;

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

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ static int hclge_alloc_vport(struct hclge_dev *hdev)
13581358
vport->back = hdev;
13591359
vport->vport_id = i;
13601360
vport->mps = HCLGE_MAC_DEFAULT_FRAME;
1361+
vport->port_base_vlan_cfg.state = HNAE3_PORT_BASE_VLAN_DISABLE;
1362+
vport->rxvlan_cfg.rx_vlan_offload_en = true;
13611363
INIT_LIST_HEAD(&vport->vlan_list);
13621364
INIT_LIST_HEAD(&vport->uc_mac_list);
13631365
INIT_LIST_HEAD(&vport->mc_mac_list);
@@ -6680,6 +6682,52 @@ static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
66806682
return status;
66816683
}
66826684

6685+
static int hclge_vlan_offload_cfg(struct hclge_vport *vport,
6686+
u16 port_base_vlan_state,
6687+
u16 vlan_tag)
6688+
{
6689+
int ret;
6690+
6691+
if (port_base_vlan_state == HNAE3_PORT_BASE_VLAN_DISABLE) {
6692+
vport->txvlan_cfg.accept_tag1 = true;
6693+
vport->txvlan_cfg.insert_tag1_en = false;
6694+
vport->txvlan_cfg.default_tag1 = 0;
6695+
} else {
6696+
vport->txvlan_cfg.accept_tag1 = false;
6697+
vport->txvlan_cfg.insert_tag1_en = true;
6698+
vport->txvlan_cfg.default_tag1 = vlan_tag;
6699+
}
6700+
6701+
vport->txvlan_cfg.accept_untag1 = true;
6702+
6703+
/* accept_tag2 and accept_untag2 are not supported on
6704+
* pdev revision(0x20), new revision support them,
6705+
* this two fields can not be configured by user.
6706+
*/
6707+
vport->txvlan_cfg.accept_tag2 = true;
6708+
vport->txvlan_cfg.accept_untag2 = true;
6709+
vport->txvlan_cfg.insert_tag2_en = false;
6710+
vport->txvlan_cfg.default_tag2 = 0;
6711+
6712+
if (port_base_vlan_state == HNAE3_PORT_BASE_VLAN_DISABLE) {
6713+
vport->rxvlan_cfg.strip_tag1_en = false;
6714+
vport->rxvlan_cfg.strip_tag2_en =
6715+
vport->rxvlan_cfg.rx_vlan_offload_en;
6716+
} else {
6717+
vport->rxvlan_cfg.strip_tag1_en =
6718+
vport->rxvlan_cfg.rx_vlan_offload_en;
6719+
vport->rxvlan_cfg.strip_tag2_en = true;
6720+
}
6721+
vport->rxvlan_cfg.vlan1_vlan_prionly = false;
6722+
vport->rxvlan_cfg.vlan2_vlan_prionly = false;
6723+
6724+
ret = hclge_set_vlan_tx_offload_cfg(vport);
6725+
if (ret)
6726+
return ret;
6727+
6728+
return hclge_set_vlan_rx_offload_cfg(vport);
6729+
}
6730+
66836731
static int hclge_set_vlan_protocol_type(struct hclge_dev *hdev)
66846732
{
66856733
struct hclge_rx_vlan_type_cfg_cmd *rx_req;
@@ -6770,34 +6818,14 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
67706818
return ret;
67716819

67726820
for (i = 0; i < hdev->num_alloc_vport; i++) {
6773-
vport = &hdev->vport[i];
6774-
vport->txvlan_cfg.accept_tag1 = true;
6775-
vport->txvlan_cfg.accept_untag1 = true;
6776-
6777-
/* accept_tag2 and accept_untag2 are not supported on
6778-
* pdev revision(0x20), new revision support them. The
6779-
* value of this two fields will not return error when driver
6780-
* send command to fireware in revision(0x20).
6781-
* This two fields can not configured by user.
6782-
*/
6783-
vport->txvlan_cfg.accept_tag2 = true;
6784-
vport->txvlan_cfg.accept_untag2 = true;
6821+
u16 vlan_tag;
67856822

6786-
vport->txvlan_cfg.insert_tag1_en = false;
6787-
vport->txvlan_cfg.insert_tag2_en = false;
6788-
vport->txvlan_cfg.default_tag1 = 0;
6789-
vport->txvlan_cfg.default_tag2 = 0;
6790-
6791-
ret = hclge_set_vlan_tx_offload_cfg(vport);
6792-
if (ret)
6793-
return ret;
6794-
6795-
vport->rxvlan_cfg.strip_tag1_en = false;
6796-
vport->rxvlan_cfg.strip_tag2_en = true;
6797-
vport->rxvlan_cfg.vlan1_vlan_prionly = false;
6798-
vport->rxvlan_cfg.vlan2_vlan_prionly = false;
6823+
vport = &hdev->vport[i];
6824+
vlan_tag = vport->port_base_vlan_cfg.vlan_info.vlan_tag;
67996825

6800-
ret = hclge_set_vlan_rx_offload_cfg(vport);
6826+
ret = hclge_vlan_offload_cfg(vport,
6827+
vport->port_base_vlan_cfg.state,
6828+
vlan_tag);
68016829
if (ret)
68026830
return ret;
68036831
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,11 @@ struct hclge_tx_vtag_cfg {
807807

808808
/* VPort level vlan tag configuration for RX direction */
809809
struct hclge_rx_vtag_cfg {
810-
bool strip_tag1_en; /* Whether strip inner vlan tag */
811-
bool strip_tag2_en; /* Whether strip outer vlan tag */
812-
bool vlan1_vlan_prionly;/* Inner VLAN Tag up to descriptor Enable */
813-
bool vlan2_vlan_prionly;/* Outer VLAN Tag up to descriptor Enable */
810+
u8 rx_vlan_offload_en; /* Whether enable rx vlan offload */
811+
u8 strip_tag1_en; /* Whether strip inner vlan tag */
812+
u8 strip_tag2_en; /* Whether strip outer vlan tag */
813+
u8 vlan1_vlan_prionly; /* Inner VLAN Tag up to descriptor Enable */
814+
u8 vlan2_vlan_prionly; /* Outer VLAN Tag up to descriptor Enable */
814815
};
815816

816817
struct hclge_rss_tuple_cfg {
@@ -829,6 +830,17 @@ enum HCLGE_VPORT_STATE {
829830
HCLGE_VPORT_STATE_MAX
830831
};
831832

833+
struct hclge_vlan_info {
834+
u16 vlan_proto; /* so far support 802.1Q only */
835+
u16 qos;
836+
u16 vlan_tag;
837+
};
838+
839+
struct hclge_port_base_vlan_config {
840+
u16 state;
841+
struct hclge_vlan_info vlan_info;
842+
};
843+
832844
struct hclge_vport {
833845
u16 alloc_tqps; /* Allocated Tx/Rx queues */
834846

@@ -845,6 +857,7 @@ struct hclge_vport {
845857
u16 bw_limit; /* VSI BW Limit (0 = disabled) */
846858
u8 dwrr;
847859

860+
struct hclge_port_base_vlan_config port_base_vlan_cfg;
848861
struct hclge_tx_vtag_cfg txvlan_cfg;
849862
struct hclge_rx_vtag_cfg rxvlan_cfg;
850863

0 commit comments

Comments
 (0)