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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
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>
36 #include <sys/module.h>
38 #include <sys/socket.h>
39 #include <sys/random.h>
40 #include <machine/clock.h>
41 #include <machine/stdarg.h>
44 #include <net/if_arp.h>
45 #include <net/ethernet.h>
46 #include <net/if_media.h>
47 #include <net/if_types.h>
53 #include <machine/bus.h>
54 #include <machine/resource.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
61 #include <dev/sbsh/if_sbshreg.h>
63 /* -------------------------------------------------------------------------- */
65 struct sbni16_hw_regs {
66 u_int8_t CR, CRB, SR, IMR, CTDR, LTDR, CRDR, LRDR;
74 struct cx28975_cmdarea {
92 u_int8_t out_data[75];
102 struct resource *mem_res;
103 struct resource *irq_res;
106 void *mem_base; /* mapped memory address */
108 volatile struct sbni16_hw_regs *regs;
109 volatile struct hw_descr *tbd;
110 volatile struct hw_descr *rbd;
111 volatile struct cx28975_cmdarea *cmdp;
113 /* SBNI16 controller statistics */
114 struct sbni16_stats {
115 u_int32_t sent_pkts, rcvd_pkts;
116 u_int32_t crc_errs, ufl_errs, ofl_errs, attempts, last_time;
119 /* transmit and reception queues */
120 struct mbuf *xq[XQLEN], *rq[RQLEN];
121 unsigned head_xq, tail_xq, head_rq, tail_rq;
123 /* the descriptors mapped onto the first buffers in xq and rq */
124 unsigned head_tdesc, head_rdesc;
129 u_int8_t *firmw_image;
135 u_int32_t fill_7e: 1;
142 /* SHDSL transceiver statistics */
144 u_int8_t status_1, status_3;
145 u_int8_t attenuat, nmr, tpbo, rpbo;
146 u_int16_t losw, segd, crc, sega, losd;
149 enum State { NOT_LOADED, DOWN, ACTIVATION, ACTIVE };
151 #define SIOCLOADFIRMW _IOWR('i', 67, struct ifreq)
152 #define SIOCGETSTATS _IOWR('i', 68, struct ifreq)
153 #define SIOCCLRSTATS _IOWR('i', 69, struct ifreq)
155 static int sbsh_probe(device_t);
156 static int sbsh_attach(device_t);
157 static int sbsh_detach(device_t);
158 static int sbsh_ioctl(struct ifnet *, u_long, caddr_t);
159 static void sbsh_shutdown(device_t);
160 static int sbsh_suspend(device_t);
161 static int sbsh_resume(device_t);
162 static void sbsh_watchdog(struct ifnet *);
164 static void sbsh_start(struct ifnet *);
165 static void sbsh_init(void *);
166 static void sbsh_stop(struct sbsh_softc *);
167 static void init_card(struct sbsh_softc *);
168 static void sbsh_intr(void *);
169 static void resume_tx(struct sbsh_softc *);
170 static void start_xmit_frames(struct sbsh_softc *);
171 static void encap_frame(struct sbsh_softc *, struct mbuf *);
172 static struct mbuf * repack(struct sbsh_softc *, struct mbuf *);
173 static void free_sent_buffers(struct sbsh_softc *);
174 static void alloc_rx_buffers(struct sbsh_softc *);
175 static void indicate_frames(struct sbsh_softc *);
176 static void drop_queues(struct sbsh_softc *);
177 static void activate(struct sbsh_softc *);
178 static void deactivate(struct sbsh_softc *);
179 static void cx28975_interrupt(struct sbsh_softc *);
180 static int start_cx28975(struct sbsh_softc *, struct cx28975_cfg);
181 static int download_firmware(struct sbsh_softc *, u_int8_t *, u_int32_t);
182 static int issue_cx28975_cmd(struct sbsh_softc *, u_int8_t,
183 u_int8_t *, u_int8_t);
185 static device_method_t sbsh_methods[] = {
186 /* Device interface */
187 DEVMETHOD(device_probe, sbsh_probe),
188 DEVMETHOD(device_attach, sbsh_attach),
189 DEVMETHOD(device_detach, sbsh_detach),
190 DEVMETHOD(device_shutdown, sbsh_shutdown),
191 DEVMETHOD(device_suspend, sbsh_suspend),
192 DEVMETHOD(device_resume, sbsh_resume),
197 static driver_t sbsh_driver = {
200 sizeof(struct sbsh_softc)
203 static devclass_t sbsh_devclass;
205 DRIVER_MODULE(sbsh, pci, sbsh_driver, sbsh_devclass, 0, 0);
206 MODULE_DEPEND(sbsh, pci, 1, 1, 1);
209 sbsh_probe(device_t dev)
211 if (pci_get_vendor(dev) != SBNI16_VENDOR
212 || pci_get_device(dev) != SBNI16_DEVICE
213 || pci_get_subdevice(dev) != SBNI16_SUBDEV)
216 device_set_desc(dev, "Granch SBNI16 G.SHDSL Modem");
217 return (BUS_PROBE_DEFAULT);
221 sbsh_attach(device_t dev)
223 struct sbsh_softc *sc;
225 int unit, error = 0, rid, s;
230 sc = device_get_softc(dev);
231 unit = device_get_unit(dev);
234 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
235 0, ~0, 4096, RF_ACTIVE);
237 if (sc->mem_res == NULL) {
238 printf ("sbsh%d: couldn't map memory\n", unit);
244 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
245 RF_SHAREABLE | RF_ACTIVE);
247 if (sc->irq_res == NULL) {
248 printf("sbsh%d: couldn't map interrupt\n", unit);
249 bus_release_resource(dev, SYS_RES_MEMORY,
250 PCIR_BAR(1), sc->mem_res);
255 sc->mem_base = rman_get_virtual(sc->mem_res);
258 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
259 sbsh_intr, sc, &sc->intr_hand);
261 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
262 bus_release_resource(dev, SYS_RES_MEMORY,
263 PCIR_BAR(1), sc->mem_res);
264 printf("sbsh%d: couldn't set up irq\n", unit);
268 /* generate ethernet MAC address */
269 *(u_int32_t *)eaddr = htonl(0x00ff0192);
270 read_random(eaddr + 4, 2);
272 ifp = sc->ifp = if_alloc(IFT_ETHER);
274 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
275 bus_release_resource(dev, SYS_RES_MEMORY,
276 PCIR_BAR(1), sc->mem_res);
277 bus_teardown_intr(dev, sc->irq_res, sc->intr_hand);
278 printf("sbsh%d: can not if_alloc()\n", unit);
282 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
283 ifp->if_mtu = ETHERMTU;
284 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
286 ifp->if_ioctl = sbsh_ioctl;
287 ifp->if_start = sbsh_start;
288 ifp->if_watchdog = sbsh_watchdog;
289 ifp->if_init = sbsh_init;
290 ifp->if_baudrate = 4600000;
291 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
293 ether_ifattach(ifp, eaddr);
301 sbsh_detach(device_t dev)
303 struct sbsh_softc *sc;
309 sc = device_get_softc(dev);
316 bus_teardown_intr(dev, sc->irq_res, sc->intr_hand);
317 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
318 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(1), sc->mem_res);
326 sbsh_start(struct ifnet *ifp)
328 struct sbsh_softc *sc = ifp->if_softc;
331 if (sc->state != ACTIVE)
335 start_xmit_frames(ifp->if_softc);
343 struct sbsh_softc *sc = xsc;
344 struct ifnet *ifp = sc->ifp;
348 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) || sc->state == NOT_LOADED)
353 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
354 sc->head_xq = sc->tail_xq = sc->head_rq = sc->tail_rq = 0;
355 sc->head_tdesc = sc->head_rdesc = 0;
359 issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1);
360 if (issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1) == 0) {
361 sc->state = ACTIVATION;
363 ifp->if_drv_flags |= IFF_DRV_RUNNING;
364 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
372 sbsh_stop(struct sbsh_softc *sc)
381 issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1);
382 if (sc->state == ACTIVE) {
384 issue_cx28975_cmd(sc, _DSL_FORCE_DEACTIVATE, &t, 1);
385 /* FIX! activation manager state */
387 /* Is it really must be done here? It calls from intr handler */
398 init_card(struct sbsh_softc *sc)
400 sc->state = NOT_LOADED;
401 sc->tbd = (struct hw_descr *) sc->mem_base;
402 sc->rbd = (struct hw_descr *) ((u_int8_t *)sc->mem_base + 0x400);
403 sc->regs = (struct sbni16_hw_regs *) ((u_int8_t *)sc->mem_base + 0x800);
404 sc->cmdp = (struct cx28975_cmdarea *) ((u_int8_t *)sc->mem_base + 0xc00);
413 sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
415 struct sbsh_softc *sc = ifp->if_softc;
416 struct ifreq *ifr = (struct ifreq *) data;
417 struct cx28975_cfg cfg;
427 if ((error = suser(curthread)) != 0)
429 if (ifp->if_flags & IFF_UP)
432 bcopy((caddr_t)ifr->ifr_data, (caddr_t)&cfg, sizeof cfg);
433 if (start_cx28975(sc, cfg) == 0) {
434 static char *modstr[] = {
435 "TCPAM32", "TCPAM16", "TCPAM8", "TCPAM4" };
436 if_printf(sc->ifp, "%s, rate %d, %s\n",
437 cfg.master ? "master" : "slave",
438 cfg.lrate << 3, modstr[cfg.mod]);
441 "unable to load firmware\n");
447 if ((error = suser(curthread)) != 0)
451 if (issue_cx28975_cmd(sc, _DSL_FAR_END_ATTEN, &t, 1))
453 ds.attenuat = sc->cmdp->out_data[0];
455 if (issue_cx28975_cmd(sc, _DSL_NOISE_MARGIN, &t, 1))
457 ds.nmr = sc->cmdp->out_data[0];
459 if (issue_cx28975_cmd(sc, _DSL_POWER_BACK_OFF_RESULT, &t, 1))
461 ds.tpbo = sc->cmdp->out_data[0];
462 ds.rpbo = sc->cmdp->out_data[1];
464 if (!issue_cx28975_cmd(sc, _DSL_HDSL_PERF_ERR_CTRS, &t, 1)) {
466 for (i = 0; i < 10; ++i)
467 ((u_int8_t *) &ds.losw)[i] =
468 sc->cmdp->out_data[i];
472 ds.status_1 = ((volatile u_int8_t *)sc->cmdp)[0x3c0];
473 ds.status_3 = ((volatile u_int8_t *)sc->cmdp)[0x3c2];
475 bcopy(&sc->in_stats, ifr->ifr_data, sizeof(struct sbni16_stats));
476 bcopy(&ds, ifr->ifr_data + sizeof(struct sbni16_stats),
477 sizeof(struct dsl_stats));
481 if (!(error = suser(curthread))) {
482 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
484 if (issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1))
490 if (ifp->if_flags & IFF_UP) {
491 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
492 if (sc->state == NOT_LOADED) {
493 if_printf(ifp, "firmware wasn't loaded\n");
499 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
501 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
512 error = ether_ioctl(ifp, cmd, data);
522 sbsh_shutdown(device_t dev)
524 struct sbsh_softc *sc = device_get_softc(dev);
530 sbsh_suspend(device_t dev)
532 struct sbsh_softc *sc = device_get_softc(dev);
543 sbsh_resume(device_t dev)
545 struct sbsh_softc *sc = device_get_softc(dev);
552 if (ifp->if_flags & IFF_UP)
561 sbsh_watchdog(struct ifnet *ifp)
563 struct sbsh_softc *sc = ifp->if_softc;
565 if_printf(ifp, "transmit timeout\n");
567 if (sc->regs->SR & TXS) {
569 if_printf(ifp, "interrupt posted but not delivered\n");
571 free_sent_buffers(sc);
574 /* -------------------------------------------------------------------------- */
579 struct sbsh_softc *sc = (struct sbsh_softc *)arg;
580 u_int8_t status = sc->regs->SR;
586 cx28975_interrupt(sc);
593 ++sc->in_stats.ufl_errs;
594 ++sc->ifp->if_oerrors;
600 alloc_rx_buffers(sc);
605 free_sent_buffers(sc);
609 ++sc->in_stats.crc_errs;
610 ++sc->ifp->if_ierrors;
615 ++sc->in_stats.ofl_errs;
616 ++sc->ifp->if_ierrors;
622 * Look for a first descriptor of a next packet, and write it's number
623 * into CTDR. Then enable the transmitter.
626 resume_tx(struct sbsh_softc *sc)
628 u_int32_t cur_tbd = sc->regs->CTDR;
630 while (cur_tbd != sc->regs->LTDR
631 && (sc->tbd[cur_tbd++].length & LAST_FRAG) == 0)
633 sc->regs->CTDR = cur_tbd;
634 sc->regs->CR |= TXEN;
638 start_xmit_frames(struct sbsh_softc *sc)
640 struct ifnet *ifp = sc->ifp;
644 * Check if we have any free descriptor(s) and free space in
645 * our transmit queue.
647 while (sc->tail_xq != ((sc->head_xq - 1) & (XQLEN - 1))
648 && sc->regs->LTDR != ((sc->head_tdesc - 1) & 0x7f)) {
650 IF_DEQUEUE(&ifp->if_snd, m);
653 if (m->m_pkthdr.len) {
660 if (sc->regs->CTDR != sc->regs->LTDR)
661 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
663 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
668 * MUST be called at splimp
671 encap_frame(struct sbsh_softc *sc, struct mbuf *m_head)
678 for (m = m_head; !m->m_len; m = m->m_next)
681 cur_tbd = sc->regs->LTDR & 0x7f;
684 if (m->m_len < 5 || cur_tbd == ((sc->head_tdesc - 1) & 0x7f)) {
685 if ((m_head = repack(sc, m_head)) != NULL)
686 goto look_for_nonzero;
691 sc->tbd[cur_tbd].address = vtophys(mtod(m, vm_offset_t));
692 sc->tbd[cur_tbd].length = m->m_len;
696 } while (m && !m->m_len);
698 if (!m) { /* last fragment has been reached */
699 sc->tbd[cur_tbd].length |= LAST_FRAG;
707 sc->xq[sc->tail_xq++] = m_head;
708 sc->tail_xq &= (XQLEN - 1);
710 sc->regs->LTDR = cur_tbd;
711 ++sc->in_stats.sent_pkts;
712 ++sc->ifp->if_opackets;
716 repack(struct sbsh_softc *sc, struct mbuf *m)
720 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
723 "unable to get mbuf.\n");
727 if (m->m_pkthdr.len > MHLEN) {
728 MCLGET(m_new, M_DONTWAIT);
729 if (!(m_new->m_flags & M_EXT)) {
732 "unable to get mbuf cluster.\n");
737 m_copydata(m, 0, m->m_pkthdr.len, mtod(m_new, caddr_t));
738 m_new->m_pkthdr.len = m_new->m_len = m->m_pkthdr.len;
744 free_sent_buffers(struct sbsh_softc *sc)
748 cur_tbd = sc->regs->CTDR;
750 while (sc->head_tdesc != cur_tbd) {
752 * Be careful! one element in xq may correspond to
753 * multiple descriptors.
755 if (sc->tbd[sc->head_tdesc].length & LAST_FRAG) {
756 m_freem(sc->xq[sc->head_xq++]);
757 sc->head_xq &= (XQLEN - 1);
760 sc->tbd[sc->head_tdesc].length = 0;
761 sc->head_tdesc = (sc->head_tdesc + 1) & 0x7f;
764 start_xmit_frames(sc);
768 * DON'T use free_sent_buffers to drop the queue!
771 alloc_rx_buffers(struct sbsh_softc *sc)
773 unsigned cur_rbd = sc->regs->LRDR & 0x7f;
776 while (sc->tail_rq != ((sc->head_rq - 1) & (RQLEN - 1))) {
777 MGETHDR(m, M_DONTWAIT, MT_DATA);
780 "unable to get mbuf.\n");
784 if (SBNI16_MAX_FRAME > MHLEN) {
785 MCLGET(m, M_DONTWAIT);
786 if (!(m->m_flags & M_EXT)) {
789 "unable to get mbuf cluster.\n");
792 m->m_pkthdr.len = m->m_len = MCLBYTES;
795 m_adj(m, 2); /* align ip on longword boundaries */
797 sc->rq[sc->tail_rq++] = m;
798 sc->tail_rq &= (RQLEN - 1);
800 sc->rbd[cur_rbd].address = vtophys(mtod(m, vm_offset_t));
801 sc->rbd[cur_rbd].length = 0;
802 sc->regs->LRDR = cur_rbd = (cur_rbd + 1) & 0x7f;
807 indicate_frames(struct sbsh_softc *sc)
809 unsigned cur_rbd = sc->regs->CRDR & 0x7f;
811 while (sc->head_rdesc != cur_rbd) {
812 struct mbuf *m = sc->rq[sc->head_rq++];
813 sc->head_rq &= (RQLEN - 1);
815 m->m_pkthdr.len = m->m_len =
816 sc->rbd[sc->head_rdesc].length & 0x7ff;
817 m->m_pkthdr.rcvif = sc->ifp;
819 (*sc->ifp->if_input)(sc->ifp, m);
820 ++sc->in_stats.rcvd_pkts;
821 ++sc->ifp->if_ipackets;
823 sc->head_rdesc = (sc->head_rdesc + 1) & 0x7f;
828 drop_queues(struct sbsh_softc *sc)
830 while (sc->head_rq != sc->tail_rq) {
831 m_freem(sc->rq[sc->head_rq++]);
832 sc->head_rq &= (RQLEN - 1);
835 while (sc->head_xq != sc->tail_xq) {
836 m_freem(sc->xq[sc->head_xq++]);
837 sc->head_xq &= (XQLEN - 1);
841 /* -------------------------------------------------------------------------- */
844 activate(struct sbsh_softc *sc)
848 sc->regs->SR = 0xff; /* clear it! */
849 sc->regs->CTDR = sc->regs->LTDR = sc->regs->CRDR = sc->regs->LRDR = 0;
851 sc->head_tdesc = sc->head_rdesc = 0;
852 alloc_rx_buffers(sc);
854 sc->regs->CRB &= ~RXDE;
855 sc->regs->IMR = EXT | RXS | TXS | CRC | OFL | UFL;
856 sc->regs->CR |= TXEN | RXEN;
859 ++sc->in_stats.attempts;
861 sc->in_stats.last_time = tv.tv_sec;
862 start_xmit_frames(sc);
866 deactivate(struct sbsh_softc *sc)
868 sc->regs->CR &= ~(RXEN | TXEN);
869 sc->regs->CRB |= RXDE;
871 sc->regs->CTDR = sc->regs->LTDR;
872 sc->regs->CRDR = sc->regs->LRDR;
873 sc->state = ACTIVATION;
878 /* -------------------------------------------------------------------------- */
881 cx28975_interrupt(struct sbsh_softc *sc)
883 volatile struct cx28975_cmdarea *p = sc->cmdp;
886 if (p->intr_host != 0xfe)
889 if (p->out_ack & 0x80) {
890 if (*((volatile u_int8_t *)p + 0x3c7) & 2) {
891 if (sc->state != ACTIVE
892 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) == 0x40) {
894 if_printf(sc->ifp, "connected to peer\n");
895 } else if (sc->state == ACTIVE
896 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) != 0x40) {
898 if_printf(sc->ifp, "carrier lost\n");
913 /* -------------------------------------------------------------------------- */
916 start_cx28975(struct sbsh_softc *sc, struct cx28975_cfg cfg)
918 static char thresh[] = { +8, -4, -16, -40 };
920 volatile struct cx28975_cmdarea *p = sc->cmdp;
921 u_int8_t t, parm[12];
933 sc->regs->CR |= CMOD;
935 sc->regs->CR |= FMOD;
937 sc->regs->CR |= PMOD;
939 sc->regs->CRB |= RODD | RXDE;
941 sc->regs->CRB |= RDBE;
943 sc->regs->CRB |= WTBE;
945 tsleep(sc, PWAIT, "sbsh", 0);
946 if ((p->out_ack & 0x1f) != _ACK_BOOT_WAKE_UP)
949 if (download_firmware(sc, cfg.firmw_image, cfg.firmw_len))
952 tsleep(sc, PWAIT, "sbsh", 0);
953 if ((p->out_ack & 0x1f) != _ACK_OPER_WAKE_UP)
956 t = cfg.master ? 1 : 9;
957 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_ENABLE, &t, 1))
961 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_CONFIG, &t, 1))
964 *(u_int16_t *)parm = cfg.lrate >> 3;
965 parm[2] = parm[3] = parm[0];
966 parm[5] = cfg.lrate & 7;
967 parm[4] = parm[7] = 1;
969 if (issue_cx28975_cmd(sc, _DSL_MULTI_RATE_CONFIG, parm, 8))
972 parm[0] = 0x02 | (cfg.mod << 4);
974 if (issue_cx28975_cmd(sc, _DSL_TRAINING_MODE, parm, 2))
978 parm[0] = 0x04; /* pre-activation: G.hs */
979 parm[4] = 0x04; /* no remote configuration */
980 parm[7] = 0x01; /* annex A (default) */
981 parm[8] = 0xff; /* i-bit mask (all bits) */
982 if (issue_cx28975_cmd(sc, _DSL_PREACTIVATION_CFG, parm, 12))
985 parm[0] = 0x03; /* dying gasp time - 3 frames */
986 parm[1] = thresh[cfg.mod];
987 parm[2] = 0xff; /* attenuation */
988 parm[3] = 0x04; /* line probe NMR (+2 dB) */
989 parm[4] = 0x00; /* reserved */
991 if (issue_cx28975_cmd(sc, _DSL_THRESHOLDS, parm, 6))
994 t = cfg.master ? 0x23 : 0x21;
995 if (issue_cx28975_cmd(sc, _DSL_FR_PCM_CONFIG, &t, 1))
999 if (issue_cx28975_cmd(sc, _DSL_INTR_HOST_MASK, &t, 1))
1007 download_firmware(struct sbsh_softc *sc, u_int8_t *img, u_int32_t img_len)
1013 for (i = 0; i < img_len; ++i)
1017 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_START, (u_int8_t *) &t, 4))
1020 for (i = 0; img_len >= 75; i += 75, img_len -= 75) {
1021 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, 75))
1026 && issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, img_len))
1029 t = (cksum ^ 0xff) + 1;
1030 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_END, (u_int8_t *) &t, 1))
1037 issue_cx28975_cmd(struct sbsh_softc *sc, u_int8_t cmd,
1038 u_int8_t *data, u_int8_t size)
1040 volatile struct cx28975_cmdarea *p = sc->cmdp;
1041 u_int8_t *databuf = p->in_data;
1049 p->in_length = --size;
1050 p->in_csum = 0xf0 ^ cmd ^ size ^ 0xaa;
1052 for (i = 0; i <= size; ++i) {
1054 *databuf++ = *data++; /* only 1 byte per cycle! */
1057 p->in_datasum = cksum ^ 0xaa;
1058 p->out_ack = _ACK_NOT_COMPLETE;
1059 p->intr_8051 = 0xfe;
1061 if (tsleep(sc, PWAIT, "sbsh", hz << 3))
1064 while (p->out_ack == _ACK_NOT_COMPLETE)
1067 if ((p->out_ack & 0x1f) == _ACK_PASS) {