Lines Matching refs:nu
51 static inline struct sk_buff *nci_uart_dequeue(struct nci_uart *nu) in nci_uart_dequeue() argument
53 struct sk_buff *skb = nu->tx_skb; in nci_uart_dequeue()
56 skb = skb_dequeue(&nu->tx_q); in nci_uart_dequeue()
58 nu->tx_skb = NULL; in nci_uart_dequeue()
63 static inline int nci_uart_queue_empty(struct nci_uart *nu) in nci_uart_queue_empty() argument
65 if (nu->tx_skb) in nci_uart_queue_empty()
68 return skb_queue_empty(&nu->tx_q); in nci_uart_queue_empty()
71 static int nci_uart_tx_wakeup(struct nci_uart *nu) in nci_uart_tx_wakeup() argument
73 if (test_and_set_bit(NCI_UART_SENDING, &nu->tx_state)) { in nci_uart_tx_wakeup()
74 set_bit(NCI_UART_TX_WAKEUP, &nu->tx_state); in nci_uart_tx_wakeup()
78 schedule_work(&nu->write_work); in nci_uart_tx_wakeup()
85 struct nci_uart *nu = container_of(work, struct nci_uart, write_work); in nci_uart_write_work() local
86 struct tty_struct *tty = nu->tty; in nci_uart_write_work()
90 clear_bit(NCI_UART_TX_WAKEUP, &nu->tx_state); in nci_uart_write_work()
92 if (nu->ops.tx_start) in nci_uart_write_work()
93 nu->ops.tx_start(nu); in nci_uart_write_work()
95 while ((skb = nci_uart_dequeue(nu))) { in nci_uart_write_work()
102 nu->tx_skb = skb; in nci_uart_write_work()
108 if (test_bit(NCI_UART_TX_WAKEUP, &nu->tx_state)) in nci_uart_write_work()
111 if (nu->ops.tx_done && nci_uart_queue_empty(nu)) in nci_uart_write_work()
112 nu->ops.tx_done(nu); in nci_uart_write_work()
114 clear_bit(NCI_UART_SENDING, &nu->tx_state); in nci_uart_write_work()
119 struct nci_uart *nu = NULL; in nci_uart_set_driver() local
128 nu = kzalloc(sizeof(*nu), GFP_KERNEL); in nci_uart_set_driver()
129 if (!nu) in nci_uart_set_driver()
132 memcpy(nu, nci_uart_drivers[driver], sizeof(struct nci_uart)); in nci_uart_set_driver()
133 nu->tty = tty; in nci_uart_set_driver()
134 tty->disc_data = nu; in nci_uart_set_driver()
135 skb_queue_head_init(&nu->tx_q); in nci_uart_set_driver()
136 INIT_WORK(&nu->write_work, nci_uart_write_work); in nci_uart_set_driver()
137 spin_lock_init(&nu->rx_lock); in nci_uart_set_driver()
139 ret = nu->ops.open(nu); in nci_uart_set_driver()
142 kfree(nu); in nci_uart_set_driver()
143 } else if (!try_module_get(nu->owner)) { in nci_uart_set_driver()
144 nu->ops.close(nu); in nci_uart_set_driver()
146 kfree(nu); in nci_uart_set_driver()
187 struct nci_uart *nu = (void *)tty->disc_data; in nci_uart_tty_close() local
192 if (!nu) in nci_uart_tty_close()
195 if (nu->tx_skb) in nci_uart_tty_close()
196 kfree_skb(nu->tx_skb); in nci_uart_tty_close()
197 if (nu->rx_skb) in nci_uart_tty_close()
198 kfree_skb(nu->rx_skb); in nci_uart_tty_close()
200 skb_queue_purge(&nu->tx_q); in nci_uart_tty_close()
202 nu->ops.close(nu); in nci_uart_tty_close()
203 nu->tty = NULL; in nci_uart_tty_close()
204 module_put(nu->owner); in nci_uart_tty_close()
206 cancel_work_sync(&nu->write_work); in nci_uart_tty_close()
208 kfree(nu); in nci_uart_tty_close()
221 struct nci_uart *nu = (void *)tty->disc_data; in nci_uart_tty_wakeup() local
223 if (!nu) in nci_uart_tty_wakeup()
228 if (tty != nu->tty) in nci_uart_tty_wakeup()
231 nci_uart_tx_wakeup(nu); in nci_uart_tty_wakeup()
249 struct nci_uart *nu = (void *)tty->disc_data; in nci_uart_tty_receive() local
251 if (!nu || tty != nu->tty) in nci_uart_tty_receive()
254 spin_lock(&nu->rx_lock); in nci_uart_tty_receive()
255 nu->ops.recv_buf(nu, (void *)data, flags, count); in nci_uart_tty_receive()
256 spin_unlock(&nu->rx_lock); in nci_uart_tty_receive()
277 struct nci_uart *nu = (void *)tty->disc_data; in nci_uart_tty_ioctl() local
282 if (!nu) in nci_uart_tty_ioctl()
314 static int nci_uart_send(struct nci_uart *nu, struct sk_buff *skb) in nci_uart_send() argument
317 skb_queue_tail(&nu->tx_q, skb); in nci_uart_send()
320 nci_uart_tx_wakeup(nu); in nci_uart_send()
331 static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data, in nci_uart_default_recv_buf() argument
336 if (!nu->ndev) { in nci_uart_default_recv_buf()
337 nfc_err(nu->tty->dev, in nci_uart_default_recv_buf()
347 if (!nu->rx_skb) { in nci_uart_default_recv_buf()
348 nu->rx_packet_len = -1; in nci_uart_default_recv_buf()
349 nu->rx_skb = nci_skb_alloc(nu->ndev, in nci_uart_default_recv_buf()
352 if (!nu->rx_skb) in nci_uart_default_recv_buf()
357 if (nu->rx_skb->len < NCI_CTRL_HDR_SIZE) { in nci_uart_default_recv_buf()
358 skb_put_u8(nu->rx_skb, *data++); in nci_uart_default_recv_buf()
364 if (nu->rx_packet_len < 0) in nci_uart_default_recv_buf()
365 nu->rx_packet_len = NCI_CTRL_HDR_SIZE + in nci_uart_default_recv_buf()
366 nci_plen(nu->rx_skb->data); in nci_uart_default_recv_buf()
371 chunk_len = nu->rx_packet_len - nu->rx_skb->len; in nci_uart_default_recv_buf()
374 skb_put_data(nu->rx_skb, data, chunk_len); in nci_uart_default_recv_buf()
379 if (nu->rx_packet_len == nu->rx_skb->len) { in nci_uart_default_recv_buf()
381 if (nu->ops.recv(nu, nu->rx_skb) != 0) in nci_uart_default_recv_buf()
382 nfc_err(nu->tty->dev, "corrupted RX packet\n"); in nci_uart_default_recv_buf()
384 nu->rx_skb = NULL; in nci_uart_default_recv_buf()
392 static int nci_uart_default_recv(struct nci_uart *nu, struct sk_buff *skb) in nci_uart_default_recv() argument
394 return nci_recv_frame(nu->ndev, skb); in nci_uart_default_recv()
397 int nci_uart_register(struct nci_uart *nu) in nci_uart_register() argument
399 if (!nu || !nu->ops.open || in nci_uart_register()
400 !nu->ops.recv || !nu->ops.close) in nci_uart_register()
404 nu->ops.send = nci_uart_send; in nci_uart_register()
407 if (!nu->ops.recv_buf) in nci_uart_register()
408 nu->ops.recv_buf = nci_uart_default_recv_buf; in nci_uart_register()
409 if (!nu->ops.recv) in nci_uart_register()
410 nu->ops.recv = nci_uart_default_recv; in nci_uart_register()
413 if (nci_uart_drivers[nu->driver]) { in nci_uart_register()
414 pr_err("driver %d is already registered\n", nu->driver); in nci_uart_register()
417 nci_uart_drivers[nu->driver] = nu; in nci_uart_register()
419 pr_info("NCI uart driver '%s [%d]' registered\n", nu->name, nu->driver); in nci_uart_register()
425 void nci_uart_unregister(struct nci_uart *nu) in nci_uart_unregister() argument
427 pr_info("NCI uart driver '%s [%d]' unregistered\n", nu->name, in nci_uart_unregister()
428 nu->driver); in nci_uart_unregister()
431 nci_uart_drivers[nu->driver] = NULL; in nci_uart_unregister()
435 void nci_uart_set_config(struct nci_uart *nu, int baudrate, int flow_ctrl) in nci_uart_set_config() argument
439 if (!nu->tty) in nci_uart_set_config()
442 down_read(&nu->tty->termios_rwsem); in nci_uart_set_config()
443 new_termios = nu->tty->termios; in nci_uart_set_config()
444 up_read(&nu->tty->termios_rwsem); in nci_uart_set_config()
452 tty_set_termios(nu->tty, &new_termios); in nci_uart_set_config()