Lines Matching refs:nu
39 static inline struct sk_buff *nci_uart_dequeue(struct nci_uart *nu) in nci_uart_dequeue() argument
41 struct sk_buff *skb = nu->tx_skb; in nci_uart_dequeue()
44 skb = skb_dequeue(&nu->tx_q); in nci_uart_dequeue()
46 nu->tx_skb = NULL; in nci_uart_dequeue()
51 static inline int nci_uart_queue_empty(struct nci_uart *nu) in nci_uart_queue_empty() argument
53 if (nu->tx_skb) in nci_uart_queue_empty()
56 return skb_queue_empty(&nu->tx_q); in nci_uart_queue_empty()
59 static int nci_uart_tx_wakeup(struct nci_uart *nu) in nci_uart_tx_wakeup() argument
61 if (test_and_set_bit(NCI_UART_SENDING, &nu->tx_state)) { in nci_uart_tx_wakeup()
62 set_bit(NCI_UART_TX_WAKEUP, &nu->tx_state); in nci_uart_tx_wakeup()
66 schedule_work(&nu->write_work); in nci_uart_tx_wakeup()
73 struct nci_uart *nu = container_of(work, struct nci_uart, write_work); in nci_uart_write_work() local
74 struct tty_struct *tty = nu->tty; in nci_uart_write_work()
78 clear_bit(NCI_UART_TX_WAKEUP, &nu->tx_state); in nci_uart_write_work()
80 if (nu->ops.tx_start) in nci_uart_write_work()
81 nu->ops.tx_start(nu); in nci_uart_write_work()
83 while ((skb = nci_uart_dequeue(nu))) { in nci_uart_write_work()
90 nu->tx_skb = skb; in nci_uart_write_work()
96 if (test_bit(NCI_UART_TX_WAKEUP, &nu->tx_state)) in nci_uart_write_work()
99 if (nu->ops.tx_done && nci_uart_queue_empty(nu)) in nci_uart_write_work()
100 nu->ops.tx_done(nu); in nci_uart_write_work()
102 clear_bit(NCI_UART_SENDING, &nu->tx_state); in nci_uart_write_work()
107 struct nci_uart *nu = NULL; in nci_uart_set_driver() local
116 nu = kzalloc(sizeof(*nu), GFP_KERNEL); in nci_uart_set_driver()
117 if (!nu) in nci_uart_set_driver()
120 memcpy(nu, nci_uart_drivers[driver], sizeof(struct nci_uart)); in nci_uart_set_driver()
121 nu->tty = tty; in nci_uart_set_driver()
122 tty->disc_data = nu; in nci_uart_set_driver()
123 skb_queue_head_init(&nu->tx_q); in nci_uart_set_driver()
124 INIT_WORK(&nu->write_work, nci_uart_write_work); in nci_uart_set_driver()
125 spin_lock_init(&nu->rx_lock); in nci_uart_set_driver()
127 ret = nu->ops.open(nu); in nci_uart_set_driver()
130 kfree(nu); in nci_uart_set_driver()
131 } else if (!try_module_get(nu->owner)) { in nci_uart_set_driver()
132 nu->ops.close(nu); in nci_uart_set_driver()
134 kfree(nu); in nci_uart_set_driver()
175 struct nci_uart *nu = tty->disc_data; in nci_uart_tty_close() local
180 if (!nu) in nci_uart_tty_close()
183 kfree_skb(nu->tx_skb); in nci_uart_tty_close()
184 kfree_skb(nu->rx_skb); in nci_uart_tty_close()
186 skb_queue_purge(&nu->tx_q); in nci_uart_tty_close()
188 nu->ops.close(nu); in nci_uart_tty_close()
189 nu->tty = NULL; in nci_uart_tty_close()
190 module_put(nu->owner); in nci_uart_tty_close()
192 cancel_work_sync(&nu->write_work); in nci_uart_tty_close()
194 kfree(nu); in nci_uart_tty_close()
207 struct nci_uart *nu = tty->disc_data; in nci_uart_tty_wakeup() local
209 if (!nu) in nci_uart_tty_wakeup()
214 if (tty != nu->tty) in nci_uart_tty_wakeup()
217 nci_uart_tx_wakeup(nu); in nci_uart_tty_wakeup()
226 static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data, in nci_uart_default_recv_buf() argument
231 if (!nu->ndev) { in nci_uart_default_recv_buf()
232 nfc_err(nu->tty->dev, in nci_uart_default_recv_buf()
242 if (!nu->rx_skb) { in nci_uart_default_recv_buf()
243 nu->rx_packet_len = -1; in nci_uart_default_recv_buf()
244 nu->rx_skb = nci_skb_alloc(nu->ndev, in nci_uart_default_recv_buf()
247 if (!nu->rx_skb) in nci_uart_default_recv_buf()
252 if (nu->rx_skb->len < NCI_CTRL_HDR_SIZE) { in nci_uart_default_recv_buf()
253 skb_put_u8(nu->rx_skb, *data++); in nci_uart_default_recv_buf()
259 if (nu->rx_packet_len < 0) in nci_uart_default_recv_buf()
260 nu->rx_packet_len = NCI_CTRL_HDR_SIZE + in nci_uart_default_recv_buf()
261 nci_plen(nu->rx_skb->data); in nci_uart_default_recv_buf()
266 chunk_len = nu->rx_packet_len - nu->rx_skb->len; in nci_uart_default_recv_buf()
269 skb_put_data(nu->rx_skb, data, chunk_len); in nci_uart_default_recv_buf()
274 if (nu->rx_packet_len == nu->rx_skb->len) { in nci_uart_default_recv_buf()
276 if (nu->ops.recv(nu, nu->rx_skb) != 0) in nci_uart_default_recv_buf()
277 nfc_err(nu->tty->dev, "corrupted RX packet\n"); in nci_uart_default_recv_buf()
279 nu->rx_skb = NULL; in nci_uart_default_recv_buf()
301 struct nci_uart *nu = tty->disc_data; in nci_uart_tty_receive() local
303 if (!nu || tty != nu->tty) in nci_uart_tty_receive()
306 spin_lock(&nu->rx_lock); in nci_uart_tty_receive()
307 nci_uart_default_recv_buf(nu, data, count); in nci_uart_tty_receive()
308 spin_unlock(&nu->rx_lock); in nci_uart_tty_receive()
328 struct nci_uart *nu = tty->disc_data; in nci_uart_tty_ioctl() local
333 if (!nu) in nci_uart_tty_ioctl()
360 static int nci_uart_send(struct nci_uart *nu, struct sk_buff *skb) in nci_uart_send() argument
363 skb_queue_tail(&nu->tx_q, skb); in nci_uart_send()
366 nci_uart_tx_wakeup(nu); in nci_uart_send()
371 int nci_uart_register(struct nci_uart *nu) in nci_uart_register() argument
373 if (!nu || !nu->ops.open || in nci_uart_register()
374 !nu->ops.recv || !nu->ops.close) in nci_uart_register()
378 nu->ops.send = nci_uart_send; in nci_uart_register()
381 if (nci_uart_drivers[nu->driver]) { in nci_uart_register()
382 pr_err("driver %d is already registered\n", nu->driver); in nci_uart_register()
385 nci_uart_drivers[nu->driver] = nu; in nci_uart_register()
387 pr_info("NCI uart driver '%s [%d]' registered\n", nu->name, nu->driver); in nci_uart_register()
393 void nci_uart_unregister(struct nci_uart *nu) in nci_uart_unregister() argument
395 pr_info("NCI uart driver '%s [%d]' unregistered\n", nu->name, in nci_uart_unregister()
396 nu->driver); in nci_uart_unregister()
399 nci_uart_drivers[nu->driver] = NULL; in nci_uart_unregister()
403 void nci_uart_set_config(struct nci_uart *nu, int baudrate, int flow_ctrl) in nci_uart_set_config() argument
407 if (!nu->tty) in nci_uart_set_config()
410 down_read(&nu->tty->termios_rwsem); in nci_uart_set_config()
411 new_termios = nu->tty->termios; in nci_uart_set_config()
412 up_read(&nu->tty->termios_rwsem); in nci_uart_set_config()
420 tty_set_termios(nu->tty, &new_termios); in nci_uart_set_config()