Lines Matching refs:sndev
98 static int switchtec_ntb_part_op(struct switchtec_ntb *sndev, in switchtec_ntb_part_op() argument
144 dev_err(&sndev->stdev->dev, in switchtec_ntb_part_op()
155 static int switchtec_ntb_send_msg(struct switchtec_ntb *sndev, int idx, in switchtec_ntb_send_msg() argument
158 if (idx < 0 || idx >= ARRAY_SIZE(sndev->mmio_peer_dbmsg->omsg)) in switchtec_ntb_send_msg()
161 iowrite32(val, &sndev->mmio_peer_dbmsg->omsg[idx].msg); in switchtec_ntb_send_msg()
168 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_mw_count() local
169 int nr_direct_mw = sndev->peer_nr_direct_mw; in switchtec_ntb_mw_count()
170 int nr_lut_mw = sndev->peer_nr_lut_mw - sndev->nr_rsvd_luts; in switchtec_ntb_mw_count()
181 static int lut_index(struct switchtec_ntb *sndev, int mw_idx) in lut_index() argument
183 return mw_idx - sndev->nr_direct_mw + sndev->nr_rsvd_luts; in lut_index()
186 static int peer_lut_index(struct switchtec_ntb *sndev, int mw_idx) in peer_lut_index() argument
188 return mw_idx - sndev->peer_nr_direct_mw + sndev->nr_rsvd_luts; in peer_lut_index()
196 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_mw_get_align() local
203 lut = widx >= sndev->peer_nr_direct_mw; in switchtec_ntb_mw_get_align()
204 size = ioread64(&sndev->peer_shared->mw_sizes[widx]); in switchtec_ntb_mw_get_align()
221 static void switchtec_ntb_mw_clr_direct(struct switchtec_ntb *sndev, int idx) in switchtec_ntb_mw_clr_direct() argument
223 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl; in switchtec_ntb_mw_clr_direct()
224 int bar = sndev->peer_direct_mw_to_bar[idx]; in switchtec_ntb_mw_clr_direct()
232 iowrite64(sndev->self_partition, &ctl->bar_entry[bar].xlate_addr); in switchtec_ntb_mw_clr_direct()
235 static void switchtec_ntb_mw_clr_lut(struct switchtec_ntb *sndev, int idx) in switchtec_ntb_mw_clr_lut() argument
237 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl; in switchtec_ntb_mw_clr_lut()
239 iowrite64(0, &ctl->lut_entry[peer_lut_index(sndev, idx)]); in switchtec_ntb_mw_clr_lut()
242 static void switchtec_ntb_mw_set_direct(struct switchtec_ntb *sndev, int idx, in switchtec_ntb_mw_set_direct() argument
246 int bar = sndev->peer_direct_mw_to_bar[idx]; in switchtec_ntb_mw_set_direct()
247 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl; in switchtec_ntb_mw_set_direct()
257 iowrite64(sndev->self_partition | addr, in switchtec_ntb_mw_set_direct()
261 static void switchtec_ntb_mw_set_lut(struct switchtec_ntb *sndev, int idx, in switchtec_ntb_mw_set_lut() argument
264 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl; in switchtec_ntb_mw_set_lut()
266 iowrite64((NTB_CTRL_LUT_EN | (sndev->self_partition << 1) | addr), in switchtec_ntb_mw_set_lut()
267 &ctl->lut_entry[peer_lut_index(sndev, idx)]); in switchtec_ntb_mw_set_lut()
273 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_mw_set_trans() local
274 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl; in switchtec_ntb_mw_set_trans()
276 int nr_direct_mw = sndev->peer_nr_direct_mw; in switchtec_ntb_mw_set_trans()
282 dev_dbg(&sndev->stdev->dev, "MW %d: part %d addr %pad size %pap\n", in switchtec_ntb_mw_set_trans()
299 dev_err(&sndev->stdev->dev, in switchtec_ntb_mw_set_trans()
304 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK, in switchtec_ntb_mw_set_trans()
311 switchtec_ntb_mw_clr_direct(sndev, widx); in switchtec_ntb_mw_set_trans()
313 switchtec_ntb_mw_clr_lut(sndev, widx); in switchtec_ntb_mw_set_trans()
316 switchtec_ntb_mw_set_direct(sndev, widx, addr, size); in switchtec_ntb_mw_set_trans()
318 switchtec_ntb_mw_set_lut(sndev, widx, addr, size); in switchtec_ntb_mw_set_trans()
321 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_CFG, in switchtec_ntb_mw_set_trans()
325 dev_err(&sndev->stdev->dev, in switchtec_ntb_mw_set_trans()
330 switchtec_ntb_mw_clr_direct(sndev, widx); in switchtec_ntb_mw_set_trans()
332 switchtec_ntb_mw_clr_lut(sndev, widx); in switchtec_ntb_mw_set_trans()
334 switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_CFG, in switchtec_ntb_mw_set_trans()
343 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_mw_count() local
344 int nr_lut_mw = sndev->nr_lut_mw - sndev->nr_rsvd_luts; in switchtec_ntb_peer_mw_count()
346 return sndev->nr_direct_mw + (use_lut_mws ? nr_lut_mw : 0); in switchtec_ntb_peer_mw_count()
349 static int switchtec_ntb_direct_get_addr(struct switchtec_ntb *sndev, in switchtec_ntb_direct_get_addr() argument
353 int bar = sndev->direct_mw_to_bar[idx]; in switchtec_ntb_direct_get_addr()
366 offset = LUT_SIZE * sndev->nr_lut_mw; in switchtec_ntb_direct_get_addr()
370 *base = pci_resource_start(sndev->ntb.pdev, bar) + offset; in switchtec_ntb_direct_get_addr()
373 *size = pci_resource_len(sndev->ntb.pdev, bar) - offset; in switchtec_ntb_direct_get_addr()
384 static int switchtec_ntb_lut_get_addr(struct switchtec_ntb *sndev, in switchtec_ntb_lut_get_addr() argument
388 int bar = sndev->direct_mw_to_bar[0]; in switchtec_ntb_lut_get_addr()
391 offset = LUT_SIZE * lut_index(sndev, idx); in switchtec_ntb_lut_get_addr()
394 *base = pci_resource_start(sndev->ntb.pdev, bar) + offset; in switchtec_ntb_lut_get_addr()
406 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_mw_get_addr() local
408 if (idx < sndev->nr_direct_mw) in switchtec_ntb_peer_mw_get_addr()
409 return switchtec_ntb_direct_get_addr(sndev, idx, base, size); in switchtec_ntb_peer_mw_get_addr()
411 return switchtec_ntb_lut_get_addr(sndev, idx, base, size); in switchtec_ntb_peer_mw_get_addr()
416 static void switchtec_ntb_part_link_speed(struct switchtec_ntb *sndev, in switchtec_ntb_part_link_speed() argument
421 struct switchtec_dev *stdev = sndev->stdev; in switchtec_ntb_part_link_speed()
435 static void switchtec_ntb_set_link_speed(struct switchtec_ntb *sndev) in switchtec_ntb_set_link_speed() argument
440 if (!sndev->link_is_up) { in switchtec_ntb_set_link_speed()
441 sndev->link_speed = NTB_SPEED_NONE; in switchtec_ntb_set_link_speed()
442 sndev->link_width = NTB_WIDTH_NONE; in switchtec_ntb_set_link_speed()
446 switchtec_ntb_part_link_speed(sndev, sndev->self_partition, in switchtec_ntb_set_link_speed()
448 switchtec_ntb_part_link_speed(sndev, sndev->peer_partition, in switchtec_ntb_set_link_speed()
451 sndev->link_speed = min(self_speed, peer_speed); in switchtec_ntb_set_link_speed()
452 sndev->link_width = min(self_width, peer_width); in switchtec_ntb_set_link_speed()
455 static int crosslink_is_enabled(struct switchtec_ntb *sndev) in crosslink_is_enabled() argument
457 struct ntb_info_regs __iomem *inf = sndev->mmio_ntb; in crosslink_is_enabled()
459 return ioread8(&inf->ntp_info[sndev->peer_partition].xlink_enabled); in crosslink_is_enabled()
462 static void crosslink_init_dbmsgs(struct switchtec_ntb *sndev) in crosslink_init_dbmsgs() argument
467 if (!crosslink_is_enabled(sndev)) in crosslink_init_dbmsgs()
470 for (i = 0; i < ARRAY_SIZE(sndev->mmio_peer_dbmsg->imsg); i++) { in crosslink_init_dbmsgs()
471 int m = i | sndev->self_partition << 2; in crosslink_init_dbmsgs()
476 iowrite32(msg_map, &sndev->mmio_peer_dbmsg->msg_map); in crosslink_init_dbmsgs()
477 iowrite64(sndev->db_valid_mask << sndev->db_peer_shift, in crosslink_init_dbmsgs()
478 &sndev->mmio_peer_dbmsg->odb_mask); in crosslink_init_dbmsgs()
489 static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev);
491 static void switchtec_ntb_link_status_update(struct switchtec_ntb *sndev) in switchtec_ntb_link_status_update() argument
494 int old = sndev->link_is_up; in switchtec_ntb_link_status_update()
496 link_sta = sndev->self_shared->link_sta; in switchtec_ntb_link_status_update()
498 u64 peer = ioread64(&sndev->peer_shared->magic); in switchtec_ntb_link_status_update()
506 sndev->link_is_up = link_sta; in switchtec_ntb_link_status_update()
507 switchtec_ntb_set_link_speed(sndev); in switchtec_ntb_link_status_update()
510 switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_CHECK_LINK); in switchtec_ntb_link_status_update()
511 ntb_link_event(&sndev->ntb); in switchtec_ntb_link_status_update()
512 dev_info(&sndev->stdev->dev, "ntb link %s\n", in switchtec_ntb_link_status_update()
516 crosslink_init_dbmsgs(sndev); in switchtec_ntb_link_status_update()
522 struct switchtec_ntb *sndev; in check_link_status_work() local
524 sndev = container_of(work, struct switchtec_ntb, in check_link_status_work()
527 if (sndev->link_force_down) { in check_link_status_work()
528 sndev->link_force_down = false; in check_link_status_work()
529 switchtec_ntb_reinit_peer(sndev); in check_link_status_work()
531 if (sndev->link_is_up) { in check_link_status_work()
532 sndev->link_is_up = 0; in check_link_status_work()
533 ntb_link_event(&sndev->ntb); in check_link_status_work()
534 dev_info(&sndev->stdev->dev, "ntb link forced down\n"); in check_link_status_work()
540 switchtec_ntb_link_status_update(sndev); in check_link_status_work()
543 static void switchtec_ntb_check_link(struct switchtec_ntb *sndev, in switchtec_ntb_check_link() argument
547 sndev->link_force_down = true; in switchtec_ntb_check_link()
549 schedule_work(&sndev->check_link_status_work); in switchtec_ntb_check_link()
554 struct switchtec_ntb *sndev = stdev->sndev; in switchtec_ntb_link_notification() local
556 switchtec_ntb_check_link(sndev, MSG_CHECK_LINK); in switchtec_ntb_link_notification()
563 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_link_is_up() local
566 *speed = sndev->link_speed; in switchtec_ntb_link_is_up()
568 *width = sndev->link_width; in switchtec_ntb_link_is_up()
570 return sndev->link_is_up; in switchtec_ntb_link_is_up()
577 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_link_enable() local
579 dev_dbg(&sndev->stdev->dev, "enabling link\n"); in switchtec_ntb_link_enable()
581 sndev->self_shared->link_sta = 1; in switchtec_ntb_link_enable()
582 switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_UP); in switchtec_ntb_link_enable()
584 switchtec_ntb_link_status_update(sndev); in switchtec_ntb_link_enable()
591 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_link_disable() local
593 dev_dbg(&sndev->stdev->dev, "disabling link\n"); in switchtec_ntb_link_disable()
595 sndev->self_shared->link_sta = 0; in switchtec_ntb_link_disable()
596 switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_DOWN); in switchtec_ntb_link_disable()
598 switchtec_ntb_link_status_update(sndev); in switchtec_ntb_link_disable()
605 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_valid_mask() local
607 return sndev->db_valid_mask; in switchtec_ntb_db_valid_mask()
617 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_vector_mask() local
622 return sndev->db_valid_mask; in switchtec_ntb_db_vector_mask()
628 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_read() local
630 ret = ioread64(&sndev->mmio_self_dbmsg->idb) >> sndev->db_shift; in switchtec_ntb_db_read()
632 return ret & sndev->db_valid_mask; in switchtec_ntb_db_read()
637 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_clear() local
639 iowrite64(db_bits << sndev->db_shift, &sndev->mmio_self_dbmsg->idb); in switchtec_ntb_db_clear()
647 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_set_mask() local
649 if (db_bits & ~sndev->db_valid_mask) in switchtec_ntb_db_set_mask()
652 spin_lock_irqsave(&sndev->db_mask_lock, irqflags); in switchtec_ntb_db_set_mask()
654 sndev->db_mask |= db_bits << sndev->db_shift; in switchtec_ntb_db_set_mask()
655 iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask); in switchtec_ntb_db_set_mask()
657 spin_unlock_irqrestore(&sndev->db_mask_lock, irqflags); in switchtec_ntb_db_set_mask()
665 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_clear_mask() local
667 if (db_bits & ~sndev->db_valid_mask) in switchtec_ntb_db_clear_mask()
670 spin_lock_irqsave(&sndev->db_mask_lock, irqflags); in switchtec_ntb_db_clear_mask()
672 sndev->db_mask &= ~(db_bits << sndev->db_shift); in switchtec_ntb_db_clear_mask()
673 iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask); in switchtec_ntb_db_clear_mask()
675 spin_unlock_irqrestore(&sndev->db_mask_lock, irqflags); in switchtec_ntb_db_clear_mask()
682 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_db_read_mask() local
684 return (sndev->db_mask >> sndev->db_shift) & sndev->db_valid_mask; in switchtec_ntb_db_read_mask()
693 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_db_addr() local
699 offset = (unsigned long)sndev->mmio_peer_dbmsg->odb - in switchtec_ntb_peer_db_addr()
700 (unsigned long)sndev->stdev->mmio; in switchtec_ntb_peer_db_addr()
702 offset += sndev->db_shift / 8; in switchtec_ntb_peer_db_addr()
709 *db_data = BIT_ULL(db_bit) << sndev->db_peer_shift; in switchtec_ntb_peer_db_addr()
716 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_db_set() local
718 iowrite64(db_bits << sndev->db_peer_shift, in switchtec_ntb_peer_db_set()
719 &sndev->mmio_peer_dbmsg->odb); in switchtec_ntb_peer_db_set()
726 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_spad_count() local
728 return ARRAY_SIZE(sndev->self_shared->spad); in switchtec_ntb_spad_count()
733 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_spad_read() local
735 if (idx < 0 || idx >= ARRAY_SIZE(sndev->self_shared->spad)) in switchtec_ntb_spad_read()
738 if (!sndev->self_shared) in switchtec_ntb_spad_read()
741 return sndev->self_shared->spad[idx]; in switchtec_ntb_spad_read()
746 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_spad_write() local
748 if (idx < 0 || idx >= ARRAY_SIZE(sndev->self_shared->spad)) in switchtec_ntb_spad_write()
751 if (!sndev->self_shared) in switchtec_ntb_spad_write()
754 sndev->self_shared->spad[idx] = val; in switchtec_ntb_spad_write()
762 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_spad_read() local
767 if (sidx < 0 || sidx >= ARRAY_SIZE(sndev->peer_shared->spad)) in switchtec_ntb_peer_spad_read()
770 if (!sndev->peer_shared) in switchtec_ntb_peer_spad_read()
773 return ioread32(&sndev->peer_shared->spad[sidx]); in switchtec_ntb_peer_spad_read()
779 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_spad_write() local
784 if (sidx < 0 || sidx >= ARRAY_SIZE(sndev->peer_shared->spad)) in switchtec_ntb_peer_spad_write()
787 if (!sndev->peer_shared) in switchtec_ntb_peer_spad_write()
790 iowrite32(val, &sndev->peer_shared->spad[sidx]); in switchtec_ntb_peer_spad_write()
798 struct switchtec_ntb *sndev = ntb_sndev(ntb); in switchtec_ntb_peer_spad_addr() local
804 offset = (unsigned long)&sndev->peer_shared->spad[sidx] - in switchtec_ntb_peer_spad_addr()
805 (unsigned long)sndev->stdev->mmio; in switchtec_ntb_peer_spad_addr()
840 static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev) in switchtec_ntb_init_sndev() argument
846 sndev->ntb.pdev = sndev->stdev->pdev; in switchtec_ntb_init_sndev()
847 sndev->ntb.topo = NTB_TOPO_SWITCH; in switchtec_ntb_init_sndev()
848 sndev->ntb.ops = &switchtec_ntb_ops; in switchtec_ntb_init_sndev()
850 INIT_WORK(&sndev->check_link_status_work, check_link_status_work); in switchtec_ntb_init_sndev()
851 sndev->link_force_down = false; in switchtec_ntb_init_sndev()
853 sndev->self_partition = sndev->stdev->partition; in switchtec_ntb_init_sndev()
855 sndev->mmio_ntb = sndev->stdev->mmio_ntb; in switchtec_ntb_init_sndev()
857 self = sndev->self_partition; in switchtec_ntb_init_sndev()
858 tpart_vec = ioread32(&sndev->mmio_ntb->ntp_info[self].target_part_high); in switchtec_ntb_init_sndev()
860 tpart_vec |= ioread32(&sndev->mmio_ntb->ntp_info[self].target_part_low); in switchtec_ntb_init_sndev()
862 part_map = ioread64(&sndev->mmio_ntb->ep_map); in switchtec_ntb_init_sndev()
864 part_map &= ~(1 << sndev->self_partition); in switchtec_ntb_init_sndev()
867 if (sndev->stdev->partition_count != 2) { in switchtec_ntb_init_sndev()
868 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_sndev()
874 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_sndev()
879 sndev->peer_partition = __ffs64(part_map); in switchtec_ntb_init_sndev()
882 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_sndev()
887 sndev->peer_partition = __ffs64(tpart_vec); in switchtec_ntb_init_sndev()
888 if (!(part_map & (1ULL << sndev->peer_partition))) { in switchtec_ntb_init_sndev()
889 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_sndev()
895 dev_dbg(&sndev->stdev->dev, "Partition ID %d of %d\n", in switchtec_ntb_init_sndev()
896 sndev->self_partition, sndev->stdev->partition_count); in switchtec_ntb_init_sndev()
898 sndev->mmio_ctrl = (void * __iomem)sndev->mmio_ntb + in switchtec_ntb_init_sndev()
900 sndev->mmio_dbmsg = (void * __iomem)sndev->mmio_ntb + in switchtec_ntb_init_sndev()
903 sndev->mmio_self_ctrl = &sndev->mmio_ctrl[sndev->self_partition]; in switchtec_ntb_init_sndev()
904 sndev->mmio_peer_ctrl = &sndev->mmio_ctrl[sndev->peer_partition]; in switchtec_ntb_init_sndev()
905 sndev->mmio_self_dbmsg = &sndev->mmio_dbmsg[sndev->self_partition]; in switchtec_ntb_init_sndev()
906 sndev->mmio_peer_dbmsg = sndev->mmio_self_dbmsg; in switchtec_ntb_init_sndev()
911 static int config_rsvd_lut_win(struct switchtec_ntb *sndev, in config_rsvd_lut_win() argument
915 int peer_bar = sndev->peer_direct_mw_to_bar[0]; in config_rsvd_lut_win()
919 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK, in config_rsvd_lut_win()
928 ctl_val |= (sndev->nr_lut_mw - 1) << 14; in config_rsvd_lut_win()
934 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_CFG, in config_rsvd_lut_win()
941 dev_err(&sndev->stdev->dev, in config_rsvd_lut_win()
950 static int config_req_id_table(struct switchtec_ntb *sndev, in config_req_id_table() argument
959 dev_err(&sndev->stdev->dev, in config_req_id_table()
964 rc = switchtec_ntb_part_op(sndev, mmio_ctrl, in config_req_id_table()
975 dev_dbg(&sndev->stdev->dev, in config_req_id_table()
982 rc = switchtec_ntb_part_op(sndev, mmio_ctrl, in config_req_id_table()
988 dev_err(&sndev->stdev->dev, in config_req_id_table()
996 static int crosslink_setup_mws(struct switchtec_ntb *sndev, int ntb_lut_idx, in crosslink_setup_mws() argument
1000 struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_self_ctrl; in crosslink_setup_mws()
1007 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK, in crosslink_setup_mws()
1012 for (i = 0; i < sndev->nr_lut_mw; i++) { in crosslink_setup_mws()
1018 iowrite64((NTB_CTRL_LUT_EN | (sndev->peer_partition << 1) | in crosslink_setup_mws()
1023 sndev->nr_direct_mw = min_t(int, sndev->nr_direct_mw, mw_count); in crosslink_setup_mws()
1025 for (i = 0; i < sndev->nr_direct_mw; i++) { in crosslink_setup_mws()
1026 bar = sndev->direct_mw_to_bar[i]; in crosslink_setup_mws()
1027 offset = (i == 0) ? LUT_SIZE * sndev->nr_lut_mw : 0; in crosslink_setup_mws()
1029 size = pci_resource_len(sndev->ntb.pdev, bar) - offset; in crosslink_setup_mws()
1042 iowrite64(sndev->peer_partition | addr, in crosslink_setup_mws()
1046 rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_CFG, in crosslink_setup_mws()
1053 dev_err(&sndev->stdev->dev, in crosslink_setup_mws()
1062 static int crosslink_setup_req_ids(struct switchtec_ntb *sndev, in crosslink_setup_req_ids() argument
1070 proxy_id = ioread32(&sndev->mmio_self_ctrl->req_id_table[i]); in crosslink_setup_req_ids()
1078 return config_req_id_table(sndev, mmio_ctrl, req_ids, i); in crosslink_setup_req_ids()
1086 static int crosslink_enum_partition(struct switchtec_ntb *sndev, in crosslink_enum_partition() argument
1090 &sndev->stdev->mmio_part_cfg_all[sndev->peer_partition]; in crosslink_enum_partition()
1093 &sndev->stdev->mmio_pff_csr[pff]; in crosslink_enum_partition()
1106 dev_dbg(&sndev->stdev->dev, in crosslink_enum_partition()
1119 static int switchtec_ntb_init_crosslink(struct switchtec_ntb *sndev) in switchtec_ntb_init_crosslink() argument
1122 int bar = sndev->direct_mw_to_bar[0]; in switchtec_ntb_init_crosslink()
1129 if (!crosslink_is_enabled(sndev)) in switchtec_ntb_init_crosslink()
1132 dev_info(&sndev->stdev->dev, "Using crosslink configuration\n"); in switchtec_ntb_init_crosslink()
1133 sndev->ntb.topo = NTB_TOPO_CROSSLINK; in switchtec_ntb_init_crosslink()
1135 bar_cnt = crosslink_enum_partition(sndev, bar_addrs); in switchtec_ntb_init_crosslink()
1136 if (bar_cnt < sndev->nr_direct_mw + 1) { in switchtec_ntb_init_crosslink()
1137 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_crosslink()
1144 sizeof(struct ntb_dbmsg_regs) * sndev->peer_partition); in switchtec_ntb_init_crosslink()
1149 rc = config_rsvd_lut_win(sndev, sndev->mmio_self_ctrl, ntb_lut_idx, in switchtec_ntb_init_crosslink()
1150 sndev->peer_partition, addr); in switchtec_ntb_init_crosslink()
1154 rc = crosslink_setup_mws(sndev, ntb_lut_idx, &bar_addrs[1], in switchtec_ntb_init_crosslink()
1159 rc = crosslink_setup_req_ids(sndev, sndev->mmio_peer_ctrl); in switchtec_ntb_init_crosslink()
1163 sndev->mmio_xlink_win = pci_iomap_range(sndev->stdev->pdev, bar, in switchtec_ntb_init_crosslink()
1165 if (!sndev->mmio_xlink_win) { in switchtec_ntb_init_crosslink()
1170 sndev->mmio_peer_dbmsg = sndev->mmio_xlink_win + offset; in switchtec_ntb_init_crosslink()
1171 sndev->nr_rsvd_luts++; in switchtec_ntb_init_crosslink()
1173 crosslink_init_dbmsgs(sndev); in switchtec_ntb_init_crosslink()
1178 static void switchtec_ntb_deinit_crosslink(struct switchtec_ntb *sndev) in switchtec_ntb_deinit_crosslink() argument
1180 if (sndev->mmio_xlink_win) in switchtec_ntb_deinit_crosslink()
1181 pci_iounmap(sndev->stdev->pdev, sndev->mmio_xlink_win); in switchtec_ntb_deinit_crosslink()
1199 static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev) in switchtec_ntb_init_mw() argument
1201 sndev->nr_direct_mw = map_bars(sndev->direct_mw_to_bar, in switchtec_ntb_init_mw()
1202 sndev->mmio_self_ctrl); in switchtec_ntb_init_mw()
1204 sndev->nr_lut_mw = ioread16(&sndev->mmio_self_ctrl->lut_table_entries); in switchtec_ntb_init_mw()
1205 sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw); in switchtec_ntb_init_mw()
1207 dev_dbg(&sndev->stdev->dev, "MWs: %d direct, %d lut\n", in switchtec_ntb_init_mw()
1208 sndev->nr_direct_mw, sndev->nr_lut_mw); in switchtec_ntb_init_mw()
1210 sndev->peer_nr_direct_mw = map_bars(sndev->peer_direct_mw_to_bar, in switchtec_ntb_init_mw()
1211 sndev->mmio_peer_ctrl); in switchtec_ntb_init_mw()
1213 sndev->peer_nr_lut_mw = in switchtec_ntb_init_mw()
1214 ioread16(&sndev->mmio_peer_ctrl->lut_table_entries); in switchtec_ntb_init_mw()
1215 sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw); in switchtec_ntb_init_mw()
1217 dev_dbg(&sndev->stdev->dev, "Peer MWs: %d direct, %d lut\n", in switchtec_ntb_init_mw()
1218 sndev->peer_nr_direct_mw, sndev->peer_nr_lut_mw); in switchtec_ntb_init_mw()
1232 static void switchtec_ntb_init_db(struct switchtec_ntb *sndev) in switchtec_ntb_init_db() argument
1234 sndev->db_mask = 0x0FFFFFFFFFFFFFFFULL; in switchtec_ntb_init_db()
1236 if (sndev->mmio_peer_dbmsg != sndev->mmio_self_dbmsg) { in switchtec_ntb_init_db()
1237 sndev->db_shift = 0; in switchtec_ntb_init_db()
1238 sndev->db_peer_shift = 0; in switchtec_ntb_init_db()
1239 sndev->db_valid_mask = sndev->db_mask; in switchtec_ntb_init_db()
1240 } else if (sndev->self_partition < sndev->peer_partition) { in switchtec_ntb_init_db()
1241 sndev->db_shift = 0; in switchtec_ntb_init_db()
1242 sndev->db_peer_shift = 32; in switchtec_ntb_init_db()
1243 sndev->db_valid_mask = 0x0FFFFFFF; in switchtec_ntb_init_db()
1245 sndev->db_shift = 32; in switchtec_ntb_init_db()
1246 sndev->db_peer_shift = 0; in switchtec_ntb_init_db()
1247 sndev->db_valid_mask = 0x0FFFFFFF; in switchtec_ntb_init_db()
1250 iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask); in switchtec_ntb_init_db()
1251 iowrite64(sndev->db_valid_mask << sndev->db_peer_shift, in switchtec_ntb_init_db()
1252 &sndev->mmio_peer_dbmsg->odb_mask); in switchtec_ntb_init_db()
1254 dev_dbg(&sndev->stdev->dev, "dbs: shift %d/%d, mask %016llx\n", in switchtec_ntb_init_db()
1255 sndev->db_shift, sndev->db_peer_shift, sndev->db_valid_mask); in switchtec_ntb_init_db()
1258 static void switchtec_ntb_init_msgs(struct switchtec_ntb *sndev) in switchtec_ntb_init_msgs() argument
1263 for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++) { in switchtec_ntb_init_msgs()
1264 int m = i | sndev->peer_partition << 2; in switchtec_ntb_init_msgs()
1269 iowrite32(msg_map, &sndev->mmio_self_dbmsg->msg_map); in switchtec_ntb_init_msgs()
1271 for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++) in switchtec_ntb_init_msgs()
1273 &sndev->mmio_self_dbmsg->imsg[i]); in switchtec_ntb_init_msgs()
1277 switchtec_ntb_init_req_id_table(struct switchtec_ntb *sndev) in switchtec_ntb_init_req_id_table() argument
1289 req_ids[1] = ioread16(&sndev->mmio_ntb->requester_id); in switchtec_ntb_init_req_id_table()
1291 return config_req_id_table(sndev, sndev->mmio_self_ctrl, req_ids, in switchtec_ntb_init_req_id_table()
1295 static void switchtec_ntb_init_shared(struct switchtec_ntb *sndev) in switchtec_ntb_init_shared() argument
1299 memset(sndev->self_shared, 0, LUT_SIZE); in switchtec_ntb_init_shared()
1300 sndev->self_shared->magic = SWITCHTEC_NTB_MAGIC; in switchtec_ntb_init_shared()
1301 sndev->self_shared->partition_id = sndev->stdev->partition; in switchtec_ntb_init_shared()
1303 for (i = 0; i < sndev->nr_direct_mw; i++) { in switchtec_ntb_init_shared()
1304 int bar = sndev->direct_mw_to_bar[i]; in switchtec_ntb_init_shared()
1305 resource_size_t sz = pci_resource_len(sndev->stdev->pdev, bar); in switchtec_ntb_init_shared()
1309 LUT_SIZE * sndev->nr_lut_mw); in switchtec_ntb_init_shared()
1311 sndev->self_shared->mw_sizes[i] = sz; in switchtec_ntb_init_shared()
1314 for (i = 0; i < sndev->nr_lut_mw; i++) { in switchtec_ntb_init_shared()
1315 int idx = sndev->nr_direct_mw + i; in switchtec_ntb_init_shared()
1317 sndev->self_shared->mw_sizes[idx] = LUT_SIZE; in switchtec_ntb_init_shared()
1321 static int switchtec_ntb_init_shared_mw(struct switchtec_ntb *sndev) in switchtec_ntb_init_shared_mw() argument
1323 int self_bar = sndev->direct_mw_to_bar[0]; in switchtec_ntb_init_shared_mw()
1326 sndev->nr_rsvd_luts++; in switchtec_ntb_init_shared_mw()
1327 sndev->self_shared = dma_alloc_coherent(&sndev->stdev->pdev->dev, in switchtec_ntb_init_shared_mw()
1329 &sndev->self_shared_dma, in switchtec_ntb_init_shared_mw()
1331 if (!sndev->self_shared) { in switchtec_ntb_init_shared_mw()
1332 dev_err(&sndev->stdev->dev, in switchtec_ntb_init_shared_mw()
1337 switchtec_ntb_init_shared(sndev); in switchtec_ntb_init_shared_mw()
1339 rc = config_rsvd_lut_win(sndev, sndev->mmio_peer_ctrl, 0, in switchtec_ntb_init_shared_mw()
1340 sndev->self_partition, in switchtec_ntb_init_shared_mw()
1341 sndev->self_shared_dma); in switchtec_ntb_init_shared_mw()
1345 sndev->peer_shared = pci_iomap(sndev->stdev->pdev, self_bar, LUT_SIZE); in switchtec_ntb_init_shared_mw()
1346 if (!sndev->peer_shared) { in switchtec_ntb_init_shared_mw()
1351 dev_dbg(&sndev->stdev->dev, "Shared MW Ready\n"); in switchtec_ntb_init_shared_mw()
1355 dma_free_coherent(&sndev->stdev->pdev->dev, LUT_SIZE, in switchtec_ntb_init_shared_mw()
1356 sndev->self_shared, sndev->self_shared_dma); in switchtec_ntb_init_shared_mw()
1361 static void switchtec_ntb_deinit_shared_mw(struct switchtec_ntb *sndev) in switchtec_ntb_deinit_shared_mw() argument
1363 if (sndev->peer_shared) in switchtec_ntb_deinit_shared_mw()
1364 pci_iounmap(sndev->stdev->pdev, sndev->peer_shared); in switchtec_ntb_deinit_shared_mw()
1366 if (sndev->self_shared) in switchtec_ntb_deinit_shared_mw()
1367 dma_free_coherent(&sndev->stdev->pdev->dev, LUT_SIZE, in switchtec_ntb_deinit_shared_mw()
1368 sndev->self_shared, in switchtec_ntb_deinit_shared_mw()
1369 sndev->self_shared_dma); in switchtec_ntb_deinit_shared_mw()
1370 sndev->nr_rsvd_luts--; in switchtec_ntb_deinit_shared_mw()
1375 struct switchtec_ntb *sndev = dev; in switchtec_ntb_doorbell_isr() local
1377 dev_dbg(&sndev->stdev->dev, "doorbell\n"); in switchtec_ntb_doorbell_isr()
1379 ntb_db_event(&sndev->ntb, 0); in switchtec_ntb_doorbell_isr()
1387 struct switchtec_ntb *sndev = dev; in switchtec_ntb_message_isr() local
1389 for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++) { in switchtec_ntb_message_isr()
1390 u64 msg = ioread64(&sndev->mmio_self_dbmsg->imsg[i]); in switchtec_ntb_message_isr()
1393 dev_dbg(&sndev->stdev->dev, "message: %d %08x\n", in switchtec_ntb_message_isr()
1395 iowrite8(1, &sndev->mmio_self_dbmsg->imsg[i].status); in switchtec_ntb_message_isr()
1398 switchtec_ntb_check_link(sndev, msg); in switchtec_ntb_message_isr()
1405 static int switchtec_ntb_init_db_msg_irq(struct switchtec_ntb *sndev) in switchtec_ntb_init_db_msg_irq() argument
1412 int idb_vecs = sizeof(sndev->mmio_self_dbmsg->idb_vec_map); in switchtec_ntb_init_db_msg_irq()
1414 event_irq = ioread32(&sndev->stdev->mmio_part_cfg->vep_vector_number); in switchtec_ntb_init_db_msg_irq()
1422 dev_dbg(&sndev->stdev->dev, "irqs - event: %d, db: %d, msgs: %d\n", in switchtec_ntb_init_db_msg_irq()
1427 &sndev->mmio_self_dbmsg->idb_vec_map[i]); in switchtec_ntb_init_db_msg_irq()
1431 &sndev->mmio_self_dbmsg->idb_vec_map[i]); in switchtec_ntb_init_db_msg_irq()
1433 sndev->doorbell_irq = pci_irq_vector(sndev->stdev->pdev, doorbell_irq); in switchtec_ntb_init_db_msg_irq()
1434 sndev->message_irq = pci_irq_vector(sndev->stdev->pdev, message_irq); in switchtec_ntb_init_db_msg_irq()
1436 rc = request_irq(sndev->doorbell_irq, in switchtec_ntb_init_db_msg_irq()
1438 "switchtec_ntb_doorbell", sndev); in switchtec_ntb_init_db_msg_irq()
1442 rc = request_irq(sndev->message_irq, in switchtec_ntb_init_db_msg_irq()
1444 "switchtec_ntb_message", sndev); in switchtec_ntb_init_db_msg_irq()
1446 free_irq(sndev->doorbell_irq, sndev); in switchtec_ntb_init_db_msg_irq()
1453 static void switchtec_ntb_deinit_db_msg_irq(struct switchtec_ntb *sndev) in switchtec_ntb_deinit_db_msg_irq() argument
1455 free_irq(sndev->doorbell_irq, sndev); in switchtec_ntb_deinit_db_msg_irq()
1456 free_irq(sndev->message_irq, sndev); in switchtec_ntb_deinit_db_msg_irq()
1459 static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev) in switchtec_ntb_reinit_peer() argument
1463 if (crosslink_is_enabled(sndev)) in switchtec_ntb_reinit_peer()
1466 dev_info(&sndev->stdev->dev, "reinitialize shared memory window\n"); in switchtec_ntb_reinit_peer()
1467 rc = config_rsvd_lut_win(sndev, sndev->mmio_peer_ctrl, 0, in switchtec_ntb_reinit_peer()
1468 sndev->self_partition, in switchtec_ntb_reinit_peer()
1469 sndev->self_shared_dma); in switchtec_ntb_reinit_peer()
1476 struct switchtec_ntb *sndev; in switchtec_ntb_add() local
1479 stdev->sndev = NULL; in switchtec_ntb_add()
1484 sndev = kzalloc_node(sizeof(*sndev), GFP_KERNEL, dev_to_node(dev)); in switchtec_ntb_add()
1485 if (!sndev) in switchtec_ntb_add()
1488 sndev->stdev = stdev; in switchtec_ntb_add()
1489 rc = switchtec_ntb_init_sndev(sndev); in switchtec_ntb_add()
1493 switchtec_ntb_init_mw(sndev); in switchtec_ntb_add()
1495 rc = switchtec_ntb_init_req_id_table(sndev); in switchtec_ntb_add()
1499 rc = switchtec_ntb_init_crosslink(sndev); in switchtec_ntb_add()
1503 switchtec_ntb_init_db(sndev); in switchtec_ntb_add()
1504 switchtec_ntb_init_msgs(sndev); in switchtec_ntb_add()
1506 rc = switchtec_ntb_init_shared_mw(sndev); in switchtec_ntb_add()
1510 rc = switchtec_ntb_init_db_msg_irq(sndev); in switchtec_ntb_add()
1519 switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_FORCE_DOWN); in switchtec_ntb_add()
1521 rc = ntb_register_device(&sndev->ntb); in switchtec_ntb_add()
1525 stdev->sndev = sndev; in switchtec_ntb_add()
1532 switchtec_ntb_deinit_db_msg_irq(sndev); in switchtec_ntb_add()
1534 switchtec_ntb_deinit_shared_mw(sndev); in switchtec_ntb_add()
1536 switchtec_ntb_deinit_crosslink(sndev); in switchtec_ntb_add()
1538 kfree(sndev); in switchtec_ntb_add()
1546 struct switchtec_ntb *sndev = stdev->sndev; in switchtec_ntb_remove() local
1548 if (!sndev) in switchtec_ntb_remove()
1552 stdev->sndev = NULL; in switchtec_ntb_remove()
1553 ntb_unregister_device(&sndev->ntb); in switchtec_ntb_remove()
1554 switchtec_ntb_deinit_db_msg_irq(sndev); in switchtec_ntb_remove()
1555 switchtec_ntb_deinit_shared_mw(sndev); in switchtec_ntb_remove()
1556 switchtec_ntb_deinit_crosslink(sndev); in switchtec_ntb_remove()
1557 cancel_work_sync(&sndev->check_link_status_work); in switchtec_ntb_remove()
1558 kfree(sndev); in switchtec_ntb_remove()