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
532 static void mlxsw_pci_cqe_sdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_sdq_handle() argument
538 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_sdq_handle()
551 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_cqe_sdq_handle()
555 mlxsw_pci_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_sdq_handle()
556 mlxsw_core_ptp_transmitted(mlxsw_pci->core, skb, in mlxsw_pci_cqe_sdq_handle()
619 static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_rdq_handle() argument
624 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_rdq_handle()
639 err = mlxsw_pci_rdq_skb_alloc(mlxsw_pci, elem_info); in mlxsw_pci_cqe_rdq_handle()
645 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, 0, DMA_FROM_DEVICE); in mlxsw_pci_cqe_rdq_handle()
663 if (mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) in mlxsw_pci_cqe_rdq_handle()
668 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_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_rdq_handle()
682 mlxsw_core_skb_receive(mlxsw_pci->core, skb, &rx_info); in mlxsw_pci_cqe_rdq_handle()
687 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_cqe_rdq_handle()
710 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_cq_tasklet() local
722 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_tasklet()
727 sdq = mlxsw_pci_sdq_get(mlxsw_pci, dqn); in mlxsw_pci_cq_tasklet()
728 mlxsw_pci_cqe_sdq_handle(mlxsw_pci, sdq, in mlxsw_pci_cq_tasklet()
734 rdq = mlxsw_pci_rdq_get(mlxsw_pci, dqn); in mlxsw_pci_cq_tasklet()
735 mlxsw_pci_cqe_rdq_handle(mlxsw_pci, rdq, in mlxsw_pci_cq_tasklet()
743 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_tasklet()
758 static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_eq_init() argument
780 err = mlxsw_cmd_sw2hw_eq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_eq_init()
783 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
784 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
788 static void mlxsw_pci_eq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_eq_fini() argument
791 mlxsw_cmd_hw2sw_eq(mlxsw_pci->core, q->num); in mlxsw_pci_eq_fini()
794 static void mlxsw_pci_eq_cmd_event(struct mlxsw_pci *mlxsw_pci, char *eqe) in mlxsw_pci_eq_cmd_event() argument
796 mlxsw_pci->cmd.comp.status = mlxsw_pci_eqe_cmd_status_get(eqe); in mlxsw_pci_eq_cmd_event()
797 mlxsw_pci->cmd.comp.out_param = in mlxsw_pci_eq_cmd_event()
800 mlxsw_pci->cmd.wait_done = true; in mlxsw_pci_eq_cmd_event()
801 wake_up(&mlxsw_pci->cmd.wait); in mlxsw_pci_eq_cmd_event()
823 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_eq_tasklet() local
824 u8 cq_count = mlxsw_pci_cq_count(mlxsw_pci); in mlxsw_pci_eq_tasklet()
842 mlxsw_pci_eq_cmd_event(mlxsw_pci, eqe); in mlxsw_pci_eq_tasklet()
858 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
859 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
865 q = mlxsw_pci_cq_get(mlxsw_pci, cqn); in mlxsw_pci_eq_tasklet()
873 void (*pre_init)(struct mlxsw_pci *mlxsw_pci,
875 int (*init)(struct mlxsw_pci *mlxsw_pci, char *mbox,
877 void (*fini)(struct mlxsw_pci *mlxsw_pci,
921 static int mlxsw_pci_queue_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_init() argument
931 q_ops->pre_init(mlxsw_pci, q); in mlxsw_pci_queue_init()
939 q->pci = mlxsw_pci; in mlxsw_pci_queue_init()
945 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_queue_init()
969 err = q_ops->init(mlxsw_pci, mbox, q); in mlxsw_pci_queue_init()
977 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_init()
982 static void mlxsw_pci_queue_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_fini() argument
988 q_ops->fini(mlxsw_pci, q); in mlxsw_pci_queue_fini()
990 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_fini()
994 static int mlxsw_pci_queue_group_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_group_init() argument
1002 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_init()
1008 err = mlxsw_pci_queue_init(mlxsw_pci, mbox, q_ops, in mlxsw_pci_queue_group_init()
1019 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_init()
1024 static void mlxsw_pci_queue_group_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_group_fini() argument
1030 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_fini()
1032 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_fini()
1036 static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_aqs_init() argument
1038 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_aqs_init()
1051 err = mlxsw_cmd_query_aq_cap(mlxsw_pci->core, mbox); in mlxsw_pci_aqs_init()
1075 (mlxsw_pci->max_cqe_ver == MLXSW_PCI_CQE_V2 && in mlxsw_pci_aqs_init()
1082 mlxsw_pci->num_sdq_cqs = num_sdqs; in mlxsw_pci_aqs_init()
1084 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_eq_ops, in mlxsw_pci_aqs_init()
1091 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_cq_ops, in mlxsw_pci_aqs_init()
1098 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_sdq_ops, in mlxsw_pci_aqs_init()
1105 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_rdq_ops, in mlxsw_pci_aqs_init()
1113 mlxsw_pci->cmd.nopoll = true; in mlxsw_pci_aqs_init()
1117 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_init()
1119 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_init()
1121 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_init()
1125 static void mlxsw_pci_aqs_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_aqs_fini() argument
1127 mlxsw_pci->cmd.nopoll = false; in mlxsw_pci_aqs_fini()
1128 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_rdq_ops); in mlxsw_pci_aqs_fini()
1129 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_fini()
1130 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_fini()
1131 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_fini()
1135 mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_config_profile_swid_config() argument
1155 mlxsw_pci_profile_get_kvd_sizes(const struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_profile_get_kvd_sizes() argument
1162 err = mlxsw_core_kvd_sizes_get(mlxsw_pci->core, profile, in mlxsw_pci_profile_get_kvd_sizes()
1175 static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_config_profile() argument
1277 err = mlxsw_pci_profile_get_kvd_sizes(mlxsw_pci, profile, res); in mlxsw_pci_config_profile()
1295 mlxsw_pci_config_profile_swid_config(mlxsw_pci, mbox, i, in mlxsw_pci_config_profile()
1298 if (mlxsw_pci->max_cqe_ver > MLXSW_PCI_CQE_V0) { in mlxsw_pci_config_profile()
1310 return mlxsw_cmd_config_profile_set(mlxsw_pci->core, mbox); in mlxsw_pci_config_profile()
1313 static int mlxsw_pci_boardinfo(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_boardinfo() argument
1315 struct mlxsw_bus_info *bus_info = &mlxsw_pci->bus_info; in mlxsw_pci_boardinfo()
1319 err = mlxsw_cmd_boardinfo(mlxsw_pci->core, mbox); in mlxsw_pci_boardinfo()
1327 static int mlxsw_pci_fw_area_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_fw_area_init() argument
1335 mlxsw_pci->fw_area.items = kcalloc(num_pages, sizeof(*mem_item), in mlxsw_pci_fw_area_init()
1337 if (!mlxsw_pci->fw_area.items) in mlxsw_pci_fw_area_init()
1339 mlxsw_pci->fw_area.count = num_pages; in mlxsw_pci_fw_area_init()
1343 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1346 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_fw_area_init()
1356 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1365 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1375 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1377 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_init()
1380 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_init()
1384 static void mlxsw_pci_fw_area_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_fw_area_fini() argument
1389 mlxsw_cmd_unmap_fa(mlxsw_pci->core); in mlxsw_pci_fw_area_fini()
1391 for (i = 0; i < mlxsw_pci->fw_area.count; i++) { in mlxsw_pci_fw_area_fini()
1392 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_fini()
1394 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_fini()
1397 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_fini()
1402 struct mlxsw_pci *mlxsw_pci = dev_id; in mlxsw_pci_eq_irq_handler() local
1407 q = mlxsw_pci_eq_get(mlxsw_pci, i); in mlxsw_pci_eq_irq_handler()
1413 static int mlxsw_pci_mbox_alloc(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_alloc() argument
1416 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_alloc()
1430 static void mlxsw_pci_mbox_free(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_free() argument
1433 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_free()
1439 static int mlxsw_pci_sys_ready_wait(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sys_ready_wait() argument
1451 val = mlxsw_pci_read32(mlxsw_pci, FW_READY); in mlxsw_pci_sys_ready_wait()
1462 static int mlxsw_pci_sw_reset(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sw_reset() argument
1465 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_sw_reset()
1470 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_sw_reset()
1478 err = mlxsw_reg_write(mlxsw_pci->core, MLXSW_REG(mrsr), mrsr_pl); in mlxsw_pci_sw_reset()
1482 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_sw_reset()
1492 static int mlxsw_pci_alloc_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_alloc_irq_vectors() argument
1496 err = pci_alloc_irq_vectors(mlxsw_pci->pdev, 1, 1, PCI_IRQ_MSIX); in mlxsw_pci_alloc_irq_vectors()
1498 dev_err(&mlxsw_pci->pdev->dev, "MSI-X init failed\n"); in mlxsw_pci_alloc_irq_vectors()
1502 static void mlxsw_pci_free_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_free_irq_vectors() argument
1504 pci_free_irq_vectors(mlxsw_pci->pdev); in mlxsw_pci_free_irq_vectors()
1511 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_init() local
1512 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_init()
1517 mlxsw_pci->core = mlxsw_core; in mlxsw_pci_init()
1523 err = mlxsw_pci_sw_reset(mlxsw_pci, mlxsw_pci->id); in mlxsw_pci_init()
1527 err = mlxsw_pci_alloc_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
1537 mlxsw_pci->bus_info.fw_rev.major = in mlxsw_pci_init()
1539 mlxsw_pci->bus_info.fw_rev.minor = in mlxsw_pci_init()
1541 mlxsw_pci->bus_info.fw_rev.subminor = in mlxsw_pci_init()
1555 mlxsw_pci->doorbell_offset = in mlxsw_pci_init()
1564 mlxsw_pci->free_running_clock_offset = in mlxsw_pci_init()
1573 mlxsw_pci->utc_sec_offset = in mlxsw_pci_init()
1582 mlxsw_pci->utc_nsec_offset = in mlxsw_pci_init()
1586 err = mlxsw_pci_fw_area_init(mlxsw_pci, mbox, num_pages); in mlxsw_pci_init()
1590 err = mlxsw_pci_boardinfo(mlxsw_pci, mbox); in mlxsw_pci_init()
1600 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V2; in mlxsw_pci_init()
1603 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V1; in mlxsw_pci_init()
1607 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V0; in mlxsw_pci_init()
1613 err = mlxsw_pci_config_profile(mlxsw_pci, mbox, profile, res); in mlxsw_pci_init()
1625 err = mlxsw_pci_aqs_init(mlxsw_pci, mbox); in mlxsw_pci_init()
1631 mlxsw_pci->bus_info.device_kind, mlxsw_pci); in mlxsw_pci_init()
1640 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_init()
1647 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_init()
1655 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
1665 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_fini() local
1667 free_irq(pci_irq_vector(mlxsw_pci->pdev, 0), mlxsw_pci); in mlxsw_pci_fini()
1668 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_fini()
1669 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_fini()
1670 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_fini()
1674 mlxsw_pci_sdq_pick(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_pick() argument
1677 u8 ctl_sdq_count = mlxsw_pci_sdq_count(mlxsw_pci) - 1; in mlxsw_pci_sdq_pick()
1687 return mlxsw_pci_sdq_get(mlxsw_pci, sdqn); in mlxsw_pci_sdq_pick()
1693 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit_busy() local
1694 struct mlxsw_pci_queue *q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit_busy()
1702 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit() local
1715 q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit()
1731 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, 0, skb->data, in mlxsw_pci_skb_transmit()
1739 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, i + 1, in mlxsw_pci_skb_transmit()
1756 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_skb_transmit()
1762 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_skb_transmit()
1774 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_cmd_exec() local
1776 bool evreq = mlxsw_pci->cmd.nopoll; in mlxsw_pci_cmd_exec()
1778 bool *p_wait_done = &mlxsw_pci->cmd.wait_done; in mlxsw_pci_cmd_exec()
1783 err = mutex_lock_interruptible(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
1788 memcpy(mlxsw_pci->cmd.in_mbox.buf, in_mbox, in_mbox_size); in mlxsw_pci_cmd_exec()
1789 in_mapaddr = mlxsw_pci->cmd.in_mbox.mapaddr; in mlxsw_pci_cmd_exec()
1791 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_HI, upper_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
1792 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_LO, lower_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
1795 out_mapaddr = mlxsw_pci->cmd.out_mbox.mapaddr; in mlxsw_pci_cmd_exec()
1796 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_HI, upper_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
1797 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_LO, lower_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
1799 mlxsw_pci_write32(mlxsw_pci, CIR_IN_MODIFIER, in_mod); in mlxsw_pci_cmd_exec()
1800 mlxsw_pci_write32(mlxsw_pci, CIR_TOKEN, 0); in mlxsw_pci_cmd_exec()
1805 mlxsw_pci_write32(mlxsw_pci, CIR_CTRL, in mlxsw_pci_cmd_exec()
1816 u32 ctrl = mlxsw_pci_read32(mlxsw_pci, CIR_CTRL); in mlxsw_pci_cmd_exec()
1826 wait_event_timeout(mlxsw_pci->cmd.wait, *p_wait_done, timeout); in mlxsw_pci_cmd_exec()
1827 *p_status = mlxsw_pci->cmd.comp.status; in mlxsw_pci_cmd_exec()
1846 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
1849 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
1854 memcpy(out_mbox, mlxsw_pci->cmd.out_mbox.buf, out_mbox_size); in mlxsw_pci_cmd_exec()
1857 mutex_unlock(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
1864 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_h() local
1867 frc_offset_h = mlxsw_pci->free_running_clock_offset; in mlxsw_pci_read_frc_h()
1868 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_h); in mlxsw_pci_read_frc_h()
1873 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_l() local
1876 frc_offset_l = mlxsw_pci->free_running_clock_offset + 4; in mlxsw_pci_read_frc_l()
1877 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_l); in mlxsw_pci_read_frc_l()
1882 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_sec() local
1884 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_sec_offset); in mlxsw_pci_read_utc_sec()
1889 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_nsec() local
1891 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_nsec_offset); in mlxsw_pci_read_utc_nsec()
1908 static int mlxsw_pci_cmd_init(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_init() argument
1912 mutex_init(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
1913 init_waitqueue_head(&mlxsw_pci->cmd.wait); in mlxsw_pci_cmd_init()
1915 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
1919 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_init()
1926 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
1928 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
1932 static void mlxsw_pci_cmd_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_fini() argument
1934 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_fini()
1935 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_fini()
1936 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_fini()
1942 struct mlxsw_pci *mlxsw_pci; in mlxsw_pci_probe() local
1945 mlxsw_pci = kzalloc(sizeof(*mlxsw_pci), GFP_KERNEL); in mlxsw_pci_probe()
1946 if (!mlxsw_pci) in mlxsw_pci_probe()
1976 mlxsw_pci->hw_addr = ioremap(pci_resource_start(pdev, 0), in mlxsw_pci_probe()
1978 if (!mlxsw_pci->hw_addr) { in mlxsw_pci_probe()
1985 mlxsw_pci->pdev = pdev; in mlxsw_pci_probe()
1986 pci_set_drvdata(pdev, mlxsw_pci); in mlxsw_pci_probe()
1988 err = mlxsw_pci_cmd_init(mlxsw_pci); in mlxsw_pci_probe()
1992 mlxsw_pci->bus_info.device_kind = driver_name; in mlxsw_pci_probe()
1993 mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev); in mlxsw_pci_probe()
1994 mlxsw_pci->bus_info.dev = &pdev->dev; in mlxsw_pci_probe()
1995 mlxsw_pci->bus_info.read_clock_capable = true; in mlxsw_pci_probe()
1996 mlxsw_pci->id = id; in mlxsw_pci_probe()
1998 err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, in mlxsw_pci_probe()
1999 &mlxsw_pci_bus, mlxsw_pci, false, in mlxsw_pci_probe()
2009 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_probe()
2011 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_probe()
2019 kfree(mlxsw_pci); in mlxsw_pci_probe()
2025 struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); in mlxsw_pci_remove() local
2027 mlxsw_core_bus_device_unregister(mlxsw_pci->core, false); in mlxsw_pci_remove()
2028 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_remove()
2029 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_remove()
2030 pci_release_regions(mlxsw_pci->pdev); in mlxsw_pci_remove()
2031 pci_disable_device(mlxsw_pci->pdev); in mlxsw_pci_remove()
2032 kfree(mlxsw_pci); in mlxsw_pci_remove()