History

ice: fix access-beyond-end in the switch code

Global `-Warray-bounds` enablement revealed some problems, one of which is the way we define and use AQC rules messages. In fact, they have a shared header, followed by the actual message, which can be of one of several different formats. So it is straightforward enough to define that header as a separate struct and then embed it into message structures as needed, but currently all the formats reside in one union coupled with the header. Then, the code allocates only the memory needed for a particular message format, leaving the union potentially incomplete. There are no actual reads or writes beyond the end of an allocated chunk, but at the same time, the whole implementation is fragile and backed by an equilibrium rather than strong type and memory checks. Define the structures the other way around: one for the common header and the rest for the actual formats with the header embedded. There are no places where several union members would be used at the same time anyway. This allows to use proper struct_size() and let the compiler know what is going to be done. Finally, unsilence `-Warray-bounds` back for ice_switch.c. Other little things worth mentioning: * &ice_sw_rule_vsi_list_query is not used anywhere, remove it. It's weird anyway to talk to hardware with purely kernel types (bitmaps); * expand the ICE_SW_RULE_*_SIZE() macros to pass a structure variable name to struct_size() to let it do strict typechecking; * rename ice_sw_rule_lkup_rx_tx::hdr to ::hdr_data to keep ::hdr for the header structure to have the same name for it constistenly everywhere; * drop the duplicate of %ICE_SW_RULE_RX_TX_NO_HDR_SIZE residing in ice_switch.h.

Alexander Lobakin committed 4 years ago

Commit 6e1ff611 parent c6fbbf14 files · +115 −139Browse files

Unified · Split

4 files
  1. drivers/net/ethernet/intel/ice/Makefile +0 −5
  2. drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +26 −32
  3. drivers/net/ethernet/intel/ice/ice_switch.c +89 −99
  4. drivers/net/ethernet/intel/ice/ice_switch.h +0 −3
