Debian Codegraph @

common/dev_pa_a1.c

raw
1 /*
2 * Cisco router simulation platform.
3 * Copyright (C) 2005,2006 Christophe Fillot. All rights reserved.
4 *
5 * PA-A1 ATM interface based on TI1570 and PLX 9060-ES.
6 *
7 * EEPROM types:
8 * - 0x17: PA-A1-OC3MM
9 * - 0x2C: PA-A1-OC3SM
10 * - 0x2D: PA-A1-OC3UTP
11 *
12 * IOS command: "sh controller atm2/0"
13 *
14 * Manuals:
15 *
16 * Texas Instruments TNETA1570 ATM segmentation and reassembly device
17 * with integrated 64-bit PCI-host interface
18 * http://focus.ti.com/docs/prod/folders/print/tneta1570.html
19 *
20 * PLX 9060-ES
21 * http://www.plxtech.com/products/io_accelerators/PCI9060/default.htm
22 *
23 * TODO:
24 * - RX error handling and RX AAL5-related stuff
25 * - HEC and AAL5 CRC fields.
26 *
27 * Cell trains for faster NETIO communications ?
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34 #include <errno.h>
35
36 #include "crc.h"
37 #include "atm.h"
38 #include "cpu.h"
39 #include "vm.h"
40 #include "dynamips.h"
41 #include "memory.h"
42 #include "device.h"
43 #include "ptask.h"
44 #include "dev_c7200.h"
45
46 /* Debugging flags */
47 #define DEBUG_ACCESS 0
48 #define DEBUG_UNKNOWN 0
49 #define DEBUG_TRANSMIT 0
50 #define DEBUG_RECEIVE 0
51 #define DEBUG_TX_DMA 0
52
53 /* PCI vendor/product codes */
54 #define TI1570_PCI_VENDOR_ID 0x104c
55 #define TI1570_PCI_PRODUCT_ID 0xa001
56
57 #define PLX_9060ES_PCI_VENDOR_ID 0x10b5
58 #define PLX_9060ES_PCI_PRODUCT_ID 0x906e
59
60 /* Number of buffers transmitted at each TX DMA ring scan pass */
61 #define TI1570_TXDMA_PASS_COUNT 16
62
63 /* TI1570 Internal Registers (p.58 of doc) */
64 #define TI1570_REG_CONFIG 0x0000 /* Configuration registers */
65 #define TI1570_REG_STATUS 0x0001 /* Status register */
66 #define TI1570_REG_IMASK 0x0002 /* Interrupt-mask register */
67 #define TI1570_REG_RGT_RAT 0x0003 /* RGT + RAT cycle-counter */
68 #define TI1570_REG_RX_UNKNOWN 0x0004 /* RX Unknown Register */
69 #define TI1570_REG_TX_CRING_SIZE 0x0005 /* TX Completion ring sizes */
70 #define TI1570_REG_RX_CRING_SIZE 0x0006 /* RX Completion ring sizes */
71 #define TI1570_REG_TX_PSR_SIZE 0x0007 /* TX Pkt-seg ring size + FIFO */
72 #define TI1570_REG_HEC_AAL5_DISC 0x0008 /* HEC err + AAL5 CPCS discard */
73 #define TI1570_REG_UNK_PROTO_CNT 0x0009 /* Unknown-protocols counter */
74 #define TI1570_REG_RX_ATM_COUNT 0x000A /* ATM-cells-received counter */
75 #define TI1570_REG_TX_ATM_COUNT 0x000B /* ATM-cells-tranmitted counter */
76 #define TI1570_REG_TX_RX_FIFO 0x000C /* TX/RX FIFO occupancy, VCI mask */
77 #define TI1570_REG_SCHED_SIZE 0x000D /* Scheduler Table size */
78 #define TI1570_REG_SOFT_RESET 0x000E /* Software Reset */
79 #define TI1570_REG_TCR_WOI_ADDR 0x0080 /* TX Compl. Ring w/o IRQ addr. */
80 #define TI1570_REG_TCR_WI_ADDR 0x0081 /* TX Compl. Ring w/ IRQ addr. */
81 #define TI1570_REG_RCR_WOI_ADDR 0x0082 /* RX Compl. Ring w/o IRQ addr. */
82 #define TI1570_REG_RCR_WI_ADDR 0x0083 /* RX Compl. Ring w/ IRQ addr. */
83
84 /* TI1570 configuration register (p.59) */
85 #define TI1570_CFG_EN_RAT 0x00000001 /* Reassembly Aging */
86 #define TI1570_CFG_BP_SEL 0x00000002 /* IRQ on packet or buffer */
87 #define TI1570_CFG_EN_RX 0x00000010 /* RX enable */
88 #define TI1570_CFG_EN_TX 0x00000020 /* TX enable */
89 #define TI1570_CFG_SMALL_MAP 0x00000040 /* Small map */
90
91 /* TI1570 status register (p.61) */
92 #define TI1570_STAT_CP_TX 0x00000001 /* Transmit completion ring */
93 #define TI1570_STAT_RX_IRR 0x00000040 /* Receive unknown reg set */
94 #define TI1570_STAT_CP_RX 0x00000080 /* Receive completion ring */
95 #define TI1570_STAT_TX_FRZ 0x00000100 /* TX Freeze */
96 #define TI1570_STAT_RX_FRZ 0x00000200 /* RX Freeze */
97
98 /* Mask for RX/TX completion-ring sizes */
99 #define TI1570_TCR_SIZE_MASK 0x00001FFF /* TX compl. ring size mask */
100 #define TI1570_RCR_SIZE_MASK 0x000003FF /* RX compl. ring size mask */
101
102 /* TI1750 TX packet segmentation ring register */
103 #define TI1570_PSR_SIZE_MASK 0x000000FF /* pkt-seg ring size */
104
105 /* Total size of the TI1570 Control Memory */
106 #define TI1570_CTRL_MEM_SIZE 0x100000
107
108 /* Offsets of the TI1570 structures (p.66) */
109 #define TI1570_TX_SCHED_OFFSET 0x0000 /* TX scheduler table */
110 #define TI1570_INTERNAL_REGS_OFFSET 0x3200 /* Internal Registers */
111 #define TI1570_FREE_BUFFERS_OFFSET 0x3800 /* Free-Buffer Pointers */
112 #define TI1570_RX_DMA_PTR_TABLE_OFFSET 0x4000 /* RX VPI/VCI pointer table */
113 #define TI1570_TX_DMA_TABLE_OFFSET 0x8000 /* TX DMA state table */
114 #define TI1570_RX_DMA_TABLE_OFFSET 0x10000 /* RX DMA state table */
115
116 /* TX scheduler table */
117 #define TI1570_TX_SCHED_ENTRY_COUNT 6200
118 #define TI1570_TX_SCHED_ENTRY_MASK 0x3FF /* Entry mask */
119 #define TI1570_TX_SCHED_E0_SHIFT 0 /* Shift for entry 0 */
120 #define TI1570_TX_SCHED_E1_SHIFT 16 /* Shift for entry 0 */
121
122 /* TX DMA state table */
123 #define TI1570_TX_DMA_ACT 0x80000000 /* ACTive (word 0) */
124 #define TI1570_TX_DMA_SOP 0x40000000 /* Start of Packet (SOP) */
125 #define TI1570_TX_DMA_EOP 0x20000000 /* End of Packet (EOP) */
126 #define TI1570_TX_DMA_ABORT 0x10000000 /* Abort */
127 #define TI1570_TX_DMA_TCR_SELECT 0x02000000 /* TX comp. ring selection */
128 #define TI1570_TX_DMA_AAL_TYPE_MASK 0x0C000000 /* AAL-type mask */
129
130 #define TI1570_TX_DMA_AAL_TRWPTI 0x00000000 /* Transp. AAL w/ PTI set */
131 #define TI1570_TX_DMA_AAL_AAL5 0x04000000 /* AAL5 */
132 #define TI1570_TX_DMA_AAL_TRWOPTI 0x08000000 /* Transp. AAL w/o PTI set */
133
134 #define TI1570_TX_DMA_OFFSET_MASK 0x00FF0000
135 #define TI1570_TX_DMA_OFFSET_SHIFT 16
136 #define TI1570_TX_DMA_DCOUNT_MASK 0x0000FFFF
137
138 #define TI1570_TX_DMA_ON 0x80000000 /* DMA state (word 3) */
139 #define TI1570_TX_DMA_RING_OFFSET_MASK 0x3FFFFF00
140 #define TI1570_TX_DMA_RING_OFFSET_SHIFT 8
141 #define TI1570_TX_DMA_RING_INDEX_MASK 0x000000FF
142
143 #define TI1570_TX_DMA_RING_AAL5_LEN_MASK 0x0000FFFF
144
145 typedef struct ti1570_tx_dma_entry ti1570_tx_dma_entry_t;
146 struct ti1570_tx_dma_entry {
147 m_uint32_t ctrl_buf; /* Ctrl, Buffer Offset, Buffer data-byte count */
148 m_uint32_t cb_addr; /* Current Buffer Address */
149 m_uint32_t atm_hdr; /* 4-byte ATM header */
150 m_uint32_t dma_state; /* DMA state + Packet segmentation ring address */
151 m_uint32_t nb_addr; /* Next Buffer address */
152 m_uint32_t sb_addr; /* Start of Buffer address */
153 m_uint32_t aal5_crc; /* Partial AAL5-transmit CRC */
154 m_uint32_t aal5_ctrl; /* AAL5-control field and length field */
155 };
156
157 /* TX Packet-Segmentation Rings */
158 #define TI1570_TX_RING_OWN 0x80000000 /* If set, packet is ready */
159 #define TI1570_TX_RING_PTR_MASK 0x3FFFFFFF /* Buffer pointer */
160
161 /* TX Data Buffers */
162 #define TI1570_TX_BUFFER_RDY 0x80000000 /* If set, buffer is ready */
163 #define TI1570_TX_BUFFER_SOP 0x40000000 /* First buffer of packet */
164 #define TI1570_TX_BUFFER_EOP 0x20000000 /* Last buffer of packet */
165 #define TI1570_TX_BUFFER_ABORT 0x10000000 /* Abort */
166
167 #define TI1570_TX_BUFFER_OFFSET_MASK 0x00FF0000
168 #define TI1570_TX_BUFFER_OFFSET_SHIFT 16
169 #define TI1570_TX_BUFFER_DCOUNT_MASK 0x0000FFFF
170
171 typedef struct ti1570_tx_buffer ti1570_tx_buffer_t;
172 struct ti1570_tx_buffer {
173 m_uint32_t ctrl_buf; /* Ctrl, Buffer offset, Buffer data-byte count */
174 m_uint32_t nb_addr; /* Start-of-next buffer pointer */
175 m_uint32_t atm_hdr; /* 4-byte ATM header */
176 m_uint32_t aal5_ctrl; /* PCS-UU/CPI field (AAL5 control field) */
177 };
178
179 /* TX completion-ring */
180 #define TI1570_TCR_OWN 0x80000000 /* OWNner bit */
181 #define TI1570_TCR_ABORT 0x40000000 /* Abort */
182
183 /* RX VPI/VCI DMA pointer table */
184 #define TI1570_RX_VPI_ENABLE 0x80000000 /* VPI enabled ? */
185 #define TI1570_RX_BASE_PTR_MASK 0x7FFF0000 /* Base pointer mask */
186 #define TI1570_RX_BASE_PTR_SHIFT 16 /* Base pointer shift */
187 #define TI1570_RX_VCI_RANGE_MASK 0x0000FFFF /* Valid VCI range */
188
189 /* RX DMA state table (p.36) */
190 #define TI1570_RX_DMA_ACT 0x80000000 /* ACTive (word 0) */
191 #define TI1570_RX_DMA_RCR_SELECT 0x20000000 /* RX comp. ring selection */
192 #define TI1570_RX_DMA_WAIT_EOP 0x10000000 /* Wait for EOP */
193 #define TI1570_RX_DMA_AAL_TYPE_MASK 0x0C000000 /* AAL-type mask */
194
195 #define TI1570_RX_DMA_AAL_PTI 0x00000000 /* PTI based tr. AAL pkt */
196 #define TI1570_RX_DMA_AAL_AAL5 0x04000000 /* AAL5 */
197 #define TI1570_RX_DMA_AAL_CNT 0x08000000 /* Cnt based tr. AAL pkt */
198
199 #define TI1570_RX_DMA_FIFO 0x02000000 /* FIFO used for free bufs */
200
201 #define TI1570_RX_DMA_TR_CNT_MASK 0xFFFF0000 /* Cnt-based Tr-AAL */
202 #define TI1570_RX_DMA_TR_CNT_SHIFT 16
203 #define TI1570_RX_DMA_CB_LEN_MASK 0x0000FFFF /* Current buffer length */
204
205 #define TI1570_RX_DMA_ON 0x80000000 /* DMA state (word 6) */
206 #define TI1570_RX_DMA_FILTER 0x40000000 /* Filter */
207
208 #define TI1570_RX_DMA_FB_PTR_MASK 0x3FFFFFFF /* Free-buffer ptr mask */
209 #define TI1570_RX_DMA_FB_INDEX_MASK 0x000000FF /* Index with Free-buf ring */
210
211 typedef struct ti1570_rx_dma_entry ti1570_rx_dma_entry_t;
212 struct ti1570_rx_dma_entry {
213 m_uint32_t ctrl; /* Control field, EFCN cell cnt, pkt length */
214 m_uint32_t cb_addr; /* Current Buffer Address */
215 m_uint32_t sb_addr; /* Start of Buffer address */
216 m_uint32_t cb_len; /* Transp-AAL pkt counter, current buf length */
217 m_uint32_t sp_ptr; /* Start-of-packet pointer */
218 m_uint32_t aal5_crc; /* Partial AAL5-receive CRC */
219 m_uint32_t fbr_entry; /* Free-buffer ring-pointer table entry */
220 m_uint32_t timeout; /* Timeout value, current timeout count */
221 };
222
223 /* RX free-buffer ring pointer table entry (p.39) */
224 #define TI1570_RX_FBR_PTR_MASK 0xFFFFFFFC
225 #define TI1570_RX_FBR_BS_MASK 0xFFFF0000 /* Buffer size mask */
226 #define TI1570_RX_FBR_BS_SHIFT 16
227 #define TI1570_RX_FBR_RS_MASK 0x0000FC00 /* Ring size mask */
228 #define TI1570_RX_FBR_RS_SHIFT 10
229 #define TI1570_RX_FBR_IDX_MASK 0x000003FF /* Current index mask */
230
231 typedef struct ti1570_rx_fbr_entry ti1570_rx_fbr_entry_t;
232 struct ti1570_rx_fbr_entry {
233 m_uint32_t fbr_ptr; /* RX free-buffer ring pointer */
234 m_uint32_t ring_size; /* Ring size and buffer size */
235 };
236
237 /* RX buffer pointer (p.41) */
238 #define TI1570_RX_BUFPTR_OWN 0x80000000 /* If set, buffer is ready */
239 #define TI1570_RX_BUFPTR_MASK 0x3FFFFFFF /* Buffer address mask */
240
241 /* RX data buffer (p.42) */
242 #define TI1570_RX_BUFFER_SOP 0x80000000 /* Start-of-Packet buffer */
243 #define TI1570_RX_BUFFER_EOP 0x40000000 /* End-of-Packet buffer */
244
245 typedef struct ti1570_rx_buffer ti1570_rx_buffer_t;
246 struct ti1570_rx_buffer {
247 m_uint32_t reserved; /* Reserved, not used by the TI1570 */
248 m_uint32_t ctrl; /* Control field, Start of next buffer pointer */
249 m_uint32_t atm_hdr; /* ATM header */
250 m_uint32_t user; /* User-defined value */
251 };
252
253 /* Internal structure to hold free buffer info */
254 typedef struct ti1570_rx_buf_holder ti1570_rx_buf_holder_t;
255 struct ti1570_rx_buf_holder {
256 m_uint32_t buf_addr;
257 m_uint32_t buf_size;
258 ti1570_rx_buffer_t rx_buf;
259 };
260
261 /* RX completion ring entry */
262 #define TI1570_RCR_PKT_OVFLW 0x80000000 /* Packet overflow (word 0) */
263 #define TI1570_RCR_CRC_ERROR 0x40000000 /* CRC error */
264 #define TI1570_RCR_BUF_STARV 0x20000000 /* Buffer starvation */
265 #define TI1570_RCR_TIMEOUT 0x10000000 /* Reassembly timeout */
266 #define TI1570_RCR_ABORT 0x08000000 /* Abort condition */
267 #define TI1570_RCR_AAL5 0x04000000 /* AAL5 indicator */
268
269 #define TI1570_RCR_VALID 0x80000000 /* Start-ptr valid (word 2) */
270
271 #define TI1570_RCR_OWN 0x80000000 /* Buffer ready (word 4) */
272 #define TI1570_RCR_ERROR 0x40000000 /* Error entry */
273
274 typedef struct ti1570_rcr_entry ti1570_rcr_entry_t;
275 struct ti1570_rcr_entry {
276 m_uint32_t atm_hdr; /* ATM header */
277 m_uint32_t error; /* Error Indicator + Congestion cell count */
278 m_uint32_t sp_addr; /* Start of packet */
279 m_uint32_t aal5_trailer; /* AAL5 trailer */
280 m_uint32_t fbr_entry; /* Free-buffer ring-pointer table entry */
281 m_uint32_t res[3]; /* Reserved, not used by the TI1570 */
282 };
283
284 /* TI1570 Data */
285 struct pa_a1_data {
286 char *name;
287
288 /* IRQ clearing counter */
289 u_int irq_clear_count;
290
291 /* Control Memory pointer */
292 m_uint32_t *ctrl_mem_ptr;
293
294 /* TI1570 internal registers */
295 m_uint32_t *iregs;
296
297 /* TX FIFO cell */
298 m_uint8_t txfifo_cell[ATM_CELL_SIZE];
299 m_uint32_t txfifo_avail,txfifo_pos;
300
301 /* TX Scheduler table */
302 m_uint32_t *tx_sched_table;
303
304 /* TX DMA state table */
305 ti1570_tx_dma_entry_t *tx_dma_table;
306
307 /* TX/RX completion ring current position */
308 m_uint32_t tcr_wi_pos,tcr_woi_pos;
309 m_uint32_t rcr_wi_pos,rcr_woi_pos;
310
311 /* RX VPI/VCI DMA pointer table */
312 m_uint32_t *rx_vpi_vci_dma_table;
313
314 /* RX DMA state table */
315 ti1570_rx_dma_entry_t *rx_dma_table;
316
317 /* RX Free-buffer ring pointer table */
318 ti1570_rx_fbr_entry_t *rx_fbr_table;
319
320 /* Virtual device */
321 struct vdevice *dev;
322
323 /* PCI device information */
324 struct pci_device *pci_dev_ti,*pci_dev_plx;
325
326 /* Virtual machine */
327 vm_instance_t *vm;
328
329 /* NetIO descriptor */
330 netio_desc_t *nio;
331
332 /* TX ring scanner task id */
333 ptask_id_t tx_tid;
334 };
335
336 /* Log a TI1570 message */
337 #define TI1570_LOG(d,msg...) vm_log((d)->vm,(d)->name,msg)
338
339 /* Reset the TI1570 (forward declaration) */
340 static void ti1570_reset(struct pa_a1_data *d,int clear_ctrl_mem);
341
342 /* Update the interrupt status */
343 static inline void dev_pa_a1_update_irq_status(struct pa_a1_data *d)
344 {
345 if (d->iregs[TI1570_REG_STATUS] & d->iregs[TI1570_REG_IMASK]) {
346 pci_dev_trigger_irq(d->vm,d->pci_dev_ti);
347 } else {
348 pci_dev_clear_irq(d->vm,d->pci_dev_ti);
349 }
350 }
351
352 /*
353 * dev_pa_a1_access()
354 */
355 void *dev_pa_a1_access(cpu_gen_t *cpu,struct vdevice *dev,m_uint32_t offset,
356 u_int op_size,u_int op_type,m_uint64_t *data)
357 {
358 struct pa_a1_data *d = dev->priv_data;
359
360 if (op_type == MTS_READ)
361 *data = 0;
362
363 #if DEBUG_ACCESS
364 if (op_type == MTS_READ) {
365 cpu_log(cpu,"TI1570","read access to offset = 0x%x, pc = 0x%llx\n",
366 offset,cpu_get_pc(cpu));
367 } else {
368 cpu_log(cpu,"TI1570","write access to vaddr = 0x%x, pc = 0x%llx, "
369 "val = 0x%llx\n",offset,cpu_get_pc(cpu),*data);
370 }
371 #endif
372
373 /* Specific cases */
374 switch(offset) {
375 /* Status register */
376 case 0x3204:
377 if (op_type == MTS_READ) {
378 *data = d->iregs[TI1570_REG_STATUS];
379
380 if (++d->irq_clear_count == 5) {
381 d->iregs[TI1570_REG_STATUS] &= ~0x3FF;
382 d->irq_clear_count = 0;
383 }
384
385 dev_pa_a1_update_irq_status(d);
386 }
387 break;
388
389 /* Software Reset register */
390 case 0x3238:
391 TI1570_LOG(d,"reset issued.\n");
392 ti1570_reset(d,FALSE);
393 break;
394
395 case 0x18000c:
396 if (op_type == MTS_READ) {
397 *data = 0xa6;
398 return NULL;
399 }
400 break;
401 }
402
403 /* Control Memory access */
404 if (offset < TI1570_CTRL_MEM_SIZE) {
405 if (op_type == MTS_READ)
406 *data = d->ctrl_mem_ptr[offset >> 2];
407 else
408 d->ctrl_mem_ptr[offset >> 2] = *data;
409 return NULL;
410 }
411
412 /* Unknown offset */
413 #if DEBUG_UNKNOWN
414 if (op_type == MTS_READ) {
415 cpu_log(cpu,d->name,"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n",
416 offset,cpu_get_pc(cpu),op_size);
417 } else {
418 cpu_log(cpu,d->name,"write to unknown addr 0x%x, value=0x%llx, "
419 "pc=0x%llx (size=%u)\n",offset,*data,cpu_get_pc(cpu),op_size);
420 }
421 #endif
422 return NULL;
423 }
424
425 /* Fetch a TX data buffer from host memory */
426 static void ti1570_read_tx_buffer(struct pa_a1_data *d,m_uint32_t addr,
427 ti1570_tx_buffer_t *tx_buf)
428 {
429 physmem_copy_from_vm(d->vm,tx_buf,addr,sizeof(ti1570_tx_buffer_t));
430
431 /* byte-swapping */
432 tx_buf->ctrl_buf = vmtoh32(tx_buf->ctrl_buf);
433 tx_buf->nb_addr = vmtoh32(tx_buf->nb_addr);
434 tx_buf->atm_hdr = vmtoh32(tx_buf->atm_hdr);
435 tx_buf->aal5_ctrl = vmtoh32(tx_buf->aal5_ctrl);
436 }
437
438 /* Acquire a TX buffer */
439 static int ti1570_acquire_tx_buffer(struct pa_a1_data *d,
440 ti1570_tx_dma_entry_t *tde,
441 m_uint32_t buf_addr)
442 {
443 ti1570_tx_buffer_t tx_buf;
444 m_uint32_t buf_offset;
445
446 #if DEBUG_TRANSMIT
447 TI1570_LOG(d,"ti1570_acquire_tx_buffer: acquiring buffer at address 0x%x\n",
448 buf_addr);
449 #endif
450
451 /* Read the TX buffer from host memory */
452 ti1570_read_tx_buffer(d,buf_addr,&tx_buf);
453
454 /* The buffer must be ready to be acquired */
455 if (!(tx_buf.ctrl_buf & TI1570_TX_BUFFER_RDY))
456 return(FALSE);
457
458 /* Put the TX buffer data into the TX DMA state entry */
459 tde->ctrl_buf = tx_buf.ctrl_buf;
460 tde->nb_addr = tx_buf.nb_addr << 2;
461
462 /* Read the ATM header only from the first buffer */
463 if (tx_buf.ctrl_buf & TI1570_TX_BUFFER_SOP) {
464 tde->atm_hdr = tx_buf.atm_hdr;
465 tde->aal5_ctrl = tx_buf.aal5_ctrl;
466 tde->aal5_crc = 0; /* will be inverted at first CRC update */
467 }
468
469 /* Compute the current-buffer-data address */
470 buf_offset = tx_buf.ctrl_buf & TI1570_TX_BUFFER_OFFSET_MASK;
471 buf_offset >>= TI1570_TX_BUFFER_OFFSET_SHIFT;
472 tde->cb_addr = buf_addr + sizeof(tx_buf) + buf_offset;
473
474 /* Remember the start address of the buffer */
475 tde->sb_addr = buf_addr;
476 return(TRUE);
477 }
478
479 /* Returns TRUE if the TX DMA entry is for an AAL5 packet */
480 static inline int ti1570_is_tde_aal5(ti1570_tx_dma_entry_t *tde)
481 {
482 m_uint32_t pkt_type;
483
484 pkt_type = tde->ctrl_buf & TI1570_TX_DMA_AAL_TYPE_MASK;
485 return(pkt_type == TI1570_TX_DMA_AAL_AAL5);
486 }
487
488 /* Update the AAL5 partial CRC */
489 static void ti1570_update_aal5_crc(struct pa_a1_data *d,
490 ti1570_tx_dma_entry_t *tde)
491 {
492 tde->aal5_crc = crc32_compute(~tde->aal5_crc,
493 &d->txfifo_cell[ATM_HDR_SIZE],
494 ATM_PAYLOAD_SIZE);
495 }
496
497 /*
498 * Update the TX DMA entry buffer offset and count when "data_len" bytes
499 * have been transmitted.
500 */
501 static void ti1570_update_tx_dma_bufinfo(ti1570_tx_dma_entry_t *tde,
502 m_uint32_t buf_size,
503 m_uint32_t data_len)
504 {
505 m_uint32_t tmp,tot_len;
506
507 /* update the current buffer address */
508 tde->cb_addr += data_len;
509
510 /* set the remaining byte count */
511 tmp = tde->ctrl_buf & ~TI1570_TX_BUFFER_DCOUNT_MASK;
512 tde->ctrl_buf = tmp + (buf_size - data_len);
513
514 /* update the AAL5 count */
515 if (ti1570_is_tde_aal5(tde)) {
516 tot_len = tde->aal5_ctrl & TI1570_TX_DMA_RING_AAL5_LEN_MASK;
517 tot_len += data_len;
518
519 tmp = (tde->aal5_ctrl & ~TI1570_TX_DMA_RING_AAL5_LEN_MASK) + tot_len;
520 tde->aal5_ctrl = tmp;
521 }
522 }
523
524 /* Clear the TX fifo */
525 static void ti1570_clear_tx_fifo(struct pa_a1_data *d)
526 {
527 d->txfifo_avail = ATM_PAYLOAD_SIZE;
528 d->txfifo_pos = ATM_HDR_SIZE;
529 memset(d->txfifo_cell,0,ATM_CELL_SIZE);
530 }
531
532 /*
533 * Transmit the TX FIFO cell through the NETIO infrastructure if
534 * it is full.
535 */
536 static void ti1570_send_tx_fifo(struct pa_a1_data *d,
537 ti1570_tx_dma_entry_t *tde,
538 int update_aal5_crc)
539 {
540 if (d->txfifo_avail == 0) {
541 #if DEBUG_TRANSMIT
542 TI1570_LOG(d,"ti1570_transmit_cell: transmitting to NETIO device\n");
543 mem_dump(log_file,d->txfifo_cell,ATM_CELL_SIZE);
544 #endif
545 if (update_aal5_crc)
546 ti1570_update_aal5_crc(d,tde);
547
548 netio_send(d->nio,d->txfifo_cell,ATM_CELL_SIZE);
549 ti1570_clear_tx_fifo(d);
550 }
551 }
552
553 /* Add padding to the FIFO */
554 static void ti1570_add_tx_padding(struct pa_a1_data *d,m_uint32_t len)
555 {
556 if (len > d->txfifo_avail) {
557 TI1570_LOG(d,"ti1570_add_tx_padding: trying to add too large "
558 "padding (avail: 0x%x, pad: 0x%x)\n",d->txfifo_avail,len);
559 len = d->txfifo_avail;
560 }
561
562 memset(&d->txfifo_cell[d->txfifo_pos],0,len);
563 d->txfifo_pos += len;
564 d->txfifo_avail -= len;
565 }
566
567 /* Initialize an ATM cell for tranmitting */
568 static m_uint32_t ti1570_init_tx_atm_cell(struct pa_a1_data *d,
569 ti1570_tx_dma_entry_t *tde,
570 int set_pti)
571 {
572 m_uint32_t buf_size,len,atm_hdr;
573
574 buf_size = tde->ctrl_buf & TI1570_TX_DMA_DCOUNT_MASK;
575 len = m_min(buf_size,d->txfifo_avail);
576
577 #if DEBUG_TRANSMIT
578 TI1570_LOG(d,"ti1570_init_tx_atm_cell: data ptr=0x%x, "
579 "buf_size=%u (0x%x), len=%u (0x%x), atm_hdr=0x%x\n",
580 tde->cb_addr,buf_size,buf_size,len,len,tde->atm_hdr);
581 #endif
582
583 /* copy the ATM header */
584 atm_hdr = tde->atm_hdr;
585
586 if (set_pti) {
587 atm_hdr &= ~ATM_PTI_NETWORK;
588 atm_hdr |= ATM_PTI_EOP;
589 }
590
591 atm_hdr = htonl(atm_hdr);
592 memcpy(&d->txfifo_cell[0],&atm_hdr,sizeof(atm_hdr));
593
594 /* compute HEC field */
595 atm_insert_hec(d->txfifo_cell);
596
597 /* copy the payload and try to transmit if the FIFO is full */
598 if (len > 0) {
599 physmem_copy_from_vm(d->vm,&d->txfifo_cell[d->txfifo_pos],
600 tde->cb_addr,len);
601 d->txfifo_pos += len;
602 d->txfifo_avail -= len;
603 }
604
605 ti1570_update_tx_dma_bufinfo(tde,buf_size,len);
606 return(len);
607 }
608
609 /*
610 * Transmit an Transparent-AAL ATM cell through the NETIO infrastructure.
611 */
612 static int ti1570_transmit_transp_cell(struct pa_a1_data *d,
613 ti1570_tx_dma_entry_t *tde,
614 int atm_set_eop,int *buf_end)
615 {
616 m_uint32_t buf_size,len;
617 int pkt_end,last_cell;
618
619 pkt_end = tde->ctrl_buf & TI1570_TX_DMA_EOP;
620 buf_size = tde->ctrl_buf & TI1570_TX_DMA_DCOUNT_MASK;
621 last_cell = FALSE;
622
623 if (!pkt_end) {
624 len = ti1570_init_tx_atm_cell(d,tde,FALSE);
625 ti1570_send_tx_fifo(d,tde,FALSE);
626
627 if ((buf_size - len) == 0)
628 *buf_end = TRUE;
629
630 return(FALSE);
631 }
632
633 /* this is the end of packet and the last buffer */
634 if (buf_size <= d->txfifo_avail)
635 last_cell = TRUE;
636
637 len = ti1570_init_tx_atm_cell(d,tde,last_cell & atm_set_eop);
638 if (last_cell) ti1570_add_tx_padding(d,d->txfifo_avail);
639 ti1570_send_tx_fifo(d,tde,FALSE);
640 return(last_cell);
641 }
642
643 /* Add the AAL5 trailer to the TX FIFO */
644 static void ti1570_add_aal5_trailer(struct pa_a1_data *d,
645 ti1570_tx_dma_entry_t *tde)
646 {
647 m_uint8_t *trailer;
648
649 trailer = &d->txfifo_cell[ATM_AAL5_TRAILER_POS];
650
651 /* Control field + Length */
652 *(m_uint32_t *)trailer = htonl(tde->aal5_ctrl);
653
654 /* Final CRC-32 computation */
655 tde->aal5_crc = crc32_compute(~tde->aal5_crc,
656 &d->txfifo_cell[ATM_HDR_SIZE],
657 ATM_PAYLOAD_SIZE - 4);
658
659 *(m_uint32_t *)(trailer+4) = htonl(~tde->aal5_crc);
660
661 /* Consider the FIFO as full */
662 d->txfifo_avail = 0;
663 }
664
665 /*
666 * Tranmit an AAL5 cell through the NETIO infrastructure.
667 *
668 * Returns TRUE if this is the real end of packet.
669 */
670 static int ti1570_transmit_aal5_cell(struct pa_a1_data *d,
671 ti1570_tx_dma_entry_t *tde,
672 int *buf_end)
673 {
674 m_uint32_t buf_size,len;
675 int pkt_end;
676
677 pkt_end = tde->ctrl_buf & TI1570_TX_DMA_EOP;
678 buf_size = tde->ctrl_buf & TI1570_TX_DMA_DCOUNT_MASK;
679
680 #if DEBUG_TRANSMIT
681 TI1570_LOG(d,"ti1570_transmit_aal5_cell: data ptr=0x%x, "
682 "buf_size=0x%x (%u)\n",tde->cb_addr,buf_size,buf_size);
683 #endif
684
685 /* If this is not the end of packet, transmit the cell normally */
686 if (!pkt_end) {
687 len = ti1570_init_tx_atm_cell(d,tde,FALSE);
688 ti1570_send_tx_fifo(d,tde,TRUE);
689
690 if ((buf_size - len) == 0)
691 *buf_end = TRUE;
692
693 return(FALSE);
694 }
695
696 /*
697 * This is the end of packet, check if we need to emit a special cell
698 * for the AAL5 trailer.
699 */
700 if ((buf_size + ATM_AAL5_TRAILER_SIZE) <= d->txfifo_avail) {
701 len = ti1570_init_tx_atm_cell(d,tde,TRUE);
702
703 /* add the padding */
704 ti1570_add_tx_padding(d,d->txfifo_avail - ATM_AAL5_TRAILER_SIZE);
705
706 /* add the AAL5 trailer at offset 40 */
707 ti1570_add_aal5_trailer(d,tde);
708
709 /* we can transmit the cell */
710 ti1570_send_tx_fifo(d,tde,FALSE);
711
712 *buf_end = TRUE;
713 return(TRUE);
714 }
715
716 /* Transmit the cell normally */
717 len = ti1570_init_tx_atm_cell(d,tde,FALSE);
718 ti1570_add_tx_padding(d,d->txfifo_avail);
719 ti1570_send_tx_fifo(d,tde,TRUE);
720 return(FALSE);
721 }
722
723 /* Update the TX completion ring */
724 static void ti1570_update_tx_cring(struct pa_a1_data *d,
725 ti1570_tx_dma_entry_t *tde)
726 {
727 m_uint32_t tcr_addr,tcr_end,val;
728
729 if (tde->ctrl_buf & TI1570_TX_DMA_TCR_SELECT) {
730 /* TX completion ring with interrupt */
731 tcr_addr = d->iregs[TI1570_REG_TCR_WI_ADDR] + (d->tcr_wi_pos * 4);
732 } else {
733 /* TX completion ring without interrupt */
734 tcr_addr = d->iregs[TI1570_REG_TCR_WOI_ADDR] + (d->tcr_woi_pos * 4);
735 }
736
737 #if DEBUG_TRANSMIT
738 TI1570_LOG(d,"ti1570_update_tx_cring: posting 0x%x at address 0x%x\n",
739 tde->sb_addr,tcr_addr);
740
741 physmem_dump_vm(d->vm,tde->sb_addr,sizeof(ti1570_tx_buffer_t) >> 2);
742 #endif
743
744 /* we have a TX freeze if the buffer belongs to the host */
745 val = physmem_copy_u32_from_vm(d->vm,tcr_addr);
746 if (!(val & TI1570_TCR_OWN)) {
747 d->iregs[TI1570_REG_STATUS] |= TI1570_STAT_TX_FRZ;
748 return;
749 }
750
751 /* put the buffer address in the ring */
752 val = tde->sb_addr >> 2;
753
754 if (tde->ctrl_buf & TI1570_TX_DMA_ABORT)
755 val |= TI1570_TCR_ABORT;
756
757 physmem_copy_u32_to_vm(d->vm,tcr_addr,val);
758
759 /* update the internal position pointer */
760 if (tde->ctrl_buf & TI1570_TX_DMA_TCR_SELECT) {
761 tcr_end = d->iregs[TI1570_REG_TX_CRING_SIZE] & TI1570_TCR_SIZE_MASK;
762
763 if ((d->tcr_wi_pos++) == tcr_end)
764 d->tcr_wi_pos = 0;
765 } else {
766 tcr_end = (d->iregs[TI1570_REG_TX_CRING_SIZE] >> 16);
767 tcr_end &= TI1570_TCR_SIZE_MASK;
768
769 if ((d->tcr_woi_pos++) == tcr_end)
770 d->tcr_woi_pos = 0;
771 }
772 }
773
774 /* Analyze a TX DMA state table entry */
775 static int ti1570_scan_tx_dma_entry_single(struct pa_a1_data *d,
776 m_uint32_t index)
777 {
778 ti1570_tx_dma_entry_t *tde;
779 m_uint32_t psr_base,psr_addr,psr_entry,psr_end;
780 m_uint32_t buf_addr,buf_size,pkt_type,tmp;
781 m_uint32_t psr_index;
782 int atm_set_eop = 0;
783 int pkt_end,buf_end = 0;
784
785 tde = &d->tx_dma_table[index];
786
787 /* The DMA channel state flag must be ON */
788 if (!(tde->dma_state & TI1570_TX_DMA_ON))
789 return(FALSE);
790
791 #if DEBUG_TX_DMA
792 /* We have a running DMA channel */
793 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: TX DMA entry %u is ON "
794 "(ctrl_buf = 0x%x)\n",index,tde->ctrl_buf);
795 #endif
796
797 /* Is this the start of a new packet ? */
798 if (!(tde->ctrl_buf & TI1570_TX_DMA_ACT))
799 {
800 #if DEBUG_TX_DMA
801 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: TX DMA entry %u is not ACT\n",
802 index);
803 #endif
804
805 /* No packet yet, fetch it from the packet-segmentation ring */
806 psr_base = tde->dma_state & TI1570_TX_DMA_RING_OFFSET_MASK;
807 psr_index = tde->dma_state & TI1570_TX_DMA_RING_INDEX_MASK;
808
809 /* Compute address of the current packet segmentation ring entry */
810 psr_addr = (psr_base + psr_index) << 2;
811 psr_entry = physmem_copy_u32_from_vm(d->vm,psr_addr);
812
813 #if DEBUG_TX_DMA
814 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: psr_addr = 0x%x, "
815 "psr_entry = 0x%x\n",psr_addr,psr_entry);
816 #endif
817
818 /* The packet-segmentation-ring entry is owned by host, quit now */
819 if (!(psr_entry & TI1570_TX_RING_OWN))
820 return(FALSE);
821
822 /* Acquire the first buffer (it MUST be in the ready state) */
823 buf_addr = (psr_entry & TI1570_TX_RING_PTR_MASK) << 2;
824
825 if (!ti1570_acquire_tx_buffer(d,tde,buf_addr)) {
826 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: PSR entry with OWN bit set "
827 "but buffer without RDY bit set.\n");
828 return(FALSE);
829 }
830
831 /* Set ACT bit for the DMA channel */
832 tde->ctrl_buf |= TI1570_TX_DMA_ACT;
833 }
834
835 /* Compute the remaining size and determine the packet type */
836 buf_size = tde->ctrl_buf & TI1570_TX_DMA_DCOUNT_MASK;
837 pkt_type = tde->ctrl_buf & TI1570_TX_DMA_AAL_TYPE_MASK;
838 pkt_end = tde->ctrl_buf & TI1570_TX_DMA_EOP;
839
840 #if DEBUG_TRANSMIT
841 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: ctrl_buf=0x%8.8x, "
842 "cb_addr=0x%8.8x, atm_hdr=0x%8.8x, dma_state=0x%8.8x\n",
843 tde->ctrl_buf, tde->cb_addr, tde->atm_hdr, tde->dma_state);
844
845 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: nb_addr=0x%8.8x, "
846 "sb_addr=0x%8.8x, aal5_crc=0x%8.8x, aal5_ctrl=0x%8.8x\n",
847 tde->nb_addr, tde->sb_addr, tde->aal5_crc, tde->aal5_ctrl);
848 #endif
849
850 /*
851 * If the current buffer is now empty and if this is not the last
852 * buffer in the current packet, try to fetch a new buffer.
853 * If the next buffer is not yet ready, we have finished.
854 */
855 if (!buf_size && !pkt_end && !ti1570_acquire_tx_buffer(d,tde,tde->nb_addr))
856 return(FALSE);
857
858 switch(pkt_type) {
859 case TI1570_TX_DMA_AAL_TRWPTI:
860 atm_set_eop = 1;
861
862 case TI1570_TX_DMA_AAL_TRWOPTI:
863 /* Transmit the ATM cell transparently */
864 pkt_end = ti1570_transmit_transp_cell(d,tde,atm_set_eop,&buf_end);
865 break;
866
867 case TI1570_TX_DMA_AAL_AAL5:
868 pkt_end = ti1570_transmit_aal5_cell(d,tde,&buf_end);
869 break;
870
871 default:
872 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: invalid AAL-type\n");
873 return(FALSE);
874 }
875
876 /* Re-read the remaining buffer size */
877 buf_size = tde->ctrl_buf & TI1570_TX_DMA_DCOUNT_MASK;
878
879 /* Put the buffer address in the transmit completion ring */
880 if (buf_end) ti1570_update_tx_cring(d,tde);
881
882 /*
883 * If we have reached end of packet (EOP): clear the ACT bit,
884 * give back the packet-segmentation ring entry to the host,
885 * and increment the PSR index.
886 */
887 if (pkt_end) {
888 tde->ctrl_buf &= ~TI1570_TX_DMA_ACT;
889
890 /* Clear the OWN bit of the packet-segmentation ring entry */
891 psr_base = tde->dma_state & TI1570_TX_DMA_RING_OFFSET_MASK;
892 psr_index = (tde->dma_state & TI1570_TX_DMA_RING_INDEX_MASK);
893 psr_addr = (psr_base + psr_index) << 2;
894
895 psr_entry = physmem_copy_u32_from_vm(d->vm,psr_addr);
896 psr_entry &= ~TI1570_TX_RING_OWN;
897 physmem_copy_u32_to_vm(d->vm,psr_addr,psr_entry);
898
899 /* Increment the packet-segmentation ring index */
900 psr_index++;
901 psr_end = d->iregs[TI1570_REG_TX_PSR_SIZE] >> 16;
902 psr_end &= TI1570_PSR_SIZE_MASK;
903
904 if (psr_index > psr_end) {
905 psr_index = 0;
906 #if DEBUG_TX_DMA
907 TI1570_LOG(d,"ti1570_scan_tx_dma_entry: PSR ring rotation "
908 "(psr_end = %u)\n",psr_end);
909 #endif
910 }
911
912 tmp = (tde->dma_state & ~TI1570_TX_DMA_RING_INDEX_MASK);
913 tmp |= (psr_index & TI1570_TX_DMA_RING_INDEX_MASK);
914 tde->dma_state = tmp;
915 }
916
917 /* Generate an interrupt if required */
918 if (tde->ctrl_buf & TI1570_TX_DMA_TCR_SELECT)
919 {
920 if (((d->iregs[TI1570_REG_CONFIG] & TI1570_CFG_BP_SEL) && buf_end) ||
921 pkt_end)
922 {
923 d->iregs[TI1570_REG_STATUS] |= TI1570_STAT_CP_TX;
924 dev_pa_a1_update_irq_status(d);
925 }
926 }
927
928 return(TRUE);
929 }
930
931 /* Analyze a TX DMA state table entry */
932 static void ti1570_scan_tx_dma_entry(struct pa_a1_data *d,m_uint32_t index)
933 {
934 int i;
935
936 for(i=0;i<TI1570_TXDMA_PASS_COUNT;i++)
937 if (!ti1570_scan_tx_dma_entry_single(d,index))
938 break;
939 }
940
941 /* Analyze the TX schedule table */
942 static void ti1570_scan_tx_sched_table(struct pa_a1_data *d)
943 {
944 m_uint32_t cw,index0,index1;
945 u_int i;
946
947 for(i=0;i<TI1570_TX_SCHED_ENTRY_COUNT>>1;i++) {
948 cw = d->tx_sched_table[i];
949
950 /* We have 2 index in TX DMA state table per word */
951 index0 = (cw >> TI1570_TX_SCHED_E0_SHIFT) & TI1570_TX_SCHED_ENTRY_MASK;
952 index1 = (cw >> TI1570_TX_SCHED_E1_SHIFT) & TI1570_TX_SCHED_ENTRY_MASK;
953
954 /* Scan the two entries (null entry => nothing to do) */
955 if (index0) ti1570_scan_tx_dma_entry(d,index0);
956 if (index1) ti1570_scan_tx_dma_entry(d,index1);
957 }
958 }
959
960 /*
961 * Read a RX buffer from the host memory.
962 */
963 static void ti1570_read_rx_buffer(struct pa_a1_data *d,m_uint32_t addr,
964 ti1570_rx_buffer_t *rx_buf)
965 {
966 physmem_copy_from_vm(d->vm,rx_buf,addr,sizeof(ti1570_rx_buffer_t));
967
968 /* byte-swapping */
969 rx_buf->reserved = vmtoh32(rx_buf->reserved);
970 rx_buf->ctrl = vmtoh32(rx_buf->ctrl);
971 rx_buf->atm_hdr = vmtoh32(rx_buf->atm_hdr);
972 rx_buf->user = vmtoh32(rx_buf->user);
973 }
974
975 /* Update the RX completion ring */
976 static void ti1570_update_rx_cring(struct pa_a1_data *d,
977 ti1570_rx_dma_entry_t *rde,
978 m_uint32_t atm_hdr,
979 m_uint32_t aal5_trailer,
980 m_uint32_t err_ind,
981 m_uint32_t fbuf_valid)
982 {
983 m_uint32_t rcr_addr,rcr_end,aal_type,ptr,val;
984 ti1570_rcr_entry_t rcre;
985
986 if (rde->ctrl & TI1570_RX_DMA_RCR_SELECT) {
987 /* RX completion ring with interrupt */
988 rcr_addr = d->iregs[TI1570_REG_RCR_WI_ADDR];
989 rcr_addr += (d->rcr_wi_pos * sizeof(rcre));
990 } else {
991 /* RX completion ring without interrupt */
992 rcr_addr = d->iregs[TI1570_REG_RCR_WOI_ADDR];
993 rcr_addr += (d->rcr_woi_pos * sizeof(rcre));
994 }
995
996 #if DEBUG_RECEIVE
997 TI1570_LOG(d,"ti1570_update_rx_cring: posting 0x%x at address 0x%x\n",
998 (rde->sp_ptr << 2),rcr_addr);
999
1000 physmem_dump_vm(d->vm,rde->sp_ptr<<2,sizeof(ti1570_rx_buffer_t) >> 2);
1001 #endif
1002
1003 /* we have a RX freeze if the buffer belongs to the host */
1004 ptr = rcr_addr + OFFSET(ti1570_rcr_entry_t,fbr_entry);
1005 val = physmem_copy_u32_from_vm(d->vm,ptr);
1006
1007 if (!(val & TI1570_RCR_OWN)) {
1008 TI1570_LOG(d,"ti1570_update_rx_cring: RX freeze...\n");
1009 d->iregs[TI1570_REG_STATUS] |= TI1570_STAT_RX_FRZ;
1010 return;
1011 }
1012
1013 /* fill the RX completion ring entry and write it back to the host */
1014 memset(&rcre,0,sizeof(rcre));
1015
1016 /* word 0: atm header from last cell received */
1017 rcre.atm_hdr = atm_hdr;
1018
1019 /* word 1: error indicator */
1020 aal_type = rde->ctrl & TI1570_RX_DMA_AAL_TYPE_MASK;
1021 if (aal_type == TI1570_RX_DMA_AAL_AAL5)
1022 rcre.error |= TI1570_RCR_AAL5;
1023
1024 rcre.error |= err_ind;
1025
1026 /* word 2: Start of packet */
1027 if (fbuf_valid)
1028 rcre.sp_addr = TI1570_RCR_VALID | rde->sp_ptr;
1029
1030 /* word 3: AAL5 trailer */
1031 rcre.aal5_trailer = aal5_trailer;
1032
1033 /* word 4: OWN + error entry + free-buffer ring pointer */
1034 rcre.fbr_entry = rde->fbr_entry & TI1570_RX_DMA_FB_PTR_MASK;
1035 if (err_ind) rcre.fbr_entry |= TI1570_RCR_ERROR;
1036
1037 /* byte-swap and write this back to the host memory */
1038 rcre.atm_hdr = htonl(rcre.atm_hdr);
1039 rcre.error = htonl(rcre.error);
1040 rcre.sp_addr = htonl(rcre.sp_addr);
1041 rcre.aal5_trailer = htonl(rcre.aal5_trailer);
1042 rcre.fbr_entry = htonl(rcre.fbr_entry);
1043 physmem_copy_to_vm(d->vm,&rcre,rcr_addr,sizeof(rcre));
1044
1045 /* clear the active bit of the RX DMA entry */
1046 rde->ctrl &= ~TI1570_RX_DMA_ACT;
1047
1048 /* update the internal position pointer */
1049 if (rde->ctrl & TI1570_RX_DMA_RCR_SELECT) {
1050 rcr_end = d->iregs[TI1570_REG_RX_CRING_SIZE] & TI1570_RCR_SIZE_MASK;
1051
1052 if ((d->rcr_wi_pos++) == rcr_end)
1053 d->rcr_wi_pos = 0;
1054
1055 /* generate the appropriate IRQ */
1056 d->iregs[TI1570_REG_STATUS] |= TI1570_STAT_CP_RX;
1057 dev_pa_a1_update_irq_status(d);
1058 } else {
1059 rcr_end = (d->iregs[TI1570_REG_RX_CRING_SIZE] >> 16);
1060 rcr_end &= TI1570_RCR_SIZE_MASK;
1061
1062 if ((d->rcr_woi_pos++) == rcr_end)
1063 d->rcr_woi_pos = 0;
1064 }
1065 }
1066
1067 /*
1068 * Acquire a free RX buffer.
1069 *
1070 * Returns FALSE if no buffer is available (buffer starvation).
1071 */
1072 static int ti1570_acquire_rx_buffer(struct pa_a1_data *d,
1073 ti1570_rx_dma_entry_t *rde,
1074 ti1570_rx_buf_holder_t *rbh,
1075 m_uint32_t atm_hdr)
1076 {
1077 ti1570_rx_fbr_entry_t *fbr_entry = NULL;
1078 m_uint32_t bp_addr,buf_addr,buf_size,buf_idx;
1079 m_uint32_t ring_index,ring_size;
1080 m_uint32_t buf_ptr,val;
1081 int fifo = FALSE;
1082
1083 /* To keep this fucking compiler quiet */
1084 ring_size = 0;
1085 buf_idx = 0;
1086
1087 if (rde->ctrl & TI1570_RX_DMA_FIFO) {
1088 bp_addr = (rde->fbr_entry & TI1570_RX_DMA_FB_PTR_MASK) << 2;
1089 buf_ptr = physmem_copy_u32_from_vm(d->vm,bp_addr);
1090 buf_size = d->iregs[TI1570_REG_TX_PSR_SIZE] & 0xFFFF;
1091 fifo = TRUE;
1092
1093 #if DEBUG_RECEIVE
1094 TI1570_LOG(d,"ti1570_acquire_rx_buffer: acquiring FIFO buffer\n");
1095 #endif
1096 }
1097 else
1098 {
1099 ring_index = rde->fbr_entry & TI1570_RX_DMA_FB_INDEX_MASK;
1100 fbr_entry = &d->rx_fbr_table[ring_index];
1101
1102 #if DEBUG_RECEIVE
1103 TI1570_LOG(d,"ti1570_acquire_rx_buffer: acquiring non-FIFO buffer, "
1104 "ring index=%u (0x%x)\n",ring_index,ring_index);
1105 #endif
1106
1107 /* Compute the number of entries in ring */
1108 ring_size = fbr_entry->ring_size & TI1570_RX_FBR_RS_MASK;
1109 ring_size >>= TI1570_RX_FBR_RS_SHIFT;
1110 ring_size = (ring_size << 4) + 15 + 1;
1111
1112 /* Compute the buffer size */
1113 buf_size = fbr_entry->ring_size & TI1570_RX_FBR_BS_MASK;
1114 buf_size >>= TI1570_RX_FBR_BS_SHIFT;
1115
1116 /* Compute the buffer address */
1117 buf_idx = fbr_entry->ring_size & TI1570_RX_FBR_IDX_MASK;
1118 bp_addr = fbr_entry->fbr_ptr + (buf_idx << 2);
1119
1120 #if DEBUG_RECEIVE
1121 TI1570_LOG(d,"ti1570_acquire_rx_buffer: ring size=%u (0x%x), "
1122 "buf size=%u ATM cells\n",ring_size,ring_size,buf_size);
1123
1124 TI1570_LOG(d,"ti1570_acquire_rx_buffer: buffer index=%u (0x%x), "
1125 "buffer ptr address = 0x%x\n",buf_idx,buf_idx,bp_addr);
1126 #endif
1127
1128 buf_ptr = physmem_copy_u32_from_vm(d->vm,bp_addr);
1129 }
1130
1131 #if DEBUG_RECEIVE
1132 TI1570_LOG(d,"ti1570_acquire_rx_buffer: buf_ptr = 0x%x\n",buf_ptr);
1133 #endif
1134
1135 /* The TI1570 must own the buffer */
1136 if (!(buf_ptr & TI1570_RX_BUFPTR_OWN)) {
1137 TI1570_LOG(d,"ti1570_acquire_rx_buffer: no free buffer available.\n");
1138 return(FALSE);
1139 }
1140
1141 /*
1142 * If we are using a ring, we have to clear the OWN bit and increment
1143 * the index field.
1144 */
1145 if (!fifo) {
1146 buf_ptr &= ~TI1570_RX_BUFPTR_OWN;
1147 physmem_copy_u32_to_vm(d->vm,bp_addr,buf_ptr);
1148
1149 if (++buf_idx == ring_size) {
1150 #if DEBUG_RECEIVE
1151 TI1570_LOG(d,"ti1570_acquire_rx_buffer: buf_idx=0x%x, "
1152 "ring_size=0x%x -> resetting buf_idx\n",
1153 buf_idx-1,ring_size);
1154 #endif
1155 buf_idx = 0;
1156 }
1157
1158 val = fbr_entry->ring_size & ~TI1570_RX_FBR_IDX_MASK;
1159 val |= buf_idx;
1160 fbr_entry->ring_size = val;
1161 }
1162
1163 /* Get the buffer address */
1164 buf_addr = (buf_ptr & TI1570_RX_BUFPTR_MASK) << 2;
1165
1166 #if DEBUG_RECEIVE
1167 TI1570_LOG(d,"ti1570_acquire_rx_buffer: buf_addr = 0x%x\n",buf_addr);
1168 #endif
1169
1170 /* Read the buffer descriptor itself and store info for caller */
1171 rbh->buf_addr = buf_addr;
1172 rbh->buf_size = buf_size;
1173 ti1570_read_rx_buffer(d,buf_addr,&rbh->rx_buf);
1174
1175 /* Clear the control field */
1176 physmem_copy_u32_to_vm(d->vm,buf_addr+OFFSET(ti1570_rx_buffer_t,ctrl),0);
1177
1178 /* Store the ATM header in data buffer */
1179 physmem_copy_u32_to_vm(d->vm,buf_addr+OFFSET(ti1570_rx_buffer_t,atm_hdr),
1180 atm_hdr);
1181 return(TRUE);
1182 }
1183
1184 /* Insert a new free buffer in a RX DMA entry */
1185 static void ti1570_insert_rx_free_buf(struct pa_a1_data *d,
1186 ti1570_rx_dma_entry_t *rde,
1187 ti1570_rx_buf_holder_t *rbh)
1188 {
1189 m_uint32_t val,aal_type;
1190
1191 aal_type = rde->ctrl & TI1570_RX_DMA_AAL_TYPE_MASK;
1192
1193 /* Set current and start of buffer addresses */
1194 rde->cb_addr = rbh->buf_addr + sizeof(ti1570_rx_buffer_t);
1195 rde->sb_addr = rbh->buf_addr >> 2;
1196
1197 /* Set the buffer length */
1198 val = rbh->buf_size;
1199
1200 if (aal_type == TI1570_RX_DMA_AAL_CNT)
1201 val |= (rde->aal5_crc & 0xFFFF) << 16;
1202
1203 rde->cb_len = val;
1204 }
1205
1206 /* Store a RX cell */
1207 static int ti1570_store_rx_cell(struct pa_a1_data *d,
1208 ti1570_rx_dma_entry_t *rde,
1209 m_uint8_t *atm_cell)
1210 {
1211 m_uint32_t aal_type,atm_hdr,aal5_trailer,pti,real_eop,pti_eop;
1212 m_uint32_t prev_buf_addr,buf_len,val,ptr,cnt;
1213 ti1570_rx_buf_holder_t rbh;
1214
1215 real_eop = pti_eop = FALSE;
1216 aal_type = rde->ctrl & TI1570_RX_DMA_AAL_TYPE_MASK;
1217
1218 /* Extract PTI from the ATM header */
1219 atm_hdr = ntohl(*(m_uint32_t *)&atm_cell[0]);
1220 pti = (atm_hdr & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1221
1222 /* PTI == 0x1 => EOP */
1223 if ((pti == 0x01) || (pti == 0x03))
1224 pti_eop = TRUE;
1225
1226 if (rde->ctrl & TI1570_RX_DMA_WAIT_EOP) {
1227 TI1570_LOG(d,"ti1570_store_rx_cell: EOP processing, not handled yet.\n");
1228 return(FALSE);
1229 }
1230
1231 /* AAL5 special processing */
1232 if (aal_type == TI1570_RX_DMA_AAL_AAL5)
1233 {
1234 /* Check that we don't exceed 1366 cells for AAL5 */
1235 /* XXX TODO */
1236 }
1237 else
1238 {
1239 /* EOP processing for non counter-based transparent-AAL packets */
1240 if ((rde->ctrl & TI1570_RX_DMA_WAIT_EOP) && pti_eop)
1241 {
1242 /* XXX TODO */
1243 }
1244 }
1245
1246 /* do we have enough room in buffer ? */
1247 buf_len = rde->cb_len & TI1570_RX_DMA_CB_LEN_MASK;
1248
1249 if (!buf_len) {
1250 prev_buf_addr = rde->sb_addr << 2;
1251
1252 /* acquire a new free buffer */
1253 if (!ti1570_acquire_rx_buffer(d,rde,&rbh,atm_hdr)) {
1254 rde->ctrl |= TI1570_RX_DMA_WAIT_EOP;
1255 return(FALSE);
1256 }
1257
1258 /* insert the free buffer in the RX DMA structure */
1259 ti1570_insert_rx_free_buf(d,rde,&rbh);
1260
1261 /* chain the buffers (keep SOP/EOP bits intact) */
1262 ptr = prev_buf_addr + OFFSET(ti1570_rx_buffer_t,ctrl);
1263
1264 val = physmem_copy_u32_from_vm(d->vm,ptr);
1265 val |= rde->sb_addr;
1266 physmem_copy_u32_to_vm(d->vm,ptr,val);
1267
1268 /* read the new buffer length */
1269 buf_len = rde->cb_len & TI1570_RX_DMA_CB_LEN_MASK;
1270 }
1271
1272 /* copy the ATM payload */
1273 #if DEBUG_RECEIVE
1274 TI1570_LOG(d,"ti1570_store_rx_cell: storing cell payload at 0x%x "
1275 "(buf_addr=0x%x)\n",rde->cb_addr,rde->sb_addr << 2);
1276 #endif
1277
1278 physmem_copy_to_vm(d->vm,&atm_cell[ATM_HDR_SIZE],
1279 rde->cb_addr,ATM_PAYLOAD_SIZE);
1280 rde->cb_addr += ATM_PAYLOAD_SIZE;
1281
1282 /* update the current buffer length */
1283 val = rde->cb_len & ~TI1570_RX_DMA_CB_LEN_MASK;
1284 rde->cb_len = val | (--buf_len);
1285
1286 #if DEBUG_RECEIVE
1287 TI1570_LOG(d,"ti1570_store_rx_cell: new rde->cb_len = 0x%x, "
1288 "buf_len=0x%x\n",rde->cb_len,buf_len);
1289 #endif
1290
1291 /* determine if this is the end of the packet (EOP) */
1292 if (aal_type == TI1570_RX_DMA_AAL_CNT)
1293 {
1294 /* counter-based tranparent-AAL packets */
1295 cnt = rde->cb_len & TI1570_RX_DMA_TR_CNT_MASK;
1296 cnt >>= TI1570_RX_DMA_TR_CNT_SHIFT;
1297
1298 /* if the counter reaches 0, this is the EOP */
1299 if (--cnt == 0)
1300 real_eop = TRUE;
1301
1302 val = rde->cb_len & ~TI1570_RX_DMA_TR_CNT_MASK;
1303 val |= cnt << TI1570_RX_DMA_TR_CNT_SHIFT;
1304 }
1305 else {
1306 /* PTI-based transparent AAL packets or AAL5 */
1307 if (pti_eop)
1308 real_eop = TRUE;
1309 }
1310
1311 if (real_eop) {
1312 /* mark the buffer as EOP */
1313 ptr = (rde->sb_addr << 2) + OFFSET(ti1570_rx_buffer_t,ctrl);
1314 val = physmem_copy_u32_from_vm(d->vm,ptr);
1315 val |= TI1570_RX_BUFFER_EOP;
1316 physmem_copy_u32_to_vm(d->vm,ptr,val);
1317
1318 /* get the aal5 trailer */
1319 aal5_trailer = ntohl(*(m_uint32_t *)&atm_cell[ATM_AAL5_TRAILER_POS]);
1320
1321 /* post the entry into the appropriate RX completion ring */
1322 ti1570_update_rx_cring(d,rde,atm_hdr,aal5_trailer,0,TRUE);
1323 }
1324
1325 return(TRUE);
1326 }
1327
1328 /* Handle a received ATM cell */
1329 static int ti1570_handle_rx_cell(netio_desc_t *nio,
1330 u_char *atm_cell,ssize_t cell_len,
1331 struct pa_a1_data *d)
1332 {
1333 m_uint32_t atm_hdr,vpi,vci,vci_idx,vci_mask;
1334 m_uint32_t vci_max,rvd_entry,bptr,pti,ptr;
1335 ti1570_rx_dma_entry_t *rde = NULL;
1336 ti1570_rx_buf_holder_t rbh;
1337
1338 if (cell_len != ATM_CELL_SIZE) {
1339 TI1570_LOG(d,"invalid RX cell size (%ld)\n",(long)cell_len);
1340 return(FALSE);
1341 }
1342
1343 /* Extract the VPI/VCI used as index in the RX VPI/VCI DMA pointer table */
1344 atm_hdr = ntohl(*(m_uint32_t *)&atm_cell[0]);
1345 vpi = (atm_hdr & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
1346 vci = (atm_hdr & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
1347 pti = (atm_hdr & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1348
1349 #if DEBUG_RECEIVE
1350 TI1570_LOG(d,"ti1570_handle_rx_cell: received cell with VPI/VCI=%u/%u\n",
1351 vpi,vci);
1352 #endif
1353
1354 /* Get the entry corresponding to this VPI in RX VPI/VCI dma ptr table */
1355 rvd_entry = d->rx_vpi_vci_dma_table[vpi];
1356
1357 if (!(rvd_entry & TI1570_RX_VPI_ENABLE)) {
1358 TI1570_LOG(d,"ti1570_handle_rx_cell: received cell with "
1359 "unknown VPI %u (VCI=%u)\n",vpi,vci);
1360 return(FALSE);
1361 }
1362
1363 /*
1364 * Special routing for OAM F4 cells:
1365 * - VCI 3 : OAM F4 segment cell
1366 * - VCI 4 : OAM F4 end-to-end cell
1367 */
1368 if ((vci == 3) || (vci == 4))
1369 rde = &d->rx_dma_table[2];
1370 else {
1371 if ((atm_hdr & ATM_PTI_NETWORK) != 0) {
1372 switch(pti) {
1373 case 0x04: /* OAM F5-segment cell */
1374 case 0x05: /* OAM F5 end-to-end cell */
1375 rde = &d->rx_dma_table[0];
1376 break;
1377
1378 case 0x06:
1379 case 0x07:
1380 rde = &d->rx_dma_table[1];
1381 break;
1382 }
1383 } else {
1384 /*
1385 * Standard VPI/VCI.
1386 * Apply the VCI mask if we don't have an OAM cell.
1387 */
1388 if (!(atm_hdr & ATM_PTI_NETWORK)) {
1389 vci_mask = d->iregs[TI1570_REG_TX_RX_FIFO] >> 16;
1390 vci_idx = vci & (~vci_mask);
1391
1392 vci_max = rvd_entry & TI1570_RX_VCI_RANGE_MASK;
1393
1394 if (vci_idx > vci_max) {
1395 TI1570_LOG(d,"ti1570_handle_rx_cell: out-of-range VCI %u "
1396 "(VPI=%u,vci_mask=%u,vci_max=%u)\n",
1397 vci,vpi,vci_mask,vci_max);
1398 return(FALSE);
1399 }
1400
1401 #if DEBUG_RECEIVE
1402 TI1570_LOG(d,"ti1570_handle_rx_cell: VPI/VCI=%u/%u, "
1403 "vci_mask=0x%x, vci_idx=%u (0x%x), vci_max=%u (0x%x)\n",
1404 vpi,vci,vci_mask,vci_idx,vci_idx,vci_max,vci_max);
1405 #endif
1406 bptr = (rvd_entry & TI1570_RX_BASE_PTR_MASK);
1407 bptr >>= TI1570_RX_BASE_PTR_SHIFT;
1408 bptr = (bptr + vci) * sizeof(ti1570_rx_dma_entry_t);
1409
1410 if (bptr < TI1570_RX_DMA_TABLE_OFFSET) {
1411 TI1570_LOG(d,"ti1570_handle_rx_cell: inconsistency in "
1412 "RX VPI/VCI table, VPI/VCI=%u/u, bptr=0x%x\n",
1413 vpi,vci,bptr);
1414 return(FALSE);
1415 }
1416
1417 bptr -= TI1570_RX_DMA_TABLE_OFFSET;
1418 rde = &d->rx_dma_table[bptr / sizeof(ti1570_rx_dma_entry_t)];
1419 }
1420 }
1421 }
1422
1423 if (!rde) {
1424 TI1570_LOG(d,"ti1570_handle_rx_cell: no RX DMA table entry found!\n");
1425 return(FALSE);
1426 }
1427
1428 /* The entry must be active */
1429 if (!(rde->fbr_entry & TI1570_RX_DMA_ON))
1430 return(FALSE);
1431
1432 /* Is this the start of a new packet ? */
1433 if (!(rde->ctrl & TI1570_RX_DMA_ACT))
1434 {
1435 /* Try to acquire a free buffer */
1436 if (!ti1570_acquire_rx_buffer(d,rde,&rbh,atm_hdr)) {
1437 rde->ctrl |= TI1570_RX_DMA_WAIT_EOP;
1438 return(FALSE);
1439 }
1440
1441 /* Insert the free buffer in the RX DMA structure */
1442 ti1570_insert_rx_free_buf(d,rde,&rbh);
1443 rde->sp_ptr = rde->sb_addr;
1444
1445 /* Mark the RX buffer as the start of packet (SOP) */
1446 ptr = (rde->sb_addr << 2) + OFFSET(ti1570_rx_buffer_t,ctrl);
1447 physmem_copy_u32_to_vm(d->vm,ptr,TI1570_RX_BUFFER_SOP);
1448
1449 /* Set ACT bit for the DMA channel */
1450 rde->ctrl |= TI1570_RX_DMA_ACT;
1451 }
1452
1453 /* Store the received cell */
1454 ti1570_store_rx_cell(d,rde,atm_cell);
1455 return(TRUE);
1456 }
1457
1458 /*
1459 * pci_ti1570_read()
1460 */
1461 static m_uint32_t pci_ti1570_read(cpu_gen_t *cpu,struct pci_device *dev,
1462 int reg)
1463 {
1464 struct pa_a1_data *d = dev->priv_data;
1465
1466 #if DEBUG_ACCESS
1467 TI1570_LOG(d,"pci_ti1570_read: read reg 0x%x\n",reg);
1468 #endif
1469
1470 switch(reg) {
1471 case PCI_REG_BAR0:
1472 return(d->dev->phys_addr);
1473 default:
1474 return(0);
1475 }
1476 }
1477
1478 /*
1479 * pci_ti1570_write()
1480 */
1481 static void pci_ti1570_write(cpu_gen_t *cpu,struct pci_device *dev,
1482 int reg,m_uint32_t value)
1483 {
1484 struct pa_a1_data *d = dev->priv_data;
1485
1486 #if DEBUG_ACCESS
1487 TI1570_LOG(d,"pci_ti1570_write: write reg 0x%x, value 0x%x\n",reg,value);
1488 #endif
1489
1490 switch(reg) {
1491 case PCI_REG_BAR0:
1492 vm_map_device(cpu->vm,d->dev,(m_uint64_t)value);
1493 TI1570_LOG(d,"registers are mapped at 0x%x\n",value);
1494 break;
1495 }
1496 }
1497
1498 /*
1499 * pci_plx9060es_read()
1500 */
1501 static m_uint32_t pci_plx9060es_read(cpu_gen_t *cpu,struct pci_device *dev,
1502 int reg)
1503 {
1504 //struct pa_a1_data *d = dev->priv_data;
1505
1506 #if DEBUG_ACCESS
1507 TI1570_LOG(d,"PLX9060ES","read reg 0x%x\n",reg);
1508 #endif
1509 switch(reg) {
1510 default:
1511 return(0);
1512 }
1513 }
1514
1515 /*
1516 * pci_plx9060es_write()
1517 */
1518 static void pci_plx9060es_write(cpu_gen_t *cpu,struct pci_device *dev,
1519 int reg,m_uint32_t value)
1520 {
1521 //struct pa_a1_data *d = dev->priv_data;
1522
1523 #if DEBUG_ACCESS
1524 TI1570_LOG(d,"PLX9060ES","write reg 0x%x, value 0x%x\n",reg,value);
1525 #endif
1526
1527 switch(reg) {
1528 }
1529 }
1530
1531 /* Reset the TI1570 */
1532 static void ti1570_reset(struct pa_a1_data *d,int clear_ctrl_mem)
1533 {
1534 ti1570_clear_tx_fifo(d);
1535
1536 d->tcr_wi_pos = d->tcr_woi_pos = 0;
1537 d->rcr_wi_pos = d->rcr_woi_pos = 0;
1538
1539 if (clear_ctrl_mem)
1540 memset(d->ctrl_mem_ptr,0,TI1570_CTRL_MEM_SIZE);
1541 }
1542
1543 /*
1544 * dev_c7200_pa_a1_init()
1545 *
1546 * Add a PA-A1 port adapter into specified slot.
1547 */
1548 int dev_c7200_pa_a1_init(vm_instance_t *vm,struct cisco_card *card)
1549 {
1550 u_int slot = card->slot_id;
1551 struct pci_device *pci_dev_ti,*pci_dev_plx;
1552 struct pa_a1_data *d;
1553 struct vdevice *dev;
1554 m_uint8_t *p;
1555
1556 /* Allocate the private data structure for TI1570 chip */
1557 if (!(d = malloc(sizeof(*d)))) {
1558 vm_error(vm,"%s: out of memory\n",card->dev_name);
1559 return(-1);
1560 }
1561
1562 memset(d,0,sizeof(*d));
1563
1564 /* Set the PCI bus */
1565 card->pci_bus = vm->slots_pci_bus[slot];
1566
1567 /* Set the EEPROM */
1568 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-A1"));
1569 c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
1570
1571 /* Add PCI device TI1570 */
1572 pci_dev_ti = pci_dev_add(card->pci_bus,card->dev_name,
1573 TI1570_PCI_VENDOR_ID,TI1570_PCI_PRODUCT_ID,
1574 0,0,c7200_net_irq_for_slot_port(slot,0),d,
1575 NULL,pci_ti1570_read,pci_ti1570_write);
1576
1577 if (!pci_dev_ti) {
1578 vm_error(vm,"%s: unable to create PCI device TI1570.\n",
1579 card->dev_name);
1580 return(-1);
1581 }
1582
1583 /* Add PCI device PLX9060ES */
1584 pci_dev_plx = pci_dev_add(card->pci_bus,card->dev_name,
1585 PLX_9060ES_PCI_VENDOR_ID,
1586 PLX_9060ES_PCI_PRODUCT_ID,
1587 1,0,-1,d,
1588 NULL,pci_plx9060es_read,pci_plx9060es_write);
1589
1590 if (!pci_dev_plx) {
1591 vm_error(vm,"%s: unable to create PCI device PLX 9060ES.\n",
1592 card->dev_name);
1593 return(-1);
1594 }
1595
1596 /* Create the TI1570 structure */
1597 d->name = card->dev_name;
1598 d->vm = vm;
1599 d->pci_dev_ti = pci_dev_ti;
1600 d->pci_dev_plx = pci_dev_plx;
1601
1602 /* Allocate the control memory */
1603 if (!(d->ctrl_mem_ptr = malloc(TI1570_CTRL_MEM_SIZE))) {
1604 vm_error(vm,"%s: unable to create control memory.\n",card->dev_name);
1605 return(-1);
1606 }
1607
1608 /* Standard tables for the TI1570 */
1609 p = (m_uint8_t *)d->ctrl_mem_ptr;
1610
1611 d->iregs = (m_uint32_t *)(p + TI1570_INTERNAL_REGS_OFFSET);
1612 d->tx_sched_table = (m_uint32_t *)(p + TI1570_TX_SCHED_OFFSET);
1613 d->tx_dma_table = (ti1570_tx_dma_entry_t *)(p + TI1570_TX_DMA_TABLE_OFFSET);
1614 d->rx_vpi_vci_dma_table = (m_uint32_t *)(p+TI1570_RX_DMA_PTR_TABLE_OFFSET);
1615 d->rx_dma_table = (ti1570_rx_dma_entry_t *)(p + TI1570_RX_DMA_TABLE_OFFSET);
1616 d->rx_fbr_table = (ti1570_rx_fbr_entry_t *)(p + TI1570_FREE_BUFFERS_OFFSET);
1617
1618 ti1570_reset(d,TRUE);
1619
1620 /* Create the device itself */
1621 if (!(dev = dev_create(card->dev_name))) {
1622 vm_error(vm,"%s: unable to create device.\n",card->dev_name);
1623 return(-1);
1624 }
1625
1626 dev->phys_addr = 0;
1627 dev->phys_len = 0x200000;
1628 dev->handler = dev_pa_a1_access;
1629
1630 /* Store device info */
1631 dev->priv_data = d;
1632 d->dev = dev;
1633
1634 /* Store device info into the router structure */
1635 card->drv_info = d;
1636 return(0);
1637 }
1638
1639 /* Remove a PA-A1 from the specified slot */
1640 int dev_c7200_pa_a1_shutdown(vm_instance_t *vm,struct cisco_card *card)
1641 {
1642 struct pa_a1_data *d = card->drv_info;
1643
1644 /* Remove the PA EEPROM */
1645 cisco_card_unset_eeprom(card);
1646 c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
1647
1648 /* Remove the PCI devices */
1649 pci_dev_remove(d->pci_dev_ti);
1650 pci_dev_remove(d->pci_dev_plx);
1651
1652 /* Remove the device from the VM address space */
1653 vm_unbind_device(vm,d->dev);
1654 cpu_group_rebuild_mts(vm->cpu_group);
1655
1656 /* Free the control memory */
1657 free(d->ctrl_mem_ptr);
1658
1659 /* Free the device structure itself */
1660 free(d->dev);
1661 free(d);
1662 return(0);
1663 }
1664
1665 /* Bind a Network IO descriptor to a specific port */
1666 int dev_c7200_pa_a1_set_nio(vm_instance_t *vm,struct cisco_card *card,
1667 u_int port_id,netio_desc_t *nio)
1668 {
1669 struct pa_a1_data *d = card->drv_info;
1670
1671 if (!d || (port_id > 0))
1672 return(-1);
1673
1674 if (d->nio != NULL)
1675 return(-1);
1676
1677 d->nio = nio;
1678 d->tx_tid = ptask_add((ptask_callback)ti1570_scan_tx_sched_table,d,NULL);
1679 netio_rxl_add(nio,(netio_rx_handler_t)ti1570_handle_rx_cell,d,NULL);
1680 return(0);
1681 }
1682
1683 /* Unbind a Network IO descriptor to a specific port */
1684 int dev_c7200_pa_a1_unset_nio(vm_instance_t *vm,struct cisco_card *card,
1685 u_int port_id)
1686 {
1687 struct pa_a1_data *d = card->drv_info;
1688
1689 if (!d || (port_id > 0))
1690 return(-1);
1691
1692 if (d->nio) {
1693 ptask_remove(d->tx_tid);
1694 netio_rxl_remove(d->nio);
1695 d->nio = NULL;
1696 }
1697 return(0);
1698 }
1699
1700 /* PA-A1 driver */
1701 struct cisco_card_driver dev_c7200_pa_a1_driver = {
1702 "PA-A1", 1, 0,
1703 dev_c7200_pa_a1_init,
1704 dev_c7200_pa_a1_shutdown,
1705 NULL,
1706 dev_c7200_pa_a1_set_nio,
1707 dev_c7200_pa_a1_unset_nio,
1708 NULL,
1709 };