4 * Copyright (C) 2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
6 ********************************************************************
8 * Copyright (C) 1999 RG Studio s.c.
9 * Written by Krzysztof Halasa <khc@rgstudio.com.pl>
11 * Portions (C) SBE Inc., used by permission.
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
19 #ifndef __COMEDI_PLX9080_H
20 #define __COMEDI_PLX9080_H
22 #include <linux/compiler.h>
23 #include <linux/types.h>
24 #include <linux/bitops.h>
25 #include <linux/delay.h>
26 #include <linux/errno.h>
30 * struct plx_dma_desc - DMA descriptor format for PLX PCI 9080
31 * @pci_start_addr: PCI Bus address for transfer (DMAPADR).
32 * @local_start_addr: Local Bus address for transfer (DMALADR).
33 * @transfer_size: Transfer size in bytes (max 8 MiB) (DMASIZ).
34 * @next: Address of next descriptor + flags (DMADPR).
36 * Describes the format of a scatter-gather DMA descriptor for the PLX
37 * PCI 9080. All members are raw, little-endian register values that
38 * will be transferred by the DMA engine from local or PCI memory into
39 * corresponding registers for the DMA channel.
41 * The DMA descriptors must be aligned on a 16-byte boundary. Bits 3:0
42 * of @next contain flags describing the address space of the next
43 * descriptor (local or PCI), an "end of chain" marker, an "interrupt on
44 * terminal count" bit, and a data transfer direction.
47 __le32 pci_start_addr;
48 __le32 local_start_addr;
54 * Register Offsets and Bit Definitions
57 /* Local Address Space 0 Range Register */
58 #define PLX_REG_LAS0RR 0x0000
59 /* Local Address Space 1 Range Register */
60 #define PLX_REG_LAS1RR 0x00f0
62 #define PLX_LASRR_IO BIT(0) /* Map to: 1=I/O, 0=Mem */
63 #define PLX_LASRR_ANY32 (BIT(1) * 0) /* Locate anywhere in 32 bit */
64 #define PLX_LASRR_LT1MB (BIT(1) * 1) /* Locate in 1st meg */
65 #define PLX_LASRR_ANY64 (BIT(1) * 2) /* Locate anywhere in 64 bit */
66 #define PLX_LASRR_MLOC_MASK GENMASK(2, 1) /* Memory location bits */
67 #define PLX_LASRR_PREFETCH BIT(3) /* Memory is prefetchable */
68 /* bits that specify range for memory space decode bits */
69 #define PLX_LASRR_MEM_MASK GENMASK(31, 4)
70 /* bits that specify range for i/o space decode bits */
71 #define PLX_LASRR_IO_MASK GENMASK(31, 2)
73 /* Local Address Space 0 Local Base Address (Remap) Register */
74 #define PLX_REG_LAS0BA 0x0004
75 /* Local Address Space 1 Local Base Address (Remap) Register */
76 #define PLX_REG_LAS1BA 0x00f4
78 #define PLX_LASBA_EN BIT(0) /* Enable slave decode */
79 /* bits that specify local base address for memory space */
80 #define PLX_LASBA_MEM_MASK GENMASK(31, 4)
81 /* bits that specify local base address for i/o space */
82 #define PLX_LASBA_IO_MASK GENMASK(31, 2)
84 /* Mode/Arbitration Register */
85 #define PLX_REG_MARBR 0x0008
86 /* DMA Arbitration Register (alias of MARBR). */
87 #define PLX_REG_DMAARB 0x00ac
89 /* Local Bus Latency Timer */
90 #define PLX_MARBR_LT(x) (BIT(0) * ((x) & 0xff))
91 #define PLX_MARBR_LT_MASK GENMASK(7, 0)
92 #define PLX_MARBR_LT_SHIFT 0
93 /* Local Bus Pause Timer */
94 #define PLX_MARBR_PT(x) (BIT(8) * ((x) & 0xff))
95 #define PLX_MARBR_PT_MASK GENMASK(15, 8)
96 #define PLX_MARBR_PT_SHIFT 8
97 /* Local Bus Latency Timer Enable */
98 #define PLX_MARBR_LTEN BIT(16)
99 /* Local Bus Pause Timer Enable */
100 #define PLX_MARBR_PTEN BIT(17)
101 /* Local Bus BREQ Enable */
102 #define PLX_MARBR_BREQEN BIT(18)
103 /* DMA Channel Priority */
104 #define PLX_MARBR_PRIO_ROT (BIT(19) * 0) /* Rotational priority */
105 #define PLX_MARBR_PRIO_DMA0 (BIT(19) * 1) /* DMA channel 0 has priority */
106 #define PLX_MARBR_PRIO_DMA1 (BIT(19) * 2) /* DMA channel 1 has priority */
107 #define PLX_MARBR_PRIO_MASK GENMASK(20, 19)
108 /* Local Bus Direct Slave Give Up Bus Mode */
109 #define PLX_MARBR_DSGUBM BIT(21)
110 /* Direct Slace LLOCKo# Enable */
111 #define PLX_MARBR_DSLLOCKOEN BIT(22)
112 /* PCI Request Mode */
113 #define PLX_MARBR_PCIREQM BIT(23)
114 /* PCI Specification v2.1 Mode */
115 #define PLX_MARBR_PCIV21M BIT(24)
116 /* PCI Read No Write Mode */
117 #define PLX_MARBR_PCIRNWM BIT(25)
118 /* PCI Read with Write Flush Mode */
119 #define PLX_MARBR_PCIRWFM BIT(26)
120 /* Gate Local Bus Latency Timer with BREQ */
121 #define PLX_MARBR_GLTBREQ BIT(27)
122 /* PCI Read No Flush Mode */
123 #define PLX_MARBR_PCIRNFM BIT(28)
125 * Make reads from PCI Configuration register 0 return Subsystem ID and
126 * Subsystem Vendor ID instead of Device ID and Vendor ID
128 #define PLX_MARBR_SUBSYSIDS BIT(29)
130 /* Big/Little Endian Descriptor Register */
131 #define PLX_REG_BIGEND 0x000c
133 /* Configuration Register Big Endian Mode */
134 #define PLX_BIGEND_CONFIG BIT(0)
135 /* Direct Master Big Endian Mode */
136 #define PLX_BIGEND_DM BIT(1)
137 /* Direct Slave Address Space 0 Big Endian Mode */
138 #define PLX_BIGEND_DSAS0 BIT(2)
139 /* Direct Slave Expansion ROM Big Endian Mode */
140 #define PLX_BIGEND_EROM BIT(3)
141 /* Big Endian Byte Lane Mode - use most significant byte lanes */
142 #define PLX_BIGEND_BEBLM BIT(4)
143 /* Direct Slave Address Space 1 Big Endian Mode */
144 #define PLX_BIGEND_DSAS1 BIT(5)
145 /* DMA Channel 1 Big Endian Mode */
146 #define PLX_BIGEND_DMA1 BIT(6)
147 /* DMA Channel 0 Big Endian Mode */
148 #define PLX_BIGEND_DMA0 BIT(7)
149 /* DMA Channel N Big Endian Mode (N <= 1) */
150 #define PLX_BIGEND_DMA(n) ((n) ? PLX_BIGEND_DMA1 : PLX_BIGEND_DMA0)
153 * Note: The Expansion ROM stuff is only relevant to the PC environment.
154 * This expansion ROM code is executed by the host CPU at boot time.
155 * For this reason no bit definitions are provided here.
158 /* Expansion ROM Range Register */
159 #define PLX_REG_EROMRR 0x0010
160 /* Expansion ROM Local Base Address (Remap) Register */
161 #define PLX_REG_EROMBA 0x0014
163 /* Local Address Space 0/Expansion ROM Bus Region Descriptor Register */
164 #define PLX_REG_LBRD0 0x0018
165 /* Local Address Space 1 Bus Region Descriptor Register */
166 #define PLX_REG_LBRD1 0x00f8
168 /* Memory Space Local Bus Width */
169 #define PLX_LBRD_MSWIDTH8 (BIT(0) * 0) /* 8 bits wide */
170 #define PLX_LBRD_MSWIDTH16 (BIT(0) * 1) /* 16 bits wide */
171 #define PLX_LBRD_MSWIDTH32 (BIT(0) * 2) /* 32 bits wide */
172 #define PLX_LBRD_MSWIDTH32A (BIT(0) * 3) /* 32 bits wide */
173 #define PLX_LBRD_MSWIDTH_MASK GENMASK(1, 0)
174 #define PLX_LBRD_MSWIDTH_SHIFT 0
175 /* Memory Space Internal Wait States */
176 #define PLX_LBRD_MSIWS(x) (BIT(2) * ((x) & 0xf))
177 #define PLX_LBRD_MSIWS_MASK GENMASK(5, 2)
178 #define PLX_LBRD_MSIWS_SHIFT 2
179 /* Memory Space Ready Input Enable */
180 #define PLX_LBRD_MSREADYIEN BIT(6)
181 /* Memory Space BTERM# Input Enable */
182 #define PLX_LBRD_MSBTERMIEN BIT(7)
183 /* Memory Space 0 Prefetch Disable (LBRD0 only) */
184 #define PLX_LBRD0_MSPREDIS BIT(8)
185 /* Memory Space 1 Burst Enable (LBRD1 only) */
186 #define PLX_LBRD1_MSBURSTEN BIT(8)
187 /* Expansion ROM Space Prefetch Disable (LBRD0 only) */
188 #define PLX_LBRD0_EROMPREDIS BIT(9)
189 /* Memory Space 1 Prefetch Disable (LBRD1 only) */
190 #define PLX_LBRD1_MSPREDIS BIT(9)
191 /* Read Prefetch Count Enable */
192 #define PLX_LBRD_RPFCOUNTEN BIT(10)
193 /* Prefetch Counter */
194 #define PLX_LBRD_PFCOUNT(x) (BIT(11) * ((x) & 0xf))
195 #define PLX_LBRD_PFCOUNT_MASK GENMASK(14, 11)
196 #define PLX_LBRD_PFCOUNT_SHIFT 11
197 /* Expansion ROM Space Local Bus Width (LBRD0 only) */
198 #define PLX_LBRD0_EROMWIDTH8 (BIT(16) * 0) /* 8 bits wide */
199 #define PLX_LBRD0_EROMWIDTH16 (BIT(16) * 1) /* 16 bits wide */
200 #define PLX_LBRD0_EROMWIDTH32 (BIT(16) * 2) /* 32 bits wide */
201 #define PLX_LBRD0_EROMWIDTH32A (BIT(16) * 3) /* 32 bits wide */
202 #define PLX_LBRD0_EROMWIDTH_MASK GENMASK(17, 16)
203 #define PLX_LBRD0_EROMWIDTH_SHIFT 16
204 /* Expansion ROM Space Internal Wait States (LBRD0 only) */
205 #define PLX_LBRD0_EROMIWS(x) (BIT(18) * ((x) & 0xf))
206 #define PLX_LBRD0_EROMIWS_MASK GENMASK(21, 18)
207 #define PLX_LBRD0_EROMIWS_SHIFT 18
208 /* Expansion ROM Space Ready Input Enable (LBDR0 only) */
209 #define PLX_LBRD0_EROMREADYIEN BIT(22)
210 /* Expansion ROM Space BTERM# Input Enable (LBRD0 only) */
211 #define PLX_LBRD0_EROMBTERMIEN BIT(23)
212 /* Memory Space 0 Burst Enable (LBRD0 only) */
213 #define PLX_LBRD0_MSBURSTEN BIT(24)
214 /* Extra Long Load From Serial EEPROM (LBRD0 only) */
215 #define PLX_LBRD0_EELONGLOAD BIT(25)
216 /* Expansion ROM Space Burst Enable (LBRD0 only) */
217 #define PLX_LBRD0_EROMBURSTEN BIT(26)
218 /* Direct Slave PCI Write Mode - assert TRDY# when FIFO full (LBRD0 only) */
219 #define PLX_LBRD0_DSWMTRDY BIT(27)
220 /* PCI Target Retry Delay Clocks / 8 (LBRD0 only) */
221 #define PLX_LBRD0_TRDELAY(x) (BIT(28) * ((x) & 0xF))
222 #define PLX_LBRD0_TRDELAY_MASK GENMASK(31, 28)
223 #define PLX_LBRD0_TRDELAY_SHIFT 28
225 /* Local Range Register for Direct Master to PCI */
226 #define PLX_REG_DMRR 0x001c
228 /* Local Bus Base Address Register for Direct Master to PCI Memory */
229 #define PLX_REG_DMLBAM 0x0020
231 /* Local Base Address Register for Direct Master to PCI IO/CFG */
232 #define PLX_REG_DMLBAI 0x0024
234 /* PCI Base Address (Remap) Register for Direct Master to PCI Memory */
235 #define PLX_REG_DMPBAM 0x0028
237 /* Direct Master Memory Access Enable */
238 #define PLX_DMPBAM_MEMACCEN BIT(0)
239 /* Direct Master I/O Access Enable */
240 #define PLX_DMPBAM_IOACCEN BIT(1)
241 /* LLOCK# Input Enable */
242 #define PLX_DMPBAM_LLOCKIEN BIT(2)
243 /* Direct Master Read Prefetch Size Control (bits 12, 3) */
244 #define PLX_DMPBAM_RPSIZECONT ((BIT(12) * 0) | (BIT(3) * 0))
245 #define PLX_DMPBAM_RPSIZE4 ((BIT(12) * 0) | (BIT(3) * 1))
246 #define PLX_DMPBAM_RPSIZE8 ((BIT(12) * 1) | (BIT(3) * 0))
247 #define PLX_DMPBAM_RPSIZE16 ((BIT(12) * 1) | (BIT(3) * 1))
248 #define PLX_DMPBAM_RPSIZE_MASK (BIT(12) | BIT(3))
249 /* Direct Master PCI Read Mode - deassert IRDY when FIFO full */
250 #define PLX_DMPBAM_RMIRDY BIT(4)
251 /* Programmable Almost Full Level (bits 10, 8:5) */
252 #define PLX_DMPBAM_PAFL(x) ((BIT(10) * !!((x) & 0x10)) | \
253 (BIT(5) * ((x) & 0xf)))
254 #define PLX_DMPBAM_TO_PAFL(v) ((((BIT(10) & (v)) >> 1) | \
255 (GENMASK(8, 5) & (v))) >> 5)
256 #define PLX_DMPBAM_PAFL_MASK (BIT(10) | GENMASK(8, 5))
257 /* Write And Invalidate Mode */
258 #define PLX_DMPBAM_WIM BIT(9)
259 /* Direct Master Prefetch Limit */
260 #define PLX_DBPBAM_PFLIMIT BIT(11)
261 /* I/O Remap Select */
262 #define PLX_DMPBAM_IOREMAPSEL BIT(13)
263 /* Direct Master Write Delay */
264 #define PLX_DMPBAM_WDELAYNONE (BIT(14) * 0)
265 #define PLX_DMPBAM_WDELAY4 (BIT(14) * 1)
266 #define PLX_DMPBAM_WDELAY8 (BIT(14) * 2)
267 #define PLX_DMPBAM_WDELAY16 (BIT(14) * 3)
268 #define PLX_DMPBAM_WDELAY_MASK GENMASK(15, 14)
269 /* Remap of Local-to-PCI Space Into PCI Address Space */
270 #define PLX_DMPBAM_REMAP_MASK GENMASK(31, 16)
272 /* PCI Configuration Address Register for Direct Master to PCI IO/CFG */
273 #define PLX_REG_DMCFGA 0x002c
275 /* Congiguration Type */
276 #define PLX_DMCFGA_TYPE0 (BIT(0) * 0)
277 #define PLX_DMCFGA_TYPE1 (BIT(0) * 1)
278 #define PLX_DMCFGA_TYPE_MASK GENMASK(1, 0)
279 /* Register Number */
280 #define PLX_DMCFGA_REGNUM(x) (BIT(2) * ((x) & 0x3f))
281 #define PLX_DMCFGA_REGNUM_MASK GENMASK(7, 2)
282 #define PLX_DMCFGA_REGNUM_SHIFT 2
283 /* Function Number */
284 #define PLX_DMCFGA_FUNCNUM(x) (BIT(8) * ((x) & 0x7))
285 #define PLX_DMCFGA_FUNCNUM_MASK GENMASK(10, 8)
286 #define PLX_DMCFGA_FUNCNUM_SHIFT 8
288 #define PLX_DMCFGA_DEVNUM(x) (BIT(11) * ((x) & 0x1f))
289 #define PLX_DMCFGA_DEVNUM_MASK GENMASK(15, 11)
290 #define PLX_DMCFGA_DEVNUM_SHIFT 11
292 #define PLX_DMCFGA_BUSNUM(x) (BIT(16) * ((x) & 0xff))
293 #define PLX_DMCFGA_BUSNUM_MASK GENMASK(23, 16)
294 #define PLX_DMCFGA_BUSNUM_SHIFT 16
295 /* Configuration Enable */
296 #define PLX_DMCFGA_CONFIGEN BIT(31)
299 * Mailbox Register N (N <= 7)
301 * Note that if the I2O feature is enabled (QSR[0] is set), Mailbox Register 0
302 * is replaced by the Inbound Queue Port, and Mailbox Register 1 is replaced
303 * by the Outbound Queue Port. However, Mailbox Register 0 and 1 are always
304 * accessible at alternative offsets if the I2O feature is enabled.
306 #define PLX_REG_MBOX(n) (0x0040 + (n) * 4)
307 #define PLX_REG_MBOX0 PLX_REG_MBOX(0)
308 #define PLX_REG_MBOX1 PLX_REG_MBOX(1)
309 #define PLX_REG_MBOX2 PLX_REG_MBOX(2)
310 #define PLX_REG_MBOX3 PLX_REG_MBOX(3)
311 #define PLX_REG_MBOX4 PLX_REG_MBOX(4)
312 #define PLX_REG_MBOX5 PLX_REG_MBOX(5)
313 #define PLX_REG_MBOX6 PLX_REG_MBOX(6)
314 #define PLX_REG_MBOX7 PLX_REG_MBOX(7)
316 /* Alternative offsets for Mailbox Registers 0 and 1 (in case I2O is enabled) */
317 #define PLX_REG_ALT_MBOX(n) ((n) < 2 ? 0x0078 + (n) * 4 : PLX_REG_MBOX(n))
318 #define PLX_REG_ALT_MBOX0 PLX_REG_ALT_MBOX(0)
319 #define PLX_REG_ALT_MBOX1 PLX_REG_ALT_MBOX(1)
321 /* PCI-to-Local Doorbell Register */
322 #define PLX_REG_P2LDBELL 0x0060
324 /* Local-to-PCI Doorbell Register */
325 #define PLX_REG_L2PDBELL 0x0064
327 /* Interrupt Control/Status Register */
328 #define PLX_REG_INTCSR 0x0068
330 /* Enable Local Bus LSERR# when PCI Bus Target Abort or Master Abort occurs */
331 #define PLX_INTCSR_LSEABORTEN BIT(0)
332 /* Enable Local Bus LSERR# when PCI parity error occurs */
333 #define PLX_INTCSR_LSEPARITYEN BIT(1)
334 /* Generate PCI Bus SERR# when set to 1 */
335 #define PLX_INTCSR_GENSERR BIT(2)
336 /* Mailbox Interrupt Enable (local bus interrupts on PCI write to MBOX0-3) */
337 #define PLX_INTCSR_MBIEN BIT(3)
338 /* PCI Interrupt Enable */
339 #define PLX_INTCSR_PIEN BIT(8)
340 /* PCI Doorbell Interrupt Enable */
341 #define PLX_INTCSR_PDBIEN BIT(9)
342 /* PCI Abort Interrupt Enable */
343 #define PLX_INTCSR_PABORTIEN BIT(10)
344 /* PCI Local Interrupt Enable */
345 #define PLX_INTCSR_PLIEN BIT(11)
346 /* Retry Abort Enable (for diagnostic purposes only) */
347 #define PLX_INTCSR_RAEN BIT(12)
348 /* PCI Doorbell Interrupt Active (read-only) */
349 #define PLX_INTCSR_PDBIA BIT(13)
350 /* PCI Abort Interrupt Active (read-only) */
351 #define PLX_INTCSR_PABORTIA BIT(14)
352 /* Local Interrupt (LINTi#) Active (read-only) */
353 #define PLX_INTCSR_PLIA BIT(15)
354 /* Local Interrupt Output (LINTo#) Enable */
355 #define PLX_INTCSR_LIOEN BIT(16)
356 /* Local Doorbell Interrupt Enable */
357 #define PLX_INTCSR_LDBIEN BIT(17)
358 /* DMA Channel 0 Interrupt Enable */
359 #define PLX_INTCSR_DMA0IEN BIT(18)
360 /* DMA Channel 1 Interrupt Enable */
361 #define PLX_INTCSR_DMA1IEN BIT(19)
362 /* DMA Channel N Interrupt Enable (N <= 1) */
363 #define PLX_INTCSR_DMAIEN(n) ((n) ? PLX_INTCSR_DMA1IEN : PLX_INTCSR_DMA0IEN)
364 /* Local Doorbell Interrupt Active (read-only) */
365 #define PLX_INTCSR_LDBIA BIT(20)
366 /* DMA Channel 0 Interrupt Active (read-only) */
367 #define PLX_INTCSR_DMA0IA BIT(21)
368 /* DMA Channel 1 Interrupt Active (read-only) */
369 #define PLX_INTCSR_DMA1IA BIT(22)
370 /* DMA Channel N Interrupt Active (N <= 1) (read-only) */
371 #define PLX_INTCSR_DMAIA(n) ((n) ? PLX_INTCSR_DMA1IA : PLX_INTCSR_DMA0IA)
372 /* BIST Interrupt Active (read-only) */
373 #define PLX_INTCSR_BISTIA BIT(23)
374 /* Direct Master Not Bus Master During Master Or Target Abort (read-only) */
375 #define PLX_INTCSR_ABNOTDM BIT(24)
376 /* DMA Channel 0 Not Bus Master During Master Or Target Abort (read-only) */
377 #define PLX_INTCSR_ABNOTDMA0 BIT(25)
378 /* DMA Channel 1 Not Bus Master During Master Or Target Abort (read-only) */
379 #define PLX_INTCSR_ABNOTDMA1 BIT(26)
380 /* DMA Channel N Not Bus Master During Master Or Target Abort (read-only) */
381 #define PLX_INTCSR_ABNOTDMA(n) ((n) ? PLX_INTCSR_ABNOTDMA1 \
382 : PLX_INTCSR_ABNOTDMA0)
383 /* Target Abort Not Generated After 256 Master Retries (read-only) */
384 #define PLX_INTCSR_ABNOTRETRY BIT(27)
385 /* PCI Wrote Mailbox 0 (enabled if bit 3 set) (read-only) */
386 #define PLX_INTCSR_MB0IA BIT(28)
387 /* PCI Wrote Mailbox 1 (enabled if bit 3 set) (read-only) */
388 #define PLX_INTCSR_MB1IA BIT(29)
389 /* PCI Wrote Mailbox 2 (enabled if bit 3 set) (read-only) */
390 #define PLX_INTCSR_MB2IA BIT(30)
391 /* PCI Wrote Mailbox 3 (enabled if bit 3 set) (read-only) */
392 #define PLX_INTCSR_MB3IA BIT(31)
393 /* PCI Wrote Mailbox N (N <= 3) (enabled if bit 3 set) (read-only) */
394 #define PLX_INTCSR_MBIA(n) BIT(28 + (n))
397 * Serial EEPROM Control, PCI Command Codes, User I/O Control,
398 * Init Control Register
400 #define PLX_REG_CNTRL 0x006c
402 /* PCI Read Command Code For DMA */
403 #define PLX_CNTRL_CCRDMA(x) (BIT(0) * ((x) & 0xf))
404 #define PLX_CNTRL_CCRDMA_MASK GENMASK(3, 0)
405 #define PLX_CNTRL_CCRDMA_SHIFT 0
406 #define PLX_CNTRL_CCRDMA_NORMAL PLX_CNTRL_CCRDMA(14) /* value after reset */
407 /* PCI Write Command Code For DMA 0 */
408 #define PLX_CNTRL_CCWDMA(x) (BIT(4) * ((x) & 0xf))
409 #define PLX_CNTRL_CCWDMA_MASK GENMASK(7, 4)
410 #define PLX_CNTRL_CCWDMA_SHIFT 4
411 #define PLX_CNTRL_CCWDMA_NORMAL PLX_CNTRL_CCWDMA(7) /* value after reset */
412 /* PCI Memory Read Command Code For Direct Master */
413 #define PLX_CNTRL_CCRDM(x) (BIT(8) * ((x) & 0xf))
414 #define PLX_CNTRL_CCRDM_MASK GENMASK(11, 8)
415 #define PLX_CNTRL_CCRDM_SHIFT 8
416 #define PLX_CNTRL_CCRDM_NORMAL PLX_CNTRL_CCRDM(6) /* value after reset */
417 /* PCI Memory Write Command Code For Direct Master */
418 #define PLX_CNTRL_CCWDM(x) (BIT(12) * ((x) & 0xf))
419 #define PLX_CNTRL_CCWDM_MASK GENMASK(15, 12)
420 #define PLX_CNTRL_CCWDM_SHIFT 12
421 #define PLX_CNTRL_CCWDM_NORMAL PLX_CNTRL_CCWDM(7) /* value after reset */
422 /* General Purpose Output (USERO) */
423 #define PLX_CNTRL_USERO BIT(16)
424 /* General Purpose Input (USERI) (read-only) */
425 #define PLX_CNTRL_USERI BIT(17)
426 /* Serial EEPROM Clock Output (EESK) */
427 #define PLX_CNTRL_EESK BIT(24)
428 /* Serial EEPROM Chip Select Output (EECS) */
429 #define PLX_CNTRL_EECS BIT(25)
430 /* Serial EEPROM Data Write Bit (EEDI (sic)) */
431 #define PLX_CNTRL_EEWB BIT(26)
432 /* Serial EEPROM Data Read Bit (EEDO (sic)) (read-only) */
433 #define PLX_CNTRL_EERB BIT(27)
434 /* Serial EEPROM Present (read-only) */
435 #define PLX_CNTRL_EEPRESENT BIT(28)
436 /* Reload Configuration Registers from EEPROM */
437 #define PLX_CNTRL_EERELOAD BIT(29)
438 /* PCI Adapter Software Reset (asserts LRESETo#) */
439 #define PLX_CNTRL_RESET BIT(30)
440 /* Local Init Status (read-only) */
441 #define PLX_CNTRL_INITDONE BIT(31)
443 * Combined command code stuff for convenience.
445 #define PLX_CNTRL_CC_MASK \
446 (PLX_CNTRL_CCRDMA_MASK | PLX_CNTRL_CCWDMA_MASK | \
447 PLX_CNTRL_CCRDM_MASK | PLX_CNTRL_CCWDM_MASK)
448 #define PLX_CNTRL_CC_NORMAL \
449 (PLX_CNTRL_CCRDMA_NORMAL | PLX_CNTRL_CCWDMA_NORMAL | \
450 PLX_CNTRL_CCRDM_NORMAL | PLX_CNTRL_CCWDM_NORMAL) /* val after reset */
452 /* PCI Permanent Configuration ID Register (hard-coded PLX vendor and device) */
453 #define PLX_REG_PCIHIDR 0x0070
455 /* Hard-coded ID for PLX PCI 9080 */
456 #define PLX_PCIHIDR_9080 0x908010b5
458 /* PCI Permanent Revision ID Register (hard-coded silicon revision) (8-bit). */
459 #define PLX_REG_PCIHREV 0x0074
461 /* DMA Channel N Mode Register (N <= 1) */
462 #define PLX_REG_DMAMODE(n) ((n) ? PLX_REG_DMAMODE1 : PLX_REG_DMAMODE0)
463 #define PLX_REG_DMAMODE0 0x0080
464 #define PLX_REG_DMAMODE1 0x0094
466 /* Local Bus Width */
467 #define PLX_DMAMODE_WIDTH8 (BIT(0) * 0) /* 8 bits wide */
468 #define PLX_DMAMODE_WIDTH16 (BIT(0) * 1) /* 16 bits wide */
469 #define PLX_DMAMODE_WIDTH32 (BIT(0) * 2) /* 32 bits wide */
470 #define PLX_DMAMODE_WIDTH32A (BIT(0) * 3) /* 32 bits wide */
471 #define PLX_DMAMODE_WIDTH_MASK GENMASK(1, 0)
472 #define PLX_DMAMODE_WIDTH_SHIFT 0
473 /* Internal Wait States */
474 #define PLX_DMAMODE_IWS(x) (BIT(2) * ((x) & 0xf))
475 #define PLX_DMAMODE_IWS_MASK GENMASK(5, 2)
476 #define PLX_DMAMODE_SHIFT 2
477 /* Ready Input Enable */
478 #define PLX_DMAMODE_READYIEN BIT(6)
479 /* BTERM# Input Enable */
480 #define PLX_DMAMODE_BTERMIEN BIT(7)
481 /* Local Burst Enable */
482 #define PLX_DMAMODE_BURSTEN BIT(8)
483 /* Chaining Enable */
484 #define PLX_DMAMODE_CHAINEN BIT(9)
485 /* Done Interrupt Enable */
486 #define PLX_DMAMODE_DONEIEN BIT(10)
487 /* Hold Local Address Constant */
488 #define PLX_DMAMODE_LACONST BIT(11)
490 #define PLX_DMAMODE_DEMAND BIT(12)
491 /* Write And Invalidate Mode */
492 #define PLX_DMAMODE_WINVALIDATE BIT(13)
493 /* DMA EOT Enable - enables EOT0# or EOT1# input pin */
494 #define PLX_DMAMODE_EOTEN BIT(14)
495 /* DMA Stop Data Transfer Mode - 0:BLAST; 1:EOT asserted or DREQ deasserted */
496 #define PLX_DMAMODE_STOP BIT(15)
497 /* DMA Clear Count Mode - count in descriptor cleared on completion */
498 #define PLX_DMAMODE_CLRCOUNT BIT(16)
499 /* DMA Channel Interrupt Select - 0:local bus interrupt; 1:PCI interrupt */
500 #define PLX_DMAMODE_INTRPCI BIT(17)
502 /* DMA Channel N PCI Address Register (N <= 1) */
503 #define PLX_REG_DMAPADR(n) ((n) ? PLX_REG_DMAPADR1 : PLX_REG_DMAPADR0)
504 #define PLX_REG_DMAPADR0 0x0084
505 #define PLX_REG_DMAPADR1 0x0098
507 /* DMA Channel N Local Address Register (N <= 1) */
508 #define PLX_REG_DMALADR(n) ((n) ? PLX_REG_DMALADR1 : PLX_REG_DMALADR0)
509 #define PLX_REG_DMALADR0 0x0088
510 #define PLX_REG_DMALADR1 0x009c
512 /* DMA Channel N Transfer Size (Bytes) Register (N <= 1) (first 23 bits) */
513 #define PLX_REG_DMASIZ(n) ((n) ? PLX_REG_DMASIZ1 : PLX_REG_DMASIZ0)
514 #define PLX_REG_DMASIZ0 0x008c
515 #define PLX_REG_DMASIZ1 0x00a0
517 /* DMA Channel N Descriptor Pointer Register (N <= 1) */
518 #define PLX_REG_DMADPR(n) ((n) ? PLX_REG_DMADPR1 : PLX_REG_DMADPR0)
519 #define PLX_REG_DMADPR0 0x0090
520 #define PLX_REG_DMADPR1 0x00a4
522 /* Descriptor Located In PCI Address Space (not local address space) */
523 #define PLX_DMADPR_DESCPCI BIT(0)
525 #define PLX_DMADPR_CHAINEND BIT(1)
526 /* Interrupt After Terminal Count */
527 #define PLX_DMADPR_TCINTR BIT(2)
528 /* Direction Of Transfer Local Bus To PCI (not PCI to local) */
529 #define PLX_DMADPR_XFERL2P BIT(3)
530 /* Next Descriptor Address Bits 31:4 (16 byte boundary) */
531 #define PLX_DMADPR_NEXT_MASK GENMASK(31, 4)
533 /* DMA Channel N Command/Status Register (N <= 1) (8-bit) */
534 #define PLX_REG_DMACSR(n) ((n) ? PLX_REG_DMACSR1 : PLX_REG_DMACSR0)
535 #define PLX_REG_DMACSR0 0x00a8
536 #define PLX_REG_DMACSR1 0x00a9
539 #define PLX_DMACSR_ENABLE BIT(0)
540 /* Channel Start - write 1 to start transfer (write-only) */
541 #define PLX_DMACSR_START BIT(1)
542 /* Channel Abort - write 1 to abort transfer (write-only) */
543 #define PLX_DMACSR_ABORT BIT(2)
544 /* Clear Interrupt - write 1 to clear DMA Channel Interrupt (write-only) */
545 #define PLX_DMACSR_CLEARINTR BIT(3)
546 /* Channel Done - transfer complete/inactive (read-only) */
547 #define PLX_DMACSR_DONE BIT(4)
549 /* DMA Threshold Register */
550 #define PLX_REG_DMATHR 0x00b0
553 * DMA Threshold constraints:
554 * (C0PLAF + 1) + (C0PLAE + 1) <= 32
555 * (C0LPAF + 1) + (C0LPAE + 1) <= 32
556 * (C1PLAF + 1) + (C1PLAE + 1) <= 16
557 * (C1LPAF + 1) + (C1LPAE + 1) <= 16
560 /* DMA Channel 0 PCI-to-Local Almost Full (divided by 2, minus 1) */
561 #define PLX_DMATHR_C0PLAF(x) (BIT(0) * ((x) & 0xf))
562 #define PLX_DMATHR_C0PLAF_MASK GENMASK(3, 0)
563 #define PLX_DMATHR_C0PLAF_SHIFT 0
564 /* DMA Channel 0 Local-to-PCI Almost Empty (divided by 2, minus 1) */
565 #define PLX_DMATHR_C0LPAE(x) (BIT(4) * ((x) & 0xf))
566 #define PLX_DMATHR_C0LPAE_MASK GENMASK(7, 4)
567 #define PLX_DMATHR_C0LPAE_SHIFT 4
568 /* DMA Channel 0 Local-to-PCI Almost Full (divided by 2, minus 1) */
569 #define PLX_DMATHR_C0LPAF(x) (BIT(8) * ((x) & 0xf))
570 #define PLX_DMATHR_C0LPAF_MASK GENMASK(11, 8)
571 #define PLX_DMATHR_C0LPAF_SHIFT 8
572 /* DMA Channel 0 PCI-to-Local Almost Empty (divided by 2, minus 1) */
573 #define PLX_DMATHR_C0PLAE(x) (BIT(12) * ((x) & 0xf))
574 #define PLX_DMATHR_C0PLAE_MASK GENMASK(15, 12)
575 #define PLX_DMATHR_C0PLAE_SHIFT 12
576 /* DMA Channel 1 PCI-to-Local Almost Full (divided by 2, minus 1) */
577 #define PLX_DMATHR_C1PLAF(x) (BIT(16) * ((x) & 0xf))
578 #define PLX_DMATHR_C1PLAF_MASK GENMASK(19, 16)
579 #define PLX_DMATHR_C1PLAF_SHIFT 16
580 /* DMA Channel 1 Local-to-PCI Almost Empty (divided by 2, minus 1) */
581 #define PLX_DMATHR_C1LPAE(x) (BIT(20) * ((x) & 0xf))
582 #define PLX_DMATHR_C1LPAE_MASK GENMASK(23, 20)
583 #define PLX_DMATHR_C1LPAE_SHIFT 20
584 /* DMA Channel 1 Local-to-PCI Almost Full (divided by 2, minus 1) */
585 #define PLX_DMATHR_C1LPAF(x) (BIT(24) * ((x) & 0xf))
586 #define PLX_DMATHR_C1LPAF_MASK GENMASK(27, 24)
587 #define PLX_DMATHR_C1LPAF_SHIFT 24
588 /* DMA Channel 1 PCI-to-Local Almost Empty (divided by 2, minus 1) */
589 #define PLX_DMATHR_C1PLAE(x) (BIT(28) * ((x) & 0xf))
590 #define PLX_DMATHR_C1PLAE_MASK GENMASK(31, 28)
591 #define PLX_DMATHR_C1PLAE_SHIFT 28
594 * Messaging Queue Registers OPLFIS, OPLFIM, IQP, OQP, MQCR, QBAR, IFHPR,
595 * IFTPR, IPHPR, IPTPR, OFHPR, OFTPR, OPHPR, OPTPR, and QSR have been omitted.
596 * They are used by the I2O feature. (IQP and OQP occupy the usual offsets of
597 * the MBOX0 and MBOX1 registers if the I2O feature is enabled, but MBOX0 and
598 * MBOX1 are accessible via alternative offsets.
601 /* Queue Status/Control Register */
602 #define PLX_REG_QSR 0x00e8
604 /* Value of QSR after reset - disables I2O feature completely. */
605 #define PLX_QSR_VALUE_AFTER_RESET 0x00000050
608 * Accesses near the end of memory can cause the PLX chip
609 * to pre-fetch data off of end-of-ram. Limit the size of
610 * memory so host-side accesses cannot occur.
613 #define PLX_PREFETCH 32
616 * plx9080_abort_dma - Abort a PLX PCI 9080 DMA transfer
617 * @iobase: Remapped base address of configuration registers.
618 * @channel: DMA channel number (0 or 1).
620 * Aborts the DMA transfer on the channel, which must have been enabled
621 * and started beforehand.
625 * -%ETIMEDOUT if timed out waiting for abort to complete.
627 static inline int plx9080_abort_dma(void __iomem *iobase, unsigned int channel)
629 void __iomem *dma_cs_addr;
631 const int timeout = 10000;
634 dma_cs_addr = iobase + PLX_REG_DMACSR(channel);
636 /* abort dma transfer if necessary */
637 dma_status = readb(dma_cs_addr);
638 if ((dma_status & PLX_DMACSR_ENABLE) == 0)
641 /* wait to make sure done bit is zero */
642 for (i = 0; (dma_status & PLX_DMACSR_DONE) && i < timeout; i++) {
644 dma_status = readb(dma_cs_addr);
649 /* disable and abort channel */
650 writeb(PLX_DMACSR_ABORT, dma_cs_addr);
651 /* wait for dma done bit */
652 dma_status = readb(dma_cs_addr);
653 for (i = 0; (dma_status & PLX_DMACSR_DONE) == 0 && i < timeout; i++) {
655 dma_status = readb(dma_cs_addr);
663 #endif /* __COMEDI_PLX9080_H */