2 * Granch SBNI16 G.SHDSL Modem driver
3 * Written by Denis I. Timofeev, 2002-2003.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/dev/sbsh/if_sbsh.c,v 1.3.2.1 2003/04/15 18:15:07 fjoe Exp $
27 * $DragonFly: src/sys/dev/netif/sbsh/if_sbsh.c,v 1.4 2003/06/25 03:55:48 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/sockio.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
37 #include <sys/socket.h>
38 #include <sys/random.h>
39 #include <machine/clock.h>
40 #include <machine/stdarg.h>
43 #include <net/if_arp.h>
44 #include <net/ethernet.h>
45 #include <net/if_media.h>
51 #include <machine/bus.h>
52 #include <machine/resource.h>
56 #include <pci/pcireg.h>
57 #include <pci/pcivar.h>
59 #include <dev/sbsh/if_sbshreg.h>
61 /* -------------------------------------------------------------------------- */
63 struct sbni16_hw_regs {
64 u_int8_t CR, CRB, SR, IMR, CTDR, LTDR, CRDR, LRDR;
72 struct cx28975_cmdarea {
90 u_int8_t out_data[75];
98 struct arpcom arpcom; /* ethernet common */
100 struct resource *mem_res;
101 struct resource *irq_res;
104 void *mem_base; /* mapped memory address */
106 volatile struct sbni16_hw_regs *regs;
107 volatile struct hw_descr *tbd;
108 volatile struct hw_descr *rbd;
109 volatile struct cx28975_cmdarea *cmdp;
111 /* SBNI16 controller statistics */
112 struct sbni16_stats {
113 u_int32_t sent_pkts, rcvd_pkts;
114 u_int32_t crc_errs, ufl_errs, ofl_errs, attempts, last_time;
117 /* transmit and reception queues */
118 struct mbuf *xq[XQLEN], *rq[RQLEN];
119 unsigned head_xq, tail_xq, head_rq, tail_rq;
121 /* the descriptors mapped onto the first buffers in xq and rq */
122 unsigned head_tdesc, head_rdesc;
127 u_int8_t *firmw_image;
133 u_int32_t fill_7e: 1;
140 /* SHDSL transceiver statistics */
142 u_int8_t status_1, status_3;
143 u_int8_t attenuat, nmr, tpbo, rpbo;
144 u_int16_t losw, segd, crc, sega, losd;
147 enum State { NOT_LOADED, DOWN, ACTIVATION, ACTIVE };
149 #define SIOCLOADFIRMW _IOWR('i', 67, struct ifreq)
150 #define SIOCGETSTATS _IOWR('i', 68, struct ifreq)
151 #define SIOCCLRSTATS _IOWR('i', 69, struct ifreq)
153 static int sbsh_probe(device_t);
154 static int sbsh_attach(device_t);
155 static int sbsh_detach(device_t);
156 static int sbsh_ioctl(struct ifnet *, u_long, caddr_t);
157 static void sbsh_shutdown(device_t);
158 static int sbsh_suspend(device_t);
159 static int sbsh_resume(device_t);
160 static void sbsh_watchdog(struct ifnet *);
162 static void sbsh_start(struct ifnet *);
163 static void sbsh_init(void *);
164 static void sbsh_stop(struct sbsh_softc *);
165 static void init_card(struct sbsh_softc *);
166 static void sbsh_intr(void *);
167 static void resume_tx(struct sbsh_softc *);
168 static void start_xmit_frames(struct sbsh_softc *);
169 static void encap_frame(struct sbsh_softc *, struct mbuf *);
170 static struct mbuf * repack(struct sbsh_softc *, struct mbuf *);
171 static void free_sent_buffers(struct sbsh_softc *);
172 static void alloc_rx_buffers(struct sbsh_softc *);
173 static void indicate_frames(struct sbsh_softc *);
174 static void drop_queues(struct sbsh_softc *);
175 static void activate(struct sbsh_softc *);
176 static void deactivate(struct sbsh_softc *);
177 static void cx28975_interrupt(struct sbsh_softc *);
178 static int start_cx28975(struct sbsh_softc *, struct cx28975_cfg);
179 static int download_firmware(struct sbsh_softc *, u_int8_t *, u_int32_t);
180 static int issue_cx28975_cmd(struct sbsh_softc *, u_int8_t,
181 u_int8_t *, u_int8_t);
183 static device_method_t sbsh_methods[] = {
184 /* Device interface */
185 DEVMETHOD(device_probe, sbsh_probe),
186 DEVMETHOD(device_attach, sbsh_attach),
187 DEVMETHOD(device_detach, sbsh_detach),
188 DEVMETHOD(device_shutdown, sbsh_shutdown),
189 DEVMETHOD(device_suspend, sbsh_suspend),
190 DEVMETHOD(device_resume, sbsh_resume),
195 static driver_t sbsh_driver = {
198 sizeof(struct sbsh_softc)
201 static devclass_t sbsh_devclass;
203 DRIVER_MODULE(if_sbsh, pci, sbsh_driver, sbsh_devclass, 0, 0);
206 sbsh_probe(device_t dev)
208 if (pci_get_vendor(dev) != SBNI16_VENDOR
209 || pci_get_device(dev) != SBNI16_DEVICE
210 || pci_get_subdevice(dev) != SBNI16_SUBDEV)
213 device_set_desc(dev, "Granch SBNI16 G.SHDSL Modem");
218 sbsh_attach(device_t dev)
220 struct sbsh_softc *sc;
222 int unit, error = 0, rid, s;
226 sc = device_get_softc(dev);
227 unit = device_get_unit(dev);
230 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
231 0, ~0, 4096, RF_ACTIVE);
233 if (sc->mem_res == NULL) {
234 printf ("sbsh%d: couldn't map memory\n", unit);
240 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
241 RF_SHAREABLE | RF_ACTIVE);
243 if (sc->irq_res == NULL) {
244 printf("sbsh%d: couldn't map interrupt\n", unit);
245 bus_release_resource(dev, SYS_RES_MEMORY,
246 PCIR_MAPS + 4, sc->mem_res);
251 sc->mem_base = rman_get_virtual(sc->mem_res);
254 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
255 sbsh_intr, sc, &sc->intr_hand);
257 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
258 bus_release_resource(dev, SYS_RES_MEMORY,
259 PCIR_MAPS + 4, sc->mem_res);
260 printf("sbsh%d: couldn't set up irq\n", unit);
264 /* generate ethernet MAC address */
265 *(u_int32_t *)sc->arpcom.ac_enaddr = htonl(0x00ff0192);
266 read_random_unlimited(sc->arpcom.ac_enaddr + 4, 2);
268 ifp = &sc->arpcom.ac_if;
271 ifp->if_name = "sbsh";
272 ifp->if_mtu = ETHERMTU;
273 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
274 ifp->if_ioctl = sbsh_ioctl;
275 ifp->if_output = ether_output;
276 ifp->if_start = sbsh_start;
277 ifp->if_watchdog = sbsh_watchdog;
278 ifp->if_init = sbsh_init;
279 ifp->if_baudrate = 4600000;
280 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
282 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
290 sbsh_detach(device_t dev)
292 struct sbsh_softc *sc;
298 sc = device_get_softc(dev);
299 ifp = &sc->arpcom.ac_if;
302 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
304 bus_teardown_intr(dev, sc->irq_res, sc->intr_hand);
305 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
306 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_MAPS + 4, sc->mem_res);
314 sbsh_start(struct ifnet *ifp)
316 struct sbsh_softc *sc = ifp->if_softc;
319 if (sc->state != ACTIVE)
323 start_xmit_frames(ifp->if_softc);
331 struct sbsh_softc *sc = xsc;
332 struct ifnet *ifp = &sc->arpcom.ac_if;
336 if ((ifp->if_flags & IFF_RUNNING) || sc->state == NOT_LOADED)
341 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
342 sc->head_xq = sc->tail_xq = sc->head_rq = sc->tail_rq = 0;
343 sc->head_tdesc = sc->head_rdesc = 0;
347 issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1);
348 if (issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1) == 0) {
349 sc->state = ACTIVATION;
351 ifp->if_flags |= IFF_RUNNING;
352 ifp->if_flags &= ~IFF_OACTIVE;
360 sbsh_stop(struct sbsh_softc *sc)
369 issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1);
370 if (sc->state == ACTIVE) {
372 issue_cx28975_cmd(sc, _DSL_FORCE_DEACTIVATE, &t, 1);
373 /* FIX! activation manager state */
375 /* Is it really must be done here? It calls from intr handler */
386 init_card(struct sbsh_softc *sc)
388 sc->state = NOT_LOADED;
389 sc->tbd = (struct hw_descr *) sc->mem_base;
390 sc->rbd = (struct hw_descr *) ((u_int8_t *)sc->mem_base + 0x400);
391 sc->regs = (struct sbni16_hw_regs *) ((u_int8_t *)sc->mem_base + 0x800);
392 sc->cmdp = (struct cx28975_cmdarea *) ((u_int8_t *)sc->mem_base + 0xc00);
401 sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
403 struct sbsh_softc *sc = ifp->if_softc;
404 struct ifreq *ifr = (struct ifreq *) data;
405 struct cx28975_cfg cfg;
407 struct thread *td = curthread;
415 if ((error = suser(td)) != 0)
417 if (ifp->if_flags & IFF_UP)
420 bcopy((caddr_t)ifr->ifr_data, (caddr_t)&cfg, sizeof cfg);
421 if (start_cx28975(sc, cfg) == 0) {
422 static char *modstr[] = {
423 "TCPAM32", "TCPAM16", "TCPAM8", "TCPAM4" };
424 if_printf(&sc->arpcom.ac_if, "%s, rate %d, %s\n",
425 cfg.master ? "master" : "slave",
426 cfg.lrate << 3, modstr[cfg.mod]);
428 if_printf(&sc->arpcom.ac_if,
429 "unable to load firmware\n");
435 if ((error = suser(td)) != 0)
439 if (issue_cx28975_cmd(sc, _DSL_FAR_END_ATTEN, &t, 1))
441 ds.attenuat = sc->cmdp->out_data[0];
443 if (issue_cx28975_cmd(sc, _DSL_NOISE_MARGIN, &t, 1))
445 ds.nmr = sc->cmdp->out_data[0];
447 if (issue_cx28975_cmd(sc, _DSL_POWER_BACK_OFF_RESULT, &t, 1))
449 ds.tpbo = sc->cmdp->out_data[0];
450 ds.rpbo = sc->cmdp->out_data[1];
452 if (!issue_cx28975_cmd(sc, _DSL_HDSL_PERF_ERR_CTRS, &t, 1)) {
454 for (i = 0; i < 10; ++i)
455 ((u_int8_t *) &ds.losw)[i] =
456 sc->cmdp->out_data[i];
460 ds.status_1 = ((volatile u_int8_t *)sc->cmdp)[0x3c0];
461 ds.status_3 = ((volatile u_int8_t *)sc->cmdp)[0x3c2];
463 bcopy(&sc->in_stats, ifr->ifr_data, sizeof(struct sbni16_stats));
464 bcopy(&ds, ifr->ifr_data + sizeof(struct sbni16_stats),
465 sizeof(struct dsl_stats));
469 if (!(error = suser(td))) {
470 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
472 if (issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1))
480 error = ether_ioctl(ifp, cmd, data);
484 if (ifp->if_flags & IFF_UP) {
485 if (!(ifp->if_flags & IFF_RUNNING)) {
486 if (sc->state == NOT_LOADED) {
487 if_printf(ifp, "firmware wasn't loaded\n");
493 if (ifp->if_flags & IFF_RUNNING) {
495 ifp->if_flags &= ~IFF_RUNNING;
516 sbsh_shutdown(device_t dev)
518 struct sbsh_softc *sc = device_get_softc(dev);
524 sbsh_suspend(device_t dev)
526 struct sbsh_softc *sc = device_get_softc(dev);
537 sbsh_resume(device_t dev)
539 struct sbsh_softc *sc = device_get_softc(dev);
544 ifp = &sc->arpcom.ac_if;
546 if (ifp->if_flags & IFF_UP)
555 sbsh_watchdog(struct ifnet *ifp)
557 struct sbsh_softc *sc = ifp->if_softc;
559 if_printf(ifp, "transmit timeout\n");
561 if (sc->regs->SR & TXS) {
563 if_printf(ifp, "interrupt posted but not delivered\n");
565 free_sent_buffers(sc);
568 /* -------------------------------------------------------------------------- */
573 struct sbsh_softc *sc = (struct sbsh_softc *)arg;
574 u_int8_t status = sc->regs->SR;
580 cx28975_interrupt(sc);
587 ++sc->in_stats.ufl_errs;
588 ++sc->arpcom.ac_if.if_oerrors;
594 alloc_rx_buffers(sc);
599 free_sent_buffers(sc);
603 ++sc->in_stats.crc_errs;
604 ++sc->arpcom.ac_if.if_ierrors;
609 ++sc->in_stats.ofl_errs;
610 ++sc->arpcom.ac_if.if_ierrors;
616 * Look for a first descriptor of a next packet, and write it's number
617 * into CTDR. Then enable the transmitter.
620 resume_tx(struct sbsh_softc *sc)
622 u_int32_t cur_tbd = sc->regs->CTDR;
624 while (cur_tbd != sc->regs->LTDR
625 && (sc->tbd[cur_tbd++].length & LAST_FRAG) == 0)
627 sc->regs->CTDR = cur_tbd;
628 sc->regs->CR |= TXEN;
632 start_xmit_frames(struct sbsh_softc *sc)
634 struct ifnet *ifp = &sc->arpcom.ac_if;
638 * Check if we have any free descriptor(s) and free space in
639 * our transmit queue.
641 while (sc->tail_xq != ((sc->head_xq - 1) & (XQLEN - 1))
642 && sc->regs->LTDR != ((sc->head_tdesc - 1) & 0x7f)) {
644 IF_DEQUEUE(&ifp->if_snd, m);
647 if (m->m_pkthdr.len) {
655 if (sc->regs->CTDR != sc->regs->LTDR)
656 ifp->if_flags |= IFF_OACTIVE;
658 ifp->if_flags &= ~IFF_OACTIVE;
663 * MUST be called at splimp
666 encap_frame(struct sbsh_softc *sc, struct mbuf *m_head)
673 for (m = m_head; !m->m_len; m = m->m_next)
676 cur_tbd = sc->regs->LTDR & 0x7f;
679 if (m->m_len < 5 || cur_tbd == ((sc->head_tdesc - 1) & 0x7f)) {
680 if ((m_head = repack(sc, m_head)) != NULL)
681 goto look_for_nonzero;
686 sc->tbd[cur_tbd].address = vtophys(mtod(m, vm_offset_t));
687 sc->tbd[cur_tbd].length = m->m_len;
691 } while (m && !m->m_len);
693 if (!m) { /* last fragment has been reached */
694 sc->tbd[cur_tbd].length |= LAST_FRAG;
702 sc->xq[sc->tail_xq++] = m_head;
703 sc->tail_xq &= (XQLEN - 1);
705 sc->regs->LTDR = cur_tbd;
706 ++sc->in_stats.sent_pkts;
707 ++sc->arpcom.ac_if.if_opackets;
711 repack(struct sbsh_softc *sc, struct mbuf *m)
715 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
717 if_printf (&sc->arpcom.ac_if,
718 "unable to get mbuf.\n");
722 if (m->m_pkthdr.len > MHLEN) {
723 MCLGET(m_new, M_DONTWAIT);
724 if (!(m_new->m_flags & M_EXT)) {
726 if_printf (&sc->arpcom.ac_if,
727 "unable to get mbuf cluster.\n");
732 m_copydata(m, 0, m->m_pkthdr.len, mtod(m_new, caddr_t));
733 m_new->m_pkthdr.len = m_new->m_len = m->m_pkthdr.len;
739 free_sent_buffers(struct sbsh_softc *sc)
743 cur_tbd = sc->regs->CTDR;
745 while (sc->head_tdesc != cur_tbd) {
747 * Be careful! one element in xq may correspond to
748 * multiple descriptors.
750 if (sc->tbd[sc->head_tdesc].length & LAST_FRAG) {
751 m_freem(sc->xq[sc->head_xq++]);
752 sc->head_xq &= (XQLEN - 1);
755 sc->tbd[sc->head_tdesc].length = 0;
756 sc->head_tdesc = (sc->head_tdesc + 1) & 0x7f;
759 start_xmit_frames(sc);
763 * DON'T use free_sent_buffers to drop the queue!
766 alloc_rx_buffers(struct sbsh_softc *sc)
768 unsigned cur_rbd = sc->regs->LRDR & 0x7f;
771 while (sc->tail_rq != ((sc->head_rq - 1) & (RQLEN - 1))) {
772 MGETHDR(m, M_DONTWAIT, MT_DATA);
774 if_printf (&sc->arpcom.ac_if,
775 "unable to get mbuf.\n");
779 if (SBNI16_MAX_FRAME > MHLEN) {
780 MCLGET(m, M_DONTWAIT);
781 if (!(m->m_flags & M_EXT)) {
783 if_printf (&sc->arpcom.ac_if,
784 "unable to get mbuf cluster.\n");
787 m->m_pkthdr.len = m->m_len = MCLBYTES;
790 m_adj(m, 2); /* align ip on longword boundaries */
792 sc->rq[sc->tail_rq++] = m;
793 sc->tail_rq &= (RQLEN - 1);
795 sc->rbd[cur_rbd].address = vtophys(mtod(m, vm_offset_t));
796 sc->rbd[cur_rbd].length = 0;
797 sc->regs->LRDR = cur_rbd = (cur_rbd + 1) & 0x7f;
802 indicate_frames(struct sbsh_softc *sc)
804 struct ether_header *eh;
805 unsigned cur_rbd = sc->regs->CRDR & 0x7f;
807 while (sc->head_rdesc != cur_rbd) {
808 struct mbuf *m = sc->rq[sc->head_rq++];
809 sc->head_rq &= (RQLEN - 1);
811 m->m_pkthdr.len = m->m_len =
812 sc->rbd[sc->head_rdesc].length & 0x7ff;
813 m->m_pkthdr.rcvif = &sc->arpcom.ac_if;
815 eh = mtod(m, struct ether_header *);
816 m_adj(m, sizeof(struct ether_header));
817 ether_input(&sc->arpcom.ac_if, eh, m);
818 ++sc->in_stats.rcvd_pkts;
819 ++sc->arpcom.ac_if.if_ipackets;
821 sc->head_rdesc = (sc->head_rdesc + 1) & 0x7f;
826 drop_queues(struct sbsh_softc *sc)
828 while (sc->head_rq != sc->tail_rq) {
829 m_freem(sc->rq[sc->head_rq++]);
830 sc->head_rq &= (RQLEN - 1);
833 while (sc->head_xq != sc->tail_xq) {
834 m_freem(sc->xq[sc->head_xq++]);
835 sc->head_xq &= (XQLEN - 1);
839 /* -------------------------------------------------------------------------- */
842 activate(struct sbsh_softc *sc)
846 sc->regs->SR = 0xff; /* clear it! */
847 sc->regs->CTDR = sc->regs->LTDR = sc->regs->CRDR = sc->regs->LRDR = 0;
849 sc->head_tdesc = sc->head_rdesc = 0;
850 alloc_rx_buffers(sc);
852 sc->regs->CRB &= ~RXDE;
853 sc->regs->IMR = EXT | RXS | TXS | CRC | OFL | UFL;
854 sc->regs->CR |= TXEN | RXEN;
857 ++sc->in_stats.attempts;
859 sc->in_stats.last_time = tv.tv_sec;
860 start_xmit_frames(sc);
864 deactivate(struct sbsh_softc *sc)
866 sc->regs->CR &= ~(RXEN | TXEN);
867 sc->regs->CRB |= RXDE;
869 sc->regs->CTDR = sc->regs->LTDR;
870 sc->regs->CRDR = sc->regs->LRDR;
871 sc->state = ACTIVATION;
876 /* -------------------------------------------------------------------------- */
879 cx28975_interrupt(struct sbsh_softc *sc)
881 volatile struct cx28975_cmdarea *p = sc->cmdp;
884 if (p->intr_host != 0xfe)
887 if (p->out_ack & 0x80) {
888 if (*((volatile u_int8_t *)p + 0x3c7) & 2) {
889 if (sc->state != ACTIVE
890 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) == 0x40) {
892 if_printf(&sc->arpcom.ac_if, "connected to peer\n");
893 } else if (sc->state == ACTIVE
894 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) != 0x40) {
896 if_printf(&sc->arpcom.ac_if, "carrier lost\n");
911 /* -------------------------------------------------------------------------- */
914 start_cx28975(struct sbsh_softc *sc, struct cx28975_cfg cfg)
916 static char thresh[] = { +8, -4, -16, -40 };
918 volatile struct cx28975_cmdarea *p = sc->cmdp;
919 u_int8_t t, parm[12];
931 sc->regs->CR |= CMOD;
933 sc->regs->CR |= FMOD;
935 sc->regs->CR |= PMOD;
937 sc->regs->CRB |= RODD | RXDE;
939 sc->regs->CRB |= RDBE;
941 sc->regs->CRB |= WTBE;
943 tsleep(sc, PWAIT, "sbsh", 0);
944 if ((p->out_ack & 0x1f) != _ACK_BOOT_WAKE_UP)
947 if (download_firmware(sc, cfg.firmw_image, cfg.firmw_len))
950 tsleep(sc, PWAIT, "sbsh", 0);
951 if ((p->out_ack & 0x1f) != _ACK_OPER_WAKE_UP)
954 t = cfg.master ? 1 : 9;
955 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_ENABLE, &t, 1))
959 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_CONFIG, &t, 1))
962 *(u_int16_t *)parm = cfg.lrate >> 3;
963 parm[2] = parm[3] = parm[0];
964 parm[5] = cfg.lrate & 7;
965 parm[4] = parm[7] = 1;
967 if (issue_cx28975_cmd(sc, _DSL_MULTI_RATE_CONFIG, parm, 8))
970 parm[0] = 0x02 | (cfg.mod << 4);
972 if (issue_cx28975_cmd(sc, _DSL_TRAINING_MODE, parm, 2))
976 parm[0] = 0x04; /* pre-activation: G.hs */
977 parm[4] = 0x04; /* no remote configuration */
978 parm[7] = 0x01; /* annex A (default) */
979 parm[8] = 0xff; /* i-bit mask (all bits) */
980 if (issue_cx28975_cmd(sc, _DSL_PREACTIVATION_CFG, parm, 12))
983 parm[0] = 0x03; /* dying gasp time - 3 frames */
984 parm[1] = thresh[cfg.mod];
985 parm[2] = 0xff; /* attenuation */
986 parm[3] = 0x04; /* line probe NMR (+2 dB) */
987 parm[4] = 0x00; /* reserved */
989 if (issue_cx28975_cmd(sc, _DSL_THRESHOLDS, parm, 6))
992 t = cfg.master ? 0x23 : 0x21;
993 if (issue_cx28975_cmd(sc, _DSL_FR_PCM_CONFIG, &t, 1))
997 if (issue_cx28975_cmd(sc, _DSL_INTR_HOST_MASK, &t, 1))
1005 download_firmware(struct sbsh_softc *sc, u_int8_t *img, u_int32_t img_len)
1011 for (i = 0; i < img_len; ++i)
1015 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_START, (u_int8_t *) &t, 4))
1018 for (i = 0; img_len >= 75; i += 75, img_len -= 75) {
1019 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, 75))
1024 && issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, img_len))
1027 t = (cksum ^ 0xff) + 1;
1028 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_END, (u_int8_t *) &t, 1))
1035 issue_cx28975_cmd(struct sbsh_softc *sc, u_int8_t cmd,
1036 u_int8_t *data, u_int8_t size)
1038 volatile struct cx28975_cmdarea *p = sc->cmdp;
1039 u_int8_t *databuf = p->in_data;
1047 p->in_length = --size;
1048 p->in_csum = 0xf0 ^ cmd ^ size ^ 0xaa;
1050 for (i = 0; i <= size; ++i) {
1052 *databuf++ = *data++; /* only 1 byte per cycle! */
1055 p->in_datasum = cksum ^ 0xaa;
1056 p->out_ack = _ACK_NOT_COMPLETE;
1057 p->intr_8051 = 0xfe;
1059 if (tsleep(sc, PWAIT, "sbsh", hz << 3))
1062 while (p->out_ack == _ACK_NOT_COMPLETE)
1065 if ((p->out_ack & 0x1f) == _ACK_PASS) {