Lines Matching refs:priv
48 typedef int (*cw1200_wsm_handler)(struct cw1200_common *priv,
53 struct cw1200_common *priv = in cw1200_bh_work() local
55 cw1200_bh(priv); in cw1200_bh_work()
58 int cw1200_register_bh(struct cw1200_common *priv) in cw1200_register_bh() argument
62 priv->bh_workqueue = alloc_workqueue("cw1200_bh", in cw1200_register_bh()
66 if (!priv->bh_workqueue) in cw1200_register_bh()
69 INIT_WORK(&priv->bh_work, cw1200_bh_work); in cw1200_register_bh()
73 atomic_set(&priv->bh_rx, 0); in cw1200_register_bh()
74 atomic_set(&priv->bh_tx, 0); in cw1200_register_bh()
75 atomic_set(&priv->bh_term, 0); in cw1200_register_bh()
76 atomic_set(&priv->bh_suspend, CW1200_BH_RESUMED); in cw1200_register_bh()
77 priv->bh_error = 0; in cw1200_register_bh()
78 priv->hw_bufs_used = 0; in cw1200_register_bh()
79 priv->buf_id_tx = 0; in cw1200_register_bh()
80 priv->buf_id_rx = 0; in cw1200_register_bh()
81 init_waitqueue_head(&priv->bh_wq); in cw1200_register_bh()
82 init_waitqueue_head(&priv->bh_evt_wq); in cw1200_register_bh()
84 err = !queue_work(priv->bh_workqueue, &priv->bh_work); in cw1200_register_bh()
89 void cw1200_unregister_bh(struct cw1200_common *priv) in cw1200_unregister_bh() argument
91 atomic_add(1, &priv->bh_term); in cw1200_unregister_bh()
92 wake_up(&priv->bh_wq); in cw1200_unregister_bh()
94 flush_workqueue(priv->bh_workqueue); in cw1200_unregister_bh()
96 destroy_workqueue(priv->bh_workqueue); in cw1200_unregister_bh()
97 priv->bh_workqueue = NULL; in cw1200_unregister_bh()
102 void cw1200_irq_handler(struct cw1200_common *priv) in cw1200_irq_handler() argument
108 __cw1200_irq_enable(priv, 0); in cw1200_irq_handler()
110 if (/* WARN_ON */(priv->bh_error)) in cw1200_irq_handler()
113 if (atomic_add_return(1, &priv->bh_rx) == 1) in cw1200_irq_handler()
114 wake_up(&priv->bh_wq); in cw1200_irq_handler()
118 void cw1200_bh_wakeup(struct cw1200_common *priv) in cw1200_bh_wakeup() argument
121 if (priv->bh_error) { in cw1200_bh_wakeup()
126 if (atomic_add_return(1, &priv->bh_tx) == 1) in cw1200_bh_wakeup()
127 wake_up(&priv->bh_wq); in cw1200_bh_wakeup()
130 int cw1200_bh_suspend(struct cw1200_common *priv) in cw1200_bh_suspend() argument
133 if (priv->bh_error) { in cw1200_bh_suspend()
134 wiphy_warn(priv->hw->wiphy, "BH error -- can't suspend\n"); in cw1200_bh_suspend()
138 atomic_set(&priv->bh_suspend, CW1200_BH_SUSPEND); in cw1200_bh_suspend()
139 wake_up(&priv->bh_wq); in cw1200_bh_suspend()
140 return wait_event_timeout(priv->bh_evt_wq, priv->bh_error || in cw1200_bh_suspend()
141 (CW1200_BH_SUSPENDED == atomic_read(&priv->bh_suspend)), in cw1200_bh_suspend()
145 int cw1200_bh_resume(struct cw1200_common *priv) in cw1200_bh_resume() argument
148 if (priv->bh_error) { in cw1200_bh_resume()
149 wiphy_warn(priv->hw->wiphy, "BH error -- can't resume\n"); in cw1200_bh_resume()
153 atomic_set(&priv->bh_suspend, CW1200_BH_RESUME); in cw1200_bh_resume()
154 wake_up(&priv->bh_wq); in cw1200_bh_resume()
155 return wait_event_timeout(priv->bh_evt_wq, priv->bh_error || in cw1200_bh_resume()
156 (CW1200_BH_RESUMED == atomic_read(&priv->bh_suspend)), in cw1200_bh_resume()
160 static inline void wsm_alloc_tx_buffer(struct cw1200_common *priv) in wsm_alloc_tx_buffer() argument
162 ++priv->hw_bufs_used; in wsm_alloc_tx_buffer()
165 int wsm_release_tx_buffer(struct cw1200_common *priv, int count) in wsm_release_tx_buffer() argument
168 int hw_bufs_used = priv->hw_bufs_used; in wsm_release_tx_buffer()
170 priv->hw_bufs_used -= count; in wsm_release_tx_buffer()
171 if (WARN_ON(priv->hw_bufs_used < 0)) in wsm_release_tx_buffer()
173 else if (hw_bufs_used >= priv->wsm_caps.input_buffers) in wsm_release_tx_buffer()
175 if (!priv->hw_bufs_used) in wsm_release_tx_buffer()
176 wake_up(&priv->bh_evt_wq); in wsm_release_tx_buffer()
180 static int cw1200_bh_read_ctrl_reg(struct cw1200_common *priv, in cw1200_bh_read_ctrl_reg() argument
185 ret = cw1200_reg_read_16(priv, in cw1200_bh_read_ctrl_reg()
188 ret = cw1200_reg_read_16(priv, in cw1200_bh_read_ctrl_reg()
197 static int cw1200_device_wakeup(struct cw1200_common *priv) in cw1200_device_wakeup() argument
205 ret = cw1200_reg_write_32(priv, ST90TDS_TSET_GEN_R_W_REG_ID, in cw1200_device_wakeup()
206 cw1200_dpll_from_clk(priv->hw_refclk)); in cw1200_device_wakeup()
211 ret = cw1200_reg_write_16(priv, ST90TDS_CONTROL_REG_ID, in cw1200_device_wakeup()
216 ret = cw1200_bh_read_ctrl_reg(priv, &ctrl_reg); in cw1200_device_wakeup()
232 void cw1200_enable_powersave(struct cw1200_common *priv, in cw1200_enable_powersave() argument
237 priv->powersave_enabled = enable; in cw1200_enable_powersave()
240 static int cw1200_bh_rx_helper(struct cw1200_common *priv, in cw1200_bh_rx_helper() argument
271 alloc_len = priv->hwbus_ops->align_size( in cw1200_bh_rx_helper()
272 priv->hwbus_priv, read_len); in cw1200_bh_rx_helper()
290 if (WARN_ON(cw1200_data_read(priv, data, alloc_len))) { in cw1200_bh_rx_helper()
304 if (priv->wsm_enable_wsm_dumps) in cw1200_bh_rx_helper()
315 wsm_handle_exception(priv, in cw1200_bh_rx_helper()
320 if (WARN_ON(wsm_seq != priv->wsm_rx_seq)) in cw1200_bh_rx_helper()
323 priv->wsm_rx_seq = (wsm_seq + 1) & 7; in cw1200_bh_rx_helper()
327 int rc = wsm_release_tx_buffer(priv, 1); in cw1200_bh_rx_helper()
335 if (WARN_ON(wsm_handle_rx(priv, wsm_id, wsm, &skb_rx))) in cw1200_bh_rx_helper()
353 static int cw1200_bh_tx_helper(struct cw1200_common *priv, in cw1200_bh_tx_helper() argument
362 if (priv->device_can_sleep) { in cw1200_bh_tx_helper()
363 ret = cw1200_device_wakeup(priv); in cw1200_bh_tx_helper()
368 priv->device_can_sleep = false; in cw1200_bh_tx_helper()
375 wsm_alloc_tx_buffer(priv); in cw1200_bh_tx_helper()
376 ret = wsm_get_tx(priv, &data, &tx_len, tx_burst); in cw1200_bh_tx_helper()
378 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
388 atomic_add(1, &priv->bh_tx); in cw1200_bh_tx_helper()
390 tx_len = priv->hwbus_ops->align_size( in cw1200_bh_tx_helper()
391 priv->hwbus_priv, tx_len); in cw1200_bh_tx_helper()
398 wsm->id |= __cpu_to_le16(WSM_TX_SEQ(priv->wsm_tx_seq)); in cw1200_bh_tx_helper()
400 if (WARN_ON(cw1200_data_write(priv, data, tx_len))) { in cw1200_bh_tx_helper()
402 wsm_release_tx_buffer(priv, 1); in cw1200_bh_tx_helper()
406 if (priv->wsm_enable_wsm_dumps) in cw1200_bh_tx_helper()
412 wsm_txed(priv, data); in cw1200_bh_tx_helper()
413 priv->wsm_tx_seq = (priv->wsm_tx_seq + 1) & WSM_TX_SEQ_MAX; in cw1200_bh_tx_helper()
416 cw1200_debug_tx_burst(priv); in cw1200_bh_tx_helper()
425 struct cw1200_common *priv = arg; in cw1200_bh() local
436 if (!priv->hw_bufs_used && in cw1200_bh()
437 priv->powersave_enabled && in cw1200_bh()
438 !priv->device_can_sleep && in cw1200_bh()
439 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
442 cw1200_reg_write_16(priv, ST90TDS_CONTROL_REG_ID, 0); in cw1200_bh()
443 priv->device_can_sleep = true; in cw1200_bh()
444 } else if (priv->hw_bufs_used) { in cw1200_bh()
452 if ((priv->hw_type != -1) && in cw1200_bh()
453 (atomic_read(&priv->bh_rx) == 0) && in cw1200_bh()
454 (atomic_read(&priv->bh_tx) == 0)) in cw1200_bh()
455 cw1200_reg_read(priv, ST90TDS_CONFIG_REG_ID, in cw1200_bh()
459 status = wait_event_interruptible_timeout(priv->bh_wq, ({ in cw1200_bh()
460 rx = atomic_xchg(&priv->bh_rx, 0); in cw1200_bh()
461 tx = atomic_xchg(&priv->bh_tx, 0); in cw1200_bh()
462 term = atomic_xchg(&priv->bh_term, 0); in cw1200_bh()
464 0 : atomic_read(&priv->bh_suspend); in cw1200_bh()
465 (rx || tx || term || suspend || priv->bh_error); in cw1200_bh()
469 rx, tx, term, suspend, priv->bh_error, status); in cw1200_bh()
473 term || priv->bh_error) { in cw1200_bh()
483 if (priv->hw_bufs_used && (!rx || !tx)) { in cw1200_bh()
484 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
486 priv->hw_bufs_used); in cw1200_bh()
492 &priv->tx_queue[i], in cw1200_bh()
494 priv->pending_frame_id); in cw1200_bh()
507 wiphy_warn(priv->hw->wiphy, in cw1200_bh()
509 priv->hw_bufs_used, pending, in cw1200_bh()
513 } else if (!priv->device_can_sleep && in cw1200_bh()
514 !atomic_read(&priv->recent_scan)) { in cw1200_bh()
516 cw1200_reg_write_16(priv, in cw1200_bh()
518 priv->device_can_sleep = true; in cw1200_bh()
523 if (priv->powersave_enabled) { in cw1200_bh()
525 cw1200_reg_write_16(priv, in cw1200_bh()
527 priv->device_can_sleep = true; in cw1200_bh()
530 atomic_set(&priv->bh_suspend, CW1200_BH_SUSPENDED); in cw1200_bh()
531 wake_up(&priv->bh_evt_wq); in cw1200_bh()
532 status = wait_event_interruptible(priv->bh_wq, in cw1200_bh()
533 CW1200_BH_RESUME == atomic_read(&priv->bh_suspend)); in cw1200_bh()
535 wiphy_err(priv->hw->wiphy, in cw1200_bh()
541 atomic_set(&priv->bh_suspend, CW1200_BH_RESUMED); in cw1200_bh()
542 wake_up(&priv->bh_evt_wq); in cw1200_bh()
543 atomic_add(1, &priv->bh_rx); in cw1200_bh()
551 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
556 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
561 ret = cw1200_bh_rx_helper(priv, &ctrl_reg, &tx); in cw1200_bh()
571 BUG_ON(priv->hw_bufs_used > priv->wsm_caps.input_buffers); in cw1200_bh()
572 tx_burst = priv->wsm_caps.input_buffers - priv->hw_bufs_used; in cw1200_bh()
582 ret = cw1200_bh_tx_helper(priv, &pending_tx, &tx_burst); in cw1200_bh()
589 if (cw1200_bh_read_ctrl_reg(priv, &ctrl_reg)) in cw1200_bh()
594 if (priv->bh_error) in cw1200_bh()
603 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
604 __cw1200_irq_enable(priv, 1); in cw1200_bh()
605 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
609 priv->hwbus_ops->lock(priv->hwbus_priv); in cw1200_bh()
610 __cw1200_irq_enable(priv, 0); in cw1200_bh()
611 priv->hwbus_ops->unlock(priv->hwbus_priv); in cw1200_bh()
615 priv->bh_error = 1; in cw1200_bh()