Lines Matching refs:priv
47 struct cw1200_common *priv = in cw1200_bh_work() local
49 cw1200_bh(priv); in cw1200_bh_work()
52 int cw1200_register_bh(struct cw1200_common *priv) in cw1200_register_bh() argument
56 priv->bh_workqueue = alloc_workqueue("cw1200_bh", in cw1200_register_bh()
60 if (!priv->bh_workqueue) in cw1200_register_bh()
63 INIT_WORK(&priv->bh_work, cw1200_bh_work); in cw1200_register_bh()
67 atomic_set(&priv->bh_rx, 0); in cw1200_register_bh()
68 atomic_set(&priv->bh_tx, 0); in cw1200_register_bh()
69 atomic_set(&priv->bh_term, 0); in cw1200_register_bh()
70 atomic_set(&priv->bh_suspend, CW1200_BH_RESUMED); in cw1200_register_bh()
71 priv->bh_error = 0; in cw1200_register_bh()
72 priv->hw_bufs_used = 0; in cw1200_register_bh()
73 priv->buf_id_tx = 0; in cw1200_register_bh()
74 priv->buf_id_rx = 0; in cw1200_register_bh()
75 init_waitqueue_head(&priv->bh_wq); in cw1200_register_bh()
76 init_waitqueue_head(&priv->bh_evt_wq); in cw1200_register_bh()
78 err = !queue_work(priv->bh_workqueue, &priv->bh_work); in cw1200_register_bh()
83 void cw1200_unregister_bh(struct cw1200_common *priv) in cw1200_unregister_bh() argument
85 atomic_inc(&priv->bh_term); in cw1200_unregister_bh()
86 wake_up(&priv->bh_wq); in cw1200_unregister_bh()
88 destroy_workqueue(priv->bh_workqueue); in cw1200_unregister_bh()
89 priv->bh_workqueue = NULL; in cw1200_unregister_bh()
94 void cw1200_irq_handler(struct cw1200_common *priv) in cw1200_irq_handler() argument
100 __cw1200_irq_enable(priv, 0); in cw1200_irq_handler()
102 if (/* WARN_ON */(priv->bh_error)) in cw1200_irq_handler()
105 if (atomic_inc_return(&priv->bh_rx) == 1) in cw1200_irq_handler()
106 wake_up(&priv->bh_wq); in cw1200_irq_handler()
110 void cw1200_bh_wakeup(struct cw1200_common *priv) in cw1200_bh_wakeup() argument
113 if (priv->bh_error) { in cw1200_bh_wakeup()
118 if (atomic_inc_return(&priv->bh_tx) == 1) in cw1200_bh_wakeup()
119 wake_up(&priv->bh_wq); in cw1200_bh_wakeup()
122 int cw1200_bh_suspend(struct cw1200_common *priv) in cw1200_bh_suspend() argument
125 if (priv->bh_error) { in cw1200_bh_suspend()
126 wiphy_warn(priv->hw->wiphy, "BH error -- can't suspend\n"); in cw1200_bh_suspend()
130 atomic_set(&priv->bh_suspend, CW1200_BH_SUSPEND); in cw1200_bh_suspend()
131 wake_up(&priv->bh_wq); in cw1200_bh_suspend()
132 return wait_event_timeout(priv->bh_evt_wq, priv->bh_error || in cw1200_bh_suspend()
133 (CW1200_BH_SUSPENDED == atomic_read(&priv->bh_suspend)), in cw1200_bh_suspend()
137 int cw1200_bh_resume(struct cw1200_common *priv) in cw1200_bh_resume() argument
140 if (priv->bh_error) { in cw1200_bh_resume()
141 wiphy_warn(priv->hw->wiphy, "BH error -- can't resume\n"); in cw1200_bh_resume()
145 atomic_set(&priv->bh_suspend, CW1200_BH_RESUME); in cw1200_bh_resume()
146 wake_up(&priv->bh_wq); in cw1200_bh_resume()
147 return wait_event_timeout(priv->bh_evt_wq, priv->bh_error || in cw1200_bh_resume()
148 (CW1200_BH_RESUMED == atomic_read(&priv->bh_suspend)), in cw1200_bh_resume()
152 static inline void wsm_alloc_tx_buffer(struct cw1200_common *priv) in wsm_alloc_tx_buffer() argument
154 ++priv->hw_bufs_used; in wsm_alloc_tx_buffer()
157 int wsm_release_tx_buffer(struct cw1200_common *priv, int count) in wsm_release_tx_buffer() argument
160 int hw_bufs_used = priv->hw_bufs_used; in wsm_release_tx_buffer()
162 priv->hw_bufs_used -= count; in wsm_release_tx_buffer()
163 if (WARN_ON(priv->hw_bufs_used < 0)) in wsm_release_tx_buffer()
165 else if (hw_bufs_used >= priv->wsm_caps.input_buffers) in wsm_release_tx_buffer()
167 if (!priv->hw_bufs_used) in wsm_release_tx_buffer()
168 wake_up(&priv->bh_evt_wq); in wsm_release_tx_buffer()
172 static int cw1200_bh_read_ctrl_reg(struct cw1200_common *priv, in cw1200_bh_read_ctrl_reg() argument
177 ret = cw1200_reg_read_16(priv, in cw1200_bh_read_ctrl_reg()
180 ret = cw1200_reg_read_16(priv, in cw1200_bh_read_ctrl_reg()
189 static int cw1200_device_wakeup(struct cw1200_common *priv) in cw1200_device_wakeup() argument
197 ret = cw1200_reg_write_32(priv, ST90TDS_TSET_GEN_R_W_REG_ID, in cw1200_device_wakeup()
198 cw1200_dpll_from_clk(priv->hw_refclk)); in cw1200_device_wakeup()
203 ret = cw1200_reg_write_16(priv, ST90TDS_CONTROL_REG_ID, in cw1200_device_wakeup()
208 ret = cw1200_bh_read_ctrl_reg(priv, &ctrl_reg); in cw1200_device_wakeup()
224 void cw1200_enable_powersave(struct cw1200_common *priv, in cw1200_enable_powersave() argument
229 priv->powersave_enabled = enable; in cw1200_enable_powersave()
232 static int cw1200_bh_rx_helper(struct cw1200_common *priv, in cw1200_bh_rx_helper() argument
263 alloc_len = priv->hwbus_ops->align_size( in cw1200_bh_rx_helper()
264 priv->hwbus_priv, read_len); in cw1200_bh_rx_helper()
282 if (WARN_ON(cw1200_data_read(priv, data, alloc_len))) { in cw1200_bh_rx_helper()
296 if (priv->wsm_enable_wsm_dumps) in cw1200_bh_rx_helper()
307 wsm_handle_exception(priv, in cw1200_bh_rx_helper()
312 if (WARN_ON(wsm_seq != priv->wsm_rx_seq)) in cw1200_bh_rx_helper()
315 priv->wsm_rx_seq = (wsm_seq + 1) & 7; in cw1200_bh_rx_helper()
319 int rc = wsm_release_tx_buffer(priv, 1); in cw1200_bh_rx_helper()
327 if (WARN_ON(wsm_handle_rx(priv, wsm_id, wsm, &skb_rx))) in cw1200_bh_rx_helper()
345 static int cw1200_bh_tx_helper(struct cw1200_common *priv, in cw1200_bh_tx_helper() argument
354 if (priv->device_can_sleep) { in cw1200_bh_tx_helper()
355 ret = cw1200_device_wakeup(priv); in cw1200_bh_tx_helper()
360 priv->device_can_sleep = false; in cw1200_bh_tx_helper()
367 wsm_alloc_tx_buffer(priv); in cw1200_bh_tx_helper()
368 ret = wsm_get_tx(priv, &data, &tx_len, tx_burst); in cw1200_bh_tx_helper()
370 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
380 atomic_inc(&priv->bh_tx); in cw1200_bh_tx_helper()
382 tx_len = priv->hwbus_ops->align_size( in cw1200_bh_tx_helper()
383 priv->hwbus_priv, tx_len); in cw1200_bh_tx_helper()
390 wsm->id |= __cpu_to_le16(WSM_TX_SEQ(priv->wsm_tx_seq)); in cw1200_bh_tx_helper()
392 if (WARN_ON(cw1200_data_write(priv, data, tx_len))) { in cw1200_bh_tx_helper()
394 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
398 if (priv->wsm_enable_wsm_dumps) in cw1200_bh_tx_helper()
404 wsm_txed(priv, data); in cw1200_bh_tx_helper()
405 priv->wsm_tx_seq = (priv->wsm_tx_seq + 1) & WSM_TX_SEQ_MAX; in cw1200_bh_tx_helper()
408 cw1200_debug_tx_burst(priv); in cw1200_bh_tx_helper()
417 struct cw1200_common *priv = arg; in cw1200_bh() local
428 if (!priv->hw_bufs_used && in cw1200_bh()
429 priv->powersave_enabled && in cw1200_bh()
430 !priv->device_can_sleep && in cw1200_bh()
431 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
434 cw1200_reg_write_16(priv, ST90TDS_CONTROL_REG_ID, 0); in cw1200_bh()
435 priv->device_can_sleep = true; in cw1200_bh()
436 } else if (priv->hw_bufs_used) { in cw1200_bh()
444 if ((priv->hw_type != -1) && in cw1200_bh()
445 (atomic_read(&priv->bh_rx) == 0) && in cw1200_bh()
446 (atomic_read(&priv->bh_tx) == 0)) in cw1200_bh()
447 cw1200_reg_read(priv, ST90TDS_CONFIG_REG_ID, in cw1200_bh()
451 status = wait_event_interruptible_timeout(priv->bh_wq, ({ in cw1200_bh()
452 rx = atomic_xchg(&priv->bh_rx, 0); in cw1200_bh()
453 tx = atomic_xchg(&priv->bh_tx, 0); in cw1200_bh()
454 term = atomic_xchg(&priv->bh_term, 0); in cw1200_bh()
456 0 : atomic_read(&priv->bh_suspend); in cw1200_bh()
457 (rx || tx || term || suspend || priv->bh_error); in cw1200_bh()
461 rx, tx, term, suspend, priv->bh_error, status); in cw1200_bh()
465 term || priv->bh_error) { in cw1200_bh()
475 if (priv->hw_bufs_used && (!rx || !tx)) { in cw1200_bh()
476 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
478 priv->hw_bufs_used); in cw1200_bh()
484 &priv->tx_queue[i], in cw1200_bh()
486 priv->pending_frame_id); in cw1200_bh()
499 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
501 priv->hw_bufs_used, pending, in cw1200_bh()
505 } else if (!priv->device_can_sleep && in cw1200_bh()
506 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
508 cw1200_reg_write_16(priv, in cw1200_bh()
510 priv->device_can_sleep = true; in cw1200_bh()
515 if (priv->powersave_enabled) { in cw1200_bh()
517 cw1200_reg_write_16(priv, in cw1200_bh()
519 priv->device_can_sleep = true; in cw1200_bh()
522 atomic_set(&priv->bh_suspend, CW1200_BH_SUSPENDED); in cw1200_bh()
523 wake_up(&priv->bh_evt_wq); in cw1200_bh()
524 status = wait_event_interruptible(priv->bh_wq, in cw1200_bh()
525 CW1200_BH_RESUME == atomic_read(&priv->bh_suspend)); in cw1200_bh()
527 wiphy_err(priv->hw->wiphy, in cw1200_bh()
533 atomic_set(&priv->bh_suspend, CW1200_BH_RESUMED); in cw1200_bh()
534 wake_up(&priv->bh_evt_wq); in cw1200_bh()
535 atomic_inc(&priv->bh_rx); in cw1200_bh()
543 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
548 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
553 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
563 BUG_ON(priv->hw_bufs_used > priv->wsm_caps.input_buffers); in cw1200_bh()
564 tx_burst = priv->wsm_caps.input_buffers - priv->hw_bufs_used; in cw1200_bh()
574 ret = cw1200_bh_tx_helper(priv, &pending_tx, &tx_burst); in cw1200_bh()
581 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
586 if (priv->bh_error) in cw1200_bh()
595 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
596 __cw1200_irq_enable(priv, 1); in cw1200_bh()
597 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
601 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
602 __cw1200_irq_enable(priv, 0); in cw1200_bh()
603 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
607 priv->bh_error = 1; in cw1200_bh()