Lines Matching +full:msi +full:- +full:base +full:- +full:vec

65 #include <linux/dma-mapping.h>
70 #include <linux/io-64-nonatomic-lo-hi.h>
87 /* Hardware Descriptor Constants - Control Field */
96 /* Hardware Descriptor Constants - Status Field */
117 #define ISMT_MSTR_MDBA 0x100 /* Master Descriptor Base Address */
153 /* MSI Control Register (MSICTL) bit definitions */
154 #define ISMT_MSICTL_MSIE 0x01 /* MSI Enable */
174 struct ismt_desc *hw; /* descriptor virt base addr */
175 dma_addr_t io_rng_dma; /* descriptor HW base addr */
195 /* Bus speed control bits for slow debuggers - refer to the docs for usage */
201 * __ismt_desc_dump() - dump the contents of a specific descriptor
209 dev_dbg(dev, "\ttgtaddr_rw=0x%02X\n", desc->tgtaddr_rw); in __ismt_desc_dump()
210 dev_dbg(dev, "\twr_len_cmd=0x%02X\n", desc->wr_len_cmd); in __ismt_desc_dump()
211 dev_dbg(dev, "\trd_len= 0x%02X\n", desc->rd_len); in __ismt_desc_dump()
212 dev_dbg(dev, "\tcontrol= 0x%02X\n", desc->control); in __ismt_desc_dump()
213 dev_dbg(dev, "\tstatus= 0x%02X\n", desc->status); in __ismt_desc_dump()
214 dev_dbg(dev, "\tretry= 0x%02X\n", desc->retry); in __ismt_desc_dump()
215 dev_dbg(dev, "\trxbytes= 0x%02X\n", desc->rxbytes); in __ismt_desc_dump()
216 dev_dbg(dev, "\ttxbytes= 0x%02X\n", desc->txbytes); in __ismt_desc_dump()
217 dev_dbg(dev, "\tdptr_low= 0x%08X\n", desc->dptr_low); in __ismt_desc_dump()
218 dev_dbg(dev, "\tdptr_high= 0x%08X\n", desc->dptr_high); in __ismt_desc_dump()
221 * ismt_desc_dump() - dump the contents of a descriptor for debug purposes
226 struct device *dev = &priv->pci_dev->dev; in ismt_desc_dump()
227 struct ismt_desc *desc = &priv->hw[priv->head]; in ismt_desc_dump()
229 dev_dbg(dev, "Dump of the descriptor struct: 0x%X\n", priv->head); in ismt_desc_dump()
234 * ismt_gen_reg_dump() - dump the iSMT General Registers
239 struct device *dev = &priv->pci_dev->dev; in ismt_gen_reg_dump()
243 priv->smba + ISMT_GR_GCTRL, in ismt_gen_reg_dump()
244 readl(priv->smba + ISMT_GR_GCTRL)); in ismt_gen_reg_dump()
246 priv->smba + ISMT_GR_SMTICL, in ismt_gen_reg_dump()
247 (long long unsigned int)readq(priv->smba + ISMT_GR_SMTICL)); in ismt_gen_reg_dump()
249 priv->smba + ISMT_GR_ERRINTMSK, in ismt_gen_reg_dump()
250 readl(priv->smba + ISMT_GR_ERRINTMSK)); in ismt_gen_reg_dump()
252 priv->smba + ISMT_GR_ERRAERMSK, in ismt_gen_reg_dump()
253 readl(priv->smba + ISMT_GR_ERRAERMSK)); in ismt_gen_reg_dump()
255 priv->smba + ISMT_GR_ERRSTS, in ismt_gen_reg_dump()
256 readl(priv->smba + ISMT_GR_ERRSTS)); in ismt_gen_reg_dump()
258 priv->smba + ISMT_GR_ERRINFO, in ismt_gen_reg_dump()
259 readl(priv->smba + ISMT_GR_ERRINFO)); in ismt_gen_reg_dump()
263 * ismt_mstr_reg_dump() - dump the iSMT Master Registers
268 struct device *dev = &priv->pci_dev->dev; in ismt_mstr_reg_dump()
272 priv->smba + ISMT_MSTR_MDBA, in ismt_mstr_reg_dump()
273 (long long unsigned int)readq(priv->smba + ISMT_MSTR_MDBA)); in ismt_mstr_reg_dump()
275 priv->smba + ISMT_MSTR_MCTRL, in ismt_mstr_reg_dump()
276 readl(priv->smba + ISMT_MSTR_MCTRL)); in ismt_mstr_reg_dump()
278 priv->smba + ISMT_MSTR_MSTS, in ismt_mstr_reg_dump()
279 readl(priv->smba + ISMT_MSTR_MSTS)); in ismt_mstr_reg_dump()
281 priv->smba + ISMT_MSTR_MDS, in ismt_mstr_reg_dump()
282 readl(priv->smba + ISMT_MSTR_MDS)); in ismt_mstr_reg_dump()
284 priv->smba + ISMT_MSTR_RPOLICY, in ismt_mstr_reg_dump()
285 readl(priv->smba + ISMT_MSTR_RPOLICY)); in ismt_mstr_reg_dump()
287 priv->smba + ISMT_SPGT, in ismt_mstr_reg_dump()
288 readl(priv->smba + ISMT_SPGT)); in ismt_mstr_reg_dump()
292 * ismt_submit_desc() - add a descriptor to the ring
305 fmhp = ((priv->head + 1) % ISMT_DESC_ENTRIES) << 16; in ismt_submit_desc()
306 val = readl(priv->smba + ISMT_MSTR_MCTRL); in ismt_submit_desc()
308 priv->smba + ISMT_MSTR_MCTRL); in ismt_submit_desc()
311 val = readl(priv->smba + ISMT_MSTR_MCTRL); in ismt_submit_desc()
313 priv->smba + ISMT_MSTR_MCTRL); in ismt_submit_desc()
317 * ismt_process_desc() - handle the completion of the descriptor
329 u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); in ismt_process_desc()
331 dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n"); in ismt_process_desc()
332 __ismt_desc_dump(&priv->pci_dev->dev, desc); in ismt_process_desc()
336 if (desc->status & ISMT_DESC_SCS) { in ismt_process_desc()
345 data->byte = dma_buffer[0]; in ismt_process_desc()
349 data->word = dma_buffer[0] | (dma_buffer[1] << 8); in ismt_process_desc()
353 if (desc->rxbytes != dma_buffer[0] + 1) in ismt_process_desc()
354 return -EMSGSIZE; in ismt_process_desc()
356 memcpy(data->block, dma_buffer, desc->rxbytes); in ismt_process_desc()
359 memcpy(&data->block[1], dma_buffer, desc->rxbytes); in ismt_process_desc()
360 data->block[0] = desc->rxbytes; in ismt_process_desc()
366 if (likely(desc->status & ISMT_DESC_NAK)) in ismt_process_desc()
367 return -ENXIO; in ismt_process_desc()
369 if (desc->status & ISMT_DESC_CRC) in ismt_process_desc()
370 return -EBADMSG; in ismt_process_desc()
372 if (desc->status & ISMT_DESC_COL) in ismt_process_desc()
373 return -EAGAIN; in ismt_process_desc()
375 if (desc->status & ISMT_DESC_LPR) in ismt_process_desc()
376 return -EPROTO; in ismt_process_desc()
378 if (desc->status & (ISMT_DESC_DLTO | ISMT_DESC_CLTO)) in ismt_process_desc()
379 return -ETIMEDOUT; in ismt_process_desc()
381 return -EIO; in ismt_process_desc()
385 * ismt_kill_transaction() - kill current transaction
390 writel(ISMT_GCTRL_KILL, priv->smba + ISMT_GR_GCTRL); in ismt_kill_transaction()
394 * ismt_access() - process an SMBus command
414 struct device *dev = &priv->pci_dev->dev; in ismt_access()
415 u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); in ismt_access()
417 desc = &priv->hw[priv->head]; in ismt_access()
420 memset(priv->buffer, 0, sizeof(priv->buffer)); in ismt_access()
424 desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write); in ismt_access()
427 memset(priv->log, 0, ISMT_LOG_ENTRIES * sizeof(u32)); in ismt_access()
430 if (likely(pci_dev_msi_enabled(priv->pci_dev))) in ismt_access()
431 desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR; in ismt_access()
433 desc->control = ISMT_DESC_FAIR; in ismt_access()
437 desc->control |= ISMT_DESC_PEC; in ismt_access()
451 desc->control |= ISMT_DESC_CWRL; in ismt_access()
452 desc->wr_len_cmd = command; in ismt_access()
458 desc->rd_len = 1; in ismt_access()
469 desc->wr_len_cmd = 2; in ismt_access()
473 dma_buffer[1] = data->byte; in ismt_access()
477 desc->control |= ISMT_DESC_CWRL; in ismt_access()
478 desc->wr_len_cmd = command; in ismt_access()
479 desc->rd_len = 1; in ismt_access()
489 desc->wr_len_cmd = 3; in ismt_access()
493 dma_buffer[1] = data->word & 0xff; in ismt_access()
494 dma_buffer[2] = data->word >> 8; in ismt_access()
498 desc->wr_len_cmd = command; in ismt_access()
499 desc->control |= ISMT_DESC_CWRL; in ismt_access()
500 desc->rd_len = 2; in ismt_access()
508 desc->wr_len_cmd = 3; in ismt_access()
509 desc->rd_len = 2; in ismt_access()
513 dma_buffer[1] = data->word & 0xff; in ismt_access()
514 dma_buffer[2] = data->word >> 8; in ismt_access()
521 if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX) in ismt_access()
522 return -EINVAL; in ismt_access()
524 dma_size = data->block[0] + 1; in ismt_access()
526 desc->wr_len_cmd = dma_size; in ismt_access()
527 desc->control |= ISMT_DESC_BLK; in ismt_access()
529 memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); in ismt_access()
535 desc->rd_len = dma_size; in ismt_access()
536 desc->wr_len_cmd = command; in ismt_access()
537 desc->control |= (ISMT_DESC_BLK | ISMT_DESC_CWRL); in ismt_access()
543 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) in ismt_access()
544 return -EINVAL; in ismt_access()
547 desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, 1); in ismt_access()
548 desc->wr_len_cmd = data->block[0] + 1; in ismt_access()
549 desc->rd_len = dma_size; in ismt_access()
550 desc->control |= ISMT_DESC_BLK; in ismt_access()
553 memcpy(&dma_buffer[1], &data->block[1], data->block[0]); in ismt_access()
558 if (data->block[0] < 1) in ismt_access()
559 data->block[0] = 1; in ismt_access()
561 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) in ismt_access()
562 data->block[0] = I2C_SMBUS_BLOCK_MAX; in ismt_access()
567 dma_size = data->block[0] + 1; in ismt_access()
569 desc->wr_len_cmd = dma_size; in ismt_access()
570 desc->control |= ISMT_DESC_I2C; in ismt_access()
572 memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); in ismt_access()
576 dma_size = data->block[0]; in ismt_access()
578 desc->rd_len = dma_size; in ismt_access()
579 desc->wr_len_cmd = command; in ismt_access()
580 desc->control |= (ISMT_DESC_I2C | ISMT_DESC_CWRL); in ismt_access()
582 * Per the "Table 15-15. I2C Commands", in ismt_access()
587 desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, 0); in ismt_access()
594 return -EOPNOTSUPP; in ismt_access()
613 return -EIO; in ismt_access()
618 desc->dptr_low = lower_32_bits(dma_addr); in ismt_access()
619 desc->dptr_high = upper_32_bits(dma_addr); in ismt_access()
622 reinit_completion(&priv->cmp); in ismt_access()
628 time_left = wait_for_completion_timeout(&priv->cmp, HZ*1); in ismt_access()
636 ret = -ETIMEDOUT; in ismt_access()
645 priv->head++; in ismt_access()
646 priv->head %= ISMT_DESC_ENTRIES; in ismt_access()
652 * ismt_func() - report which i2c commands are supported by this adapter
674 * ismt_handle_isr() - interrupt handler bottom half
679 complete(&priv->cmp); in ismt_handle_isr()
686 * ismt_do_interrupt() - IRQ interrupt handler
687 * @vec: interrupt vector
690 static irqreturn_t ismt_do_interrupt(int vec, void *data) in ismt_do_interrupt() argument
699 val = readl(priv->smba + ISMT_MSTR_MSTS); in ismt_do_interrupt()
705 priv->smba + ISMT_MSTR_MSTS); in ismt_do_interrupt()
711 * ismt_do_msi_interrupt() - MSI interrupt handler
712 * @vec: interrupt vector
715 static irqreturn_t ismt_do_msi_interrupt(int vec, void *data) in ismt_do_msi_interrupt() argument
721 * ismt_hw_init() - initialize the iSMT hardware
727 struct device *dev = &priv->pci_dev->dev; in ismt_hw_init()
729 /* initialize the Master Descriptor Base Address (MDBA) */ in ismt_hw_init()
730 writeq(priv->io_rng_dma, priv->smba + ISMT_MSTR_MDBA); in ismt_hw_init()
732 writeq(priv->log_dma, priv->smba + ISMT_GR_SMTICL); in ismt_hw_init()
735 writel(ISMT_MCTRL_MEIE, priv->smba + ISMT_MSTR_MCTRL); in ismt_hw_init()
738 writel(0, priv->smba + ISMT_MSTR_MSTS); in ismt_hw_init()
741 val = readl(priv->smba + ISMT_MSTR_MDS); in ismt_hw_init()
742 writel((val & ~ISMT_MDS_MASK) | (ISMT_DESC_ENTRIES - 1), in ismt_hw_init()
743 priv->smba + ISMT_MSTR_MDS); in ismt_hw_init()
749 val = readl(priv->smba + ISMT_SPGT); in ismt_hw_init()
758 priv->smba + ISMT_SPGT); in ismt_hw_init()
764 priv->smba + ISMT_SPGT); in ismt_hw_init()
770 priv->smba + ISMT_SPGT); in ismt_hw_init()
776 priv->smba + ISMT_SPGT); in ismt_hw_init()
784 val = readl(priv->smba + ISMT_SPGT); in ismt_hw_init()
804 * ismt_dev_init() - initialize the iSMT data structures
810 priv->hw = dmam_alloc_coherent(&priv->pci_dev->dev, in ismt_dev_init()
813 &priv->io_rng_dma, in ismt_dev_init()
815 if (!priv->hw) in ismt_dev_init()
816 return -ENOMEM; in ismt_dev_init()
818 priv->head = 0; in ismt_dev_init()
819 init_completion(&priv->cmp); in ismt_dev_init()
821 priv->log = dmam_alloc_coherent(&priv->pci_dev->dev, in ismt_dev_init()
823 &priv->log_dma, GFP_KERNEL); in ismt_dev_init()
824 if (!priv->log) in ismt_dev_init()
825 return -ENOMEM; in ismt_dev_init()
831 * ismt_int_init() - initialize interrupts
838 /* Try using MSI interrupts */ in ismt_int_init()
839 err = pci_enable_msi(priv->pci_dev); in ismt_int_init()
843 err = devm_request_irq(&priv->pci_dev->dev, in ismt_int_init()
844 priv->pci_dev->irq, in ismt_int_init()
847 "ismt-msi", in ismt_int_init()
850 pci_disable_msi(priv->pci_dev); in ismt_int_init()
858 dev_warn(&priv->pci_dev->dev, in ismt_int_init()
859 "Unable to use MSI interrupts, falling back to legacy\n"); in ismt_int_init()
861 err = devm_request_irq(&priv->pci_dev->dev, in ismt_int_init()
862 priv->pci_dev->irq, in ismt_int_init()
865 "ismt-intx", in ismt_int_init()
868 dev_err(&priv->pci_dev->dev, "no usable interrupts\n"); in ismt_int_init()
878 * ismt_probe() - probe for iSMT devices
879 * @pdev: PCI-Express device
880 * @id: PCI-Express device ID
889 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in ismt_probe()
891 return -ENOMEM; in ismt_probe()
895 i2c_set_adapdata(&priv->adapter, priv); in ismt_probe()
896 priv->adapter.owner = THIS_MODULE; in ismt_probe()
897 priv->adapter.class = I2C_CLASS_HWMON; in ismt_probe()
898 priv->adapter.algo = &smbus_algorithm; in ismt_probe()
899 priv->adapter.dev.parent = &pdev->dev; in ismt_probe()
900 ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&pdev->dev)); in ismt_probe()
901 priv->adapter.retries = ISMT_MAX_RETRIES; in ismt_probe()
903 priv->pci_dev = pdev; in ismt_probe()
907 dev_err(&pdev->dev, "Failed to enable SMBus PCI device (%d)\n", in ismt_probe()
919 dev_err(&pdev->dev, in ismt_probe()
920 "SMBus base address uninitialized, upgrade BIOS\n"); in ismt_probe()
921 return -ENODEV; in ismt_probe()
924 snprintf(priv->adapter.name, sizeof(priv->adapter.name), in ismt_probe()
927 dev_dbg(&priv->pci_dev->dev, " start=0x%lX\n", start); in ismt_probe()
928 dev_dbg(&priv->pci_dev->dev, " len=0x%lX\n", len); in ismt_probe()
930 err = acpi_check_resource_conflict(&pdev->resource[SMBBAR]); in ismt_probe()
932 dev_err(&pdev->dev, "ACPI resource conflict!\n"); in ismt_probe()
938 dev_err(&pdev->dev, in ismt_probe()
939 "Failed to request SMBus region 0x%lx-0x%lx\n", in ismt_probe()
944 priv->smba = pcim_iomap(pdev, SMBBAR, len); in ismt_probe()
945 if (!priv->smba) { in ismt_probe()
946 dev_err(&pdev->dev, "Unable to ioremap SMBus BAR\n"); in ismt_probe()
947 return -ENODEV; in ismt_probe()
950 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in ismt_probe()
952 dev_err(&pdev->dev, "dma_set_mask fail\n"); in ismt_probe()
953 return -ENODEV; in ismt_probe()
966 err = i2c_add_adapter(&priv->adapter); in ismt_probe()
968 return -ENODEV; in ismt_probe()
973 * ismt_remove() - release driver resources
974 * @pdev: PCI-Express device
980 i2c_del_adapter(&priv->adapter); in ismt_remove()