forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Huawei HiNIC PCI Express Linux driver
34 * Copyright(c) 2017 Huawei Technologies Co., Ltd
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
- * for more details.
13
- *
145 */
156
167 #include <linux/kernel.h>
....@@ -121,6 +112,26 @@
121112 return HINIC_API_CMD_STATUS_GET(val, CONS_IDX);
122113 }
123114
115
+static void dump_api_chain_reg(struct hinic_api_cmd_chain *chain)
116
+{
117
+ u32 addr, val;
118
+
119
+ addr = HINIC_CSR_API_CMD_STATUS_ADDR(chain->chain_type);
120
+ val = hinic_hwif_read_reg(chain->hwif, addr);
121
+
122
+ dev_err(&chain->hwif->pdev->dev, "Chain type: 0x%x, cpld error: 0x%x, check error: 0x%x, current fsm: 0x%x\n",
123
+ chain->chain_type, HINIC_API_CMD_STATUS_GET(val, CPLD_ERR),
124
+ HINIC_API_CMD_STATUS_GET(val, CHKSUM_ERR),
125
+ HINIC_API_CMD_STATUS_GET(val, FSM));
126
+
127
+ dev_err(&chain->hwif->pdev->dev, "Chain hw current ci: 0x%x\n",
128
+ HINIC_API_CMD_STATUS_GET(val, CONS_IDX));
129
+
130
+ addr = HINIC_CSR_API_CMD_CHAIN_PI_ADDR(chain->chain_type);
131
+ val = hinic_hwif_read_reg(chain->hwif, addr);
132
+ dev_err(&chain->hwif->pdev->dev, "Chain hw current pi: 0x%x\n", val);
133
+}
134
+
124135 /**
125136 * chain_busy - check if the chain is still processing last requests
126137 * @chain: chain to check
....@@ -140,8 +151,10 @@
140151
141152 /* check for a space for a new command */
142153 if (chain->cons_idx == MASKED_IDX(chain, prod_idx + 1)) {
143
- dev_err(&pdev->dev, "API CMD chain %d is busy\n",
144
- chain->chain_type);
154
+ dev_err(&pdev->dev, "API CMD chain %d is busy, cons_idx: %d, prod_idx: %d\n",
155
+ chain->chain_type, chain->cons_idx,
156
+ chain->prod_idx);
157
+ dump_api_chain_reg(chain);
145158 return -EBUSY;
146159 }
147160 break;
....@@ -341,6 +354,7 @@
341354 err = wait_for_status_poll(chain);
342355 if (err) {
343356 dev_err(&pdev->dev, "API CMD Poll status timeout\n");
357
+ dump_api_chain_reg(chain);
344358 break;
345359 }
346360 break;
....@@ -359,7 +373,7 @@
359373 * @chain: chain for the command
360374 * @dest: destination node on the card that will receive the command
361375 * @cmd: command data
362
- * @size: the command size
376
+ * @cmd_size: the command size
363377 *
364378 * Return 0 - Success, negative - Failure
365379 **/
....@@ -613,8 +627,8 @@
613627 u8 *cmd_vaddr;
614628 int err = 0;
615629
616
- cmd_vaddr = dma_zalloc_coherent(&pdev->dev, API_CMD_BUF_SIZE,
617
- &cmd_paddr, GFP_KERNEL);
630
+ cmd_vaddr = dma_alloc_coherent(&pdev->dev, API_CMD_BUF_SIZE,
631
+ &cmd_paddr, GFP_KERNEL);
618632 if (!cmd_vaddr) {
619633 dev_err(&pdev->dev, "Failed to allocate API CMD DMA memory\n");
620634 return -ENOMEM;
....@@ -663,8 +677,8 @@
663677 dma_addr_t node_paddr;
664678 int err;
665679
666
- node = dma_zalloc_coherent(&pdev->dev, chain->cell_size,
667
- &node_paddr, GFP_KERNEL);
680
+ node = dma_alloc_coherent(&pdev->dev, chain->cell_size, &node_paddr,
681
+ GFP_KERNEL);
668682 if (!node) {
669683 dev_err(&pdev->dev, "Failed to allocate dma API CMD cell\n");
670684 return -ENOMEM;
....@@ -804,7 +818,6 @@
804818 {
805819 struct hinic_hwif *hwif = attr->hwif;
806820 struct pci_dev *pdev = hwif->pdev;
807
- size_t cell_ctxt_size;
808821
809822 chain->hwif = hwif;
810823 chain->chain_type = attr->chain_type;
....@@ -816,15 +829,15 @@
816829
817830 sema_init(&chain->sem, 1);
818831
819
- cell_ctxt_size = chain->num_cells * sizeof(*chain->cell_ctxt);
820
- chain->cell_ctxt = devm_kzalloc(&pdev->dev, cell_ctxt_size, GFP_KERNEL);
832
+ chain->cell_ctxt = devm_kcalloc(&pdev->dev, chain->num_cells,
833
+ sizeof(*chain->cell_ctxt), GFP_KERNEL);
821834 if (!chain->cell_ctxt)
822835 return -ENOMEM;
823836
824
- chain->wb_status = dma_zalloc_coherent(&pdev->dev,
825
- sizeof(*chain->wb_status),
826
- &chain->wb_status_paddr,
827
- GFP_KERNEL);
837
+ chain->wb_status = dma_alloc_coherent(&pdev->dev,
838
+ sizeof(*chain->wb_status),
839
+ &chain->wb_status_paddr,
840
+ GFP_KERNEL);
828841 if (!chain->wb_status) {
829842 dev_err(&pdev->dev, "Failed to allocate DMA wb status\n");
830843 return -ENOMEM;