Lines Matching refs:nn
54 static u32 nfp_ccm_mbox_max_msg(struct nfp_net *nn) in nfp_ccm_mbox_max_msg() argument
56 return round_down(nn->tlv_caps.mbox_len, 4) - in nfp_ccm_mbox_max_msg()
116 static bool nfp_ccm_mbox_is_first(struct nfp_net *nn, struct sk_buff *skb) in nfp_ccm_mbox_is_first() argument
118 return skb_queue_is_first(&nn->mbox_cmsg.queue, skb); in nfp_ccm_mbox_is_first()
121 static bool nfp_ccm_mbox_should_run(struct nfp_net *nn, struct sk_buff *skb) in nfp_ccm_mbox_should_run() argument
128 static void nfp_ccm_mbox_mark_next_runner(struct nfp_net *nn) in nfp_ccm_mbox_mark_next_runner() argument
133 skb = skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_mark_next_runner()
140 queue_work(nn->mbox_cmsg.workq, &nn->mbox_cmsg.runq_work); in nfp_ccm_mbox_mark_next_runner()
144 nfp_ccm_mbox_write_tlv(struct nfp_net *nn, u32 off, u32 type, u32 len) in nfp_ccm_mbox_write_tlv() argument
146 nn_writel(nn, off, in nfp_ccm_mbox_write_tlv()
151 static void nfp_ccm_mbox_copy_in(struct nfp_net *nn, struct sk_buff *last) in nfp_ccm_mbox_copy_in() argument
158 off = nn->tlv_caps.mbox_off + NFP_NET_CFG_MBOX_SIMPLE_VAL; in nfp_ccm_mbox_copy_in()
159 skb = __skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_copy_in()
161 nfp_ccm_mbox_write_tlv(nn, off, NFP_NET_MBOX_TLV_TYPE_MSG, in nfp_ccm_mbox_copy_in()
169 nn_writel(nn, off, be32_to_cpu(data[i])); in nfp_ccm_mbox_copy_in()
176 nn_writel(nn, off, be32_to_cpu(tmp)); in nfp_ccm_mbox_copy_in()
184 nfp_ccm_mbox_write_tlv(nn, off, in nfp_ccm_mbox_copy_in()
192 skb = skb_queue_next(&nn->mbox_cmsg.queue, skb); in nfp_ccm_mbox_copy_in()
195 nfp_ccm_mbox_write_tlv(nn, off, NFP_NET_MBOX_TLV_TYPE_END, 0); in nfp_ccm_mbox_copy_in()
199 nfp_ccm_mbox_find_req(struct nfp_net *nn, __be16 tag, struct sk_buff *last) in nfp_ccm_mbox_find_req() argument
203 skb = __skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_find_req()
210 skb = skb_queue_next(&nn->mbox_cmsg.queue, skb); in nfp_ccm_mbox_find_req()
214 static void nfp_ccm_mbox_copy_out(struct nfp_net *nn, struct sk_buff *last) in nfp_ccm_mbox_copy_out() argument
220 data = nn->dp.ctrl_bar + nn->tlv_caps.mbox_off + in nfp_ccm_mbox_copy_out()
222 end = data + nn->tlv_caps.mbox_len; in nfp_ccm_mbox_copy_out()
232 offset = data - nn->dp.ctrl_bar; in nfp_ccm_mbox_copy_out()
238 nn_dp_warn(&nn->dp, "mailbox oversized TLV type:%d offset:%u len:%u\n", in nfp_ccm_mbox_copy_out()
249 nn_dp_warn(&nn->dp, "mailbox unknown TLV type:%d offset:%u len:%u\n", in nfp_ccm_mbox_copy_out()
255 nn_dp_warn(&nn->dp, "mailbox msg too short to contain header TLV type:%d offset:%u len:%u\n", in nfp_ccm_mbox_copy_out()
262 skb = nfp_ccm_mbox_find_req(nn, hdr.tag, last); in nfp_ccm_mbox_copy_out()
264 nn_dp_warn(&nn->dp, "mailbox request not found:%u\n", in nfp_ccm_mbox_copy_out()
271 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_copy_out()
279 nn_dp_warn(&nn->dp, "mailbox msg reply wrong type:%u expected:%lu\n", in nfp_ccm_mbox_copy_out()
286 nn_dp_warn(&nn->dp, "mailbox msg reply wrong size type:%u expected:%u have:%u\n", in nfp_ccm_mbox_copy_out()
292 nn_dp_warn(&nn->dp, "mailbox msg oversized reply type:%u max:%u have:%u\n", in nfp_ccm_mbox_copy_out()
323 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_copy_out()
330 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_copy_out()
332 skb = __skb_dequeue(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_copy_out()
343 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_copy_out()
350 nfp_ccm_mbox_mark_next_runner(nn); in nfp_ccm_mbox_copy_out()
351 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_copy_out()
355 nfp_ccm_mbox_mark_all_err(struct nfp_net *nn, struct sk_buff *last, int err) in nfp_ccm_mbox_mark_all_err() argument
360 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_mark_all_err()
362 skb = __skb_dequeue(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_mark_all_err()
370 nfp_ccm_mbox_mark_next_runner(nn); in nfp_ccm_mbox_mark_all_err()
371 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_mark_all_err()
374 static void nfp_ccm_mbox_run_queue_unlock(struct nfp_net *nn) in nfp_ccm_mbox_run_queue_unlock() argument
375 __releases(&nn->mbox_cmsg.queue.lock) in nfp_ccm_mbox_run_queue_unlock()
377 int space = nn->tlv_caps.mbox_len - NFP_NET_CFG_MBOX_SIMPLE_VAL; in nfp_ccm_mbox_run_queue_unlock()
385 last = skb = __skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_run_queue_unlock()
388 while (!skb_queue_is_last(&nn->mbox_cmsg.queue, last)) { in nfp_ccm_mbox_run_queue_unlock()
389 skb = skb_queue_next(&nn->mbox_cmsg.queue, last); in nfp_ccm_mbox_run_queue_unlock()
399 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_run_queue_unlock()
405 nn_ctrl_bar_lock(nn); in nfp_ccm_mbox_run_queue_unlock()
407 nfp_ccm_mbox_copy_in(nn, last); in nfp_ccm_mbox_run_queue_unlock()
409 err = nfp_net_mbox_reconfig(nn, NFP_NET_CFG_MBOX_CMD_TLV_CMSG); in nfp_ccm_mbox_run_queue_unlock()
411 nfp_ccm_mbox_copy_out(nn, last); in nfp_ccm_mbox_run_queue_unlock()
413 nfp_ccm_mbox_mark_all_err(nn, last, -EIO); in nfp_ccm_mbox_run_queue_unlock()
415 nn_ctrl_bar_unlock(nn); in nfp_ccm_mbox_run_queue_unlock()
417 wake_up_all(&nn->mbox_cmsg.wq); in nfp_ccm_mbox_run_queue_unlock()
434 nfp_ccm_mbox_unlink_unlock(struct nfp_net *nn, struct sk_buff *skb, in nfp_ccm_mbox_unlink_unlock() argument
436 __releases(&nn->mbox_cmsg.queue.lock) in nfp_ccm_mbox_unlink_unlock()
441 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_unlink_unlock()
443 wait_event(nn->mbox_cmsg.wq, nfp_ccm_mbox_done(skb)); in nfp_ccm_mbox_unlink_unlock()
448 was_first = nfp_ccm_mbox_should_run(nn, skb); in nfp_ccm_mbox_unlink_unlock()
449 __skb_unlink(skb, &nn->mbox_cmsg.queue); in nfp_ccm_mbox_unlink_unlock()
451 nfp_ccm_mbox_mark_next_runner(nn); in nfp_ccm_mbox_unlink_unlock()
453 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_unlink_unlock()
456 wake_up_all(&nn->mbox_cmsg.wq); in nfp_ccm_mbox_unlink_unlock()
458 nn_dp_warn(&nn->dp, "time out waiting for mbox response to 0x%02x\n", in nfp_ccm_mbox_unlink_unlock()
464 nfp_ccm_mbox_msg_prepare(struct nfp_net *nn, struct sk_buff *skb, in nfp_ccm_mbox_msg_prepare() argument
469 const unsigned int mbox_max = nfp_ccm_mbox_max_msg(nn); in nfp_ccm_mbox_msg_prepare()
474 if (unlikely(!(nn->tlv_caps.mbox_cmsg_types & BIT(type)))) { in nfp_ccm_mbox_msg_prepare()
475 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_msg_prepare()
496 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_msg_prepare()
505 nn_dp_warn(&nn->dp, in nfp_ccm_mbox_msg_prepare()
517 nfp_ccm_mbox_msg_enqueue(struct nfp_net *nn, struct sk_buff *skb, in nfp_ccm_mbox_msg_enqueue() argument
522 assert_spin_locked(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_msg_enqueue()
524 if (!critical && nn->mbox_cmsg.queue.qlen >= NFP_CCM_MAX_QLEN) { in nfp_ccm_mbox_msg_enqueue()
525 nn_dp_warn(&nn->dp, "mailbox request queue too long\n"); in nfp_ccm_mbox_msg_enqueue()
532 hdr->tag = cpu_to_be16(nn->mbox_cmsg.tag++); in nfp_ccm_mbox_msg_enqueue()
534 __skb_queue_tail(&nn->mbox_cmsg.queue, skb); in nfp_ccm_mbox_msg_enqueue()
539 int __nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb, in __nfp_ccm_mbox_communicate() argument
546 err = nfp_ccm_mbox_msg_prepare(nn, skb, type, reply_size, in __nfp_ccm_mbox_communicate()
551 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in __nfp_ccm_mbox_communicate()
553 err = nfp_ccm_mbox_msg_enqueue(nn, skb, type, critical); in __nfp_ccm_mbox_communicate()
558 if (!nfp_ccm_mbox_is_first(nn, skb)) { in __nfp_ccm_mbox_communicate()
561 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in __nfp_ccm_mbox_communicate()
563 to = !wait_event_timeout(nn->mbox_cmsg.wq, in __nfp_ccm_mbox_communicate()
565 nfp_ccm_mbox_should_run(nn, skb), in __nfp_ccm_mbox_communicate()
574 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in __nfp_ccm_mbox_communicate()
576 if (!nfp_ccm_mbox_is_first(nn, skb)) { in __nfp_ccm_mbox_communicate()
579 err = nfp_ccm_mbox_unlink_unlock(nn, skb, type); in __nfp_ccm_mbox_communicate()
587 nfp_ccm_mbox_run_queue_unlock(nn); in __nfp_ccm_mbox_communicate()
591 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in __nfp_ccm_mbox_communicate()
597 int nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb, in nfp_ccm_mbox_communicate() argument
602 return __nfp_ccm_mbox_communicate(nn, skb, type, reply_size, in nfp_ccm_mbox_communicate()
609 struct nfp_net *nn; in nfp_ccm_mbox_post_runq_work() local
611 nn = container_of(work, struct nfp_net, mbox_cmsg.runq_work); in nfp_ccm_mbox_post_runq_work()
613 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_post_runq_work()
615 skb = __skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_post_runq_work()
617 !nfp_ccm_mbox_should_run(nn, skb))) { in nfp_ccm_mbox_post_runq_work()
618 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_post_runq_work()
622 nfp_ccm_mbox_run_queue_unlock(nn); in nfp_ccm_mbox_post_runq_work()
628 struct nfp_net *nn; in nfp_ccm_mbox_post_wait_work() local
631 nn = container_of(work, struct nfp_net, mbox_cmsg.wait_work); in nfp_ccm_mbox_post_wait_work()
633 skb = skb_peek(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_post_wait_work()
638 err = nfp_net_mbox_reconfig_wait_posted(nn); in nfp_ccm_mbox_post_wait_work()
640 nfp_ccm_mbox_copy_out(nn, skb); in nfp_ccm_mbox_post_wait_work()
642 nfp_ccm_mbox_mark_all_err(nn, skb, -EIO); in nfp_ccm_mbox_post_wait_work()
644 nn_ctrl_bar_unlock(nn); in nfp_ccm_mbox_post_wait_work()
645 wake_up_all(&nn->mbox_cmsg.wq); in nfp_ccm_mbox_post_wait_work()
648 int nfp_ccm_mbox_post(struct nfp_net *nn, struct sk_buff *skb, in nfp_ccm_mbox_post() argument
653 err = nfp_ccm_mbox_msg_prepare(nn, skb, type, 0, max_reply_size, in nfp_ccm_mbox_post()
660 spin_lock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_post()
662 err = nfp_ccm_mbox_msg_enqueue(nn, skb, type, false); in nfp_ccm_mbox_post()
666 if (nfp_ccm_mbox_is_first(nn, skb)) { in nfp_ccm_mbox_post()
667 if (nn_ctrl_bar_trylock(nn)) { in nfp_ccm_mbox_post()
668 nfp_ccm_mbox_copy_in(nn, skb); in nfp_ccm_mbox_post()
669 nfp_net_mbox_reconfig_post(nn, in nfp_ccm_mbox_post()
671 queue_work(nn->mbox_cmsg.workq, in nfp_ccm_mbox_post()
672 &nn->mbox_cmsg.wait_work); in nfp_ccm_mbox_post()
674 nfp_ccm_mbox_mark_next_runner(nn); in nfp_ccm_mbox_post()
678 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_post()
683 spin_unlock_bh(&nn->mbox_cmsg.queue.lock); in nfp_ccm_mbox_post()
690 nfp_ccm_mbox_msg_alloc(struct nfp_net *nn, unsigned int req_size, in nfp_ccm_mbox_msg_alloc() argument
697 max_size = nfp_ccm_mbox_max_msg(nn); in nfp_ccm_mbox_msg_alloc()
711 bool nfp_ccm_mbox_fits(struct nfp_net *nn, unsigned int size) in nfp_ccm_mbox_fits() argument
713 return nfp_ccm_mbox_max_msg(nn) >= size; in nfp_ccm_mbox_fits()
716 int nfp_ccm_mbox_init(struct nfp_net *nn) in nfp_ccm_mbox_init() argument
721 void nfp_ccm_mbox_clean(struct nfp_net *nn) in nfp_ccm_mbox_clean() argument
723 drain_workqueue(nn->mbox_cmsg.workq); in nfp_ccm_mbox_clean()
726 int nfp_ccm_mbox_alloc(struct nfp_net *nn) in nfp_ccm_mbox_alloc() argument
728 skb_queue_head_init(&nn->mbox_cmsg.queue); in nfp_ccm_mbox_alloc()
729 init_waitqueue_head(&nn->mbox_cmsg.wq); in nfp_ccm_mbox_alloc()
730 INIT_WORK(&nn->mbox_cmsg.wait_work, nfp_ccm_mbox_post_wait_work); in nfp_ccm_mbox_alloc()
731 INIT_WORK(&nn->mbox_cmsg.runq_work, nfp_ccm_mbox_post_runq_work); in nfp_ccm_mbox_alloc()
733 nn->mbox_cmsg.workq = alloc_workqueue("nfp-ccm-mbox", WQ_UNBOUND, 0); in nfp_ccm_mbox_alloc()
734 if (!nn->mbox_cmsg.workq) in nfp_ccm_mbox_alloc()
739 void nfp_ccm_mbox_free(struct nfp_net *nn) in nfp_ccm_mbox_free() argument
741 destroy_workqueue(nn->mbox_cmsg.workq); in nfp_ccm_mbox_free()
742 WARN_ON(!skb_queue_empty(&nn->mbox_cmsg.queue)); in nfp_ccm_mbox_free()