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.9 2005/05/24 20:59:01 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/kernel.h>
39 #include <sys/sysctl.h>
42 #include <sys/systm.h>
43 #include <sys/malloc.h>
45 #include <bus/pci/pcireg.h>
46 #include <bus/pci/pcivar.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
51 #include <machine/clock.h>
58 #include <netgraph/ng_message.h>
59 #include <netgraph/netgraph.h>
62 static int mn_maxlatency = 1000;
63 SYSCTL_INT(_debug, OID_AUTO, mn_maxlatency, CTLFLAG_RW,
65 "The number of milliseconds a packet is allowed to spend in the output queue. "
66 "If the output queue is longer than this number of milliseconds when the packet "
67 "arrives for output, the packet will be dropped."
71 /* Most machines don't support more than 4 busmaster PCI slots, if even that many */
75 /* From: PEB 20321 data sheet, p187, table 22 */
77 u_int32_t conf, cmd, stat, imask;
78 u_int32_t fill10, piqba, piql, fill1c;
79 u_int32_t mode1, mode2, ccba, txpoll;
80 u_int32_t tiqba, tiql, riqba, riql;
81 u_int32_t lconf, lccba, fill48, ltran;
82 u_int32_t ltiqba, ltiql, lriqba, lriql;
83 u_int32_t lreg0, lreg1, lreg2, lreg3;
84 u_int32_t lreg4, lreg5, lre6, lstat;
85 u_int32_t gpdir, gpdata, gpod, fill8c;
86 u_int32_t ssccon, sscbr, ssctb, sscrb;
87 u_int32_t ssccse, sscim, fillab, fillac;
88 u_int32_t iomcon1, iomcon2, iomstat, fillbc;
89 u_int32_t iomcit0, iomcit1, iomcir0, iomcir1;
90 u_int32_t iomtmo, iomrmo, filld8, filldc;
91 u_int32_t mbcmd, mbdata1, mbdata2, mbdata3;
92 u_int32_t mbdata4, mbdata5, mbdata6, mbdata7;
95 /* From: PEB 2254 data sheet, p80, table 10 */
98 u_int8_t cmdr, mode, rah1, rah2, ral1, ral2;
99 u_int8_t ipc, ccr1, ccr3, pre, rtr1, rtr2, rtr3, rtr4;
100 u_int8_t ttr1, ttr2, ttr3, ttr4, imr0, imr1, imr2, imr3;
101 u_int8_t imr4, fill19, fmr0, fmr1, fmr2, loop, xsw, xsp;
102 u_int8_t xc0, xc1, rc0, rc1, xpm0, xpm1, xpm2, tswm;
103 u_int8_t test1, idle, xsa4, xsa5, xsa6, xsa7, xsa8, fmr3;
104 u_int8_t icb1, icb2, icb3, icb4, lim0, lim1, pcd, pcr;
105 u_int8_t lim2, fill39[7];
110 u_int8_t dec, fill61, test2, fill63[5];
115 /* From: PEB 2254 data sheet, p117, table 10 */
118 u_int8_t fill2, mode, rah1, rah2, ral1, ral2;
119 u_int8_t ipc, ccr1, ccr3, pre, rtr1, rtr2, rtr3, rtr4;
120 u_int8_t ttr1, ttr2, ttr3, ttr4, imr0, imr1, imr2, imr3;
121 u_int8_t imr4, fill19, fmr0, fmr1, fmr2, loop, xsw, xsp;
122 u_int8_t xc0, xc1, rc0, rc1, xpm0, xpm1, xpm2, tswm;
123 u_int8_t test, idle, xsa4, xsa5, xsa6, xsa7, xsa8, fmr13;
124 u_int8_t icb1, icb2, icb3, icb4, lim0, lim1, pcd, pcr;
125 u_int8_t lim2, fill39[7];
127 u_int8_t fill48[4], frs0, frs1, rsw, rsp;
128 u_int16_t fec, cvc, cec1, ebc;
129 u_int16_t cec2, cec3;
130 u_int8_t rsa4, rsa5, rsa6, rsa7;
131 u_int8_t rsa8, rsa6s, tsr0, tsr1, sis, rsis;
133 u_int8_t isr0, isr1, isr2, isr3, fill6c, fill6d, gis, vstr;
137 /* Transmit & receive descriptors */
142 u_int32_t status; /* only used for receive */
143 struct mbuf *m; /* software use only */
144 struct trxd *vnext; /* software use only */
147 /* Channel specification */
158 u_int32_t reserve1[2];
159 u_int32_t ts[M32_TS];
160 struct cspec cs[M32_CHAN];
161 vm_offset_t crxd[M32_CHAN];
162 vm_offset_t ctxd[M32_CHAN];
169 static int mn_probe (device_t self);
170 static int mn_attach (device_t self);
171 static void mn_create_channel(struct softc *sc, int chan);
172 static int mn_reset(struct softc *sc);
173 static struct trxd * mn_alloc_desc(void);
174 static void mn_free_desc(struct trxd *dp);
175 static void mn_intr(void *xsc);
176 static u_int32_t mn_parse_ts(const char *s, int *nbit);
178 static void m32_dump(struct softc *sc);
179 static void f54_dump(struct softc *sc);
180 static void mn_fmt_ts(char *p, u_int32_t ts);
182 static void f54_init(struct softc *sc);
184 static ng_constructor_t ngmn_constructor;
185 static ng_rcvmsg_t ngmn_rcvmsg;
186 static ng_shutdown_t ngmn_shutdown;
187 static ng_newhook_t ngmn_newhook;
188 static ng_connect_t ngmn_connect;
189 static ng_rcvdata_t ngmn_rcvdata;
190 static ng_disconnect_t ngmn_disconnect;
192 static struct ng_type mntypestruct = {
208 static MALLOC_DEFINE(M_MN, "mn", "Mx driver related");
213 enum {DOWN, UP} state;
218 struct trxd *r1, *rl;
219 struct trxd *x1, *xl;
230 u_long dribble_error;
233 u_long overflow_error;
242 enum framing {WHOKNOWS, E1, E1U, T1, T1U};
247 struct resource *irq;
249 enum framing framing;
252 vm_offset_t m0p, m1p;
253 struct m32xreg *m32x;
254 struct f54wreg *f54w;
255 struct f54rreg *f54r;
256 struct m32_mem m32_mem;
257 u_int32_t tiqb[NIQB];
258 u_int32_t riqb[NIQB];
259 u_int32_t piqb[NIQB];
260 u_int32_t ltiqb[NIQB];
261 u_int32_t lriqb[NIQB];
263 u_int32_t falc_irq, falc_state, framer_state;
264 struct schan *ch[M32_CHAN];
265 char nodename[NG_NODELEN + 1];
278 ngmn_constructor(node_p *nodep)
285 ngmn_shutdown(node_p nodep)
292 ngmn_config(node_p node, char *set, char *ret)
295 enum framing wframing;
300 if (!strncmp(set, "line ", 5)) {
301 wframing = sc->framing;
302 if (!strcmp(set, "line e1")) {
304 } else if (!strcmp(set, "line e1u")) {
307 strcat(ret, "ENOGROK\n");
310 if (wframing == sc->framing)
312 if (sc->nhooks > 0) {
313 sprintf(ret, "Cannot change line when %d hooks open\n", sc->nhooks);
316 sc->framing = wframing;
323 printf("%s CONFIG SET [%s]\n", sc->nodename, set);
324 strcat(ret, "ENOGROK\n");
332 ngmn_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, struct ng_mesg **resp)
341 if (msg->header.typecookie != NGM_GENERIC_COOKIE) {
344 FREE(msg, M_NETGRAPH);
348 if (msg->header.cmd != NGM_TEXT_CONFIG &&
349 msg->header.cmd != NGM_TEXT_STATUS) {
352 FREE(msg, M_NETGRAPH);
356 NG_MKRESPONSE(*resp, msg, sizeof(struct ng_mesg) + NG_TEXTRESPONSE,
359 FREE(msg, M_NETGRAPH);
363 if (msg->header.arglen)
364 s = (char *)msg->data;
367 r = (char *)(*resp)->data;
370 if (msg->header.cmd == NGM_TEXT_CONFIG) {
371 ngmn_config(node, s, r);
372 (*resp)->header.arglen = strlen(r) + 1;
373 FREE(msg, M_NETGRAPH);
378 pos += sprintf(pos + r,"Framer status %b;\n", sc->framer_state, "\20"
379 "\40LOS\37AIS\36LFA\35RRA"
380 "\34AUXP\33NMF\32LMFA\31frs0.0"
381 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS"
382 "\24TS16LFA\23frs1.2\22XLS\21XLO"
383 "\20RS1\17rsw.6\16RRA\15RY0"
384 "\14RY1\13RY2\12RY3\11RY4"
385 "\10SI1\7SI2\6rsp.5\5rsp.4"
386 "\4rsp.3\3RSIF\2RS13\1RS15");
387 pos += sprintf(pos + r," Framing errors: %lu", sc->cnt_fec);
388 pos += sprintf(pos + r," Code Violations: %lu\n", sc->cnt_cvc);
390 pos += sprintf(pos + r," Falc State %b;\n", sc->falc_state, "\20"
391 "\40LOS\37AIS\36LFA\35RRA"
392 "\34AUXP\33NMF\32LMFA\31frs0.0"
393 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS"
394 "\24TS16LFA\23frs1.2\22XLS\21XLO"
395 "\20RS1\17rsw.6\16RRA\15RY0"
396 "\14RY1\13RY2\12RY3\11RY4"
397 "\10SI1\7SI2\6rsp.5\5rsp.4"
398 "\4rsp.3\3RSIF\2RS13\1RS15");
399 pos += sprintf(pos + r, " Falc IRQ %b\n", sc->falc_irq, "\20"
400 "\40RME\37RFS\36T8MS\35RMB\34CASC\33CRC4\32SA6SC\31RPF"
401 "\30b27\27RDO\26ALLS\25XDU\24XMB\23b22\22XLSC\21XPR"
402 "\20FAR\17LFA\16MFAR\15T400MS\14AIS\13LOS\12RAR\11RA"
403 "\10ES\7SEC\6LMFA16\5AIS16\4RA16\3API\2SLN\1SLP");
404 for (i = 0; i < M32_CHAN; i++) {
409 pos += sprintf(r + pos, " Chan %d <%s> ",
412 pos += sprintf(r + pos, " Last Rx: ");
414 pos += sprintf(r + pos, "%lu s", time_second - sch->last_recv);
416 pos += sprintf(r + pos, "never");
418 pos += sprintf(r + pos, ", last RxErr: ");
420 pos += sprintf(r + pos, "%lu s", time_second - sch->last_rxerr);
422 pos += sprintf(r + pos, "never");
424 pos += sprintf(r + pos, ", last Tx: ");
426 pos += sprintf(r + pos, "%lu s\n", time_second - sch->last_xmit);
428 pos += sprintf(r + pos, "never\n");
430 pos += sprintf(r + pos, " RX error(s) %lu", sch->rx_error);
431 pos += sprintf(r + pos, " Short: %lu", sch->short_error);
432 pos += sprintf(r + pos, " CRC: %lu", sch->crc_error);
433 pos += sprintf(r + pos, " Mod8: %lu", sch->dribble_error);
434 pos += sprintf(r + pos, " Long: %lu", sch->long_error);
435 pos += sprintf(r + pos, " Abort: %lu", sch->abort_error);
436 pos += sprintf(r + pos, " Overflow: %lu\n", sch->overflow_error);
438 pos += sprintf(r + pos, " Last error: %b Prev error: %b\n",
439 sch->last_error, "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN",
440 sch->prev_error, "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN");
441 pos += sprintf(r + pos, " Xmit bytes pending %ld\n",
444 (*resp)->header.arglen = pos + 1;
445 FREE(msg, M_NETGRAPH);
450 ngmn_newhook(node_p node, hook_p hook, const char *name)
458 if (name[0] != 't' || name[1] != 's')
461 ts = mn_parse_ts(name + 2, &nbit);
462 printf("%d bits %x\n", nbit, ts);
463 if (sc->framing == E1 && (ts & 1))
465 if (sc->framing == E1U && nbit != 32)
469 if (sc->framing == E1)
474 mn_create_channel(sc, chan);
475 else if (sc->ch[chan]->state == UP)
477 sc->ch[chan]->ts = ts;
478 sc->ch[chan]->hook = hook;
479 sc->ch[chan]->tx_limit = nbit * 8;
480 hook->private = sc->ch[chan];
486 static struct trxd *mn_desc_free;
495 mn_desc_free = dp->vnext;
497 dp = (struct trxd *)malloc(sizeof *dp, M_MN, M_INTWAIT);
502 mn_free_desc(struct trxd *dp)
504 dp->vnext = mn_desc_free;
509 mn_parse_ts(const char *s, int *nbit)
519 i = strtol(s, &p, 0);
522 while (j != -1 && j < i) {
532 } else if (*p == '-') {
547 mn_fmt_ts(char *p, u_int32_t ts)
554 for (j = 0; j < 32; j++) {
555 if (!(ts & (1 << j)))
557 sprintf(p, "%s%d", s, j);
560 if (!(ts & (1 << (j+1))))
563 if (!(ts & (1 << (j+1))))
565 sprintf(p, "-%d", j);
577 ngmn_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
580 struct trxd *dp, *dp2;
583 int chan, pitch, len;
589 if (sch->state != UP) {
590 NG_FREE_DATA(m, meta);
593 if (sch->tx_pending + m->m_pkthdr.len > sch->tx_limit * mn_maxlatency) {
594 NG_FREE_DATA(m, meta);
600 dp2 = sc->ch[chan]->xl;
601 len = m->m_pkthdr.len;
603 dp = mn_alloc_desc();
607 sc->ch[chan]->xl = dp2;
614 sc->ch[chan]->xl->vnext = 0;
617 dp->data = vtophys(m2->m_data);
618 dp->flags = m2->m_len << 16;
621 dp->next = vtophys(dp);
623 sc->ch[chan]->xl->next = vtophys(dp);
624 sc->ch[chan]->xl->vnext = dp;
625 sc->ch[chan]->xl = dp;
628 dp->flags |= 0xc0000000;
629 dp2->flags &= ~0x40000000;
636 printf("%s%d: Short on mem, pitched %d packets\n",
637 sc->name, chan, pitch);
640 printf("%d = %d + %d (%p)\n",
641 sch->tx_pending + m->m_pkthdr.len,
642 sch->tx_pending , m->m_pkthdr.len, m);
644 sch->tx_pending += m->m_pkthdr.len;
645 sc->m32x->txpoll &= ~(1 << chan);
654 ngmn_connect(hook_p hook)
657 struct trxd *dp, *dp2;
667 if (sch->state == UP)
671 /* Count and configure the timeslots for this channel */
672 for (nts = i = 0; i < 32; i++)
673 if (sch->ts & (1 << i)) {
674 sc->m32_mem.ts[i] = 0x00ff00ff |
675 (chan << 24) | (chan << 8);
679 /* Init the receiver & xmitter to HDLC */
680 sc->m32_mem.cs[chan].flags = 0x80e90006;
681 /* Allocate two buffers per timeslot */
683 sc->m32_mem.cs[chan].itbs = 63;
685 sc->m32_mem.cs[chan].itbs = nts * 2;
687 /* Setup a transmit chain with one descriptor */
688 /* XXX: we actually send a 1 byte packet */
689 dp = mn_alloc_desc();
690 MGETHDR(m, MB_WAIT, MT_DATA);
695 dp->flags = 0xc0000000 + (1 << 16);
696 dp->next = vtophys(dp);
698 dp->data = vtophys(sc->name);
699 sc->m32_mem.cs[chan].tdesc = vtophys(dp);
700 sc->ch[chan]->x1 = dp;
701 sc->ch[chan]->xl = dp;
703 /* Setup a receive chain with 5 + NTS descriptors */
705 dp = mn_alloc_desc();
707 MGETHDR(m, MB_WAIT, MT_DATA);
713 if ((m->m_flags & M_EXT) == 0) {
719 dp->data = vtophys(m->m_data);
720 dp->flags = 0x40000000;
721 dp->flags += 1600 << 16;
722 dp->next = vtophys(dp);
724 sc->ch[chan]->rl = dp;
726 for (i = 0; i < (nts + 10); i++) {
728 dp = mn_alloc_desc();
730 MGETHDR(m, MB_WAIT, MT_DATA);
737 if ((m->m_flags & M_EXT) == 0) {
743 dp->data = vtophys(m->m_data);
744 dp->flags = 0x00000000;
745 dp->flags += 1600 << 16;
746 dp->next = vtophys(dp2);
749 sc->m32_mem.cs[chan].rdesc = vtophys(dp);
750 sc->ch[chan]->r1 = dp;
752 /* Initialize this channel */
753 sc->m32_mem.ccb = 0x00008000 + (chan << 8);
758 printf("%s: init chan %d stat %08x\n", sc->name, chan, u);
768 ngmn_disconnect(hook_p hook)
773 struct trxd *dp, *dp2;
780 if (sch->state == DOWN)
784 /* Set receiver & transmitter off */
785 sc->m32_mem.cs[chan].flags = 0x80920006;
786 sc->m32_mem.cs[chan].itbs = 0;
788 /* free the timeslots */
789 for (i = 0; i < 32; i++)
790 if (sc->ch[chan]->ts & (1 << i))
791 sc->m32_mem.ts[i] = 0x20002000;
793 /* Initialize this channel */
794 sc->m32_mem.ccb = 0x00008000 + (chan << 8);
799 printf("%s: zap chan %d stat %08x\n", sc->name, chan, u);
802 /* Free all receive descriptors and mbufs */
803 for (dp = sc->ch[chan]->r1; dp ; dp = dp2) {
806 sc->ch[chan]->r1 = dp2 = dp->vnext;
810 /* Free all transmit descriptors and mbufs */
811 for (dp = sc->ch[chan]->x1; dp ; dp = dp2) {
813 sc->ch[chan]->tx_pending -= dp->m->m_pkthdr.len;
816 sc->ch[chan]->x1 = dp2 = dp->vnext;
824 * Create a new channel.
827 mn_create_channel(struct softc *sc, int chan)
831 sch = sc->ch[chan] = (struct schan *)malloc(sizeof *sc->ch[chan],
832 M_MN, M_WAITOK | M_ZERO);
836 sprintf(sch->name, "%s%d", sc->name, chan);
842 * Dump Munich32x state
845 m32_dump(struct softc *sc)
850 printf("mn%d: MUNICH32X dump\n", sc->unit);
851 tp4 = (u_int32_t *)sc->m0v;
852 for(j = 0; j < 64; j += 8) {
853 printf("%02x", j * sizeof *tp4);
854 for(i = 0; i < 8; i++)
855 printf(" %08x", tp4[i+j]);
858 for(j = 0; j < M32_CHAN; j++) {
861 printf("CH%d: state %d ts %08x",
862 j, sc->ch[j]->state, sc->ch[j]->ts);
863 printf(" %08x %08x %08x %08x %08x %08x\n",
864 sc->m32_mem.cs[j].flags,
865 sc->m32_mem.cs[j].rdesc,
866 sc->m32_mem.cs[j].tdesc,
867 sc->m32_mem.cs[j].itbs,
869 sc->m32_mem.ctxd[j] );
877 f54_dump(struct softc *sc)
882 printf("%s: FALC54 dump\n", sc->name);
883 tp1 = (u_int8_t *)sc->m1v;
884 for(j = 0; j < 128; j += 16) {
885 printf("%s: %02x |", sc->name, j * sizeof *tp1);
886 for(i = 0; i < 16; i++)
887 printf(" %02x", tp1[i+j]);
897 m32_init(struct softc *sc)
900 sc->m32x->conf = 0x00000000;
901 sc->m32x->mode1 = 0x81048000 + 1600; /* XXX: temp */
903 sc->m32x->mode2 = 0x00000081;
904 sc->m32x->txpoll = 0xffffffff;
906 sc->m32x->mode2 = 0x00000081;
907 sc->m32x->txpoll = 0xffffffff;
909 sc->m32x->mode2 = 0x00000101;
911 sc->m32x->lconf = 0x6060009B;
912 sc->m32x->imask = 0x00000000;
919 f54_init(struct softc *sc)
921 sc->f54w->ipc = 0x07;
923 sc->f54w->xpm0 = 0xbd;
924 sc->f54w->xpm1 = 0x03;
925 sc->f54w->xpm2 = 0x00;
927 sc->f54w->imr0 = 0x18; /* RMB, CASC */
928 sc->f54w->imr1 = 0x08; /* XMB */
929 sc->f54w->imr2 = 0x00;
930 sc->f54w->imr3 = 0x38; /* LMFA16, AIS16, RA16 */
931 sc->f54w->imr4 = 0x00;
933 sc->f54w->fmr0 = 0xf0; /* X: HDB3, R: HDB3 */
934 sc->f54w->fmr1 = 0x0e; /* Send CRC4, 2Mbit, ECM */
935 if (sc->framing == E1)
936 sc->f54w->fmr2 = 0x03; /* Auto Rem-Alarm, Auto resync */
937 else if (sc->framing == E1U)
938 sc->f54w->fmr2 = 0x33; /* dais, rtm, Auto Rem-Alarm, Auto resync */
940 sc->f54w->lim1 = 0xb0; /* XCLK=8kHz, .62V threshold */
941 sc->f54w->pcd = 0x0a;
942 sc->f54w->pcr = 0x15;
943 sc->f54w->xsw = 0x9f; /* fmr4 */
944 if (sc->framing == E1)
945 sc->f54w->xsp = 0x1c; /* fmr5 */
946 else if (sc->framing == E1U)
947 sc->f54w->xsp = 0x3c; /* tt0, fmr5 */
948 sc->f54w->xc0 = 0x07;
949 sc->f54w->xc1 = 0x3d;
950 sc->f54w->rc0 = 0x05;
951 sc->f54w->rc1 = 0x00;
952 sc->f54w->cmdr = 0x51;
956 mn_reset(struct softc *sc)
961 sc->m32x->ccba = vtophys(&sc->m32_mem.csa);
962 sc->m32_mem.csa = vtophys(&sc->m32_mem.ccb);
964 bzero(sc->tiqb, sizeof sc->tiqb);
965 sc->m32x->tiqba = vtophys(&sc->tiqb);
966 sc->m32x->tiql = NIQB / 16 - 1;
968 bzero(sc->riqb, sizeof sc->riqb);
969 sc->m32x->riqba = vtophys(&sc->riqb);
970 sc->m32x->riql = NIQB / 16 - 1;
972 bzero(sc->ltiqb, sizeof sc->ltiqb);
973 sc->m32x->ltiqba = vtophys(&sc->ltiqb);
974 sc->m32x->ltiql = NIQB / 16 - 1;
976 bzero(sc->lriqb, sizeof sc->lriqb);
977 sc->m32x->lriqba = vtophys(&sc->lriqb);
978 sc->m32x->lriql = NIQB / 16 - 1;
980 bzero(sc->piqb, sizeof sc->piqb);
981 sc->m32x->piqba = vtophys(&sc->piqb);
982 sc->m32x->piql = NIQB / 16 - 1;
989 sc->m32_mem.ccb = 0x4;
995 /* set all timeslots to known state */
996 for (i = 0; i < 32; i++)
997 sc->m32_mem.ts[i] = 0x20002000;
1001 "mn%d: WARNING: Controller failed the PCI bus-master test.\n"
1002 "mn%d: WARNING: Use a PCI slot which can support bus-master cards.\n",
1003 sc->unit, sc->unit);
1010 * FALC54 interrupt handling
1013 f54_intr(struct softc *sc)
1018 u = sc->f54r->isr0 << 24;
1019 u |= sc->f54r->isr1 << 16;
1020 u |= sc->f54r->isr2 << 8;
1021 u |= sc->f54r->isr3;
1023 /* don't chat about the 1 sec heart beat */
1026 printf("%s*: FALC54 IRQ GIS:%02x %b\n", sc->name, g, u, "\20"
1027 "\40RME\37RFS\36T8MS\35RMB\34CASC\33CRC4\32SA6SC\31RPF"
1028 "\30b27\27RDO\26ALLS\25XDU\24XMB\23b22\22XLSC\21XPR"
1029 "\20FAR\17LFA\16MFAR\15T400MS\14AIS\13LOS\12RAR\11RA"
1030 "\10ES\7SEC\6LMFA16\5AIS16\4RA16\3API\2SLN\1SLP");
1032 s = sc->f54r->frs0 << 24;
1033 s |= sc->f54r->frs1 << 16;
1034 s |= sc->f54r->rsw << 8;
1038 s &= ~0x01844038; /* undefined or static bits */
1039 s &= ~0x00009fc7; /* bits we don't care about */
1040 s &= ~0x00780000; /* XXX: TS16 related */
1041 s &= ~0x06000000; /* XXX: Multiframe related */
1043 printf("%s*: FALC54 Status %b\n", sc->name, s, "\20"
1044 "\40LOS\37AIS\36LFA\35RRA\34AUXP\33NMF\32LMFA\31frs0.0"
1045 "\30frs1.7\27TS16RA\26TS16LOS\25TS16AIS\24TS16LFA\23frs1.2\22XLS\21XLO"
1046 "\20RS1\17rsw.6\16RRA\15RY0\14RY1\13RY2\12RY3\11RY4"
1047 "\10SI1\7SI2\6rsp.5\5rsp.4\4rsp.3\3RSIF\2RS13\1RS15");
1049 if (s != sc->framer_state) {
1051 for (i = 0; i < M32_CHAN; i++) {
1054 sp = &sc->ch[i]->ifsppp;
1055 if (!(sp->pp_if.if_flags & IFF_UP))
1058 timeout((timeout_t *)sp->pp_down, sp, 1 * hz);
1060 timeout((timeout_t *)sp->pp_up, sp, 1 * hz);
1063 sc->framer_state = s;
1066 /* Once per second check error counters */
1067 /* XXX: not clear if this is actually ok */
1070 sc->cnt_fec += sc->f54r->fec;
1071 sc->cnt_cvc += sc->f54r->cvc;
1072 sc->cnt_cec1 += sc->f54r->cec1;
1073 sc->cnt_ebc += sc->f54r->ebc;
1074 sc->cnt_cec2 += sc->f54r->cec2;
1075 sc->cnt_cec3 += sc->f54r->cec3;
1076 sc->cnt_rbc += sc->f54r->rbc;
1080 * Transmit interrupt for one channel
1083 mn_tx_intr(struct softc *sc, u_int32_t vector)
1089 chan = vector & 0x1f;
1092 if (sc->ch[chan]->state != UP) {
1093 printf("%s: tx_intr when not UP\n", sc->name);
1097 dp = sc->ch[chan]->x1;
1098 if (vtophys(dp) == sc->m32_mem.ctxd[chan])
1103 printf("%d = %d - %d (%p)\n",
1104 sc->ch[chan]->tx_pending - m->m_pkthdr.len,
1105 sc->ch[chan]->tx_pending , m->m_pkthdr.len, m);
1107 sc->ch[chan]->tx_pending -= m->m_pkthdr.len;
1110 sc->ch[chan]->last_xmit = time_second;
1111 sc->ch[chan]->x1 = dp->vnext;
1117 * Receive interrupt for one channel
1120 mn_rx_intr(struct softc *sc, u_int32_t vector)
1122 u_int32_t chan, err;
1127 chan = vector & 0x1f;
1131 if (sch->state != UP) {
1132 printf("%s: rx_intr when not UP\n", sc->name);
1136 if (vector == 0x30000b00)
1140 if (vtophys(dp) == sc->m32_mem.crxd[chan])
1144 m->m_pkthdr.len = m->m_len = (dp->status >> 16) & 0x1fff;
1145 err = (dp->status >> 8) & 0xff;
1147 ng_queue_data(sch->hook, m, NULL);
1148 sch->last_recv = time_second;
1150 /* we could be down by now... */
1151 if (sch->state != UP)
1153 } else if (err & 0x40) {
1155 } else if (err & 0x10) {
1157 } else if (err & 0x08) {
1158 sch->dribble_error++;
1159 } else if (err & 0x04) {
1161 } else if (err & 0x02) {
1163 } else if (err & 0x01) {
1164 sch->overflow_error++;
1167 sch->last_rxerr = time_second;
1168 sch->prev_error = sch->last_error;
1169 sch->last_error = err;
1172 sc->ch[chan]->r1 = dp->vnext;
1174 /* Replenish desc + mbuf supplies */
1176 MGETHDR(m, MB_DONTWAIT, MT_DATA);
1179 return; /* ENOBUFS */
1181 MCLGET(m, MB_DONTWAIT);
1182 if((m->m_flags & M_EXT) == 0) {
1185 return; /* ENOBUFS */
1189 dp->data = vtophys(m->m_data);
1190 dp->flags = 0x40000000;
1191 dp->flags += 1600 << 16;
1192 dp->next = vtophys(dp);
1194 sc->ch[chan]->rl->next = vtophys(dp);
1195 sc->ch[chan]->rl->vnext = dp;
1196 sc->ch[chan]->rl->flags &= ~0x40000000;
1197 sc->ch[chan]->rl = dp;
1210 u_int32_t stat, lstat, u;
1214 stat = sc->m32x->stat;
1215 lstat = sc->m32x->lstat;
1217 if (!stat && !(lstat & 2))
1221 if (stat & ~0xc200) {
1222 printf("%s: I stat=%08x lstat=%08x\n", sc->name, stat, lstat);
1225 if ((stat & 0x200) || (lstat & 2))
1228 for (j = i = 0; i < 64; i ++) {
1233 if ((u & ~0x1f) == 0x30000800 || (u & ~0x1f) == 0x30000b00)
1235 u &= ~0x30000400; /* bits we don't care about */
1236 if ((u & ~0x1f) == 0x00000900)
1241 printf("%s*: RIQB:", sc->name);
1242 printf(" [%d]=%08x", i, u);
1249 for (j = i = 0; i < 64; i ++) {
1254 if ((u & ~0x1f) == 0x20000800)
1256 u &= ~0x20000000; /* bits we don't care about */
1260 printf("%s*: TIQB:", sc->name);
1261 printf(" [%d]=%08x", i, u);
1267 sc->m32x->stat = stat;
1271 * PCI initialization stuff
1275 mn_probe (device_t self)
1277 u_int id = pci_get_devid(self);
1279 if (sizeof (struct m32xreg) != 256) {
1280 printf("MN: sizeof(struct m32xreg) = %d, should have been 256\n", sizeof (struct m32xreg));
1283 if (sizeof (struct f54rreg) != 128) {
1284 printf("MN: sizeof(struct f54rreg) = %d, should have been 128\n", sizeof (struct f54rreg));
1287 if (sizeof (struct f54wreg) != 128) {
1288 printf("MN: sizeof(struct f54wreg) = %d, should have been 128\n", sizeof (struct f54wreg));
1292 if (id != 0x2101110a)
1295 device_set_desc_copy(self, "Munich32X E1/T1 HDLC Controller");
1300 mn_attach (device_t self)
1307 struct resource *res;
1310 if (ng_newtype(&mntypestruct))
1311 printf("ng_newtype failed\n");
1315 sc = (struct softc *)malloc(sizeof *sc, M_MN, M_WAITOK | M_ZERO);
1316 device_set_softc(self, sc);
1319 sc->unit = device_get_unit(self);
1321 sprintf(sc->name, "mn%d", sc->unit);
1324 res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE);
1326 device_printf(self, "Could not map memory\n");
1329 sc->m0v = rman_get_virtual(res);
1330 sc->m0p = rman_get_start(res);
1332 rid = PCIR_MAPS + 4;
1333 res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE);
1335 device_printf(self, "Could not map memory\n");
1338 sc->m1v = rman_get_virtual(res);
1339 sc->m1p = rman_get_start(res);
1341 /* Allocate interrupt */
1343 sc->irq = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
1344 RF_SHAREABLE | RF_ACTIVE);
1346 if (sc->irq == NULL) {
1347 printf("couldn't map interrupt\n");
1351 error = bus_setup_intr(self, sc->irq, INTR_TYPE_NET, mn_intr, sc,
1352 &sc->intrhand, NULL);
1355 printf("couldn't set up irq\n");
1359 u = pci_read_config(self, PCIR_COMMAND, 1);
1361 pci_write_config(self, PCIR_COMMAND, u | PCIM_CMD_PERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN, 1);
1363 pci_write_config(self, PCIR_COMMAND, 0x02800046, 4);
1365 u = pci_read_config(self, PCIR_COMMAND, 1);
1368 ver = pci_get_revid(self);
1370 sc->m32x = (struct m32xreg *) sc->m0v;
1371 sc->f54w = (struct f54wreg *) sc->m1v;
1372 sc->f54r = (struct f54rreg *) sc->m1v;
1374 /* We must reset before poking at FALC54 registers */
1379 printf("mn%d: Munich32X", sc->unit);
1385 printf(" Rev 0x%x\n", ver);
1388 switch (sc->f54r->vstr) {
1390 printf(" Rev < 1.3\n");
1393 printf(" Rev 1.3\n");
1396 printf(" Rev 1.4\n");
1399 printf("-LH Rev 1.1\n");
1402 printf("-LH Rev 1.3\n");
1405 printf(" Rev 0x%x\n", sc->f54r->vstr);
1408 if (ng_make_node_common(&mntypestruct, &sc->node) != 0) {
1409 printf("ng_make_node_common failed\n");
1412 sc->node->private = sc;
1413 sprintf(sc->nodename, "%s%d", NG_MN_NODE_TYPE, sc->unit);
1414 if (ng_name_node(sc->node, sc->nodename)) {
1415 ng_rmnode(sc->node);
1424 static device_method_t mn_methods[] = {
1425 /* Device interface */
1426 DEVMETHOD(device_probe, mn_probe),
1427 DEVMETHOD(device_attach, mn_attach),
1428 DEVMETHOD(device_suspend, bus_generic_suspend),
1429 DEVMETHOD(device_resume, bus_generic_resume),
1430 DEVMETHOD(device_shutdown, bus_generic_shutdown),
1435 static driver_t mn_driver = {
1441 static devclass_t mn_devclass;
1443 DECLARE_DUMMY_MODULE(if_mn);
1444 DRIVER_MODULE(if_mn, pci, mn_driver, mn_devclass, 0, 0);