0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef HTC_H
0019 #define HTC_H
0020
0021 #include "common.h"
0022
0023
0024
0025
0026 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
0027 #define HTC_FLAGS_SEND_BUNDLE (1 << 1)
0028 #define HTC_FLAGS_TX_FIXUP_NETBUF (1 << 2)
0029
0030
0031 #define HTC_FLG_RX_UNUSED (1 << 0)
0032 #define HTC_FLG_RX_TRAILER (1 << 1)
0033
0034 #define HTC_FLG_RX_BNDL_CNT (0xF0)
0035 #define HTC_FLG_RX_BNDL_CNT_S 4
0036
0037 #define HTC_HDR_LENGTH (sizeof(struct htc_frame_hdr))
0038 #define HTC_MAX_PAYLOAD_LENGTH (4096 - sizeof(struct htc_frame_hdr))
0039
0040
0041
0042 #define HTC_MSG_READY_ID 1
0043 #define HTC_MSG_CONN_SVC_ID 2
0044 #define HTC_MSG_CONN_SVC_RESP_ID 3
0045 #define HTC_MSG_SETUP_COMPLETE_ID 4
0046 #define HTC_MSG_SETUP_COMPLETE_EX_ID 5
0047
0048 #define HTC_MAX_CTRL_MSG_LEN 256
0049
0050 #define HTC_VERSION_2P0 0x00
0051 #define HTC_VERSION_2P1 0x01
0052
0053 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
0054
0055 #define HTC_CONN_FLGS_THRESH_LVL_QUAT 0x0
0056 #define HTC_CONN_FLGS_THRESH_LVL_HALF 0x1
0057 #define HTC_CONN_FLGS_THRESH_LVL_THREE_QUAT 0x2
0058 #define HTC_CONN_FLGS_REDUCE_CRED_DRIB 0x4
0059 #define HTC_CONN_FLGS_THRESH_MASK 0x3
0060
0061 #define HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL (1 << 3)
0062 #define HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT 8
0063 #define HTC_CONN_FLGS_SET_RECV_ALLOC_MASK 0xFF00U
0064
0065
0066 #define HTC_SERVICE_SUCCESS 0
0067 #define HTC_SERVICE_NOT_FOUND 1
0068 #define HTC_SERVICE_FAILED 2
0069
0070
0071 #define HTC_SERVICE_NO_RESOURCES 3
0072
0073
0074 #define HTC_SERVICE_NO_MORE_EP 4
0075
0076
0077 #define HTC_RECORD_NULL 0
0078 #define HTC_RECORD_CREDITS 1
0079 #define HTC_RECORD_LOOKAHEAD 2
0080 #define HTC_RECORD_LOOKAHEAD_BUNDLE 3
0081
0082 #define HTC_SETUP_COMP_FLG_RX_BNDL_EN (1 << 0)
0083 #define HTC_SETUP_COMP_FLG_DISABLE_TX_CREDIT_FLOW (1 << 1)
0084
0085 #define MAKE_SERVICE_ID(group, index) \
0086 (int)(((int)group << 8) | (int)(index))
0087
0088
0089 #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
0090 #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
0091 #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
0092 #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
0093 #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
0094 #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
0095 #define WMI_MAX_SERVICES 5
0096
0097 #define WMM_NUM_AC 4
0098
0099
0100 #define HTC_TX_PACKET_TAG_ALL 0
0101 #define HTC_SERVICE_TX_PACKET_TAG 1
0102 #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_SERVICE_TX_PACKET_TAG + 9)
0103
0104
0105 #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
0106
0107
0108 #define ENDPOINT1 0
0109
0110 #define HTC_MAILBOX_NUM_MAX 4
0111
0112
0113 #define HTC_FLGS_TX_BNDL_PAD_EN (1 << 0)
0114 #define HTC_EP_ACTIVE ((u32) (1u << 31))
0115
0116
0117 #define HTC_TARGET_RESPONSE_TIMEOUT 2000
0118 #define HTC_TARGET_RESPONSE_POLL_WAIT 10
0119 #define HTC_TARGET_RESPONSE_POLL_COUNT 200
0120 #define HTC_TARGET_DEBUG_INTR_MASK 0x01
0121 #define HTC_TARGET_CREDIT_INTR_MASK 0xF0
0122
0123 #define HTC_HOST_MAX_MSG_PER_BUNDLE 8
0124 #define HTC_MIN_HTC_MSGS_TO_BUNDLE 2
0125
0126
0127
0128 #define HTC_RX_PKT_IGNORE_LOOKAHEAD (1 << 0)
0129 #define HTC_RX_PKT_REFRESH_HDR (1 << 1)
0130 #define HTC_RX_PKT_PART_OF_BUNDLE (1 << 2)
0131 #define HTC_RX_PKT_NO_RECYCLE (1 << 3)
0132
0133 #define NUM_CONTROL_BUFFERS 8
0134 #define NUM_CONTROL_TX_BUFFERS 2
0135 #define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)
0136
0137 #define HTC_RECV_WAIT_BUFFERS (1 << 0)
0138 #define HTC_OP_STATE_STOPPING (1 << 0)
0139 #define HTC_OP_STATE_SETUP_COMPLETE (1 << 1)
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 struct htc_frame_hdr {
0156 struct_group_tagged(htc_frame_look_ahead, header,
0157 union {
0158 struct {
0159 u8 eid;
0160 u8 flags;
0161
0162
0163 __le16 payld_len;
0164
0165 };
0166 u32 word;
0167 };
0168 );
0169
0170
0171 u8 ctrl[2];
0172 } __packed;
0173
0174
0175 struct htc_ready_msg {
0176 __le16 msg_id;
0177 __le16 cred_cnt;
0178 __le16 cred_sz;
0179 u8 max_ep;
0180 u8 pad;
0181 } __packed;
0182
0183
0184 struct htc_ready_ext_msg {
0185 struct htc_ready_msg ver2_0_info;
0186 u8 htc_ver;
0187 u8 msg_per_htc_bndl;
0188 } __packed;
0189
0190
0191 struct htc_conn_service_msg {
0192 __le16 msg_id;
0193 __le16 svc_id;
0194 __le16 conn_flags;
0195 u8 svc_meta_len;
0196 u8 pad;
0197 } __packed;
0198
0199
0200 struct htc_conn_service_resp {
0201 __le16 msg_id;
0202 __le16 svc_id;
0203 u8 status;
0204 u8 eid;
0205 __le16 max_msg_sz;
0206 u8 svc_meta_len;
0207 u8 pad;
0208 } __packed;
0209
0210 struct htc_setup_comp_msg {
0211 __le16 msg_id;
0212 } __packed;
0213
0214
0215 struct htc_setup_comp_ext_msg {
0216 __le16 msg_id;
0217 __le32 flags;
0218 u8 msg_per_rxbndl;
0219 u8 Rsvd[3];
0220 } __packed;
0221
0222 struct htc_record_hdr {
0223 u8 rec_id;
0224 u8 len;
0225 } __packed;
0226
0227 struct htc_credit_report {
0228 u8 eid;
0229 u8 credits;
0230 } __packed;
0231
0232
0233
0234
0235
0236
0237 struct htc_lookahead_report {
0238 u8 pre_valid;
0239 u8 lk_ahd[4];
0240 u8 post_valid;
0241 } __packed;
0242
0243 struct htc_bundle_lkahd_rpt {
0244 u8 lk_ahd[4];
0245 } __packed;
0246
0247
0248
0249 enum htc_service_grp_ids {
0250 RSVD_SERVICE_GROUP = 0,
0251 WMI_SERVICE_GROUP = 1,
0252
0253 HTC_TEST_GROUP = 254,
0254 HTC_SERVICE_GROUP_LAST = 255
0255 };
0256
0257
0258
0259 enum htc_endpoint_id {
0260 ENDPOINT_UNUSED = -1,
0261 ENDPOINT_0 = 0,
0262 ENDPOINT_1 = 1,
0263 ENDPOINT_2 = 2,
0264 ENDPOINT_3,
0265 ENDPOINT_4,
0266 ENDPOINT_5,
0267 ENDPOINT_6,
0268 ENDPOINT_7,
0269 ENDPOINT_8,
0270 ENDPOINT_MAX,
0271 };
0272
0273 struct htc_tx_packet_info {
0274 u16 tag;
0275 int cred_used;
0276 u8 flags;
0277 int seqno;
0278 };
0279
0280 struct htc_rx_packet_info {
0281 u32 exp_hdr;
0282 u32 rx_flags;
0283 u32 indicat_flags;
0284 };
0285
0286 struct htc_target;
0287
0288
0289 struct htc_packet {
0290 struct list_head list;
0291
0292
0293 void *pkt_cntxt;
0294
0295
0296
0297
0298
0299
0300
0301
0302 u8 *buf_start;
0303
0304
0305
0306
0307
0308
0309
0310
0311 u8 *buf;
0312 u32 buf_len;
0313
0314
0315 u32 act_len;
0316
0317
0318 enum htc_endpoint_id endpoint;
0319
0320
0321
0322 int status;
0323 union {
0324 struct htc_tx_packet_info tx;
0325 struct htc_rx_packet_info rx;
0326 } info;
0327
0328 void (*completion) (struct htc_target *, struct htc_packet *);
0329 struct htc_target *context;
0330
0331
0332
0333
0334
0335
0336
0337 struct sk_buff *skb;
0338 };
0339
0340 enum htc_send_full_action {
0341 HTC_SEND_FULL_KEEP = 0,
0342 HTC_SEND_FULL_DROP = 1,
0343 };
0344
0345 struct htc_ep_callbacks {
0346 void (*tx_complete) (struct htc_target *, struct htc_packet *);
0347 void (*rx) (struct htc_target *, struct htc_packet *);
0348 void (*rx_refill) (struct htc_target *, enum htc_endpoint_id endpoint);
0349 enum htc_send_full_action (*tx_full) (struct htc_target *,
0350 struct htc_packet *);
0351 struct htc_packet *(*rx_allocthresh) (struct htc_target *,
0352 enum htc_endpoint_id, int);
0353 void (*tx_comp_multi) (struct htc_target *, struct list_head *);
0354 int rx_alloc_thresh;
0355 int rx_refill_thresh;
0356 };
0357
0358
0359 struct htc_service_connect_req {
0360 u16 svc_id;
0361 u16 conn_flags;
0362 struct htc_ep_callbacks ep_cb;
0363 int max_txq_depth;
0364 u32 flags;
0365 unsigned int max_rxmsg_sz;
0366 };
0367
0368
0369 struct htc_service_connect_resp {
0370 u8 buf_len;
0371 u8 act_len;
0372 enum htc_endpoint_id endpoint;
0373 unsigned int len_max;
0374 u8 resp_code;
0375 };
0376
0377
0378 struct htc_endpoint_credit_dist {
0379 struct list_head list;
0380
0381
0382 u16 svc_id;
0383
0384
0385 enum htc_endpoint_id endpoint;
0386
0387 u32 dist_flags;
0388
0389
0390
0391
0392
0393 int cred_norm;
0394
0395
0396 int cred_min;
0397
0398 int cred_assngd;
0399
0400
0401 int credits;
0402
0403
0404
0405
0406
0407
0408
0409 int cred_to_dist;
0410
0411
0412
0413
0414
0415
0416 int seek_cred;
0417
0418
0419 int cred_sz;
0420
0421
0422 int cred_per_msg;
0423
0424
0425 struct htc_endpoint *htc_ep;
0426
0427
0428
0429
0430
0431
0432
0433 int txq_depth;
0434 };
0435
0436
0437
0438
0439
0440 enum htc_credit_dist_reason {
0441 HTC_CREDIT_DIST_SEND_COMPLETE = 0,
0442 HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
0443 HTC_CREDIT_DIST_SEEK_CREDITS,
0444 };
0445
0446 struct ath6kl_htc_credit_info {
0447 int total_avail_credits;
0448 int cur_free_credits;
0449
0450
0451 struct list_head lowestpri_ep_dist;
0452 };
0453
0454
0455 struct htc_endpoint_stats {
0456
0457
0458
0459
0460 u32 cred_low_indicate;
0461
0462 u32 tx_issued;
0463 u32 tx_pkt_bundled;
0464 u32 tx_bundles;
0465 u32 tx_dropped;
0466
0467
0468 u32 tx_cred_rpt;
0469
0470
0471 u32 cred_rpt_from_rx;
0472
0473
0474 u32 cred_rpt_from_other;
0475
0476
0477 u32 cred_rpt_ep0;
0478
0479
0480 u32 cred_from_rx;
0481
0482
0483 u32 cred_from_other;
0484
0485
0486 u32 cred_from_ep0;
0487
0488
0489 u32 cred_cosumd;
0490
0491
0492 u32 cred_retnd;
0493
0494 u32 rx_pkts;
0495
0496
0497 u32 rx_lkahds;
0498
0499
0500 u32 rx_bundl;
0501
0502
0503 u32 rx_bundle_lkahd;
0504
0505
0506 u32 rx_bundle_from_hdr;
0507
0508
0509 u32 rx_alloc_thresh_hit;
0510
0511
0512 u32 rxalloc_thresh_byte;
0513 };
0514
0515 struct htc_endpoint {
0516 enum htc_endpoint_id eid;
0517 u16 svc_id;
0518 struct list_head txq;
0519 struct list_head rx_bufq;
0520 struct htc_endpoint_credit_dist cred_dist;
0521 struct htc_ep_callbacks ep_cb;
0522 int max_txq_depth;
0523 int len_max;
0524 int tx_proc_cnt;
0525 int rx_proc_cnt;
0526 struct htc_target *target;
0527 u8 seqno;
0528 u32 conn_flags;
0529 struct htc_endpoint_stats ep_st;
0530 u16 tx_drop_packet_threshold;
0531
0532 struct {
0533 u8 pipeid_ul;
0534 u8 pipeid_dl;
0535 struct list_head tx_lookup_queue;
0536 bool tx_credit_flow_enabled;
0537 } pipe;
0538 };
0539
0540 struct htc_control_buffer {
0541 struct htc_packet packet;
0542 u8 *buf;
0543 };
0544
0545 struct htc_pipe_txcredit_alloc {
0546 u16 service_id;
0547 u8 credit_alloc;
0548 };
0549
0550 enum htc_send_queue_result {
0551 HTC_SEND_QUEUE_OK = 0,
0552 HTC_SEND_QUEUE_DROP = 1,
0553 };
0554
0555 struct ath6kl_htc_ops {
0556 void* (*create)(struct ath6kl *ar);
0557 int (*wait_target)(struct htc_target *target);
0558 int (*start)(struct htc_target *target);
0559 int (*conn_service)(struct htc_target *target,
0560 struct htc_service_connect_req *req,
0561 struct htc_service_connect_resp *resp);
0562 int (*tx)(struct htc_target *target, struct htc_packet *packet);
0563 void (*stop)(struct htc_target *target);
0564 void (*cleanup)(struct htc_target *target);
0565 void (*flush_txep)(struct htc_target *target,
0566 enum htc_endpoint_id endpoint, u16 tag);
0567 void (*flush_rx_buf)(struct htc_target *target);
0568 void (*activity_changed)(struct htc_target *target,
0569 enum htc_endpoint_id endpoint,
0570 bool active);
0571 int (*get_rxbuf_num)(struct htc_target *target,
0572 enum htc_endpoint_id endpoint);
0573 int (*add_rxbuf_multiple)(struct htc_target *target,
0574 struct list_head *pktq);
0575 int (*credit_setup)(struct htc_target *target,
0576 struct ath6kl_htc_credit_info *cred_info);
0577 int (*tx_complete)(struct ath6kl *ar, struct sk_buff *skb);
0578 int (*rx_complete)(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
0579 };
0580
0581 struct ath6kl_device;
0582
0583
0584 struct htc_target {
0585 struct htc_endpoint endpoint[ENDPOINT_MAX];
0586
0587
0588 struct list_head cred_dist_list;
0589
0590 struct list_head free_ctrl_txbuf;
0591 struct list_head free_ctrl_rxbuf;
0592 struct ath6kl_htc_credit_info *credit_info;
0593 int tgt_creds;
0594 unsigned int tgt_cred_sz;
0595
0596
0597 spinlock_t htc_lock;
0598
0599
0600 spinlock_t rx_lock;
0601
0602
0603 spinlock_t tx_lock;
0604
0605 struct ath6kl_device *dev;
0606 u32 htc_flags;
0607 u32 rx_st_flags;
0608 enum htc_endpoint_id ep_waiting;
0609 u8 htc_tgt_ver;
0610
0611
0612 int msg_per_bndl_max;
0613
0614 u32 tx_bndl_mask;
0615 int rx_bndl_enable;
0616 int max_rx_bndl_sz;
0617 int max_tx_bndl_sz;
0618
0619 u32 block_sz;
0620 u32 block_mask;
0621
0622 int max_scat_entries;
0623 int max_xfer_szper_scatreq;
0624
0625 int chk_irq_status_cnt;
0626
0627
0628 u32 ac_tx_count[WMM_NUM_AC];
0629
0630 struct {
0631 struct htc_packet *htc_packet_pool;
0632 u8 ctrl_response_buf[HTC_MAX_CTRL_MSG_LEN];
0633 int ctrl_response_len;
0634 bool ctrl_response_valid;
0635 struct htc_pipe_txcredit_alloc txcredit_alloc[ENDPOINT_MAX];
0636 } pipe;
0637 };
0638
0639 int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
0640 u32 msg_look_ahead, int *n_pkts);
0641
0642 static inline void set_htc_pkt_info(struct htc_packet *packet, void *context,
0643 u8 *buf, unsigned int len,
0644 enum htc_endpoint_id eid, u16 tag)
0645 {
0646 packet->pkt_cntxt = context;
0647 packet->buf = buf;
0648 packet->act_len = len;
0649 packet->endpoint = eid;
0650 packet->info.tx.tag = tag;
0651 }
0652
0653 static inline void htc_rxpkt_reset(struct htc_packet *packet)
0654 {
0655 packet->buf = packet->buf_start;
0656 packet->act_len = 0;
0657 }
0658
0659 static inline void set_htc_rxpkt_info(struct htc_packet *packet, void *context,
0660 u8 *buf, unsigned long len,
0661 enum htc_endpoint_id eid)
0662 {
0663 packet->pkt_cntxt = context;
0664 packet->buf = buf;
0665 packet->buf_start = buf;
0666 packet->buf_len = len;
0667 packet->endpoint = eid;
0668 }
0669
0670 static inline int get_queue_depth(struct list_head *queue)
0671 {
0672 struct list_head *tmp_list;
0673 int depth = 0;
0674
0675 list_for_each(tmp_list, queue)
0676 depth++;
0677
0678 return depth;
0679 }
0680
0681 void ath6kl_htc_pipe_attach(struct ath6kl *ar);
0682 void ath6kl_htc_mbox_attach(struct ath6kl *ar);
0683
0684 #endif