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
316 bc->cfg.intclk ? "int" : "ext", in eppconfig()
317 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in eppconfig()
318 (bc->cfg.fclk + 8 * bc->cfg.bps) / (16 * bc->cfg.bps), in eppconfig()
319 bc->cfg.loopback ? ",loopback" : ""); in eppconfig()
320 sprintf(portarg, "%ld", bc->pdev->port->base); in eppconfig()
328 static inline void do_kiss_params(struct baycom_state *bc, in do_kiss_params() argument
342 bc->ch_params.tx_delay = data[1]; in do_kiss_params()
343 PKP("TX delay = %ums", 10 * bc->ch_params.tx_delay); in do_kiss_params()
346 bc->ch_params.ppersist = data[1]; in do_kiss_params()
347 PKP("p persistence = %u", bc->ch_params.ppersist); in do_kiss_params()
350 bc->ch_params.slottime = data[1]; in do_kiss_params()
351 PKP("slot time = %ums", bc->ch_params.slottime); in do_kiss_params()
354 bc->ch_params.tx_tail = data[1]; in do_kiss_params()
355 PKP("TX tail = %ums", bc->ch_params.tx_tail); in do_kiss_params()
358 bc->ch_params.fulldup = !!data[1]; in do_kiss_params()
359 PKP("%s duplex", bc->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
369 static void encode_hdlc(struct baycom_state *bc) in encode_hdlc() argument
378 if (bc->hdlctx.bufcnt > 0) in encode_hdlc()
380 skb = bc->skb; in encode_hdlc()
383 bc->skb = NULL; in encode_hdlc()
385 wp = bc->hdlctx.buf; in encode_hdlc()
423 bc->hdlctx.bufptr = bc->hdlctx.buf; in encode_hdlc()
424 bc->hdlctx.bufcnt = wp - bc->hdlctx.buf; in encode_hdlc()
426 bc->dev->stats.tx_packets++; in encode_hdlc()
431 static int transmit(struct baycom_state *bc, int cnt, unsigned char stat) in transmit() argument
433 struct parport *pp = bc->pdev->port; in transmit()
437 if (bc->hdlctx.state == tx_tail && !(stat & EPP_PTTBIT)) in transmit()
438 bc->hdlctx.state = tx_idle; in transmit()
439 if (bc->hdlctx.state == tx_idle && bc->hdlctx.calibrate <= 0) { in transmit()
440 if (bc->hdlctx.bufcnt <= 0) in transmit()
441 encode_hdlc(bc); in transmit()
442 if (bc->hdlctx.bufcnt <= 0) in transmit()
444 if (!bc->ch_params.fulldup) { in transmit()
446 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
449 if ((--bc->hdlctx.slotcnt) > 0) in transmit()
451 bc->hdlctx.slotcnt = bc->ch_params.slottime; in transmit()
452 if ((prandom_u32() % 256) > bc->ch_params.ppersist) in transmit()
456 if (bc->hdlctx.state == tx_idle && bc->hdlctx.bufcnt > 0) { in transmit()
457 bc->hdlctx.state = tx_keyup; in transmit()
458 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_delay); in transmit()
459 bc->ptt_keyed++; in transmit()
462 switch (bc->hdlctx.state) { in transmit()
464 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
466 bc->hdlctx.flags -= i; in transmit()
467 if (bc->hdlctx.flags <= 0) in transmit()
468 bc->hdlctx.state = tx_data; in transmit()
479 if (bc->hdlctx.bufcnt <= 0) { in transmit()
480 encode_hdlc(bc); in transmit()
481 if (bc->hdlctx.bufcnt <= 0) { in transmit()
482 bc->hdlctx.state = tx_tail; in transmit()
483 bc->hdlctx.flags = tenms_to_flags(bc, bc->ch_params.tx_tail); in transmit()
487 i = min_t(int, cnt, bc->hdlctx.bufcnt); in transmit()
488 bc->hdlctx.bufcnt -= i; in transmit()
490 if (i != pp->ops->epp_write_data(pp, bc->hdlctx.bufptr, i, 0)) in transmit()
492 bc->hdlctx.bufptr += i; in transmit()
496 encode_hdlc(bc); in transmit()
497 if (bc->hdlctx.bufcnt > 0) { in transmit()
498 bc->hdlctx.state = tx_data; in transmit()
501 i = min_t(int, cnt, bc->hdlctx.flags); in transmit()
504 bc->hdlctx.flags -= i; in transmit()
516 if (bc->hdlctx.calibrate <= 0) in transmit()
518 i = min_t(int, cnt, bc->hdlctx.calibrate); in transmit()
520 bc->hdlctx.calibrate -= i; in transmit()
538 struct baycom_state *bc = netdev_priv(dev); in do_rxpacket() local
543 if (bc->hdlcrx.bufcnt < 4) in do_rxpacket()
545 if (!check_crc_ccitt(bc->hdlcrx.buf, bc->hdlcrx.bufcnt)) in do_rxpacket()
547 pktlen = bc->hdlcrx.bufcnt-2+1; /* KISS kludge */ in do_rxpacket()
555 memcpy(cp, bc->hdlcrx.buf, pktlen - 1); in do_rxpacket()
563 struct baycom_state *bc = netdev_priv(dev); in receive() local
564 struct parport *pp = bc->pdev->port; in receive()
571 numbits = bc->hdlcrx.numbits; in receive()
572 state = bc->hdlcrx.state; in receive()
573 bitstream = bc->hdlcrx.bitstream; in receive()
574 bitbuf = bc->hdlcrx.bitbuf; in receive()
603 bc->hdlcrx.bufcnt = 0; in receive()
604 bc->hdlcrx.bufptr = bc->hdlcrx.buf; in receive()
617 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { in receive()
620 *(bc->hdlcrx.bufptr)++ = bitbuf >> (16-numbits); in receive()
621 bc->hdlcrx.bufcnt++; in receive()
627 bc->hdlcrx.numbits = numbits; in receive()
628 bc->hdlcrx.state = state; in receive()
629 bc->hdlcrx.bitstream = bitstream; in receive()
630 bc->hdlcrx.bitbuf = bitbuf; in receive()
650 struct baycom_state *bc; in epp_bh() local
657 bc = container_of(work, struct baycom_state, run_work.work); in epp_bh()
658 dev = bc->dev; in epp_bh()
659 if (!bc->work_running) in epp_bh()
661 baycom_int_freq(bc); in epp_bh()
662 pp = bc->pdev->port; in epp_bh()
666 bc->stat = stat; in epp_bh()
667 bc->debug_vals.last_pllcorr = stat; in epp_bh()
669 if (bc->modem == EPP_FPGAEXTSTATUS) { in epp_bh()
690 if (transmit(bc, cnt2, stat)) in epp_bh()
697 bc->stat = stat; in epp_bh()
717 if (transmit(bc, cnt, stat)) in epp_bh()
741 if (bc->bitrate < 50000) in epp_bh()
743 else if (bc->bitrate < 100000) in epp_bh()
755 bc->debug_vals.mod_cycles = time2 - time1; in epp_bh()
756 bc->debug_vals.demod_cycles = time3 - time2; in epp_bh()
758 schedule_delayed_work(&bc->run_work, 1); in epp_bh()
759 if (!bc->skb) in epp_bh()
773 struct baycom_state *bc = netdev_priv(dev); in baycom_send_packet() local
779 do_kiss_params(bc, skb->data, skb->len); in baycom_send_packet()
783 if (bc->skb) in baycom_send_packet()
791 bc->skb = skb; in baycom_send_packet()
811 struct baycom_state *bc = netdev_priv(dev); in epp_wakeup() local
814 if (!parport_claim(bc->pdev)) in epp_wakeup()
831 struct baycom_state *bc = netdev_priv(dev); in epp_open() local
855 memset(&bc->modem, 0, sizeof(bc->modem)); in epp_open()
856 bc->pdev = parport_register_device(pp, dev->name, NULL, epp_wakeup, 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 if (bc->skb) in epp_close()
959 dev_kfree_skb(bc->skb); in epp_close()
960 bc->skb = NULL; in epp_close()
968 static int baycom_setmode(struct baycom_state *bc, const char *modestr) in baycom_setmode() argument
973 bc->cfg.intclk = 1; in baycom_setmode()
975 bc->cfg.intclk = 0; in baycom_setmode()
977 bc->cfg.extmodem = 0; in baycom_setmode()
979 bc->cfg.extmodem = 1; in baycom_setmode()
981 bc->cfg.loopback = 0; in baycom_setmode()
983 bc->cfg.loopback = 1; in baycom_setmode()
985 bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0); in baycom_setmode()
986 if (bc->cfg.fclk < 1000000) in baycom_setmode()
987 bc->cfg.fclk = 1000000; in baycom_setmode()
988 if (bc->cfg.fclk > 25000000) in baycom_setmode()
989 bc->cfg.fclk = 25000000; in baycom_setmode()
992 bc->cfg.bps = simple_strtoul(cp+4, NULL, 0); in baycom_setmode()
993 if (bc->cfg.bps < 1000) in baycom_setmode()
994 bc->cfg.bps = 1000; in baycom_setmode()
995 if (bc->cfg.bps > 1500000) in baycom_setmode()
996 bc->cfg.bps = 1500000; in baycom_setmode()
1005 struct baycom_state *bc = netdev_priv(dev); in baycom_ioctl() local
1018 hi.data.cp.tx_delay = bc->ch_params.tx_delay; in baycom_ioctl()
1019 hi.data.cp.tx_tail = bc->ch_params.tx_tail; in baycom_ioctl()
1020 hi.data.cp.slottime = bc->ch_params.slottime; in baycom_ioctl()
1021 hi.data.cp.ppersist = bc->ch_params.ppersist; in baycom_ioctl()
1022 hi.data.cp.fulldup = bc->ch_params.fulldup; in baycom_ioctl()
1028 bc->ch_params.tx_delay = hi.data.cp.tx_delay; in baycom_ioctl()
1029 bc->ch_params.tx_tail = hi.data.cp.tx_tail; in baycom_ioctl()
1030 bc->ch_params.slottime = hi.data.cp.slottime; in baycom_ioctl()
1031 bc->ch_params.ppersist = hi.data.cp.ppersist; in baycom_ioctl()
1032 bc->ch_params.fulldup = hi.data.cp.fulldup; in baycom_ioctl()
1033 bc->hdlctx.slotcnt = 1; in baycom_ioctl()
1055 hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1056 hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1057 hi.data.cs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1065 hi.data.ocs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_ioctl()
1066 hi.data.ocs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_ioctl()
1067 hi.data.ocs.ptt_keyed = bc->ptt_keyed; in baycom_ioctl()
1073 bc->hdlctx.calibrate = hi.data.calibrate * bc->bitrate / 8; in baycom_ioctl()
1082 bc->cfg.intclk ? "int" : "ext", in baycom_ioctl()
1083 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in baycom_ioctl()
1084 bc->cfg.loopback ? ",loopback" : ""); in baycom_ioctl()
1091 return baycom_setmode(bc, hi.data.modename); in baycom_ioctl()
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()
1184 struct baycom_state *bc = netdev_priv(dev); in baycom_epp_dev_setup() local
1189 bc->dev = dev; in baycom_epp_dev_setup()
1190 bc->magic = BAYCOM_MAGIC; in baycom_epp_dev_setup()
1191 bc->cfg.fclk = 19666600; in baycom_epp_dev_setup()
1192 bc->cfg.bps = 9600; in baycom_epp_dev_setup()
1249 struct baycom_state *bc = netdev_priv(dev); in cleanup_baycomepp() local
1250 if (bc->magic == BAYCOM_MAGIC) { in cleanup_baycomepp()