/** * hinic_port_set_state - set port state * @nic_dev: nic device * @state: the state to set * * Return 0 - Success, negative - Failure **/ int hinic_port_set_state(struct hinic_dev *nic_dev, enum hinic_port_state state) { struct hinic_hwdev *hwdev = nic_dev->hwdev; struct hinic_port_state_cmd port_state; struct hinic_hwif *hwif = hwdev->hwif; struct pci_dev *pdev = hwif->pdev; u16 out_size; int err; if (!HINIC_IS_PF(hwif) && !HINIC_IS_PPF(hwif)) { dev_err(&pdev->dev, "unsupported PCI Function type\n"); return -EINVAL; } port_state.state = state; err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_SET_PORT_STATE, &port_state, sizeof(port_state), &port_state, &out_size); if (err || (out_size != sizeof(port_state)) || port_state.status) { dev_err(&pdev->dev, "Failed to set port state, ret = %d\n", port_state.status); return -EFAULT; } return 0; }
/** * hinic_port_link_state - get the link state * @nic_dev: nic device * @link_state: the returned link state * * Return 0 - Success, negative - Failure **/ int hinic_port_link_state(struct hinic_dev *nic_dev, enum hinic_port_link_state *link_state) { struct hinic_hwdev *hwdev = nic_dev->hwdev; struct hinic_hwif *hwif = hwdev->hwif; struct hinic_port_link_cmd link_cmd; struct pci_dev *pdev = hwif->pdev; u16 out_size; int err; if (!HINIC_IS_PF(hwif) && !HINIC_IS_PPF(hwif)) { dev_err(&pdev->dev, "unsupported PCI Function type\n"); return -EINVAL; } link_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif); err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_LINK_STATE, &link_cmd, sizeof(link_cmd), &link_cmd, &out_size); if (err || (out_size != sizeof(link_cmd)) || link_cmd.status) { dev_err(&pdev->dev, "Failed to get link state, ret = %d\n", link_cmd.status); return -EINVAL; } *link_state = link_cmd.state; return 0; }
/** * hinic_init_hwif - initialize the hw interface * @hwif: the HW interface of a pci function device * @pdev: the pci device for acessing PCI resources * * Return 0 - Success, negative - Failure **/ int hinic_init_hwif(struct hinic_hwif *hwif, struct pci_dev *pdev) { int err; hwif->pdev = pdev; hwif->cfg_regs_bar = pci_ioremap_bar(pdev, HINIC_PCI_CFG_REGS_BAR); if (!hwif->cfg_regs_bar) { dev_err(&pdev->dev, "Failed to map configuration regs\n"); return -ENOMEM; } hwif->intr_regs_base = pci_ioremap_bar(pdev, HINIC_PCI_INTR_REGS_BAR); if (!hwif->intr_regs_base) { dev_err(&pdev->dev, "Failed to map configuration regs\n"); err = -ENOMEM; goto err_map_intr_bar; } err = hwif_ready(hwif); if (err) { dev_err(&pdev->dev, "HW interface is not ready\n"); goto err_hwif_ready; } read_hwif_attr(hwif); if (HINIC_IS_PF(hwif)) set_ppf(hwif); /* No transactionss before DMA is initialized */ dma_attr_init(hwif); return 0; err_hwif_ready: iounmap(hwif->intr_regs_base); err_map_intr_bar: iounmap(hwif->cfg_regs_bar); return err; }
/** * init_cmdqs_ctxt - write the cmdq ctxt to HW after init all cmdq * @hwdev: the NIC HW device * @cmdqs: cmdqs to write the ctxts for * &db_area: db_area for all the cmdqs * * Return 0 - Success, negative - Failure **/ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev, struct hinic_cmdqs *cmdqs, void __iomem **db_area) { struct hinic_hwif *hwif = hwdev->hwif; enum hinic_cmdq_type type, cmdq_type; struct hinic_cmdq_ctxt *cmdq_ctxts; struct pci_dev *pdev = hwif->pdev; struct hinic_pfhwdev *pfhwdev; size_t cmdq_ctxts_size; int err; if (!HINIC_IS_PF(hwif) && !HINIC_IS_PPF(hwif)) { dev_err(&pdev->dev, "Unsupported PCI function type\n"); return -EINVAL; } cmdq_ctxts_size = HINIC_MAX_CMDQ_TYPES * sizeof(*cmdq_ctxts); cmdq_ctxts = devm_kzalloc(&pdev->dev, cmdq_ctxts_size, GFP_KERNEL); if (!cmdq_ctxts) return -ENOMEM; pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev); cmdq_type = HINIC_CMDQ_SYNC; for (; cmdq_type < HINIC_MAX_CMDQ_TYPES; cmdq_type++) { err = init_cmdq(&cmdqs->cmdq[cmdq_type], &cmdqs->saved_wqs[cmdq_type], cmdq_type, db_area[cmdq_type]); if (err) { dev_err(&pdev->dev, "Failed to initialize cmdq\n"); goto err_init_cmdq; } cmdq_init_queue_ctxt(&cmdq_ctxts[cmdq_type], &cmdqs->cmdq[cmdq_type], &cmdqs->cmdq_pages); } /* Write the CMDQ ctxts */ cmdq_type = HINIC_CMDQ_SYNC; for (; cmdq_type < HINIC_MAX_CMDQ_TYPES; cmdq_type++) { err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM, HINIC_COMM_CMD_CMDQ_CTXT_SET, &cmdq_ctxts[cmdq_type], sizeof(cmdq_ctxts[cmdq_type]), NULL, NULL, HINIC_MGMT_MSG_SYNC); if (err) { dev_err(&pdev->dev, "Failed to set CMDQ CTXT type = %d\n", cmdq_type); goto err_write_cmdq_ctxt; } } devm_kfree(&pdev->dev, cmdq_ctxts); return 0; err_write_cmdq_ctxt: cmdq_type = HINIC_MAX_CMDQ_TYPES; err_init_cmdq: for (type = HINIC_CMDQ_SYNC; type < cmdq_type; type++) free_cmdq(&cmdqs->cmdq[type]); devm_kfree(&pdev->dev, cmdq_ctxts); return err; }