Lines Matching refs:bcsp

136 	struct bcsp_struct *bcsp = hu->priv;  in bcsp_enqueue()  local
147 skb_queue_tail(&bcsp->rel, skb); in bcsp_enqueue()
151 skb_queue_tail(&bcsp->unrel, skb); in bcsp_enqueue()
163 static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data, in bcsp_prepare_pkt() argument
226 hdr[0] = bcsp->rxseq_txack << 3; in bcsp_prepare_pkt()
227 bcsp->txack_req = 0; in bcsp_prepare_pkt()
228 BT_DBG("We request packet no %u to card", bcsp->rxseq_txack); in bcsp_prepare_pkt()
231 hdr[0] |= 0x80 + bcsp->msgq_txseq; in bcsp_prepare_pkt()
232 BT_DBG("Sending packet with seqno %u", bcsp->msgq_txseq); in bcsp_prepare_pkt()
233 bcsp->msgq_txseq = (bcsp->msgq_txseq + 1) & 0x07; in bcsp_prepare_pkt()
236 if (bcsp->use_crc) in bcsp_prepare_pkt()
247 if (bcsp->use_crc) in bcsp_prepare_pkt()
255 if (bcsp->use_crc) in bcsp_prepare_pkt()
260 if (bcsp->use_crc) { in bcsp_prepare_pkt()
273 struct bcsp_struct *bcsp = hu->priv; in bcsp_dequeue() local
281 skb = skb_dequeue(&bcsp->unrel); in bcsp_dequeue()
285 nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, in bcsp_dequeue()
291 skb_queue_head(&bcsp->unrel, skb); in bcsp_dequeue()
301 spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING); in bcsp_dequeue()
303 if (bcsp->unack.qlen < BCSP_TXWINSIZE) { in bcsp_dequeue()
304 skb = skb_dequeue(&bcsp->rel); in bcsp_dequeue()
308 nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, in bcsp_dequeue()
311 __skb_queue_tail(&bcsp->unack, skb); in bcsp_dequeue()
312 mod_timer(&bcsp->tbcsp, jiffies + HZ / 4); in bcsp_dequeue()
313 spin_unlock_irqrestore(&bcsp->unack.lock, flags); in bcsp_dequeue()
316 skb_queue_head(&bcsp->rel, skb); in bcsp_dequeue()
322 spin_unlock_irqrestore(&bcsp->unack.lock, flags); in bcsp_dequeue()
329 if (bcsp->txack_req) { in bcsp_dequeue()
333 struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, NULL, 0, BCSP_ACK_PKT); in bcsp_dequeue()
348 static void bcsp_pkt_cull(struct bcsp_struct *bcsp) in bcsp_pkt_cull() argument
355 spin_lock_irqsave(&bcsp->unack.lock, flags); in bcsp_pkt_cull()
357 pkts_to_be_removed = skb_queue_len(&bcsp->unack); in bcsp_pkt_cull()
358 seqno = bcsp->msgq_txseq; in bcsp_pkt_cull()
361 if (bcsp->rxack == seqno) in bcsp_pkt_cull()
367 if (bcsp->rxack != seqno) in bcsp_pkt_cull()
371 pkts_to_be_removed, skb_queue_len(&bcsp->unack), in bcsp_pkt_cull()
375 skb_queue_walk_safe(&bcsp->unack, skb, tmp) { in bcsp_pkt_cull()
380 __skb_unlink(skb, &bcsp->unack); in bcsp_pkt_cull()
384 if (skb_queue_empty(&bcsp->unack)) in bcsp_pkt_cull()
385 del_timer(&bcsp->tbcsp); in bcsp_pkt_cull()
387 spin_unlock_irqrestore(&bcsp->unack.lock, flags); in bcsp_pkt_cull()
399 struct bcsp_struct *bcsp = hu->priv; in bcsp_handle_le_pkt() local
405 if (bcsp->rx_skb->data[1] >> 4 == 4 && bcsp->rx_skb->data[2] == 0 && in bcsp_handle_le_pkt()
406 !memcmp(&bcsp->rx_skb->data[4], conf_pkt, 4)) { in bcsp_handle_le_pkt()
415 skb_queue_head(&bcsp->unrel, nskb); in bcsp_handle_le_pkt()
419 else if (bcsp->rx_skb->data[1] >> 4 == 4 && bcsp->rx_skb->data[2] == 0 && in bcsp_handle_le_pkt()
420 !memcmp(&bcsp->rx_skb->data[4], sync_pkt, 4)) { in bcsp_handle_le_pkt()
425 static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char byte) in bcsp_unslip_one_byte() argument
429 switch (bcsp->rx_esc_state) { in bcsp_unslip_one_byte()
433 bcsp->rx_esc_state = BCSP_ESCSTATE_ESC; in bcsp_unslip_one_byte()
436 skb_put_data(bcsp->rx_skb, &byte, 1); in bcsp_unslip_one_byte()
437 if ((bcsp->rx_skb->data[0] & 0x40) != 0 && in bcsp_unslip_one_byte()
438 bcsp->rx_state != BCSP_W4_CRC) in bcsp_unslip_one_byte()
439 bcsp_crc_update(&bcsp->message_crc, byte); in bcsp_unslip_one_byte()
440 bcsp->rx_count--; in bcsp_unslip_one_byte()
447 skb_put_data(bcsp->rx_skb, &c0, 1); in bcsp_unslip_one_byte()
448 if ((bcsp->rx_skb->data[0] & 0x40) != 0 && in bcsp_unslip_one_byte()
449 bcsp->rx_state != BCSP_W4_CRC) in bcsp_unslip_one_byte()
450 bcsp_crc_update(&bcsp->message_crc, 0xc0); in bcsp_unslip_one_byte()
451 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; in bcsp_unslip_one_byte()
452 bcsp->rx_count--; in bcsp_unslip_one_byte()
456 skb_put_data(bcsp->rx_skb, &db, 1); in bcsp_unslip_one_byte()
457 if ((bcsp->rx_skb->data[0] & 0x40) != 0 && in bcsp_unslip_one_byte()
458 bcsp->rx_state != BCSP_W4_CRC) in bcsp_unslip_one_byte()
459 bcsp_crc_update(&bcsp->message_crc, 0xdb); in bcsp_unslip_one_byte()
460 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; in bcsp_unslip_one_byte()
461 bcsp->rx_count--; in bcsp_unslip_one_byte()
466 kfree_skb(bcsp->rx_skb); in bcsp_unslip_one_byte()
467 bcsp->rx_skb = NULL; in bcsp_unslip_one_byte()
468 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_unslip_one_byte()
469 bcsp->rx_count = 0; in bcsp_unslip_one_byte()
476 struct bcsp_struct *bcsp = hu->priv; in bcsp_complete_rx_pkt() local
479 if (bcsp->rx_skb->data[0] & 0x80) { /* reliable pkt */ in bcsp_complete_rx_pkt()
480 BT_DBG("Received seqno %u from card", bcsp->rxseq_txack); in bcsp_complete_rx_pkt()
483 if ((bcsp->rx_skb->data[0] & 0x07) == bcsp->rxseq_txack) { in bcsp_complete_rx_pkt()
484 bcsp->rxseq_txack++; in bcsp_complete_rx_pkt()
485 bcsp->rxseq_txack %= 0x8; in bcsp_complete_rx_pkt()
491 bcsp->rx_skb->data[0] & 0x07, bcsp->rxseq_txack); in bcsp_complete_rx_pkt()
498 bcsp->txack_req = 1; in bcsp_complete_rx_pkt()
504 bcsp->rxack = (bcsp->rx_skb->data[0] >> 3) & 0x07; in bcsp_complete_rx_pkt()
505 BT_DBG("Request for pkt %u from card", bcsp->rxack); in bcsp_complete_rx_pkt()
510 bcsp_pkt_cull(bcsp); in bcsp_complete_rx_pkt()
513 if ((bcsp->rx_skb->data[1] & 0x0f) == 6 && in bcsp_complete_rx_pkt()
514 (bcsp->rx_skb->data[0] & 0x80)) { in bcsp_complete_rx_pkt()
515 hci_skb_pkt_type(bcsp->rx_skb) = HCI_ACLDATA_PKT; in bcsp_complete_rx_pkt()
517 } else if ((bcsp->rx_skb->data[1] & 0x0f) == 5 && in bcsp_complete_rx_pkt()
518 (bcsp->rx_skb->data[0] & 0x80)) { in bcsp_complete_rx_pkt()
519 hci_skb_pkt_type(bcsp->rx_skb) = HCI_EVENT_PKT; in bcsp_complete_rx_pkt()
521 } else if ((bcsp->rx_skb->data[1] & 0x0f) == 7) { in bcsp_complete_rx_pkt()
522 hci_skb_pkt_type(bcsp->rx_skb) = HCI_SCODATA_PKT; in bcsp_complete_rx_pkt()
524 } else if ((bcsp->rx_skb->data[1] & 0x0f) == 1 && in bcsp_complete_rx_pkt()
525 !(bcsp->rx_skb->data[0] & 0x80)) { in bcsp_complete_rx_pkt()
535 u8 desc = (bcsp->rx_skb->data[1] & 0x0f); in bcsp_complete_rx_pkt()
540 skb_pull(bcsp->rx_skb, 4); in bcsp_complete_rx_pkt()
541 memcpy(skb_push(bcsp->rx_skb, 1), &desc, 1); in bcsp_complete_rx_pkt()
544 hdr.plen = bcsp->rx_skb->len; in bcsp_complete_rx_pkt()
545 memcpy(skb_push(bcsp->rx_skb, HCI_EVENT_HDR_SIZE), &hdr, HCI_EVENT_HDR_SIZE); in bcsp_complete_rx_pkt()
546 hci_skb_pkt_type(bcsp->rx_skb) = HCI_EVENT_PKT; in bcsp_complete_rx_pkt()
548 hci_recv_frame(hu->hdev, bcsp->rx_skb); in bcsp_complete_rx_pkt()
551 bcsp->rx_skb->data[1] & 0x0f, in bcsp_complete_rx_pkt()
552 bcsp->rx_skb->data[0] & 0x80 ? in bcsp_complete_rx_pkt()
554 kfree_skb(bcsp->rx_skb); in bcsp_complete_rx_pkt()
557 kfree_skb(bcsp->rx_skb); in bcsp_complete_rx_pkt()
560 skb_pull(bcsp->rx_skb, 4); in bcsp_complete_rx_pkt()
562 hci_recv_frame(hu->hdev, bcsp->rx_skb); in bcsp_complete_rx_pkt()
567 kfree_skb(bcsp->rx_skb); in bcsp_complete_rx_pkt()
570 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_complete_rx_pkt()
571 bcsp->rx_skb = NULL; in bcsp_complete_rx_pkt()
574 static u16 bscp_get_crc(struct bcsp_struct *bcsp) in bscp_get_crc() argument
576 return get_unaligned_be16(&bcsp->rx_skb->data[bcsp->rx_skb->len - 2]); in bscp_get_crc()
582 struct bcsp_struct *bcsp = hu->priv; in bcsp_recv() local
586 hu, count, bcsp->rx_state, bcsp->rx_count); in bcsp_recv()
590 if (bcsp->rx_count) { in bcsp_recv()
593 kfree_skb(bcsp->rx_skb); in bcsp_recv()
594 bcsp->rx_skb = NULL; in bcsp_recv()
595 bcsp->rx_state = BCSP_W4_PKT_START; in bcsp_recv()
596 bcsp->rx_count = 0; in bcsp_recv()
598 bcsp_unslip_one_byte(bcsp, *ptr); in bcsp_recv()
604 switch (bcsp->rx_state) { in bcsp_recv()
606 if ((0xff & (u8)~(bcsp->rx_skb->data[0] + bcsp->rx_skb->data[1] + in bcsp_recv()
607 bcsp->rx_skb->data[2])) != bcsp->rx_skb->data[3]) { in bcsp_recv()
609 kfree_skb(bcsp->rx_skb); in bcsp_recv()
610 bcsp->rx_skb = NULL; in bcsp_recv()
611 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_recv()
612 bcsp->rx_count = 0; in bcsp_recv()
615 bcsp->rx_state = BCSP_W4_DATA; in bcsp_recv()
616 bcsp->rx_count = (bcsp->rx_skb->data[1] >> 4) + in bcsp_recv()
617 (bcsp->rx_skb->data[2] << 4); /* May be 0 */ in bcsp_recv()
621 if (bcsp->rx_skb->data[0] & 0x40) { /* pkt with crc */ in bcsp_recv()
622 bcsp->rx_state = BCSP_W4_CRC; in bcsp_recv()
623 bcsp->rx_count = 2; in bcsp_recv()
629 if (bitrev16(bcsp->message_crc) != bscp_get_crc(bcsp)) { in bcsp_recv()
631 bitrev16(bcsp->message_crc), in bcsp_recv()
632 bscp_get_crc(bcsp)); in bcsp_recv()
634 kfree_skb(bcsp->rx_skb); in bcsp_recv()
635 bcsp->rx_skb = NULL; in bcsp_recv()
636 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_recv()
637 bcsp->rx_count = 0; in bcsp_recv()
640 skb_trim(bcsp->rx_skb, bcsp->rx_skb->len - 2); in bcsp_recv()
647 bcsp->rx_state = BCSP_W4_PKT_START; in bcsp_recv()
663 bcsp->rx_state = BCSP_W4_BCSP_HDR; in bcsp_recv()
664 bcsp->rx_count = 4; in bcsp_recv()
665 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; in bcsp_recv()
666 BCSP_CRC_INIT(bcsp->message_crc); in bcsp_recv()
673 bcsp->rx_skb = bt_skb_alloc(0x1005, GFP_ATOMIC); in bcsp_recv()
674 if (!bcsp->rx_skb) { in bcsp_recv()
676 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_recv()
677 bcsp->rx_count = 0; in bcsp_recv()
691 struct bcsp_struct *bcsp = from_timer(bcsp, t, tbcsp); in bcsp_timed_event() local
692 struct hci_uart *hu = bcsp->hu; in bcsp_timed_event()
696 BT_DBG("hu %p retransmitting %u pkts", hu, bcsp->unack.qlen); in bcsp_timed_event()
698 spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING); in bcsp_timed_event()
700 while ((skb = __skb_dequeue_tail(&bcsp->unack)) != NULL) { in bcsp_timed_event()
701 bcsp->msgq_txseq = (bcsp->msgq_txseq - 1) & 0x07; in bcsp_timed_event()
702 skb_queue_head(&bcsp->rel, skb); in bcsp_timed_event()
705 spin_unlock_irqrestore(&bcsp->unack.lock, flags); in bcsp_timed_event()
712 struct bcsp_struct *bcsp; in bcsp_open() local
716 bcsp = kzalloc(sizeof(*bcsp), GFP_KERNEL); in bcsp_open()
717 if (!bcsp) in bcsp_open()
720 hu->priv = bcsp; in bcsp_open()
721 bcsp->hu = hu; in bcsp_open()
722 skb_queue_head_init(&bcsp->unack); in bcsp_open()
723 skb_queue_head_init(&bcsp->rel); in bcsp_open()
724 skb_queue_head_init(&bcsp->unrel); in bcsp_open()
726 timer_setup(&bcsp->tbcsp, bcsp_timed_event, 0); in bcsp_open()
728 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; in bcsp_open()
731 bcsp->use_crc = 1; in bcsp_open()
738 struct bcsp_struct *bcsp = hu->priv; in bcsp_close() local
740 timer_shutdown_sync(&bcsp->tbcsp); in bcsp_close()
746 skb_queue_purge(&bcsp->unack); in bcsp_close()
747 skb_queue_purge(&bcsp->rel); in bcsp_close()
748 skb_queue_purge(&bcsp->unrel); in bcsp_close()
750 if (bcsp->rx_skb) { in bcsp_close()
751 kfree_skb(bcsp->rx_skb); in bcsp_close()
752 bcsp->rx_skb = NULL; in bcsp_close()
755 kfree(bcsp); in bcsp_close()
759 static const struct hci_uart_proto bcsp = { variable
772 return hci_uart_register_proto(&bcsp); in bcsp_init()
777 return hci_uart_unregister_proto(&bcsp); in bcsp_deinit()