Lines Matching refs:s

107 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16)  argument
114 static int hdlc_rx_add_bytes(struct hdlcdrv_state *s, unsigned int bits, in hdlc_rx_add_bytes() argument
119 while (s->hdlcrx.rx_state && num >= 8) { in hdlc_rx_add_bytes()
120 if (s->hdlcrx.len >= sizeof(s->hdlcrx.buffer)) { in hdlc_rx_add_bytes()
121 s->hdlcrx.rx_state = 0; in hdlc_rx_add_bytes()
124 *s->hdlcrx.bp++ = bits >> (32-num); in hdlc_rx_add_bytes()
125 s->hdlcrx.len++; in hdlc_rx_add_bytes()
132 static void hdlc_rx_flag(struct net_device *dev, struct hdlcdrv_state *s) in hdlc_rx_flag() argument
138 if (s->hdlcrx.len < 4) in hdlc_rx_flag()
140 if (!check_crc_ccitt(s->hdlcrx.buffer, s->hdlcrx.len)) in hdlc_rx_flag()
142 pkt_len = s->hdlcrx.len - 2 + 1; /* KISS kludge */ in hdlc_rx_flag()
150 memcpy(cp, s->hdlcrx.buffer, pkt_len - 1); in hdlc_rx_flag()
156 void hdlcdrv_receiver(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_receiver() argument
161 if (!s || s->magic != HDLCDRV_MAGIC) in hdlcdrv_receiver()
163 if (test_and_set_bit(0, &s->hdlcrx.in_hdlc_rx)) in hdlcdrv_receiver()
166 while (!hdlcdrv_hbuf_empty(&s->hdlcrx.hbuf)) { in hdlcdrv_receiver()
167 word = hdlcdrv_hbuf_get(&s->hdlcrx.hbuf); in hdlcdrv_receiver()
170 hdlcdrv_add_bitbuffer_word(&s->bitbuf_hdlc, word); in hdlcdrv_receiver()
172 s->hdlcrx.bitstream >>= 16; in hdlcdrv_receiver()
173 s->hdlcrx.bitstream |= word << 16; in hdlcdrv_receiver()
174 s->hdlcrx.bitbuf >>= 16; in hdlcdrv_receiver()
175 s->hdlcrx.bitbuf |= word << 16; in hdlcdrv_receiver()
176 s->hdlcrx.numbits += 16; in hdlcdrv_receiver()
182 if ((s->hdlcrx.bitstream & mask1) == mask1) in hdlcdrv_receiver()
183 s->hdlcrx.rx_state = 0; /* abort received */ in hdlcdrv_receiver()
184 else if ((s->hdlcrx.bitstream & mask2) == mask3) { in hdlcdrv_receiver()
186 if (s->hdlcrx.rx_state) { in hdlcdrv_receiver()
187 hdlc_rx_add_bytes(s, s->hdlcrx.bitbuf in hdlcdrv_receiver()
189 s->hdlcrx.numbits in hdlcdrv_receiver()
191 hdlc_rx_flag(dev, s); in hdlcdrv_receiver()
193 s->hdlcrx.len = 0; in hdlcdrv_receiver()
194 s->hdlcrx.bp = s->hdlcrx.buffer; in hdlcdrv_receiver()
195 s->hdlcrx.rx_state = 1; in hdlcdrv_receiver()
196 s->hdlcrx.numbits = i; in hdlcdrv_receiver()
197 } else if ((s->hdlcrx.bitstream & mask4) == mask5) { in hdlcdrv_receiver()
199 s->hdlcrx.numbits--; in hdlcdrv_receiver()
200 s->hdlcrx.bitbuf = (s->hdlcrx.bitbuf & (~mask6)) | in hdlcdrv_receiver()
201 ((s->hdlcrx.bitbuf & mask6) << 1); in hdlcdrv_receiver()
204 s->hdlcrx.numbits -= hdlc_rx_add_bytes(s, s->hdlcrx.bitbuf, in hdlcdrv_receiver()
205 s->hdlcrx.numbits); in hdlcdrv_receiver()
207 clear_bit(0, &s->hdlcrx.in_hdlc_rx); in hdlcdrv_receiver()
212 static inline void do_kiss_params(struct hdlcdrv_state *s, in do_kiss_params() argument
226 s->ch_params.tx_delay = data[1]; in do_kiss_params()
227 PKP("TX delay = %ums", 10 * s->ch_params.tx_delay); in do_kiss_params()
230 s->ch_params.ppersist = data[1]; in do_kiss_params()
231 PKP("p persistence = %u", s->ch_params.ppersist); in do_kiss_params()
234 s->ch_params.slottime = data[1]; in do_kiss_params()
235 PKP("slot time = %ums", s->ch_params.slottime); in do_kiss_params()
238 s->ch_params.tx_tail = data[1]; in do_kiss_params()
239 PKP("TX tail = %ums", s->ch_params.tx_tail); in do_kiss_params()
242 s->ch_params.fulldup = !!data[1]; in do_kiss_params()
243 PKP("%s duplex", s->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
253 void hdlcdrv_transmitter(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_transmitter() argument
260 if (!s || s->magic != HDLCDRV_MAGIC) in hdlcdrv_transmitter()
262 if (test_and_set_bit(0, &s->hdlctx.in_hdlc_tx)) in hdlcdrv_transmitter()
265 if (s->hdlctx.numbits >= 16) { in hdlcdrv_transmitter()
266 if (hdlcdrv_hbuf_full(&s->hdlctx.hbuf)) { in hdlcdrv_transmitter()
267 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
270 hdlcdrv_hbuf_put(&s->hdlctx.hbuf, s->hdlctx.bitbuf); in hdlcdrv_transmitter()
271 s->hdlctx.bitbuf >>= 16; in hdlcdrv_transmitter()
272 s->hdlctx.numbits -= 16; in hdlcdrv_transmitter()
274 switch (s->hdlctx.tx_state) { in hdlcdrv_transmitter()
276 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
280 if (s->hdlctx.numflags) { in hdlcdrv_transmitter()
281 s->hdlctx.numflags--; in hdlcdrv_transmitter()
282 s->hdlctx.bitbuf |= in hdlcdrv_transmitter()
283 0x7e7e << s->hdlctx.numbits; in hdlcdrv_transmitter()
284 s->hdlctx.numbits += 16; in hdlcdrv_transmitter()
287 if (s->hdlctx.tx_state == 1) { in hdlcdrv_transmitter()
288 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
291 if (!(skb = s->skb)) { in hdlcdrv_transmitter()
292 int flgs = tenms_to_2flags(s, s->ch_params.tx_tail); in hdlcdrv_transmitter()
295 s->hdlctx.tx_state = 1; in hdlcdrv_transmitter()
296 s->hdlctx.numflags = flgs; in hdlcdrv_transmitter()
299 s->skb = NULL; in hdlcdrv_transmitter()
303 s->hdlctx.tx_state = 0; in hdlcdrv_transmitter()
304 s->hdlctx.numflags = 1; in hdlcdrv_transmitter()
309 s->hdlctx.buffer, in hdlcdrv_transmitter()
312 s->hdlctx.bp = s->hdlctx.buffer; in hdlcdrv_transmitter()
313 append_crc_ccitt(s->hdlctx.buffer, pkt_len); in hdlcdrv_transmitter()
314 s->hdlctx.len = pkt_len+2; /* the appended CRC */ in hdlcdrv_transmitter()
315 s->hdlctx.tx_state = 2; in hdlcdrv_transmitter()
316 s->hdlctx.bitstream = 0; in hdlcdrv_transmitter()
320 if (!s->hdlctx.len) { in hdlcdrv_transmitter()
321 s->hdlctx.tx_state = 0; in hdlcdrv_transmitter()
322 s->hdlctx.numflags = 1; in hdlcdrv_transmitter()
325 s->hdlctx.len--; in hdlcdrv_transmitter()
326 s->hdlctx.bitbuf |= *s->hdlctx.bp << in hdlcdrv_transmitter()
327 s->hdlctx.numbits; in hdlcdrv_transmitter()
328 s->hdlctx.bitstream >>= 8; in hdlcdrv_transmitter()
329 s->hdlctx.bitstream |= (*s->hdlctx.bp++) << 16; in hdlcdrv_transmitter()
332 mask3 = 0xffffffff >> (31-s->hdlctx.numbits); in hdlcdrv_transmitter()
333 s->hdlctx.numbits += 8; in hdlcdrv_transmitter()
336 if ((s->hdlctx.bitstream & mask1) != mask1) in hdlcdrv_transmitter()
338 s->hdlctx.bitstream &= ~mask2; in hdlcdrv_transmitter()
339 s->hdlctx.bitbuf = in hdlcdrv_transmitter()
340 (s->hdlctx.bitbuf & mask3) | in hdlcdrv_transmitter()
341 ((s->hdlctx.bitbuf & in hdlcdrv_transmitter()
343 s->hdlctx.numbits++; in hdlcdrv_transmitter()
353 static void start_tx(struct net_device *dev, struct hdlcdrv_state *s) in start_tx() argument
355 s->hdlctx.tx_state = 0; in start_tx()
356 s->hdlctx.numflags = tenms_to_2flags(s, s->ch_params.tx_delay); in start_tx()
357 s->hdlctx.bitbuf = s->hdlctx.bitstream = s->hdlctx.numbits = 0; in start_tx()
358 hdlcdrv_transmitter(dev, s); in start_tx()
359 s->hdlctx.ptt = 1; in start_tx()
360 s->ptt_keyed++; in start_tx()
365 void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_arbitrate() argument
367 if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) in hdlcdrv_arbitrate()
369 if (s->ch_params.fulldup) { in hdlcdrv_arbitrate()
370 start_tx(dev, s); in hdlcdrv_arbitrate()
373 if (s->hdlcrx.dcd) { in hdlcdrv_arbitrate()
374 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_arbitrate()
377 if ((--s->hdlctx.slotcnt) > 0) in hdlcdrv_arbitrate()
379 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_arbitrate()
380 if (get_random_u8() > s->ch_params.ppersist) in hdlcdrv_arbitrate()
382 start_tx(dev, s); in hdlcdrv_arbitrate()
435 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_open() local
438 if (!s->ops || !s->ops->open) in hdlcdrv_open()
444 s->opened = 1; in hdlcdrv_open()
445 s->hdlcrx.hbuf.rd = s->hdlcrx.hbuf.wr = 0; in hdlcdrv_open()
446 s->hdlcrx.in_hdlc_rx = 0; in hdlcdrv_open()
447 s->hdlcrx.rx_state = 0; in hdlcdrv_open()
449 s->hdlctx.hbuf.rd = s->hdlctx.hbuf.wr = 0; in hdlcdrv_open()
450 s->hdlctx.in_hdlc_tx = 0; in hdlcdrv_open()
451 s->hdlctx.tx_state = 1; in hdlcdrv_open()
452 s->hdlctx.numflags = 0; in hdlcdrv_open()
453 s->hdlctx.bitstream = s->hdlctx.bitbuf = s->hdlctx.numbits = 0; in hdlcdrv_open()
454 s->hdlctx.ptt = 0; in hdlcdrv_open()
455 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_open()
456 s->hdlctx.calibrate = 0; in hdlcdrv_open()
458 i = s->ops->open(dev); in hdlcdrv_open()
472 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_close() local
477 if (s->ops && s->ops->close) in hdlcdrv_close()
478 i = s->ops->close(dev); in hdlcdrv_close()
479 dev_kfree_skb(s->skb); in hdlcdrv_close()
480 s->skb = NULL; in hdlcdrv_close()
481 s->opened = 0; in hdlcdrv_close()
490 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_siocdevprivate() local
504 if (s->ops && s->ops->ioctl) in hdlcdrv_siocdevprivate()
505 return s->ops->ioctl(dev, data, &bi, cmd); in hdlcdrv_siocdevprivate()
509 bi.data.cp.tx_delay = s->ch_params.tx_delay; in hdlcdrv_siocdevprivate()
510 bi.data.cp.tx_tail = s->ch_params.tx_tail; in hdlcdrv_siocdevprivate()
511 bi.data.cp.slottime = s->ch_params.slottime; in hdlcdrv_siocdevprivate()
512 bi.data.cp.ppersist = s->ch_params.ppersist; in hdlcdrv_siocdevprivate()
513 bi.data.cp.fulldup = s->ch_params.fulldup; in hdlcdrv_siocdevprivate()
519 s->ch_params.tx_delay = bi.data.cp.tx_delay; in hdlcdrv_siocdevprivate()
520 s->ch_params.tx_tail = bi.data.cp.tx_tail; in hdlcdrv_siocdevprivate()
521 s->ch_params.slottime = bi.data.cp.slottime; in hdlcdrv_siocdevprivate()
522 s->ch_params.ppersist = bi.data.cp.ppersist; in hdlcdrv_siocdevprivate()
523 s->ch_params.fulldup = bi.data.cp.fulldup; in hdlcdrv_siocdevprivate()
524 s->hdlctx.slotcnt = 1; in hdlcdrv_siocdevprivate()
531 bi.data.mp.dma2 = s->ptt_out.dma2; in hdlcdrv_siocdevprivate()
532 bi.data.mp.seriobase = s->ptt_out.seriobase; in hdlcdrv_siocdevprivate()
533 bi.data.mp.pariobase = s->ptt_out.pariobase; in hdlcdrv_siocdevprivate()
534 bi.data.mp.midiiobase = s->ptt_out.midiiobase; in hdlcdrv_siocdevprivate()
543 s->ptt_out.dma2 = bi.data.mp.dma2; in hdlcdrv_siocdevprivate()
544 s->ptt_out.seriobase = bi.data.mp.seriobase; in hdlcdrv_siocdevprivate()
545 s->ptt_out.pariobase = bi.data.mp.pariobase; in hdlcdrv_siocdevprivate()
546 s->ptt_out.midiiobase = bi.data.mp.midiiobase; in hdlcdrv_siocdevprivate()
550 bi.data.cs.ptt = hdlcdrv_ptt(s); in hdlcdrv_siocdevprivate()
551 bi.data.cs.dcd = s->hdlcrx.dcd; in hdlcdrv_siocdevprivate()
552 bi.data.cs.ptt_keyed = s->ptt_keyed; in hdlcdrv_siocdevprivate()
560 bi.data.ocs.ptt = hdlcdrv_ptt(s); in hdlcdrv_siocdevprivate()
561 bi.data.ocs.dcd = s->hdlcrx.dcd; in hdlcdrv_siocdevprivate()
562 bi.data.ocs.ptt_keyed = s->ptt_keyed; in hdlcdrv_siocdevprivate()
568 if (s->par.bitrate <= 0) in hdlcdrv_siocdevprivate()
570 if (bi.data.calibrate > INT_MAX / s->par.bitrate) in hdlcdrv_siocdevprivate()
572 s->hdlctx.calibrate = bi.data.calibrate * s->par.bitrate / 16; in hdlcdrv_siocdevprivate()
579 if (s->bitbuf_channel.rd == s->bitbuf_channel.wr) in hdlcdrv_siocdevprivate()
582 s->bitbuf_channel.buffer[s->bitbuf_channel.rd]; in hdlcdrv_siocdevprivate()
583 s->bitbuf_channel.rd = (s->bitbuf_channel.rd+1) % in hdlcdrv_siocdevprivate()
584 sizeof(s->bitbuf_channel.buffer); in hdlcdrv_siocdevprivate()
592 if (s->bitbuf_hdlc.rd == s->bitbuf_hdlc.wr) in hdlcdrv_siocdevprivate()
595 s->bitbuf_hdlc.buffer[s->bitbuf_hdlc.rd]; in hdlcdrv_siocdevprivate()
596 s->bitbuf_hdlc.rd = (s->bitbuf_hdlc.rd+1) % in hdlcdrv_siocdevprivate()
597 sizeof(s->bitbuf_hdlc.buffer); in hdlcdrv_siocdevprivate()
602 if (s->ops && s->ops->drvname) { in hdlcdrv_siocdevprivate()
603 strscpy(bi.data.drivername, s->ops->drvname, in hdlcdrv_siocdevprivate()
635 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_setup() local
640 s->ch_params = dflt_ch_params; in hdlcdrv_setup()
641 s->ptt_keyed = 0; in hdlcdrv_setup()
643 spin_lock_init(&s->hdlcrx.hbuf.lock); in hdlcdrv_setup()
644 s->hdlcrx.hbuf.rd = s->hdlcrx.hbuf.wr = 0; in hdlcdrv_setup()
645 s->hdlcrx.in_hdlc_rx = 0; in hdlcdrv_setup()
646 s->hdlcrx.rx_state = 0; in hdlcdrv_setup()
648 spin_lock_init(&s->hdlctx.hbuf.lock); in hdlcdrv_setup()
649 s->hdlctx.hbuf.rd = s->hdlctx.hbuf.wr = 0; in hdlcdrv_setup()
650 s->hdlctx.in_hdlc_tx = 0; in hdlcdrv_setup()
651 s->hdlctx.tx_state = 1; in hdlcdrv_setup()
652 s->hdlctx.numflags = 0; in hdlcdrv_setup()
653 s->hdlctx.bitstream = s->hdlctx.bitbuf = s->hdlctx.numbits = 0; in hdlcdrv_setup()
654 s->hdlctx.ptt = 0; in hdlcdrv_setup()
655 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_setup()
656 s->hdlctx.calibrate = 0; in hdlcdrv_setup()
659 s->bitbuf_channel.rd = s->bitbuf_channel.wr = 0; in hdlcdrv_setup()
660 s->bitbuf_channel.shreg = 0x80; in hdlcdrv_setup()
662 s->bitbuf_hdlc.rd = s->bitbuf_hdlc.wr = 0; in hdlcdrv_setup()
663 s->bitbuf_hdlc.shreg = 0x80; in hdlcdrv_setup()
669 s->skb = NULL; in hdlcdrv_setup()
690 struct hdlcdrv_state *s; in hdlcdrv_register() local
703 s = netdev_priv(dev); in hdlcdrv_register()
704 s->magic = HDLCDRV_MAGIC; in hdlcdrv_register()
705 s->ops = ops; in hdlcdrv_register()
724 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_unregister() local
726 BUG_ON(s->magic != HDLCDRV_MAGIC); in hdlcdrv_unregister()
728 if (s->opened && s->ops->close) in hdlcdrv_unregister()
729 s->ops->close(dev); in hdlcdrv_unregister()