Lines Matching full:bc
260 #define tenms_to_flags(bc,tenms) ((tenms * bc->bitrate) / 800) argument
264 static inline void baycom_int_freq(struct baycom_state *bc) in baycom_int_freq() argument
271 bc->debug_vals.cur_intcnt++; in baycom_int_freq()
272 if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { in baycom_int_freq()
273 bc->debug_vals.last_jiffies = cur_jiffies; in baycom_int_freq()
274 bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; in baycom_int_freq()
275 bc->debug_vals.cur_intcnt = 0; in baycom_int_freq()
276 bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr; in baycom_int_freq()
277 bc->debug_vals.cur_pllcorr = 0; in baycom_int_freq()
292 static int eppconfig(struct baycom_state *bc) in eppconfig() argument
305 bc->cfg.intclk ? "int" : "ext", in eppconfig()
306 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in eppconfig()
307 (bc->cfg.fclk + 8 * bc->cfg.bps) / (16 * bc->cfg.bps), in eppconfig()
308 bc->cfg.loopback ? ",loopback" : ""); in eppconfig()
309 sprintf(portarg, "%ld", bc->pdev->port->base); in eppconfig()
317 static inline void do_kiss_params(struct baycom_state *bc, in do_kiss_params() argument
331 bc->ch_params.tx_delay = data[1]; in do_kiss_params()
332 PKP("TX delay = %ums", 10 * bc->ch_params.tx_delay); in do_kiss_params()
335 bc->ch_params.ppersist = data[1]; in do_kiss_params()
336 PKP("p persistence = %u", bc->ch_params.ppersist); in do_kiss_params()
339 bc->ch_params.slottime = data[1]; in do_kiss_params()
340 PKP("slot time = %ums", bc->ch_params.slottime); in do_kiss_params()
343 bc->ch_params.tx_tail = data[1]; in do_kiss_params()
344 PKP("TX tail = %ums", bc->ch_params.tx_tail); in do_kiss_params()
347 bc->ch_params.fulldup = !!data[1]; in do_kiss_params()
348 PKP("%s duplex", bc->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
358 static void encode_hdlc(struct baycom_state *bc) in encode_hdlc() argument
367 if (bc->hdlctx.bufcnt > 0) in encode_hdlc()
369 skb = bc->skb; in encode_hdlc()
372 bc->skb = NULL; in encode_hdlc()
374 wp = bc->hdlctx.buf; in encode_hdlc()
412 bc->hdlctx.bufptr = bc->hdlctx.buf; in encode_hdlc()
413 bc->hdlctx.bufcnt = wp - bc->hdlctx.buf; in encode_hdlc()
415 bc->dev->stats.tx_packets++; in encode_hdlc()
420 static int transmit(struct baycom_state *bc, int cnt, unsigned char stat) in transmit() argument
422 struct parport *pp = bc->pdev->port; in transmit()
426 if (bc->hdlctx.state == tx_tail && !(stat & EPP_PTTBIT)) in transmit()
427 bc->hdlctx.state = tx_idle; in transmit()
428 if (bc->hdlctx.state == tx_idle && bc->hdlctx.calibrate <= 0) { in transmit()
429 if (bc->hdlctx.bufcnt <= 0) in transmit()
430 encode_hdlc(bc); in transmit()
431 if (bc->hdlctx.bufcnt <= 0) in transmit()
433 if (!bc->ch_params.fulldup) { in transmit()
435 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
438 if ((--bc->hdlctx.slotcnt) > 0) in transmit()
440 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
441 if (get_random_u8() > bc->ch_params.ppersist) in transmit()
445 if (bc->hdlctx.state == tx_idle && bc->hdlctx.bufcnt > 0) { in transmit()
446 bc->hdlctx.state = tx_keyup; in transmit()
447 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_delay); in transmit()
448 bc->ptt_keyed++; in transmit()
451 switch (bc->hdlctx.state) { in transmit()
453 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
455 bc->hdlctx.flags -= i; in transmit()
456 if (bc->hdlctx.flags <= 0) in transmit()
457 bc->hdlctx.state = tx_data; in transmit()
468 if (bc->hdlctx.bufcnt <= 0) { in transmit()
469 encode_hdlc(bc); in transmit()
470 if (bc->hdlctx.bufcnt <= 0) { in transmit()
471 bc->hdlctx.state = tx_tail; in transmit()
472 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_tail); in transmit()
476 i = min_t(int, cnt, bc->hdlctx.bufcnt); in transmit()
477 bc->hdlctx.bufcnt -= i; in transmit()
479 if (i != pp->ops->epp_write_data(pp, bc->hdlctx.bufptr, i, 0)) in transmit()
481 bc->hdlctx.bufptr += i; in transmit()
485 encode_hdlc(bc); in transmit()
486 if (bc->hdlctx.bufcnt > 0) { in transmit()
487 bc->hdlctx.state = tx_data; in transmit()
490 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
493 bc->hdlctx.flags -= i; in transmit()
506 if (bc->hdlctx.calibrate <= 0) in transmit()
508 i = min_t(int, cnt, bc->hdlctx.calibrate); in transmit()
510 bc->hdlctx.calibrate -= i; in transmit()
528 struct baycom_state *bc = netdev_priv(dev); in do_rxpacket() local
533 if (bc->hdlcrx.bufcnt < 4) in do_rxpacket()
535 if (!check_crc_ccitt(bc->hdlcrx.buf, bc->hdlcrx.bufcnt)) in do_rxpacket()
537 pktlen = bc->hdlcrx.bufcnt-2+1; /* KISS kludge */ in do_rxpacket()
545 memcpy(cp, bc->hdlcrx.buf, pktlen - 1); in do_rxpacket()
553 struct baycom_state *bc = netdev_priv(dev); in receive() local
554 struct parport *pp = bc->pdev->port; in receive()
561 numbits = bc->hdlcrx.numbits; in receive()
562 state = bc->hdlcrx.state; in receive()
563 bitstream = bc->hdlcrx.bitstream; in receive()
564 bitbuf = bc->hdlcrx.bitbuf; in receive()
593 bc->hdlcrx.bufcnt = 0; in receive()
594 bc->hdlcrx.bufptr = bc->hdlcrx.buf; in receive()
607 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { in receive()
610 *(bc->hdlcrx.bufptr)++ = bitbuf >> (16-numbits); in receive()
611 bc->hdlcrx.bufcnt++; in receive()
617 bc->hdlcrx.numbits = numbits; in receive()
618 bc->hdlcrx.state = state; in receive()
619 bc->hdlcrx.bitstream = bitstream; in receive()
620 bc->hdlcrx.bitbuf = bitbuf; in receive()
634 struct baycom_state *bc; in epp_bh() local
641 bc = container_of(work, struct baycom_state, run_work.work); in epp_bh()
642 dev = bc->dev; in epp_bh()
643 if (!bc->work_running) in epp_bh()
645 baycom_int_freq(bc); in epp_bh()
646 pp = bc->pdev->port; in epp_bh()
650 bc->stat = stat; in epp_bh()
651 bc->debug_vals.last_pllcorr = stat; in epp_bh()
653 if (bc->modem == EPP_FPGAEXTSTATUS) { in epp_bh()
674 if (transmit(bc, cnt2, stat)) in epp_bh()
681 bc->stat = stat; in epp_bh()
701 if (transmit(bc, cnt, stat)) in epp_bh()
725 if (bc->bitrate < 50000) in epp_bh()
727 else if (bc->bitrate < 100000) in epp_bh()
739 bc->debug_vals.mod_cycles = time2 - time1; in epp_bh()
740 bc->debug_vals.demod_cycles = time3 - time2; in epp_bh()
742 schedule_delayed_work(&bc->run_work, 1); in epp_bh()
743 if (!bc->skb) in epp_bh()
757 struct baycom_state *bc = netdev_priv(dev); in baycom_send_packet() local
763 do_kiss_params(bc, skb->data, skb->len); in baycom_send_packet()
767 if (bc->skb) { in baycom_send_packet()
777 bc->skb = skb; in baycom_send_packet()
797 struct baycom_state *bc = netdev_priv(dev); in epp_wakeup() local
800 if (!parport_claim(bc->pdev)) in epp_wakeup()
817 struct baycom_state *bc = netdev_priv(dev); in epp_open() local
842 memset(&bc->modem, 0, sizeof(bc->modem)); in epp_open()
857 bc->pdev = parport_register_dev_model(pp, dev->name, &par_cb, i); in epp_open()
859 if (!bc->pdev) { in epp_open()
863 if (parport_claim(bc->pdev)) { in epp_open()
865 parport_unregister_device(bc->pdev); in epp_open()
869 INIT_DELAYED_WORK(&bc->run_work, epp_bh); in epp_open()
870 bc->work_running = 1; in epp_open()
871 bc->modem = EPP_CONVENTIONAL; in epp_open()
872 if (eppconfig(bc)) in epp_open()
875 bc->modem = /*EPP_FPGA*/ EPP_FPGAEXTSTATUS; in epp_open()
908 bc->bitrate = i * (8 * HZ) / tstart; in epp_open()
910 i = bc->bitrate >> 3; in epp_open()
916 bc_drvname, bc->bitrate, j, bc->bitrate >> (j+2)); in epp_open()
923 bc->hdlcrx.state = 0; in epp_open()
924 bc->hdlcrx.numbits = 0; in epp_open()
925 bc->hdlctx.state = tx_idle; in epp_open()
926 bc->hdlctx.bufcnt = 0; in epp_open()
927 bc->hdlctx.slotcnt = bc->ch_params.slottime; in epp_open()
928 bc->hdlctx.calibrate = 0; in epp_open()
930 schedule_delayed_work(&bc->run_work, 1); in epp_open()
937 parport_release(bc->pdev); in epp_open()
938 parport_unregister_device(bc->pdev); in epp_open()
946 struct baycom_state *bc = netdev_priv(dev); in epp_close() local
947 struct parport *pp = bc->pdev->port; in epp_close()
950 bc->work_running = 0; in epp_close()
951 cancel_delayed_work_sync(&bc->run_work); in epp_close()
952 bc->stat = EPP_DCDBIT; in epp_close()
956 parport_release(bc->pdev); in epp_close()
957 parport_unregister_device(bc->pdev); in epp_close()
958 dev_kfree_skb(bc->skb); in epp_close()
959 bc->skb = NULL; in epp_close()
967 static int baycom_setmode(struct baycom_state *bc, const char *modestr) in baycom_setmode() argument
972 bc->cfg.intclk = 1; in baycom_setmode()
974 bc->cfg.intclk = 0; in baycom_setmode()
976 bc->cfg.extmodem = 0; in baycom_setmode()
978 bc->cfg.extmodem = 1; in baycom_setmode()
980 bc->cfg.loopback = 1; in baycom_setmode()
982 bc->cfg.loopback = 0; in baycom_setmode()
984 bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0); in baycom_setmode()
985 if (bc->cfg.fclk < 1000000) in baycom_setmode()
986 bc->cfg.fclk = 1000000; in baycom_setmode()
987 if (bc->cfg.fclk > 25000000) in baycom_setmode()
988 bc->cfg.fclk = 25000000; in baycom_setmode()
991 bc->cfg.bps = simple_strtoul(cp+4, NULL, 0); in baycom_setmode()
992 if (bc->cfg.bps < 1000) in baycom_setmode()
993 bc->cfg.bps = 1000; in baycom_setmode()
994 if (bc->cfg.bps > 1500000) in baycom_setmode()
995 bc->cfg.bps = 1500000; in baycom_setmode()
1005 struct baycom_state *bc = netdev_priv(dev); in baycom_siocdevprivate() local
1018 hi.data.cp.tx_delay = bc->ch_params.tx_delay; in baycom_siocdevprivate()
1019 hi.data.cp.tx_tail = bc->ch_params.tx_tail; in baycom_siocdevprivate()
1020 hi.data.cp.slottime = bc->ch_params.slottime; in baycom_siocdevprivate()
1021 hi.data.cp.ppersist = bc->ch_params.ppersist; in baycom_siocdevprivate()
1022 hi.data.cp.fulldup = bc->ch_params.fulldup; in baycom_siocdevprivate()
1028 bc->ch_params.tx_delay = hi.data.cp.tx_delay; in baycom_siocdevprivate()
1029 bc->ch_params.tx_tail = hi.data.cp.tx_tail; in baycom_siocdevprivate()
1030 bc->ch_params.slottime = hi.data.cp.slottime; in baycom_siocdevprivate()
1031 bc->ch_params.ppersist = hi.data.cp.ppersist; in baycom_siocdevprivate()
1032 bc->ch_params.fulldup = hi.data.cp.fulldup; in baycom_siocdevprivate()
1033 bc->hdlctx.slotcnt = 1; in baycom_siocdevprivate()
1055 hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_siocdevprivate()
1056 hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_siocdevprivate()
1057 hi.data.cs.ptt_keyed = bc->ptt_keyed; in baycom_siocdevprivate()
1065 hi.data.ocs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_siocdevprivate()
1066 hi.data.ocs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_siocdevprivate()
1067 hi.data.ocs.ptt_keyed = bc->ptt_keyed; in baycom_siocdevprivate()
1073 bc->hdlctx.calibrate = hi.data.calibrate * bc->bitrate / 8; in baycom_siocdevprivate()
1082 bc->cfg.intclk ? "int" : "ext", in baycom_siocdevprivate()
1083 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in baycom_siocdevprivate()
1084 bc->cfg.loopback ? ",loopback" : ""); in baycom_siocdevprivate()
1091 return baycom_setmode(bc, hi.data.modename); in baycom_siocdevprivate()
1129 struct baycom_state *bc; in baycom_probe() local
1134 bc = netdev_priv(dev); in baycom_probe()
1138 bc->ch_params = dflt_ch_params; in baycom_probe()
1139 bc->ptt_keyed = 0; in baycom_probe()
1146 bc->skb = NULL; in baycom_probe()
1200 struct baycom_state *bc = netdev_priv(dev); in baycom_epp_dev_setup() local
1205 bc->dev = dev; in baycom_epp_dev_setup()
1206 bc->magic = BAYCOM_MAGIC; in baycom_epp_dev_setup()
1207 bc->cfg.fclk = 19666600; in baycom_epp_dev_setup()
1208 bc->cfg.bps = 9600; in baycom_epp_dev_setup()
1275 struct baycom_state *bc = netdev_priv(dev); in cleanup_baycomepp() local
1276 if (bc->magic == BAYCOM_MAGIC) { in cleanup_baycomepp()