Lines Matching refs:lp

177 do {	if (lp->cfg.debug & LDC_DEBUG_##TYPE) \
178 printk(KERN_INFO PFX "ID[%lu] " f, lp->id, ## a); \
181 #define LDC_ABORT(lp) ldc_abort((lp), __func__) argument
210 static unsigned long rx_advance(struct ldc_channel *lp, unsigned long off) in rx_advance() argument
212 return __advance(off, lp->rx_num_entries); in rx_advance()
215 static unsigned long tx_advance(struct ldc_channel *lp, unsigned long off) in tx_advance() argument
217 return __advance(off, lp->tx_num_entries); in tx_advance()
220 static struct ldc_packet *handshake_get_tx_packet(struct ldc_channel *lp, in handshake_get_tx_packet() argument
226 t = tx_advance(lp, lp->tx_tail); in handshake_get_tx_packet()
227 if (t == lp->tx_head) in handshake_get_tx_packet()
232 p = lp->tx_base; in handshake_get_tx_packet()
233 return p + (lp->tx_tail / LDC_PACKET_SIZE); in handshake_get_tx_packet()
243 static unsigned long head_for_data(struct ldc_channel *lp) in head_for_data() argument
245 if (lp->cfg.mode == LDC_MODE_STREAM) in head_for_data()
246 return lp->tx_acked; in head_for_data()
247 return lp->tx_head; in head_for_data()
250 static int tx_has_space_for(struct ldc_channel *lp, unsigned int size) in tx_has_space_for() argument
255 limit = head_for_data(lp); in tx_has_space_for()
256 tail = lp->tx_tail; in tx_has_space_for()
257 new_tail = tx_advance(lp, tail); in tx_has_space_for()
265 ((lp->tx_num_entries * LDC_PACKET_SIZE) - new_tail)); in tx_has_space_for()
267 mss = lp->mss; in tx_has_space_for()
275 static struct ldc_packet *data_get_tx_packet(struct ldc_channel *lp, in data_get_tx_packet() argument
281 h = head_for_data(lp); in data_get_tx_packet()
282 t = tx_advance(lp, lp->tx_tail); in data_get_tx_packet()
288 p = lp->tx_base; in data_get_tx_packet()
289 return p + (lp->tx_tail / LDC_PACKET_SIZE); in data_get_tx_packet()
292 static int set_tx_tail(struct ldc_channel *lp, unsigned long tail) in set_tx_tail() argument
294 unsigned long orig_tail = lp->tx_tail; in set_tx_tail()
297 lp->tx_tail = tail; in set_tx_tail()
301 err = sun4v_ldc_tx_set_qtail(lp->id, tail); in set_tx_tail()
306 lp->tx_tail = orig_tail; in set_tx_tail()
312 lp->tx_tail = orig_tail; in set_tx_tail()
320 static int __set_rx_head(struct ldc_channel *lp, unsigned long head) in __set_rx_head() argument
327 err = sun4v_ldc_rx_set_qhead(lp->id, head); in __set_rx_head()
340 static int send_tx_packet(struct ldc_channel *lp, in send_tx_packet() argument
344 BUG_ON(p != (lp->tx_base + (lp->tx_tail / LDC_PACKET_SIZE))); in send_tx_packet()
346 return set_tx_tail(lp, new_tail); in send_tx_packet()
349 static struct ldc_packet *handshake_compose_ctrl(struct ldc_channel *lp, in handshake_compose_ctrl() argument
354 struct ldc_packet *p = handshake_get_tx_packet(lp, new_tail); in handshake_compose_ctrl()
367 static int start_handshake(struct ldc_channel *lp) in start_handshake() argument
378 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_VERS, in start_handshake()
381 int err = send_tx_packet(lp, p, new_tail); in start_handshake()
383 lp->flags &= ~LDC_FLAG_RESET; in start_handshake()
389 static int send_version_nack(struct ldc_channel *lp, in send_version_nack() argument
399 p = handshake_compose_ctrl(lp, LDC_NACK, LDC_VERS, in send_version_nack()
405 return send_tx_packet(lp, p, new_tail); in send_version_nack()
410 static int send_version_ack(struct ldc_channel *lp, in send_version_ack() argument
416 p = handshake_compose_ctrl(lp, LDC_ACK, LDC_VERS, in send_version_ack()
422 return send_tx_packet(lp, p, new_tail); in send_version_ack()
427 static int send_rts(struct ldc_channel *lp) in send_rts() argument
432 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RTS, NULL, 0, in send_rts()
435 p->env = lp->cfg.mode; in send_rts()
437 lp->rcv_nxt = 0; in send_rts()
442 return send_tx_packet(lp, p, new_tail); in send_rts()
447 static int send_rtr(struct ldc_channel *lp) in send_rtr() argument
452 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RTR, NULL, 0, in send_rtr()
455 p->env = lp->cfg.mode; in send_rtr()
461 return send_tx_packet(lp, p, new_tail); in send_rtr()
466 static int send_rdx(struct ldc_channel *lp) in send_rdx() argument
471 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RDX, NULL, 0, in send_rdx()
475 p->seqid = ++lp->snd_nxt; in send_rdx()
476 p->u.r.ackid = lp->rcv_nxt; in send_rdx()
481 return send_tx_packet(lp, p, new_tail); in send_rdx()
486 static int send_data_nack(struct ldc_channel *lp, struct ldc_packet *data_pkt) in send_data_nack() argument
492 p = data_get_tx_packet(lp, &new_tail); in send_data_nack()
499 p->seqid = lp->snd_nxt + 1; in send_data_nack()
500 p->u.r.ackid = lp->rcv_nxt; in send_data_nack()
505 err = send_tx_packet(lp, p, new_tail); in send_data_nack()
507 lp->snd_nxt++; in send_data_nack()
512 static int ldc_abort(struct ldc_channel *lp, const char *msg) in ldc_abort() argument
517 ldc_print(lp); in ldc_abort()
522 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_abort()
526 lp->id, lp->tx_ra, lp->tx_num_entries, hv_err); in ldc_abort()
528 hv_err = sun4v_ldc_tx_get_state(lp->id, in ldc_abort()
529 &lp->tx_head, in ldc_abort()
530 &lp->tx_tail, in ldc_abort()
531 &lp->chan_state); in ldc_abort()
535 lp->id, hv_err); in ldc_abort()
537 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_abort()
541 lp->id, lp->rx_ra, lp->rx_num_entries, hv_err); in ldc_abort()
546 hv_err = sun4v_ldc_rx_get_state(lp->id, in ldc_abort()
547 &lp->rx_head, in ldc_abort()
548 &lp->rx_tail, in ldc_abort()
549 &lp->chan_state); in ldc_abort()
553 lp->id, hv_err); in ldc_abort()
573 static int process_ver_info(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_info() argument
581 if (lp->hs_state == LDC_HS_GOTVERS) { in process_ver_info()
582 lp->hs_state = LDC_HS_OPEN; in process_ver_info()
583 memset(&lp->ver, 0, sizeof(lp->ver)); in process_ver_info()
588 err = send_version_nack(lp, 0, 0); in process_ver_info()
590 err = send_version_nack(lp, vap->major, vap->minor); in process_ver_info()
595 err = send_version_ack(lp, &ver); in process_ver_info()
597 lp->ver = ver; in process_ver_info()
598 lp->hs_state = LDC_HS_GOTVERS; in process_ver_info()
602 return LDC_ABORT(lp); in process_ver_info()
607 static int process_ver_ack(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_ack() argument
612 if (lp->hs_state == LDC_HS_GOTVERS) { in process_ver_ack()
613 if (lp->ver.major != vp->major || in process_ver_ack()
614 lp->ver.minor != vp->minor) in process_ver_ack()
615 return LDC_ABORT(lp); in process_ver_ack()
617 lp->ver = *vp; in process_ver_ack()
618 lp->hs_state = LDC_HS_GOTVERS; in process_ver_ack()
620 if (send_rts(lp)) in process_ver_ack()
621 return LDC_ABORT(lp); in process_ver_ack()
625 static int process_ver_nack(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_nack() argument
632 return LDC_ABORT(lp); in process_ver_nack()
636 return LDC_ABORT(lp); in process_ver_nack()
638 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_VERS, in process_ver_nack()
642 return LDC_ABORT(lp); in process_ver_nack()
644 return send_tx_packet(lp, p, new_tail); in process_ver_nack()
647 static int process_version(struct ldc_channel *lp, in process_version() argument
656 return process_ver_info(lp, vp); in process_version()
659 return process_ver_ack(lp, vp); in process_version()
662 return process_ver_nack(lp, vp); in process_version()
665 return LDC_ABORT(lp); in process_version()
669 static int process_rts(struct ldc_channel *lp, in process_rts() argument
676 lp->hs_state != LDC_HS_GOTVERS || in process_rts()
677 p->env != lp->cfg.mode) in process_rts()
678 return LDC_ABORT(lp); in process_rts()
680 lp->snd_nxt = p->seqid; in process_rts()
681 lp->rcv_nxt = p->seqid; in process_rts()
682 lp->hs_state = LDC_HS_SENTRTR; in process_rts()
683 if (send_rtr(lp)) in process_rts()
684 return LDC_ABORT(lp); in process_rts()
689 static int process_rtr(struct ldc_channel *lp, in process_rtr() argument
696 p->env != lp->cfg.mode) in process_rtr()
697 return LDC_ABORT(lp); in process_rtr()
699 lp->snd_nxt = p->seqid; in process_rtr()
700 lp->hs_state = LDC_HS_COMPLETE; in process_rtr()
701 ldc_set_state(lp, LDC_STATE_CONNECTED); in process_rtr()
702 send_rdx(lp); in process_rtr()
707 static int rx_seq_ok(struct ldc_channel *lp, u32 seqid) in rx_seq_ok() argument
709 return lp->rcv_nxt + 1 == seqid; in rx_seq_ok()
712 static int process_rdx(struct ldc_channel *lp, in process_rdx() argument
719 !(rx_seq_ok(lp, p->seqid))) in process_rdx()
720 return LDC_ABORT(lp); in process_rdx()
722 lp->rcv_nxt = p->seqid; in process_rdx()
724 lp->hs_state = LDC_HS_COMPLETE; in process_rdx()
725 ldc_set_state(lp, LDC_STATE_CONNECTED); in process_rdx()
730 static int process_control_frame(struct ldc_channel *lp, in process_control_frame() argument
735 return process_version(lp, p); in process_control_frame()
738 return process_rts(lp, p); in process_control_frame()
741 return process_rtr(lp, p); in process_control_frame()
744 return process_rdx(lp, p); in process_control_frame()
747 return LDC_ABORT(lp); in process_control_frame()
751 static int process_error_frame(struct ldc_channel *lp, in process_error_frame() argument
754 return LDC_ABORT(lp); in process_error_frame()
757 static int process_data_ack(struct ldc_channel *lp, in process_data_ack() argument
760 unsigned long head = lp->tx_acked; in process_data_ack()
764 struct ldc_packet *p = lp->tx_base + (head / LDC_PACKET_SIZE); in process_data_ack()
766 head = tx_advance(lp, head); in process_data_ack()
769 lp->tx_acked = head; in process_data_ack()
772 if (head == lp->tx_tail) in process_data_ack()
773 return LDC_ABORT(lp); in process_data_ack()
779 static void send_events(struct ldc_channel *lp, unsigned int event_mask) in send_events() argument
782 lp->cfg.event(lp->event_arg, LDC_EVENT_RESET); in send_events()
784 lp->cfg.event(lp->event_arg, LDC_EVENT_UP); in send_events()
786 lp->cfg.event(lp->event_arg, LDC_EVENT_DATA_READY); in send_events()
791 struct ldc_channel *lp = dev_id; in ldc_rx() local
795 spin_lock_irqsave(&lp->lock, flags); in ldc_rx()
797 orig_state = lp->chan_state; in ldc_rx()
802 sun4v_ldc_rx_get_state(lp->id, in ldc_rx()
803 &lp->rx_head, in ldc_rx()
804 &lp->rx_tail, in ldc_rx()
805 &lp->chan_state); in ldc_rx()
808 orig_state, lp->chan_state, lp->rx_head, lp->rx_tail); in ldc_rx()
812 if (lp->cfg.mode == LDC_MODE_RAW && in ldc_rx()
813 lp->chan_state == LDC_CHANNEL_UP) { in ldc_rx()
814 lp->hs_state = LDC_HS_COMPLETE; in ldc_rx()
815 ldc_set_state(lp, LDC_STATE_CONNECTED); in ldc_rx()
823 orig_state = lp->chan_state; in ldc_rx()
830 if (lp->flags & LDC_FLAG_RESET) { in ldc_rx()
831 (void) ldc_rx_reset(lp); in ldc_rx()
839 if (lp->hs_state == LDC_HS_COMPLETE) { in ldc_rx()
841 if (lp->chan_state != orig_state) { in ldc_rx()
844 if (lp->chan_state == LDC_CHANNEL_UP) in ldc_rx()
849 if (lp->rx_head != lp->rx_tail) in ldc_rx()
855 if (lp->chan_state != orig_state) in ldc_rx()
858 while (lp->rx_head != lp->rx_tail) { in ldc_rx()
863 p = lp->rx_base + (lp->rx_head / LDC_PACKET_SIZE); in ldc_rx()
867 err = process_control_frame(lp, p); in ldc_rx()
878 err = process_error_frame(lp, p); in ldc_rx()
882 err = LDC_ABORT(lp); in ldc_rx()
889 new = lp->rx_head; in ldc_rx()
891 if (new == (lp->rx_num_entries * LDC_PACKET_SIZE)) in ldc_rx()
893 lp->rx_head = new; in ldc_rx()
895 err = __set_rx_head(lp, new); in ldc_rx()
897 (void) LDC_ABORT(lp); in ldc_rx()
900 if (lp->hs_state == LDC_HS_COMPLETE) in ldc_rx()
905 spin_unlock_irqrestore(&lp->lock, flags); in ldc_rx()
907 send_events(lp, event_mask); in ldc_rx()
914 struct ldc_channel *lp = dev_id; in ldc_tx() local
918 spin_lock_irqsave(&lp->lock, flags); in ldc_tx()
920 orig_state = lp->chan_state; in ldc_tx()
925 sun4v_ldc_tx_get_state(lp->id, in ldc_tx()
926 &lp->tx_head, in ldc_tx()
927 &lp->tx_tail, in ldc_tx()
928 &lp->chan_state); in ldc_tx()
931 orig_state, lp->chan_state, lp->tx_head, lp->tx_tail); in ldc_tx()
933 if (lp->cfg.mode == LDC_MODE_RAW && in ldc_tx()
934 lp->chan_state == LDC_CHANNEL_UP) { in ldc_tx()
935 lp->hs_state = LDC_HS_COMPLETE; in ldc_tx()
936 ldc_set_state(lp, LDC_STATE_CONNECTED); in ldc_tx()
944 orig_state = lp->chan_state; in ldc_tx()
948 spin_unlock_irqrestore(&lp->lock, flags); in ldc_tx()
950 send_events(lp, event_mask); in ldc_tx()
966 struct ldc_channel *lp; in __ldc_channel_exists() local
968 hlist_for_each_entry(lp, &ldc_channel_list, list) { in __ldc_channel_exists()
969 if (lp->id == id) in __ldc_channel_exists()
1041 static int ldc_iommu_init(const char *name, struct ldc_channel *lp) in ldc_iommu_init() argument
1044 struct ldc_iommu *ldc_iommu = &lp->iommu; in ldc_iommu_init()
1081 hv_err = sun4v_ldc_set_map_table(lp->id, __pa(table), in ldc_iommu_init()
1100 static void ldc_iommu_release(struct ldc_channel *lp) in ldc_iommu_release() argument
1102 struct ldc_iommu *ldc_iommu = &lp->iommu; in ldc_iommu_release()
1106 (void) sun4v_ldc_set_map_table(lp->id, 0, 0); in ldc_iommu_release()
1124 struct ldc_channel *lp; in ldc_alloc() local
1174 lp = kzalloc(sizeof(*lp), GFP_KERNEL); in ldc_alloc()
1176 if (!lp) in ldc_alloc()
1179 spin_lock_init(&lp->lock); in ldc_alloc()
1181 lp->id = id; in ldc_alloc()
1183 err = ldc_iommu_init(name, lp); in ldc_alloc()
1187 lp->mops = mops; in ldc_alloc()
1188 lp->mss = mss; in ldc_alloc()
1190 lp->cfg = *cfgp; in ldc_alloc()
1191 if (!lp->cfg.mtu) in ldc_alloc()
1192 lp->cfg.mtu = LDC_DEFAULT_MTU; in ldc_alloc()
1194 if (lp->cfg.mode == LDC_MODE_STREAM) { in ldc_alloc()
1195 mssbuf = kzalloc(lp->cfg.mtu, GFP_KERNEL); in ldc_alloc()
1200 lp->mssbuf = mssbuf; in ldc_alloc()
1203 lp->event_arg = event_arg; in ldc_alloc()
1208 lp->tx_num_entries = LDC_DEFAULT_NUM_ENTRIES; in ldc_alloc()
1209 lp->rx_num_entries = LDC_DEFAULT_NUM_ENTRIES; in ldc_alloc()
1211 err = alloc_queue("TX", lp->tx_num_entries, in ldc_alloc()
1212 &lp->tx_base, &lp->tx_ra); in ldc_alloc()
1216 err = alloc_queue("RX", lp->rx_num_entries, in ldc_alloc()
1217 &lp->rx_base, &lp->rx_ra); in ldc_alloc()
1221 lp->flags |= LDC_FLAG_ALLOCED_QUEUES; in ldc_alloc()
1223 lp->hs_state = LDC_HS_CLOSED; in ldc_alloc()
1224 ldc_set_state(lp, LDC_STATE_INIT); in ldc_alloc()
1226 INIT_HLIST_NODE(&lp->list); in ldc_alloc()
1227 hlist_add_head(&lp->list, &ldc_channel_list); in ldc_alloc()
1229 INIT_HLIST_HEAD(&lp->mh_list); in ldc_alloc()
1231 snprintf(lp->rx_irq_name, LDC_IRQ_NAME_MAX, "%s RX", name); in ldc_alloc()
1232 snprintf(lp->tx_irq_name, LDC_IRQ_NAME_MAX, "%s TX", name); in ldc_alloc()
1234 err = request_irq(lp->cfg.rx_irq, ldc_rx, 0, in ldc_alloc()
1235 lp->rx_irq_name, lp); in ldc_alloc()
1239 err = request_irq(lp->cfg.tx_irq, ldc_tx, 0, in ldc_alloc()
1240 lp->tx_irq_name, lp); in ldc_alloc()
1242 free_irq(lp->cfg.rx_irq, lp); in ldc_alloc()
1246 return lp; in ldc_alloc()
1249 free_queue(lp->tx_num_entries, lp->tx_base); in ldc_alloc()
1255 ldc_iommu_release(lp); in ldc_alloc()
1258 kfree(lp); in ldc_alloc()
1265 void ldc_unbind(struct ldc_channel *lp) in ldc_unbind() argument
1267 if (lp->flags & LDC_FLAG_REGISTERED_IRQS) { in ldc_unbind()
1268 free_irq(lp->cfg.rx_irq, lp); in ldc_unbind()
1269 free_irq(lp->cfg.tx_irq, lp); in ldc_unbind()
1270 lp->flags &= ~LDC_FLAG_REGISTERED_IRQS; in ldc_unbind()
1273 if (lp->flags & LDC_FLAG_REGISTERED_QUEUES) { in ldc_unbind()
1274 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_unbind()
1275 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_unbind()
1276 lp->flags &= ~LDC_FLAG_REGISTERED_QUEUES; in ldc_unbind()
1278 if (lp->flags & LDC_FLAG_ALLOCED_QUEUES) { in ldc_unbind()
1279 free_queue(lp->tx_num_entries, lp->tx_base); in ldc_unbind()
1280 free_queue(lp->rx_num_entries, lp->rx_base); in ldc_unbind()
1281 lp->flags &= ~LDC_FLAG_ALLOCED_QUEUES; in ldc_unbind()
1284 ldc_set_state(lp, LDC_STATE_INIT); in ldc_unbind()
1288 void ldc_free(struct ldc_channel *lp) in ldc_free() argument
1290 ldc_unbind(lp); in ldc_free()
1291 hlist_del(&lp->list); in ldc_free()
1292 kfree(lp->mssbuf); in ldc_free()
1293 ldc_iommu_release(lp); in ldc_free()
1295 kfree(lp); in ldc_free()
1304 int ldc_bind(struct ldc_channel *lp) in ldc_bind() argument
1309 if (lp->state != LDC_STATE_INIT) in ldc_bind()
1312 spin_lock_irqsave(&lp->lock, flags); in ldc_bind()
1314 enable_irq(lp->cfg.rx_irq); in ldc_bind()
1315 enable_irq(lp->cfg.tx_irq); in ldc_bind()
1317 lp->flags |= LDC_FLAG_REGISTERED_IRQS; in ldc_bind()
1320 hv_err = sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_bind()
1324 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_bind()
1328 hv_err = sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_bind()
1332 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_bind()
1336 lp->flags |= LDC_FLAG_REGISTERED_QUEUES; in ldc_bind()
1338 hv_err = sun4v_ldc_tx_get_state(lp->id, in ldc_bind()
1339 &lp->tx_head, in ldc_bind()
1340 &lp->tx_tail, in ldc_bind()
1341 &lp->chan_state); in ldc_bind()
1346 lp->tx_acked = lp->tx_head; in ldc_bind()
1348 lp->hs_state = LDC_HS_OPEN; in ldc_bind()
1349 ldc_set_state(lp, LDC_STATE_BOUND); in ldc_bind()
1351 if (lp->cfg.mode == LDC_MODE_RAW) { in ldc_bind()
1356 lp->hs_state = LDC_HS_COMPLETE; in ldc_bind()
1359 spin_unlock_irqrestore(&lp->lock, flags); in ldc_bind()
1364 lp->flags &= ~LDC_FLAG_REGISTERED_QUEUES; in ldc_bind()
1365 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_bind()
1368 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_bind()
1371 lp->flags &= ~LDC_FLAG_REGISTERED_IRQS; in ldc_bind()
1372 free_irq(lp->cfg.tx_irq, lp); in ldc_bind()
1373 free_irq(lp->cfg.rx_irq, lp); in ldc_bind()
1375 spin_unlock_irqrestore(&lp->lock, flags); in ldc_bind()
1381 int ldc_connect(struct ldc_channel *lp) in ldc_connect() argument
1386 if (lp->cfg.mode == LDC_MODE_RAW) in ldc_connect()
1389 spin_lock_irqsave(&lp->lock, flags); in ldc_connect()
1391 if (!(lp->flags & LDC_FLAG_ALLOCED_QUEUES) || in ldc_connect()
1392 !(lp->flags & LDC_FLAG_REGISTERED_QUEUES) || in ldc_connect()
1393 lp->hs_state != LDC_HS_OPEN) in ldc_connect()
1394 err = ((lp->hs_state > LDC_HS_OPEN) ? 0 : -EINVAL); in ldc_connect()
1396 err = start_handshake(lp); in ldc_connect()
1398 spin_unlock_irqrestore(&lp->lock, flags); in ldc_connect()
1404 int ldc_disconnect(struct ldc_channel *lp) in ldc_disconnect() argument
1409 if (lp->cfg.mode == LDC_MODE_RAW) in ldc_disconnect()
1412 if (!(lp->flags & LDC_FLAG_ALLOCED_QUEUES) || in ldc_disconnect()
1413 !(lp->flags & LDC_FLAG_REGISTERED_QUEUES)) in ldc_disconnect()
1416 spin_lock_irqsave(&lp->lock, flags); in ldc_disconnect()
1419 hv_err = sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_disconnect()
1423 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_disconnect()
1427 hv_err = sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_disconnect()
1431 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_disconnect()
1435 ldc_set_state(lp, LDC_STATE_BOUND); in ldc_disconnect()
1436 lp->hs_state = LDC_HS_OPEN; in ldc_disconnect()
1437 lp->flags |= LDC_FLAG_RESET; in ldc_disconnect()
1439 spin_unlock_irqrestore(&lp->lock, flags); in ldc_disconnect()
1444 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_disconnect()
1445 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_disconnect()
1446 free_irq(lp->cfg.tx_irq, lp); in ldc_disconnect()
1447 free_irq(lp->cfg.rx_irq, lp); in ldc_disconnect()
1448 lp->flags &= ~(LDC_FLAG_REGISTERED_IRQS | in ldc_disconnect()
1450 ldc_set_state(lp, LDC_STATE_INIT); in ldc_disconnect()
1452 spin_unlock_irqrestore(&lp->lock, flags); in ldc_disconnect()
1458 int ldc_state(struct ldc_channel *lp) in ldc_state() argument
1460 return lp->state; in ldc_state()
1464 void ldc_set_state(struct ldc_channel *lp, u8 state) in ldc_set_state() argument
1467 state_to_str(lp->state), in ldc_set_state()
1470 lp->state = state; in ldc_set_state()
1474 int ldc_mode(struct ldc_channel *lp) in ldc_mode() argument
1476 return lp->cfg.mode; in ldc_mode()
1480 int ldc_rx_reset(struct ldc_channel *lp) in ldc_rx_reset() argument
1482 return __set_rx_head(lp, lp->rx_tail); in ldc_rx_reset()
1486 void __ldc_print(struct ldc_channel *lp, const char *caller) in __ldc_print() argument
1492 caller, lp->id, lp->flags, state_to_str(lp->state), in __ldc_print()
1493 lp->chan_state, lp->hs_state, in __ldc_print()
1494 lp->rx_head, lp->rx_tail, lp->rx_num_entries, in __ldc_print()
1495 lp->tx_head, lp->tx_tail, lp->tx_num_entries, in __ldc_print()
1496 lp->rcv_nxt, lp->snd_nxt); in __ldc_print()
1500 static int write_raw(struct ldc_channel *lp, const void *buf, unsigned int size) in write_raw() argument
1506 hv_err = sun4v_ldc_tx_get_state(lp->id, &lp->tx_head, &lp->tx_tail, in write_raw()
1507 &lp->chan_state); in write_raw()
1511 if (unlikely(lp->chan_state != LDC_CHANNEL_UP)) in write_raw()
1512 return LDC_ABORT(lp); in write_raw()
1517 p = data_get_tx_packet(lp, &new_tail); in write_raw()
1523 err = send_tx_packet(lp, p, new_tail); in write_raw()
1530 static int read_raw(struct ldc_channel *lp, void *buf, unsigned int size) in read_raw() argument
1539 hv_err = sun4v_ldc_rx_get_state(lp->id, in read_raw()
1540 &lp->rx_head, in read_raw()
1541 &lp->rx_tail, in read_raw()
1542 &lp->chan_state); in read_raw()
1544 return LDC_ABORT(lp); in read_raw()
1546 if (lp->chan_state == LDC_CHANNEL_DOWN || in read_raw()
1547 lp->chan_state == LDC_CHANNEL_RESETTING) in read_raw()
1550 if (lp->rx_head == lp->rx_tail) in read_raw()
1553 p = lp->rx_base + (lp->rx_head / LDC_PACKET_SIZE); in read_raw()
1556 new = rx_advance(lp, lp->rx_head); in read_raw()
1557 lp->rx_head = new; in read_raw()
1559 err = __set_rx_head(lp, new); in read_raw()
1573 static int write_nonraw(struct ldc_channel *lp, const void *buf, in write_nonraw() argument
1581 hv_err = sun4v_ldc_tx_get_state(lp->id, &lp->tx_head, &lp->tx_tail, in write_nonraw()
1582 &lp->chan_state); in write_nonraw()
1586 if (unlikely(lp->chan_state != LDC_CHANNEL_UP)) in write_nonraw()
1587 return LDC_ABORT(lp); in write_nonraw()
1589 if (!tx_has_space_for(lp, size)) in write_nonraw()
1592 seq = lp->snd_nxt; in write_nonraw()
1594 tail = lp->tx_tail; in write_nonraw()
1596 struct ldc_packet *p = lp->tx_base + (tail / LDC_PACKET_SIZE); in write_nonraw()
1597 u8 *data = ((lp->cfg.mode == LDC_MODE_UNRELIABLE) ? in write_nonraw()
1607 if (data_len > lp->mss) in write_nonraw()
1608 data_len = lp->mss; in write_nonraw()
1629 tail = tx_advance(lp, tail); in write_nonraw()
1632 err = set_tx_tail(lp, tail); in write_nonraw()
1634 lp->snd_nxt = seq; in write_nonraw()
1641 static int rx_bad_seq(struct ldc_channel *lp, struct ldc_packet *p, in rx_bad_seq() argument
1647 lp->rcv_nxt = first_frag->seqid - 1; in rx_bad_seq()
1649 err = send_data_nack(lp, p); in rx_bad_seq()
1653 err = ldc_rx_reset(lp); in rx_bad_seq()
1655 return LDC_ABORT(lp); in rx_bad_seq()
1660 static int data_ack_nack(struct ldc_channel *lp, struct ldc_packet *p) in data_ack_nack() argument
1663 int err = process_data_ack(lp, p); in data_ack_nack()
1668 return LDC_ABORT(lp); in data_ack_nack()
1673 static int rx_data_wait(struct ldc_channel *lp, unsigned long cur_head) in rx_data_wait() argument
1679 cur_head, lp->rx_head, lp->rx_tail); in rx_data_wait()
1683 hv_err = sun4v_ldc_rx_get_state(lp->id, in rx_data_wait()
1685 &lp->rx_tail, in rx_data_wait()
1686 &lp->chan_state); in rx_data_wait()
1688 return LDC_ABORT(lp); in rx_data_wait()
1690 if (lp->chan_state == LDC_CHANNEL_DOWN || in rx_data_wait()
1691 lp->chan_state == LDC_CHANNEL_RESETTING) in rx_data_wait()
1694 if (cur_head != lp->rx_tail) { in rx_data_wait()
1697 dummy, lp->rx_tail, lp->chan_state); in rx_data_wait()
1706 static int rx_set_head(struct ldc_channel *lp, unsigned long head) in rx_set_head() argument
1708 int err = __set_rx_head(lp, head); in rx_set_head()
1711 return LDC_ABORT(lp); in rx_set_head()
1713 lp->rx_head = head; in rx_set_head()
1717 static void send_data_ack(struct ldc_channel *lp) in send_data_ack() argument
1722 p = data_get_tx_packet(lp, &new_tail); in send_data_ack()
1730 p->seqid = lp->snd_nxt + 1; in send_data_ack()
1731 p->u.r.ackid = lp->rcv_nxt; in send_data_ack()
1733 err = send_tx_packet(lp, p, new_tail); in send_data_ack()
1735 lp->snd_nxt++; in send_data_ack()
1739 static int read_nonraw(struct ldc_channel *lp, void *buf, unsigned int size) in read_nonraw() argument
1745 hv_err = sun4v_ldc_rx_get_state(lp->id, in read_nonraw()
1746 &lp->rx_head, in read_nonraw()
1747 &lp->rx_tail, in read_nonraw()
1748 &lp->chan_state); in read_nonraw()
1750 return LDC_ABORT(lp); in read_nonraw()
1752 if (lp->chan_state == LDC_CHANNEL_DOWN || in read_nonraw()
1753 lp->chan_state == LDC_CHANNEL_RESETTING) in read_nonraw()
1756 if (lp->rx_head == lp->rx_tail) in read_nonraw()
1761 new = lp->rx_head; in read_nonraw()
1766 BUG_ON(new == lp->rx_tail); in read_nonraw()
1767 p = lp->rx_base + (new / LDC_PACKET_SIZE); in read_nonraw()
1777 lp->rcv_nxt); in read_nonraw()
1779 if (unlikely(!rx_seq_ok(lp, p->seqid))) { in read_nonraw()
1780 err = rx_bad_seq(lp, p, first_frag); in read_nonraw()
1786 err = process_control_frame(lp, p); in read_nonraw()
1792 lp->rcv_nxt = p->seqid; in read_nonraw()
1800 new = rx_advance(lp, new); in read_nonraw()
1804 err = data_ack_nack(lp, p); in read_nonraw()
1809 new = rx_advance(lp, new); in read_nonraw()
1810 err = rx_set_head(lp, new); in read_nonraw()
1834 new = rx_advance(lp, new); in read_nonraw()
1836 err = rx_set_head(lp, new); in read_nonraw()
1864 new = rx_advance(lp, new); in read_nonraw()
1867 (lp->cfg.mode == LDC_MODE_UNRELIABLE ? in read_nonraw()
1876 if (new == lp->rx_tail) { in read_nonraw()
1877 err = rx_data_wait(lp, new); in read_nonraw()
1884 err = rx_set_head(lp, new); in read_nonraw()
1887 lp->rcv_nxt = first_frag->seqid - 1; in read_nonraw()
1891 if (err > 0 && lp->cfg.mode != LDC_MODE_UNRELIABLE) in read_nonraw()
1892 send_data_ack(lp); in read_nonraw()
1903 static int write_stream(struct ldc_channel *lp, const void *buf, in write_stream() argument
1906 if (size > lp->cfg.mtu) in write_stream()
1907 size = lp->cfg.mtu; in write_stream()
1908 return write_nonraw(lp, buf, size); in write_stream()
1911 static int read_stream(struct ldc_channel *lp, void *buf, unsigned int size) in read_stream() argument
1913 if (!lp->mssbuf_len) { in read_stream()
1914 int err = read_nonraw(lp, lp->mssbuf, lp->cfg.mtu); in read_stream()
1918 lp->mssbuf_len = err; in read_stream()
1919 lp->mssbuf_off = 0; in read_stream()
1922 if (size > lp->mssbuf_len) in read_stream()
1923 size = lp->mssbuf_len; in read_stream()
1924 memcpy(buf, lp->mssbuf + lp->mssbuf_off, size); in read_stream()
1926 lp->mssbuf_off += size; in read_stream()
1927 lp->mssbuf_len -= size; in read_stream()
1937 int ldc_write(struct ldc_channel *lp, const void *buf, unsigned int size) in ldc_write() argument
1948 spin_lock_irqsave(&lp->lock, flags); in ldc_write()
1950 if (lp->hs_state != LDC_HS_COMPLETE) in ldc_write()
1953 err = lp->mops->write(lp, buf, size); in ldc_write()
1955 spin_unlock_irqrestore(&lp->lock, flags); in ldc_write()
1961 int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size) in ldc_read() argument
1974 spin_lock_irqsave(&lp->lock, flags); in ldc_read()
1976 if (lp->hs_state != LDC_HS_COMPLETE) in ldc_read()
1979 err = lp->mops->read(lp, buf, size); in ldc_read()
1981 spin_unlock_irqrestore(&lp->lock, flags); in ldc_read()
1984 lp->cfg.mode, lp->rx_head, lp->rx_tail, err); in ldc_read()
2147 int ldc_map_sg(struct ldc_channel *lp, in ldc_map_sg() argument
2170 iommu = &lp->iommu; in ldc_map_sg()
2193 int ldc_map_single(struct ldc_channel *lp, in ldc_map_single() argument
2212 iommu = &lp->iommu; in ldc_map_single()
2245 void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies, in ldc_unmap() argument
2248 struct ldc_iommu *iommu = &lp->iommu; in ldc_unmap()
2257 free_npages(lp->id, iommu, addr, size); in ldc_unmap()
2263 int ldc_copy(struct ldc_channel *lp, int copy_dir, in ldc_copy() argument
2273 lp->id, copy_dir); in ldc_copy()
2281 lp->id, ra, len, offset); in ldc_copy()
2285 if (lp->hs_state != LDC_HS_COMPLETE || in ldc_copy()
2286 (lp->flags & LDC_FLAG_RESET)) { in ldc_copy()
2288 "flags[%x]\n", lp->id, lp->hs_state, lp->flags); in ldc_copy()
2317 hv_err = sun4v_ldc_copy(lp->id, copy_dir, in ldc_copy()
2323 lp->id, hv_err); in ldc_copy()
2324 if (lp->hs_state != LDC_HS_COMPLETE || in ldc_copy()
2325 (lp->flags & LDC_FLAG_RESET)) in ldc_copy()
2353 void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len, in ldc_alloc_exp_dring() argument
2367 err = ldc_map_single(lp, buf, len, cookies, *ncookies, map_perm); in ldc_alloc_exp_dring()
2378 void ldc_free_exp_dring(struct ldc_channel *lp, void *buf, unsigned int len, in ldc_free_exp_dring() argument
2381 ldc_unmap(lp, cookies, ncookies); in ldc_free_exp_dring()