1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 Madge Ambassador ATM Adapter driver.
4 Copyright (C) 1995-1999 Madge Networks Ltd.
12 #ifdef CONFIG_ATM_AMBASSADOR_DEBUG
13 #define DEBUG_AMBASSADOR
16 #define DEV_LABEL "amb"
18 #ifndef PCI_VENDOR_ID_MADGE
19 #define PCI_VENDOR_ID_MADGE 0x10B6
21 #ifndef PCI_VENDOR_ID_MADGE_AMBASSADOR
22 #define PCI_DEVICE_ID_MADGE_AMBASSADOR 0x1001
24 #ifndef PCI_VENDOR_ID_MADGE_AMBASSADOR_BAD
25 #define PCI_DEVICE_ID_MADGE_AMBASSADOR_BAD 0x1002
30 #define PRINTK(severity,format,args...) \
31 printk(severity DEV_LABEL ": " format "\n" , ## args)
33 #ifdef DEBUG_AMBASSADOR
35 #define DBG_ERR 0x0001
36 #define DBG_WARN 0x0002
37 #define DBG_INFO 0x0004
38 #define DBG_INIT 0x0008
39 #define DBG_LOAD 0x0010
40 #define DBG_VCC 0x0020
41 #define DBG_QOS 0x0040
42 #define DBG_CMD 0x0080
45 #define DBG_SKB 0x0400
46 #define DBG_POOL 0x0800
47 #define DBG_IRQ 0x1000
48 #define DBG_FLOW 0x2000
49 #define DBG_REGS 0x4000
50 #define DBG_DATA 0x8000
51 #define DBG_MASK 0xffff
53 /* the ## prevents the annoying double expansion of the macro arguments */
54 /* KERN_INFO is used since KERN_DEBUG often does not make it to the console */
55 #define PRINTDB(bits,format,args...) \
56 ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format , ## args) : 1 )
57 #define PRINTDM(bits,format,args...) \
58 ( (debug & (bits)) ? printk (format , ## args) : 1 )
59 #define PRINTDE(bits,format,args...) \
60 ( (debug & (bits)) ? printk (format "\n" , ## args) : 1 )
61 #define PRINTD(bits,format,args...) \
62 ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format "\n" , ## args) : 1 )
66 #define PRINTD(bits,format,args...)
67 #define PRINTDB(bits,format,args...)
68 #define PRINTDM(bits,format,args...)
69 #define PRINTDE(bits,format,args...)
73 #define PRINTDD(bits,format,args...)
74 #define PRINTDDB(sec,fmt,args...)
75 #define PRINTDDM(sec,fmt,args...)
76 #define PRINTDDE(sec,fmt,args...)
80 /* MUST be powers of two -- why ? */
81 #define COM_Q_ENTRIES 8
82 #define TX_Q_ENTRIES 32
83 #define RX_Q_ENTRIES 64
88 #define AMB_EXTENT 0x80
90 // Minimum allowed size for an Ambassador queue
91 #define MIN_QUEUE_SIZE 2
93 // Ambassador microcode allows 1 to 4 pools, we use 4 (simpler)
94 #define NUM_RX_POOLS 4
96 // minimum RX buffers required to cope with replenishing delay
97 #define MIN_RX_BUFFERS 1
99 // minimum PCI latency we will tolerate (32 IS TOO SMALL)
100 #define MIN_PCI_LATENCY 64 // 255
102 // VCs supported by card (VPI always 0)
103 #define NUM_VPI_BITS 0
104 #define NUM_VCI_BITS 10
107 /* The status field bits defined so far. */
108 #define RX_ERR 0x8000 // always present if there is an error (hmm)
109 #define CRC_ERR 0x4000 // AAL5 CRC error
110 #define LEN_ERR 0x2000 // overlength frame
111 #define ABORT_ERR 0x1000 // zero length field in received frame
112 #define UNUSED_ERR 0x0800 // buffer returned unused
116 #define SRB_OPEN_VC 0
117 /* par_0: dwordswap(VC_number) */
118 /* par_1: dwordswap(flags<<16) or wordswap(flags)*/
122 /* NOT_UBR: 0x0008 */
125 /* RxPool0: 0x0000 */
126 /* RxPool1: 0x0020 */
127 /* RxPool2: 0x0040 */
128 /* RxPool3: 0x0060 */
130 /* par_2: dwordswap(fp_rate<<16) or wordswap(fp_rate) */
132 #define SRB_CLOSE_VC 1
133 /* par_0: dwordswap(VC_number) */
135 #define SRB_GET_BIA 2
137 /* par_0: dwordswap(half BIA) */
138 /* par_1: dwordswap(half BIA) */
140 #define SRB_GET_SUNI_STATS 3
141 /* par_0: dwordswap(physical_host_address) */
143 #define SRB_SET_BITS_8 4
144 #define SRB_SET_BITS_16 5
145 #define SRB_SET_BITS_32 6
146 #define SRB_CLEAR_BITS_8 7
147 #define SRB_CLEAR_BITS_16 8
148 #define SRB_CLEAR_BITS_32 9
149 /* par_0: dwordswap(ATMizer address) */
150 /* par_1: dwordswap(mask) */
153 #define SRB_SET_16 11
154 #define SRB_SET_32 12
155 /* par_0: dwordswap(ATMizer address) */
156 /* par_1: dwordswap(data) */
158 #define SRB_GET_32 13
159 /* par_0: dwordswap(ATMizer address) */
161 /* par_1: dwordswap(ATMizer data) */
163 #define SRB_GET_VERSION 14
165 /* par_0: dwordswap(Major Version) */
166 /* par_1: dwordswap(Minor Version) */
168 #define SRB_FLUSH_BUFFER_Q 15
169 /* Only flags to define which buffer pool; all others must be zero */
170 /* par_0: dwordswap(flags<<16) or wordswap(flags)*/
172 #define SRB_GET_DMA_SPEEDS 16
174 /* par_0: dwordswap(Read speed (bytes/sec)) */
175 /* par_1: dwordswap(Write speed (bytes/sec)) */
177 #define SRB_MODIFY_VC_RATE 17
178 /* par_0: dwordswap(VC_number) */
179 /* par_1: dwordswap(fp_rate<<16) or wordswap(fp_rate) */
181 #define SRB_MODIFY_VC_FLAGS 18
182 /* par_0: dwordswap(VC_number) */
183 /* par_1: dwordswap(flags<<16) or wordswap(flags)*/
188 /* NOT_UBR: 0x0008 */
191 /* RxPool0: 0x0000 */
192 /* RxPool1: 0x0020 */
193 /* RxPool2: 0x0040 */
194 /* RxPool3: 0x0060 */
196 #define SRB_RATE_SHIFT 16
197 #define SRB_POOL_SHIFT (SRB_FLAGS_SHIFT+5)
198 #define SRB_FLAGS_SHIFT 16
200 #define SRB_STOP_TASKING 19
201 #define SRB_START_TASKING 20
202 #define SRB_SHUT_DOWN 21
205 #define SRB_COMPLETE 0xffffffff
207 #define TX_FRAME 0x80000000
209 // number of types of SRB MUST be a power of two -- why?
210 #define NUM_OF_SRB 32
212 // number of bits of period info for rate
213 #define MAX_RATE_BITS 6
215 #define TX_UBR 0x0000
216 #define TX_UBR_CAPPED 0x0008
217 #define TX_ABR 0x0018
218 #define TX_FRAME_NOTCAP 0x0000
219 #define TX_FRAME_CAPPED 0x8000
221 #define FP_155_RATE 0x24b1
222 #define FP_25_RATE 0x1f9d
224 /* #define VERSION_NUMBER 0x01000000 // initial release */
225 /* #define VERSION_NUMBER 0x01010000 // fixed startup probs PLX MB0 not cleared */
226 /* #define VERSION_NUMBER 0x01020000 // changed SUNI reset timings; allowed r/w onchip */
228 /* #define VERSION_NUMBER 0x01030000 // clear local doorbell int reg on reset */
229 /* #define VERSION_NUMBER 0x01040000 // PLX bug work around version PLUS */
230 /* remove race conditions on basic interface */
231 /* indicate to the host that diagnostics */
232 /* have finished; if failed, how and what */
234 /* fix host memory test to fix PLX bug */
235 /* allow flash upgrade and BIA upgrade directly */
237 #define VERSION_NUMBER 0x01050025 /* Jason's first hacked version. */
238 /* Change in download algorithm */
240 #define DMA_VALID 0xb728e149 /* completely random */
242 #define FLASH_BASE 0xa0c00000
243 #define FLASH_SIZE 0x00020000 /* 128K */
244 #define BIA_BASE (FLASH_BASE+0x0001c000) /* Flash Sector 7 */
245 #define BIA_ADDRESS ((void *)0xa0c1c000)
246 #define PLX_BASE 0xe0000000
249 host_memory_test
= 1,
251 write_adapter_memory
,
256 adap_download_block
= 0x20,
262 #define BAD_COMMAND (-1)
263 #define COMMAND_IN_PROGRESS 1
264 #define COMMAND_PASSED_TEST 2
265 #define COMMAND_FAILED_TEST 3
266 #define COMMAND_READ_DATA_OK 4
267 #define COMMAND_READ_BAD_ADDRESS 5
268 #define COMMAND_WRITE_DATA_OK 6
269 #define COMMAND_WRITE_BAD_ADDRESS 7
270 #define COMMAND_WRITE_FLASH_FAILURE 8
271 #define COMMAND_COMPLETE 9
272 #define COMMAND_FLASH_ERASE_FAILURE 10
273 #define COMMAND_WRITE_BAD_DATA 11
275 /* bit fields for mailbox[0] return values */
277 #define GPINT_TST_FAILURE 0x00000001
278 #define SUNI_DATA_PATTERN_FAILURE 0x00000002
279 #define SUNI_DATA_BITS_FAILURE 0x00000004
280 #define SUNI_UTOPIA_FAILURE 0x00000008
281 #define SUNI_FIFO_FAILURE 0x00000010
282 #define SRAM_FAILURE 0x00000020
283 #define SELF_TEST_FAILURE 0x0000003f
285 /* mailbox[1] = 0 in progress, -1 on completion */
286 /* mailbox[2] = current test 00 00 test(8 bit) phase(8 bit) */
287 /* mailbox[3] = last failure, 00 00 test(8 bit) phase(8 bit) */
288 /* mailbox[4],mailbox[5],mailbox[6] random failure values */
290 /* PLX/etc. memory map including command structure */
292 /* These registers may also be memory mapped in PCI memory */
294 #define UNUSED_LOADER_MAILBOXES 6
302 u32 stuff
[UNUSED_LOADER_MAILBOXES
];
307 u32 rx_address
[NUM_RX_POOLS
];
314 u32 interrupt_control
;
318 /* RESET bit, IRQ (card to host) and doorbell (host to card) enable bits */
319 #define AMB_RESET_BITS 0x40000000
320 #define AMB_INTERRUPT_BITS 0x00000300
321 #define AMB_DOORBELL_BITS 0x00030000
323 /* loader commands */
325 #define MAX_COMMAND_DATA 13
326 #define MAX_TRANSFER_DATA 11
331 __be32 data
[MAX_TRANSFER_DATA
];
338 transfer_block transfer
;
341 __be32 data
[MAX_COMMAND_DATA
];
348 /* Again all data are BIG ENDIAN */
395 /* transmit queues and associated structures */
397 /* The hosts transmit structure. All BIG ENDIAN; host address
398 restricted to first 1GByte, but address passed to the card must
399 have the top MS bit or'ed in. -- check this */
401 /* TX is described by 1+ tx_frags followed by a tx_frag_end */
408 /* apart from handle the fields here are for the adapter to play with
409 and should be set to zero */
414 u16 next_descriptor_length
;
416 #ifdef AMB_NEW_MICROCODE
425 tx_frag_end tx_frag_end
;
426 struct sk_buff
* skb
;
432 tx_frag_end end_of_list
;
436 /* this "points" to the sequence of fragments and trailer */
440 __be16 tx_descr_length
;
441 __be32 tx_descr_addr
;
444 /* handle is the handle from tx_in */
450 /* receive frame structure */
452 /* All BIG ENDIAN; handle is as passed from host; length is zero for
453 aborted frames, and frames with errors. Header is actually VC
454 number, lec-id is NOT yet supported. */
459 __be16 lec_id
; // unused
464 /* buffer supply structure */
471 /* This first structure is the area in host memory where the adapter
472 writes its pointer values. These pointer values are BIG ENDIAN and
473 reside in the same 4MB 'page' as this structure. The host gives the
474 adapter the address of this block by sending a doorbell interrupt
475 to the adapter after downloading the code and setting it going. The
476 addresses have the top 10 bits set to 1010000010b -- really?
478 The host must initialise these before handing the block to the
482 __be32 command_start
; /* SRB commands completions */
483 __be32 command_end
; /* SRB commands completions */
486 __be32 txcom_start
; /* tx completions */
487 __be32 txcom_end
; /* tx completions */
494 __be32 rx_start
; /* rx completions */
497 __be32 buffer_size
; /* size of host buffer */
498 } rec_struct
[NUM_RX_POOLS
];
499 #ifdef AMB_NEW_MICROCODE
501 u16 talk_block_spare
;
505 /* This structure must be kept in line with the vcr image in sarmain.h
507 This is the structure in the host filled in by the adapter by
525 #define NEXTQ(current,start,limit) \
526 ( (current)+1 < (limit) ? (current)+1 : (start) )
537 unsigned int pending
;
540 unsigned int maximum
; // size - 1 (q implementation)
546 unsigned int pending
;
549 unsigned int maximum
; // size - 1 (q implementation)
564 unsigned int pending
;
566 unsigned int emptied
;
567 unsigned int maximum
; // size - 1 (q implementation)
578 unsigned int buffers_wanted
;
579 unsigned int buffer_size
;
587 unsigned long badcrc
;
588 unsigned long toolong
;
589 unsigned long aborted
;
590 unsigned long unused
;
594 // a single struct pointed to by atm_vcc->dev_data
608 unsigned int tx_rate
;
609 unsigned int rx_rate
;
620 amb_rxq rxq
[NUM_RX_POOLS
];
623 amb_tx_info txer
[NUM_VCS
];
624 struct atm_vcc
* rxer
[NUM_VCS
];
625 unsigned int tx_avail
;
626 unsigned int rx_avail
;
630 struct atm_dev
* atm_dev
;
631 struct pci_dev
* pci_dev
;
632 struct timer_list housekeeping
;
635 typedef struct amb_dev amb_dev
;
637 #define AMB_DEV(atm_dev) ((amb_dev *) (atm_dev)->dev_data)
638 #define AMB_VCC(atm_vcc) ((amb_vcc *) (atm_vcc)->dev_data)