52 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
57 #include "../comedidev.h"
60 #define PCI_MITE_SIZE 4096
61 #define PCI_DAQ_SIZE 4096
62 #define PCI_DAQ_SIZE_660X 8192
64 #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK)))
85 static void dump_chip_signature(
u32 csigr_bits)
87 pr_info(
"version = %i, type = %i, mite mode = %i, interface mode = %i\n",
88 mite_csigr_version(csigr_bits), mite_csigr_type(csigr_bits),
89 mite_csigr_mmode(csigr_bits), mite_csigr_imode(csigr_bits));
90 pr_info(
"num channels = %i, write post fifo depth = %i, wins = %i, iowins = %i\n",
91 mite_csigr_dmac(csigr_bits), mite_csigr_wpdep(csigr_bits),
92 mite_csigr_wins(csigr_bits), mite_csigr_iowins(csigr_bits));
98 unsigned empty_count = (fcr_bits >> 16) & 0xff;
99 unsigned full_count = fcr_bits & 0xff;
100 return empty_count + full_count;
109 unsigned unknown_dma_burst_bits;
113 "error enabling mite and requesting io regions\n");
123 "Failed to remap mite io memory address\n");
137 "Failed to remap daq io memory address\n");
144 "using I/O Window Base Size register 1\n");
146 MITE_IODWBSR_1_WSIZE_bits(length),
160 unknown_dma_burst_bits =
163 writel(unknown_dma_burst_bits,
170 "mite: bug? chip claims to have %i dma channels. Setting to %i.\n",
174 dump_chip_signature(csigr_bits);
183 mite->
fifo_size = mite_fifo_size(mite, 0);
255 *
ring,
unsigned min_channel,
256 unsigned max_channel)
266 for (i = min_channel; i <= max_channel; ++
i) {
274 spin_unlock_irqrestore(&mite->
lock, flags);
288 mite_dma_reset(mite_chan);
302 spin_unlock_irqrestore(&mite->
lock, flags);
324 spin_unlock_irqrestore(&mite->
lock, flags);
334 unsigned int n_links;
353 MDPRINTK(
"ring->hw_dev=%p, n_links=0x%04x\n", ring->
hw_dev, n_links);
361 "mite: ring buffer allocation failed\n");
366 for (i = 0; i < n_links; i++) {
387 unsigned int num_device_bits,
unsigned int num_memory_bits)
389 unsigned int chor, chcr, mcr,
dcr, lkcr;
410 if (num_memory_bits == 32 && num_device_bits == 16) {
427 switch (num_memory_bits) {
438 pr_warn(
"bug! invalid mem bit width for dma transfer\n");
446 switch (num_device_bits) {
457 pr_warn(
"bug! invalid dev bit width for dma transfer\n");
477 static u32 mite_device_bytes_transferred(
struct mite_channel *mite_chan)
487 MITE_FCR(mite_chan->
channel)) & 0x000000FF;
494 u32 device_byte_count;
496 device_byte_count = mite_device_bytes_transferred(mite_chan);
504 u32 in_transit_count;
507 return mite_device_bytes_transferred(mite_chan) - in_transit_count;
514 u32 device_byte_count;
516 device_byte_count = mite_device_bytes_transferred(mite_chan);
524 u32 in_transit_count;
527 return mite_device_bytes_transferred(mite_chan) + in_transit_count;
539 MDPRINTK(
"mite_dma_tcr ch%i, lkar=0x%08x tcr=%d\n", mite_chan->
channel,
561 unsigned int nbytes, old_alloc_count;
562 const unsigned bytes_per_scan = cfc_bytes_per_scan(async->
subdevice);
570 old_alloc_count) > 0) {
572 "mite: DMA overwrite of free area\n");
599 u32 nbytes_ub, nbytes_lb;
600 unsigned int old_alloc_count;
602 async->
cmd.stop_arg * cfc_bytes_per_scan(async->
subdevice);
609 (
int)(nbytes_lb - stop_count) > 0)
610 nbytes_lb = stop_count;
613 (
int)(nbytes_ub - stop_count) > 0)
614 nbytes_ub = stop_count;
615 if ((
int)(nbytes_ub - old_alloc_count) > 0) {
617 "mite: DMA underrun\n");
647 spin_unlock_irqrestore(&mite->
lock, flags);
660 done = mite_chan->
done;
661 spin_unlock_irqrestore(&mite->
lock, flags);
670 static const char *
const mite_CHOR_strings[] = {
671 "start",
"cont",
"stop",
"abort",
672 "freset",
"clrlc",
"clrrb",
"clrdone",
673 "clr_lpause",
"set_lpause",
"clr_send_tc",
674 "set_send_tc",
"12",
"13",
"14",
675 "15",
"16",
"17",
"18",
676 "19",
"20",
"21",
"22",
677 "23",
"24",
"25",
"26",
678 "27",
"28",
"29",
"30",
682 static const char *
const mite_CHCR_strings[] = {
683 "continue",
"ringbuff",
"2",
"3",
685 "8",
"9",
"10",
"11",
686 "12",
"13",
"bursten",
"fifodis",
687 "clr_cont_rb_ie",
"set_cont_rb_ie",
"clr_lc_ie",
"set_lc_ie",
688 "clr_drdy_ie",
"set_drdy_ie",
"clr_mrdy_ie",
"set_mrdy_ie",
689 "clr_done_ie",
"set_done_ie",
"clr_sar_ie",
"set_sar_ie",
690 "clr_linkp_ie",
"set_linkp_ie",
"clr_dma_ie",
"set_dma_ie",
693 static const char *
const mite_MCR_strings[] = {
694 "amdevice",
"1",
"2",
"3",
695 "4",
"5",
"portio",
"portvxi",
696 "psizebyte",
"psizehalf (byte & half = word)",
"aseqxp1",
"11",
697 "12",
"13",
"blocken",
"berhand",
698 "reqsintlim/reqs0",
"reqs1",
"reqs2",
"rd32",
699 "rd512",
"rl1",
"rl2",
"rl8",
700 "24",
"25",
"26",
"27",
701 "28",
"29",
"30",
"stopen",
704 static const char *
const mite_DCR_strings[] = {
705 "amdevice",
"1",
"2",
"3",
706 "4",
"5",
"portio",
"portvxi",
707 "psizebyte",
"psizehalf (byte & half = word)",
"aseqxp1",
"aseqxp2",
708 "aseqxp8",
"13",
"blocken",
"berhand",
709 "reqsintlim",
"reqs1",
"reqs2",
"rd32",
710 "rd512",
"rl1",
"rl2",
"rl8",
711 "23",
"24",
"25",
"27",
712 "28",
"wsdevc",
"wsdevs",
"rwdevpack",
715 static const char *
const mite_LKCR_strings[] = {
716 "amdevice",
"1",
"2",
"3",
717 "4",
"5",
"portio",
"portvxi",
718 "psizebyte",
"psizehalf (byte & half = word)",
"asequp",
"aseqdown",
719 "12",
"13",
"14",
"berhand",
720 "16",
"17",
"18",
"rd32",
721 "rd512",
"rl1",
"rl2",
"rl8",
722 "24",
"25",
"26",
"27",
723 "28",
"29",
"30",
"chngend",
726 static const char *
const mite_CHSR_strings[] = {
727 "d.err0",
"d.err1",
"m.err0",
"m.err1",
728 "l.err0",
"l.err1",
"drq0",
"drq1",
729 "end",
"xferr",
"operr0",
"operr1",
730 "stops",
"habort",
"sabort",
"error",
731 "16",
"conts_rb",
"18",
"linkc",
732 "20",
"drdy",
"22",
"mrdy",
733 "24",
"done",
"26",
"sars",
734 "28",
"lpauses",
"30",
"int",
737 static void mite_decode(
const char *
const *bit_str,
unsigned int bits)
741 for (i = 31; i >= 0; i--) {
752 int channel = mite_chan->
channel;
754 pr_debug(
"mite_dump_regs ch%i\n", channel);
755 pr_debug(
"mite address is =%p\n", mite_io_addr);
757 offset = MITE_CHOR(channel);
758 value =
readl(mite_io_addr + offset);
759 pr_debug(
"mite status[CHOR] at 0x%08x =0x%08x\n", offset, value);
760 mite_decode(mite_CHOR_strings, value);
761 offset = MITE_CHCR(channel);
762 value =
readl(mite_io_addr + offset);
763 pr_debug(
"mite status[CHCR] at 0x%08x =0x%08x\n", offset, value);
764 mite_decode(mite_CHCR_strings, value);
765 offset = MITE_TCR(channel);
766 value =
readl(mite_io_addr + offset);
767 pr_debug(
"mite status[TCR] at 0x%08x =0x%08x\n", offset, value);
768 offset = MITE_MCR(channel);
769 value =
readl(mite_io_addr + offset);
770 pr_debug(
"mite status[MCR] at 0x%08x =0x%08x\n", offset, value);
771 mite_decode(mite_MCR_strings, value);
772 offset = MITE_MAR(channel);
773 value =
readl(mite_io_addr + offset);
774 pr_debug(
"mite status[MAR] at 0x%08x =0x%08x\n", offset, value);
775 offset = MITE_DCR(channel);
776 value =
readl(mite_io_addr + offset);
777 pr_debug(
"mite status[DCR] at 0x%08x =0x%08x\n", offset, value);
778 mite_decode(mite_DCR_strings, value);
779 offset = MITE_DAR(channel);
780 value =
readl(mite_io_addr + offset);
781 pr_debug(
"mite status[DAR] at 0x%08x =0x%08x\n", offset, value);
782 offset = MITE_LKCR(channel);
783 value =
readl(mite_io_addr + offset);
784 pr_debug(
"mite status[LKCR] at 0x%08x =0x%08x\n", offset, value);
785 mite_decode(mite_LKCR_strings, value);
786 offset = MITE_LKAR(channel);
787 value =
readl(mite_io_addr + offset);
788 pr_debug(
"mite status[LKAR] at 0x%08x =0x%08x\n", offset, value);
789 offset = MITE_CHSR(channel);
790 value =
readl(mite_io_addr + offset);
791 pr_debug(
"mite status[CHSR] at 0x%08x =0x%08x\n", offset, value);
792 mite_decode(mite_CHSR_strings, value);
793 offset = MITE_FCR(channel);
794 value =
readl(mite_io_addr + offset);
795 pr_debug(
"mite status[FCR] at 0x%08x =0x%08x\n", offset, value);
800 static int __init mite_module_init(
void)
805 static void __exit mite_module_exit(
void)