drivers/net/ethernet/intel/ice/Makefile+0−5
@@ -47,8 +47,3 @@ ice-$(CONFIG_DCB) += ice_dcb.o ice_dcb_nl.o ice_dcb_lib.o · 46 unmodified lines
4747 ice-$(CONFIG_RFS_ACCEL) += ice_arfs.o
4848 ice-$(CONFIG_XDP_SOCKETS) += ice_xsk.o
4949 ice-$(CONFIG_ICE_SWITCHDEV) += ice_eswitch.o
50−
51−# FIXME: temporarily silence -Warray-bounds on non W=1+ builds
52−ifndef KBUILD_EXTRA_WARN
53−CFLAGS_ice_switch.o += -Wno-array-bounds
54−endif
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h+26−32
@@ -601,12 +601,30 @@ struct ice_aqc_sw_rules { · 600 unmodified lines
601601 __le32 addr_low;
602602 };
603603
604+/* Add switch rule response:
605+ * Content of return buffer is same as the input buffer. The status field and
606+ * LUT index are updated as part of the response
607+ */
608+struct ice_aqc_sw_rules_elem_hdr {
609+ __le16 type; /* Switch rule type, one of T_... */
610+#define ICE_AQC_SW_RULES_T_LKUP_RX 0x0
611+#define ICE_AQC_SW_RULES_T_LKUP_TX 0x1
612+#define ICE_AQC_SW_RULES_T_LG_ACT 0x2
613+#define ICE_AQC_SW_RULES_T_VSI_LIST_SET 0x3
614+#define ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR 0x4
615+#define ICE_AQC_SW_RULES_T_PRUNE_LIST_SET 0x5
616+#define ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR 0x6
617+ __le16 status;
618+} __packed __aligned(sizeof(__le16));
619+
604620 /* Add/Update/Get/Remove lookup Rx/Tx command/response entry
605621 * This structures describes the lookup rules and associated actions. "index"
606622 * is returned as part of a response to a successful Add command, and can be
607623 * used to identify the rule for Update/Get/Remove commands.
608624 */
609625 struct ice_sw_rule_lkup_rx_tx {
626+ struct ice_aqc_sw_rules_elem_hdr hdr;
627+
610628 __le16 recipe_id;
611629 #define ICE_SW_RECIPE_LOGICAL_PORT_FWD 10
612630 /* Source port for LOOKUP_RX and source VSI in case of LOOKUP_TX */
@@ -683,14 +701,16 @@ struct ice_sw_rule_lkup_rx_tx { · 70 unmodified lines
683701 * lookup-type
684702 */
685703 __le16 hdr_len;
686− u8 hdr[];
687−};
704+ u8 hdr_data[];
705+} __packed __aligned(sizeof(__le16));
688706
689707 /* Add/Update/Remove large action command/response entry
690708 * "index" is returned as part of a response to a successful Add command, and
691709 * can be used to identify the action for Update/Get/Remove commands.
692710 */
693711 struct ice_sw_rule_lg_act {
712+ struct ice_aqc_sw_rules_elem_hdr hdr;
713+
694714 __le16 index; /* Index in large action table */
695715 __le16 size;
696716 /* Max number of large actions */
@@ -744,45 +764,19 @@ struct ice_sw_rule_lg_act { · 47 unmodified lines
744764 #define ICE_LG_ACT_STAT_COUNT_S 3
745765 #define ICE_LG_ACT_STAT_COUNT_M (0x7F << ICE_LG_ACT_STAT_COUNT_S)
746766 __le32 act[]; /* array of size for actions */
747−};
767+} __packed __aligned(sizeof(__le16));
748768
749769 /* Add/Update/Remove VSI list command/response entry
750770 * "index" is returned as part of a response to a successful Add command, and
751771 * can be used to identify the VSI list for Update/Get/Remove commands.
752772 */
753773 struct ice_sw_rule_vsi_list {
774+ struct ice_aqc_sw_rules_elem_hdr hdr;
775+
754776 __le16 index; /* Index of VSI/Prune list */
755777 __le16 number_vsi;
756778 __le16 vsi[]; /* Array of number_vsi VSI numbers */
757−};
758−
759−/* Query VSI list command/response entry */
760−struct ice_sw_rule_vsi_list_query {
761− __le16 index;
762− DECLARE_BITMAP(vsi_list, ICE_MAX_VSI);
763−} __packed;
764−
765−/* Add switch rule response:
766− * Content of return buffer is same as the input buffer. The status field and
767− * LUT index are updated as part of the response
768− */
769−struct ice_aqc_sw_rules_elem {
770− __le16 type; /* Switch rule type, one of T_... */
771−#define ICE_AQC_SW_RULES_T_LKUP_RX 0x0
772−#define ICE_AQC_SW_RULES_T_LKUP_TX 0x1
773−#define ICE_AQC_SW_RULES_T_LG_ACT 0x2
774−#define ICE_AQC_SW_RULES_T_VSI_LIST_SET 0x3
775−#define ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR 0x4
776−#define ICE_AQC_SW_RULES_T_PRUNE_LIST_SET 0x5
777−#define ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR 0x6
778− __le16 status;
779− union {
780− struct ice_sw_rule_lkup_rx_tx lkup_tx_rx;
781− struct ice_sw_rule_lg_act lg_act;
782− struct ice_sw_rule_vsi_list vsi_list;
783− struct ice_sw_rule_vsi_list_query vsi_list_query;
784− } __packed pdata;
785−};
779+} __packed __aligned(sizeof(__le16));
786780
787781 /* Query PFC Mode (direct 0x0302)
788782 * Set PFC Mode (direct 0x0303)
drivers/net/ethernet/intel/ice/ice_switch.c+89−99
@@ -1282,18 +1282,13 @@ static const struct ice_dummy_pkt_profile ice_dummy_pkt_profiles[] = { · 1281 unmodified lines
12821282 ICE_PKT_PROFILE(tcp, 0),
12831283 };
12841284
1285−#define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
1286− (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr) + \
1287− (DUMMY_ETH_HDR_LEN * \
1288− sizeof(((struct ice_sw_rule_lkup_rx_tx *)0)->hdr[0])))
1289−#define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
1290− (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr))
1291−#define ICE_SW_RULE_LG_ACT_SIZE(n) \
1292− (offsetof(struct ice_aqc_sw_rules_elem, pdata.lg_act.act) + \
1293− ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act[0])))
1294−#define ICE_SW_RULE_VSI_LIST_SIZE(n) \
1295− (offsetof(struct ice_aqc_sw_rules_elem, pdata.vsi_list.vsi) + \
1296− ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi[0])))
1285+#define ICE_SW_RULE_RX_TX_HDR_SIZE(s, l) struct_size((s), hdr_data, (l))
1286+#define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s) \
1287+ ICE_SW_RULE_RX_TX_HDR_SIZE((s), DUMMY_ETH_HDR_LEN)
1288+#define ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s) \
1289+ ICE_SW_RULE_RX_TX_HDR_SIZE((s), 0)
1290+#define ICE_SW_RULE_LG_ACT_SIZE(s, n) struct_size((s), act, (n))
1291+#define ICE_SW_RULE_VSI_LIST_SIZE(s, n) struct_size((s), vsi, (n))
12971292
12981293 /* this is a recipe to profile association bitmap */
12991294 static DECLARE_BITMAP(recipe_to_profile[ICE_MAX_NUM_RECIPES],
@@ -2376,7 +2371,8 @@ static void ice_fill_sw_info(struct ice_hw *hw, struct ice_fltr_info *fi) · 1076 unmodified lines
23762371 */
23772372 static void
23782373 ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
2379− struct ice_aqc_sw_rules_elem *s_rule, enum ice_adminq_opc opc)
2374+ struct ice_sw_rule_lkup_rx_tx *s_rule,
2375+ enum ice_adminq_opc opc)
23802376 {
23812377 u16 vlan_id = ICE_MAX_VLAN_ID + 1;
23822378 u16 vlan_tpid = ETH_P_8021Q;
@@ -2388,15 +2384,14 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, · 5 unmodified lines
23882384 u8 q_rgn;
23892385
23902386 if (opc == ice_aqc_opc_remove_sw_rules) {
2391− s_rule->pdata.lkup_tx_rx.act = 0;
2392− s_rule->pdata.lkup_tx_rx.index =
2393− cpu_to_le16(f_info->fltr_rule_id);
2394− s_rule->pdata.lkup_tx_rx.hdr_len = 0;
2387+ s_rule->act = 0;
2388+ s_rule->index = cpu_to_le16(f_info->fltr_rule_id);
2389+ s_rule->hdr_len = 0;
23952390 return;
23962391 }
23972392
23982393 eth_hdr_sz = sizeof(dummy_eth_header);
2399− eth_hdr = s_rule->pdata.lkup_tx_rx.hdr;
2394+ eth_hdr = s_rule->hdr_data;
24002395
24012396 /* initialize the ether header with a dummy header */
24022397 memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz);
@@ -2481,14 +2476,14 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, · 78 unmodified lines
24812476 break;
24822477 }
24832478
2484− s_rule->type = (f_info->flag & ICE_FLTR_RX) ?
2479+ s_rule->hdr.type = (f_info->flag & ICE_FLTR_RX) ?
24852480 cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX) :
24862481 cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_TX);
24872482
24882483 /* Recipe set depending on lookup type */
2489− s_rule->pdata.lkup_tx_rx.recipe_id = cpu_to_le16(f_info->lkup_type);
2490− s_rule->pdata.lkup_tx_rx.src = cpu_to_le16(f_info->src);
2491− s_rule->pdata.lkup_tx_rx.act = cpu_to_le32(act);
2484+ s_rule->recipe_id = cpu_to_le16(f_info->lkup_type);
2485+ s_rule->src = cpu_to_le16(f_info->src);
2486+ s_rule->act = cpu_to_le32(act);
24922487
24932488 if (daddr)
24942489 ether_addr_copy(eth_hdr + ICE_ETH_DA_OFFSET, daddr);
@@ -2502,7 +2497,7 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, · 7 unmodified lines
25022497
25032498 /* Create the switch rule with the final dummy Ethernet header */
25042499 if (opc != ice_aqc_opc_update_sw_rules)
2505− s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(eth_hdr_sz);
2500+ s_rule->hdr_len = cpu_to_le16(eth_hdr_sz);
25062501 }
25072502
25082503 /**
@@ -2519,7 +2514,8 @@ static int · 10 unmodified lines
25192514 ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
25202515 u16 sw_marker, u16 l_id)
25212516 {
2522− struct ice_aqc_sw_rules_elem *lg_act, *rx_tx;
2517+ struct ice_sw_rule_lkup_rx_tx *rx_tx;
2518+ struct ice_sw_rule_lg_act *lg_act;
25232519 /* For software marker we need 3 large actions
25242520 * 1. FWD action: FWD TO VSI or VSI LIST
25252521 * 2. GENERIC VALUE action to hold the profile ID
@@ -2540,18 +2536,18 @@ ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent, · 14 unmodified lines
25402536 * 1. Large Action
25412537 * 2. Look up Tx Rx
25422538 */
2543− lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_lg_acts);
2544− rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
2539+ lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(lg_act, num_lg_acts);
2540+ rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(rx_tx);
25452541 lg_act = devm_kzalloc(ice_hw_to_dev(hw), rules_size, GFP_KERNEL);
25462542 if (!lg_act)
25472543 return -ENOMEM;
25482544
2549− rx_tx = (struct ice_aqc_sw_rules_elem *)((u8 *)lg_act + lg_act_size);
2545+ rx_tx = (typeof(rx_tx))((u8 *)lg_act + lg_act_size);
25502546
25512547 /* Fill in the first switch rule i.e. large action */
2552− lg_act->type = cpu_to_le16(ICE_AQC_SW_RULES_T_LG_ACT);
2553− lg_act->pdata.lg_act.index = cpu_to_le16(l_id);
2554− lg_act->pdata.lg_act.size = cpu_to_le16(num_lg_acts);
2548+ lg_act->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_LG_ACT);
2549+ lg_act->index = cpu_to_le16(l_id);
2550+ lg_act->size = cpu_to_le16(num_lg_acts);
25552551
25562552 /* First action VSI forwarding or VSI list forwarding depending on how
25572553 * many VSIs
@@ -2563,13 +2559,13 @@ ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent, · 5 unmodified lines
25632559 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) & ICE_LG_ACT_VSI_LIST_ID_M;
25642560 if (m_ent->vsi_count > 1)
25652561 act |= ICE_LG_ACT_VSI_LIST;
2566− lg_act->pdata.lg_act.act[0] = cpu_to_le32(act);
2562+ lg_act->act[0] = cpu_to_le32(act);
25672563
25682564 /* Second action descriptor type */
25692565 act = ICE_LG_ACT_GENERIC;
25702566
25712567 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
2572− lg_act->pdata.lg_act.act[1] = cpu_to_le32(act);
2568+ lg_act->act[1] = cpu_to_le32(act);
25732569
25742570 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
25752571 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
@@ -2579,24 +2575,22 @@ ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent, · 3 unmodified lines
25792575 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
25802576 ICE_LG_ACT_GENERIC_VALUE_M;
25812577
2582− lg_act->pdata.lg_act.act[2] = cpu_to_le32(act);
2578+ lg_act->act[2] = cpu_to_le32(act);
25832579
25842580 /* call the fill switch rule to fill the lookup Tx Rx structure */
25852581 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
25862582 ice_aqc_opc_update_sw_rules);
25872583
25882584 /* Update the action to point to the large action ID */
2589− rx_tx->pdata.lkup_tx_rx.act =
2590− cpu_to_le32(ICE_SINGLE_ACT_PTR |
2591− ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
2592− ICE_SINGLE_ACT_PTR_VAL_M));
2585+ rx_tx->act = cpu_to_le32(ICE_SINGLE_ACT_PTR |
2586+ ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
2587+ ICE_SINGLE_ACT_PTR_VAL_M));
25932588
25942589 /* Use the filter rule ID of the previously created rule with single
25952590 * act. Once the update happens, hardware will treat this as large
25962591 * action
25972592 */
2598− rx_tx->pdata.lkup_tx_rx.index =
2599− cpu_to_le16(m_ent->fltr_info.fltr_rule_id);
2593+ rx_tx->index = cpu_to_le16(m_ent->fltr_info.fltr_rule_id);
26002594
26012595 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
26022596 ice_aqc_opc_update_sw_rules, NULL);
@@ -2658,7 +2652,7 @@ ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi, · 55 unmodified lines
26582652 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
26592653 enum ice_sw_lkup_type lkup_type)
26602654 {
2661− struct ice_aqc_sw_rules_elem *s_rule;
2655+ struct ice_sw_rule_vsi_list *s_rule;
26622656 u16 s_rule_size;
26632657 u16 rule_type;
26642658 int status;
@@ -2681,7 +2675,7 @@ ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi, · 16 unmodified lines
26812675 else
26822676 return -EINVAL;
26832677
2684− s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
2678+ s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, num_vsi);
26852679 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
26862680 if (!s_rule)
26872681 return -ENOMEM;
@@ -2691,13 +2685,13 @@ ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi, · 3 unmodified lines
26912685 goto exit;
26922686 }
26932687 /* AQ call requires hw_vsi_id(s) */
2694− s_rule->pdata.vsi_list.vsi[i] =
2688+ s_rule->vsi[i] =
26952689 cpu_to_le16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
26962690 }
26972691
2698− s_rule->type = cpu_to_le16(rule_type);
2699− s_rule->pdata.vsi_list.number_vsi = cpu_to_le16(num_vsi);
2700− s_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);
2692+ s_rule->hdr.type = cpu_to_le16(rule_type);
2693+ s_rule->number_vsi = cpu_to_le16(num_vsi);
2694+ s_rule->index = cpu_to_le16(vsi_list_id);
27012695
27022696 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
27032697
@@ -2745,13 +2739,14 @@ ice_create_pkt_fwd_rule(struct ice_hw *hw, · 41 unmodified lines
27452739 struct ice_fltr_list_entry *f_entry)
27462740 {
27472741 struct ice_fltr_mgmt_list_entry *fm_entry;
2748− struct ice_aqc_sw_rules_elem *s_rule;
2742+ struct ice_sw_rule_lkup_rx_tx *s_rule;
27492743 enum ice_sw_lkup_type l_type;
27502744 struct ice_sw_recipe *recp;
27512745 int status;
27522746
27532747 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
2754− ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, GFP_KERNEL);
2748+ ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule),
2749+ GFP_KERNEL);
27552750 if (!s_rule)
27562751 return -ENOMEM;
27572752 fm_entry = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*fm_entry),
@@ -2772,17 +2767,16 @@ ice_create_pkt_fwd_rule(struct ice_hw *hw, · 14 unmodified lines
27722767 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
27732768 ice_aqc_opc_add_sw_rules);
27742769
2775− status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
2770+ status = ice_aq_sw_rules(hw, s_rule,
2771+ ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule), 1,
27762772 ice_aqc_opc_add_sw_rules, NULL);
27772773 if (status) {
27782774 devm_kfree(ice_hw_to_dev(hw), fm_entry);
27792775 goto ice_create_pkt_fwd_rule_exit;
27802776 }
27812777
2782− f_entry->fltr_info.fltr_rule_id =
2783− le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
2784− fm_entry->fltr_info.fltr_rule_id =
2785− le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
2778+ f_entry->fltr_info.fltr_rule_id = le16_to_cpu(s_rule->index);
2779+ fm_entry->fltr_info.fltr_rule_id = le16_to_cpu(s_rule->index);
27862780
27872781 /* The book keeping entries will get removed when base driver
27882782 * calls remove filter AQ command
@@ -2807,20 +2801,22 @@ ice_create_pkt_fwd_rule_exit: · 18 unmodified lines
28072801 static int
28082802 ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
28092803 {
2810− struct ice_aqc_sw_rules_elem *s_rule;
2804+ struct ice_sw_rule_lkup_rx_tx *s_rule;
28112805 int status;
28122806
28132807 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
2814− ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, GFP_KERNEL);
2808+ ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule),
2809+ GFP_KERNEL);
28152810 if (!s_rule)
28162811 return -ENOMEM;
28172812
28182813 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
28192814
2820− s_rule->pdata.lkup_tx_rx.index = cpu_to_le16(f_info->fltr_rule_id);
2815+ s_rule->index = cpu_to_le16(f_info->fltr_rule_id);
28212816
28222817 /* Update switch rule with new rule set to forward VSI list */
2823− status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
2818+ status = ice_aq_sw_rules(hw, s_rule,
2819+ ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule), 1,
28242820 ice_aqc_opc_update_sw_rules, NULL);
28252821
28262822 devm_kfree(ice_hw_to_dev(hw), s_rule);
@@ -3104,17 +3100,17 @@ static int · 277 unmodified lines
31043100 ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
31053101 enum ice_sw_lkup_type lkup_type)
31063102 {
3107− struct ice_aqc_sw_rules_elem *s_rule;
3103+ struct ice_sw_rule_vsi_list *s_rule;
31083104 u16 s_rule_size;
31093105 int status;
31103106
3111− s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
3107+ s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, 0);
31123108 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
31133109 if (!s_rule)
31143110 return -ENOMEM;
31153111
3116− s_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
3117− s_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);
3112+ s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
3113+ s_rule->index = cpu_to_le16(vsi_list_id);
31183114
31193115 /* Free the vsi_list resource that we allocated. It is assumed that the
31203116 * list is empty at this point.
@@ -3274,10 +3270,10 @@ ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id, · 153 unmodified lines
32743270
32753271 if (remove_rule) {
32763272 /* Remove the lookup rule */
3277− struct ice_aqc_sw_rules_elem *s_rule;
3273+ struct ice_sw_rule_lkup_rx_tx *s_rule;
32783274
32793275 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
3280− ICE_SW_RULE_RX_TX_NO_HDR_SIZE,
3276+ ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s_rule),
32813277 GFP_KERNEL);
32823278 if (!s_rule) {
32833279 status = -ENOMEM;
@@ -3288,8 +3284,8 @@ ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id, · 4 unmodified lines
32883284 ice_aqc_opc_remove_sw_rules);
32893285
32903286 status = ice_aq_sw_rules(hw, s_rule,
3291− ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
3292− ice_aqc_opc_remove_sw_rules, NULL);
3287+ ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s_rule),
3288+ 1, ice_aqc_opc_remove_sw_rules, NULL);
32933289
32943290 /* Remove a book keeping from the list */
32953291 devm_kfree(ice_hw_to_dev(hw), s_rule);
@@ -3437,7 +3433,7 @@ bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle) · 141 unmodified lines
34373433 */
34383434 int ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
34393435 {
3440− struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
3436+ struct ice_sw_rule_lkup_rx_tx *s_rule, *r_iter;
34413437 struct ice_fltr_list_entry *m_list_itr;
34423438 struct list_head *rule_head;
34433439 u16 total_elem_left, s_rule_size;
@@ -3501,7 +3497,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 57 unmodified lines
35013497 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
35023498
35033499 /* Allocate switch rule buffer for the bulk update for unicast */
3504− s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
3500+ s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule);
35053501 s_rule = devm_kcalloc(ice_hw_to_dev(hw), num_unicast, s_rule_size,
35063502 GFP_KERNEL);
35073503 if (!s_rule) {
@@ -3517,8 +3513,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 9 unmodified lines
35173513 if (is_unicast_ether_addr(mac_addr)) {
35183514 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
35193515 ice_aqc_opc_add_sw_rules);
3520− r_iter = (struct ice_aqc_sw_rules_elem *)
3521− ((u8 *)r_iter + s_rule_size);
3516+ r_iter = (typeof(s_rule))((u8 *)r_iter + s_rule_size);
35223517 }
35233518 }
35243519
@@ -3527,7 +3522,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 2 unmodified lines
35273522 /* Call AQ switch rule in AQ_MAX chunk */
35283523 for (total_elem_left = num_unicast; total_elem_left > 0;
35293524 total_elem_left -= elem_sent) {
3530− struct ice_aqc_sw_rules_elem *entry = r_iter;
3525+ struct ice_sw_rule_lkup_rx_tx *entry = r_iter;
35313526
35323527 elem_sent = min_t(u8, total_elem_left,
35333528 (ICE_AQ_MAX_BUF_LEN / s_rule_size));
@@ -3536,7 +3531,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 2 unmodified lines
35363531 NULL);
35373532 if (status)
35383533 goto ice_add_mac_exit;
3539− r_iter = (struct ice_aqc_sw_rules_elem *)
3534+ r_iter = (typeof(s_rule))
35403535 ((u8 *)r_iter + (elem_sent * s_rule_size));
35413536 }
35423537
@@ -3548,8 +3543,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 5 unmodified lines
35483543 struct ice_fltr_mgmt_list_entry *fm_entry;
35493544
35503545 if (is_unicast_ether_addr(mac_addr)) {
3551− f_info->fltr_rule_id =
3552− le16_to_cpu(r_iter->pdata.lkup_tx_rx.index);
3546+ f_info->fltr_rule_id = le16_to_cpu(r_iter->index);
35533547 f_info->fltr_act = ICE_FWD_TO_VSI;
35543548 /* Create an entry to track this MAC address */
35553549 fm_entry = devm_kzalloc(ice_hw_to_dev(hw),
@@ -3565,8 +3559,7 @@ int ice_add_mac(struct ice_hw *hw, struct list_head *m_list) · 9 unmodified lines
35653559 */
35663560
35673561 list_add(&fm_entry->list_entry, rule_head);
3568− r_iter = (struct ice_aqc_sw_rules_elem *)
3569− ((u8 *)r_iter + s_rule_size);
3562+ r_iter = (typeof(s_rule))((u8 *)r_iter + s_rule_size);
35703563 }
35713564 }
35723565
@@ -3865,7 +3858,7 @@ ice_rem_adv_rule_info(struct ice_hw *hw, struct list_head *rule_head) · 292 unmodified lines
38653858 */
38663859 int ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction)
38673860 {
3868− struct ice_aqc_sw_rules_elem *s_rule;
3861+ struct ice_sw_rule_lkup_rx_tx *s_rule;
38693862 struct ice_fltr_info f_info;
38703863 enum ice_adminq_opc opcode;
38713864 u16 s_rule_size;
@@ -3876,8 +3869,8 @@ int ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction) · 4 unmodified lines
38763869 return -EINVAL;
38773870 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
38783871
3879− s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
3880− ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
3872+ s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule) :
3873+ ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s_rule);
38813874
38823875 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
38833876 if (!s_rule)
@@ -3915,7 +3908,7 @@ int ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction) · 31 unmodified lines
39153908 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
39163909 goto out;
39173910 if (set) {
3918− u16 index = le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
3911+ u16 index = le16_to_cpu(s_rule->index);
39193912
39203913 if (f_info.flag & ICE_FLTR_TX) {
39213914 hw->port_info->dflt_tx_vsi_num = hw_vsi_id;
@@ -5641,7 +5634,7 @@ ice_find_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt, · 1719 unmodified lines
56415634 */
56425635 static int
56435636 ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
5644− struct ice_aqc_sw_rules_elem *s_rule,
5637+ struct ice_sw_rule_lkup_rx_tx *s_rule,
56455638 const struct ice_dummy_pkt_profile *profile)
56465639 {
56475640 u8 *pkt;
@@ -5650,7 +5643,7 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt, · 2 unmodified lines
56505643 /* Start with a packet with a pre-defined/dummy content. Then, fill
56515644 * in the header values to be looked up or matched.
56525645 */
5653− pkt = s_rule->pdata.lkup_tx_rx.hdr;
5646+ pkt = s_rule->hdr_data;
56545647
56555648 memcpy(pkt, profile->pkt, profile->pkt_len);
56565649
@@ -5740,7 +5733,7 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt, · 83 unmodified lines
57405733 }
57415734 }
57425735
5743− s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(profile->pkt_len);
5736+ s_rule->hdr_len = cpu_to_le16(profile->pkt_len);
57445737
57455738 return 0;
57465739 }
@@ -5963,7 +5956,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 216 unmodified lines
59635956 struct ice_rule_query_data *added_entry)
59645957 {
59655958 struct ice_adv_fltr_mgmt_list_entry *m_entry, *adv_fltr = NULL;
5966− struct ice_aqc_sw_rules_elem *s_rule = NULL;
5959+ struct ice_sw_rule_lkup_rx_tx *s_rule = NULL;
59675960 const struct ice_dummy_pkt_profile *profile;
59685961 u16 rid = 0, i, rule_buf_sz, vsi_handle;
59695962 struct list_head *rule_head;
@@ -6040,7 +6033,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 70 unmodified lines
60406033 }
60416034 return status;
60426035 }
6043− rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE + profile->pkt_len;
6036+ rule_buf_sz = ICE_SW_RULE_RX_TX_HDR_SIZE(s_rule, profile->pkt_len);
60446037 s_rule = kzalloc(rule_buf_sz, GFP_KERNEL);
60456038 if (!s_rule)
60466039 return -ENOMEM;
@@ -6089,16 +6082,15 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 42 unmodified lines
60896082 * by caller)
60906083 */
60916084 if (rinfo->rx) {
6092− s_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX);
6093− s_rule->pdata.lkup_tx_rx.src =
6094− cpu_to_le16(hw->port_info->lport);
6085+ s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX);
6086+ s_rule->src = cpu_to_le16(hw->port_info->lport);
60956087 } else {
6096− s_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_TX);
6097− s_rule->pdata.lkup_tx_rx.src = cpu_to_le16(rinfo->sw_act.src);
6088+ s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_TX);
6089+ s_rule->src = cpu_to_le16(rinfo->sw_act.src);
60986090 }
60996091
6100− s_rule->pdata.lkup_tx_rx.recipe_id = cpu_to_le16(rid);
6101− s_rule->pdata.lkup_tx_rx.act = cpu_to_le32(act);
6092+ s_rule->recipe_id = cpu_to_le16(rid);
6093+ s_rule->act = cpu_to_le32(act);
61026094
61036095 status = ice_fill_adv_dummy_packet(lkups, lkups_cnt, s_rule, profile);
61046096 if (status)
@@ -6107,7 +6099,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 2 unmodified lines
61076099 if (rinfo->tun_type != ICE_NON_TUN &&
61086100 rinfo->tun_type != ICE_SW_TUN_AND_NON_TUN) {
61096101 status = ice_fill_adv_packet_tun(hw, rinfo->tun_type,
6110− s_rule->pdata.lkup_tx_rx.hdr,
6102+ s_rule->hdr_data,
61116103 profile->offsets);
61126104 if (status)
61136105 goto err_ice_add_adv_rule;
@@ -6135,8 +6127,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 21 unmodified lines
61356127
61366128 adv_fltr->lkups_cnt = lkups_cnt;
61376129 adv_fltr->rule_info = *rinfo;
6138− adv_fltr->rule_info.fltr_rule_id =
6139− le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
6130+ adv_fltr->rule_info.fltr_rule_id = le16_to_cpu(s_rule->index);
61406131 sw = hw->switch_info;
61416132 sw->recp_list[rid].adv_rule = true;
61426133 rule_head = &sw->recp_list[rid].filt_rules;
@@ -6384,17 +6375,16 @@ ice_rem_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, · 241 unmodified lines
63846375 }
63856376 mutex_unlock(rule_lock);
63866377 if (remove_rule) {
6387− struct ice_aqc_sw_rules_elem *s_rule;
6378+ struct ice_sw_rule_lkup_rx_tx *s_rule;
63886379 u16 rule_buf_sz;
63896380
6390− rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
6381+ rule_buf_sz = ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s_rule);
63916382 s_rule = kzalloc(rule_buf_sz, GFP_KERNEL);
63926383 if (!s_rule)
63936384 return -ENOMEM;
6394− s_rule->pdata.lkup_tx_rx.act = 0;
6395− s_rule->pdata.lkup_tx_rx.index =
6396− cpu_to_le16(list_elem->rule_info.fltr_rule_id);
6397− s_rule->pdata.lkup_tx_rx.hdr_len = 0;
6385+ s_rule->act = 0;
6386+ s_rule->index = cpu_to_le16(list_elem->rule_info.fltr_rule_id);
6387+ s_rule->hdr_len = 0;
63986388 status = ice_aq_sw_rules(hw, (struct ice_aqc_sw_rules *)s_rule,
63996389 rule_buf_sz, 1,
64006390 ice_aqc_opc_remove_sw_rules, NULL);
drivers/net/ethernet/intel/ice/ice_switch.h+0−3
@@ -23,9 +23,6 @@ · 22 unmodified lines
2323 #define ICE_PROFID_IPV6_GTPU_TEID 46
2424 #define ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER 70
2525
26−#define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
27− (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr))
28−
2926 /* VSI context structure for add/get/update/free operations */
3027 struct ice_vsi_ctx {
3128 u16 vsi_num;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t