Lines Matching full:chain
49 #define MASKED_IDX(chain, idx) ((idx) & ((chain)->num_cells - 1)) argument
89 static void set_prod_idx(struct hinic_api_cmd_chain *chain) in set_prod_idx() argument
91 enum hinic_api_cmd_chain_type chain_type = chain->chain_type; in set_prod_idx()
92 struct hinic_hwif *hwif = chain->hwif; in set_prod_idx()
100 prod_idx |= HINIC_API_CMD_PI_SET(chain->prod_idx, IDX); in set_prod_idx()
105 static u32 get_hw_cons_idx(struct hinic_api_cmd_chain *chain) in get_hw_cons_idx() argument
109 addr = HINIC_CSR_API_CMD_STATUS_ADDR(chain->chain_type); in get_hw_cons_idx()
110 val = hinic_hwif_read_reg(chain->hwif, addr); in get_hw_cons_idx()
115 static void dump_api_chain_reg(struct hinic_api_cmd_chain *chain) in dump_api_chain_reg() argument
119 addr = HINIC_CSR_API_CMD_STATUS_ADDR(chain->chain_type); in dump_api_chain_reg()
120 val = hinic_hwif_read_reg(chain->hwif, addr); in dump_api_chain_reg()
122 …dev_err(&chain->hwif->pdev->dev, "Chain type: 0x%x, cpld error: 0x%x, check error: 0x%x, current f… in dump_api_chain_reg()
123 chain->chain_type, HINIC_API_CMD_STATUS_GET(val, CPLD_ERR), in dump_api_chain_reg()
127 dev_err(&chain->hwif->pdev->dev, "Chain hw current ci: 0x%x\n", in dump_api_chain_reg()
130 addr = HINIC_CSR_API_CMD_CHAIN_PI_ADDR(chain->chain_type); in dump_api_chain_reg()
131 val = hinic_hwif_read_reg(chain->hwif, addr); in dump_api_chain_reg()
132 dev_err(&chain->hwif->pdev->dev, "Chain hw current pi: 0x%x\n", val); in dump_api_chain_reg()
136 * chain_busy - check if the chain is still processing last requests
137 * @chain: chain to check
141 static int chain_busy(struct hinic_api_cmd_chain *chain) in chain_busy() argument
143 struct hinic_hwif *hwif = chain->hwif; in chain_busy()
147 switch (chain->chain_type) { in chain_busy()
149 chain->cons_idx = get_hw_cons_idx(chain); in chain_busy()
150 prod_idx = chain->prod_idx; in chain_busy()
153 if (chain->cons_idx == MASKED_IDX(chain, prod_idx + 1)) { in chain_busy()
154 dev_err(&pdev->dev, "API CMD chain %d is busy, cons_idx: %d, prod_idx: %d\n", in chain_busy()
155 chain->chain_type, chain->cons_idx, in chain_busy()
156 chain->prod_idx); in chain_busy()
157 dump_api_chain_reg(chain); in chain_busy()
163 dev_err(&pdev->dev, "Unknown API CMD Chain type\n"); in chain_busy()
172 * @type: chain type
217 * @chain: chain for the command
222 static void prepare_api_cmd(struct hinic_api_cmd_chain *chain, in prepare_api_cmd() argument
226 struct hinic_api_cmd_cell *cell = chain->curr_node; in prepare_api_cmd()
228 struct hinic_hwif *hwif = chain->hwif; in prepare_api_cmd()
231 cell_ctxt = &chain->cell_ctxt[chain->prod_idx]; in prepare_api_cmd()
233 switch (chain->chain_type) { in prepare_api_cmd()
241 dev_err(&pdev->dev, "unknown Chain type\n"); in prepare_api_cmd()
259 * @chain: chain for the command
266 static void prepare_cell(struct hinic_api_cmd_chain *chain, in prepare_cell() argument
270 struct hinic_api_cmd_cell *curr_node = chain->curr_node; in prepare_cell()
271 u16 data_size = get_cell_data_size(chain->chain_type); in prepare_cell()
274 prepare_api_cmd(chain, dest, cmd, cmd_size); in prepare_cell()
277 static inline void cmd_chain_prod_idx_inc(struct hinic_api_cmd_chain *chain) in cmd_chain_prod_idx_inc() argument
279 chain->prod_idx = MASKED_IDX(chain, chain->prod_idx + 1); in cmd_chain_prod_idx_inc()
283 * api_cmd_status_update - update the status in the chain struct
284 * @chain: chain to update
286 static void api_cmd_status_update(struct hinic_api_cmd_chain *chain) in api_cmd_status_update() argument
290 struct hinic_hwif *hwif = chain->hwif; in api_cmd_status_update()
295 wb_status = chain->wb_status; in api_cmd_status_update()
306 dev_err(&pdev->dev, "unknown API CMD Chain %d\n", chain_type); in api_cmd_status_update()
310 chain->cons_idx = HINIC_API_CMD_STATUS_GET(status, CONS_IDX); in api_cmd_status_update()
315 * @chain: the chain of the command
319 static int wait_for_status_poll(struct hinic_api_cmd_chain *chain) in wait_for_status_poll() argument
326 api_cmd_status_update(chain); in wait_for_status_poll()
329 if (chain->cons_idx == chain->prod_idx) { in wait_for_status_poll()
342 * @chain: chain for the command
346 static int wait_for_api_cmd_completion(struct hinic_api_cmd_chain *chain) in wait_for_api_cmd_completion() argument
348 struct hinic_hwif *hwif = chain->hwif; in wait_for_api_cmd_completion()
352 switch (chain->chain_type) { in wait_for_api_cmd_completion()
354 err = wait_for_status_poll(chain); in wait_for_api_cmd_completion()
357 dump_api_chain_reg(chain); in wait_for_api_cmd_completion()
363 dev_err(&pdev->dev, "unknown API CMD Chain type\n"); in wait_for_api_cmd_completion()
373 * @chain: chain for the command
380 static int api_cmd(struct hinic_api_cmd_chain *chain, in api_cmd() argument
386 down(&chain->sem); in api_cmd()
387 if (chain_busy(chain)) { in api_cmd()
388 up(&chain->sem); in api_cmd()
392 prepare_cell(chain, dest, cmd, cmd_size); in api_cmd()
393 cmd_chain_prod_idx_inc(chain); in api_cmd()
397 set_prod_idx(chain); /* issue the command */ in api_cmd()
399 ctxt = &chain->cell_ctxt[chain->prod_idx]; in api_cmd()
401 chain->curr_node = ctxt->cell_vaddr; in api_cmd()
403 err = wait_for_api_cmd_completion(chain); in api_cmd()
405 up(&chain->sem); in api_cmd()
411 * @chain: chain for write command
418 int hinic_api_cmd_write(struct hinic_api_cmd_chain *chain, in hinic_api_cmd_write() argument
421 /* Verify the chain type */ in hinic_api_cmd_write()
422 if (chain->chain_type == HINIC_API_CMD_WRITE_TO_MGMT_CPU) in hinic_api_cmd_write()
423 return api_cmd(chain, dest, cmd, size); in hinic_api_cmd_write()
429 * api_cmd_hw_restart - restart the chain in the HW
430 * @chain: the API CMD specific chain to restart
434 static int api_cmd_hw_restart(struct hinic_api_cmd_chain *chain) in api_cmd_hw_restart() argument
436 struct hinic_hwif *hwif = chain->hwif; in api_cmd_hw_restart()
442 reg_addr = HINIC_CSR_API_CMD_CHAIN_REQ_ADDR(chain->chain_type); in api_cmd_hw_restart()
466 * api_cmd_ctrl_init - set the control register of a chain
467 * @chain: the API CMD specific chain to set control register for
469 static void api_cmd_ctrl_init(struct hinic_api_cmd_chain *chain) in api_cmd_ctrl_init() argument
471 struct hinic_hwif *hwif = chain->hwif; in api_cmd_ctrl_init()
476 addr = HINIC_CSR_API_CMD_CHAIN_CTRL_ADDR(chain->chain_type); in api_cmd_ctrl_init()
478 cell_size = API_CMD_CELL_SIZE_VAL(chain->cell_size); in api_cmd_ctrl_init()
496 * api_cmd_set_status_addr - set the status address of a chain in the HW
497 * @chain: the API CMD specific chain to set in HW status address for
499 static void api_cmd_set_status_addr(struct hinic_api_cmd_chain *chain) in api_cmd_set_status_addr() argument
501 struct hinic_hwif *hwif = chain->hwif; in api_cmd_set_status_addr()
504 addr = HINIC_CSR_API_CMD_STATUS_HI_ADDR(chain->chain_type); in api_cmd_set_status_addr()
505 val = upper_32_bits(chain->wb_status_paddr); in api_cmd_set_status_addr()
508 addr = HINIC_CSR_API_CMD_STATUS_LO_ADDR(chain->chain_type); in api_cmd_set_status_addr()
509 val = lower_32_bits(chain->wb_status_paddr); in api_cmd_set_status_addr()
514 * api_cmd_set_num_cells - set the number cells of a chain in the HW
515 * @chain: the API CMD specific chain to set in HW the number of cells for
517 static void api_cmd_set_num_cells(struct hinic_api_cmd_chain *chain) in api_cmd_set_num_cells() argument
519 struct hinic_hwif *hwif = chain->hwif; in api_cmd_set_num_cells()
522 addr = HINIC_CSR_API_CMD_CHAIN_NUM_CELLS_ADDR(chain->chain_type); in api_cmd_set_num_cells()
523 val = chain->num_cells; in api_cmd_set_num_cells()
528 * api_cmd_head_init - set the head of a chain in the HW
529 * @chain: the API CMD specific chain to set in HW the head for
531 static void api_cmd_head_init(struct hinic_api_cmd_chain *chain) in api_cmd_head_init() argument
533 struct hinic_hwif *hwif = chain->hwif; in api_cmd_head_init()
536 addr = HINIC_CSR_API_CMD_CHAIN_HEAD_HI_ADDR(chain->chain_type); in api_cmd_head_init()
537 val = upper_32_bits(chain->head_cell_paddr); in api_cmd_head_init()
540 addr = HINIC_CSR_API_CMD_CHAIN_HEAD_LO_ADDR(chain->chain_type); in api_cmd_head_init()
541 val = lower_32_bits(chain->head_cell_paddr); in api_cmd_head_init()
547 * @chain: the API CMD specific chain
549 static void api_cmd_chain_hw_clean(struct hinic_api_cmd_chain *chain) in api_cmd_chain_hw_clean() argument
551 struct hinic_hwif *hwif = chain->hwif; in api_cmd_chain_hw_clean()
554 addr = HINIC_CSR_API_CMD_CHAIN_CTRL_ADDR(chain->chain_type); in api_cmd_chain_hw_clean()
567 * api_cmd_chain_hw_init - initialize the chain in the HW
568 * @chain: the API CMD specific chain to initialize in HW
572 static int api_cmd_chain_hw_init(struct hinic_api_cmd_chain *chain) in api_cmd_chain_hw_init() argument
574 struct hinic_hwif *hwif = chain->hwif; in api_cmd_chain_hw_init()
578 api_cmd_chain_hw_clean(chain); in api_cmd_chain_hw_init()
580 api_cmd_set_status_addr(chain); in api_cmd_chain_hw_init()
582 err = api_cmd_hw_restart(chain); in api_cmd_chain_hw_init()
588 api_cmd_ctrl_init(chain); in api_cmd_chain_hw_init()
589 api_cmd_set_num_cells(chain); in api_cmd_chain_hw_init()
590 api_cmd_head_init(chain); in api_cmd_chain_hw_init()
596 * @chain: the API CMD specific chain of the cmd
599 static void free_cmd_buf(struct hinic_api_cmd_chain *chain, int cell_idx) in free_cmd_buf() argument
602 struct hinic_hwif *hwif = chain->hwif; in free_cmd_buf()
605 cell_ctxt = &chain->cell_ctxt[cell_idx]; in free_cmd_buf()
614 * @chain: the API CMD specific chain for the cmd
620 static int alloc_cmd_buf(struct hinic_api_cmd_chain *chain, in alloc_cmd_buf() argument
624 struct hinic_hwif *hwif = chain->hwif; in alloc_cmd_buf()
635 cell_ctxt = &chain->cell_ctxt[cell_idx]; in alloc_cmd_buf()
641 switch (chain->chain_type) { in alloc_cmd_buf()
648 dev_err(&pdev->dev, "Unsupported API CMD chain type\n"); in alloc_cmd_buf()
649 free_cmd_buf(chain, cell_idx); in alloc_cmd_buf()
658 * api_cmd_create_cell - create API CMD cell for specific chain
659 * @chain: the API CMD specific chain to create its cell
666 static int api_cmd_create_cell(struct hinic_api_cmd_chain *chain, in api_cmd_create_cell() argument
672 struct hinic_hwif *hwif = chain->hwif; in api_cmd_create_cell()
678 node = dma_alloc_coherent(&pdev->dev, chain->cell_size, &node_paddr, in api_cmd_create_cell()
685 cell_ctxt = &chain->cell_ctxt[cell_idx]; in api_cmd_create_cell()
690 chain->head_cell_paddr = node_paddr; in api_cmd_create_cell()
691 chain->head_node = node; in api_cmd_create_cell()
697 switch (chain->chain_type) { in api_cmd_create_cell()
699 err = alloc_cmd_buf(chain, node, cell_idx); in api_cmd_create_cell()
707 dev_err(&pdev->dev, "Unsupported API CMD chain type\n"); in api_cmd_create_cell()
716 dma_free_coherent(&pdev->dev, chain->cell_size, node, node_paddr); in api_cmd_create_cell()
721 * api_cmd_destroy_cell - destroy API CMD cell of specific chain
722 * @chain: the API CMD specific chain to destroy its cell
725 static void api_cmd_destroy_cell(struct hinic_api_cmd_chain *chain, in api_cmd_destroy_cell() argument
729 struct hinic_hwif *hwif = chain->hwif; in api_cmd_destroy_cell()
735 cell_ctxt = &chain->cell_ctxt[cell_idx]; in api_cmd_destroy_cell()
739 node_size = chain->cell_size; in api_cmd_destroy_cell()
742 switch (chain->chain_type) { in api_cmd_destroy_cell()
744 free_cmd_buf(chain, cell_idx); in api_cmd_destroy_cell()
747 dev_err(&pdev->dev, "Unsupported API CMD chain type\n"); in api_cmd_destroy_cell()
757 * api_cmd_destroy_cells - destroy API CMD cells of specific chain
758 * @chain: the API CMD specific chain to destroy its cells
761 static void api_cmd_destroy_cells(struct hinic_api_cmd_chain *chain, in api_cmd_destroy_cells() argument
767 api_cmd_destroy_cell(chain, cell_idx); in api_cmd_destroy_cells()
771 * api_cmd_create_cells - create API CMD cells for specific chain
772 * @chain: the API CMD specific chain
776 static int api_cmd_create_cells(struct hinic_api_cmd_chain *chain) in api_cmd_create_cells() argument
779 struct hinic_hwif *hwif = chain->hwif; in api_cmd_create_cells()
783 for (cell_idx = 0; cell_idx < chain->num_cells; cell_idx++) { in api_cmd_create_cells()
784 err = api_cmd_create_cell(chain, cell_idx, pre_node, &node); in api_cmd_create_cells()
794 node->next_cell_paddr = cpu_to_be64(chain->head_cell_paddr); in api_cmd_create_cells()
797 chain->curr_node = chain->head_node; in api_cmd_create_cells()
801 api_cmd_destroy_cells(chain, cell_idx); in api_cmd_create_cells()
806 * api_chain_init - initialize API CMD specific chain
807 * @chain: the API CMD specific chain to initialize
808 * @attr: attributes to set in the chain
812 static int api_chain_init(struct hinic_api_cmd_chain *chain, in api_chain_init() argument
818 chain->hwif = hwif; in api_chain_init()
819 chain->chain_type = attr->chain_type; in api_chain_init()
820 chain->num_cells = attr->num_cells; in api_chain_init()
821 chain->cell_size = attr->cell_size; in api_chain_init()
823 chain->prod_idx = 0; in api_chain_init()
824 chain->cons_idx = 0; in api_chain_init()
826 sema_init(&chain->sem, 1); in api_chain_init()
828 chain->cell_ctxt = devm_kcalloc(&pdev->dev, chain->num_cells, in api_chain_init()
829 sizeof(*chain->cell_ctxt), GFP_KERNEL); in api_chain_init()
830 if (!chain->cell_ctxt) in api_chain_init()
833 chain->wb_status = dma_alloc_coherent(&pdev->dev, in api_chain_init()
834 sizeof(*chain->wb_status), in api_chain_init()
835 &chain->wb_status_paddr, in api_chain_init()
837 if (!chain->wb_status) { in api_chain_init()
846 * api_chain_free - free API CMD specific chain
847 * @chain: the API CMD specific chain to free
849 static void api_chain_free(struct hinic_api_cmd_chain *chain) in api_chain_free() argument
851 struct hinic_hwif *hwif = chain->hwif; in api_chain_free()
854 dma_free_coherent(&pdev->dev, sizeof(*chain->wb_status), in api_chain_free()
855 chain->wb_status, chain->wb_status_paddr); in api_chain_free()
859 * api_cmd_create_chain - create API CMD specific chain
860 * @attr: attributes to set the chain
862 * Return the created chain
869 struct hinic_api_cmd_chain *chain; in api_cmd_create_chain() local
877 chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); in api_cmd_create_chain()
878 if (!chain) in api_cmd_create_chain()
881 err = api_chain_init(chain, attr); in api_cmd_create_chain()
883 dev_err(&pdev->dev, "Failed to initialize chain\n"); in api_cmd_create_chain()
887 err = api_cmd_create_cells(chain); in api_cmd_create_chain()
889 dev_err(&pdev->dev, "Failed to create cells for API CMD chain\n"); in api_cmd_create_chain()
893 err = api_cmd_chain_hw_init(chain); in api_cmd_create_chain()
895 dev_err(&pdev->dev, "Failed to initialize chain HW\n"); in api_cmd_create_chain()
899 return chain; in api_cmd_create_chain()
902 api_cmd_destroy_cells(chain, chain->num_cells); in api_cmd_create_chain()
905 api_chain_free(chain); in api_cmd_create_chain()
910 * api_cmd_destroy_chain - destroy API CMD specific chain
911 * @chain: the API CMD specific chain to destroy
913 static void api_cmd_destroy_chain(struct hinic_api_cmd_chain *chain) in api_cmd_destroy_chain() argument
915 api_cmd_chain_hw_clean(chain); in api_cmd_destroy_chain()
916 api_cmd_destroy_cells(chain, chain->num_cells); in api_cmd_destroy_chain()
917 api_chain_free(chain); in api_cmd_destroy_chain()
922 * @chain: the API CMD chains that are initialized
927 int hinic_api_cmd_init(struct hinic_api_cmd_chain **chain, in hinic_api_cmd_init() argument
949 chain[chain_type] = api_cmd_create_chain(&attr); in hinic_api_cmd_init()
950 if (IS_ERR(chain[chain_type])) { in hinic_api_cmd_init()
951 dev_err(&pdev->dev, "Failed to create chain %d\n", in hinic_api_cmd_init()
953 err = PTR_ERR(chain[chain_type]); in hinic_api_cmd_init()
966 api_cmd_destroy_chain(chain[type]); in hinic_api_cmd_init()
974 * @chain: the API CMD chains that are freed
976 void hinic_api_cmd_free(struct hinic_api_cmd_chain **chain) in hinic_api_cmd_free() argument
985 api_cmd_destroy_chain(chain[chain_type]); in hinic_api_cmd_free()