Lines Matching refs: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 ((prandom_u32() % 256) > 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()
640 struct baycom_state *bc; in epp_bh() local
647 bc = container_of(work, struct baycom_state, run_work.work); in epp_bh()
648 dev = bc->dev; in epp_bh()
649 if (!bc->work_running) in epp_bh()
651 baycom_int_freq(bc); in epp_bh()
652 pp = bc->pdev->port; in epp_bh()
656 bc->stat = stat; in epp_bh()
657 bc->debug_vals.last_pllcorr = stat; in epp_bh()
659 if (bc->modem == EPP_FPGAEXTSTATUS) { in epp_bh()
680 if (transmit(bc, cnt2, stat)) in epp_bh()
687 bc->stat = stat; in epp_bh()
707 if (transmit(bc, cnt, stat)) in epp_bh()
731 if (bc->bitrate < 50000) in epp_bh()
733 else if (bc->bitrate < 100000) in epp_bh()
745 bc->debug_vals.mod_cycles = time2 - time1; in epp_bh()
746 bc->debug_vals.demod_cycles = time3 - time2; in epp_bh()
748 schedule_delayed_work(&bc->run_work, 1); in epp_bh()
749 if (!bc->skb) in epp_bh()
763 struct baycom_state *bc = netdev_priv(dev); in baycom_send_packet() local
769 do_kiss_params(bc, skb->data, skb->len); in baycom_send_packet()
773 if (bc->skb) { in baycom_send_packet()
783 bc->skb = skb; in baycom_send_packet()
803 struct baycom_state *bc = netdev_priv(dev); in epp_wakeup() local
806 if (!parport_claim(bc->pdev)) in epp_wakeup()
823 struct baycom_state *bc = netdev_priv(dev); in epp_open() local
848 memset(&bc->modem, 0, sizeof(bc->modem)); in epp_open()
863 bc->pdev = parport_register_dev_model(pp, dev->name, &par_cb, i); in epp_open()
865 if (!bc->pdev) { in epp_open()
869 if (parport_claim(bc->pdev)) { in epp_open()
871 parport_unregister_device(bc->pdev); in epp_open()
875 INIT_DELAYED_WORK(&bc->run_work, epp_bh); in epp_open()
876 bc->work_running = 1; in epp_open()
877 bc->modem = EPP_CONVENTIONAL; in epp_open()
878 if (eppconfig(bc)) in epp_open()
881 bc->modem = /*EPP_FPGA*/ EPP_FPGAEXTSTATUS; in epp_open()
914 bc->bitrate = i * (8 * HZ) / tstart; in epp_open()
916 i = bc->bitrate >> 3; in epp_open()
922 bc_drvname, bc->bitrate, j, bc->bitrate >> (j+2)); in epp_open()
929 bc->hdlcrx.state = 0; in epp_open()
930 bc->hdlcrx.numbits = 0; in epp_open()
931 bc->hdlctx.state = tx_idle; in epp_open()
932 bc->hdlctx.bufcnt = 0; in epp_open()
933 bc->hdlctx.slotcnt = bc->ch_params.slottime; in epp_open()
934 bc->hdlctx.calibrate = 0; in epp_open()
936 schedule_delayed_work(&bc->run_work, 1); in epp_open()
943 parport_release(bc->pdev); in epp_open()
944 parport_unregister_device(bc->pdev); in epp_open()
952 struct baycom_state *bc = netdev_priv(dev); in epp_close() local
953 struct parport *pp = bc->pdev->port; in epp_close()
956 bc->work_running = 0; in epp_close()
957 cancel_delayed_work_sync(&bc->run_work); in epp_close()
958 bc->stat = EPP_DCDBIT; in epp_close()
962 parport_release(bc->pdev); in epp_close()
963 parport_unregister_device(bc->pdev); in epp_close()
964 dev_kfree_skb(bc->skb); in epp_close()
965 bc->skb = NULL; in epp_close()
973 static int baycom_setmode(struct baycom_state *bc, const char *modestr) in baycom_setmode() argument
978 bc->cfg.intclk = 1; in baycom_setmode()
980 bc->cfg.intclk = 0; in baycom_setmode()
982 bc->cfg.extmodem = 0; in baycom_setmode()
984 bc->cfg.extmodem = 1; in baycom_setmode()
986 bc->cfg.loopback = 0; in baycom_setmode()
988 bc->cfg.loopback = 1; in baycom_setmode()
990 bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0); in baycom_setmode()
991 if (bc->cfg.fclk < 1000000) in baycom_setmode()
992 bc->cfg.fclk = 1000000; in baycom_setmode()
993 if (bc->cfg.fclk > 25000000) in baycom_setmode()
994 bc->cfg.fclk = 25000000; in baycom_setmode()
997 bc->cfg.bps = simple_strtoul(cp+4, NULL, 0); in baycom_setmode()
998 if (bc->cfg.bps < 1000) in baycom_setmode()
999 bc->cfg.bps = 1000; in baycom_setmode()
1000 if (bc->cfg.bps > 1500000) in baycom_setmode()
1001 bc->cfg.bps = 1500000; in baycom_setmode()
1011 struct baycom_state *bc = netdev_priv(dev); in baycom_siocdevprivate() local
1024 hi.data.cp.tx_delay = bc->ch_params.tx_delay; in baycom_siocdevprivate()
1025 hi.data.cp.tx_tail = bc->ch_params.tx_tail; in baycom_siocdevprivate()
1026 hi.data.cp.slottime = bc->ch_params.slottime; in baycom_siocdevprivate()
1027 hi.data.cp.ppersist = bc->ch_params.ppersist; in baycom_siocdevprivate()
1028 hi.data.cp.fulldup = bc->ch_params.fulldup; in baycom_siocdevprivate()
1034 bc->ch_params.tx_delay = hi.data.cp.tx_delay; in baycom_siocdevprivate()
1035 bc->ch_params.tx_tail = hi.data.cp.tx_tail; in baycom_siocdevprivate()
1036 bc->ch_params.slottime = hi.data.cp.slottime; in baycom_siocdevprivate()
1037 bc->ch_params.ppersist = hi.data.cp.ppersist; in baycom_siocdevprivate()
1038 bc->ch_params.fulldup = hi.data.cp.fulldup; in baycom_siocdevprivate()
1039 bc->hdlctx.slotcnt = 1; in baycom_siocdevprivate()
1061 hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_siocdevprivate()
1062 hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_siocdevprivate()
1063 hi.data.cs.ptt_keyed = bc->ptt_keyed; in baycom_siocdevprivate()
1071 hi.data.ocs.ptt = !!(bc->stat & EPP_PTTBIT); in baycom_siocdevprivate()
1072 hi.data.ocs.dcd = !(bc->stat & EPP_DCDBIT); in baycom_siocdevprivate()
1073 hi.data.ocs.ptt_keyed = bc->ptt_keyed; in baycom_siocdevprivate()
1079 bc->hdlctx.calibrate = hi.data.calibrate * bc->bitrate / 8; in baycom_siocdevprivate()
1088 bc->cfg.intclk ? "int" : "ext", in baycom_siocdevprivate()
1089 bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, in baycom_siocdevprivate()
1090 bc->cfg.loopback ? ",loopback" : ""); in baycom_siocdevprivate()
1097 return baycom_setmode(bc, hi.data.modename); in baycom_siocdevprivate()
1135 struct baycom_state *bc; in baycom_probe() local
1140 bc = netdev_priv(dev); in baycom_probe()
1144 bc->ch_params = dflt_ch_params; in baycom_probe()
1145 bc->ptt_keyed = 0; in baycom_probe()
1152 bc->skb = NULL; in baycom_probe()
1207 struct baycom_state *bc = netdev_priv(dev); in baycom_epp_dev_setup() local
1212 bc->dev = dev; in baycom_epp_dev_setup()
1213 bc->magic = BAYCOM_MAGIC; in baycom_epp_dev_setup()
1214 bc->cfg.fclk = 19666600; in baycom_epp_dev_setup()
1215 bc->cfg.bps = 9600; in baycom_epp_dev_setup()
1282 struct baycom_state *bc = netdev_priv(dev); in cleanup_baycomepp() local
1283 if (bc->magic == BAYCOM_MAGIC) { in cleanup_baycomepp()