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;
104 struct mlxsw_pci { struct
141 static int mlxsw_pci_napi_devs_init(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_napi_devs_init() argument
145 mlxsw_pci->napi_dev_tx = alloc_netdev_dummy(0); in mlxsw_pci_napi_devs_init()
146 if (!mlxsw_pci->napi_dev_tx) in mlxsw_pci_napi_devs_init()
148 strscpy(mlxsw_pci->napi_dev_tx->name, "mlxsw_tx", in mlxsw_pci_napi_devs_init()
149 sizeof(mlxsw_pci->napi_dev_tx->name)); in mlxsw_pci_napi_devs_init()
151 mlxsw_pci->napi_dev_rx = alloc_netdev_dummy(0); in mlxsw_pci_napi_devs_init()
152 if (!mlxsw_pci->napi_dev_rx) { in mlxsw_pci_napi_devs_init()
156 strscpy(mlxsw_pci->napi_dev_rx->name, "mlxsw_rx", in mlxsw_pci_napi_devs_init()
157 sizeof(mlxsw_pci->napi_dev_rx->name)); in mlxsw_pci_napi_devs_init()
158 dev_set_threaded(mlxsw_pci->napi_dev_rx, true); in mlxsw_pci_napi_devs_init()
163 free_netdev(mlxsw_pci->napi_dev_tx); in mlxsw_pci_napi_devs_init()
167 static void mlxsw_pci_napi_devs_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_napi_devs_fini() argument
169 free_netdev(mlxsw_pci->napi_dev_rx); in mlxsw_pci_napi_devs_fini()
170 free_netdev(mlxsw_pci->napi_dev_tx); in mlxsw_pci_napi_devs_fini()
214 mlxsw_pci_queue_type_group_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_type_group_get() argument
217 return &mlxsw_pci->queues[q_type]; in mlxsw_pci_queue_type_group_get()
221 __mlxsw_pci_queue_get(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_get() argument
224 return &mlxsw_pci->queues[q_type].q[q_num]; in __mlxsw_pci_queue_get()
227 static struct mlxsw_pci_queue *mlxsw_pci_sdq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_get() argument
230 return __mlxsw_pci_queue_get(mlxsw_pci, in mlxsw_pci_sdq_get()
234 static struct mlxsw_pci_queue *mlxsw_pci_cq_get(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_get() argument
237 return __mlxsw_pci_queue_get(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_CQ, q_num); in mlxsw_pci_cq_get()
240 static struct mlxsw_pci_queue *mlxsw_pci_eq_get(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_eq_get() argument
243 return __mlxsw_pci_queue_get(mlxsw_pci, MLXSW_PCI_QUEUE_TYPE_EQ, 0); in mlxsw_pci_eq_get()
246 static void __mlxsw_pci_queue_doorbell_set(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_doorbell_set() argument
250 mlxsw_pci_write32(mlxsw_pci, in __mlxsw_pci_queue_doorbell_set()
251 DOORBELL(mlxsw_pci->doorbell_offset, in __mlxsw_pci_queue_doorbell_set()
256 static void __mlxsw_pci_queue_doorbell_arm_set(struct mlxsw_pci *mlxsw_pci, in __mlxsw_pci_queue_doorbell_arm_set() argument
260 mlxsw_pci_write32(mlxsw_pci, in __mlxsw_pci_queue_doorbell_arm_set()
261 DOORBELL(mlxsw_pci->doorbell_offset, in __mlxsw_pci_queue_doorbell_arm_set()
266 static void mlxsw_pci_queue_doorbell_producer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_producer_ring() argument
270 __mlxsw_pci_queue_doorbell_set(mlxsw_pci, q, q->producer_counter); in mlxsw_pci_queue_doorbell_producer_ring()
273 static void mlxsw_pci_queue_doorbell_consumer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_consumer_ring() argument
277 __mlxsw_pci_queue_doorbell_set(mlxsw_pci, q, in mlxsw_pci_queue_doorbell_consumer_ring()
282 mlxsw_pci_queue_doorbell_arm_consumer_ring(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_doorbell_arm_consumer_ring() argument
286 __mlxsw_pci_queue_doorbell_arm_set(mlxsw_pci, q, q->consumer_counter); in mlxsw_pci_queue_doorbell_arm_consumer_ring()
295 static int mlxsw_pci_sdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_sdq_init() argument
324 err = mlxsw_cmd_sw2hw_sdq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_sdq_init()
328 cq = mlxsw_pci_cq_get(mlxsw_pci, cq_num); in mlxsw_pci_sdq_init()
330 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_sdq_init()
334 static void mlxsw_pci_sdq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_fini() argument
337 mlxsw_cmd_hw2sw_sdq(mlxsw_pci->core, q->num); in mlxsw_pci_sdq_fini()
347 mlxsw_pci_wqe_rx_frag_set(struct mlxsw_pci *mlxsw_pci, struct page *page, in mlxsw_pci_wqe_rx_frag_set() argument
363 static int mlxsw_pci_wqe_frag_map(struct mlxsw_pci *mlxsw_pci, char *wqe, in mlxsw_pci_wqe_frag_map() argument
367 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_wqe_frag_map()
380 static void mlxsw_pci_wqe_frag_unmap(struct mlxsw_pci *mlxsw_pci, char *wqe, in mlxsw_pci_wqe_frag_unmap() argument
383 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_wqe_frag_unmap()
536 static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_rdq_init() argument
540 u8 sdq_count = mlxsw_pci->num_sdqs; in mlxsw_pci_rdq_init()
561 err = mlxsw_cmd_sw2hw_rdq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_rdq_init()
565 cq = mlxsw_pci_cq_get(mlxsw_pci, cq_num); in mlxsw_pci_rdq_init()
569 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_rdq_init()
575 for (j = 0; j < mlxsw_pci->num_sg_entries; j++) { in mlxsw_pci_rdq_init()
582 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_rdq_init()
592 j = mlxsw_pci->num_sg_entries; in mlxsw_pci_rdq_init()
596 mlxsw_cmd_hw2sw_rdq(mlxsw_pci->core, q->num); in mlxsw_pci_rdq_init()
601 static void mlxsw_pci_rdq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_rdq_fini() argument
607 mlxsw_cmd_hw2sw_rdq(mlxsw_pci->core, q->num); in mlxsw_pci_rdq_fini()
610 for (j = 0; j < mlxsw_pci->num_sg_entries; j++) in mlxsw_pci_rdq_fini()
615 static void mlxsw_pci_cq_pre_init(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_pre_init() argument
618 q->u.cq.v = mlxsw_pci->max_cqe_ver; in mlxsw_pci_cq_pre_init()
621 q->num < mlxsw_pci->num_sdqs && in mlxsw_pci_cq_pre_init()
622 !mlxsw_core_sdq_supports_cqe_v2(mlxsw_pci->core)) in mlxsw_pci_cq_pre_init()
626 static unsigned int mlxsw_pci_read32_off(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_read32_off() argument
629 return ioread32be(mlxsw_pci->hw_addr + off); in mlxsw_pci_read32_off()
632 static void mlxsw_pci_skb_cb_ts_set(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_skb_cb_ts_set() argument
652 static void mlxsw_pci_cqe_sdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_sdq_handle() argument
658 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_sdq_handle()
671 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_cqe_sdq_handle()
675 mlxsw_pci_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_sdq_handle()
676 mlxsw_core_ptp_transmitted(mlxsw_pci->core, skb, in mlxsw_pci_cqe_sdq_handle()
739 static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cqe_rdq_handle() argument
744 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_cqe_rdq_handle()
796 if (mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) in mlxsw_pci_cqe_rdq_handle()
801 mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) { in mlxsw_pci_cqe_rdq_handle()
805 mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) { in mlxsw_pci_cqe_rdq_handle()
809 mlxsw_pci_skb_cb_ts_set(mlxsw_pci, skb, cqe_v, cqe); in mlxsw_pci_cqe_rdq_handle()
811 mlxsw_core_skb_receive(mlxsw_pci->core, skb, &rx_info); in mlxsw_pci_cqe_rdq_handle()
849 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_napi_poll_cq_rx() local
872 mlxsw_pci_cqe_rdq_handle(mlxsw_pci, rdq, in mlxsw_pci_napi_poll_cq_rx()
879 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_napi_poll_cq_rx()
880 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, rdq); in mlxsw_pci_napi_poll_cq_rx()
901 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_napi_poll_cq_rx()
911 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_napi_poll_cq_tx() local
932 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_napi_poll_cq_tx()
934 mlxsw_pci_cqe_sdq_handle(mlxsw_pci, sdq, in mlxsw_pci_napi_poll_cq_tx()
949 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_napi_poll_cq_tx()
955 mlxsw_pci_cq_type(const struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_type() argument
961 if (q->num < mlxsw_pci->num_sdqs) in mlxsw_pci_cq_type()
970 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_cq_napi_setup() local
974 netif_napi_add(mlxsw_pci->napi_dev_tx, &q->u.cq.napi, in mlxsw_pci_cq_napi_setup()
978 netif_napi_add(mlxsw_pci->napi_dev_rx, &q->u.cq.napi, in mlxsw_pci_cq_napi_setup()
993 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_cq_page_pool_init() local
1000 pp_params.pool_size = MLXSW_PCI_WQE_COUNT * mlxsw_pci->num_sg_entries; in mlxsw_pci_cq_page_pool_init()
1001 pp_params.nid = dev_to_node(&mlxsw_pci->pdev->dev); in mlxsw_pci_cq_page_pool_init()
1002 pp_params.dev = &mlxsw_pci->pdev->dev; in mlxsw_pci_cq_page_pool_init()
1024 static int mlxsw_pci_cq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_cq_init() argument
1027 enum mlxsw_pci_cq_type cq_type = mlxsw_pci_cq_type(mlxsw_pci, q); in mlxsw_pci_cq_init()
1054 err = mlxsw_cmd_sw2hw_cq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_cq_init()
1064 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_init()
1065 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_cq_init()
1073 static void mlxsw_pci_cq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_cq_fini() argument
1076 enum mlxsw_pci_cq_type cq_type = mlxsw_pci_cq_type(mlxsw_pci, q); in mlxsw_pci_cq_fini()
1081 mlxsw_cmd_hw2sw_cq(mlxsw_pci->core, q->num); in mlxsw_pci_cq_fini()
1116 struct mlxsw_pci *mlxsw_pci = q->pci; in mlxsw_pci_eq_tasklet() local
1135 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
1136 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_tasklet()
1138 cq_count = mlxsw_pci->num_cqs; in mlxsw_pci_eq_tasklet()
1140 q = mlxsw_pci_cq_get(mlxsw_pci, cqn); in mlxsw_pci_eq_tasklet()
1145 static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_eq_init() argument
1174 err = mlxsw_cmd_sw2hw_eq(mlxsw_pci->core, mbox, q->num); in mlxsw_pci_eq_init()
1178 mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
1179 mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q); in mlxsw_pci_eq_init()
1183 static void mlxsw_pci_eq_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_eq_fini() argument
1186 mlxsw_cmd_hw2sw_eq(mlxsw_pci->core, q->num); in mlxsw_pci_eq_fini()
1192 void (*pre_init)(struct mlxsw_pci *mlxsw_pci,
1194 int (*init)(struct mlxsw_pci *mlxsw_pci, char *mbox,
1196 void (*fini)(struct mlxsw_pci *mlxsw_pci,
1237 static int mlxsw_pci_queue_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_init() argument
1247 q_ops->pre_init(mlxsw_pci, q); in mlxsw_pci_queue_init()
1255 q->pci = mlxsw_pci; in mlxsw_pci_queue_init()
1258 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_queue_init()
1282 err = q_ops->init(mlxsw_pci, mbox, q); in mlxsw_pci_queue_init()
1290 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_init()
1295 static void mlxsw_pci_queue_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_fini() argument
1301 q_ops->fini(mlxsw_pci, q); in mlxsw_pci_queue_fini()
1303 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_queue_fini()
1307 static int mlxsw_pci_queue_group_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_queue_group_init() argument
1315 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_init()
1321 err = mlxsw_pci_queue_init(mlxsw_pci, mbox, q_ops, in mlxsw_pci_queue_group_init()
1332 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_init()
1337 static void mlxsw_pci_queue_group_fini(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_queue_group_fini() argument
1343 queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type); in mlxsw_pci_queue_group_fini()
1345 mlxsw_pci_queue_fini(mlxsw_pci, q_ops, &queue_group->q[i]); in mlxsw_pci_queue_group_fini()
1349 static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_aqs_init() argument
1351 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_aqs_init()
1364 err = mlxsw_cmd_query_aq_cap(mlxsw_pci->core, mbox); in mlxsw_pci_aqs_init()
1388 (mlxsw_pci->max_cqe_ver == MLXSW_PCI_CQE_V2 && in mlxsw_pci_aqs_init()
1395 mlxsw_pci->num_cqs = num_cqs; in mlxsw_pci_aqs_init()
1396 mlxsw_pci->num_sdqs = num_sdqs; in mlxsw_pci_aqs_init()
1398 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_eq_ops, in mlxsw_pci_aqs_init()
1405 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_cq_ops, in mlxsw_pci_aqs_init()
1412 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_sdq_ops, in mlxsw_pci_aqs_init()
1419 err = mlxsw_pci_queue_group_init(mlxsw_pci, mbox, &mlxsw_pci_rdq_ops, in mlxsw_pci_aqs_init()
1429 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_init()
1431 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_init()
1433 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_init()
1437 static void mlxsw_pci_aqs_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_aqs_fini() argument
1439 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_rdq_ops); in mlxsw_pci_aqs_fini()
1440 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops); in mlxsw_pci_aqs_fini()
1441 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops); in mlxsw_pci_aqs_fini()
1442 mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_eq_ops); in mlxsw_pci_aqs_fini()
1446 mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_config_profile_swid_config() argument
1466 mlxsw_pci_profile_get_kvd_sizes(const struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_profile_get_kvd_sizes() argument
1473 err = mlxsw_core_kvd_sizes_get(mlxsw_pci->core, profile, in mlxsw_pci_profile_get_kvd_sizes()
1486 static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_config_profile() argument
1552 if (profile->flood_mode_prefer_cff && mlxsw_pci->cff_support) { in mlxsw_pci_config_profile()
1558 mlxsw_pci->flood_mode = flood_mode; in mlxsw_pci_config_profile()
1564 mlxsw_pci->flood_mode = profile->flood_mode; in mlxsw_pci_config_profile()
1599 err = mlxsw_pci_profile_get_kvd_sizes(mlxsw_pci, profile, res); in mlxsw_pci_config_profile()
1617 mlxsw_pci_config_profile_swid_config(mlxsw_pci, mbox, i, in mlxsw_pci_config_profile()
1620 if (mlxsw_pci->max_cqe_ver > MLXSW_PCI_CQE_V0) { in mlxsw_pci_config_profile()
1632 if (profile->lag_mode_prefer_sw && mlxsw_pci->lag_mode_support) { in mlxsw_pci_config_profile()
1638 mlxsw_pci->lag_mode = lag_mode; in mlxsw_pci_config_profile()
1640 mlxsw_pci->lag_mode = MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_FW; in mlxsw_pci_config_profile()
1642 return mlxsw_cmd_config_profile_set(mlxsw_pci->core, mbox); in mlxsw_pci_config_profile()
1645 static int mlxsw_pci_boardinfo(struct mlxsw_pci *mlxsw_pci, char *mbox) in mlxsw_pci_boardinfo() argument
1647 struct mlxsw_bus_info *bus_info = &mlxsw_pci->bus_info; in mlxsw_pci_boardinfo()
1651 err = mlxsw_cmd_boardinfo(mlxsw_pci->core, mbox); in mlxsw_pci_boardinfo()
1659 static int mlxsw_pci_fw_area_init(struct mlxsw_pci *mlxsw_pci, char *mbox, in mlxsw_pci_fw_area_init() argument
1667 mlxsw_pci->fw_area.items = kcalloc(num_pages, sizeof(*mem_item), in mlxsw_pci_fw_area_init()
1669 if (!mlxsw_pci->fw_area.items) in mlxsw_pci_fw_area_init()
1671 mlxsw_pci->fw_area.count = num_pages; in mlxsw_pci_fw_area_init()
1675 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1678 mem_item->buf = dma_alloc_coherent(&mlxsw_pci->pdev->dev, in mlxsw_pci_fw_area_init()
1688 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1697 err = mlxsw_cmd_map_fa(mlxsw_pci->core, mbox, nent); in mlxsw_pci_fw_area_init()
1707 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_init()
1709 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_init()
1712 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_init()
1716 static void mlxsw_pci_fw_area_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_fw_area_fini() argument
1721 mlxsw_cmd_unmap_fa(mlxsw_pci->core); in mlxsw_pci_fw_area_fini()
1723 for (i = 0; i < mlxsw_pci->fw_area.count; i++) { in mlxsw_pci_fw_area_fini()
1724 mem_item = &mlxsw_pci->fw_area.items[i]; in mlxsw_pci_fw_area_fini()
1726 dma_free_coherent(&mlxsw_pci->pdev->dev, mem_item->size, in mlxsw_pci_fw_area_fini()
1729 kfree(mlxsw_pci->fw_area.items); in mlxsw_pci_fw_area_fini()
1734 struct mlxsw_pci *mlxsw_pci = dev_id; in mlxsw_pci_eq_irq_handler() local
1737 q = mlxsw_pci_eq_get(mlxsw_pci); in mlxsw_pci_eq_irq_handler()
1742 static int mlxsw_pci_mbox_alloc(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_alloc() argument
1745 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_alloc()
1759 static void mlxsw_pci_mbox_free(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_mbox_free() argument
1762 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_mbox_free()
1768 static int mlxsw_pci_sys_ready_wait(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sys_ready_wait() argument
1780 val = mlxsw_pci_read32(mlxsw_pci, FW_READY); in mlxsw_pci_sys_ready_wait()
1791 static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_reset_at_pci_disable() argument
1794 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_reset_at_pci_disable()
1806 err = mlxsw_reg_write(mlxsw_pci->core, MLXSW_REG(mrsr), mrsr_pl); in mlxsw_pci_reset_at_pci_disable()
1831 static int mlxsw_pci_reset_sw(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_reset_sw() argument
1836 return mlxsw_reg_write(mlxsw_pci->core, MLXSW_REG(mrsr), mrsr_pl); in mlxsw_pci_reset_sw()
1840 mlxsw_pci_reset(struct mlxsw_pci *mlxsw_pci, const struct pci_device_id *id) in mlxsw_pci_reset() argument
1842 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_reset()
1849 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_reset()
1857 if (mlxsw_pci->skip_reset) in mlxsw_pci_reset()
1862 err = mlxsw_reg_query(mlxsw_pci->core, MLXSW_REG(mcam), mcam_pl); in mlxsw_pci_reset()
1872 err = mlxsw_pci_reset_at_pci_disable(mlxsw_pci, in mlxsw_pci_reset()
1876 err = mlxsw_pci_reset_sw(mlxsw_pci); in mlxsw_pci_reset()
1881 err = mlxsw_pci_sys_ready_wait(mlxsw_pci, id, &sys_status); in mlxsw_pci_reset()
1891 static int mlxsw_pci_alloc_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_alloc_irq_vectors() argument
1895 err = pci_alloc_irq_vectors(mlxsw_pci->pdev, 1, 1, PCI_IRQ_MSIX); in mlxsw_pci_alloc_irq_vectors()
1897 dev_err(&mlxsw_pci->pdev->dev, "MSI-X init failed\n"); in mlxsw_pci_alloc_irq_vectors()
1901 static void mlxsw_pci_free_irq_vectors(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_free_irq_vectors() argument
1903 pci_free_irq_vectors(mlxsw_pci->pdev); in mlxsw_pci_free_irq_vectors()
1906 static void mlxsw_pci_num_sg_entries_set(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_num_sg_entries_set() argument
1911 mlxsw_pci->num_sg_entries = min(num_sg_entries, in mlxsw_pci_num_sg_entries_set()
1921 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_init() local
1922 struct pci_dev *pdev = mlxsw_pci->pdev; in mlxsw_pci_init()
1927 mlxsw_pci->core = mlxsw_core; in mlxsw_pci_init()
1933 err = mlxsw_pci_reset(mlxsw_pci, mlxsw_pci->id); in mlxsw_pci_init()
1937 err = mlxsw_pci_alloc_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
1947 mlxsw_pci->bus_info.fw_rev.major = in mlxsw_pci_init()
1949 mlxsw_pci->bus_info.fw_rev.minor = in mlxsw_pci_init()
1951 mlxsw_pci->bus_info.fw_rev.subminor = in mlxsw_pci_init()
1965 mlxsw_pci->doorbell_offset = in mlxsw_pci_init()
1974 mlxsw_pci->free_running_clock_offset = in mlxsw_pci_init()
1983 mlxsw_pci->utc_sec_offset = in mlxsw_pci_init()
1992 mlxsw_pci->utc_nsec_offset = in mlxsw_pci_init()
1995 mlxsw_pci->lag_mode_support = in mlxsw_pci_init()
1997 mlxsw_pci->cff_support = in mlxsw_pci_init()
2001 err = mlxsw_pci_fw_area_init(mlxsw_pci, mbox, num_pages); in mlxsw_pci_init()
2005 err = mlxsw_pci_boardinfo(mlxsw_pci, mbox); in mlxsw_pci_init()
2015 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V2; in mlxsw_pci_init()
2018 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V1; in mlxsw_pci_init()
2022 mlxsw_pci->max_cqe_ver = MLXSW_PCI_CQE_V0; in mlxsw_pci_init()
2028 err = mlxsw_pci_config_profile(mlxsw_pci, mbox, profile, res); in mlxsw_pci_init()
2039 mlxsw_pci_num_sg_entries_set(mlxsw_pci); in mlxsw_pci_init()
2041 err = mlxsw_pci_napi_devs_init(mlxsw_pci); in mlxsw_pci_init()
2045 err = mlxsw_pci_aqs_init(mlxsw_pci, mbox); in mlxsw_pci_init()
2051 mlxsw_pci->bus_info.device_kind, mlxsw_pci); in mlxsw_pci_init()
2060 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_init()
2062 mlxsw_pci_napi_devs_fini(mlxsw_pci); in mlxsw_pci_init()
2069 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_init()
2077 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_init()
2087 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_fini() local
2089 free_irq(pci_irq_vector(mlxsw_pci->pdev, 0), mlxsw_pci); in mlxsw_pci_fini()
2090 mlxsw_pci_aqs_fini(mlxsw_pci); in mlxsw_pci_fini()
2091 mlxsw_pci_napi_devs_fini(mlxsw_pci); in mlxsw_pci_fini()
2092 mlxsw_pci_fw_area_fini(mlxsw_pci); in mlxsw_pci_fini()
2093 mlxsw_pci_free_irq_vectors(mlxsw_pci); in mlxsw_pci_fini()
2097 mlxsw_pci_sdq_pick(struct mlxsw_pci *mlxsw_pci, in mlxsw_pci_sdq_pick() argument
2100 u8 ctl_sdq_count = mlxsw_pci->num_sdqs - 1; in mlxsw_pci_sdq_pick()
2110 return mlxsw_pci_sdq_get(mlxsw_pci, sdqn); in mlxsw_pci_sdq_pick()
2116 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit_busy() local
2117 struct mlxsw_pci_queue *q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit_busy()
2125 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_skb_transmit() local
2138 q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info); in mlxsw_pci_skb_transmit()
2154 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, 0, skb->data, in mlxsw_pci_skb_transmit()
2162 err = mlxsw_pci_wqe_frag_map(mlxsw_pci, wqe, i + 1, in mlxsw_pci_skb_transmit()
2179 mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q); in mlxsw_pci_skb_transmit()
2185 mlxsw_pci_wqe_frag_unmap(mlxsw_pci, wqe, i, DMA_TO_DEVICE); in mlxsw_pci_skb_transmit()
2197 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_cmd_exec() local
2206 err = mutex_lock_interruptible(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
2211 memcpy(mlxsw_pci->cmd.in_mbox.buf, in_mbox, in_mbox_size); in mlxsw_pci_cmd_exec()
2212 in_mapaddr = mlxsw_pci->cmd.in_mbox.mapaddr; in mlxsw_pci_cmd_exec()
2214 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_HI, upper_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
2215 mlxsw_pci_write32(mlxsw_pci, CIR_IN_PARAM_LO, lower_32_bits(in_mapaddr)); in mlxsw_pci_cmd_exec()
2218 out_mapaddr = mlxsw_pci->cmd.out_mbox.mapaddr; in mlxsw_pci_cmd_exec()
2219 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_HI, upper_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
2220 mlxsw_pci_write32(mlxsw_pci, CIR_OUT_PARAM_LO, lower_32_bits(out_mapaddr)); in mlxsw_pci_cmd_exec()
2222 mlxsw_pci_write32(mlxsw_pci, CIR_IN_MODIFIER, in_mod); in mlxsw_pci_cmd_exec()
2223 mlxsw_pci_write32(mlxsw_pci, CIR_TOKEN, 0); in mlxsw_pci_cmd_exec()
2228 mlxsw_pci_write32(mlxsw_pci, CIR_CTRL, in mlxsw_pci_cmd_exec()
2235 u32 ctrl = mlxsw_pci_read32(mlxsw_pci, CIR_CTRL); in mlxsw_pci_cmd_exec()
2260 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
2263 tmp = cpu_to_be32(mlxsw_pci_read32(mlxsw_pci, in mlxsw_pci_cmd_exec()
2267 memcpy(out_mbox, mlxsw_pci->cmd.out_mbox.buf, out_mbox_size); in mlxsw_pci_cmd_exec()
2270 mutex_unlock(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_exec()
2277 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_h() local
2280 frc_offset_h = mlxsw_pci->free_running_clock_offset; in mlxsw_pci_read_frc_h()
2281 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_h); in mlxsw_pci_read_frc_h()
2286 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_frc_l() local
2289 frc_offset_l = mlxsw_pci->free_running_clock_offset + 4; in mlxsw_pci_read_frc_l()
2290 return mlxsw_pci_read32_off(mlxsw_pci, frc_offset_l); in mlxsw_pci_read_frc_l()
2295 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_sec() local
2297 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_sec_offset); in mlxsw_pci_read_utc_sec()
2302 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_read_utc_nsec() local
2304 return mlxsw_pci_read32_off(mlxsw_pci, mlxsw_pci->utc_nsec_offset); in mlxsw_pci_read_utc_nsec()
2310 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_lag_mode() local
2312 return mlxsw_pci->lag_mode; in mlxsw_pci_lag_mode()
2318 struct mlxsw_pci *mlxsw_pci = bus_priv; in mlxsw_pci_flood_mode() local
2320 return mlxsw_pci->flood_mode; in mlxsw_pci_flood_mode()
2339 static int mlxsw_pci_cmd_init(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_init() argument
2343 mutex_init(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
2345 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
2349 err = mlxsw_pci_mbox_alloc(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_init()
2356 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_init()
2358 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_init()
2362 static void mlxsw_pci_cmd_fini(struct mlxsw_pci *mlxsw_pci) in mlxsw_pci_cmd_fini() argument
2364 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.out_mbox); in mlxsw_pci_cmd_fini()
2365 mlxsw_pci_mbox_free(mlxsw_pci, &mlxsw_pci->cmd.in_mbox); in mlxsw_pci_cmd_fini()
2366 mutex_destroy(&mlxsw_pci->cmd.lock); in mlxsw_pci_cmd_fini()
2372 struct mlxsw_pci *mlxsw_pci; in mlxsw_pci_probe() local
2375 mlxsw_pci = kzalloc(sizeof(*mlxsw_pci), GFP_KERNEL); in mlxsw_pci_probe()
2376 if (!mlxsw_pci) in mlxsw_pci_probe()
2406 mlxsw_pci->hw_addr = ioremap(pci_resource_start(pdev, 0), in mlxsw_pci_probe()
2408 if (!mlxsw_pci->hw_addr) { in mlxsw_pci_probe()
2415 mlxsw_pci->pdev = pdev; in mlxsw_pci_probe()
2416 pci_set_drvdata(pdev, mlxsw_pci); in mlxsw_pci_probe()
2418 err = mlxsw_pci_cmd_init(mlxsw_pci); in mlxsw_pci_probe()
2422 mlxsw_pci->bus_info.device_kind = driver_name; in mlxsw_pci_probe()
2423 mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev); in mlxsw_pci_probe()
2424 mlxsw_pci->bus_info.dev = &pdev->dev; in mlxsw_pci_probe()
2425 mlxsw_pci->bus_info.read_clock_capable = true; in mlxsw_pci_probe()
2426 mlxsw_pci->id = id; in mlxsw_pci_probe()
2428 err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, in mlxsw_pci_probe()
2429 &mlxsw_pci_bus, mlxsw_pci, false, in mlxsw_pci_probe()
2439 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_probe()
2441 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_probe()
2449 kfree(mlxsw_pci); in mlxsw_pci_probe()
2455 struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); in mlxsw_pci_remove() local
2457 mlxsw_core_bus_device_unregister(mlxsw_pci->core, false); in mlxsw_pci_remove()
2458 mlxsw_pci_cmd_fini(mlxsw_pci); in mlxsw_pci_remove()
2459 iounmap(mlxsw_pci->hw_addr); in mlxsw_pci_remove()
2460 pci_release_regions(mlxsw_pci->pdev); in mlxsw_pci_remove()
2461 pci_disable_device(mlxsw_pci->pdev); in mlxsw_pci_remove()
2462 kfree(mlxsw_pci); in mlxsw_pci_remove()
2467 struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); in mlxsw_pci_reset_prepare() local
2469 mlxsw_core_bus_device_unregister(mlxsw_pci->core, false); in mlxsw_pci_reset_prepare()
2474 struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); in mlxsw_pci_reset_done() local
2476 mlxsw_pci->skip_reset = true; in mlxsw_pci_reset_done()
2477 mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, &mlxsw_pci_bus, in mlxsw_pci_reset_done()
2478 mlxsw_pci, false, NULL, NULL); in mlxsw_pci_reset_done()
2479 mlxsw_pci->skip_reset = false; in mlxsw_pci_reset_done()