+
+/**
+ * hinic_set_fdir_filter - Set fdir filter for control path
+ * packet to notify firmware.
+ *
+ * @param hwdev
+ * The hardware interface of a nic device.
+ * @param filter_type
+ * Packet type to filter.
+ * @param qid
+ * Rx qid to filter.
+ * @param type_enable
+ * The status of pkt type filter.
+ * @param enable
+ * Fdir function Enable or Disable.
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+int hinic_set_fdir_filter(void *hwdev, u8 filter_type, u8 qid, u8 type_enable,
+ bool enable)
+{
+ struct hinic_port_qfilter_info port_filer_cmd;
+ u16 out_size = sizeof(port_filer_cmd);
+ int err;
+
+ if (!hwdev)
+ return -EINVAL;
+
+ memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
+ port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ port_filer_cmd.func_id = hinic_global_func_id(hwdev);
+ port_filer_cmd.filter_enable = (u8)enable;
+ port_filer_cmd.filter_type = filter_type;
+ port_filer_cmd.qid = qid;
+ port_filer_cmd.filter_type_enable = type_enable;
+ port_filer_cmd.fdir_flag = 0;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
+ &port_filer_cmd, sizeof(port_filer_cmd),
+ &port_filer_cmd, &out_size);
+ if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR, "Set port Q filter failed, err: %d, status: 0x%x, out size: 0x%x, type: 0x%x,"
+ " enable: 0x%x, qid: 0x%x, filter_type_enable: 0x%x\n",
+ err, port_filer_cmd.mgmt_msg_head.status, out_size,
+ filter_type, enable, qid, type_enable);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * hinic_set_normal_filter - Set fdir filter for IO path packet.
+ *
+ * @param hwdev
+ * The hardware interface of a nic device.
+ * @param qid
+ * Rx qid to filter.
+ * @param normal_type_enable
+ * IO path packet function Enable or Disable
+ * @param key
+ * IO path packet filter key value, such as DIP from pkt.
+ * @param enable
+ * Fdir function Enable or Disable.
+ * @param flag
+ * Filter flag, such as dip or others.
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+int hinic_set_normal_filter(void *hwdev, u8 qid, u8 normal_type_enable,
+ u32 key, bool enable, u8 flag)
+{
+ struct hinic_port_qfilter_info port_filer_cmd;
+ u16 out_size = sizeof(port_filer_cmd);
+ int err;
+
+ if (!hwdev)
+ return -EINVAL;
+
+ memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
+ port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ port_filer_cmd.func_id = hinic_global_func_id(hwdev);
+ port_filer_cmd.filter_enable = (u8)enable;
+ port_filer_cmd.qid = qid;
+ port_filer_cmd.normal_type_enable = normal_type_enable;
+ port_filer_cmd.fdir_flag = flag; /* fdir flag: support dip */
+ port_filer_cmd.key = key;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
+ &port_filer_cmd, sizeof(port_filer_cmd),
+ &port_filer_cmd, &out_size);
+ if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR, "Set normal filter failed, err: %d, status: 0x%x, out size: 0x%x, fdir_flag: 0x%x,"
+ " enable: 0x%x, qid: 0x%x, normal_type_enable: 0x%x, key:0x%x\n",
+ err, port_filer_cmd.mgmt_msg_head.status, out_size,
+ flag, enable, qid, normal_type_enable, key);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * hinic_set_fdir_tcam - Set fdir filter for control packet
+ * by tcam table to notify hardware.
+ *
+ * @param hwdev
+ * The hardware interface of a nic device.
+ * @param type_mask
+ * Index of TCAM.
+ * @param filter_rule
+ * TCAM rule for control packet, such as lacp or bgp.
+ * @param filter_action
+ * TCAM action for control packet, such as accept or drop.
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+int hinic_set_fdir_tcam(void *hwdev, u16 type_mask,
+ struct tag_pa_rule *filter_rule,
+ struct tag_pa_action *filter_action)
+{
+ struct hinic_fdir_tcam_info port_tcam_cmd;
+ u16 out_size = sizeof(port_tcam_cmd);
+ int err;
+
+ if (!hwdev)
+ return -EINVAL;
+
+ memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
+ port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ port_tcam_cmd.tcam_index = type_mask;
+ port_tcam_cmd.flag = TCAM_SET;
+ memcpy((void *)&port_tcam_cmd.filter_rule,
+ (void *)filter_rule, sizeof(struct tag_pa_rule));
+ memcpy((void *)&port_tcam_cmd.filter_action,
+ (void *)filter_action, sizeof(struct tag_pa_action));
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
+ &port_tcam_cmd, sizeof(port_tcam_cmd),
+ &port_tcam_cmd, &out_size);
+ if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR, "Set tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, port_tcam_cmd.mgmt_msg_head.status, out_size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * hinic_clear_fdir_tcam - Clear fdir filter TCAM table for control packet.
+ *
+ * @param hwdev
+ * The hardware interface of a nic device.
+ * @param type_mask
+ * Index of TCAM.
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+int hinic_clear_fdir_tcam(void *hwdev, u16 type_mask)
+{
+ struct hinic_fdir_tcam_info port_tcam_cmd;
+ u16 out_size = sizeof(port_tcam_cmd);
+ int err;
+
+ if (!hwdev)
+ return -EINVAL;
+
+ memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
+ port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ port_tcam_cmd.tcam_index = type_mask;
+ port_tcam_cmd.flag = TCAM_CLEAR;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
+ &port_tcam_cmd, sizeof(port_tcam_cmd),
+ &port_tcam_cmd, &out_size);
+ if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR, "Clear tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, port_tcam_cmd.mgmt_msg_head.status, out_size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int hinic_add_tcam_rule(void *hwdev, struct tag_tcam_cfg_rule *tcam_rule)
+{
+ u16 out_size = sizeof(struct tag_fdir_add_rule_cmd);
+ struct tag_fdir_add_rule_cmd tcam_cmd;
+ int err;
+
+ if (!hwdev) {
+ PMD_DRV_LOG(ERR, "Hwdev is NULL");
+ return -EINVAL;
+ }
+
+ if (tcam_rule->index >= HINIC_MAX_TCAM_RULES_NUM) {
+ PMD_DRV_LOG(ERR, "Tcam rules num to add is invalid");
+ return -EINVAL;
+ }
+
+ memset(&tcam_cmd, 0, sizeof(struct tag_fdir_add_rule_cmd));
+ tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ memcpy((void *)&tcam_cmd.rule, (void *)tcam_rule,
+ sizeof(struct tag_tcam_cfg_rule));
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_ADD_FLOW,
+ &tcam_cmd, sizeof(tcam_cmd),
+ &tcam_cmd, &out_size);
+ if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
+ PMD_DRV_LOG(ERR,
+ "Add tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, tcam_cmd.mgmt_msg_head.status, out_size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int hinic_del_tcam_rule(void *hwdev, u32 index)
+{
+ u16 out_size = sizeof(struct tag_fdir_del_rule_cmd);
+ struct tag_fdir_del_rule_cmd tcam_cmd;
+ int err;
+
+ if (!hwdev) {
+ PMD_DRV_LOG(ERR, "Hwdev is NULL");
+ return -EINVAL;
+ }
+
+ if (index >= HINIC_MAX_TCAM_RULES_NUM) {
+ PMD_DRV_LOG(ERR, "Tcam rules num to del is invalid");
+ return -EINVAL;
+ }
+
+ memset(&tcam_cmd, 0, sizeof(struct tag_fdir_del_rule_cmd));
+ tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ tcam_cmd.index_start = index;
+ tcam_cmd.index_num = 1;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_DEL_FLOW,
+ &tcam_cmd, sizeof(tcam_cmd),
+ &tcam_cmd, &out_size);
+ if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
+ PMD_DRV_LOG(ERR,
+ "Del tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, tcam_cmd.mgmt_msg_head.status, out_size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static int hinic_mgmt_tcam_block(void *hwdev, u8 alloc_en,
+ u8 block_type, u16 *index)
+{
+ struct hinic_cmd_ctrl_tcam_block tcam_block_info;
+ u16 out_size = sizeof(struct hinic_cmd_ctrl_tcam_block);
+ struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
+ int err;
+
+ if (!hwdev) {
+ PMD_DRV_LOG(ERR, "Hwdev is NULL");
+ return -EINVAL;
+ }
+
+ memset(&tcam_block_info, 0, sizeof(struct hinic_cmd_ctrl_tcam_block));
+ tcam_block_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ tcam_block_info.func_id = hinic_global_func_id(hwdev);
+ tcam_block_info.alloc_en = alloc_en;
+ tcam_block_info.tcam_type = block_type;
+ tcam_block_info.tcam_block_index = *index;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev,
+ HINIC_PORT_CMD_UP_TC_CTRL_TCAM_BLOCK,
+ &tcam_block_info, sizeof(tcam_block_info),
+ &tcam_block_info, &out_size);
+ if (tcam_block_info.mgmt_msg_head.status ==
+ HINIC_MGMT_CMD_UNSUPPORTED) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(INFO, "Firmware/uP doesn't support alloc or del tcam block");
+ return err;
+ } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
+ (HINIC_IS_VF(nic_hwdev))) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(INFO, "VF doesn't support alloc and del tcam block.");
+ return err;
+ } else if (err || (!out_size) || tcam_block_info.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR,
+ "Set tcam block failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, tcam_block_info.mgmt_msg_head.status, out_size);
+ return -EIO;
+ }
+
+ if (alloc_en)
+ *index = tcam_block_info.tcam_block_index;
+
+ return 0;
+}
+
+int hinic_alloc_tcam_block(void *hwdev, u8 block_type, u16 *index)
+{
+ return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_ENABLE,
+ block_type, index);
+}
+
+int hinic_free_tcam_block(void *hwdev, u8 block_type, u16 *index)
+{
+ return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_DISABLE,
+ block_type, index);
+}
+
+int hinic_flush_tcam_rule(void *hwdev)
+{
+ struct hinic_cmd_flush_tcam_rules tcam_flush;
+ u16 out_size = sizeof(struct hinic_cmd_flush_tcam_rules);
+ struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
+ int err;
+
+ if (!hwdev) {
+ PMD_DRV_LOG(ERR, "Hwdev is NULL");
+ return -EINVAL;
+ }
+
+ memset(&tcam_flush, 0, sizeof(struct hinic_cmd_flush_tcam_rules));
+ tcam_flush.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ tcam_flush.func_id = hinic_global_func_id(hwdev);
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_FLUSH_TCAM,
+ &tcam_flush, sizeof(struct hinic_cmd_flush_tcam_rules),
+ &tcam_flush, &out_size);
+ if (tcam_flush.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(INFO, "Firmware/uP doesn't support flush tcam fdir");
+ } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
+ (HINIC_IS_VF(nic_hwdev))) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(INFO, "VF doesn't support flush tcam fdir");
+ } else if (err || (!out_size) || tcam_flush.mgmt_msg_head.status) {
+ PMD_DRV_LOG(ERR,
+ "Flush tcam fdir rules failed, err: %d, status: 0x%x, out size: 0x%x",
+ err, tcam_flush.mgmt_msg_head.status, out_size);
+ err = -EIO;
+ }
+
+ return err;
+}
+
+int hinic_set_fdir_tcam_rule_filter(void *hwdev, bool enable)
+{
+ struct hinic_port_tcam_info port_tcam_cmd;
+ u16 out_size = sizeof(port_tcam_cmd);
+ int err;
+
+ if (!hwdev)
+ return -EINVAL;
+
+ memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
+ port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+ port_tcam_cmd.func_id = hinic_global_func_id(hwdev);
+ port_tcam_cmd.tcam_enable = (u8)enable;
+
+ err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_ENABLE,
+ &port_tcam_cmd, sizeof(port_tcam_cmd),
+ &port_tcam_cmd, &out_size);
+ if ((port_tcam_cmd.mgmt_msg_head.status != HINIC_MGMT_CMD_UNSUPPORTED &&
+ port_tcam_cmd.mgmt_msg_head.status) || err || !out_size) {
+ if (err == HINIC_MBOX_VF_CMD_ERROR &&
+ HINIC_IS_VF((struct hinic_hwdev *)hwdev)) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(WARNING, "VF doesn't support setting fdir tcam filter");
+ return err;
+ }
+ PMD_DRV_LOG(ERR, "Set fdir tcam filter failed, err: %d, "
+ "status: 0x%x, out size: 0x%x, enable: 0x%x",
+ err, port_tcam_cmd.mgmt_msg_head.status, out_size,
+ enable);
+ return -EIO;
+ }
+
+ if (port_tcam_cmd.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
+ err = HINIC_MGMT_CMD_UNSUPPORTED;
+ PMD_DRV_LOG(WARNING, "Fw doesn't support setting fdir tcam filter");
+ }
+
+ return err;
+}
+
+