2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
9 * $Id: if_mn.c,v 1.1 1999/02/01 13:06:40 phk Exp $
11 * Driver for Siemens reference design card "Easy321-R1".
13 * This card contains a FALC54 E1/T1 framer and a MUNICH32X 32-channel HDLC
16 * The driver supports E1 mode with up to 31 channels. We send CRC4 but don't
19 * The FALC54 and MUNICH32X have far too many registers and weird modes for
20 * comfort, so I have not bothered typing it all into a "fooreg.h" file,
21 * you will (badly!) need the documentation anyway if you want to mess with
24 * $FreeBSD: src/sys/pci/if_mn.c,v 1.11.2.3 2001/01/23 12:47:09 phk Exp $
25 * $DragonFly: src/sys/dev/netif/mn/if_mn.c,v 1.17 2007/06/03 20:51:08 dillon Exp $
29 * Stuff to describe the MUNIC32X and FALC54 chips.
32 #define M32_CHAN 32 /* We have 32 channels */
33 #define M32_TS 32 /* We have 32 timeslots */
35 #define NG_MN_NODE_TYPE "mn"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/sysctl.h>
43 #include <sys/malloc.h>
46 #include <bus/pci/pcireg.h>
47 #include <bus/pci/pcivar.h>
50 #include <machine/clock.h>
55 #include <netgraph/ng_message.h>
56 #include <netgraph/netgraph.h>
59 static int mn_maxlatency
= 1000;
60 SYSCTL_INT(_debug
, OID_AUTO
, mn_maxlatency
, CTLFLAG_RW
,
62 "The number of milliseconds a packet is allowed to spend in the output queue. "
63 "If the output queue is longer than this number of milliseconds when the packet "
64 "arrives for output, the packet will be dropped."
68 /* Most machines don't support more than 4 busmaster PCI slots, if even that many */
72 /* From: PEB 20321 data sheet, p187, table 22 */
74 u_int32_t conf
, cmd
, stat
, imask
;
75 u_int32_t fill10
, piqba
, piql
, fill1c
;
76 u_int32_t mode1
, mode2
, ccba
, txpoll
;
77 u_int32_t tiqba
, tiql
, riqba
, riql
;
78 u_int32_t lconf
, lccba
, fill48
, ltran
;
79 u_int32_t ltiqba
, ltiql
, lriqba
, lriql
;
80 u_int32_t lreg0
, lreg1
, lreg2
, lreg3
;
81 u_int32_t lreg4
, lreg5
, lre6
, lstat
;
82 u_int32_t gpdir
, gpdata
, gpod
, fill8c
;
83 u_int32_t ssccon
, sscbr
, ssctb
, sscrb
;
84 u_int32_t ssccse
, sscim
, fillab
, fillac
;
85 u_int32_t iomcon1
, iomcon2
, iomstat
, fillbc
;
86 u_int32_t iomcit0
, iomcit1
, iomcir0
, iomcir1
;
87 u_int32_t iomtmo
, iomrmo
, filld8
, filldc
;
88 u_int32_t mbcmd
, mbdata1
, mbdata2
, mbdata3
;
89 u_int32_t mbdata4
, mbdata5
, mbdata6
, mbdata7
;
92 /* From: PEB 2254 data sheet, p80, table 10 */
95 u_int8_t cmdr
, mode
, rah1
, rah2
, ral1
, ral2
;
96 u_int8_t ipc
, ccr1
, ccr3
, pre
, rtr1
, rtr2
, rtr3
, rtr4
;
97 u_int8_t ttr1
, ttr2
, ttr3
, ttr4
, imr0
, imr1
, imr2
, imr3
;
98 u_int8_t imr4
, fill19
, fmr0
, fmr1
, fmr2
, loop
, xsw
, xsp
;
99 u_int8_t xc0
, xc1
, rc0
, rc1
, xpm0
, xpm1
, xpm2
, tswm
;
100 u_int8_t test1
, idle
, xsa4
, xsa5
, xsa6
, xsa7
, xsa8
, fmr3
;
101 u_int8_t icb1
, icb2
, icb3
, icb4
, lim0
, lim1
, pcd
, pcr
;
102 u_int8_t lim2
, fill39
[7];
107 u_int8_t dec
, fill61
, test2
, fill63
[5];
112 /* From: PEB 2254 data sheet, p117, table 10 */
115 u_int8_t fill2
, mode
, rah1
, rah2
, ral1
, ral2
;
116 u_int8_t ipc
, ccr1
, ccr3
, pre
, rtr1
, rtr2
, rtr3
, rtr4
;
117 u_int8_t ttr1
, ttr2
, ttr3
, ttr4
, imr0
, imr1
, imr2
, imr3
;
118 u_int8_t imr4
, fill19
, fmr0
, fmr1
, fmr2
, loop
, xsw
, xsp
;
119 u_int8_t xc0
, xc1
, rc0
, rc1
, xpm0
, xpm1
, xpm2
, tswm
;
120 u_int8_t test
, idle
, xsa4
, xsa5
, xsa6
, xsa7
, xsa8
, fmr13
;
121 u_int8_t icb1
, icb2
, icb3
, icb4
, lim0
, lim1
, pcd
, pcr
;
122 u_int8_t lim2
, fill39
[7];
124 u_int8_t fill48
[4], frs0
, frs1
, rsw
, rsp
;
125 u_int16_t fec
, cvc
, cec1
, ebc
;
126 u_int16_t cec2
, cec3
;
127 u_int8_t rsa4
, rsa5
, rsa6
, rsa7
;
128 u_int8_t rsa8
, rsa6s
, tsr0
, tsr1
, sis
, rsis
;
130 u_int8_t isr0
, isr1
, isr2
, isr3
, fill6c
, fill6d
, gis
, vstr
;
134 /* Transmit & receive descriptors */
139 u_int32_t status
; /* only used for receive */
140 struct mbuf
*m
; /* software use only */
141 struct trxd
*vnext
; /* software use only */
144 /* Channel specification */
155 u_int32_t reserve1
[2];
156 u_int32_t ts
[M32_TS
];
157 struct cspec cs
[M32_CHAN
];
158 vm_offset_t crxd
[M32_CHAN
];
159 vm_offset_t ctxd
[M32_CHAN
];
166 static int mn_probe (device_t self
);
167 static int mn_attach (device_t self
);
168 static void mn_create_channel(struct softc
*sc
, int chan
);
169 static int mn_reset(struct softc
*sc
);
170 static struct trxd
* mn_alloc_desc(void);
171 static void mn_free_desc(struct trxd
*dp
);
172 static void mn_intr(void *xsc
);
173 static u_int32_t
mn_parse_ts(const char *s
, int *nbit
);
175 static void m32_dump(struct softc
*sc
);
176 static void f54_dump(struct softc
*sc
);
177 static void mn_fmt_ts(char *p
, u_int32_t ts
);
179 static void f54_init(struct softc
*sc
);
181 static ng_constructor_t ngmn_constructor
;
182 static ng_rcvmsg_t ngmn_rcvmsg
;
183 static ng_shutdown_t ngmn_shutdown
;
184 static ng_newhook_t ngmn_newhook
;
185 static ng_connect_t ngmn_connect
;
186 static ng_rcvdata_t ngmn_rcvdata
;
187 static ng_disconnect_t ngmn_disconnect
;
189 static struct ng_type mntypestruct
= {
205 static MALLOC_DEFINE(M_MN
, "mn", "Mx driver related");
210 enum {DOWN
, UP
} state
;
215 struct trxd
*r1
, *rl
;
216 struct trxd
*x1
, *xl
;
227 u_long dribble_error
;
230 u_long overflow_error
;
239 enum framing
{WHOKNOWS
, E1
, E1U
, T1
, T1U
};
244 struct resource
*irq
;
246 enum framing framing
;
249 vm_offset_t m0p
, m1p
;
250 struct m32xreg
*m32x
;
251 struct f54wreg
*f54w
;
252 struct f54rreg
*f54r
;
253 struct m32_mem m32_mem
;
254 u_int32_t tiqb
[NIQB
];
255 u_int32_t riqb
[NIQB
];
256 u_int32_t piqb
[NIQB
];
257 u_int32_t ltiqb
[NIQB
];
258 u_int32_t lriqb
[NIQB
];
260 u_int32_t falc_irq
, falc_state
, framer_state
;
261 struct schan
*ch
[M32_CHAN
];
262 char nodename
[NG_NODESIZ
];
275 ngmn_constructor(node_p
*nodep
)
282 ngmn_shutdown(node_p nodep
)
289 ngmn_config(node_p node
, char *set
, char *ret
)
292 enum framing wframing
;
297 if (!strncmp(set
, "line ", 5)) {
298 wframing
= sc
->framing
;
299 if (!strcmp(set
, "line e1")) {
301 } else if (!strcmp(set
, "line e1u")) {
304 strcat(ret
, "ENOGROK\n");
307 if (wframing
== sc
->framing
)
309 if (sc
->nhooks
> 0) {
310 ksprintf(ret
, "Cannot change line when %d hooks open\n", sc
->nhooks
);
313 sc
->framing
= wframing
;
320 kprintf("%s CONFIG SET [%s]\n", sc
->nodename
, set
);
321 strcat(ret
, "ENOGROK\n");
329 ngmn_rcvmsg(node_p node
, struct ng_mesg
*msg
, const char *retaddr
, struct ng_mesg
**resp
)
338 if (msg
->header
.typecookie
!= NGM_GENERIC_COOKIE
) {
341 FREE(msg
, M_NETGRAPH
);
345 if (msg
->header
.cmd
!= NGM_TEXT_CONFIG
&&
346 msg
->header
.cmd
!= NGM_TEXT_STATUS
) {
349 FREE(msg
, M_NETGRAPH
);
353 NG_MKRESPONSE(*resp
, msg
, sizeof(struct ng_mesg
) + NG_TEXTRESPONSE
,
356 FREE(msg
, M_NETGRAPH
);
360 if (msg
->header
.arglen
)
361 s
= (char *)msg
->data
;
364 r
= (char *)(*resp
)->data
;
367 if (msg
->header
.cmd
== NGM_TEXT_CONFIG
) {
368 ngmn_config(node
, s
, r
);
369 (*resp
)->header
.arglen
= strlen(r
) + 1;
370 FREE(msg
, M_NETGRAPH
);
375 pos
+= ksprintf(pos
+ r
,"Framer status %b;\n", sc
->framer_state
, "\20"
376 "\40LOS\37AIS\36LFA\35RRA"
377 "\34AUXP\33NMF\32LMFA\31frs0.0"
378 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS"
379 "\24TS16LFA\23frs1.2\22XLS\21XLO"
380 "\20RS1\17rsw.6\16RRA\15RY0"
381 "\14RY1\13RY2\12RY3\11RY4"
382 "\10SI1\7SI2\6rsp.5\5rsp.4"
383 "\4rsp.3\3RSIF\2RS13\1RS15");
384 pos
+= ksprintf(pos
+ r
," Framing errors: %lu", sc
->cnt_fec
);
385 pos
+= ksprintf(pos
+ r
," Code Violations: %lu\n", sc
->cnt_cvc
);
387 pos
+= ksprintf(pos
+ r
," Falc State %b;\n", sc
->falc_state
, "\20"
388 "\40LOS\37AIS\36LFA\35RRA"
389 "\34AUXP\33NMF\32LMFA\31frs0.0"
390 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS"
391 "\24TS16LFA\23frs1.2\22XLS\21XLO"
392 "\20RS1\17rsw.6\16RRA\15RY0"
393 "\14RY1\13RY2\12RY3\11RY4"
394 "\10SI1\7SI2\6rsp.5\5rsp.4"
395 "\4rsp.3\3RSIF\2RS13\1RS15");
396 pos
+= ksprintf(pos
+ r
, " Falc IRQ %b\n", sc
->falc_irq
, "\20"
397 "\40RME\37RFS\36T8MS\35RMB\34CASC\33CRC4\32SA6SC\31RPF"
398 "\30b27\27RDO\26ALLS\25XDU\24XMB\23b22\22XLSC\21XPR"
399 "\20FAR\17LFA\16MFAR\15T400MS\14AIS\13LOS\12RAR\11RA"
400 "\10ES\7SEC\6LMFA16\5AIS16\4RA16\3API\2SLN\1SLP");
401 for (i
= 0; i
< M32_CHAN
; i
++) {
406 pos
+= ksprintf(r
+ pos
, " Chan %d <%s> ",
409 pos
+= ksprintf(r
+ pos
, " Last Rx: ");
411 pos
+= ksprintf(r
+ pos
, "%lu s", time_second
- sch
->last_recv
);
413 pos
+= ksprintf(r
+ pos
, "never");
415 pos
+= ksprintf(r
+ pos
, ", last RxErr: ");
417 pos
+= ksprintf(r
+ pos
, "%lu s", time_second
- sch
->last_rxerr
);
419 pos
+= ksprintf(r
+ pos
, "never");
421 pos
+= ksprintf(r
+ pos
, ", last Tx: ");
423 pos
+= ksprintf(r
+ pos
, "%lu s\n", time_second
- sch
->last_xmit
);
425 pos
+= ksprintf(r
+ pos
, "never\n");
427 pos
+= ksprintf(r
+ pos
, " RX error(s) %lu", sch
->rx_error
);
428 pos
+= ksprintf(r
+ pos
, " Short: %lu", sch
->short_error
);
429 pos
+= ksprintf(r
+ pos
, " CRC: %lu", sch
->crc_error
);
430 pos
+= ksprintf(r
+ pos
, " Mod8: %lu", sch
->dribble_error
);
431 pos
+= ksprintf(r
+ pos
, " Long: %lu", sch
->long_error
);
432 pos
+= ksprintf(r
+ pos
, " Abort: %lu", sch
->abort_error
);
433 pos
+= ksprintf(r
+ pos
, " Overflow: %lu\n", sch
->overflow_error
);
435 pos
+= ksprintf(r
+ pos
, " Last error: %b Prev error: %b\n",
436 sch
->last_error
, "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN",
437 sch
->prev_error
, "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN");
438 pos
+= ksprintf(r
+ pos
, " Xmit bytes pending %ld\n",
441 (*resp
)->header
.arglen
= pos
+ 1;
442 FREE(msg
, M_NETGRAPH
);
447 ngmn_newhook(node_p node
, hook_p hook
, const char *name
)
455 if (name
[0] != 't' || name
[1] != 's')
458 ts
= mn_parse_ts(name
+ 2, &nbit
);
459 kprintf("%d bits %x\n", nbit
, ts
);
460 if (sc
->framing
== E1
&& (ts
& 1))
462 if (sc
->framing
== E1U
&& nbit
!= 32)
466 if (sc
->framing
== E1
)
471 mn_create_channel(sc
, chan
);
472 else if (sc
->ch
[chan
]->state
== UP
)
474 sc
->ch
[chan
]->ts
= ts
;
475 sc
->ch
[chan
]->hook
= hook
;
476 sc
->ch
[chan
]->tx_limit
= nbit
* 8;
477 hook
->private = sc
->ch
[chan
];
483 static struct trxd
*mn_desc_free
;
492 mn_desc_free
= dp
->vnext
;
494 dp
= (struct trxd
*)kmalloc(sizeof *dp
, M_MN
, M_INTWAIT
);
499 mn_free_desc(struct trxd
*dp
)
501 dp
->vnext
= mn_desc_free
;
506 mn_parse_ts(const char *s
, int *nbit
)
516 i
= strtol(s
, &p
, 0);
519 while (j
!= -1 && j
< i
) {
529 } else if (*p
== '-') {
544 mn_fmt_ts(char *p
, u_int32_t ts
)
551 for (j
= 0; j
< 32; j
++) {
552 if (!(ts
& (1 << j
)))
554 ksprintf(p
, "%s%d", s
, j
);
557 if (!(ts
& (1 << (j
+1))))
560 if (!(ts
& (1 << (j
+1))))
562 ksprintf(p
, "-%d", j
);
574 ngmn_rcvdata(hook_p hook
, struct mbuf
*m
, meta_p meta
)
577 struct trxd
*dp
, *dp2
;
580 int chan
, pitch
, len
;
586 if (sch
->state
!= UP
) {
587 NG_FREE_DATA(m
, meta
);
590 if (sch
->tx_pending
+ m
->m_pkthdr
.len
> sch
->tx_limit
* mn_maxlatency
) {
591 NG_FREE_DATA(m
, meta
);
597 dp2
= sc
->ch
[chan
]->xl
;
598 len
= m
->m_pkthdr
.len
;
600 dp
= mn_alloc_desc();
604 sc
->ch
[chan
]->xl
= dp2
;
611 sc
->ch
[chan
]->xl
->vnext
= 0;
614 dp
->data
= vtophys(m2
->m_data
);
615 dp
->flags
= m2
->m_len
<< 16;
618 dp
->next
= vtophys(dp
);
620 sc
->ch
[chan
]->xl
->next
= vtophys(dp
);
621 sc
->ch
[chan
]->xl
->vnext
= dp
;
622 sc
->ch
[chan
]->xl
= dp
;
625 dp
->flags
|= 0xc0000000;
626 dp2
->flags
&= ~0x40000000;
633 kprintf("%s%d: Short on mem, pitched %d packets\n",
634 sc
->name
, chan
, pitch
);
637 kprintf("%d = %d + %d (%p)\n",
638 sch
->tx_pending
+ m
->m_pkthdr
.len
,
639 sch
->tx_pending
, m
->m_pkthdr
.len
, m
);
641 sch
->tx_pending
+= m
->m_pkthdr
.len
;
642 sc
->m32x
->txpoll
&= ~(1 << chan
);
651 ngmn_connect(hook_p hook
)
654 struct trxd
*dp
, *dp2
;
664 if (sch
->state
== UP
)
668 /* Count and configure the timeslots for this channel */
669 for (nts
= i
= 0; i
< 32; i
++)
670 if (sch
->ts
& (1 << i
)) {
671 sc
->m32_mem
.ts
[i
] = 0x00ff00ff |
672 (chan
<< 24) | (chan
<< 8);
676 /* Init the receiver & xmitter to HDLC */
677 sc
->m32_mem
.cs
[chan
].flags
= 0x80e90006;
678 /* Allocate two buffers per timeslot */
680 sc
->m32_mem
.cs
[chan
].itbs
= 63;
682 sc
->m32_mem
.cs
[chan
].itbs
= nts
* 2;
684 /* Setup a transmit chain with one descriptor */
685 /* XXX: we actually send a 1 byte packet */
686 dp
= mn_alloc_desc();
687 MGETHDR(m
, MB_WAIT
, MT_DATA
);
692 dp
->flags
= 0xc0000000 + (1 << 16);
693 dp
->next
= vtophys(dp
);
695 dp
->data
= vtophys(sc
->name
);
696 sc
->m32_mem
.cs
[chan
].tdesc
= vtophys(dp
);
697 sc
->ch
[chan
]->x1
= dp
;
698 sc
->ch
[chan
]->xl
= dp
;
700 /* Setup a receive chain with 5 + NTS descriptors */
702 dp
= mn_alloc_desc();
704 MGETHDR(m
, MB_WAIT
, MT_DATA
);
710 if ((m
->m_flags
& M_EXT
) == 0) {
716 dp
->data
= vtophys(m
->m_data
);
717 dp
->flags
= 0x40000000;
718 dp
->flags
+= 1600 << 16;
719 dp
->next
= vtophys(dp
);
721 sc
->ch
[chan
]->rl
= dp
;
723 for (i
= 0; i
< (nts
+ 10); i
++) {
725 dp
= mn_alloc_desc();
727 MGETHDR(m
, MB_WAIT
, MT_DATA
);
734 if ((m
->m_flags
& M_EXT
) == 0) {
740 dp
->data
= vtophys(m
->m_data
);
741 dp
->flags
= 0x00000000;
742 dp
->flags
+= 1600 << 16;
743 dp
->next
= vtophys(dp2
);
746 sc
->m32_mem
.cs
[chan
].rdesc
= vtophys(dp
);
747 sc
->ch
[chan
]->r1
= dp
;
749 /* Initialize this channel */
750 sc
->m32_mem
.ccb
= 0x00008000 + (chan
<< 8);
755 kprintf("%s: init chan %d stat %08x\n", sc
->name
, chan
, u
);
765 ngmn_disconnect(hook_p hook
)
770 struct trxd
*dp
, *dp2
;
777 if (sch
->state
== DOWN
)
781 /* Set receiver & transmitter off */
782 sc
->m32_mem
.cs
[chan
].flags
= 0x80920006;
783 sc
->m32_mem
.cs
[chan
].itbs
= 0;
785 /* free the timeslots */
786 for (i
= 0; i
< 32; i
++)
787 if (sc
->ch
[chan
]->ts
& (1 << i
))
788 sc
->m32_mem
.ts
[i
] = 0x20002000;
790 /* Initialize this channel */
791 sc
->m32_mem
.ccb
= 0x00008000 + (chan
<< 8);
796 kprintf("%s: zap chan %d stat %08x\n", sc
->name
, chan
, u
);
799 /* Free all receive descriptors and mbufs */
800 for (dp
= sc
->ch
[chan
]->r1
; dp
; dp
= dp2
) {
803 sc
->ch
[chan
]->r1
= dp2
= dp
->vnext
;
807 /* Free all transmit descriptors and mbufs */
808 for (dp
= sc
->ch
[chan
]->x1
; dp
; dp
= dp2
) {
810 sc
->ch
[chan
]->tx_pending
-= dp
->m
->m_pkthdr
.len
;
813 sc
->ch
[chan
]->x1
= dp2
= dp
->vnext
;
821 * Create a new channel.
824 mn_create_channel(struct softc
*sc
, int chan
)
828 sch
= sc
->ch
[chan
] = (struct schan
*)kmalloc(sizeof *sc
->ch
[chan
],
829 M_MN
, M_WAITOK
| M_ZERO
);
833 ksprintf(sch
->name
, "%s%d", sc
->name
, chan
);
839 * Dump Munich32x state
842 m32_dump(struct softc
*sc
)
847 kprintf("mn%d: MUNICH32X dump\n", sc
->unit
);
848 tp4
= (u_int32_t
*)sc
->m0v
;
849 for(j
= 0; j
< 64; j
+= 8) {
850 kprintf("%02x", j
* sizeof *tp4
);
851 for(i
= 0; i
< 8; i
++)
852 kprintf(" %08x", tp4
[i
+j
]);
855 for(j
= 0; j
< M32_CHAN
; j
++) {
858 kprintf("CH%d: state %d ts %08x",
859 j
, sc
->ch
[j
]->state
, sc
->ch
[j
]->ts
);
860 kprintf(" %08x %08x %08x %08x %08x %08x\n",
861 sc
->m32_mem
.cs
[j
].flags
,
862 sc
->m32_mem
.cs
[j
].rdesc
,
863 sc
->m32_mem
.cs
[j
].tdesc
,
864 sc
->m32_mem
.cs
[j
].itbs
,
866 sc
->m32_mem
.ctxd
[j
] );
874 f54_dump(struct softc
*sc
)
879 kprintf("%s: FALC54 dump\n", sc
->name
);
880 tp1
= (u_int8_t
*)sc
->m1v
;
881 for(j
= 0; j
< 128; j
+= 16) {
882 kprintf("%s: %02x |", sc
->name
, j
* sizeof *tp1
);
883 for(i
= 0; i
< 16; i
++)
884 kprintf(" %02x", tp1
[i
+j
]);
894 m32_init(struct softc
*sc
)
897 sc
->m32x
->conf
= 0x00000000;
898 sc
->m32x
->mode1
= 0x81048000 + 1600; /* XXX: temp */
900 sc
->m32x
->mode2
= 0x00000081;
901 sc
->m32x
->txpoll
= 0xffffffff;
903 sc
->m32x
->mode2
= 0x00000081;
904 sc
->m32x
->txpoll
= 0xffffffff;
906 sc
->m32x
->mode2
= 0x00000101;
908 sc
->m32x
->lconf
= 0x6060009B;
909 sc
->m32x
->imask
= 0x00000000;
916 f54_init(struct softc
*sc
)
918 sc
->f54w
->ipc
= 0x07;
920 sc
->f54w
->xpm0
= 0xbd;
921 sc
->f54w
->xpm1
= 0x03;
922 sc
->f54w
->xpm2
= 0x00;
924 sc
->f54w
->imr0
= 0x18; /* RMB, CASC */
925 sc
->f54w
->imr1
= 0x08; /* XMB */
926 sc
->f54w
->imr2
= 0x00;
927 sc
->f54w
->imr3
= 0x38; /* LMFA16, AIS16, RA16 */
928 sc
->f54w
->imr4
= 0x00;
930 sc
->f54w
->fmr0
= 0xf0; /* X: HDB3, R: HDB3 */
931 sc
->f54w
->fmr1
= 0x0e; /* Send CRC4, 2Mbit, ECM */
932 if (sc
->framing
== E1
)
933 sc
->f54w
->fmr2
= 0x03; /* Auto Rem-Alarm, Auto resync */
934 else if (sc
->framing
== E1U
)
935 sc
->f54w
->fmr2
= 0x33; /* dais, rtm, Auto Rem-Alarm, Auto resync */
937 sc
->f54w
->lim1
= 0xb0; /* XCLK=8kHz, .62V threshold */
938 sc
->f54w
->pcd
= 0x0a;
939 sc
->f54w
->pcr
= 0x15;
940 sc
->f54w
->xsw
= 0x9f; /* fmr4 */
941 if (sc
->framing
== E1
)
942 sc
->f54w
->xsp
= 0x1c; /* fmr5 */
943 else if (sc
->framing
== E1U
)
944 sc
->f54w
->xsp
= 0x3c; /* tt0, fmr5 */
945 sc
->f54w
->xc0
= 0x07;
946 sc
->f54w
->xc1
= 0x3d;
947 sc
->f54w
->rc0
= 0x05;
948 sc
->f54w
->rc1
= 0x00;
949 sc
->f54w
->cmdr
= 0x51;
953 mn_reset(struct softc
*sc
)
958 sc
->m32x
->ccba
= vtophys(&sc
->m32_mem
.csa
);
959 sc
->m32_mem
.csa
= vtophys(&sc
->m32_mem
.ccb
);
961 bzero(sc
->tiqb
, sizeof sc
->tiqb
);
962 sc
->m32x
->tiqba
= vtophys(&sc
->tiqb
);
963 sc
->m32x
->tiql
= NIQB
/ 16 - 1;
965 bzero(sc
->riqb
, sizeof sc
->riqb
);
966 sc
->m32x
->riqba
= vtophys(&sc
->riqb
);
967 sc
->m32x
->riql
= NIQB
/ 16 - 1;
969 bzero(sc
->ltiqb
, sizeof sc
->ltiqb
);
970 sc
->m32x
->ltiqba
= vtophys(&sc
->ltiqb
);
971 sc
->m32x
->ltiql
= NIQB
/ 16 - 1;
973 bzero(sc
->lriqb
, sizeof sc
->lriqb
);
974 sc
->m32x
->lriqba
= vtophys(&sc
->lriqb
);
975 sc
->m32x
->lriql
= NIQB
/ 16 - 1;
977 bzero(sc
->piqb
, sizeof sc
->piqb
);
978 sc
->m32x
->piqba
= vtophys(&sc
->piqb
);
979 sc
->m32x
->piql
= NIQB
/ 16 - 1;
986 sc
->m32_mem
.ccb
= 0x4;
992 /* set all timeslots to known state */
993 for (i
= 0; i
< 32; i
++)
994 sc
->m32_mem
.ts
[i
] = 0x20002000;
998 "mn%d: WARNING: Controller failed the PCI bus-master test.\n"
999 "mn%d: WARNING: Use a PCI slot which can support bus-master cards.\n",
1000 sc
->unit
, sc
->unit
);
1007 * FALC54 interrupt handling
1010 f54_intr(struct softc
*sc
)
1015 u
= sc
->f54r
->isr0
<< 24;
1016 u
|= sc
->f54r
->isr1
<< 16;
1017 u
|= sc
->f54r
->isr2
<< 8;
1018 u
|= sc
->f54r
->isr3
;
1020 /* don't chat about the 1 sec heart beat */
1023 kprintf("%s*: FALC54 IRQ GIS:%02x %b\n", sc
->name
, g
, u
, "\20"
1024 "\40RME\37RFS\36T8MS\35RMB\34CASC\33CRC4\32SA6SC\31RPF"
1025 "\30b27\27RDO\26ALLS\25XDU\24XMB\23b22\22XLSC\21XPR"
1026 "\20FAR\17LFA\16MFAR\15T400MS\14AIS\13LOS\12RAR\11RA"
1027 "\10ES\7SEC\6LMFA16\5AIS16\4RA16\3API\2SLN\1SLP");
1029 s
= sc
->f54r
->frs0
<< 24;
1030 s
|= sc
->f54r
->frs1
<< 16;
1031 s
|= sc
->f54r
->rsw
<< 8;
1035 s
&= ~0x01844038; /* undefined or static bits */
1036 s
&= ~0x00009fc7; /* bits we don't care about */
1037 s
&= ~0x00780000; /* XXX: TS16 related */
1038 s
&= ~0x06000000; /* XXX: Multiframe related */
1040 kprintf("%s*: FALC54 Status %b\n", sc
->name
, s
, "\20"
1041 "\40LOS\37AIS\36LFA\35RRA\34AUXP\33NMF\32LMFA\31frs0.0"
1042 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS\24TS16LFA\23frs1.2\22XLS\21XLO"
1043 "\20RS1\17rsw.6\16RRA\15RY0\14RY1\13RY2\12RY3\11RY4"
1044 "\10SI1\7SI2\6rsp.5\5rsp.4\4rsp.3\3RSIF\2RS13\1RS15");
1046 if (s
!= sc
->framer_state
) {
1048 for (i
= 0; i
< M32_CHAN
; i
++) {
1051 sp
= &sc
->ch
[i
]->ifsppp
;
1052 if (!(sp
->pp_if
.if_flags
& IFF_UP
))
1055 timeout((timeout_t
*)sp
->pp_down
, sp
, 1 * hz
);
1057 timeout((timeout_t
*)sp
->pp_up
, sp
, 1 * hz
);
1060 sc
->framer_state
= s
;
1063 /* Once per second check error counters */
1064 /* XXX: not clear if this is actually ok */
1067 sc
->cnt_fec
+= sc
->f54r
->fec
;
1068 sc
->cnt_cvc
+= sc
->f54r
->cvc
;
1069 sc
->cnt_cec1
+= sc
->f54r
->cec1
;
1070 sc
->cnt_ebc
+= sc
->f54r
->ebc
;
1071 sc
->cnt_cec2
+= sc
->f54r
->cec2
;
1072 sc
->cnt_cec3
+= sc
->f54r
->cec3
;
1073 sc
->cnt_rbc
+= sc
->f54r
->rbc
;
1077 * Transmit interrupt for one channel
1080 mn_tx_intr(struct softc
*sc
, u_int32_t vector
)
1086 chan
= vector
& 0x1f;
1089 if (sc
->ch
[chan
]->state
!= UP
) {
1090 kprintf("%s: tx_intr when not UP\n", sc
->name
);
1094 dp
= sc
->ch
[chan
]->x1
;
1095 if (vtophys(dp
) == sc
->m32_mem
.ctxd
[chan
])
1100 kprintf("%d = %d - %d (%p)\n",
1101 sc
->ch
[chan
]->tx_pending
- m
->m_pkthdr
.len
,
1102 sc
->ch
[chan
]->tx_pending
, m
->m_pkthdr
.len
, m
);
1104 sc
->ch
[chan
]->tx_pending
-= m
->m_pkthdr
.len
;
1107 sc
->ch
[chan
]->last_xmit
= time_second
;
1108 sc
->ch
[chan
]->x1
= dp
->vnext
;
1114 * Receive interrupt for one channel
1117 mn_rx_intr(struct softc
*sc
, u_int32_t vector
)
1119 u_int32_t chan
, err
;
1124 chan
= vector
& 0x1f;
1128 if (sch
->state
!= UP
) {
1129 kprintf("%s: rx_intr when not UP\n", sc
->name
);
1133 if (vector
== 0x30000b00)
1137 if (vtophys(dp
) == sc
->m32_mem
.crxd
[chan
])
1141 m
->m_pkthdr
.len
= m
->m_len
= (dp
->status
>> 16) & 0x1fff;
1142 err
= (dp
->status
>> 8) & 0xff;
1144 ng_queue_data(sch
->hook
, m
, NULL
);
1145 sch
->last_recv
= time_second
;
1147 /* we could be down by now... */
1148 if (sch
->state
!= UP
)
1150 } else if (err
& 0x40) {
1152 } else if (err
& 0x10) {
1154 } else if (err
& 0x08) {
1155 sch
->dribble_error
++;
1156 } else if (err
& 0x04) {
1158 } else if (err
& 0x02) {
1160 } else if (err
& 0x01) {
1161 sch
->overflow_error
++;
1164 sch
->last_rxerr
= time_second
;
1165 sch
->prev_error
= sch
->last_error
;
1166 sch
->last_error
= err
;
1169 sc
->ch
[chan
]->r1
= dp
->vnext
;
1171 /* Replenish desc + mbuf supplies */
1173 MGETHDR(m
, MB_DONTWAIT
, MT_DATA
);
1176 return; /* ENOBUFS */
1178 MCLGET(m
, MB_DONTWAIT
);
1179 if((m
->m_flags
& M_EXT
) == 0) {
1182 return; /* ENOBUFS */
1186 dp
->data
= vtophys(m
->m_data
);
1187 dp
->flags
= 0x40000000;
1188 dp
->flags
+= 1600 << 16;
1189 dp
->next
= vtophys(dp
);
1191 sc
->ch
[chan
]->rl
->next
= vtophys(dp
);
1192 sc
->ch
[chan
]->rl
->vnext
= dp
;
1193 sc
->ch
[chan
]->rl
->flags
&= ~0x40000000;
1194 sc
->ch
[chan
]->rl
= dp
;
1207 u_int32_t stat
, lstat
, u
;
1211 stat
= sc
->m32x
->stat
;
1212 lstat
= sc
->m32x
->lstat
;
1214 if (!stat
&& !(lstat
& 2))
1218 if (stat
& ~0xc200) {
1219 kprintf("%s: I stat=%08x lstat=%08x\n", sc
->name
, stat
, lstat
);
1222 if ((stat
& 0x200) || (lstat
& 2))
1225 for (j
= i
= 0; i
< 64; i
++) {
1230 if ((u
& ~0x1f) == 0x30000800 || (u
& ~0x1f) == 0x30000b00)
1232 u
&= ~0x30000400; /* bits we don't care about */
1233 if ((u
& ~0x1f) == 0x00000900)
1238 kprintf("%s*: RIQB:", sc
->name
);
1239 kprintf(" [%d]=%08x", i
, u
);
1246 for (j
= i
= 0; i
< 64; i
++) {
1251 if ((u
& ~0x1f) == 0x20000800)
1253 u
&= ~0x20000000; /* bits we don't care about */
1257 kprintf("%s*: TIQB:", sc
->name
);
1258 kprintf(" [%d]=%08x", i
, u
);
1264 sc
->m32x
->stat
= stat
;
1268 * PCI initialization stuff
1272 mn_probe (device_t self
)
1274 u_int id
= pci_get_devid(self
);
1276 if (sizeof (struct m32xreg
) != 256) {
1277 kprintf("MN: sizeof(struct m32xreg) = %d, should have been 256\n", sizeof (struct m32xreg
));
1280 if (sizeof (struct f54rreg
) != 128) {
1281 kprintf("MN: sizeof(struct f54rreg) = %d, should have been 128\n", sizeof (struct f54rreg
));
1284 if (sizeof (struct f54wreg
) != 128) {
1285 kprintf("MN: sizeof(struct f54wreg) = %d, should have been 128\n", sizeof (struct f54wreg
));
1289 if (id
!= 0x2101110a)
1292 device_set_desc_copy(self
, "Munich32X E1/T1 HDLC Controller");
1297 mn_attach (device_t self
)
1304 struct resource
*res
;
1307 if (ng_newtype(&mntypestruct
))
1308 kprintf("ng_newtype failed\n");
1312 sc
= (struct softc
*)kmalloc(sizeof *sc
, M_MN
, M_WAITOK
| M_ZERO
);
1313 device_set_softc(self
, sc
);
1316 sc
->unit
= device_get_unit(self
);
1318 ksprintf(sc
->name
, "mn%d", sc
->unit
);
1321 res
= bus_alloc_resource_any(self
, SYS_RES_MEMORY
, &rid
, RF_ACTIVE
);
1323 device_printf(self
, "Could not map memory\n");
1326 sc
->m0v
= rman_get_virtual(res
);
1327 sc
->m0p
= rman_get_start(res
);
1329 rid
= PCIR_MAPS
+ 4;
1330 res
= bus_alloc_resource_any(self
, SYS_RES_MEMORY
, &rid
, RF_ACTIVE
);
1332 device_printf(self
, "Could not map memory\n");
1335 sc
->m1v
= rman_get_virtual(res
);
1336 sc
->m1p
= rman_get_start(res
);
1338 /* Allocate interrupt */
1340 sc
->irq
= bus_alloc_resource_any(self
, SYS_RES_IRQ
, &rid
,
1341 RF_SHAREABLE
| RF_ACTIVE
);
1343 if (sc
->irq
== NULL
) {
1344 kprintf("couldn't map interrupt\n");
1348 error
= bus_setup_intr(self
, sc
->irq
, INTR_NETSAFE
, mn_intr
, sc
,
1349 &sc
->intrhand
, NULL
);
1352 kprintf("couldn't set up irq\n");
1356 u
= pci_read_config(self
, PCIR_COMMAND
, 1);
1358 pci_write_config(self
, PCIR_COMMAND
, u
| PCIM_CMD_PERRESPEN
| PCIM_CMD_BUSMASTEREN
| PCIM_CMD_MEMEN
, 1);
1360 pci_write_config(self
, PCIR_COMMAND
, 0x02800046, 4);
1362 u
= pci_read_config(self
, PCIR_COMMAND
, 1);
1365 ver
= pci_get_revid(self
);
1367 sc
->m32x
= (struct m32xreg
*) sc
->m0v
;
1368 sc
->f54w
= (struct f54wreg
*) sc
->m1v
;
1369 sc
->f54r
= (struct f54rreg
*) sc
->m1v
;
1371 /* We must reset before poking at FALC54 registers */
1376 kprintf("mn%d: Munich32X", sc
->unit
);
1379 kprintf(" Rev 2.2");
1382 kprintf(" Rev 0x%x\n", ver
);
1384 kprintf(", Falc54");
1385 switch (sc
->f54r
->vstr
) {
1387 kprintf(" Rev < 1.3\n");
1390 kprintf(" Rev 1.3\n");
1393 kprintf(" Rev 1.4\n");
1396 kprintf("-LH Rev 1.1\n");
1399 kprintf("-LH Rev 1.3\n");
1402 kprintf(" Rev 0x%x\n", sc
->f54r
->vstr
);
1405 if (ng_make_node_common(&mntypestruct
, &sc
->node
) != 0) {
1406 kprintf("ng_make_node_common failed\n");
1409 sc
->node
->private = sc
;
1410 ksprintf(sc
->nodename
, "%s%d", NG_MN_NODE_TYPE
, sc
->unit
);
1411 if (ng_name_node(sc
->node
, sc
->nodename
)) {
1412 ng_rmnode(sc
->node
);
1421 static device_method_t mn_methods
[] = {
1422 /* Device interface */
1423 DEVMETHOD(device_probe
, mn_probe
),
1424 DEVMETHOD(device_attach
, mn_attach
),
1425 DEVMETHOD(device_suspend
, bus_generic_suspend
),
1426 DEVMETHOD(device_resume
, bus_generic_resume
),
1427 DEVMETHOD(device_shutdown
, bus_generic_shutdown
),
1432 static driver_t mn_driver
= {
1438 static devclass_t mn_devclass
;
1440 DECLARE_DUMMY_MODULE(if_mn
);
1441 DRIVER_MODULE(if_mn
, pci
, mn_driver
, mn_devclass
, 0, 0);