Lines Matching refs:target

28 static void ath6kl_htc_mbox_cleanup(struct htc_target *target);
29 static void ath6kl_htc_mbox_stop(struct htc_target *target);
30 static int ath6kl_htc_mbox_add_rxbuf_multiple(struct htc_target *target,
32 static void ath6kl_htc_set_credit_dist(struct htc_target *target,
375 static void htc_reclaim_txctrl_buf(struct htc_target *target,
378 spin_lock_bh(&target->htc_lock);
379 list_add_tail(&pkt->list, &target->free_ctrl_txbuf);
380 spin_unlock_bh(&target->htc_lock);
383 static struct htc_packet *htc_get_control_buf(struct htc_target *target,
389 buf_list = tx ? &target->free_ctrl_txbuf : &target->free_ctrl_rxbuf;
391 spin_lock_bh(&target->htc_lock);
394 spin_unlock_bh(&target->htc_lock);
400 spin_unlock_bh(&target->htc_lock);
408 static void htc_tx_comp_update(struct htc_target *target,
423 spin_lock_bh(&target->tx_lock);
429 target->credit_info, &target->cred_dist_list);
431 ath6kl_credit_distribute(target->credit_info,
432 &target->cred_dist_list,
435 spin_unlock_bh(&target->tx_lock);
448 ath6kl_tx_complete(endpoint->target, txq);
451 static void htc_tx_comp_handler(struct htc_target *target,
454 struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
460 htc_tx_comp_update(target, endpoint, packet);
467 static void htc_async_tx_scat_complete(struct htc_target *target,
485 endpoint = &target->endpoint[packet->endpoint];
496 htc_tx_comp_update(target, endpoint, packet);
501 hif_scatter_req_add(target->dev->ar, scat_req);
507 static int ath6kl_htc_tx_issue(struct htc_target *target,
519 padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
524 target->dev->ar->mbox_info.htc_addr,
528 status = hif_read_write_sync(target->dev->ar,
529 target->dev->ar->mbox_info.htc_addr,
536 status = hif_write_async(target->dev->ar,
537 target->dev->ar->mbox_info.htc_addr,
546 static int htc_check_credits(struct htc_target *target,
551 *req_cred = (len > target->tgt_cred_sz) ?
552 DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
564 ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
584 ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
588 /* tell the target we need credits ASAP! */
599 static void ath6kl_htc_tx_pkts_get(struct htc_target *target,
620 len = CALC_TXRX_PADDED_LEN(target,
623 if (htc_check_credits(target, endpoint, &flags,
637 packet->context = target;
679 static int ath6kl_htc_tx_setup_scat_list(struct htc_target *target,
690 rem_scat = target->max_tx_bndl_sz;
699 len = CALC_TXRX_PADDED_LEN(target,
702 cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
759 struct htc_target *target = endpoint->target;
769 ac = target->dev->ar->ep2ac_map[endpoint->eid];
774 n_scat = min(n_scat, target->msg_per_bndl_max);
780 scat_req = hif_scatter_req_get(target->dev->ar);
810 target->tx_bndl_mask &= ~txb_mask;
812 target->tx_bndl_mask |= txb_mask;
821 status = ath6kl_htc_tx_setup_scat_list(target, endpoint,
825 hif_scatter_req_add(target->dev->ar, scat_req);
844 ath6kl_hif_submit_scat_req(target->dev, scat_req, false);
858 static void ath6kl_htc_tx_from_queue(struct htc_target *target,
868 spin_lock_bh(&target->tx_lock);
873 spin_unlock_bh(&target->tx_lock);
886 ac = target->dev->ar->ep2ac_map[endpoint->eid];
892 ath6kl_htc_tx_pkts_get(target, endpoint, &txq);
897 spin_unlock_bh(&target->tx_lock);
904 if ((target->tx_bndl_mask) &&
910 if (target->tx_bndl_mask & (1 << ac)) {
927 status = ath6kl_htc_tx_issue(target, packet);
935 spin_lock_bh(&target->tx_lock);
946 if (!(target->tx_bndl_mask & (1 << ac)) &&
948 if (++target->ac_tx_count[ac] >=
950 target->ac_tx_count[ac] = 0;
951 target->tx_bndl_mask |= (1 << ac);
957 target->ac_tx_count[ac] = 0;
962 spin_unlock_bh(&target->tx_lock);
965 static bool ath6kl_htc_tx_try(struct htc_target *target,
975 spin_lock_bh(&target->tx_lock);
977 spin_unlock_bh(&target->tx_lock);
989 if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
996 spin_lock_bh(&target->tx_lock);
998 spin_unlock_bh(&target->tx_lock);
1000 ath6kl_htc_tx_from_queue(target, endpoint);
1005 static void htc_chk_ep_txq(struct htc_target *target)
1016 list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
1019 spin_lock_bh(&target->tx_lock);
1026 spin_unlock_bh(&target->tx_lock);
1034 ath6kl_htc_tx_from_queue(target, endpoint);
1035 spin_lock_bh(&target->tx_lock);
1037 spin_unlock_bh(&target->tx_lock);
1041 static int htc_setup_tx_complete(struct htc_target *target)
1046 send_pkt = htc_get_control_buf(target, true);
1051 if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
1061 if (target->msg_per_bndl_max > 0) {
1062 /* Indicate HTC bundling to the target */
1065 target->msg_per_bndl_max;
1087 status = ath6kl_htc_tx_issue(target, send_pkt);
1088 htc_reclaim_txctrl_buf(target, send_pkt);
1093 static void ath6kl_htc_set_credit_dist(struct htc_target *target,
1100 target->credit_info = credit_info;
1102 list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
1103 &target->cred_dist_list);
1107 endpoint = &target->endpoint[ep];
1110 &target->cred_dist_list);
1121 static int ath6kl_htc_mbox_tx(struct htc_target *target,
1136 endpoint = &target->endpoint[packet->endpoint];
1138 if (!ath6kl_htc_tx_try(target, endpoint, packet)) {
1139 packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
1150 static void ath6kl_htc_mbox_flush_txep(struct htc_target *target,
1155 struct htc_endpoint *endpoint = &target->endpoint[eid];
1165 spin_lock_bh(&target->tx_lock);
1173 spin_unlock_bh(&target->tx_lock);
1189 static void ath6kl_htc_flush_txep_all(struct htc_target *target)
1194 dump_cred_dist_stats(target);
1197 endpoint = &target->endpoint[i];
1201 ath6kl_htc_mbox_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
1205 static void ath6kl_htc_mbox_activity_changed(struct htc_target *target,
1209 struct htc_endpoint *endpoint = &target->endpoint[eid];
1217 spin_lock_bh(&target->tx_lock);
1237 target->credit_info, &target->cred_dist_list);
1239 ath6kl_credit_distribute(target->credit_info,
1240 &target->cred_dist_list,
1244 spin_unlock_bh(&target->tx_lock);
1247 htc_chk_ep_txq(target);
1262 static inline bool htc_valid_rx_frame_len(struct htc_target *target,
1265 return (eid == target->dev->ar->ctrl_ep) ?
1269 static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
1275 return ath6kl_htc_mbox_add_rxbuf_multiple(target, &queue);
1278 static void htc_reclaim_rxbuf(struct htc_target *target,
1285 ep->ep_cb.rx(ep->target, packet);
1288 htc_add_rxbuf((void *)(target), packet);
1292 static void reclaim_rx_ctrl_buf(struct htc_target *target,
1295 spin_lock_bh(&target->htc_lock);
1296 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
1297 spin_unlock_bh(&target->htc_lock);
1300 static int ath6kl_htc_rx_packet(struct htc_target *target,
1304 struct ath6kl_device *dev = target->dev;
1308 padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
1354 spin_lock_bh(&endpoint->target->rx_lock);
1357 spin_unlock_bh(&endpoint->target->rx_lock);
1358 ep_cb.rx_refill(endpoint->target, endpoint->eid);
1361 spin_unlock_bh(&endpoint->target->rx_lock);
1366 static int ath6kl_htc_rx_setup(struct htc_target *target,
1377 full_len = CALC_TXRX_PADDED_LEN(target,
1381 if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
1403 spin_unlock_bh(&target->rx_lock);
1406 packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
1408 spin_lock_bh(&target->rx_lock);
1413 spin_unlock_bh(&target->rx_lock);
1414 ep_cb.rx_refill(ep->target, ep->eid);
1415 spin_lock_bh(&target->rx_lock);
1429 target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
1430 target->ep_waiting = ep->eid;
1450 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
1469 static int ath6kl_htc_rx_alloc(struct htc_target *target,
1479 spin_lock_bh(&target->rx_lock);
1523 if (n_msg > target->msg_per_bndl_max) {
1537 status = ath6kl_htc_rx_setup(target, endpoint, &lk_ahds[i],
1546 spin_unlock_bh(&target->rx_lock);
1554 spin_unlock_bh(&target->rx_lock);
1559 htc_reclaim_rxbuf(target, packet,
1560 &target->endpoint[packet->endpoint]);
1592 static void htc_proc_cred_rpt(struct htc_target *target,
1601 spin_lock_bh(&target->tx_lock);
1606 spin_unlock_bh(&target->tx_lock);
1610 endpoint = &target->endpoint[rpt->eid];
1659 ath6kl_credit_distribute(target->credit_info,
1660 &target->cred_dist_list,
1664 spin_unlock_bh(&target->tx_lock);
1667 htc_chk_ep_txq(target);
1670 static int htc_parse_trailer(struct htc_target *target,
1688 htc_proc_cred_rpt(target,
1750 static int htc_proc_trailer(struct htc_target *target,
1785 status = htc_parse_trailer(target, record, record_buf,
1803 static int ath6kl_htc_rx_process_hdr(struct htc_target *target,
1878 status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
1907 endpoint->ep_cb.rx(endpoint->target, packet);
1910 static int ath6kl_htc_rx_bundle(struct htc_target *target,
1917 int rem_space = target->max_rx_bndl_sz;
1921 n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
1932 * This would only happen if the target ignored our max
1945 scat_req = hif_scatter_req_get(target->dev->ar);
1956 pad_len = CALC_TXRX_PADDED_LEN(target,
1990 status = ath6kl_hif_submit_scat_req(target->dev, scat_req, true);
1996 hif_scatter_req_add(target->dev->ar, scat_req);
2003 static int ath6kl_htc_rx_process_packets(struct htc_target *target,
2013 ep = &target->endpoint[packet->endpoint];
2019 status = ath6kl_htc_rx_process_hdr(target, packet, lk_ahds,
2053 static int ath6kl_htc_rx_fetch(struct htc_target *target,
2069 if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
2075 status = ath6kl_htc_rx_bundle(target, rx_pktq,
2105 status = ath6kl_htc_rx_packet(target, packet,
2128 htc_reclaim_rxbuf(target, packet,
2129 &target->endpoint[packet->endpoint]);
2134 htc_reclaim_rxbuf(target, packet,
2135 &target->endpoint[packet->endpoint]);
2141 int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
2168 endpoint = &target->endpoint[id];
2184 status = ath6kl_htc_rx_alloc(target, look_aheads,
2195 target->chk_irq_status_cnt = 1;
2201 status = ath6kl_htc_rx_fetch(target, &rx_pktq, &comp_pktq);
2207 status = ath6kl_htc_rx_process_packets(target, &comp_pktq,
2221 target->chk_irq_status_cnt = 1;
2232 htc_reclaim_rxbuf(target, packets,
2233 &target->endpoint[packets->endpoint]);
2236 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
2238 ath6kl_hif_rx_control(target->dev, false);
2246 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
2248 ath6kl_hif_rx_control(target->dev, false);
2256 * Synchronously wait for a control message from the target,
2260 static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
2265 if (ath6kl_hif_poll_mboxmsg_rx(target->dev, &look_ahead.word,
2275 packet = htc_get_control_buf(target, false);
2291 if (ath6kl_htc_rx_packet(target, packet, packet->act_len))
2298 packet->status = ath6kl_htc_rx_process_hdr(target, packet, NULL, NULL);
2311 reclaim_rx_ctrl_buf(target, packet);
2317 static int ath6kl_htc_mbox_add_rxbuf_multiple(struct htc_target *target,
2339 endpoint = &target->endpoint[first_pkt->endpoint];
2341 if (target->htc_flags & HTC_OP_STATE_STOPPING) {
2354 spin_lock_bh(&target->rx_lock);
2359 if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
2360 if (target->ep_waiting == first_pkt->endpoint) {
2363 target->ep_waiting);
2364 target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
2365 target->ep_waiting = ENDPOINT_MAX;
2370 spin_unlock_bh(&target->rx_lock);
2372 if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
2374 ath6kl_hif_rx_control(target->dev, true);
2379 static void ath6kl_htc_mbox_flush_rx_buf(struct htc_target *target)
2386 endpoint = &target->endpoint[i];
2391 spin_lock_bh(&target->rx_lock);
2395 spin_unlock_bh(&target->rx_lock);
2402 * been queued from target->free_ctrl_rxbuf where
2415 spin_lock_bh(&target->rx_lock);
2417 spin_unlock_bh(&target->rx_lock);
2421 static int ath6kl_htc_mbox_conn_service(struct htc_target *target,
2436 "htc connect service target 0x%p service id 0x%x\n",
2437 target, conn_req->svc_id);
2444 /* allocate a packet to send to the target */
2445 tx_pkt = htc_get_control_buf(target, true);
2463 status = ath6kl_htc_tx_issue(target, tx_pkt);
2469 rx_pkt = htc_wait_for_ctrl_msg(target);
2488 ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
2504 endpoint = &target->endpoint[assigned_ep];
2526 endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
2548 conn_req->max_rxmsg_sz / target->tgt_cred_sz;
2551 max_msg_sz / target->tgt_cred_sz;
2561 htc_reclaim_txctrl_buf(target, tx_pkt);
2565 reclaim_rx_ctrl_buf(target, rx_pkt);
2571 static void reset_ep_state(struct htc_target *target)
2577 endpoint = &target->endpoint[i];
2586 endpoint->target = target;
2591 INIT_LIST_HEAD(&target->cred_dist_list);
2594 static int ath6kl_htc_mbox_get_rxbuf_num(struct htc_target *target,
2599 spin_lock_bh(&target->rx_lock);
2600 num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
2601 spin_unlock_bh(&target->rx_lock);
2605 static void htc_setup_msg_bndl(struct htc_target *target)
2608 target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
2609 target->msg_per_bndl_max);
2611 if (ath6kl_hif_enable_scatter(target->dev->ar)) {
2612 target->msg_per_bndl_max = 0;
2617 target->msg_per_bndl_max = min(target->max_scat_entries,
2618 target->msg_per_bndl_max);
2622 target->msg_per_bndl_max);
2625 target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
2627 target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
2628 target->max_xfer_szper_scatreq);
2631 target->max_rx_bndl_sz, target->max_tx_bndl_sz);
2633 if (target->max_tx_bndl_sz)
2635 target->tx_bndl_mask = (1 << WMM_NUM_AC) - 1;
2637 if (target->max_rx_bndl_sz)
2638 target->rx_bndl_enable = true;
2640 if ((target->tgt_cred_sz % target->block_sz) != 0) {
2642 target->tgt_cred_sz);
2650 target->tx_bndl_mask = 0;
2654 static int ath6kl_htc_mbox_wait_target(struct htc_target *target)
2662 /* we should be getting 1 control message that the target is ready */
2663 packet = htc_wait_for_ctrl_msg(target);
2682 target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
2683 target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
2686 "htc target ready credits %d size %d\n",
2687 target->tgt_creds, target->tgt_cred_sz);
2692 target->htc_tgt_ver = rdy_msg->htc_ver;
2693 target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
2696 target->htc_tgt_ver = HTC_VERSION_2P0;
2697 target->msg_per_bndl_max = 0;
2701 (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
2702 target->htc_tgt_ver);
2704 if (target->msg_per_bndl_max > 0)
2705 htc_setup_msg_bndl(target);
2717 status = ath6kl_htc_mbox_conn_service((void *)target, &connect, &resp);
2724 ath6kl_hif_cleanup_scatter(target->dev->ar);
2729 reclaim_rx_ctrl_buf(target, packet);
2736 * Start HTC, enable interrupts and let the target know
2739 static int ath6kl_htc_mbox_start(struct htc_target *target)
2744 memset(&target->dev->irq_proc_reg, 0,
2745 sizeof(target->dev->irq_proc_reg));
2748 ath6kl_hif_disable_intrs(target->dev);
2750 target->htc_flags = 0;
2751 target->rx_st_flags = 0;
2754 while ((packet = htc_get_control_buf(target, false)) != NULL) {
2755 status = htc_add_rxbuf(target, packet);
2761 ath6kl_credit_init(target->credit_info, &target->cred_dist_list,
2762 target->tgt_creds);
2764 dump_cred_dist_stats(target);
2766 /* Indicate to the target of the setup completion */
2767 status = htc_setup_tx_complete(target);
2773 status = ath6kl_hif_unmask_intrs(target->dev);
2776 ath6kl_htc_mbox_stop(target);
2781 static int ath6kl_htc_reset(struct htc_target *target)
2787 reset_ep_state(target);
2789 block_size = target->dev->ar->mbox_info.block_size;
2811 list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
2813 list_add_tail(&packet->list, &target->free_ctrl_txbuf);
2821 static void ath6kl_htc_mbox_stop(struct htc_target *target)
2823 spin_lock_bh(&target->htc_lock);
2824 target->htc_flags |= HTC_OP_STATE_STOPPING;
2825 spin_unlock_bh(&target->htc_lock);
2832 ath6kl_hif_mask_intrs(target->dev);
2834 ath6kl_htc_flush_txep_all(target);
2836 ath6kl_htc_mbox_flush_rx_buf(target);
2838 ath6kl_htc_reset(target);
2843 struct htc_target *target = NULL;
2846 target = kzalloc(sizeof(*target), GFP_KERNEL);
2847 if (!target) {
2852 target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
2853 if (!target->dev) {
2855 kfree(target);
2859 spin_lock_init(&target->htc_lock);
2860 spin_lock_init(&target->rx_lock);
2861 spin_lock_init(&target->tx_lock);
2863 INIT_LIST_HEAD(&target->free_ctrl_txbuf);
2864 INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
2865 INIT_LIST_HEAD(&target->cred_dist_list);
2867 target->dev->ar = ar;
2868 target->dev->htc_cnxt = target;
2869 target->ep_waiting = ENDPOINT_MAX;
2871 status = ath6kl_hif_setup(target->dev);
2875 status = ath6kl_htc_reset(target);
2879 return target;
2882 ath6kl_htc_mbox_cleanup(target);
2888 static void ath6kl_htc_mbox_cleanup(struct htc_target *target)
2892 ath6kl_hif_cleanup_scatter(target->dev->ar);
2895 &target->free_ctrl_txbuf, list) {
2902 &target->free_ctrl_rxbuf, list) {
2908 kfree(target->dev);
2909 kfree(target);