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>
39 #include <sys/socket.h>
40 #include <sys/random.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 NULL, 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);
315 bus_teardown_intr(dev, sc->irq_res, sc->intr_hand);
316 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
317 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(1), sc->mem_res);
327 sbsh_start(struct ifnet *ifp)
329 struct sbsh_softc *sc = ifp->if_softc;
332 if (sc->state != ACTIVE)
336 start_xmit_frames(ifp->if_softc);
344 struct sbsh_softc *sc = xsc;
345 struct ifnet *ifp = sc->ifp;
349 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) || sc->state == NOT_LOADED)
354 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
355 sc->head_xq = sc->tail_xq = sc->head_rq = sc->tail_rq = 0;
356 sc->head_tdesc = sc->head_rdesc = 0;
360 issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1);
361 if (issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1) == 0) {
362 sc->state = ACTIVATION;
364 ifp->if_drv_flags |= IFF_DRV_RUNNING;
365 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
373 sbsh_stop(struct sbsh_softc *sc)
382 issue_cx28975_cmd(sc, _DSL_ACTIVATION, &t, 1);
383 if (sc->state == ACTIVE) {
385 issue_cx28975_cmd(sc, _DSL_FORCE_DEACTIVATE, &t, 1);
386 /* FIX! activation manager state */
388 /* Is it really must be done here? It calls from intr handler */
399 init_card(struct sbsh_softc *sc)
401 sc->state = NOT_LOADED;
402 sc->tbd = (struct hw_descr *) sc->mem_base;
403 sc->rbd = (struct hw_descr *) ((u_int8_t *)sc->mem_base + 0x400);
404 sc->regs = (struct sbni16_hw_regs *) ((u_int8_t *)sc->mem_base + 0x800);
405 sc->cmdp = (struct cx28975_cmdarea *) ((u_int8_t *)sc->mem_base + 0xc00);
414 sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
416 struct sbsh_softc *sc = ifp->if_softc;
417 struct ifreq *ifr = (struct ifreq *) data;
418 struct cx28975_cfg cfg;
428 if ((error = priv_check(curthread, PRIV_DRIVER)) != 0)
430 if (ifp->if_flags & IFF_UP)
433 bcopy((caddr_t)ifr->ifr_data, (caddr_t)&cfg, sizeof cfg);
434 if (start_cx28975(sc, cfg) == 0) {
435 static char *modstr[] = {
436 "TCPAM32", "TCPAM16", "TCPAM8", "TCPAM4" };
437 if_printf(sc->ifp, "%s, rate %d, %s\n",
438 cfg.master ? "master" : "slave",
439 cfg.lrate << 3, modstr[cfg.mod]);
442 "unable to load firmware\n");
448 if ((error = priv_check(curthread, PRIV_DRIVER)) != 0)
452 if (issue_cx28975_cmd(sc, _DSL_FAR_END_ATTEN, &t, 1))
454 ds.attenuat = sc->cmdp->out_data[0];
456 if (issue_cx28975_cmd(sc, _DSL_NOISE_MARGIN, &t, 1))
458 ds.nmr = sc->cmdp->out_data[0];
460 if (issue_cx28975_cmd(sc, _DSL_POWER_BACK_OFF_RESULT, &t, 1))
462 ds.tpbo = sc->cmdp->out_data[0];
463 ds.rpbo = sc->cmdp->out_data[1];
465 if (!issue_cx28975_cmd(sc, _DSL_HDSL_PERF_ERR_CTRS, &t, 1)) {
467 for (i = 0; i < 10; ++i)
468 ((u_int8_t *) &ds.losw)[i] =
469 sc->cmdp->out_data[i];
473 ds.status_1 = ((volatile u_int8_t *)sc->cmdp)[0x3c0];
474 ds.status_3 = ((volatile u_int8_t *)sc->cmdp)[0x3c2];
476 bcopy(&sc->in_stats, ifr->ifr_data, sizeof(struct sbni16_stats));
477 bcopy(&ds, ifr->ifr_data + sizeof(struct sbni16_stats),
478 sizeof(struct dsl_stats));
482 if (!(error = priv_check(curthread, PRIV_DRIVER))) {
483 bzero(&sc->in_stats, sizeof(struct sbni16_stats));
485 if (issue_cx28975_cmd(sc, _DSL_CLEAR_ERROR_CTRS, &t, 1))
491 if (ifp->if_flags & IFF_UP) {
492 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
493 if (sc->state == NOT_LOADED) {
494 if_printf(ifp, "firmware wasn't loaded\n");
500 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
502 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
513 error = ether_ioctl(ifp, cmd, data);
523 sbsh_shutdown(device_t dev)
525 struct sbsh_softc *sc = device_get_softc(dev);
531 sbsh_suspend(device_t dev)
533 struct sbsh_softc *sc = device_get_softc(dev);
544 sbsh_resume(device_t dev)
546 struct sbsh_softc *sc = device_get_softc(dev);
553 if (ifp->if_flags & IFF_UP)
562 sbsh_watchdog(struct ifnet *ifp)
564 struct sbsh_softc *sc = ifp->if_softc;
566 if_printf(ifp, "transmit timeout\n");
568 if (sc->regs->SR & TXS) {
570 if_printf(ifp, "interrupt posted but not delivered\n");
572 free_sent_buffers(sc);
575 /* -------------------------------------------------------------------------- */
580 struct sbsh_softc *sc = (struct sbsh_softc *)arg;
581 u_int8_t status = sc->regs->SR;
587 cx28975_interrupt(sc);
594 ++sc->in_stats.ufl_errs;
595 ++sc->ifp->if_oerrors;
601 alloc_rx_buffers(sc);
606 free_sent_buffers(sc);
610 ++sc->in_stats.crc_errs;
611 ++sc->ifp->if_ierrors;
616 ++sc->in_stats.ofl_errs;
617 ++sc->ifp->if_ierrors;
623 * Look for a first descriptor of a next packet, and write it's number
624 * into CTDR. Then enable the transmitter.
627 resume_tx(struct sbsh_softc *sc)
629 u_int32_t cur_tbd = sc->regs->CTDR;
631 while (cur_tbd != sc->regs->LTDR
632 && (sc->tbd[cur_tbd++].length & LAST_FRAG) == 0)
634 sc->regs->CTDR = cur_tbd;
635 sc->regs->CR |= TXEN;
639 start_xmit_frames(struct sbsh_softc *sc)
641 struct ifnet *ifp = sc->ifp;
645 * Check if we have any free descriptor(s) and free space in
646 * our transmit queue.
648 while (sc->tail_xq != ((sc->head_xq - 1) & (XQLEN - 1))
649 && sc->regs->LTDR != ((sc->head_tdesc - 1) & 0x7f)) {
651 IF_DEQUEUE(&ifp->if_snd, m);
654 if (m->m_pkthdr.len) {
661 if (sc->regs->CTDR != sc->regs->LTDR)
662 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
664 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
669 * MUST be called at splimp
672 encap_frame(struct sbsh_softc *sc, struct mbuf *m_head)
679 for (m = m_head; !m->m_len; m = m->m_next)
682 cur_tbd = sc->regs->LTDR & 0x7f;
685 if (m->m_len < 5 || cur_tbd == ((sc->head_tdesc - 1) & 0x7f)) {
686 if ((m_head = repack(sc, m_head)) != NULL)
687 goto look_for_nonzero;
692 sc->tbd[cur_tbd].address = vtophys(mtod(m, vm_offset_t));
693 sc->tbd[cur_tbd].length = m->m_len;
697 } while (m && !m->m_len);
699 if (!m) { /* last fragment has been reached */
700 sc->tbd[cur_tbd].length |= LAST_FRAG;
708 sc->xq[sc->tail_xq++] = m_head;
709 sc->tail_xq &= (XQLEN - 1);
711 sc->regs->LTDR = cur_tbd;
712 ++sc->in_stats.sent_pkts;
713 ++sc->ifp->if_opackets;
717 repack(struct sbsh_softc *sc, struct mbuf *m)
721 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
724 "unable to get mbuf.\n");
728 if (m->m_pkthdr.len > MHLEN) {
729 MCLGET(m_new, M_DONTWAIT);
730 if (!(m_new->m_flags & M_EXT)) {
733 "unable to get mbuf cluster.\n");
738 m_copydata(m, 0, m->m_pkthdr.len, mtod(m_new, caddr_t));
739 m_new->m_pkthdr.len = m_new->m_len = m->m_pkthdr.len;
745 free_sent_buffers(struct sbsh_softc *sc)
749 cur_tbd = sc->regs->CTDR;
751 while (sc->head_tdesc != cur_tbd) {
753 * Be careful! one element in xq may correspond to
754 * multiple descriptors.
756 if (sc->tbd[sc->head_tdesc].length & LAST_FRAG) {
757 m_freem(sc->xq[sc->head_xq++]);
758 sc->head_xq &= (XQLEN - 1);
761 sc->tbd[sc->head_tdesc].length = 0;
762 sc->head_tdesc = (sc->head_tdesc + 1) & 0x7f;
765 start_xmit_frames(sc);
769 * DON'T use free_sent_buffers to drop the queue!
772 alloc_rx_buffers(struct sbsh_softc *sc)
774 unsigned cur_rbd = sc->regs->LRDR & 0x7f;
777 while (sc->tail_rq != ((sc->head_rq - 1) & (RQLEN - 1))) {
778 MGETHDR(m, M_DONTWAIT, MT_DATA);
781 "unable to get mbuf.\n");
785 if (SBNI16_MAX_FRAME > MHLEN) {
786 MCLGET(m, M_DONTWAIT);
787 if (!(m->m_flags & M_EXT)) {
790 "unable to get mbuf cluster.\n");
793 m->m_pkthdr.len = m->m_len = MCLBYTES;
796 m_adj(m, 2); /* align ip on longword boundaries */
798 sc->rq[sc->tail_rq++] = m;
799 sc->tail_rq &= (RQLEN - 1);
801 sc->rbd[cur_rbd].address = vtophys(mtod(m, vm_offset_t));
802 sc->rbd[cur_rbd].length = 0;
803 sc->regs->LRDR = cur_rbd = (cur_rbd + 1) & 0x7f;
808 indicate_frames(struct sbsh_softc *sc)
810 unsigned cur_rbd = sc->regs->CRDR & 0x7f;
812 while (sc->head_rdesc != cur_rbd) {
813 struct mbuf *m = sc->rq[sc->head_rq++];
814 sc->head_rq &= (RQLEN - 1);
816 m->m_pkthdr.len = m->m_len =
817 sc->rbd[sc->head_rdesc].length & 0x7ff;
818 m->m_pkthdr.rcvif = sc->ifp;
820 (*sc->ifp->if_input)(sc->ifp, m);
821 ++sc->in_stats.rcvd_pkts;
822 ++sc->ifp->if_ipackets;
824 sc->head_rdesc = (sc->head_rdesc + 1) & 0x7f;
829 drop_queues(struct sbsh_softc *sc)
831 while (sc->head_rq != sc->tail_rq) {
832 m_freem(sc->rq[sc->head_rq++]);
833 sc->head_rq &= (RQLEN - 1);
836 while (sc->head_xq != sc->tail_xq) {
837 m_freem(sc->xq[sc->head_xq++]);
838 sc->head_xq &= (XQLEN - 1);
842 /* -------------------------------------------------------------------------- */
845 activate(struct sbsh_softc *sc)
849 sc->regs->SR = 0xff; /* clear it! */
850 sc->regs->CTDR = sc->regs->LTDR = sc->regs->CRDR = sc->regs->LRDR = 0;
852 sc->head_tdesc = sc->head_rdesc = 0;
853 alloc_rx_buffers(sc);
855 sc->regs->CRB &= ~RXDE;
856 sc->regs->IMR = EXT | RXS | TXS | CRC | OFL | UFL;
857 sc->regs->CR |= TXEN | RXEN;
860 ++sc->in_stats.attempts;
862 sc->in_stats.last_time = tv.tv_sec;
863 start_xmit_frames(sc);
867 deactivate(struct sbsh_softc *sc)
869 sc->regs->CR &= ~(RXEN | TXEN);
870 sc->regs->CRB |= RXDE;
872 sc->regs->CTDR = sc->regs->LTDR;
873 sc->regs->CRDR = sc->regs->LRDR;
874 sc->state = ACTIVATION;
879 /* -------------------------------------------------------------------------- */
882 cx28975_interrupt(struct sbsh_softc *sc)
884 volatile struct cx28975_cmdarea *p = sc->cmdp;
887 if (p->intr_host != 0xfe)
890 if (p->out_ack & 0x80) {
891 if (*((volatile u_int8_t *)p + 0x3c7) & 2) {
892 if (sc->state != ACTIVE
893 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) == 0x40) {
895 if_printf(sc->ifp, "connected to peer\n");
896 } else if (sc->state == ACTIVE
897 && (*((volatile u_int8_t *)p + 0x3c0) & 0xc0) != 0x40) {
899 if_printf(sc->ifp, "carrier lost\n");
914 /* -------------------------------------------------------------------------- */
917 start_cx28975(struct sbsh_softc *sc, struct cx28975_cfg cfg)
919 static char thresh[] = { +8, -4, -16, -40 };
921 volatile struct cx28975_cmdarea *p = sc->cmdp;
922 u_int8_t t, parm[12];
934 sc->regs->CR |= CMOD;
936 sc->regs->CR |= FMOD;
938 sc->regs->CR |= PMOD;
940 sc->regs->CRB |= RODD | RXDE;
942 sc->regs->CRB |= RDBE;
944 sc->regs->CRB |= WTBE;
946 tsleep(sc, PWAIT, "sbsh", 0);
947 if ((p->out_ack & 0x1f) != _ACK_BOOT_WAKE_UP)
950 if (download_firmware(sc, cfg.firmw_image, cfg.firmw_len))
953 tsleep(sc, PWAIT, "sbsh", 0);
954 if ((p->out_ack & 0x1f) != _ACK_OPER_WAKE_UP)
957 t = cfg.master ? 1 : 9;
958 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_ENABLE, &t, 1))
962 if (issue_cx28975_cmd(sc, _DSL_SYSTEM_CONFIG, &t, 1))
965 *(u_int16_t *)parm = cfg.lrate >> 3;
966 parm[2] = parm[3] = parm[0];
967 parm[5] = cfg.lrate & 7;
968 parm[4] = parm[7] = 1;
970 if (issue_cx28975_cmd(sc, _DSL_MULTI_RATE_CONFIG, parm, 8))
973 parm[0] = 0x02 | (cfg.mod << 4);
975 if (issue_cx28975_cmd(sc, _DSL_TRAINING_MODE, parm, 2))
979 parm[0] = 0x04; /* pre-activation: G.hs */
980 parm[4] = 0x04; /* no remote configuration */
981 parm[7] = 0x01; /* annex A (default) */
982 parm[8] = 0xff; /* i-bit mask (all bits) */
983 if (issue_cx28975_cmd(sc, _DSL_PREACTIVATION_CFG, parm, 12))
986 parm[0] = 0x03; /* dying gasp time - 3 frames */
987 parm[1] = thresh[cfg.mod];
988 parm[2] = 0xff; /* attenuation */
989 parm[3] = 0x04; /* line probe NMR (+2 dB) */
990 parm[4] = 0x00; /* reserved */
992 if (issue_cx28975_cmd(sc, _DSL_THRESHOLDS, parm, 6))
995 t = cfg.master ? 0x23 : 0x21;
996 if (issue_cx28975_cmd(sc, _DSL_FR_PCM_CONFIG, &t, 1))
1000 if (issue_cx28975_cmd(sc, _DSL_INTR_HOST_MASK, &t, 1))
1008 download_firmware(struct sbsh_softc *sc, u_int8_t *img, u_int32_t img_len)
1014 for (i = 0; i < img_len; ++i)
1018 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_START, (u_int8_t *) &t, 4))
1021 for (i = 0; img_len >= 75; i += 75, img_len -= 75) {
1022 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, 75))
1027 && issue_cx28975_cmd(sc, _DSL_DOWNLOAD_DATA, img + i, img_len))
1030 t = (cksum ^ 0xff) + 1;
1031 if (issue_cx28975_cmd(sc, _DSL_DOWNLOAD_END, (u_int8_t *) &t, 1))
1038 issue_cx28975_cmd(struct sbsh_softc *sc, u_int8_t cmd,
1039 u_int8_t *data, u_int8_t size)
1041 volatile struct cx28975_cmdarea *p = sc->cmdp;
1042 volatile u_int8_t *databuf = p->in_data;
1050 p->in_length = --size;
1051 p->in_csum = 0xf0 ^ cmd ^ size ^ 0xaa;
1053 for (i = 0; i <= size; ++i) {
1055 *databuf++ = *data++; /* only 1 byte per cycle! */
1058 p->in_datasum = cksum ^ 0xaa;
1059 p->out_ack = _ACK_NOT_COMPLETE;
1060 p->intr_8051 = 0xfe;
1062 if (tsleep(sc, PWAIT, "sbsh", hz << 3))
1065 while (p->out_ack == _ACK_NOT_COMPLETE)
1068 if ((p->out_ack & 0x1f) == _ACK_PASS) {