Lines Matching +full:ssi +full:- +full:all
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Implementation of the SSI McSAAB improved protocol.
7 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
44 #define SSIP_MAX_CMDS 5 /* Number of pre-allocated commands buffers */
45 #define SSIP_BYTES_TO_FRAMES(x) ((((x) - 1) >> 2) + 1)
48 * SSI protocol command definitions
104 * struct ssi_protocol - SSI protocol (McSAAB) data
114 * @keep_alive: Workaround for SSI HW bug
135 struct timer_list keep_alive; /* wake-up workaround */
148 /* List of ssi protocol instances */
157 data = sg_virt(msg->sgt.sgl); in ssip_set_cmd()
165 data = sg_virt(msg->sgt.sgl); in ssip_get_cmd()
176 BUG_ON(msg->sgt.nents != (unsigned int)(skb_shinfo(skb)->nr_frags + 1)); in ssip_skb_to_msg()
178 sg = msg->sgt.sgl; in ssip_skb_to_msg()
179 sg_set_buf(sg, skb->data, skb_headlen(skb)); in ssip_skb_to_msg()
180 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in ssip_skb_to_msg()
183 frag = &skb_shinfo(skb)->frags[i]; in ssip_skb_to_msg()
193 skb = msg->context; in ssip_free_data()
194 pr_debug("free data: msg %p context %p skb %p\n", msg, msg->context, in ssip_free_data()
196 msg->destructor = NULL; in ssip_free_data()
201 static struct hsi_msg *ssip_alloc_data(struct ssi_protocol *ssi, in ssip_alloc_data() argument
206 msg = hsi_alloc_msg(skb_shinfo(skb)->nr_frags + 1, flags); in ssip_alloc_data()
210 msg->destructor = ssip_free_data; in ssip_alloc_data()
211 msg->channel = ssi->channel_id_data; in ssip_alloc_data()
212 msg->context = skb; in ssip_alloc_data()
219 struct ssi_protocol *ssi = hsi_client_drvdata(msg->cl); in ssip_release_cmd() local
221 dev_dbg(&msg->cl->device, "Release cmd 0x%08x\n", ssip_get_cmd(msg)); in ssip_release_cmd()
222 spin_lock_bh(&ssi->lock); in ssip_release_cmd()
223 list_add_tail(&msg->link, &ssi->cmdqueue); in ssip_release_cmd()
224 spin_unlock_bh(&ssi->lock); in ssip_release_cmd()
227 static struct hsi_msg *ssip_claim_cmd(struct ssi_protocol *ssi) in ssip_claim_cmd() argument
231 BUG_ON(list_empty(&ssi->cmdqueue)); in ssip_claim_cmd()
233 spin_lock_bh(&ssi->lock); in ssip_claim_cmd()
234 msg = list_first_entry(&ssi->cmdqueue, struct hsi_msg, link); in ssip_claim_cmd()
235 list_del(&msg->link); in ssip_claim_cmd()
236 spin_unlock_bh(&ssi->lock); in ssip_claim_cmd()
237 msg->destructor = ssip_release_cmd; in ssip_claim_cmd()
242 static void ssip_free_cmds(struct ssi_protocol *ssi) in ssip_free_cmds() argument
246 list_for_each_entry_safe(msg, tmp, &ssi->cmdqueue, link) { in ssip_free_cmds()
247 list_del(&msg->link); in ssip_free_cmds()
248 msg->destructor = NULL; in ssip_free_cmds()
249 kfree(sg_virt(msg->sgt.sgl)); in ssip_free_cmds()
254 static int ssip_alloc_cmds(struct ssi_protocol *ssi) in ssip_alloc_cmds() argument
269 sg_init_one(msg->sgt.sgl, buf, sizeof(*buf)); in ssip_alloc_cmds()
270 msg->channel = ssi->channel_id_cmd; in ssip_alloc_cmds()
271 list_add_tail(&msg->link, &ssi->cmdqueue); in ssip_alloc_cmds()
276 ssip_free_cmds(ssi); in ssip_alloc_cmds()
278 return -ENOMEM; in ssip_alloc_cmds()
281 static void ssip_set_rxstate(struct ssi_protocol *ssi, unsigned int state) in ssip_set_rxstate() argument
283 ssi->recv_state = state; in ssip_set_rxstate()
286 del_timer(&ssi->rx_wd); in ssip_set_rxstate()
287 if (ssi->send_state == SEND_IDLE) in ssip_set_rxstate()
288 del_timer(&ssi->keep_alive); in ssip_set_rxstate()
292 if (atomic_read(&ssi->tx_usecnt)) in ssip_set_rxstate()
296 mod_timer(&ssi->keep_alive, jiffies + in ssip_set_rxstate()
298 mod_timer(&ssi->rx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT)); in ssip_set_rxstate()
305 static void ssip_set_txstate(struct ssi_protocol *ssi, unsigned int state) in ssip_set_txstate() argument
307 ssi->send_state = state; in ssip_set_txstate()
311 del_timer(&ssi->tx_wd); in ssip_set_txstate()
312 if (ssi->recv_state == RECV_IDLE) in ssip_set_txstate()
313 del_timer(&ssi->keep_alive); in ssip_set_txstate()
318 mod_timer(&ssi->keep_alive, in ssip_set_txstate()
320 mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT)); in ssip_set_txstate()
329 struct hsi_client *master = ERR_PTR(-ENODEV); in ssip_slave_get_master()
330 struct ssi_protocol *ssi; in ssip_slave_get_master() local
332 list_for_each_entry(ssi, &ssip_list, link) in ssip_slave_get_master()
333 if (slave->device.parent == ssi->cl->device.parent) { in ssip_slave_get_master()
334 master = ssi->cl; in ssip_slave_get_master()
344 struct ssi_protocol *ssi = hsi_client_drvdata(master); in ssip_slave_start_tx() local
346 dev_dbg(&master->device, "start TX %d\n", atomic_read(&ssi->tx_usecnt)); in ssip_slave_start_tx()
347 spin_lock_bh(&ssi->lock); in ssip_slave_start_tx()
348 if (ssi->send_state == SEND_IDLE) { in ssip_slave_start_tx()
349 ssip_set_txstate(ssi, WAIT4READY); in ssip_slave_start_tx()
352 spin_unlock_bh(&ssi->lock); in ssip_slave_start_tx()
353 atomic_inc(&ssi->tx_usecnt); in ssip_slave_start_tx()
361 struct ssi_protocol *ssi = hsi_client_drvdata(master); in ssip_slave_stop_tx() local
363 WARN_ON_ONCE(atomic_read(&ssi->tx_usecnt) == 0); in ssip_slave_stop_tx()
365 if (atomic_dec_and_test(&ssi->tx_usecnt)) { in ssip_slave_stop_tx()
366 spin_lock_bh(&ssi->lock); in ssip_slave_stop_tx()
367 if ((ssi->send_state == SEND_READY) || in ssip_slave_stop_tx()
368 (ssi->send_state == WAIT4READY)) { in ssip_slave_stop_tx()
369 ssip_set_txstate(ssi, SEND_IDLE); in ssip_slave_stop_tx()
372 spin_unlock_bh(&ssi->lock); in ssip_slave_stop_tx()
374 dev_dbg(&master->device, "stop TX %d\n", atomic_read(&ssi->tx_usecnt)); in ssip_slave_stop_tx()
382 struct ssi_protocol *ssi = hsi_client_drvdata(master); in ssip_slave_running() local
383 return netif_running(ssi->netdev); in ssip_slave_running()
389 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_reset() local
393 if (netif_running(ssi->netdev)) in ssip_reset()
394 netif_carrier_off(ssi->netdev); in ssip_reset()
396 spin_lock_bh(&ssi->lock); in ssip_reset()
397 if (ssi->send_state != SEND_IDLE) in ssip_reset()
399 spin_unlock_bh(&ssi->lock); in ssip_reset()
400 if (test_and_clear_bit(SSIP_WAKETEST_FLAG, &ssi->flags)) in ssip_reset()
402 spin_lock_bh(&ssi->lock); in ssip_reset()
403 del_timer(&ssi->rx_wd); in ssip_reset()
404 del_timer(&ssi->tx_wd); in ssip_reset()
405 del_timer(&ssi->keep_alive); in ssip_reset()
406 ssi->main_state = 0; in ssip_reset()
407 ssi->send_state = 0; in ssip_reset()
408 ssi->recv_state = 0; in ssip_reset()
409 ssi->flags = 0; in ssip_reset()
410 ssi->rxid = 0; in ssip_reset()
411 ssi->txid = 0; in ssip_reset()
412 list_for_each_safe(head, tmp, &ssi->txqueue) { in ssip_reset()
414 dev_dbg(&cl->device, "Pending TX data\n"); in ssip_reset()
418 ssi->txqueue_len = 0; in ssip_reset()
419 spin_unlock_bh(&ssi->lock); in ssip_reset()
424 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_dump_state() local
427 spin_lock_bh(&ssi->lock); in ssip_dump_state()
428 dev_err(&cl->device, "Main state: %d\n", ssi->main_state); in ssip_dump_state()
429 dev_err(&cl->device, "Recv state: %d\n", ssi->recv_state); in ssip_dump_state()
430 dev_err(&cl->device, "Send state: %d\n", ssi->send_state); in ssip_dump_state()
431 dev_err(&cl->device, "CMT %s\n", (ssi->main_state == ACTIVE) ? in ssip_dump_state()
433 dev_err(&cl->device, "Wake test %d\n", in ssip_dump_state()
434 test_bit(SSIP_WAKETEST_FLAG, &ssi->flags)); in ssip_dump_state()
435 dev_err(&cl->device, "Data RX id: %d\n", ssi->rxid); in ssip_dump_state()
436 dev_err(&cl->device, "Data TX id: %d\n", ssi->txid); in ssip_dump_state()
438 list_for_each_entry(msg, &ssi->txqueue, link) in ssip_dump_state()
439 dev_err(&cl->device, "pending TX data (%p)\n", msg); in ssip_dump_state()
440 spin_unlock_bh(&ssi->lock); in ssip_dump_state()
445 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_error() local
450 msg = ssip_claim_cmd(ssi); in ssip_error()
451 msg->complete = ssip_rxcmd_complete; in ssip_error()
457 struct ssi_protocol *ssi = from_timer(ssi, t, keep_alive); in ssip_keep_alive() local
458 struct hsi_client *cl = ssi->cl; in ssip_keep_alive()
460 dev_dbg(&cl->device, "Keep alive kick in: m(%d) r(%d) s(%d)\n", in ssip_keep_alive()
461 ssi->main_state, ssi->recv_state, ssi->send_state); in ssip_keep_alive()
463 spin_lock(&ssi->lock); in ssip_keep_alive()
464 if (ssi->recv_state == RECV_IDLE) in ssip_keep_alive()
465 switch (ssi->send_state) { in ssip_keep_alive()
467 if (atomic_read(&ssi->tx_usecnt) == 0) in ssip_keep_alive()
471 * Workaround for cmt-speech in that case in ssip_keep_alive()
475 spin_unlock(&ssi->lock); in ssip_keep_alive()
478 mod_timer(&ssi->keep_alive, jiffies + msecs_to_jiffies(SSIP_KATOUT)); in ssip_keep_alive()
479 spin_unlock(&ssi->lock); in ssip_keep_alive()
484 struct ssi_protocol *ssi = from_timer(ssi, t, rx_wd); in ssip_rx_wd() local
485 struct hsi_client *cl = ssi->cl; in ssip_rx_wd()
487 dev_err(&cl->device, "Watchdog triggered\n"); in ssip_rx_wd()
493 struct ssi_protocol *ssi = from_timer(ssi, t, tx_wd); in ssip_tx_wd() local
494 struct hsi_client *cl = ssi->cl; in ssip_tx_wd()
496 dev_err(&cl->device, "Watchdog triggered\n"); in ssip_tx_wd()
502 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_send_bootinfo_req_cmd() local
505 dev_dbg(&cl->device, "Issuing BOOT INFO REQ command\n"); in ssip_send_bootinfo_req_cmd()
506 msg = ssip_claim_cmd(ssi); in ssip_send_bootinfo_req_cmd()
508 msg->complete = ssip_release_cmd; in ssip_send_bootinfo_req_cmd()
510 dev_dbg(&cl->device, "Issuing RX command\n"); in ssip_send_bootinfo_req_cmd()
511 msg = ssip_claim_cmd(ssi); in ssip_send_bootinfo_req_cmd()
512 msg->complete = ssip_rxcmd_complete; in ssip_send_bootinfo_req_cmd()
518 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_start_rx() local
521 dev_dbg(&cl->device, "RX start M(%d) R(%d)\n", ssi->main_state, in ssip_start_rx()
522 ssi->recv_state); in ssip_start_rx()
523 spin_lock_bh(&ssi->lock); in ssip_start_rx()
528 if ((ssi->main_state != ACTIVE) || (ssi->recv_state == RECV_READY)) { in ssip_start_rx()
529 spin_unlock_bh(&ssi->lock); in ssip_start_rx()
532 ssip_set_rxstate(ssi, RECV_READY); in ssip_start_rx()
533 spin_unlock_bh(&ssi->lock); in ssip_start_rx()
535 msg = ssip_claim_cmd(ssi); in ssip_start_rx()
537 msg->complete = ssip_release_cmd; in ssip_start_rx()
538 dev_dbg(&cl->device, "Send READY\n"); in ssip_start_rx()
544 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_stop_rx() local
546 dev_dbg(&cl->device, "RX stop M(%d)\n", ssi->main_state); in ssip_stop_rx()
547 spin_lock_bh(&ssi->lock); in ssip_stop_rx()
548 if (likely(ssi->main_state == ACTIVE)) in ssip_stop_rx()
549 ssip_set_rxstate(ssi, RECV_IDLE); in ssip_stop_rx()
550 spin_unlock_bh(&ssi->lock); in ssip_stop_rx()
555 ssip_free_data(msg->context); in ssip_free_strans()
561 struct hsi_client *cl = msg->cl; in ssip_strans_complete()
562 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_strans_complete() local
565 data = msg->context; in ssip_strans_complete()
567 spin_lock_bh(&ssi->lock); in ssip_strans_complete()
568 ssip_set_txstate(ssi, SENDING); in ssip_strans_complete()
569 spin_unlock_bh(&ssi->lock); in ssip_strans_complete()
575 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_xmit() local
579 spin_lock_bh(&ssi->lock); in ssip_xmit()
580 if (list_empty(&ssi->txqueue)) { in ssip_xmit()
581 spin_unlock_bh(&ssi->lock); in ssip_xmit()
584 dmsg = list_first_entry(&ssi->txqueue, struct hsi_msg, link); in ssip_xmit()
585 list_del(&dmsg->link); in ssip_xmit()
586 ssi->txqueue_len--; in ssip_xmit()
587 spin_unlock_bh(&ssi->lock); in ssip_xmit()
589 msg = ssip_claim_cmd(ssi); in ssip_xmit()
590 skb = dmsg->context; in ssip_xmit()
591 msg->context = dmsg; in ssip_xmit()
592 msg->complete = ssip_strans_complete; in ssip_xmit()
593 msg->destructor = ssip_free_strans; in ssip_xmit()
595 spin_lock_bh(&ssi->lock); in ssip_xmit()
596 ssip_set_cmd(msg, SSIP_START_TRANS_CMD(SSIP_BYTES_TO_FRAMES(skb->len), in ssip_xmit()
597 ssi->txid)); in ssip_xmit()
598 ssi->txid++; in ssip_xmit()
599 ssip_set_txstate(ssi, SENDING); in ssip_xmit()
600 spin_unlock_bh(&ssi->lock); in ssip_xmit()
602 dev_dbg(&cl->device, "Send STRANS (%d frames)\n", in ssip_xmit()
603 SSIP_BYTES_TO_FRAMES(skb->len)); in ssip_xmit()
611 struct net_device *dev = skb->dev; in ssip_pn_rx()
614 dev_dbg(&dev->dev, "Drop RX packet\n"); in ssip_pn_rx()
615 dev->stats.rx_dropped++; in ssip_pn_rx()
620 dev_dbg(&dev->dev, "Error drop RX packet\n"); in ssip_pn_rx()
621 dev->stats.rx_errors++; in ssip_pn_rx()
622 dev->stats.rx_length_errors++; in ssip_pn_rx()
626 dev->stats.rx_packets++; in ssip_pn_rx()
627 dev->stats.rx_bytes += skb->len; in ssip_pn_rx()
630 ((u16 *)skb->data)[2] = ntohs(((u16 *)skb->data)[2]); in ssip_pn_rx()
631 dev_dbg(&dev->dev, "RX length fixed (%04x -> %u)\n", in ssip_pn_rx()
632 ((u16 *)skb->data)[2], ntohs(((u16 *)skb->data)[2])); in ssip_pn_rx()
634 skb->protocol = htons(ETH_P_PHONET); in ssip_pn_rx()
642 struct hsi_client *cl = msg->cl; in ssip_rx_data_complete()
643 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_data_complete() local
646 if (msg->status == HSI_STATUS_ERROR) { in ssip_rx_data_complete()
647 dev_err(&cl->device, "RX data error\n"); in ssip_rx_data_complete()
652 del_timer(&ssi->rx_wd); /* FIXME: Revisit */ in ssip_rx_data_complete()
653 skb = msg->context; in ssip_rx_data_complete()
660 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_bootinforeq() local
667 switch (ssi->main_state) { in ssip_rx_bootinforeq()
669 dev_err(&cl->device, "Boot info req on active state\n"); in ssip_rx_bootinforeq()
674 spin_lock_bh(&ssi->lock); in ssip_rx_bootinforeq()
675 ssi->main_state = HANDSHAKE; in ssip_rx_bootinforeq()
676 spin_unlock_bh(&ssi->lock); in ssip_rx_bootinforeq()
678 if (!test_and_set_bit(SSIP_WAKETEST_FLAG, &ssi->flags)) in ssip_rx_bootinforeq()
681 spin_lock_bh(&ssi->lock); in ssip_rx_bootinforeq()
683 mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT)); in ssip_rx_bootinforeq()
684 spin_unlock_bh(&ssi->lock); in ssip_rx_bootinforeq()
685 dev_dbg(&cl->device, "Send BOOTINFO_RESP\n"); in ssip_rx_bootinforeq()
687 dev_warn(&cl->device, "boot info req verid mismatch\n"); in ssip_rx_bootinforeq()
688 msg = ssip_claim_cmd(ssi); in ssip_rx_bootinforeq()
690 msg->complete = ssip_release_cmd; in ssip_rx_bootinforeq()
694 dev_dbg(&cl->device, "Wrong state M(%d)\n", ssi->main_state); in ssip_rx_bootinforeq()
701 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_bootinforesp() local
704 dev_warn(&cl->device, "boot info resp verid mismatch\n"); in ssip_rx_bootinforesp()
706 spin_lock_bh(&ssi->lock); in ssip_rx_bootinforesp()
707 if (ssi->main_state != ACTIVE) in ssip_rx_bootinforesp()
709 mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT)); in ssip_rx_bootinforesp()
711 dev_dbg(&cl->device, "boot info resp ignored M(%d)\n", in ssip_rx_bootinforesp()
712 ssi->main_state); in ssip_rx_bootinforesp()
713 spin_unlock_bh(&ssi->lock); in ssip_rx_bootinforesp()
718 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_waketest() local
721 spin_lock_bh(&ssi->lock); in ssip_rx_waketest()
722 if (ssi->main_state != HANDSHAKE) { in ssip_rx_waketest()
723 dev_dbg(&cl->device, "wake lines test ignored M(%d)\n", in ssip_rx_waketest()
724 ssi->main_state); in ssip_rx_waketest()
725 spin_unlock_bh(&ssi->lock); in ssip_rx_waketest()
728 spin_unlock_bh(&ssi->lock); in ssip_rx_waketest()
730 if (test_and_clear_bit(SSIP_WAKETEST_FLAG, &ssi->flags)) in ssip_rx_waketest()
733 spin_lock_bh(&ssi->lock); in ssip_rx_waketest()
734 ssi->main_state = ACTIVE; in ssip_rx_waketest()
735 del_timer(&ssi->tx_wd); /* Stop boot handshake timer */ in ssip_rx_waketest()
736 spin_unlock_bh(&ssi->lock); in ssip_rx_waketest()
738 dev_notice(&cl->device, "WAKELINES TEST %s\n", in ssip_rx_waketest()
744 dev_dbg(&cl->device, "CMT is ONLINE\n"); in ssip_rx_waketest()
745 netif_wake_queue(ssi->netdev); in ssip_rx_waketest()
746 netif_carrier_on(ssi->netdev); in ssip_rx_waketest()
751 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_ready() local
753 spin_lock_bh(&ssi->lock); in ssip_rx_ready()
754 if (unlikely(ssi->main_state != ACTIVE)) { in ssip_rx_ready()
755 dev_dbg(&cl->device, "READY on wrong state: S(%d) M(%d)\n", in ssip_rx_ready()
756 ssi->send_state, ssi->main_state); in ssip_rx_ready()
757 spin_unlock_bh(&ssi->lock); in ssip_rx_ready()
760 if (ssi->send_state != WAIT4READY) { in ssip_rx_ready()
761 dev_dbg(&cl->device, "Ignore spurious READY command\n"); in ssip_rx_ready()
762 spin_unlock_bh(&ssi->lock); in ssip_rx_ready()
765 ssip_set_txstate(ssi, SEND_READY); in ssip_rx_ready()
766 spin_unlock_bh(&ssi->lock); in ssip_rx_ready()
772 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_rx_strans() local
777 dev_dbg(&cl->device, "RX strans: %d frames\n", len); in ssip_rx_strans()
778 spin_lock_bh(&ssi->lock); in ssip_rx_strans()
779 if (unlikely(ssi->main_state != ACTIVE)) { in ssip_rx_strans()
780 dev_err(&cl->device, "START TRANS wrong state: S(%d) M(%d)\n", in ssip_rx_strans()
781 ssi->send_state, ssi->main_state); in ssip_rx_strans()
782 spin_unlock_bh(&ssi->lock); in ssip_rx_strans()
785 ssip_set_rxstate(ssi, RECEIVING); in ssip_rx_strans()
786 if (unlikely(SSIP_MSG_ID(cmd) != ssi->rxid)) { in ssip_rx_strans()
787 dev_err(&cl->device, "START TRANS id %d expected %d\n", in ssip_rx_strans()
788 SSIP_MSG_ID(cmd), ssi->rxid); in ssip_rx_strans()
789 spin_unlock_bh(&ssi->lock); in ssip_rx_strans()
792 ssi->rxid++; in ssip_rx_strans()
793 spin_unlock_bh(&ssi->lock); in ssip_rx_strans()
794 skb = netdev_alloc_skb(ssi->netdev, len * 4); in ssip_rx_strans()
796 dev_err(&cl->device, "No memory for rx skb\n"); in ssip_rx_strans()
800 msg = ssip_alloc_data(ssi, skb, GFP_ATOMIC); in ssip_rx_strans()
802 dev_err(&cl->device, "No memory for RX data msg\n"); in ssip_rx_strans()
805 msg->complete = ssip_rx_data_complete; in ssip_rx_strans()
817 struct hsi_client *cl = msg->cl; in ssip_rxcmd_complete()
821 if (msg->status == HSI_STATUS_ERROR) { in ssip_rxcmd_complete()
822 dev_err(&cl->device, "RX error detected\n"); in ssip_rxcmd_complete()
828 dev_dbg(&cl->device, "RX cmd: 0x%08x\n", cmd); in ssip_rxcmd_complete()
849 dev_warn(&cl->device, "command 0x%08x not supported\n", cmd); in ssip_rxcmd_complete()
856 struct hsi_client *cl = msg->cl; in ssip_swbreak_complete()
857 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_swbreak_complete() local
860 spin_lock_bh(&ssi->lock); in ssip_swbreak_complete()
861 if (list_empty(&ssi->txqueue)) { in ssip_swbreak_complete()
862 if (atomic_read(&ssi->tx_usecnt)) { in ssip_swbreak_complete()
863 ssip_set_txstate(ssi, SEND_READY); in ssip_swbreak_complete()
865 ssip_set_txstate(ssi, SEND_IDLE); in ssip_swbreak_complete()
868 spin_unlock_bh(&ssi->lock); in ssip_swbreak_complete()
870 spin_unlock_bh(&ssi->lock); in ssip_swbreak_complete()
873 netif_wake_queue(ssi->netdev); in ssip_swbreak_complete()
878 struct hsi_client *cl = msg->cl; in ssip_tx_data_complete()
879 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_tx_data_complete() local
882 if (msg->status == HSI_STATUS_ERROR) { in ssip_tx_data_complete()
883 dev_err(&cl->device, "TX data error\n"); in ssip_tx_data_complete()
887 spin_lock_bh(&ssi->lock); in ssip_tx_data_complete()
888 if (list_empty(&ssi->txqueue)) { in ssip_tx_data_complete()
889 ssip_set_txstate(ssi, SENDING_SWBREAK); in ssip_tx_data_complete()
890 spin_unlock_bh(&ssi->lock); in ssip_tx_data_complete()
891 cmsg = ssip_claim_cmd(ssi); in ssip_tx_data_complete()
893 cmsg->complete = ssip_swbreak_complete; in ssip_tx_data_complete()
894 dev_dbg(&cl->device, "Send SWBREAK\n"); in ssip_tx_data_complete()
897 spin_unlock_bh(&ssi->lock); in ssip_tx_data_complete()
920 struct hsi_client *cl = to_hsi_client(dev->dev.parent); in ssip_pn_open()
921 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_pn_open() local
926 dev_err(&cl->device, "SSI port already claimed\n"); in ssip_pn_open()
931 dev_err(&cl->device, "Register HSI port event failed (%d)\n", in ssip_pn_open()
936 dev_dbg(&cl->device, "Configuring SSI port\n"); in ssip_pn_open()
939 if (!test_and_set_bit(SSIP_WAKETEST_FLAG, &ssi->flags)) in ssip_pn_open()
942 spin_lock_bh(&ssi->lock); in ssip_pn_open()
943 ssi->main_state = HANDSHAKE; in ssip_pn_open()
944 spin_unlock_bh(&ssi->lock); in ssip_pn_open()
953 struct hsi_client *cl = to_hsi_client(dev->dev.parent); in ssip_pn_stop()
964 struct ssi_protocol *ssi = in ssip_xmit_work() local
966 struct hsi_client *cl = ssi->cl; in ssip_xmit_work()
973 struct hsi_client *cl = to_hsi_client(dev->dev.parent); in ssip_pn_xmit()
974 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssip_pn_xmit() local
977 if ((skb->protocol != htons(ETH_P_PHONET)) || in ssip_pn_xmit()
978 (skb->len < SSIP_MIN_PN_HDR)) in ssip_pn_xmit()
980 /* Pad to 32-bits - FIXME: Revisit*/ in ssip_pn_xmit()
981 if ((skb->len & 3) && skb_pad(skb, 4 - (skb->len & 3))) in ssip_pn_xmit()
985 * Modem sends Phonet messages over SSI with its own endianness. in ssip_pn_xmit()
992 ((u16 *)skb->data)[2] = htons(((u16 *)skb->data)[2]); in ssip_pn_xmit()
994 msg = ssip_alloc_data(ssi, skb, GFP_ATOMIC); in ssip_pn_xmit()
996 dev_dbg(&cl->device, "Dropping tx data: No memory\n"); in ssip_pn_xmit()
999 msg->complete = ssip_tx_data_complete; in ssip_pn_xmit()
1001 spin_lock_bh(&ssi->lock); in ssip_pn_xmit()
1002 if (unlikely(ssi->main_state != ACTIVE)) { in ssip_pn_xmit()
1003 spin_unlock_bh(&ssi->lock); in ssip_pn_xmit()
1004 dev_dbg(&cl->device, "Dropping tx data: CMT is OFFLINE\n"); in ssip_pn_xmit()
1007 list_add_tail(&msg->link, &ssi->txqueue); in ssip_pn_xmit()
1008 ssi->txqueue_len++; in ssip_pn_xmit()
1009 if (dev->tx_queue_len < ssi->txqueue_len) { in ssip_pn_xmit()
1010 dev_info(&cl->device, "TX queue full %d\n", ssi->txqueue_len); in ssip_pn_xmit()
1013 if (ssi->send_state == SEND_IDLE) { in ssip_pn_xmit()
1014 ssip_set_txstate(ssi, WAIT4READY); in ssip_pn_xmit()
1015 spin_unlock_bh(&ssi->lock); in ssip_pn_xmit()
1016 dev_dbg(&cl->device, "Start TX qlen %d\n", ssi->txqueue_len); in ssip_pn_xmit()
1018 } else if (ssi->send_state == SEND_READY) { in ssip_pn_xmit()
1019 /* Needed for cmt-speech workaround */ in ssip_pn_xmit()
1020 dev_dbg(&cl->device, "Start TX on SEND READY qlen %d\n", in ssip_pn_xmit()
1021 ssi->txqueue_len); in ssip_pn_xmit()
1022 spin_unlock_bh(&ssi->lock); in ssip_pn_xmit()
1023 schedule_work(&ssi->work); in ssip_pn_xmit()
1025 spin_unlock_bh(&ssi->lock); in ssip_pn_xmit()
1027 dev->stats.tx_packets++; in ssip_pn_xmit()
1028 dev->stats.tx_bytes += skb->len; in ssip_pn_xmit()
1036 dev->stats.tx_dropped++; in ssip_pn_xmit()
1044 struct ssi_protocol *ssi = hsi_client_drvdata(master); in ssip_reset_event() local
1045 dev_err(&ssi->cl->device, "CMT reset detected!\n"); in ssip_reset_event()
1046 ssip_error(ssi->cl); in ssip_reset_event()
1060 dev->features = 0; in ssip_pn_setup()
1061 dev->netdev_ops = &ssip_pn_ops; in ssip_pn_setup()
1062 dev->type = ARPHRD_PHONET; in ssip_pn_setup()
1063 dev->flags = IFF_POINTOPOINT | IFF_NOARP; in ssip_pn_setup()
1064 dev->mtu = SSIP_DEFAULT_MTU; in ssip_pn_setup()
1065 dev->hard_header_len = 1; in ssip_pn_setup()
1066 dev->addr_len = 1; in ssip_pn_setup()
1068 dev->tx_queue_len = SSIP_TXQUEUE_LEN; in ssip_pn_setup()
1070 dev->needs_free_netdev = true; in ssip_pn_setup()
1071 dev->header_ops = &phonet_header_ops; in ssip_pn_setup()
1078 struct ssi_protocol *ssi; in ssi_protocol_probe() local
1081 ssi = kzalloc(sizeof(*ssi), GFP_KERNEL); in ssi_protocol_probe()
1082 if (!ssi) in ssi_protocol_probe()
1083 return -ENOMEM; in ssi_protocol_probe()
1085 spin_lock_init(&ssi->lock); in ssi_protocol_probe()
1086 timer_setup(&ssi->rx_wd, ssip_rx_wd, TIMER_DEFERRABLE); in ssi_protocol_probe()
1087 timer_setup(&ssi->tx_wd, ssip_tx_wd, TIMER_DEFERRABLE); in ssi_protocol_probe()
1088 timer_setup(&ssi->keep_alive, ssip_keep_alive, 0); in ssi_protocol_probe()
1089 INIT_LIST_HEAD(&ssi->txqueue); in ssi_protocol_probe()
1090 INIT_LIST_HEAD(&ssi->cmdqueue); in ssi_protocol_probe()
1091 atomic_set(&ssi->tx_usecnt, 0); in ssi_protocol_probe()
1092 hsi_client_set_drvdata(cl, ssi); in ssi_protocol_probe()
1093 ssi->cl = cl; in ssi_protocol_probe()
1094 INIT_WORK(&ssi->work, ssip_xmit_work); in ssi_protocol_probe()
1096 ssi->channel_id_cmd = hsi_get_channel_id_by_name(cl, "mcsaab-control"); in ssi_protocol_probe()
1097 if (ssi->channel_id_cmd < 0) { in ssi_protocol_probe()
1098 err = ssi->channel_id_cmd; in ssi_protocol_probe()
1103 ssi->channel_id_data = hsi_get_channel_id_by_name(cl, "mcsaab-data"); in ssi_protocol_probe()
1104 if (ssi->channel_id_data < 0) { in ssi_protocol_probe()
1105 err = ssi->channel_id_data; in ssi_protocol_probe()
1110 err = ssip_alloc_cmds(ssi); in ssi_protocol_probe()
1116 ssi->netdev = alloc_netdev(0, ifname, NET_NAME_UNKNOWN, ssip_pn_setup); in ssi_protocol_probe()
1117 if (!ssi->netdev) { in ssi_protocol_probe()
1119 err = -ENOMEM; in ssi_protocol_probe()
1123 /* MTU range: 6 - 65535 */ in ssi_protocol_probe()
1124 ssi->netdev->min_mtu = PHONET_MIN_MTU; in ssi_protocol_probe()
1125 ssi->netdev->max_mtu = SSIP_MAX_MTU; in ssi_protocol_probe()
1127 SET_NETDEV_DEV(ssi->netdev, dev); in ssi_protocol_probe()
1128 netif_carrier_off(ssi->netdev); in ssi_protocol_probe()
1129 err = register_netdev(ssi->netdev); in ssi_protocol_probe()
1135 list_add(&ssi->link, &ssip_list); in ssi_protocol_probe()
1138 ssi->channel_id_cmd, ssi->channel_id_data); in ssi_protocol_probe()
1142 free_netdev(ssi->netdev); in ssi_protocol_probe()
1144 ssip_free_cmds(ssi); in ssi_protocol_probe()
1146 kfree(ssi); in ssi_protocol_probe()
1154 struct ssi_protocol *ssi = hsi_client_drvdata(cl); in ssi_protocol_remove() local
1156 list_del(&ssi->link); in ssi_protocol_remove()
1157 unregister_netdev(ssi->netdev); in ssi_protocol_remove()
1158 ssip_free_cmds(ssi); in ssi_protocol_remove()
1160 kfree(ssi); in ssi_protocol_remove()
1167 .name = "ssi-protocol",
1176 pr_info("SSI protocol aka McSAAB added\n"); in ssip_init()
1185 pr_info("SSI protocol driver removed\n"); in ssip_exit()
1189 MODULE_ALIAS("hsi:ssi-protocol");
1191 MODULE_AUTHOR("Remi Denis-Courmont <remi.denis-courmont@nokia.com>");
1192 MODULE_DESCRIPTION("SSI protocol improved aka McSAAB");