Lines Matching refs:mlxsw_pci
25 #define mlxsw_pci_write32(mlxsw_pci, reg, val) \ argument
26 iowrite32be(val, (mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg))
27 #define mlxsw_pci_read32(mlxsw_pci, reg) \ argument
28 ioread32be((mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg))
82 struct mlxsw_pci *pci;
102 struct mlxsw_pci { struct
179 mlxsw_pci_queue_type_group_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_type_group_get() argument
182 return &mlxsw_pci->queues[q_type]; in mlxsw_pci_queue_type_group_get()
185 static u8 __mlxsw_pci_queue_count(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_count() argument
190 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_type); in __mlxsw_pci_queue_count()
194 static u8 mlxsw_pci_sdq_count(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_sdq_count() argument
196 return __mlxsw_pci_queue_count(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_SDQ); in mlxsw_pci_sdq_count()
199 static u8 mlxsw_pci_cq_count(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cq_count() argument
201 return __mlxsw_pci_queue_count(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_CQ); in mlxsw_pci_cq_count()
205 __mlxsw_pci_queue_get(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_get() argument
208 return &mlxsw_pci->queues[q_type].q[q_num]; in __mlxsw_pci_queue_get()
211 static struct mlxsw_pci_queue *mlxsw_pci_sdq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_get() argument
214 return __mlxsw_pci_queue_get(mlxsw_pci, in mlxsw_pci_sdq_get()
218 static struct mlxsw_pci_queue *mlxsw_pci_rdq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_rdq_get() argument
221 return __mlxsw_pci_queue_get(mlxsw_pci, in mlxsw_pci_rdq_get()
225 static struct mlxsw_pci_queue *mlxsw_pci_cq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_get() argument
228 return __mlxsw_pci_queue_get(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_CQ, q_num); in mlxsw_pci_cq_get()
231 static struct mlxsw_pci_queue *mlxsw_pci_eq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_eq_get() argument
234 return __mlxsw_pci_queue_get(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_EQ, q_num); in mlxsw_pci_eq_get()
237 static void __mlxsw_pci_queue_doorbell_set(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_doorbell_set() argument
241 mlxsw_pci_write32(mlxsw_pci, in __mlxsw_pci_queue_doorbell_set()
242 DOORBELL(mlxsw_pci->doorbell_offset, in __mlxsw_pci_queue_doorbell_set()
247 static void __mlxsw_pci_queue_doorbell_arm_set(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_doorbell_arm_set() argument
251 mlxsw_pci_write32(mlxsw_pci, in __mlxsw_pci_queue_doorbell_arm_set()
252 DOORBELL(mlxsw_pci->doorbell_offset, in __mlxsw_pci_queue_doorbell_arm_set()
257 static void mlxsw_pci_queue_doorbell_producer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_producer_ring() argument
261 __mlxsw_pci_queue_doorbell_set(mlxsw_pci, q, q->producer_counter); in mlxsw_pci_queue_doorbell_producer_ring()
264 static void mlxsw_pci_queue_doorbell_consumer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_consumer_ring() argument
268 __mlxsw_pci_queue_doorbell_set(mlxsw_pci, q, in mlxsw_pci_queue_doorbell_consumer_ring()
273 mlxsw_pci_queue_doorbell_arm_consumer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_arm_consumer_ring() argument
277 __mlxsw_pci_queue_doorbell_arm_set(mlxsw_pci, q, q->consumer_counter); in mlxsw_pci_queue_doorbell_arm_consumer_ring()
286 static int mlxsw_pci_sdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_sdq_init() argument
312 err = mlxsw_cmd_sw2hw_sdq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_sdq_init()
315 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_sdq_init()
319 static void mlxsw_pci_sdq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_fini() argument
322 mlxsw_cmd_hw2sw_sdq(mlxsw_pci->core, q->num); in mlxsw_pci_sdq_fini()
325 static int mlxsw_pci_wqe_frag_map(struct mlxsw_pci *mlxsw_pci, char *wqe, in mlxsw_pci_wqe_frag_map() argument
329 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_wqe_frag_map()
342 static void mlxsw_pci_wqe_frag_unmap(struct mlxsw_pci *mlxsw_pci, char *wqe, in mlxsw_pci_wqe_frag_unmap() argument
345 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_wqe_frag_unmap()
354 static int mlxsw_pci_rdq_skb_alloc(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_rdq_skb_alloc() argument
366 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, 0, skb->data, in mlxsw_pci_rdq_skb_alloc()
379 static void mlxsw_pci_rdq_skb_free(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_rdq_skb_free() argument
388 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, 0, DMA_FROM_DEVICE); in mlxsw_pci_rdq_skb_free()
392 static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_rdq_init() argument
396 u8 sdq_count = mlxsw_pci_sdq_count(mlxsw_pci); in mlxsw_pci_rdq_init()
414 err = mlxsw_cmd_sw2hw_rdq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_rdq_init()
418 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_rdq_init()
423 err = mlxsw_pci_rdq_skb_alloc(mlxsw_pci, elem_info); in mlxsw_pci_rdq_init()
428 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_rdq_init()
436 mlxsw_pci_rdq_skb_free(mlxsw_pci, elem_info); in mlxsw_pci_rdq_init()
438 mlxsw_cmd_hw2sw_rdq(mlxsw_pci->core, q->num); in mlxsw_pci_rdq_init()
443 static void mlxsw_pci_rdq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_rdq_fini() argument
449 mlxsw_cmd_hw2sw_rdq(mlxsw_pci->core, q->num); in mlxsw_pci_rdq_fini()
452 mlxsw_pci_rdq_skb_free(mlxsw_pci, elem_info); in mlxsw_pci_rdq_fini()
456 static void mlxsw_pci_cq_pre_init(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_pre_init() argument
459 q->u.cq.v = mlxsw_pci->max_cqe_ver; in mlxsw_pci_cq_pre_init()
462 q->num < mlxsw_pci->num_sdq_cqs && in mlxsw_pci_cq_pre_init()
463 !mlxsw_core_sdq_supports_cqe_v2(mlxsw_pci->core)) in mlxsw_pci_cq_pre_init()
467 static int mlxsw_pci_cq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_cq_init() argument
496 err = mlxsw_cmd_sw2hw_cq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_cq_init()
499 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_init()
500 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_init()
504 static void mlxsw_pci_cq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_fini() argument
507 mlxsw_cmd_hw2sw_cq(mlxsw_pci->core, q->num); in mlxsw_pci_cq_fini()
510 static unsigned int mlxsw_pci_read32_off(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_read32_off() argument
513 return ioread32be(mlxsw_pci->hw_addr + off); in mlxsw_pci_read32_off()
516 static void mlxsw_pci_skb_cb_ts_set(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_skb_cb_ts_set() argument
536 static void mlxsw_pci_cqe_sdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_sdq_handle() argument
542 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_sdq_handle()
555 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_cqe_sdq_handle()
559 mlxsw_pci_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_sdq_handle()
560 mlxsw_core_ptp_transmitted(mlxsw_pci->core, skb, in mlxsw_pci_cqe_sdq_handle()
623 static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_rdq_handle() argument
628 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_rdq_handle()
643 err = mlxsw_pci_rdq_skb_alloc(mlxsw_pci, elem_info); in mlxsw_pci_cqe_rdq_handle()
649 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, 0, DMA_FROM_DEVICE); in mlxsw_pci_cqe_rdq_handle()
667 if (mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) in mlxsw_pci_cqe_rdq_handle()
672 mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) { in mlxsw_pci_cqe_rdq_handle()
676 mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) { in mlxsw_pci_cqe_rdq_handle()
680 mlxsw_pci_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_rdq_handle()
686 mlxsw_core_skb_receive(mlxsw_pci->core, skb, &rx_info); in mlxsw_pci_cqe_rdq_handle()
691 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_cqe_rdq_handle()
714 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_cq_tasklet() local
726 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_tasklet()
731 sdq = mlxsw_pci_sdq_get(mlxsw_pci, dqn); in mlxsw_pci_cq_tasklet()
732 mlxsw_pci_cqe_sdq_handle(mlxsw_pci, sdq, in mlxsw_pci_cq_tasklet()
738 rdq = mlxsw_pci_rdq_get(mlxsw_pci, dqn); in mlxsw_pci_cq_tasklet()
739 mlxsw_pci_cqe_rdq_handle(mlxsw_pci, rdq, in mlxsw_pci_cq_tasklet()
747 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_tasklet()
762 static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_eq_init() argument
784 err = mlxsw_cmd_sw2hw_eq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_eq_init()
787 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
788 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
792 static void mlxsw_pci_eq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_eq_fini() argument
795 mlxsw_cmd_hw2sw_eq(mlxsw_pci->core, q->num); in mlxsw_pci_eq_fini()
798 static void mlxsw_pci_eq_cmd_event(struct mlxsw_pci *mlxsw_pci, char *eqe) in mlxsw_pci_eq_cmd_event() argument
800 mlxsw_pci->cmd.comp.status = mlxsw_pci_eqe_cmd_status_get(eqe); in mlxsw_pci_eq_cmd_event()
801 mlxsw_pci->cmd.comp.out_param = in mlxsw_pci_eq_cmd_event()
804 mlxsw_pci->cmd.wait_done = true; in mlxsw_pci_eq_cmd_event()
805 wake_up(&mlxsw_pci->cmd.wait); in mlxsw_pci_eq_cmd_event()
827 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_eq_tasklet() local
828 u8 cq_count = mlxsw_pci_cq_count(mlxsw_pci); in mlxsw_pci_eq_tasklet()
846 mlxsw_pci_eq_cmd_event(mlxsw_pci, eqe); in mlxsw_pci_eq_tasklet()
862 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
863 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
869 q = mlxsw_pci_cq_get(mlxsw_pci, cqn); in mlxsw_pci_eq_tasklet()
877 void (*pre_init)(struct mlxsw_pci *mlxsw_pci,
879 int (*init)(struct mlxsw_pci *mlxsw_pci, char *mbox,
881 void (*fini)(struct mlxsw_pci *mlxsw_pci,
925 static int mlxsw_pci_queue_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_init() argument
935 q_ops->pre_init(mlxsw_pci, q); in mlxsw_pci_queue_init()
943 q->pci = mlxsw_pci; in mlxsw_pci_queue_init()
949 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_queue_init()
973 err = q_ops->init(mlxsw_pci, mbox, q); in mlxsw_pci_queue_init()
981 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_init()
986 static void mlxsw_pci_queue_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_fini() argument
992 q_ops->fini(mlxsw_pci, q); in mlxsw_pci_queue_fini()
994 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_fini()
998 static int mlxsw_pci_queue_group_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_group_init() argument
1006 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_init()
1012 err = mlxsw_pci_queue_init(mlxsw_pci, mbox, q_ops, in mlxsw_pci_queue_group_init()
1023 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_init()
1028 static void mlxsw_pci_queue_group_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_group_fini() argument
1034 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_fini()
1036 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_fini()
1040 static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_aqs_init() argument
1042 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_aqs_init()
1055 err = mlxsw_cmd_query_aq_cap(mlxsw_pci->core, mbox); in mlxsw_pci_aqs_init()
1079 (mlxsw_pci->max_cqe_ver == MLXSW_PCI_CQE_V2 && in mlxsw_pci_aqs_init()
1086 mlxsw_pci->num_sdq_cqs = num_sdqs; in mlxsw_pci_aqs_init()
1088 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_eq_ops, in mlxsw_pci_aqs_init()
1095 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_cq_ops, in mlxsw_pci_aqs_init()
1102 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_sdq_ops, in mlxsw_pci_aqs_init()
1109 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_rdq_ops, in mlxsw_pci_aqs_init()
1117 mlxsw_pci->cmd.nopoll = true; in mlxsw_pci_aqs_init()
1121 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_init()
1123 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_init()
1125 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_init()
1129 static void mlxsw_pci_aqs_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_aqs_fini() argument
1131 mlxsw_pci->cmd.nopoll = false; in mlxsw_pci_aqs_fini()
1132 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_rdq_ops); in mlxsw_pci_aqs_fini()
1133 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_fini()
1134 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_fini()
1135 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_fini()
1139 mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_config_profile_swid_config() argument
1159 mlxsw_pci_profile_get_kvd_sizes(const struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_profile_get_kvd_sizes() argument
1166 err = mlxsw_core_kvd_sizes_get(mlxsw_pci->core, profile, in mlxsw_pci_profile_get_kvd_sizes()
1179 static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_config_profile() argument
1281 err = mlxsw_pci_profile_get_kvd_sizes(mlxsw_pci, profile, res); in mlxsw_pci_config_profile()
1299 mlxsw_pci_config_profile_swid_config(mlxsw_pci, mbox, i, in mlxsw_pci_config_profile()
1302 if (mlxsw_pci->max_cqe_ver > MLXSW_PCI_CQE_V0) { in mlxsw_pci_config_profile()
1314 return mlxsw_cmd_config_profile_set(mlxsw_pci->core, mbox); in mlxsw_pci_config_profile()
1317 static int mlxsw_pci_boardinfo(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_boardinfo() argument
1319 struct mlxsw_bus_info *bus_info = &mlxsw_pci->bus_info; in mlxsw_pci_boardinfo()
1323 err = mlxsw_cmd_boardinfo(mlxsw_pci->core, mbox); in mlxsw_pci_boardinfo()
1331 static int mlxsw_pci_fw_area_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_fw_area_init() argument
1339 mlxsw_pci->fw_area.items = kcalloc(num_pages, sizeof(*mem_item), in mlxsw_pci_fw_area_init()
1341 if (!mlxsw_pci->fw_area.items) in mlxsw_pci_fw_area_init()
1343 mlxsw_pci->fw_area.count = num_pages; in mlxsw_pci_fw_area_init()
1347 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1350 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_fw_area_init()
1360 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1369 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1379 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1381 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_init()
1384 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_init()
1388 static void mlxsw_pci_fw_area_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_fw_area_fini() argument
1393 mlxsw_cmd_unmap_fa(mlxsw_pci->core); in mlxsw_pci_fw_area_fini()
1395 for (i = 0; i < mlxsw_pci->fw_area.count; i++) { in mlxsw_pci_fw_area_fini()
1396 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_fini()
1398 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_fini()
1401 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_fini()
1406 struct mlxsw_pci *mlxsw_pci = dev_id; in mlxsw_pci_eq_irq_handler() local
1411 q = mlxsw_pci_eq_get(mlxsw_pci, i); in mlxsw_pci_eq_irq_handler()
1417 static int mlxsw_pci_mbox_alloc(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_alloc() argument
1420 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_alloc()
1434 static void mlxsw_pci_mbox_free(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_free() argument
1437 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_free()
1443 static int mlxsw_pci_sys_ready_wait(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sys_ready_wait() argument
1455 val = mlxsw_pci_read32(mlxsw_pci, FW_READY); in mlxsw_pci_sys_ready_wait()
1466 static int mlxsw_pci_sw_reset(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sw_reset() argument
1469 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_sw_reset()
1474 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_sw_reset()
1482 err = mlxsw_reg_write(mlxsw_pci->core, MLXSW_REG(mrsr), mrsr_pl); in mlxsw_pci_sw_reset()
1486 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_sw_reset()
1496 static int mlxsw_pci_alloc_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_alloc_irq_vectors() argument
1500 err = pci_alloc_irq_vectors(mlxsw_pci->pdev, 1, 1, PCI_IRQ_MSIX); in mlxsw_pci_alloc_irq_vectors()
1502 dev_err(&mlxsw_pci->pdev->dev, "MSI-X init failed\n"); in mlxsw_pci_alloc_irq_vectors()
1506 static void mlxsw_pci_free_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_free_irq_vectors() argument
1508 pci_free_irq_vectors(mlxsw_pci->pdev); in mlxsw_pci_free_irq_vectors()
1515 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_init() local
1516 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_init()
1521 mlxsw_pci->core = mlxsw_core; in mlxsw_pci_init()
1527 err = mlxsw_pci_sw_reset(mlxsw_pci, mlxsw_pci->id); in mlxsw_pci_init()
1531 err = mlxsw_pci_alloc_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
1541 mlxsw_pci->bus_info.fw_rev.major = in mlxsw_pci_init()
1543 mlxsw_pci->bus_info.fw_rev.minor = in mlxsw_pci_init()
1545 mlxsw_pci->bus_info.fw_rev.subminor = in mlxsw_pci_init()
1559 mlxsw_pci->doorbell_offset = in mlxsw_pci_init()
1568 mlxsw_pci->free_running_clock_offset = in mlxsw_pci_init()
1577 mlxsw_pci->utc_sec_offset = in mlxsw_pci_init()
1586 mlxsw_pci->utc_nsec_offset = in mlxsw_pci_init()
1590 err = mlxsw_pci_fw_area_init(mlxsw_pci, mbox, num_pages); in mlxsw_pci_init()
1594 err = mlxsw_pci_boardinfo(mlxsw_pci, mbox); in mlxsw_pci_init()
1604 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V2; in mlxsw_pci_init()
1607 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V1; in mlxsw_pci_init()
1611 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V0; in mlxsw_pci_init()
1617 err = mlxsw_pci_config_profile(mlxsw_pci, mbox, profile, res); in mlxsw_pci_init()
1629 err = mlxsw_pci_aqs_init(mlxsw_pci, mbox); in mlxsw_pci_init()
1635 mlxsw_pci->bus_info.device_kind, mlxsw_pci); in mlxsw_pci_init()
1644 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_init()
1651 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_init()
1659 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
1669 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_fini() local
1671 free_irq(pci_irq_vector(mlxsw_pci->pdev, 0), mlxsw_pci); in mlxsw_pci_fini()
1672 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_fini()
1673 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_fini()
1674 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_fini()
1678 mlxsw_pci_sdq_pick(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_pick() argument
1681 u8 ctl_sdq_count = mlxsw_pci_sdq_count(mlxsw_pci) - 1; in mlxsw_pci_sdq_pick()
1691 return mlxsw_pci_sdq_get(mlxsw_pci, sdqn); in mlxsw_pci_sdq_pick()
1697 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit_busy() local
1698 struct mlxsw_pci_queue *q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit_busy()
1706 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit() local
1719 q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit()
1735 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, 0, skb->data, in mlxsw_pci_skb_transmit()
1743 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, i + 1, in mlxsw_pci_skb_transmit()
1760 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_skb_transmit()
1766 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_skb_transmit()
1778 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_cmd_exec() local
1780 bool evreq = mlxsw_pci->cmd.nopoll; in mlxsw_pci_cmd_exec()
1782 bool *p_wait_done = &mlxsw_pci->cmd.wait_done; in mlxsw_pci_cmd_exec()
1787 err = mutex_lock_interruptible(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
1792 memcpy(mlxsw_pci->cmd.in_mbox.buf, in_mbox, in_mbox_size); in mlxsw_pci_cmd_exec()
1793 in_mapaddr = mlxsw_pci->cmd.in_mbox.mapaddr; in mlxsw_pci_cmd_exec()
1795 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_HI, upper_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
1796 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_LO, lower_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
1799 out_mapaddr = mlxsw_pci->cmd.out_mbox.mapaddr; in mlxsw_pci_cmd_exec()
1800 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_HI, upper_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
1801 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_LO, lower_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
1803 mlxsw_pci_write32(mlxsw_pci, CIR_IN_MODIFIER, in_mod); in mlxsw_pci_cmd_exec()
1804 mlxsw_pci_write32(mlxsw_pci, CIR_TOKEN, 0); in mlxsw_pci_cmd_exec()
1809 mlxsw_pci_write32(mlxsw_pci, CIR_CTRL, in mlxsw_pci_cmd_exec()
1820 u32 ctrl = mlxsw_pci_read32(mlxsw_pci, CIR_CTRL); in mlxsw_pci_cmd_exec()
1830 wait_event_timeout(mlxsw_pci->cmd.wait, *p_wait_done, timeout); in mlxsw_pci_cmd_exec()
1831 *p_status = mlxsw_pci->cmd.comp.status; in mlxsw_pci_cmd_exec()
1850 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
1853 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
1858 memcpy(out_mbox, mlxsw_pci->cmd.out_mbox.buf, out_mbox_size); in mlxsw_pci_cmd_exec()
1861 mutex_unlock(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
1868 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_h() local
1871 frc_offset_h = mlxsw_pci->free_running_clock_offset; in mlxsw_pci_read_frc_h()
1872 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_h); in mlxsw_pci_read_frc_h()
1877 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_l() local
1880 frc_offset_l = mlxsw_pci->free_running_clock_offset + 4; in mlxsw_pci_read_frc_l()
1881 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_l); in mlxsw_pci_read_frc_l()
1886 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_sec() local
1888 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_sec_offset); in mlxsw_pci_read_utc_sec()
1893 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_nsec() local
1895 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_nsec_offset); in mlxsw_pci_read_utc_nsec()
1912 static int mlxsw_pci_cmd_init(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_init() argument
1916 mutex_init(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
1917 init_waitqueue_head(&mlxsw_pci->cmd.wait); in mlxsw_pci_cmd_init()
1919 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
1923 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_init()
1930 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
1932 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
1936 static void mlxsw_pci_cmd_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_fini() argument
1938 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_fini()
1939 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_fini()
1940 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_fini()
1946 struct mlxsw_pci *mlxsw_pci; in mlxsw_pci_probe() local
1949 mlxsw_pci = kzalloc(sizeof(*mlxsw_pci), GFP_KERNEL); in mlxsw_pci_probe()
1950 if (!mlxsw_pci) in mlxsw_pci_probe()
1980 mlxsw_pci->hw_addr = ioremap(pci_resource_start(pdev, 0), in mlxsw_pci_probe()
1982 if (!mlxsw_pci->hw_addr) { in mlxsw_pci_probe()
1989 mlxsw_pci->pdev = pdev; in mlxsw_pci_probe()
1990 pci_set_drvdata(pdev, mlxsw_pci); in mlxsw_pci_probe()
1992 err = mlxsw_pci_cmd_init(mlxsw_pci); in mlxsw_pci_probe()
1996 mlxsw_pci->bus_info.device_kind = driver_name; in mlxsw_pci_probe()
1997 mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev); in mlxsw_pci_probe()
1998 mlxsw_pci->bus_info.dev = &pdev->dev; in mlxsw_pci_probe()
1999 mlxsw_pci->bus_info.read_clock_capable = true; in mlxsw_pci_probe()
2000 mlxsw_pci->id = id; in mlxsw_pci_probe()
2002 err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, in mlxsw_pci_probe()
2003 &mlxsw_pci_bus, mlxsw_pci, false, in mlxsw_pci_probe()
2013 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_probe()
2015 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_probe()
2023 kfree(mlxsw_pci); in mlxsw_pci_probe()
2029 struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); in mlxsw_pci_remove() local
2031 mlxsw_core_bus_device_unregister(mlxsw_pci->core, false); in mlxsw_pci_remove()
2032 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_remove()
2033 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_remove()
2034 pci_release_regions(mlxsw_pci->pdev); in mlxsw_pci_remove()
2035 pci_disable_device(mlxsw_pci->pdev); in mlxsw_pci_remove()
2036 kfree(mlxsw_pci); in mlxsw_pci_remove()