1 // SPDX-License-Identifier: GPL-2.0-only
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
7 #include <linux/types.h>
8 #include <linux/netdevice.h>
9 #include <linux/etherdevice.h>
10 #include <linux/if_vlan.h>
11 #include <linux/pci.h>
12 #include <linux/device.h>
13 #include <linux/errno.h>
15 #include "hinic_hw_if.h"
16 #include "hinic_hw_dev.h"
17 #include "hinic_port.h"
18 #include "hinic_dev.h"
20 #define HINIC_MIN_MTU_SIZE 256
21 #define HINIC_MAX_JUMBO_FRAME_SIZE 15872
29 * change_mac - change(add or delete) mac address
30 * @nic_dev: nic device
32 * @vlan_id: vlan number to set with the mac
33 * @op: add or delete the mac
35 * Return 0 - Success, negative - Failure
37 static int change_mac(struct hinic_dev *nic_dev, const u8 *addr,
38 u16 vlan_id, enum mac_op op)
40 struct net_device *netdev = nic_dev->netdev;
41 struct hinic_hwdev *hwdev = nic_dev->hwdev;
42 struct hinic_port_mac_cmd port_mac_cmd;
43 struct hinic_hwif *hwif = hwdev->hwif;
44 struct pci_dev *pdev = hwif->pdev;
45 enum hinic_port_cmd cmd;
49 if (vlan_id >= VLAN_N_VID) {
50 netif_err(nic_dev, drv, netdev, "Invalid VLAN number\n");
55 cmd = HINIC_PORT_CMD_SET_MAC;
57 cmd = HINIC_PORT_CMD_DEL_MAC;
59 port_mac_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
60 port_mac_cmd.vlan_id = vlan_id;
61 memcpy(port_mac_cmd.mac, addr, ETH_ALEN);
63 err = hinic_port_msg_cmd(hwdev, cmd, &port_mac_cmd,
65 &port_mac_cmd, &out_size);
66 if (err || (out_size != sizeof(port_mac_cmd)) || port_mac_cmd.status) {
67 dev_err(&pdev->dev, "Failed to change MAC, ret = %d\n",
76 * hinic_port_add_mac - add mac address
77 * @nic_dev: nic device
79 * @vlan_id: vlan number to set with the mac
81 * Return 0 - Success, negative - Failure
83 int hinic_port_add_mac(struct hinic_dev *nic_dev,
84 const u8 *addr, u16 vlan_id)
86 return change_mac(nic_dev, addr, vlan_id, MAC_SET);
90 * hinic_port_del_mac - remove mac address
91 * @nic_dev: nic device
93 * @vlan_id: vlan number that is connected to the mac
95 * Return 0 - Success, negative - Failure
97 int hinic_port_del_mac(struct hinic_dev *nic_dev, const u8 *addr,
100 return change_mac(nic_dev, addr, vlan_id, MAC_DEL);
104 * hinic_port_get_mac - get the mac address of the nic device
105 * @nic_dev: nic device
106 * @addr: returned mac address
108 * Return 0 - Success, negative - Failure
110 int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr)
112 struct hinic_hwdev *hwdev = nic_dev->hwdev;
113 struct hinic_port_mac_cmd port_mac_cmd;
114 struct hinic_hwif *hwif = hwdev->hwif;
115 struct pci_dev *pdev = hwif->pdev;
119 port_mac_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
121 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_MAC,
122 &port_mac_cmd, sizeof(port_mac_cmd),
123 &port_mac_cmd, &out_size);
124 if (err || (out_size != sizeof(port_mac_cmd)) || port_mac_cmd.status) {
125 dev_err(&pdev->dev, "Failed to get mac, ret = %d\n",
126 port_mac_cmd.status);
130 memcpy(addr, port_mac_cmd.mac, ETH_ALEN);
135 * hinic_port_set_mtu - set mtu
136 * @nic_dev: nic device
139 * Return 0 - Success, negative - Failure
141 int hinic_port_set_mtu(struct hinic_dev *nic_dev, int new_mtu)
143 struct net_device *netdev = nic_dev->netdev;
144 struct hinic_hwdev *hwdev = nic_dev->hwdev;
145 struct hinic_port_mtu_cmd port_mtu_cmd;
146 struct hinic_hwif *hwif = hwdev->hwif;
147 struct pci_dev *pdev = hwif->pdev;
151 if (new_mtu < HINIC_MIN_MTU_SIZE) {
152 netif_err(nic_dev, drv, netdev, "mtu < MIN MTU size");
156 max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
157 if (max_frame > HINIC_MAX_JUMBO_FRAME_SIZE) {
158 netif_err(nic_dev, drv, netdev, "mtu > MAX MTU size");
162 port_mtu_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
163 port_mtu_cmd.mtu = new_mtu;
165 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_CHANGE_MTU,
166 &port_mtu_cmd, sizeof(port_mtu_cmd),
167 &port_mtu_cmd, &out_size);
168 if (err || (out_size != sizeof(port_mtu_cmd)) || port_mtu_cmd.status) {
169 dev_err(&pdev->dev, "Failed to set mtu, ret = %d\n",
170 port_mtu_cmd.status);
178 * hinic_port_add_vlan - add vlan to the nic device
179 * @nic_dev: nic device
180 * @vlan_id: the vlan number to add
182 * Return 0 - Success, negative - Failure
184 int hinic_port_add_vlan(struct hinic_dev *nic_dev, u16 vlan_id)
186 struct hinic_hwdev *hwdev = nic_dev->hwdev;
187 struct hinic_port_vlan_cmd port_vlan_cmd;
189 port_vlan_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwdev->hwif);
190 port_vlan_cmd.vlan_id = vlan_id;
192 return hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_ADD_VLAN,
193 &port_vlan_cmd, sizeof(port_vlan_cmd),
198 * hinic_port_del_vlan - delete vlan from the nic device
199 * @nic_dev: nic device
200 * @vlan_id: the vlan number to delete
202 * Return 0 - Success, negative - Failure
204 int hinic_port_del_vlan(struct hinic_dev *nic_dev, u16 vlan_id)
206 struct hinic_hwdev *hwdev = nic_dev->hwdev;
207 struct hinic_port_vlan_cmd port_vlan_cmd;
209 port_vlan_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwdev->hwif);
210 port_vlan_cmd.vlan_id = vlan_id;
212 return hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_DEL_VLAN,
213 &port_vlan_cmd, sizeof(port_vlan_cmd),
218 * hinic_port_set_rx_mode - set rx mode in the nic device
219 * @nic_dev: nic device
220 * @rx_mode: the rx mode to set
222 * Return 0 - Success, negative - Failure
224 int hinic_port_set_rx_mode(struct hinic_dev *nic_dev, u32 rx_mode)
226 struct hinic_hwdev *hwdev = nic_dev->hwdev;
227 struct hinic_port_rx_mode_cmd rx_mode_cmd;
229 rx_mode_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwdev->hwif);
230 rx_mode_cmd.rx_mode = rx_mode;
232 return hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_RX_MODE,
233 &rx_mode_cmd, sizeof(rx_mode_cmd),
238 * hinic_port_link_state - get the link state
239 * @nic_dev: nic device
240 * @link_state: the returned link state
242 * Return 0 - Success, negative - Failure
244 int hinic_port_link_state(struct hinic_dev *nic_dev,
245 enum hinic_port_link_state *link_state)
247 struct hinic_hwdev *hwdev = nic_dev->hwdev;
248 struct hinic_hwif *hwif = hwdev->hwif;
249 struct hinic_port_link_cmd link_cmd;
250 struct pci_dev *pdev = hwif->pdev;
254 if (!HINIC_IS_PF(hwif) && !HINIC_IS_PPF(hwif)) {
255 dev_err(&pdev->dev, "unsupported PCI Function type\n");
259 link_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
261 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_LINK_STATE,
262 &link_cmd, sizeof(link_cmd),
263 &link_cmd, &out_size);
264 if (err || (out_size != sizeof(link_cmd)) || link_cmd.status) {
265 dev_err(&pdev->dev, "Failed to get link state, ret = %d\n",
270 *link_state = link_cmd.state;
275 * hinic_port_set_state - set port state
276 * @nic_dev: nic device
277 * @state: the state to set
279 * Return 0 - Success, negative - Failure
281 int hinic_port_set_state(struct hinic_dev *nic_dev, enum hinic_port_state state)
283 struct hinic_hwdev *hwdev = nic_dev->hwdev;
284 struct hinic_port_state_cmd port_state;
285 struct hinic_hwif *hwif = hwdev->hwif;
286 struct pci_dev *pdev = hwif->pdev;
290 if (!HINIC_IS_PF(hwif) && !HINIC_IS_PPF(hwif)) {
291 dev_err(&pdev->dev, "unsupported PCI Function type\n");
295 port_state.state = state;
297 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_PORT_STATE,
298 &port_state, sizeof(port_state),
299 &port_state, &out_size);
300 if (err || (out_size != sizeof(port_state)) || port_state.status) {
301 dev_err(&pdev->dev, "Failed to set port state, ret = %d\n",
310 * hinic_port_set_func_state- set func device state
311 * @nic_dev: nic device
312 * @state: the state to set
314 * Return 0 - Success, negative - Failure
316 int hinic_port_set_func_state(struct hinic_dev *nic_dev,
317 enum hinic_func_port_state state)
319 struct hinic_port_func_state_cmd func_state;
320 struct hinic_hwdev *hwdev = nic_dev->hwdev;
321 struct hinic_hwif *hwif = hwdev->hwif;
322 struct pci_dev *pdev = hwif->pdev;
326 func_state.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
327 func_state.state = state;
329 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_FUNC_STATE,
330 &func_state, sizeof(func_state),
331 &func_state, &out_size);
332 if (err || (out_size != sizeof(func_state)) || func_state.status) {
333 dev_err(&pdev->dev, "Failed to set port func state, ret = %d\n",
342 * hinic_port_get_cap - get port capabilities
343 * @nic_dev: nic device
344 * @port_cap: returned port capabilities
346 * Return 0 - Success, negative - Failure
348 int hinic_port_get_cap(struct hinic_dev *nic_dev,
349 struct hinic_port_cap *port_cap)
351 struct hinic_hwdev *hwdev = nic_dev->hwdev;
352 struct hinic_hwif *hwif = hwdev->hwif;
353 struct pci_dev *pdev = hwif->pdev;
357 port_cap->func_idx = HINIC_HWIF_FUNC_IDX(hwif);
359 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_CAP,
360 port_cap, sizeof(*port_cap),
361 port_cap, &out_size);
362 if (err || (out_size != sizeof(*port_cap)) || port_cap->status) {
364 "Failed to get port capabilities, ret = %d\n",
373 * hinic_port_set_tso - set port tso configuration
374 * @nic_dev: nic device
375 * @state: the tso state to set
377 * Return 0 - Success, negative - Failure
379 int hinic_port_set_tso(struct hinic_dev *nic_dev, enum hinic_tso_state state)
381 struct hinic_hwdev *hwdev = nic_dev->hwdev;
382 struct hinic_hwif *hwif = hwdev->hwif;
383 struct hinic_tso_config tso_cfg = {0};
384 struct pci_dev *pdev = hwif->pdev;
388 tso_cfg.func_id = HINIC_HWIF_FUNC_IDX(hwif);
389 tso_cfg.tso_en = state;
391 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_TSO,
392 &tso_cfg, sizeof(tso_cfg),
393 &tso_cfg, &out_size);
394 if (err || out_size != sizeof(tso_cfg) || tso_cfg.status) {
396 "Failed to set port tso, ret = %d\n",
404 int hinic_set_rx_csum_offload(struct hinic_dev *nic_dev, u32 en)
406 struct hinic_checksum_offload rx_csum_cfg = {0};
407 struct hinic_hwdev *hwdev = nic_dev->hwdev;
408 struct hinic_hwif *hwif;
409 struct pci_dev *pdev;
418 rx_csum_cfg.func_id = HINIC_HWIF_FUNC_IDX(hwif);
419 rx_csum_cfg.rx_csum_offload = en;
421 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_RX_CSUM,
422 &rx_csum_cfg, sizeof(rx_csum_cfg),
423 &rx_csum_cfg, &out_size);
424 if (err || !out_size || rx_csum_cfg.status) {
426 "Failed to set rx csum offload, ret = %d\n",
434 int hinic_set_max_qnum(struct hinic_dev *nic_dev, u8 num_rqs)
436 struct hinic_hwdev *hwdev = nic_dev->hwdev;
437 struct hinic_hwif *hwif = hwdev->hwif;
438 struct pci_dev *pdev = hwif->pdev;
439 struct hinic_rq_num rq_num = { 0 };
440 u16 out_size = sizeof(rq_num);
443 rq_num.func_id = HINIC_HWIF_FUNC_IDX(hwif);
444 rq_num.num_rqs = num_rqs;
445 rq_num.rq_depth = ilog2(HINIC_SQ_DEPTH);
447 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_RQ_IQ_MAP,
448 &rq_num, sizeof(rq_num),
450 if (err || !out_size || rq_num.status) {
452 "Failed to rxq number, ret = %d\n",
460 static int hinic_set_rx_lro(struct hinic_dev *nic_dev, u8 ipv4_en, u8 ipv6_en,
463 struct hinic_hwdev *hwdev = nic_dev->hwdev;
464 struct hinic_hwif *hwif = hwdev->hwif;
465 struct hinic_lro_config lro_cfg = { 0 };
466 struct pci_dev *pdev = hwif->pdev;
467 u16 out_size = sizeof(lro_cfg);
470 lro_cfg.func_id = HINIC_HWIF_FUNC_IDX(hwif);
471 lro_cfg.lro_ipv4_en = ipv4_en;
472 lro_cfg.lro_ipv6_en = ipv6_en;
473 lro_cfg.lro_max_wqe_num = max_wqe_num;
475 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_LRO,
476 &lro_cfg, sizeof(lro_cfg),
477 &lro_cfg, &out_size);
478 if (err || !out_size || lro_cfg.status) {
480 "Failed to set lro offload, ret = %d\n",
488 static int hinic_set_rx_lro_timer(struct hinic_dev *nic_dev, u32 timer_value)
490 struct hinic_hwdev *hwdev = nic_dev->hwdev;
491 struct hinic_lro_timer lro_timer = { 0 };
492 struct hinic_hwif *hwif = hwdev->hwif;
493 struct pci_dev *pdev = hwif->pdev;
494 u16 out_size = sizeof(lro_timer);
497 lro_timer.status = 0;
499 lro_timer.enable = 1;
500 lro_timer.timer = timer_value;
502 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_LRO_TIMER,
503 &lro_timer, sizeof(lro_timer),
504 &lro_timer, &out_size);
505 if (lro_timer.status == 0xFF) {
506 /* For this case, we think status (0xFF) is OK */
507 lro_timer.status = 0;
509 "Set lro timer not supported by the current FW version, it will be 1ms default\n");
512 if (err || !out_size || lro_timer.status) {
514 "Failed to set lro timer, ret = %d\n",
523 int hinic_set_rx_lro_state(struct hinic_dev *nic_dev, u8 lro_en,
524 u32 lro_timer, u32 wqe_num)
526 struct hinic_hwdev *hwdev = nic_dev->hwdev;
534 ipv4_en = lro_en ? 1 : 0;
535 ipv6_en = lro_en ? 1 : 0;
537 err = hinic_set_rx_lro(nic_dev, ipv4_en, ipv6_en, (u8)wqe_num);
541 err = hinic_set_rx_lro_timer(nic_dev, lro_timer);
548 int hinic_rss_set_indir_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
549 const u32 *indir_table)
551 struct hinic_rss_indirect_tbl *indir_tbl;
552 struct hinic_func_to_io *func_to_io;
553 struct hinic_cmdq_buf cmd_buf;
554 struct hinic_hwdev *hwdev;
555 struct hinic_hwif *hwif;
556 struct pci_dev *pdev;
562 hwdev = nic_dev->hwdev;
563 func_to_io = &hwdev->func_to_io;
567 err = hinic_alloc_cmdq_buf(&func_to_io->cmdqs, &cmd_buf);
569 dev_err(&pdev->dev, "Failed to allocate cmdq buf\n");
573 cmd_buf.size = sizeof(*indir_tbl);
575 indir_tbl = cmd_buf.buf;
576 indir_tbl->group_index = cpu_to_be32(tmpl_idx);
578 for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++) {
579 indir_tbl->entry[i] = indir_table[i];
581 if (0x3 == (i & 0x3)) {
582 temp = (u32 *)&indir_tbl->entry[i - 3];
583 *temp = cpu_to_be32(*temp);
587 /* cfg the rss indirect table by command queue */
588 indir_size = HINIC_RSS_INDIR_SIZE / 2;
589 indir_tbl->offset = 0;
590 indir_tbl->size = cpu_to_be32(indir_size);
592 err = hinic_cmdq_direct_resp(&func_to_io->cmdqs, HINIC_MOD_L2NIC,
593 HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
594 &cmd_buf, &out_param);
595 if (err || out_param != 0) {
596 dev_err(&pdev->dev, "Failed to set rss indir table\n");
601 indir_tbl->offset = cpu_to_be32(indir_size);
602 indir_tbl->size = cpu_to_be32(indir_size);
603 memcpy(&indir_tbl->entry[0], &indir_tbl->entry[indir_size], indir_size);
605 err = hinic_cmdq_direct_resp(&func_to_io->cmdqs, HINIC_MOD_L2NIC,
606 HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
607 &cmd_buf, &out_param);
608 if (err || out_param != 0) {
609 dev_err(&pdev->dev, "Failed to set rss indir table\n");
614 hinic_free_cmdq_buf(&func_to_io->cmdqs, &cmd_buf);
619 int hinic_set_rss_type(struct hinic_dev *nic_dev, u32 tmpl_idx,
620 struct hinic_rss_type rss_type)
622 struct hinic_rss_context_tbl *ctx_tbl;
623 struct hinic_func_to_io *func_to_io;
624 struct hinic_cmdq_buf cmd_buf;
625 struct hinic_hwdev *hwdev;
626 struct hinic_hwif *hwif;
627 struct pci_dev *pdev;
632 hwdev = nic_dev->hwdev;
633 func_to_io = &hwdev->func_to_io;
637 err = hinic_alloc_cmdq_buf(&func_to_io->cmdqs, &cmd_buf);
639 dev_err(&pdev->dev, "Failed to allocate cmd buf\n");
643 ctx |= HINIC_RSS_TYPE_SET(1, VALID) |
644 HINIC_RSS_TYPE_SET(rss_type.ipv4, IPV4) |
645 HINIC_RSS_TYPE_SET(rss_type.ipv6, IPV6) |
646 HINIC_RSS_TYPE_SET(rss_type.ipv6_ext, IPV6_EXT) |
647 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv4, TCP_IPV4) |
648 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6, TCP_IPV6) |
649 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6_ext, TCP_IPV6_EXT) |
650 HINIC_RSS_TYPE_SET(rss_type.udp_ipv4, UDP_IPV4) |
651 HINIC_RSS_TYPE_SET(rss_type.udp_ipv6, UDP_IPV6);
653 cmd_buf.size = sizeof(struct hinic_rss_context_tbl);
655 ctx_tbl = (struct hinic_rss_context_tbl *)cmd_buf.buf;
656 ctx_tbl->group_index = cpu_to_be32(tmpl_idx);
658 ctx_tbl->size = sizeof(u32);
659 ctx_tbl->size = cpu_to_be32(ctx_tbl->size);
661 ctx_tbl->ctx = cpu_to_be32(ctx);
663 /* cfg the rss context table by command queue */
664 err = hinic_cmdq_direct_resp(&func_to_io->cmdqs, HINIC_MOD_L2NIC,
665 HINIC_UCODE_CMD_SET_RSS_CONTEXT_TABLE,
666 &cmd_buf, &out_param);
668 hinic_free_cmdq_buf(&func_to_io->cmdqs, &cmd_buf);
670 if (err || out_param != 0) {
671 dev_err(&pdev->dev, "Failed to set rss context table, err: %d\n",
679 int hinic_rss_set_template_tbl(struct hinic_dev *nic_dev, u32 template_id,
682 struct hinic_hwdev *hwdev = nic_dev->hwdev;
683 struct hinic_hwif *hwif = hwdev->hwif;
684 struct hinic_rss_key rss_key = { 0 };
685 struct pci_dev *pdev = hwif->pdev;
689 rss_key.func_id = HINIC_HWIF_FUNC_IDX(hwif);
690 rss_key.template_id = template_id;
691 memcpy(rss_key.key, temp, HINIC_RSS_KEY_SIZE);
693 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_RSS_TEMPLATE_TBL,
694 &rss_key, sizeof(rss_key),
695 &rss_key, &out_size);
696 if (err || !out_size || rss_key.status) {
698 "Failed to set rss hash key, err: %d, status: 0x%x, out size: 0x%x\n",
699 err, rss_key.status, out_size);
706 int hinic_rss_set_hash_engine(struct hinic_dev *nic_dev, u8 template_id,
709 struct hinic_rss_engine_type rss_engine = { 0 };
710 struct hinic_hwdev *hwdev = nic_dev->hwdev;
711 struct hinic_hwif *hwif = hwdev->hwif;
712 struct pci_dev *pdev = hwif->pdev;
716 rss_engine.func_id = HINIC_HWIF_FUNC_IDX(hwif);
717 rss_engine.hash_engine = type;
718 rss_engine.template_id = template_id;
720 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_RSS_HASH_ENGINE,
721 &rss_engine, sizeof(rss_engine),
722 &rss_engine, &out_size);
723 if (err || !out_size || rss_engine.status) {
725 "Failed to set hash engine, err: %d, status: 0x%x, out size: 0x%x\n",
726 err, rss_engine.status, out_size);
733 int hinic_rss_cfg(struct hinic_dev *nic_dev, u8 rss_en, u8 template_id)
735 struct hinic_hwdev *hwdev = nic_dev->hwdev;
736 struct hinic_rss_config rss_cfg = { 0 };
737 struct hinic_hwif *hwif = hwdev->hwif;
738 struct pci_dev *pdev = hwif->pdev;
742 rss_cfg.func_id = HINIC_HWIF_FUNC_IDX(hwif);
743 rss_cfg.rss_en = rss_en;
744 rss_cfg.template_id = template_id;
745 rss_cfg.rq_priority_number = 0;
747 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_RSS_CFG,
748 &rss_cfg, sizeof(rss_cfg),
749 &rss_cfg, &out_size);
750 if (err || !out_size || rss_cfg.status) {
752 "Failed to set rss cfg, err: %d, status: 0x%x, out size: 0x%x\n",
753 err, rss_cfg.status, out_size);
760 int hinic_rss_template_alloc(struct hinic_dev *nic_dev, u8 *tmpl_idx)
762 struct hinic_rss_template_mgmt template_mgmt = { 0 };
763 struct hinic_hwdev *hwdev = nic_dev->hwdev;
764 struct hinic_hwif *hwif = hwdev->hwif;
765 struct pci_dev *pdev = hwif->pdev;
769 template_mgmt.func_id = HINIC_HWIF_FUNC_IDX(hwif);
770 template_mgmt.cmd = NIC_RSS_CMD_TEMP_ALLOC;
772 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
773 &template_mgmt, sizeof(template_mgmt),
774 &template_mgmt, &out_size);
775 if (err || !out_size || template_mgmt.status) {
776 dev_err(&pdev->dev, "Failed to alloc rss template, err: %d, status: 0x%x, out size: 0x%x\n",
777 err, template_mgmt.status, out_size);
781 *tmpl_idx = template_mgmt.template_id;
786 int hinic_rss_template_free(struct hinic_dev *nic_dev, u8 tmpl_idx)
788 struct hinic_rss_template_mgmt template_mgmt = { 0 };
789 struct hinic_hwdev *hwdev = nic_dev->hwdev;
790 struct hinic_hwif *hwif = hwdev->hwif;
791 struct pci_dev *pdev = hwif->pdev;
795 template_mgmt.func_id = HINIC_HWIF_FUNC_IDX(hwif);
796 template_mgmt.template_id = tmpl_idx;
797 template_mgmt.cmd = NIC_RSS_CMD_TEMP_FREE;
799 err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
800 &template_mgmt, sizeof(template_mgmt),
801 &template_mgmt, &out_size);
802 if (err || !out_size || template_mgmt.status) {
803 dev_err(&pdev->dev, "Failed to free rss template, err: %d, status: 0x%x, out size: 0x%x\n",
804 err, template_mgmt.status, out_size);