Lines Matching refs:bc

275 #define tenms_to_flags(bc,tenms) ((tenms * bc->bitrate) / 800)  argument
279 static inline void baycom_int_freq(struct baycom_state *bc) in baycom_int_freq() argument
286 bc->debug_vals.cur_intcnt++; in baycom_int_freq()
287 if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { in baycom_int_freq()
288 bc->debug_vals.last_jiffies = cur_jiffies; in baycom_int_freq()
289 bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; in baycom_int_freq()
290 bc->debug_vals.cur_intcnt = 0; in baycom_int_freq()
291 bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr; in baycom_int_freq()
292 bc->debug_vals.cur_pllcorr = 0; in baycom_int_freq()
307 static int eppconfig(struct baycom_state *bc) in eppconfig() argument
320 bc->cfg.intclk ? "int" : "ext", in eppconfig()
321 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in eppconfig()
322 (bc->cfg.fclk + 8 * bc->cfg.bps) / (16 * bc->cfg.bps), in eppconfig()
323 bc->cfg.loopback ? ",loopback" : ""); in eppconfig()
324 sprintf(portarg, "%ld", bc->pdev->port->base); in eppconfig()
332 static inline void do_kiss_params(struct baycom_state *bc, in do_kiss_params() argument
346 bc->ch_params.tx_delay = data[1]; in do_kiss_params()
347 PKP("TX delay = %ums", 10 * bc->ch_params.tx_delay); in do_kiss_params()
350 bc->ch_params.ppersist = data[1]; in do_kiss_params()
351 PKP("p persistence = %u", bc->ch_params.ppersist); in do_kiss_params()
354 bc->ch_params.slottime = data[1]; in do_kiss_params()
355 PKP("slot time = %ums", bc->ch_params.slottime); in do_kiss_params()
358 bc->ch_params.tx_tail = data[1]; in do_kiss_params()
359 PKP("TX tail = %ums", bc->ch_params.tx_tail); in do_kiss_params()
362 bc->ch_params.fulldup = !!data[1]; in do_kiss_params()
363 PKP("%s duplex", bc->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
373 static void encode_hdlc(struct baycom_state *bc) in encode_hdlc() argument
382 if (bc->hdlctx.bufcnt > 0) in encode_hdlc()
384 skb = bc->skb; in encode_hdlc()
387 bc->skb = NULL; in encode_hdlc()
389 wp = bc->hdlctx.buf; in encode_hdlc()
427 bc->hdlctx.bufptr = bc->hdlctx.buf; in encode_hdlc()
428 bc->hdlctx.bufcnt = wp - bc->hdlctx.buf; in encode_hdlc()
430 bc->dev->stats.tx_packets++; in encode_hdlc()
435 static int transmit(struct baycom_state *bc, int cnt, unsigned char stat) in transmit() argument
437 struct parport *pp = bc->pdev->port; in transmit()
441 if (bc->hdlctx.state == tx_tail && !(stat & EPP_PTTBIT)) in transmit()
442 bc->hdlctx.state = tx_idle; in transmit()
443 if (bc->hdlctx.state == tx_idle && bc->hdlctx.calibrate <= 0) { in transmit()
444 if (bc->hdlctx.bufcnt <= 0) in transmit()
445 encode_hdlc(bc); in transmit()
446 if (bc->hdlctx.bufcnt <= 0) in transmit()
448 if (!bc->ch_params.fulldup) { in transmit()
450 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
453 if ((--bc->hdlctx.slotcnt) > 0) in transmit()
455 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
456 if ((prandom_u32() % 256) > bc->ch_params.ppersist) in transmit()
460 if (bc->hdlctx.state == tx_idle && bc->hdlctx.bufcnt > 0) { in transmit()
461 bc->hdlctx.state = tx_keyup; in transmit()
462 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_delay); in transmit()
463 bc->ptt_keyed++; in transmit()
466 switch (bc->hdlctx.state) { in transmit()
468 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
470 bc->hdlctx.flags -= i; in transmit()
471 if (bc->hdlctx.flags <= 0) in transmit()
472 bc->hdlctx.state = tx_data; in transmit()
483 if (bc->hdlctx.bufcnt <= 0) { in transmit()
484 encode_hdlc(bc); in transmit()
485 if (bc->hdlctx.bufcnt <= 0) { in transmit()
486 bc->hdlctx.state = tx_tail; in transmit()
487 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_tail); in transmit()
491 i = min_t(int, cnt, bc->hdlctx.bufcnt); in transmit()
492 bc->hdlctx.bufcnt -= i; in transmit()
494 if (i != pp->ops->epp_write_data(pp, bc->hdlctx.bufptr, i, 0)) in transmit()
496 bc->hdlctx.bufptr += i; in transmit()
500 encode_hdlc(bc); in transmit()
501 if (bc->hdlctx.bufcnt > 0) { in transmit()
502 bc->hdlctx.state = tx_data; in transmit()
505 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
508 bc->hdlctx.flags -= i; in transmit()
520 if (bc->hdlctx.calibrate <= 0) in transmit()
522 i = min_t(int, cnt, bc->hdlctx.calibrate); in transmit()
524 bc->hdlctx.calibrate -= i; in transmit()
542 struct baycom_state *bc = netdev_priv(dev); in do_rxpacket() local
547 if (bc->hdlcrx.bufcnt < 4) in do_rxpacket()
549 if (!check_crc_ccitt(bc->hdlcrx.buf, bc->hdlcrx.bufcnt)) in do_rxpacket()
551 pktlen = bc->hdlcrx.bufcnt-2+1; /* KISS kludge */ in do_rxpacket()
559 memcpy(cp, bc->hdlcrx.buf, pktlen - 1); in do_rxpacket()
567 struct baycom_state *bc = netdev_priv(dev); in receive() local
568 struct parport *pp = bc->pdev->port; in receive()
575 numbits = bc->hdlcrx.numbits; in receive()
576 state = bc->hdlcrx.state; in receive()
577 bitstream = bc->hdlcrx.bitstream; in receive()
578 bitbuf = bc->hdlcrx.bitbuf; in receive()
607 bc->hdlcrx.bufcnt = 0; in receive()
608 bc->hdlcrx.bufptr = bc->hdlcrx.buf; in receive()
621 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { in receive()
624 *(bc->hdlcrx.bufptr)++ = bitbuf >> (16-numbits); in receive()
625 bc->hdlcrx.bufcnt++; in receive()
631 bc->hdlcrx.numbits = numbits; in receive()
632 bc->hdlcrx.state = state; in receive()
633 bc->hdlcrx.bitstream = bitstream; in receive()
634 bc->hdlcrx.bitbuf = bitbuf; in receive()
654 struct baycom_state *bc; in epp_bh() local
661 bc = container_of(work, struct baycom_state, run_work.work); in epp_bh()
662 dev = bc->dev; in epp_bh()
663 if (!bc->work_running) in epp_bh()
665 baycom_int_freq(bc); in epp_bh()
666 pp = bc->pdev->port; in epp_bh()
670 bc->stat = stat; in epp_bh()
671 bc->debug_vals.last_pllcorr = stat; in epp_bh()
673 if (bc->modem == EPP_FPGAEXTSTATUS) { in epp_bh()
694 if (transmit(bc, cnt2, stat)) in epp_bh()
701 bc->stat = stat; in epp_bh()
721 if (transmit(bc, cnt, stat)) in epp_bh()
745 if (bc->bitrate < 50000) in epp_bh()
747 else if (bc->bitrate < 100000) in epp_bh()
759 bc->debug_vals.mod_cycles = time2 - time1; in epp_bh()
760 bc->debug_vals.demod_cycles = time3 - time2; in epp_bh()
762 schedule_delayed_work(&bc->run_work, 1); in epp_bh()
763 if (!bc->skb) in epp_bh()
777 struct baycom_state *bc = netdev_priv(dev); in baycom_send_packet() local
783 do_kiss_params(bc, skb->data, skb->len); in baycom_send_packet()
787 if (bc->skb) { in baycom_send_packet()
797 bc->skb = skb; in baycom_send_packet()
817 struct baycom_state *bc = netdev_priv(dev); in epp_wakeup() local
820 if (!parport_claim(bc->pdev)) in epp_wakeup()
837 struct baycom_state *bc = netdev_priv(dev); in epp_open() local
862 memset(&bc->modem, 0, sizeof(bc->modem)); in epp_open()
877 bc->pdev = parport_register_dev_model(pp, dev->name, &par_cb, i); in epp_open()
879 if (!bc->pdev) { in epp_open()
883 if (parport_claim(bc->pdev)) { in epp_open()
885 parport_unregister_device(bc->pdev); in epp_open()
889 INIT_DELAYED_WORK(&bc->run_work, epp_bh); in epp_open()
890 bc->work_running = 1; in epp_open()
891 bc->modem = EPP_CONVENTIONAL; in epp_open()
892 if (eppconfig(bc)) in epp_open()
895 bc->modem = /*EPP_FPGA*/ EPP_FPGAEXTSTATUS; in epp_open()
928 bc->bitrate = i * (8 * HZ) / tstart; in epp_open()
930 i = bc->bitrate >> 3; in epp_open()
936 bc_drvname, bc->bitrate, j, bc->bitrate >> (j+2)); in epp_open()
943 bc->hdlcrx.state = 0; in epp_open()
944 bc->hdlcrx.numbits = 0; in epp_open()
945 bc->hdlctx.state = tx_idle; in epp_open()
946 bc->hdlctx.bufcnt = 0; in epp_open()
947 bc->hdlctx.slotcnt = bc->ch_params.slottime; in epp_open()
948 bc->hdlctx.calibrate = 0; in epp_open()
950 schedule_delayed_work(&bc->run_work, 1); in epp_open()
957 parport_release(bc->pdev); in epp_open()
958 parport_unregister_device(bc->pdev); in epp_open()
966 struct baycom_state *bc = netdev_priv(dev); in epp_close() local
967 struct parport *pp = bc->pdev->port; in epp_close()
970 bc->work_running = 0; in epp_close()
971 cancel_delayed_work_sync(&bc->run_work); in epp_close()
972 bc->stat = EPP_DCDBIT; in epp_close()
976 parport_release(bc->pdev); in epp_close()
977 parport_unregister_device(bc->pdev); in epp_close()
978 if (bc->skb) in epp_close()
979 dev_kfree_skb(bc->skb); in epp_close()
980 bc->skb = NULL; in epp_close()
988 static int baycom_setmode(struct baycom_state *bc, const char *modestr) in baycom_setmode() argument
993 bc->cfg.intclk = 1; in baycom_setmode()
995 bc->cfg.intclk = 0; in baycom_setmode()
997 bc->cfg.extmodem = 0; in baycom_setmode()
999 bc->cfg.extmodem = 1; in baycom_setmode()
1001 bc->cfg.loopback = 0; in baycom_setmode()
1003 bc->cfg.loopback = 1; in baycom_setmode()
1005 bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0); in baycom_setmode()
1006 if (bc->cfg.fclk < 1000000) in baycom_setmode()
1007 bc->cfg.fclk = 1000000; in baycom_setmode()
1008 if (bc->cfg.fclk > 25000000) in baycom_setmode()
1009 bc->cfg.fclk = 25000000; in baycom_setmode()
1012 bc->cfg.bps = simple_strtoul(cp+4, NULL, 0); in baycom_setmode()
1013 if (bc->cfg.bps < 1000) in baycom_setmode()
1014 bc->cfg.bps = 1000; in baycom_setmode()
1015 if (bc->cfg.bps > 1500000) in baycom_setmode()
1016 bc->cfg.bps = 1500000; in baycom_setmode()
1025 struct baycom_state *bc = netdev_priv(dev); in baycom_ioctl() local
1038 hi.data.cp.tx_delay = bc->ch_params.tx_delay; in baycom_ioctl()
1039 hi.data.cp.tx_tail = bc->ch_params.tx_tail; in baycom_ioctl()
1040 hi.data.cp.slottime = bc->ch_params.slottime; in baycom_ioctl()
1041 hi.data.cp.ppersist = bc->ch_params.ppersist; in baycom_ioctl()
1042 hi.data.cp.fulldup = bc->ch_params.fulldup; in baycom_ioctl()
1048 bc->ch_params.tx_delay = hi.data.cp.tx_delay; in baycom_ioctl()
1049 bc->ch_params.tx_tail = hi.data.cp.tx_tail; in baycom_ioctl()
1050 bc->ch_params.slottime = hi.data.cp.slottime; in baycom_ioctl()
1051 bc->ch_params.ppersist = hi.data.cp.ppersist; in baycom_ioctl()
1052 bc->ch_params.fulldup = hi.data.cp.fulldup; in baycom_ioctl()
1053 bc->hdlctx.slotcnt = 1; in baycom_ioctl()
1075 hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1076 hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1077 hi.data.cs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1085 hi.data.ocs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1086 hi.data.ocs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1087 hi.data.ocs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1093 bc->hdlctx.calibrate = hi.data.calibrate * bc->bitrate / 8; in baycom_ioctl()
1102 bc->cfg.intclk ? "int" : "ext", in baycom_ioctl()
1103 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in baycom_ioctl()
1104 bc->cfg.loopback ? ",loopback" : ""); in baycom_ioctl()
1111 return baycom_setmode(bc, hi.data.modename); in baycom_ioctl()
1149 struct baycom_state *bc; in baycom_probe() local
1154 bc = netdev_priv(dev); in baycom_probe()
1158 bc->ch_params = dflt_ch_params; in baycom_probe()
1159 bc->ptt_keyed = 0; in baycom_probe()
1166 bc->skb = NULL; in baycom_probe()
1221 struct baycom_state *bc = netdev_priv(dev); in baycom_epp_dev_setup() local
1226 bc->dev = dev; in baycom_epp_dev_setup()
1227 bc->magic = BAYCOM_MAGIC; in baycom_epp_dev_setup()
1228 bc->cfg.fclk = 19666600; in baycom_epp_dev_setup()
1229 bc->cfg.bps = 9600; in baycom_epp_dev_setup()
1296 struct baycom_state *bc = netdev_priv(dev); in cleanup_baycomepp() local
1297 if (bc->magic == BAYCOM_MAGIC) { in cleanup_baycomepp()