Lines Matching refs:bc
344 #define tenms_to_flags(bc,tenms) ((tenms * bc->bitrate) / 800) argument
348 static void inline baycom_int_freq(struct baycom_state *bc) in baycom_int_freq() argument
355 bc->debug_vals.cur_intcnt++; in baycom_int_freq()
356 if ((cur_jiffies - bc->debug_vals.last_jiffies) >= HZ) { in baycom_int_freq()
357 bc->debug_vals.last_jiffies = cur_jiffies; in baycom_int_freq()
358 bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; in baycom_int_freq()
359 bc->debug_vals.cur_intcnt = 0; in baycom_int_freq()
360 bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr; in baycom_int_freq()
361 bc->debug_vals.cur_pllcorr = 0; in baycom_int_freq()
377 struct baycom_state *bc = (struct baycom_state *)b; in exec_eppfpga() local
385 bc->cfg.intclk ? "int" : "ext", in exec_eppfpga()
386 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in exec_eppfpga()
387 (bc->cfg.fclk + 8 * bc->cfg.bps) / (16 * bc->cfg.bps), in exec_eppfpga()
388 bc->cfg.loopback ? ",loopback" : ""); in exec_eppfpga()
389 sprintf(portarg, "%ld", bc->pdev->port->base); in exec_eppfpga()
404 static int eppconfig(struct baycom_state *bc) in eppconfig() argument
409 pid = kernel_thread(exec_eppfpga, bc, CLONE_FS); in eppconfig()
435 static void inline do_kiss_params(struct baycom_state *bc, in do_kiss_params() argument
449 bc->ch_params.tx_delay = data[1]; in do_kiss_params()
450 PKP("TX delay = %ums", 10 * bc->ch_params.tx_delay); in do_kiss_params()
453 bc->ch_params.ppersist = data[1]; in do_kiss_params()
454 PKP("p persistence = %u", bc->ch_params.ppersist); in do_kiss_params()
457 bc->ch_params.slottime = data[1]; in do_kiss_params()
458 PKP("slot time = %ums", bc->ch_params.slottime); in do_kiss_params()
461 bc->ch_params.tx_tail = data[1]; in do_kiss_params()
462 PKP("TX tail = %ums", bc->ch_params.tx_tail); in do_kiss_params()
465 bc->ch_params.fulldup = !!data[1]; in do_kiss_params()
466 PKP("%s duplex", bc->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
499 static void encode_hdlc(struct baycom_state *bc) in encode_hdlc() argument
507 if (bc->hdlctx.bufcnt > 0) in encode_hdlc()
509 skb = bc->skb; in encode_hdlc()
512 bc->skb = NULL; in encode_hdlc()
514 wp = bc->hdlctx.buf; in encode_hdlc()
562 bc->hdlctx.bufptr = bc->hdlctx.buf; in encode_hdlc()
563 bc->hdlctx.bufcnt = wp - bc->hdlctx.buf; in encode_hdlc()
565 bc->stats.tx_packets++; in encode_hdlc()
580 static int transmit(struct baycom_state *bc, int cnt, unsigned char stat) in transmit() argument
582 struct parport *pp = bc->pdev->port; in transmit()
586 if (bc->hdlctx.state == tx_tail && !(stat & EPP_PTTBIT)) in transmit()
587 bc->hdlctx.state = tx_idle; in transmit()
588 if (bc->hdlctx.state == tx_idle && bc->hdlctx.calibrate <= 0) { in transmit()
589 if (bc->hdlctx.bufcnt <= 0) in transmit()
590 encode_hdlc(bc); in transmit()
591 if (bc->hdlctx.bufcnt <= 0) in transmit()
593 if (!bc->ch_params.fulldup) { in transmit()
595 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
598 if ((--bc->hdlctx.slotcnt) > 0) in transmit()
600 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
601 if ((random_num() % 256) > bc->ch_params.ppersist) in transmit()
605 if (bc->hdlctx.state == tx_idle && bc->hdlctx.bufcnt > 0) { in transmit()
606 bc->hdlctx.state = tx_keyup; in transmit()
607 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_delay); in transmit()
608 bc->ptt_keyed++; in transmit()
611 switch (bc->hdlctx.state) { in transmit()
613 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
615 bc->hdlctx.flags -= i; in transmit()
616 if (bc->hdlctx.flags <= 0) in transmit()
617 bc->hdlctx.state = tx_data; in transmit()
628 if (bc->hdlctx.bufcnt <= 0) { in transmit()
629 encode_hdlc(bc); in transmit()
630 if (bc->hdlctx.bufcnt <= 0) { in transmit()
631 bc->hdlctx.state = tx_tail; in transmit()
632 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_tail); in transmit()
636 i = min_t(int, cnt, bc->hdlctx.bufcnt); in transmit()
637 bc->hdlctx.bufcnt -= i; in transmit()
639 if (i != pp->ops->epp_write_data(pp, bc->hdlctx.bufptr, i, 0)) in transmit()
641 bc->hdlctx.bufptr += i; in transmit()
645 encode_hdlc(bc); in transmit()
646 if (bc->hdlctx.bufcnt > 0) { in transmit()
647 bc->hdlctx.state = tx_data; in transmit()
650 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
653 bc->hdlctx.flags -= i; in transmit()
665 if (bc->hdlctx.calibrate <= 0) in transmit()
667 i = min_t(int, cnt, bc->hdlctx.calibrate); in transmit()
669 bc->hdlctx.calibrate -= i; in transmit()
687 struct baycom_state *bc = (struct baycom_state *)dev->priv; in do_rxpacket() local
692 if (bc->hdlcrx.bufcnt < 4) in do_rxpacket()
694 if (!check_crc_ccitt(bc->hdlcrx.buf, bc->hdlcrx.bufcnt)) in do_rxpacket()
696 pktlen = bc->hdlcrx.bufcnt-2+1; /* KISS kludge */ in do_rxpacket()
699 bc->stats.rx_dropped++; in do_rxpacket()
705 memcpy(cp, bc->hdlcrx.buf, pktlen - 1); in do_rxpacket()
709 bc->stats.rx_packets++; in do_rxpacket()
732 bc->hdlcrx.bufcnt = 0; \
733 bc->hdlcrx.bufptr = bc->hdlcrx.buf; \
745 struct baycom_state *bc = (struct baycom_state *)dev->priv; in receive() local
746 struct parport *pp = bc->pdev->port; in receive()
752 numbits = bc->hdlcrx.numbits; in receive()
753 state = bc->hdlcrx.state; in receive()
754 bitstream = bc->hdlcrx.bitstream; in receive()
755 bitbuf = bc->hdlcrx.bitbuf; in receive()
790 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { in receive()
793 *(bc->hdlcrx.bufptr)++ = bitbuf >> (16-numbits); in receive()
794 bc->hdlcrx.bufcnt++; in receive()
800 bc->hdlcrx.numbits = numbits; in receive()
801 bc->hdlcrx.state = state; in receive()
802 bc->hdlcrx.bitstream = bitstream; in receive()
803 bc->hdlcrx.bitbuf = bitbuf; in receive()
821 struct baycom_state *bc; in epp_bh() local
829 bc = (struct baycom_state *)dev->priv; in epp_bh()
830 if (!bc->bh_running) in epp_bh()
832 baycom_int_freq(bc); in epp_bh()
833 pp = bc->pdev->port; in epp_bh()
837 bc->stat = stat; in epp_bh()
838 bc->debug_vals.last_pllcorr = stat; in epp_bh()
840 if (bc->modem == EPP_FPGAEXTSTATUS) { in epp_bh()
861 if (transmit(bc, cnt2, stat)) in epp_bh()
868 bc->stat = stat; in epp_bh()
888 if (transmit(bc, cnt, stat)) in epp_bh()
912 if (bc->bitrate < 50000) in epp_bh()
914 else if (bc->bitrate < 100000) in epp_bh()
926 bc->debug_vals.mod_cycles = time2 - time1; in epp_bh()
927 bc->debug_vals.demod_cycles = time3 - time2; in epp_bh()
929 queue_task(&bc->run_bh, &tq_timer); in epp_bh()
930 if (!bc->skb) in epp_bh()
944 struct baycom_state *bc; in baycom_send_packet() local
947 bc = (struct baycom_state *)dev->priv; in baycom_send_packet()
949 do_kiss_params(bc, skb->data, skb->len); in baycom_send_packet()
953 if (bc->skb) in baycom_send_packet()
961 bc->skb = skb; in baycom_send_packet()
980 struct baycom_state *bc; in baycom_get_stats() local
983 bc = (struct baycom_state *)dev->priv; in baycom_get_stats()
988 return &bc->stats; in baycom_get_stats()
996 struct baycom_state *bc; in epp_wakeup() local
999 bc = (struct baycom_state *)dev->priv; in epp_wakeup()
1001 if (!parport_claim(bc->pdev)) in epp_wakeup()
1018 struct baycom_state *bc; in epp_open() local
1030 bc = (struct baycom_state *)dev->priv; in epp_open()
1049 memset(&bc->modem, 0, sizeof(bc->modem)); in epp_open()
1050 if (!(bc->pdev = parport_register_device(pp, dev->name, NULL, epp_wakeup, in epp_open()
1055 if (parport_claim(bc->pdev)) { in epp_open()
1057 parport_unregister_device(bc->pdev); in epp_open()
1061 bc->run_bh = run_bh; in epp_open()
1062 bc->bh_running = 1; in epp_open()
1063 bc->modem = EPP_CONVENTIONAL; in epp_open()
1064 if (eppconfig(bc)) in epp_open()
1067 bc->modem = /*EPP_FPGA*/ EPP_FPGAEXTSTATUS; in epp_open()
1100 bc->bitrate = i * (8 * HZ) / tstart; in epp_open()
1102 i = bc->bitrate >> 3; in epp_open()
1108 bc_drvname, bc->bitrate, j, bc->bitrate >> (j+2)); in epp_open()
1115 bc->hdlcrx.state = 0; in epp_open()
1116 bc->hdlcrx.numbits = 0; in epp_open()
1117 bc->hdlctx.state = tx_idle; in epp_open()
1118 bc->hdlctx.bufcnt = 0; in epp_open()
1119 bc->hdlctx.slotcnt = bc->ch_params.slottime; in epp_open()
1120 bc->hdlctx.calibrate = 0; in epp_open()
1122 queue_task(&bc->run_bh, &tq_timer); in epp_open()
1130 parport_release(bc->pdev); in epp_open()
1131 parport_unregister_device(bc->pdev); in epp_open()
1139 struct baycom_state *bc; in epp_close() local
1144 bc = (struct baycom_state *)dev->priv; in epp_close()
1145 pp = bc->pdev->port; in epp_close()
1146 bc->bh_running = 0; in epp_close()
1148 bc->stat = EPP_DCDBIT; in epp_close()
1152 parport_release(bc->pdev); in epp_close()
1153 parport_unregister_device(bc->pdev); in epp_close()
1154 if (bc->skb) in epp_close()
1155 dev_kfree_skb(bc->skb); in epp_close()
1156 bc->skb = NULL; in epp_close()
1165 static int baycom_setmode(struct baycom_state *bc, const char *modestr) in baycom_setmode() argument
1170 bc->cfg.intclk = 1; in baycom_setmode()
1172 bc->cfg.intclk = 0; in baycom_setmode()
1174 bc->cfg.extmodem = 0; in baycom_setmode()
1176 bc->cfg.extmodem = 1; in baycom_setmode()
1178 bc->cfg.loopback = 0; in baycom_setmode()
1180 bc->cfg.loopback = 1; in baycom_setmode()
1182 bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0); in baycom_setmode()
1183 if (bc->cfg.fclk < 1000000) in baycom_setmode()
1184 bc->cfg.fclk = 1000000; in baycom_setmode()
1185 if (bc->cfg.fclk > 25000000) in baycom_setmode()
1186 bc->cfg.fclk = 25000000; in baycom_setmode()
1189 bc->cfg.bps = simple_strtoul(cp+4, NULL, 0); in baycom_setmode()
1190 if (bc->cfg.bps < 1000) in baycom_setmode()
1191 bc->cfg.bps = 1000; in baycom_setmode()
1192 if (bc->cfg.bps > 1500000) in baycom_setmode()
1193 bc->cfg.bps = 1500000; in baycom_setmode()
1202 struct baycom_state *bc; in baycom_ioctl() local
1208 bc = (struct baycom_state *)dev->priv; in baycom_ioctl()
1215 bi.data.dbg.debug1 = bc->ptt_keyed; in baycom_ioctl()
1216 bi.data.dbg.debug2 = bc->debug_vals.last_intcnt; in baycom_ioctl()
1217 bi.data.dbg.debug3 = bc->debug_vals.last_pllcorr; in baycom_ioctl()
1218 bc->debug_vals.last_intcnt = 0; in baycom_ioctl()
1224 si.data.dbg.int_rate = bc->debug_vals.last_intcnt; in baycom_ioctl()
1225 si.data.dbg.mod_cycles = bc->debug_vals.mod_cycles; in baycom_ioctl()
1226 si.data.dbg.demod_cycles = bc->debug_vals.demod_cycles; in baycom_ioctl()
1228 bc->debug_vals.mod_cycles = bc->debug_vals.demod_cycles = 0; in baycom_ioctl()
1229 bc->debug_vals.last_intcnt = 0; in baycom_ioctl()
1243 hi.data.cp.tx_delay = bc->ch_params.tx_delay; in baycom_ioctl()
1244 hi.data.cp.tx_tail = bc->ch_params.tx_tail; in baycom_ioctl()
1245 hi.data.cp.slottime = bc->ch_params.slottime; in baycom_ioctl()
1246 hi.data.cp.ppersist = bc->ch_params.ppersist; in baycom_ioctl()
1247 hi.data.cp.fulldup = bc->ch_params.fulldup; in baycom_ioctl()
1253 bc->ch_params.tx_delay = hi.data.cp.tx_delay; in baycom_ioctl()
1254 bc->ch_params.tx_tail = hi.data.cp.tx_tail; in baycom_ioctl()
1255 bc->ch_params.slottime = hi.data.cp.slottime; in baycom_ioctl()
1256 bc->ch_params.ppersist = hi.data.cp.ppersist; in baycom_ioctl()
1257 bc->ch_params.fulldup = hi.data.cp.fulldup; in baycom_ioctl()
1258 bc->hdlctx.slotcnt = 1; in baycom_ioctl()
1280 hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1281 hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1282 hi.data.cs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1283 hi.data.cs.tx_packets = bc->stats.tx_packets; in baycom_ioctl()
1284 hi.data.cs.tx_errors = bc->stats.tx_errors; in baycom_ioctl()
1285 hi.data.cs.rx_packets = bc->stats.rx_packets; in baycom_ioctl()
1286 hi.data.cs.rx_errors = bc->stats.rx_errors; in baycom_ioctl()
1290 hi.data.ocs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1291 hi.data.ocs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1292 hi.data.ocs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1298 bc->hdlctx.calibrate = hi.data.calibrate * bc->bitrate / 8; in baycom_ioctl()
1307 bc->cfg.intclk ? "int" : "ext", in baycom_ioctl()
1308 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in baycom_ioctl()
1309 bc->cfg.loopback ? ",loopback" : ""); in baycom_ioctl()
1316 return baycom_setmode(bc, hi.data.modename); in baycom_ioctl()
1352 struct baycom_state *bc; in baycom_probe() local
1360 bc = (struct baycom_state *)dev->priv; in baycom_probe()
1364 bc->ch_params = dflt_ch_params; in baycom_probe()
1365 bc->ptt_keyed = 0; in baycom_probe()
1377 bc->skb = NULL; in baycom_probe()
1426 struct baycom_state *bc; in init_baycomepp() local
1439 if (!(bc = dev->priv = kmalloc(sizeof(struct baycom_state), GFP_KERNEL))) in init_baycomepp()
1444 memset(bc, 0, sizeof(struct baycom_state)); in init_baycomepp()
1445 bc->magic = BAYCOM_MAGIC; in init_baycomepp()
1447 bc->cfg.fclk = 19666600; in init_baycomepp()
1448 bc->cfg.bps = 9600; in init_baycomepp()
1462 if (set_hw && baycom_setmode(bc, mode[i])) in init_baycomepp()
1474 struct baycom_state *bc; in cleanup_baycomepp() local
1479 bc = (struct baycom_state *)dev->priv; in cleanup_baycomepp()
1480 if (bc) { in cleanup_baycomepp()
1481 if (bc->magic == BAYCOM_MAGIC) { in cleanup_baycomepp()