Lines Matching refs:lp
177 do { if (lp->cfg.debug & LDC_DEBUG_##TYPE) \
178 printk(KERN_INFO PFX "ID[%lu] " f, lp->id, ## a); \
199 static void ldc_set_state(struct ldc_channel *lp, u8 state) in ldc_set_state() argument
202 state_to_str(lp->state), in ldc_set_state()
205 lp->state = state; in ldc_set_state()
217 static unsigned long rx_advance(struct ldc_channel *lp, unsigned long off) in rx_advance() argument
219 return __advance(off, lp->rx_num_entries); in rx_advance()
222 static unsigned long tx_advance(struct ldc_channel *lp, unsigned long off) in tx_advance() argument
224 return __advance(off, lp->tx_num_entries); in tx_advance()
227 static struct ldc_packet *handshake_get_tx_packet(struct ldc_channel *lp, in handshake_get_tx_packet() argument
233 t = tx_advance(lp, lp->tx_tail); in handshake_get_tx_packet()
234 if (t == lp->tx_head) in handshake_get_tx_packet()
239 p = lp->tx_base; in handshake_get_tx_packet()
240 return p + (lp->tx_tail / LDC_PACKET_SIZE); in handshake_get_tx_packet()
250 static unsigned long head_for_data(struct ldc_channel *lp) in head_for_data() argument
252 if (lp->cfg.mode == LDC_MODE_STREAM) in head_for_data()
253 return lp->tx_acked; in head_for_data()
254 return lp->tx_head; in head_for_data()
257 static int tx_has_space_for(struct ldc_channel *lp, unsigned int size) in tx_has_space_for() argument
262 limit = head_for_data(lp); in tx_has_space_for()
263 tail = lp->tx_tail; in tx_has_space_for()
264 new_tail = tx_advance(lp, tail); in tx_has_space_for()
272 ((lp->tx_num_entries * LDC_PACKET_SIZE) - new_tail)); in tx_has_space_for()
274 mss = lp->mss; in tx_has_space_for()
282 static struct ldc_packet *data_get_tx_packet(struct ldc_channel *lp, in data_get_tx_packet() argument
288 h = head_for_data(lp); in data_get_tx_packet()
289 t = tx_advance(lp, lp->tx_tail); in data_get_tx_packet()
295 p = lp->tx_base; in data_get_tx_packet()
296 return p + (lp->tx_tail / LDC_PACKET_SIZE); in data_get_tx_packet()
299 static int set_tx_tail(struct ldc_channel *lp, unsigned long tail) in set_tx_tail() argument
301 unsigned long orig_tail = lp->tx_tail; in set_tx_tail()
304 lp->tx_tail = tail; in set_tx_tail()
308 err = sun4v_ldc_tx_set_qtail(lp->id, tail); in set_tx_tail()
313 lp->tx_tail = orig_tail; in set_tx_tail()
319 lp->tx_tail = orig_tail; in set_tx_tail()
327 static int __set_rx_head(struct ldc_channel *lp, unsigned long head) in __set_rx_head() argument
334 err = sun4v_ldc_rx_set_qhead(lp->id, head); in __set_rx_head()
347 static int send_tx_packet(struct ldc_channel *lp, in send_tx_packet() argument
351 BUG_ON(p != (lp->tx_base + (lp->tx_tail / LDC_PACKET_SIZE))); in send_tx_packet()
353 return set_tx_tail(lp, new_tail); in send_tx_packet()
356 static struct ldc_packet *handshake_compose_ctrl(struct ldc_channel *lp, in handshake_compose_ctrl() argument
361 struct ldc_packet *p = handshake_get_tx_packet(lp, new_tail); in handshake_compose_ctrl()
374 static int start_handshake(struct ldc_channel *lp) in start_handshake() argument
385 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_VERS, in start_handshake()
388 int err = send_tx_packet(lp, p, new_tail); in start_handshake()
390 lp->flags &= ~LDC_FLAG_RESET; in start_handshake()
396 static int send_version_nack(struct ldc_channel *lp, in send_version_nack() argument
406 p = handshake_compose_ctrl(lp, LDC_NACK, LDC_VERS, in send_version_nack()
412 return send_tx_packet(lp, p, new_tail); in send_version_nack()
417 static int send_version_ack(struct ldc_channel *lp, in send_version_ack() argument
423 p = handshake_compose_ctrl(lp, LDC_ACK, LDC_VERS, in send_version_ack()
429 return send_tx_packet(lp, p, new_tail); in send_version_ack()
434 static int send_rts(struct ldc_channel *lp) in send_rts() argument
439 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RTS, NULL, 0, in send_rts()
442 p->env = lp->cfg.mode; in send_rts()
444 lp->rcv_nxt = 0; in send_rts()
449 return send_tx_packet(lp, p, new_tail); in send_rts()
454 static int send_rtr(struct ldc_channel *lp) in send_rtr() argument
459 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RTR, NULL, 0, in send_rtr()
462 p->env = lp->cfg.mode; in send_rtr()
468 return send_tx_packet(lp, p, new_tail); in send_rtr()
473 static int send_rdx(struct ldc_channel *lp) in send_rdx() argument
478 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_RDX, NULL, 0, in send_rdx()
482 p->seqid = ++lp->snd_nxt; in send_rdx()
483 p->u.r.ackid = lp->rcv_nxt; in send_rdx()
488 return send_tx_packet(lp, p, new_tail); in send_rdx()
493 static int send_data_nack(struct ldc_channel *lp, struct ldc_packet *data_pkt) in send_data_nack() argument
499 p = data_get_tx_packet(lp, &new_tail); in send_data_nack()
506 p->seqid = lp->snd_nxt + 1; in send_data_nack()
507 p->u.r.ackid = lp->rcv_nxt; in send_data_nack()
512 err = send_tx_packet(lp, p, new_tail); in send_data_nack()
514 lp->snd_nxt++; in send_data_nack()
519 static int ldc_abort(struct ldc_channel *lp) in ldc_abort() argument
528 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_abort()
532 lp->id, lp->tx_ra, lp->tx_num_entries, hv_err); in ldc_abort()
534 hv_err = sun4v_ldc_tx_get_state(lp->id, in ldc_abort()
535 &lp->tx_head, in ldc_abort()
536 &lp->tx_tail, in ldc_abort()
537 &lp->chan_state); in ldc_abort()
541 lp->id, hv_err); in ldc_abort()
543 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_abort()
547 lp->id, lp->rx_ra, lp->rx_num_entries, hv_err); in ldc_abort()
552 hv_err = sun4v_ldc_rx_get_state(lp->id, in ldc_abort()
553 &lp->rx_head, in ldc_abort()
554 &lp->rx_tail, in ldc_abort()
555 &lp->chan_state); in ldc_abort()
559 lp->id, hv_err); in ldc_abort()
579 static int process_ver_info(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_info() argument
587 if (lp->hs_state == LDC_HS_GOTVERS) { in process_ver_info()
588 lp->hs_state = LDC_HS_OPEN; in process_ver_info()
589 memset(&lp->ver, 0, sizeof(lp->ver)); in process_ver_info()
594 err = send_version_nack(lp, 0, 0); in process_ver_info()
596 err = send_version_nack(lp, vap->major, vap->minor); in process_ver_info()
601 err = send_version_ack(lp, &ver); in process_ver_info()
603 lp->ver = ver; in process_ver_info()
604 lp->hs_state = LDC_HS_GOTVERS; in process_ver_info()
608 return ldc_abort(lp); in process_ver_info()
613 static int process_ver_ack(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_ack() argument
618 if (lp->hs_state == LDC_HS_GOTVERS) { in process_ver_ack()
619 if (lp->ver.major != vp->major || in process_ver_ack()
620 lp->ver.minor != vp->minor) in process_ver_ack()
621 return ldc_abort(lp); in process_ver_ack()
623 lp->ver = *vp; in process_ver_ack()
624 lp->hs_state = LDC_HS_GOTVERS; in process_ver_ack()
626 if (send_rts(lp)) in process_ver_ack()
627 return ldc_abort(lp); in process_ver_ack()
631 static int process_ver_nack(struct ldc_channel *lp, struct ldc_version *vp) in process_ver_nack() argument
638 return ldc_abort(lp); in process_ver_nack()
642 return ldc_abort(lp); in process_ver_nack()
644 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_VERS, in process_ver_nack()
648 return ldc_abort(lp); in process_ver_nack()
650 return send_tx_packet(lp, p, new_tail); in process_ver_nack()
653 static int process_version(struct ldc_channel *lp, in process_version() argument
662 return process_ver_info(lp, vp); in process_version()
665 return process_ver_ack(lp, vp); in process_version()
668 return process_ver_nack(lp, vp); in process_version()
671 return ldc_abort(lp); in process_version()
675 static int process_rts(struct ldc_channel *lp, in process_rts() argument
682 lp->hs_state != LDC_HS_GOTVERS || in process_rts()
683 p->env != lp->cfg.mode) in process_rts()
684 return ldc_abort(lp); in process_rts()
686 lp->snd_nxt = p->seqid; in process_rts()
687 lp->rcv_nxt = p->seqid; in process_rts()
688 lp->hs_state = LDC_HS_SENTRTR; in process_rts()
689 if (send_rtr(lp)) in process_rts()
690 return ldc_abort(lp); in process_rts()
695 static int process_rtr(struct ldc_channel *lp, in process_rtr() argument
702 p->env != lp->cfg.mode) in process_rtr()
703 return ldc_abort(lp); in process_rtr()
705 lp->snd_nxt = p->seqid; in process_rtr()
706 lp->hs_state = LDC_HS_COMPLETE; in process_rtr()
707 ldc_set_state(lp, LDC_STATE_CONNECTED); in process_rtr()
708 send_rdx(lp); in process_rtr()
713 static int rx_seq_ok(struct ldc_channel *lp, u32 seqid) in rx_seq_ok() argument
715 return lp->rcv_nxt + 1 == seqid; in rx_seq_ok()
718 static int process_rdx(struct ldc_channel *lp, in process_rdx() argument
725 !(rx_seq_ok(lp, p->seqid))) in process_rdx()
726 return ldc_abort(lp); in process_rdx()
728 lp->rcv_nxt = p->seqid; in process_rdx()
730 lp->hs_state = LDC_HS_COMPLETE; in process_rdx()
731 ldc_set_state(lp, LDC_STATE_CONNECTED); in process_rdx()
736 static int process_control_frame(struct ldc_channel *lp, in process_control_frame() argument
741 return process_version(lp, p); in process_control_frame()
744 return process_rts(lp, p); in process_control_frame()
747 return process_rtr(lp, p); in process_control_frame()
750 return process_rdx(lp, p); in process_control_frame()
753 return ldc_abort(lp); in process_control_frame()
757 static int process_error_frame(struct ldc_channel *lp, in process_error_frame() argument
760 return ldc_abort(lp); in process_error_frame()
763 static int process_data_ack(struct ldc_channel *lp, in process_data_ack() argument
766 unsigned long head = lp->tx_acked; in process_data_ack()
770 struct ldc_packet *p = lp->tx_base + (head / LDC_PACKET_SIZE); in process_data_ack()
772 head = tx_advance(lp, head); in process_data_ack()
775 lp->tx_acked = head; in process_data_ack()
778 if (head == lp->tx_tail) in process_data_ack()
779 return ldc_abort(lp); in process_data_ack()
785 static void send_events(struct ldc_channel *lp, unsigned int event_mask) in send_events() argument
788 lp->cfg.event(lp->event_arg, LDC_EVENT_RESET); in send_events()
790 lp->cfg.event(lp->event_arg, LDC_EVENT_UP); in send_events()
792 lp->cfg.event(lp->event_arg, LDC_EVENT_DATA_READY); in send_events()
797 struct ldc_channel *lp = dev_id; in ldc_rx() local
801 spin_lock_irqsave(&lp->lock, flags); in ldc_rx()
803 orig_state = lp->chan_state; in ldc_rx()
808 sun4v_ldc_rx_get_state(lp->id, in ldc_rx()
809 &lp->rx_head, in ldc_rx()
810 &lp->rx_tail, in ldc_rx()
811 &lp->chan_state); in ldc_rx()
814 orig_state, lp->chan_state, lp->rx_head, lp->rx_tail); in ldc_rx()
818 if (lp->cfg.mode == LDC_MODE_RAW && in ldc_rx()
819 lp->chan_state == LDC_CHANNEL_UP) { in ldc_rx()
820 lp->hs_state = LDC_HS_COMPLETE; in ldc_rx()
821 ldc_set_state(lp, LDC_STATE_CONNECTED); in ldc_rx()
825 orig_state = lp->chan_state; in ldc_rx()
831 if (lp->flags & LDC_FLAG_RESET) { in ldc_rx()
832 (void) __set_rx_head(lp, lp->rx_tail); in ldc_rx()
840 if (lp->hs_state == LDC_HS_COMPLETE) { in ldc_rx()
842 if (lp->chan_state != orig_state) { in ldc_rx()
845 if (lp->chan_state == LDC_CHANNEL_UP) in ldc_rx()
850 if (lp->rx_head != lp->rx_tail) in ldc_rx()
856 if (lp->chan_state != orig_state) in ldc_rx()
859 while (lp->rx_head != lp->rx_tail) { in ldc_rx()
864 p = lp->rx_base + (lp->rx_head / LDC_PACKET_SIZE); in ldc_rx()
868 err = process_control_frame(lp, p); in ldc_rx()
879 err = process_error_frame(lp, p); in ldc_rx()
883 err = ldc_abort(lp); in ldc_rx()
890 new = lp->rx_head; in ldc_rx()
892 if (new == (lp->rx_num_entries * LDC_PACKET_SIZE)) in ldc_rx()
894 lp->rx_head = new; in ldc_rx()
896 err = __set_rx_head(lp, new); in ldc_rx()
898 (void) ldc_abort(lp); in ldc_rx()
901 if (lp->hs_state == LDC_HS_COMPLETE) in ldc_rx()
906 spin_unlock_irqrestore(&lp->lock, flags); in ldc_rx()
908 send_events(lp, event_mask); in ldc_rx()
915 struct ldc_channel *lp = dev_id; in ldc_tx() local
919 spin_lock_irqsave(&lp->lock, flags); in ldc_tx()
921 orig_state = lp->chan_state; in ldc_tx()
926 sun4v_ldc_tx_get_state(lp->id, in ldc_tx()
927 &lp->tx_head, in ldc_tx()
928 &lp->tx_tail, in ldc_tx()
929 &lp->chan_state); in ldc_tx()
932 orig_state, lp->chan_state, lp->tx_head, lp->tx_tail); in ldc_tx()
934 if (lp->cfg.mode == LDC_MODE_RAW && in ldc_tx()
935 lp->chan_state == LDC_CHANNEL_UP) { in ldc_tx()
936 lp->hs_state = LDC_HS_COMPLETE; in ldc_tx()
937 ldc_set_state(lp, LDC_STATE_CONNECTED); in ldc_tx()
942 spin_unlock_irqrestore(&lp->lock, flags); in ldc_tx()
944 send_events(lp, event_mask); in ldc_tx()
960 struct ldc_channel *lp; in __ldc_channel_exists() local
962 hlist_for_each_entry(lp, &ldc_channel_list, list) { in __ldc_channel_exists()
963 if (lp->id == id) in __ldc_channel_exists()
1035 static int ldc_iommu_init(const char *name, struct ldc_channel *lp) in ldc_iommu_init() argument
1038 struct ldc_iommu *ldc_iommu = &lp->iommu; in ldc_iommu_init()
1075 hv_err = sun4v_ldc_set_map_table(lp->id, __pa(table), in ldc_iommu_init()
1094 static void ldc_iommu_release(struct ldc_channel *lp) in ldc_iommu_release() argument
1096 struct ldc_iommu *ldc_iommu = &lp->iommu; in ldc_iommu_release()
1100 (void) sun4v_ldc_set_map_table(lp->id, 0, 0); in ldc_iommu_release()
1118 struct ldc_channel *lp; in ldc_alloc() local
1168 lp = kzalloc(sizeof(*lp), GFP_KERNEL); in ldc_alloc()
1170 if (!lp) in ldc_alloc()
1173 spin_lock_init(&lp->lock); in ldc_alloc()
1175 lp->id = id; in ldc_alloc()
1177 err = ldc_iommu_init(name, lp); in ldc_alloc()
1181 lp->mops = mops; in ldc_alloc()
1182 lp->mss = mss; in ldc_alloc()
1184 lp->cfg = *cfgp; in ldc_alloc()
1185 if (!lp->cfg.mtu) in ldc_alloc()
1186 lp->cfg.mtu = LDC_DEFAULT_MTU; in ldc_alloc()
1188 if (lp->cfg.mode == LDC_MODE_STREAM) { in ldc_alloc()
1189 mssbuf = kzalloc(lp->cfg.mtu, GFP_KERNEL); in ldc_alloc()
1194 lp->mssbuf = mssbuf; in ldc_alloc()
1197 lp->event_arg = event_arg; in ldc_alloc()
1202 lp->tx_num_entries = LDC_DEFAULT_NUM_ENTRIES; in ldc_alloc()
1203 lp->rx_num_entries = LDC_DEFAULT_NUM_ENTRIES; in ldc_alloc()
1205 err = alloc_queue("TX", lp->tx_num_entries, in ldc_alloc()
1206 &lp->tx_base, &lp->tx_ra); in ldc_alloc()
1210 err = alloc_queue("RX", lp->rx_num_entries, in ldc_alloc()
1211 &lp->rx_base, &lp->rx_ra); in ldc_alloc()
1215 lp->flags |= LDC_FLAG_ALLOCED_QUEUES; in ldc_alloc()
1217 lp->hs_state = LDC_HS_CLOSED; in ldc_alloc()
1218 ldc_set_state(lp, LDC_STATE_INIT); in ldc_alloc()
1220 INIT_HLIST_NODE(&lp->list); in ldc_alloc()
1221 hlist_add_head(&lp->list, &ldc_channel_list); in ldc_alloc()
1223 INIT_HLIST_HEAD(&lp->mh_list); in ldc_alloc()
1225 snprintf(lp->rx_irq_name, LDC_IRQ_NAME_MAX, "%s RX", name); in ldc_alloc()
1226 snprintf(lp->tx_irq_name, LDC_IRQ_NAME_MAX, "%s TX", name); in ldc_alloc()
1228 err = request_irq(lp->cfg.rx_irq, ldc_rx, 0, in ldc_alloc()
1229 lp->rx_irq_name, lp); in ldc_alloc()
1233 err = request_irq(lp->cfg.tx_irq, ldc_tx, 0, in ldc_alloc()
1234 lp->tx_irq_name, lp); in ldc_alloc()
1236 free_irq(lp->cfg.rx_irq, lp); in ldc_alloc()
1240 return lp; in ldc_alloc()
1243 free_queue(lp->tx_num_entries, lp->tx_base); in ldc_alloc()
1249 ldc_iommu_release(lp); in ldc_alloc()
1252 kfree(lp); in ldc_alloc()
1259 void ldc_unbind(struct ldc_channel *lp) in ldc_unbind() argument
1261 if (lp->flags & LDC_FLAG_REGISTERED_IRQS) { in ldc_unbind()
1262 free_irq(lp->cfg.rx_irq, lp); in ldc_unbind()
1263 free_irq(lp->cfg.tx_irq, lp); in ldc_unbind()
1264 lp->flags &= ~LDC_FLAG_REGISTERED_IRQS; in ldc_unbind()
1267 if (lp->flags & LDC_FLAG_REGISTERED_QUEUES) { in ldc_unbind()
1268 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_unbind()
1269 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_unbind()
1270 lp->flags &= ~LDC_FLAG_REGISTERED_QUEUES; in ldc_unbind()
1272 if (lp->flags & LDC_FLAG_ALLOCED_QUEUES) { in ldc_unbind()
1273 free_queue(lp->tx_num_entries, lp->tx_base); in ldc_unbind()
1274 free_queue(lp->rx_num_entries, lp->rx_base); in ldc_unbind()
1275 lp->flags &= ~LDC_FLAG_ALLOCED_QUEUES; in ldc_unbind()
1278 ldc_set_state(lp, LDC_STATE_INIT); in ldc_unbind()
1282 void ldc_free(struct ldc_channel *lp) in ldc_free() argument
1284 ldc_unbind(lp); in ldc_free()
1285 hlist_del(&lp->list); in ldc_free()
1286 kfree(lp->mssbuf); in ldc_free()
1287 ldc_iommu_release(lp); in ldc_free()
1289 kfree(lp); in ldc_free()
1298 int ldc_bind(struct ldc_channel *lp) in ldc_bind() argument
1303 if (lp->state != LDC_STATE_INIT) in ldc_bind()
1306 spin_lock_irqsave(&lp->lock, flags); in ldc_bind()
1308 enable_irq(lp->cfg.rx_irq); in ldc_bind()
1309 enable_irq(lp->cfg.tx_irq); in ldc_bind()
1311 lp->flags |= LDC_FLAG_REGISTERED_IRQS; in ldc_bind()
1314 hv_err = sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_bind()
1318 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_bind()
1322 hv_err = sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_bind()
1326 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_bind()
1330 lp->flags |= LDC_FLAG_REGISTERED_QUEUES; in ldc_bind()
1332 hv_err = sun4v_ldc_tx_get_state(lp->id, in ldc_bind()
1333 &lp->tx_head, in ldc_bind()
1334 &lp->tx_tail, in ldc_bind()
1335 &lp->chan_state); in ldc_bind()
1340 lp->tx_acked = lp->tx_head; in ldc_bind()
1342 lp->hs_state = LDC_HS_OPEN; in ldc_bind()
1343 ldc_set_state(lp, LDC_STATE_BOUND); in ldc_bind()
1345 spin_unlock_irqrestore(&lp->lock, flags); in ldc_bind()
1350 lp->flags &= ~LDC_FLAG_REGISTERED_QUEUES; in ldc_bind()
1351 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_bind()
1354 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_bind()
1357 lp->flags &= ~LDC_FLAG_REGISTERED_IRQS; in ldc_bind()
1358 free_irq(lp->cfg.tx_irq, lp); in ldc_bind()
1359 free_irq(lp->cfg.rx_irq, lp); in ldc_bind()
1361 spin_unlock_irqrestore(&lp->lock, flags); in ldc_bind()
1367 int ldc_connect(struct ldc_channel *lp) in ldc_connect() argument
1372 if (lp->cfg.mode == LDC_MODE_RAW) in ldc_connect()
1375 spin_lock_irqsave(&lp->lock, flags); in ldc_connect()
1377 if (!(lp->flags & LDC_FLAG_ALLOCED_QUEUES) || in ldc_connect()
1378 !(lp->flags & LDC_FLAG_REGISTERED_QUEUES) || in ldc_connect()
1379 lp->hs_state != LDC_HS_OPEN) in ldc_connect()
1380 err = ((lp->hs_state > LDC_HS_OPEN) ? 0 : -EINVAL); in ldc_connect()
1382 err = start_handshake(lp); in ldc_connect()
1384 spin_unlock_irqrestore(&lp->lock, flags); in ldc_connect()
1390 int ldc_disconnect(struct ldc_channel *lp) in ldc_disconnect() argument
1395 if (lp->cfg.mode == LDC_MODE_RAW) in ldc_disconnect()
1398 if (!(lp->flags & LDC_FLAG_ALLOCED_QUEUES) || in ldc_disconnect()
1399 !(lp->flags & LDC_FLAG_REGISTERED_QUEUES)) in ldc_disconnect()
1402 spin_lock_irqsave(&lp->lock, flags); in ldc_disconnect()
1405 hv_err = sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_disconnect()
1409 hv_err = sun4v_ldc_tx_qconf(lp->id, lp->tx_ra, lp->tx_num_entries); in ldc_disconnect()
1413 hv_err = sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_disconnect()
1417 hv_err = sun4v_ldc_rx_qconf(lp->id, lp->rx_ra, lp->rx_num_entries); in ldc_disconnect()
1421 ldc_set_state(lp, LDC_STATE_BOUND); in ldc_disconnect()
1422 lp->hs_state = LDC_HS_OPEN; in ldc_disconnect()
1423 lp->flags |= LDC_FLAG_RESET; in ldc_disconnect()
1425 spin_unlock_irqrestore(&lp->lock, flags); in ldc_disconnect()
1430 sun4v_ldc_tx_qconf(lp->id, 0, 0); in ldc_disconnect()
1431 sun4v_ldc_rx_qconf(lp->id, 0, 0); in ldc_disconnect()
1432 free_irq(lp->cfg.tx_irq, lp); in ldc_disconnect()
1433 free_irq(lp->cfg.rx_irq, lp); in ldc_disconnect()
1434 lp->flags &= ~(LDC_FLAG_REGISTERED_IRQS | in ldc_disconnect()
1436 ldc_set_state(lp, LDC_STATE_INIT); in ldc_disconnect()
1438 spin_unlock_irqrestore(&lp->lock, flags); in ldc_disconnect()
1444 int ldc_state(struct ldc_channel *lp) in ldc_state() argument
1446 return lp->state; in ldc_state()
1450 static int write_raw(struct ldc_channel *lp, const void *buf, unsigned int size) in write_raw() argument
1459 p = data_get_tx_packet(lp, &new_tail); in write_raw()
1465 err = send_tx_packet(lp, p, new_tail); in write_raw()
1472 static int read_raw(struct ldc_channel *lp, void *buf, unsigned int size) in read_raw() argument
1481 hv_err = sun4v_ldc_rx_get_state(lp->id, in read_raw()
1482 &lp->rx_head, in read_raw()
1483 &lp->rx_tail, in read_raw()
1484 &lp->chan_state); in read_raw()
1486 return ldc_abort(lp); in read_raw()
1488 if (lp->chan_state == LDC_CHANNEL_DOWN || in read_raw()
1489 lp->chan_state == LDC_CHANNEL_RESETTING) in read_raw()
1492 if (lp->rx_head == lp->rx_tail) in read_raw()
1495 p = lp->rx_base + (lp->rx_head / LDC_PACKET_SIZE); in read_raw()
1498 new = rx_advance(lp, lp->rx_head); in read_raw()
1499 lp->rx_head = new; in read_raw()
1501 err = __set_rx_head(lp, new); in read_raw()
1515 static int write_nonraw(struct ldc_channel *lp, const void *buf, in write_nonraw() argument
1523 hv_err = sun4v_ldc_tx_get_state(lp->id, &lp->tx_head, &lp->tx_tail, in write_nonraw()
1524 &lp->chan_state); in write_nonraw()
1528 if (unlikely(lp->chan_state != LDC_CHANNEL_UP)) in write_nonraw()
1529 return ldc_abort(lp); in write_nonraw()
1531 if (!tx_has_space_for(lp, size)) in write_nonraw()
1534 seq = lp->snd_nxt; in write_nonraw()
1536 tail = lp->tx_tail; in write_nonraw()
1538 struct ldc_packet *p = lp->tx_base + (tail / LDC_PACKET_SIZE); in write_nonraw()
1539 u8 *data = ((lp->cfg.mode == LDC_MODE_UNRELIABLE) ? in write_nonraw()
1549 if (data_len > lp->mss) in write_nonraw()
1550 data_len = lp->mss; in write_nonraw()
1571 tail = tx_advance(lp, tail); in write_nonraw()
1574 err = set_tx_tail(lp, tail); in write_nonraw()
1576 lp->snd_nxt = seq; in write_nonraw()
1583 static int rx_bad_seq(struct ldc_channel *lp, struct ldc_packet *p, in rx_bad_seq() argument
1589 lp->rcv_nxt = first_frag->seqid - 1; in rx_bad_seq()
1591 err = send_data_nack(lp, p); in rx_bad_seq()
1595 err = __set_rx_head(lp, lp->rx_tail); in rx_bad_seq()
1597 return ldc_abort(lp); in rx_bad_seq()
1602 static int data_ack_nack(struct ldc_channel *lp, struct ldc_packet *p) in data_ack_nack() argument
1605 int err = process_data_ack(lp, p); in data_ack_nack()
1610 return ldc_abort(lp); in data_ack_nack()
1615 static int rx_data_wait(struct ldc_channel *lp, unsigned long cur_head) in rx_data_wait() argument
1621 cur_head, lp->rx_head, lp->rx_tail); in rx_data_wait()
1625 hv_err = sun4v_ldc_rx_get_state(lp->id, in rx_data_wait()
1627 &lp->rx_tail, in rx_data_wait()
1628 &lp->chan_state); in rx_data_wait()
1630 return ldc_abort(lp); in rx_data_wait()
1632 if (lp->chan_state == LDC_CHANNEL_DOWN || in rx_data_wait()
1633 lp->chan_state == LDC_CHANNEL_RESETTING) in rx_data_wait()
1636 if (cur_head != lp->rx_tail) { in rx_data_wait()
1639 dummy, lp->rx_tail, lp->chan_state); in rx_data_wait()
1648 static int rx_set_head(struct ldc_channel *lp, unsigned long head) in rx_set_head() argument
1650 int err = __set_rx_head(lp, head); in rx_set_head()
1653 return ldc_abort(lp); in rx_set_head()
1655 lp->rx_head = head; in rx_set_head()
1659 static void send_data_ack(struct ldc_channel *lp) in send_data_ack() argument
1664 p = data_get_tx_packet(lp, &new_tail); in send_data_ack()
1672 p->seqid = lp->snd_nxt + 1; in send_data_ack()
1673 p->u.r.ackid = lp->rcv_nxt; in send_data_ack()
1675 err = send_tx_packet(lp, p, new_tail); in send_data_ack()
1677 lp->snd_nxt++; in send_data_ack()
1681 static int read_nonraw(struct ldc_channel *lp, void *buf, unsigned int size) in read_nonraw() argument
1687 hv_err = sun4v_ldc_rx_get_state(lp->id, in read_nonraw()
1688 &lp->rx_head, in read_nonraw()
1689 &lp->rx_tail, in read_nonraw()
1690 &lp->chan_state); in read_nonraw()
1692 return ldc_abort(lp); in read_nonraw()
1694 if (lp->chan_state == LDC_CHANNEL_DOWN || in read_nonraw()
1695 lp->chan_state == LDC_CHANNEL_RESETTING) in read_nonraw()
1698 if (lp->rx_head == lp->rx_tail) in read_nonraw()
1703 new = lp->rx_head; in read_nonraw()
1708 BUG_ON(new == lp->rx_tail); in read_nonraw()
1709 p = lp->rx_base + (new / LDC_PACKET_SIZE); in read_nonraw()
1719 lp->rcv_nxt); in read_nonraw()
1721 if (unlikely(!rx_seq_ok(lp, p->seqid))) { in read_nonraw()
1722 err = rx_bad_seq(lp, p, first_frag); in read_nonraw()
1728 err = process_control_frame(lp, p); in read_nonraw()
1734 lp->rcv_nxt = p->seqid; in read_nonraw()
1737 new = rx_advance(lp, new); in read_nonraw()
1741 err = data_ack_nack(lp, p); in read_nonraw()
1746 new = rx_advance(lp, new); in read_nonraw()
1747 err = rx_set_head(lp, new); in read_nonraw()
1771 new = rx_advance(lp, new); in read_nonraw()
1773 err = rx_set_head(lp, new); in read_nonraw()
1801 new = rx_advance(lp, new); in read_nonraw()
1804 (lp->cfg.mode == LDC_MODE_UNRELIABLE ? in read_nonraw()
1813 if (new == lp->rx_tail) { in read_nonraw()
1814 err = rx_data_wait(lp, new); in read_nonraw()
1821 err = rx_set_head(lp, new); in read_nonraw()
1824 lp->rcv_nxt = first_frag->seqid - 1; in read_nonraw()
1828 if (err > 0 && lp->cfg.mode != LDC_MODE_UNRELIABLE) in read_nonraw()
1829 send_data_ack(lp); in read_nonraw()
1840 static int write_stream(struct ldc_channel *lp, const void *buf, in write_stream() argument
1843 if (size > lp->cfg.mtu) in write_stream()
1844 size = lp->cfg.mtu; in write_stream()
1845 return write_nonraw(lp, buf, size); in write_stream()
1848 static int read_stream(struct ldc_channel *lp, void *buf, unsigned int size) in read_stream() argument
1850 if (!lp->mssbuf_len) { in read_stream()
1851 int err = read_nonraw(lp, lp->mssbuf, lp->cfg.mtu); in read_stream()
1855 lp->mssbuf_len = err; in read_stream()
1856 lp->mssbuf_off = 0; in read_stream()
1859 if (size > lp->mssbuf_len) in read_stream()
1860 size = lp->mssbuf_len; in read_stream()
1861 memcpy(buf, lp->mssbuf + lp->mssbuf_off, size); in read_stream()
1863 lp->mssbuf_off += size; in read_stream()
1864 lp->mssbuf_len -= size; in read_stream()
1874 int ldc_write(struct ldc_channel *lp, const void *buf, unsigned int size) in ldc_write() argument
1885 spin_lock_irqsave(&lp->lock, flags); in ldc_write()
1887 if (lp->hs_state != LDC_HS_COMPLETE) in ldc_write()
1890 err = lp->mops->write(lp, buf, size); in ldc_write()
1892 spin_unlock_irqrestore(&lp->lock, flags); in ldc_write()
1898 int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size) in ldc_read() argument
1909 spin_lock_irqsave(&lp->lock, flags); in ldc_read()
1911 if (lp->hs_state != LDC_HS_COMPLETE) in ldc_read()
1914 err = lp->mops->read(lp, buf, size); in ldc_read()
1916 spin_unlock_irqrestore(&lp->lock, flags); in ldc_read()
2079 int ldc_map_sg(struct ldc_channel *lp, in ldc_map_sg() argument
2101 iommu = &lp->iommu; in ldc_map_sg()
2123 int ldc_map_single(struct ldc_channel *lp, in ldc_map_single() argument
2142 iommu = &lp->iommu; in ldc_map_single()
2175 void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies, in ldc_unmap() argument
2178 struct ldc_iommu *iommu = &lp->iommu; in ldc_unmap()
2187 free_npages(lp->id, iommu, addr, size); in ldc_unmap()
2193 int ldc_copy(struct ldc_channel *lp, int copy_dir, in ldc_copy() argument
2203 lp->id, copy_dir); in ldc_copy()
2211 lp->id, ra, len, offset); in ldc_copy()
2215 if (lp->hs_state != LDC_HS_COMPLETE || in ldc_copy()
2216 (lp->flags & LDC_FLAG_RESET)) { in ldc_copy()
2218 "flags[%x]\n", lp->id, lp->hs_state, lp->flags); in ldc_copy()
2247 hv_err = sun4v_ldc_copy(lp->id, copy_dir, in ldc_copy()
2253 lp->id, hv_err); in ldc_copy()
2254 if (lp->hs_state != LDC_HS_COMPLETE || in ldc_copy()
2255 (lp->flags & LDC_FLAG_RESET)) in ldc_copy()
2283 void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len, in ldc_alloc_exp_dring() argument
2297 err = ldc_map_single(lp, buf, len, cookies, *ncookies, map_perm); in ldc_alloc_exp_dring()
2308 void ldc_free_exp_dring(struct ldc_channel *lp, void *buf, unsigned int len, in ldc_free_exp_dring() argument
2311 ldc_unmap(lp, cookies, ncookies); in ldc_free_exp_dring()