Lines Matching full:s
106 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16) argument
113 static int hdlc_rx_add_bytes(struct hdlcdrv_state *s, unsigned int bits, in hdlc_rx_add_bytes() argument
118 while (s->hdlcrx.rx_state && num >= 8) { in hdlc_rx_add_bytes()
119 if (s->hdlcrx.len >= sizeof(s->hdlcrx.buffer)) { in hdlc_rx_add_bytes()
120 s->hdlcrx.rx_state = 0; in hdlc_rx_add_bytes()
123 *s->hdlcrx.bp++ = bits >> (32-num); in hdlc_rx_add_bytes()
124 s->hdlcrx.len++; in hdlc_rx_add_bytes()
131 static void hdlc_rx_flag(struct net_device *dev, struct hdlcdrv_state *s) in hdlc_rx_flag() argument
137 if (s->hdlcrx.len < 4) in hdlc_rx_flag()
139 if (!check_crc_ccitt(s->hdlcrx.buffer, s->hdlcrx.len)) in hdlc_rx_flag()
141 pkt_len = s->hdlcrx.len - 2 + 1; /* KISS kludge */ in hdlc_rx_flag()
143 printk("%s: memory squeeze, dropping packet\n", dev->name); in hdlc_rx_flag()
149 memcpy(cp, s->hdlcrx.buffer, pkt_len - 1); in hdlc_rx_flag()
155 void hdlcdrv_receiver(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_receiver() argument
160 if (!s || s->magic != HDLCDRV_MAGIC) in hdlcdrv_receiver()
162 if (test_and_set_bit(0, &s->hdlcrx.in_hdlc_rx)) in hdlcdrv_receiver()
165 while (!hdlcdrv_hbuf_empty(&s->hdlcrx.hbuf)) { in hdlcdrv_receiver()
166 word = hdlcdrv_hbuf_get(&s->hdlcrx.hbuf); in hdlcdrv_receiver()
169 hdlcdrv_add_bitbuffer_word(&s->bitbuf_hdlc, word); in hdlcdrv_receiver()
171 s->hdlcrx.bitstream >>= 16; in hdlcdrv_receiver()
172 s->hdlcrx.bitstream |= word << 16; in hdlcdrv_receiver()
173 s->hdlcrx.bitbuf >>= 16; in hdlcdrv_receiver()
174 s->hdlcrx.bitbuf |= word << 16; in hdlcdrv_receiver()
175 s->hdlcrx.numbits += 16; in hdlcdrv_receiver()
181 if ((s->hdlcrx.bitstream & mask1) == mask1) in hdlcdrv_receiver()
182 s->hdlcrx.rx_state = 0; /* abort received */ in hdlcdrv_receiver()
183 else if ((s->hdlcrx.bitstream & mask2) == mask3) { in hdlcdrv_receiver()
185 if (s->hdlcrx.rx_state) { in hdlcdrv_receiver()
186 hdlc_rx_add_bytes(s, s->hdlcrx.bitbuf in hdlcdrv_receiver()
188 s->hdlcrx.numbits in hdlcdrv_receiver()
190 hdlc_rx_flag(dev, s); in hdlcdrv_receiver()
192 s->hdlcrx.len = 0; in hdlcdrv_receiver()
193 s->hdlcrx.bp = s->hdlcrx.buffer; in hdlcdrv_receiver()
194 s->hdlcrx.rx_state = 1; in hdlcdrv_receiver()
195 s->hdlcrx.numbits = i; in hdlcdrv_receiver()
196 } else if ((s->hdlcrx.bitstream & mask4) == mask5) { in hdlcdrv_receiver()
198 s->hdlcrx.numbits--; in hdlcdrv_receiver()
199 s->hdlcrx.bitbuf = (s->hdlcrx.bitbuf & (~mask6)) | in hdlcdrv_receiver()
200 ((s->hdlcrx.bitbuf & mask6) << 1); in hdlcdrv_receiver()
203 s->hdlcrx.numbits -= hdlc_rx_add_bytes(s, s->hdlcrx.bitbuf, in hdlcdrv_receiver()
204 s->hdlcrx.numbits); in hdlcdrv_receiver()
206 clear_bit(0, &s->hdlcrx.in_hdlc_rx); in hdlcdrv_receiver()
211 static inline void do_kiss_params(struct hdlcdrv_state *s, in do_kiss_params() argument
225 s->ch_params.tx_delay = data[1]; in do_kiss_params()
226 PKP("TX delay = %ums", 10 * s->ch_params.tx_delay); in do_kiss_params()
229 s->ch_params.ppersist = data[1]; in do_kiss_params()
230 PKP("p persistence = %u", s->ch_params.ppersist); in do_kiss_params()
233 s->ch_params.slottime = data[1]; in do_kiss_params()
234 PKP("slot time = %ums", s->ch_params.slottime); in do_kiss_params()
237 s->ch_params.tx_tail = data[1]; in do_kiss_params()
238 PKP("TX tail = %ums", s->ch_params.tx_tail); in do_kiss_params()
241 s->ch_params.fulldup = !!data[1]; in do_kiss_params()
242 PKP("%s duplex", s->ch_params.fulldup ? "full" : "half"); in do_kiss_params()
252 void hdlcdrv_transmitter(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_transmitter() argument
259 if (!s || s->magic != HDLCDRV_MAGIC) in hdlcdrv_transmitter()
261 if (test_and_set_bit(0, &s->hdlctx.in_hdlc_tx)) in hdlcdrv_transmitter()
264 if (s->hdlctx.numbits >= 16) { in hdlcdrv_transmitter()
265 if (hdlcdrv_hbuf_full(&s->hdlctx.hbuf)) { in hdlcdrv_transmitter()
266 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
269 hdlcdrv_hbuf_put(&s->hdlctx.hbuf, s->hdlctx.bitbuf); in hdlcdrv_transmitter()
270 s->hdlctx.bitbuf >>= 16; in hdlcdrv_transmitter()
271 s->hdlctx.numbits -= 16; in hdlcdrv_transmitter()
273 switch (s->hdlctx.tx_state) { in hdlcdrv_transmitter()
275 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
279 if (s->hdlctx.numflags) { in hdlcdrv_transmitter()
280 s->hdlctx.numflags--; in hdlcdrv_transmitter()
281 s->hdlctx.bitbuf |= in hdlcdrv_transmitter()
282 0x7e7e << s->hdlctx.numbits; in hdlcdrv_transmitter()
283 s->hdlctx.numbits += 16; in hdlcdrv_transmitter()
286 if (s->hdlctx.tx_state == 1) { in hdlcdrv_transmitter()
287 clear_bit(0, &s->hdlctx.in_hdlc_tx); in hdlcdrv_transmitter()
290 if (!(skb = s->skb)) { in hdlcdrv_transmitter()
291 int flgs = tenms_to_2flags(s, s->ch_params.tx_tail); in hdlcdrv_transmitter()
294 s->hdlctx.tx_state = 1; in hdlcdrv_transmitter()
295 s->hdlctx.numflags = flgs; in hdlcdrv_transmitter()
298 s->skb = NULL; in hdlcdrv_transmitter()
302 s->hdlctx.tx_state = 0; in hdlcdrv_transmitter()
303 s->hdlctx.numflags = 1; in hdlcdrv_transmitter()
308 s->hdlctx.buffer, in hdlcdrv_transmitter()
311 s->hdlctx.bp = s->hdlctx.buffer; in hdlcdrv_transmitter()
312 append_crc_ccitt(s->hdlctx.buffer, pkt_len); in hdlcdrv_transmitter()
313 s->hdlctx.len = pkt_len+2; /* the appended CRC */ in hdlcdrv_transmitter()
314 s->hdlctx.tx_state = 2; in hdlcdrv_transmitter()
315 s->hdlctx.bitstream = 0; in hdlcdrv_transmitter()
319 if (!s->hdlctx.len) { in hdlcdrv_transmitter()
320 s->hdlctx.tx_state = 0; in hdlcdrv_transmitter()
321 s->hdlctx.numflags = 1; in hdlcdrv_transmitter()
324 s->hdlctx.len--; in hdlcdrv_transmitter()
325 s->hdlctx.bitbuf |= *s->hdlctx.bp << in hdlcdrv_transmitter()
326 s->hdlctx.numbits; in hdlcdrv_transmitter()
327 s->hdlctx.bitstream >>= 8; in hdlcdrv_transmitter()
328 s->hdlctx.bitstream |= (*s->hdlctx.bp++) << 16; in hdlcdrv_transmitter()
331 mask3 = 0xffffffff >> (31-s->hdlctx.numbits); in hdlcdrv_transmitter()
332 s->hdlctx.numbits += 8; in hdlcdrv_transmitter()
335 if ((s->hdlctx.bitstream & mask1) != mask1) in hdlcdrv_transmitter()
337 s->hdlctx.bitstream &= ~mask2; in hdlcdrv_transmitter()
338 s->hdlctx.bitbuf = in hdlcdrv_transmitter()
339 (s->hdlctx.bitbuf & mask3) | in hdlcdrv_transmitter()
340 ((s->hdlctx.bitbuf & in hdlcdrv_transmitter()
342 s->hdlctx.numbits++; in hdlcdrv_transmitter()
352 static void start_tx(struct net_device *dev, struct hdlcdrv_state *s) in start_tx() argument
354 s->hdlctx.tx_state = 0; in start_tx()
355 s->hdlctx.numflags = tenms_to_2flags(s, s->ch_params.tx_delay); in start_tx()
356 s->hdlctx.bitbuf = s->hdlctx.bitstream = s->hdlctx.numbits = 0; in start_tx()
357 hdlcdrv_transmitter(dev, s); in start_tx()
358 s->hdlctx.ptt = 1; in start_tx()
359 s->ptt_keyed++; in start_tx()
364 void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s) in hdlcdrv_arbitrate() argument
366 if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) in hdlcdrv_arbitrate()
368 if (s->ch_params.fulldup) { in hdlcdrv_arbitrate()
369 start_tx(dev, s); in hdlcdrv_arbitrate()
372 if (s->hdlcrx.dcd) { in hdlcdrv_arbitrate()
373 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_arbitrate()
376 if ((--s->hdlctx.slotcnt) > 0) in hdlcdrv_arbitrate()
378 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_arbitrate()
379 if ((prandom_u32() % 256) > s->ch_params.ppersist) in hdlcdrv_arbitrate()
381 start_tx(dev, s); in hdlcdrv_arbitrate()
434 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_open() local
437 if (!s->ops || !s->ops->open) in hdlcdrv_open()
443 s->opened = 1; in hdlcdrv_open()
444 s->hdlcrx.hbuf.rd = s->hdlcrx.hbuf.wr = 0; in hdlcdrv_open()
445 s->hdlcrx.in_hdlc_rx = 0; in hdlcdrv_open()
446 s->hdlcrx.rx_state = 0; in hdlcdrv_open()
448 s->hdlctx.hbuf.rd = s->hdlctx.hbuf.wr = 0; in hdlcdrv_open()
449 s->hdlctx.in_hdlc_tx = 0; in hdlcdrv_open()
450 s->hdlctx.tx_state = 1; in hdlcdrv_open()
451 s->hdlctx.numflags = 0; in hdlcdrv_open()
452 s->hdlctx.bitstream = s->hdlctx.bitbuf = s->hdlctx.numbits = 0; in hdlcdrv_open()
453 s->hdlctx.ptt = 0; in hdlcdrv_open()
454 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_open()
455 s->hdlctx.calibrate = 0; in hdlcdrv_open()
457 i = s->ops->open(dev); in hdlcdrv_open()
471 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_close() local
476 if (s->ops && s->ops->close) in hdlcdrv_close()
477 i = s->ops->close(dev); in hdlcdrv_close()
478 dev_kfree_skb(s->skb); in hdlcdrv_close()
479 s->skb = NULL; in hdlcdrv_close()
480 s->opened = 0; in hdlcdrv_close()
488 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_ioctl() local
492 if (s->ops && s->ops->ioctl) in hdlcdrv_ioctl()
493 return s->ops->ioctl(dev, ifr, &bi, cmd); in hdlcdrv_ioctl()
501 if (s->ops && s->ops->ioctl) in hdlcdrv_ioctl()
502 return s->ops->ioctl(dev, ifr, &bi, cmd); in hdlcdrv_ioctl()
506 bi.data.cp.tx_delay = s->ch_params.tx_delay; in hdlcdrv_ioctl()
507 bi.data.cp.tx_tail = s->ch_params.tx_tail; in hdlcdrv_ioctl()
508 bi.data.cp.slottime = s->ch_params.slottime; in hdlcdrv_ioctl()
509 bi.data.cp.ppersist = s->ch_params.ppersist; in hdlcdrv_ioctl()
510 bi.data.cp.fulldup = s->ch_params.fulldup; in hdlcdrv_ioctl()
516 s->ch_params.tx_delay = bi.data.cp.tx_delay; in hdlcdrv_ioctl()
517 s->ch_params.tx_tail = bi.data.cp.tx_tail; in hdlcdrv_ioctl()
518 s->ch_params.slottime = bi.data.cp.slottime; in hdlcdrv_ioctl()
519 s->ch_params.ppersist = bi.data.cp.ppersist; in hdlcdrv_ioctl()
520 s->ch_params.fulldup = bi.data.cp.fulldup; in hdlcdrv_ioctl()
521 s->hdlctx.slotcnt = 1; in hdlcdrv_ioctl()
528 bi.data.mp.dma2 = s->ptt_out.dma2; in hdlcdrv_ioctl()
529 bi.data.mp.seriobase = s->ptt_out.seriobase; in hdlcdrv_ioctl()
530 bi.data.mp.pariobase = s->ptt_out.pariobase; in hdlcdrv_ioctl()
531 bi.data.mp.midiiobase = s->ptt_out.midiiobase; in hdlcdrv_ioctl()
540 s->ptt_out.dma2 = bi.data.mp.dma2; in hdlcdrv_ioctl()
541 s->ptt_out.seriobase = bi.data.mp.seriobase; in hdlcdrv_ioctl()
542 s->ptt_out.pariobase = bi.data.mp.pariobase; in hdlcdrv_ioctl()
543 s->ptt_out.midiiobase = bi.data.mp.midiiobase; in hdlcdrv_ioctl()
547 bi.data.cs.ptt = hdlcdrv_ptt(s); in hdlcdrv_ioctl()
548 bi.data.cs.dcd = s->hdlcrx.dcd; in hdlcdrv_ioctl()
549 bi.data.cs.ptt_keyed = s->ptt_keyed; in hdlcdrv_ioctl()
557 bi.data.ocs.ptt = hdlcdrv_ptt(s); in hdlcdrv_ioctl()
558 bi.data.ocs.dcd = s->hdlcrx.dcd; in hdlcdrv_ioctl()
559 bi.data.ocs.ptt_keyed = s->ptt_keyed; in hdlcdrv_ioctl()
565 if (s->par.bitrate <= 0) in hdlcdrv_ioctl()
567 if (bi.data.calibrate > INT_MAX / s->par.bitrate) in hdlcdrv_ioctl()
569 s->hdlctx.calibrate = bi.data.calibrate * s->par.bitrate / 16; in hdlcdrv_ioctl()
576 if (s->bitbuf_channel.rd == s->bitbuf_channel.wr) in hdlcdrv_ioctl()
579 s->bitbuf_channel.buffer[s->bitbuf_channel.rd]; in hdlcdrv_ioctl()
580 s->bitbuf_channel.rd = (s->bitbuf_channel.rd+1) % in hdlcdrv_ioctl()
581 sizeof(s->bitbuf_channel.buffer); in hdlcdrv_ioctl()
589 if (s->bitbuf_hdlc.rd == s->bitbuf_hdlc.wr) in hdlcdrv_ioctl()
592 s->bitbuf_hdlc.buffer[s->bitbuf_hdlc.rd]; in hdlcdrv_ioctl()
593 s->bitbuf_hdlc.rd = (s->bitbuf_hdlc.rd+1) % in hdlcdrv_ioctl()
594 sizeof(s->bitbuf_hdlc.buffer); in hdlcdrv_ioctl()
599 if (s->ops && s->ops->drvname) { in hdlcdrv_ioctl()
600 strncpy(bi.data.drivername, s->ops->drvname, in hdlcdrv_ioctl()
632 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_setup() local
637 s->ch_params = dflt_ch_params; in hdlcdrv_setup()
638 s->ptt_keyed = 0; in hdlcdrv_setup()
640 spin_lock_init(&s->hdlcrx.hbuf.lock); in hdlcdrv_setup()
641 s->hdlcrx.hbuf.rd = s->hdlcrx.hbuf.wr = 0; in hdlcdrv_setup()
642 s->hdlcrx.in_hdlc_rx = 0; in hdlcdrv_setup()
643 s->hdlcrx.rx_state = 0; in hdlcdrv_setup()
645 spin_lock_init(&s->hdlctx.hbuf.lock); in hdlcdrv_setup()
646 s->hdlctx.hbuf.rd = s->hdlctx.hbuf.wr = 0; in hdlcdrv_setup()
647 s->hdlctx.in_hdlc_tx = 0; in hdlcdrv_setup()
648 s->hdlctx.tx_state = 1; in hdlcdrv_setup()
649 s->hdlctx.numflags = 0; in hdlcdrv_setup()
650 s->hdlctx.bitstream = s->hdlctx.bitbuf = s->hdlctx.numbits = 0; in hdlcdrv_setup()
651 s->hdlctx.ptt = 0; in hdlcdrv_setup()
652 s->hdlctx.slotcnt = s->ch_params.slottime; in hdlcdrv_setup()
653 s->hdlctx.calibrate = 0; in hdlcdrv_setup()
656 s->bitbuf_channel.rd = s->bitbuf_channel.wr = 0; in hdlcdrv_setup()
657 s->bitbuf_channel.shreg = 0x80; in hdlcdrv_setup()
659 s->bitbuf_hdlc.rd = s->bitbuf_hdlc.wr = 0; in hdlcdrv_setup()
660 s->bitbuf_hdlc.shreg = 0x80; in hdlcdrv_setup()
666 s->skb = NULL; in hdlcdrv_setup()
687 struct hdlcdrv_state *s; in hdlcdrv_register() local
702 s = netdev_priv(dev); in hdlcdrv_register()
703 s->magic = HDLCDRV_MAGIC; in hdlcdrv_register()
704 s->ops = ops; in hdlcdrv_register()
712 "device %s\n", dev->name); in hdlcdrv_register()
723 struct hdlcdrv_state *s = netdev_priv(dev); in hdlcdrv_unregister() local
725 BUG_ON(s->magic != HDLCDRV_MAGIC); in hdlcdrv_unregister()
727 if (s->opened && s->ops->close) in hdlcdrv_unregister()
728 s->ops->close(dev); in hdlcdrv_unregister()