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()
339 static int cw1200_bh_tx_helper(struct cw1200_common *priv, in cw1200_bh_tx_helper() argument
348 if (priv->device_can_sleep) { in cw1200_bh_tx_helper()
349 ret = cw1200_device_wakeup(priv); in cw1200_bh_tx_helper()
354 priv->device_can_sleep = false; in cw1200_bh_tx_helper()
361 wsm_alloc_tx_buffer(priv); in cw1200_bh_tx_helper()
362 ret = wsm_get_tx(priv, &data, &tx_len, tx_burst); in cw1200_bh_tx_helper()
364 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
374 atomic_inc(&priv->bh_tx); in cw1200_bh_tx_helper()
376 tx_len = priv->hwbus_ops->align_size( in cw1200_bh_tx_helper()
377 priv->hwbus_priv, tx_len); in cw1200_bh_tx_helper()
384 wsm->id |= __cpu_to_le16(WSM_TX_SEQ(priv->wsm_tx_seq)); in cw1200_bh_tx_helper()
386 if (WARN_ON(cw1200_data_write(priv, data, tx_len))) { in cw1200_bh_tx_helper()
388 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
392 if (priv->wsm_enable_wsm_dumps) in cw1200_bh_tx_helper()
398 wsm_txed(priv, data); in cw1200_bh_tx_helper()
399 priv->wsm_tx_seq = (priv->wsm_tx_seq + 1) & WSM_TX_SEQ_MAX; in cw1200_bh_tx_helper()
402 cw1200_debug_tx_burst(priv); in cw1200_bh_tx_helper()
411 struct cw1200_common *priv = arg; in cw1200_bh() local
422 if (!priv->hw_bufs_used && in cw1200_bh()
423 priv->powersave_enabled && in cw1200_bh()
424 !priv->device_can_sleep && in cw1200_bh()
425 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
428 cw1200_reg_write_16(priv, ST90TDS_CONTROL_REG_ID, 0); in cw1200_bh()
429 priv->device_can_sleep = true; in cw1200_bh()
430 } else if (priv->hw_bufs_used) { in cw1200_bh()
438 if ((priv->hw_type != -1) && in cw1200_bh()
439 (atomic_read(&priv->bh_rx) == 0) && in cw1200_bh()
440 (atomic_read(&priv->bh_tx) == 0)) in cw1200_bh()
441 cw1200_reg_read(priv, ST90TDS_CONFIG_REG_ID, in cw1200_bh()
445 status = wait_event_interruptible_timeout(priv->bh_wq, ({ in cw1200_bh()
446 rx = atomic_xchg(&priv->bh_rx, 0); in cw1200_bh()
447 tx = atomic_xchg(&priv->bh_tx, 0); in cw1200_bh()
448 term = atomic_xchg(&priv->bh_term, 0); in cw1200_bh()
450 0 : atomic_read(&priv->bh_suspend); in cw1200_bh()
451 (rx || tx || term || suspend || priv->bh_error); in cw1200_bh()
455 rx, tx, term, suspend, priv->bh_error, status); in cw1200_bh()
459 term || priv->bh_error) { in cw1200_bh()
469 if (priv->hw_bufs_used && (!rx || !tx)) { in cw1200_bh()
470 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
472 priv->hw_bufs_used); in cw1200_bh()
478 &priv->tx_queue[i], in cw1200_bh()
480 priv->pending_frame_id); in cw1200_bh()
493 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
495 priv->hw_bufs_used, pending, in cw1200_bh()
499 } else if (!priv->device_can_sleep && in cw1200_bh()
500 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
502 cw1200_reg_write_16(priv, in cw1200_bh()
504 priv->device_can_sleep = true; in cw1200_bh()
509 if (priv->powersave_enabled) { in cw1200_bh()
511 cw1200_reg_write_16(priv, in cw1200_bh()
513 priv->device_can_sleep = true; in cw1200_bh()
516 atomic_set(&priv->bh_suspend, CW1200_BH_SUSPENDED); in cw1200_bh()
517 wake_up(&priv->bh_evt_wq); in cw1200_bh()
518 status = wait_event_interruptible(priv->bh_wq, in cw1200_bh()
519 CW1200_BH_RESUME == atomic_read(&priv->bh_suspend)); in cw1200_bh()
521 wiphy_err(priv->hw->wiphy, in cw1200_bh()
527 atomic_set(&priv->bh_suspend, CW1200_BH_RESUMED); in cw1200_bh()
528 wake_up(&priv->bh_evt_wq); in cw1200_bh()
529 atomic_inc(&priv->bh_rx); in cw1200_bh()
537 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
542 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
547 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
557 BUG_ON(priv->hw_bufs_used > priv->wsm_caps.input_buffers); in cw1200_bh()
558 tx_burst = priv->wsm_caps.input_buffers - priv->hw_bufs_used; in cw1200_bh()
568 ret = cw1200_bh_tx_helper(priv, &pending_tx, &tx_burst); in cw1200_bh()
575 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
580 if (priv->bh_error) in cw1200_bh()
589 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
590 __cw1200_irq_enable(priv, 1); in cw1200_bh()
591 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
595 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
596 __cw1200_irq_enable(priv, 0); in cw1200_bh()
597 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
601 priv->bh_error = 1; in cw1200_bh()