Lines Matching full:table
194 dev_err(dev, "table %u not support multi-hop addressing!\n",
203 struct hns_roce_hem_table *table, unsigned long *obj,
212 if (get_hem_table_config(hr_dev, mhop, table->type))
222 bt_num = hns_roce_get_bt_num(table->type, mhop->hop_num);
224 chunk_size = table->type < HEM_TYPE_MTT ? mhop->buf_chunk_size :
226 table_idx = *obj / (chunk_size / table->obj_size);
241 dev_err(dev, "table %u not support hop_num = %u!\n",
242 table->type, mhop->hop_num);
295 struct hns_roce_hem_table *table, unsigned long obj,
306 ret = hns_roce_calc_hem_mhop(hr_dev, table, &mhop_obj, mhop);
314 bt_num = hns_roce_get_bt_num(table->type, mhop->hop_num);
330 dev_err(dev, "table %u not support mhop.hop_num = %u!\n",
331 table->type, mhop->hop_num);
335 if (unlikely(index->buf >= table->num_hem)) {
336 dev_err(dev, "table %u exceed hem limt idx %llu, max %lu!\n",
337 table->type, index->buf, table->num_hem);
345 struct hns_roce_hem_table *table,
353 hns_roce_free_hem(hr_dev, table->hem[index->buf]);
354 table->hem[index->buf] = NULL;
358 dma_free_coherent(dev, bt_size, table->bt_l1[index->l1],
359 table->bt_l1_dma_addr[index->l1]);
360 table->bt_l1[index->l1] = NULL;
364 dma_free_coherent(dev, bt_size, table->bt_l0[index->l0],
365 table->bt_l0_dma_addr[index->l0]);
366 table->bt_l0[index->l0] = NULL;
371 struct hns_roce_hem_table *table,
382 if ((check_whether_bt_num_3(table->type, mhop->hop_num) ||
383 check_whether_bt_num_2(table->type, mhop->hop_num)) &&
384 !table->bt_l0[index->l0]) {
385 table->bt_l0[index->l0] = dma_alloc_coherent(dev, bt_size,
386 &table->bt_l0_dma_addr[index->l0],
388 if (!table->bt_l0[index->l0]) {
396 if (check_whether_bt_num_3(table->type, mhop->hop_num) &&
397 !table->bt_l1[index->l1]) {
398 table->bt_l1[index->l1] = dma_alloc_coherent(dev, bt_size,
399 &table->bt_l1_dma_addr[index->l1],
401 if (!table->bt_l1[index->l1]) {
406 *(table->bt_l0[index->l0] + mhop->l1_idx) =
407 table->bt_l1_dma_addr[index->l1];
414 size = table->type < HEM_TYPE_MTT ? mhop->buf_chunk_size : bt_size;
415 table->hem[index->buf] = hns_roce_alloc_hem(hr_dev, size);
416 if (!table->hem[index->buf]) {
422 bt_ba = table->hem[index->buf]->dma;
424 if (table->type < HEM_TYPE_MTT) {
426 *(table->bt_l1[index->l1] + mhop->l2_idx) = bt_ba;
428 *(table->bt_l0[index->l0] + mhop->l1_idx) = bt_ba;
430 *(table->bt_l0[index->l0] + mhop->l1_idx) = bt_ba;
435 free_mhop_hem(hr_dev, table, mhop, index);
441 struct hns_roce_hem_table *table, unsigned long obj,
450 ret = hr_dev->hw->set_hem(hr_dev, table, obj, 0);
458 ret = hr_dev->hw->set_hem(hr_dev, table, obj, 1);
470 ret = hr_dev->hw->set_hem(hr_dev, table, obj, step_idx);
479 struct hns_roce_hem_table *table,
487 ret = calc_hem_config(hr_dev, table, obj, &mhop, &index);
493 mutex_lock(&table->mutex);
494 if (table->hem[index.buf]) {
495 refcount_inc(&table->hem[index.buf]->refcount);
499 ret = alloc_mhop_hem(hr_dev, table, &mhop, &index);
506 if (table->type < HEM_TYPE_MTT) {
507 ret = set_mhop_hem(hr_dev, table, obj, &mhop, &index);
514 refcount_set(&table->hem[index.buf]->refcount, 1);
518 free_mhop_hem(hr_dev, table, &mhop, &index);
520 mutex_unlock(&table->mutex);
525 struct hns_roce_hem_table *table, unsigned long obj)
531 if (hns_roce_check_whether_mhop(hr_dev, table->type))
532 return hns_roce_table_mhop_get(hr_dev, table, obj);
534 i = obj / (table->table_chunk_size / table->obj_size);
536 mutex_lock(&table->mutex);
538 if (table->hem[i]) {
539 refcount_inc(&table->hem[i]->refcount);
543 table->hem[i] = hns_roce_alloc_hem(hr_dev, table->table_chunk_size);
544 if (!table->hem[i]) {
550 ret = hr_dev->hw->set_hem(hr_dev, table, obj, HEM_HOP_STEP_DIRECT);
552 hns_roce_free_hem(hr_dev, table->hem[i]);
553 table->hem[i] = NULL;
559 refcount_set(&table->hem[i]->refcount, 1);
561 mutex_unlock(&table->mutex);
566 struct hns_roce_hem_table *table, unsigned long obj,
578 if (check_whether_bt_num_2(table->type, hop_num)) {
579 if (hns_roce_check_hem_null(table->hem, index->buf,
580 chunk_ba_num, table->num_hem))
582 } else if (check_whether_bt_num_3(table->type, hop_num)) {
583 if (hns_roce_check_hem_null(table->hem, index->buf,
584 chunk_ba_num, table->num_hem)) {
586 if (hns_roce_check_bt_null(table->bt_l1, index->l1,
592 if (table->type < HEM_TYPE_MTT) {
598 ret = hr_dev->hw->clear_hem(hr_dev, table, obj, step_idx);
604 ret = hr_dev->hw->clear_hem(hr_dev, table, obj, 1);
611 ret = hr_dev->hw->clear_hem(hr_dev, table, obj, 0);
620 struct hns_roce_hem_table *table,
629 ret = calc_hem_config(hr_dev, table, obj, &mhop, &index);
636 mutex_lock(&table->mutex);
637 else if (!refcount_dec_and_mutex_lock(&table->hem[index.buf]->refcount,
638 &table->mutex))
641 clear_mhop_hem(hr_dev, table, obj, &mhop, &index);
642 free_mhop_hem(hr_dev, table, &mhop, &index);
644 mutex_unlock(&table->mutex);
648 struct hns_roce_hem_table *table, unsigned long obj)
654 if (hns_roce_check_whether_mhop(hr_dev, table->type)) {
655 hns_roce_table_mhop_put(hr_dev, table, obj, 1);
659 i = obj / (table->table_chunk_size / table->obj_size);
661 if (!refcount_dec_and_mutex_lock(&table->hem[i]->refcount,
662 &table->mutex))
665 ret = hr_dev->hw->clear_hem(hr_dev, table, obj, HEM_HOP_STEP_DIRECT);
670 hns_roce_free_hem(hr_dev, table->hem[i]);
671 table->hem[i] = NULL;
673 mutex_unlock(&table->mutex);
677 struct hns_roce_hem_table *table,
690 mutex_lock(&table->mutex);
692 if (!hns_roce_check_whether_mhop(hr_dev, table->type)) {
693 obj_per_chunk = table->table_chunk_size / table->obj_size;
694 hem = table->hem[obj / obj_per_chunk];
696 dma_offset = offset = idx_offset * table->obj_size;
700 if (hns_roce_calc_hem_mhop(hr_dev, table, &mhop_obj, &mhop))
711 hem = table->hem[hem_idx];
724 mutex_unlock(&table->mutex);
729 struct hns_roce_hem_table *table, u32 type,
736 table->table_chunk_size = hr_dev->caps.chunk_sz;
737 obj_per_chunk = table->table_chunk_size / obj_size;
740 table->hem = kcalloc(num_hem, sizeof(*table->hem), GFP_KERNEL);
741 if (!table->hem)
766 table->hem = kcalloc(num_hem, sizeof(*table->hem),
768 if (!table->hem)
775 table->bt_l1 = kcalloc(num_bt_l1,
776 sizeof(*table->bt_l1),
778 if (!table->bt_l1)
781 table->bt_l1_dma_addr = kcalloc(num_bt_l1,
782 sizeof(*table->bt_l1_dma_addr),
785 if (!table->bt_l1_dma_addr)
791 table->bt_l0 = kcalloc(num_bt_l0, sizeof(*table->bt_l0),
793 if (!table->bt_l0)
796 table->bt_l0_dma_addr = kcalloc(num_bt_l0,
797 sizeof(*table->bt_l0_dma_addr),
799 if (!table->bt_l0_dma_addr)
804 table->type = type;
805 table->num_hem = num_hem;
806 table->obj_size = obj_size;
807 mutex_init(&table->mutex);
812 kfree(table->bt_l0);
813 table->bt_l0 = NULL;
816 kfree(table->bt_l1_dma_addr);
817 table->bt_l1_dma_addr = NULL;
820 kfree(table->bt_l1);
821 table->bt_l1 = NULL;
824 kfree(table->hem);
825 table->hem = NULL;
832 struct hns_roce_hem_table *table)
839 if (hns_roce_calc_hem_mhop(hr_dev, table, NULL, &mhop))
841 buf_chunk_size = table->type < HEM_TYPE_MTT ? mhop.buf_chunk_size :
844 for (i = 0; i < table->num_hem; ++i) {
845 obj = i * buf_chunk_size / table->obj_size;
846 if (table->hem[i])
847 hns_roce_table_mhop_put(hr_dev, table, obj, 0);
850 kfree(table->hem);
851 table->hem = NULL;
852 kfree(table->bt_l1);
853 table->bt_l1 = NULL;
854 kfree(table->bt_l1_dma_addr);
855 table->bt_l1_dma_addr = NULL;
856 kfree(table->bt_l0);
857 table->bt_l0 = NULL;
858 kfree(table->bt_l0_dma_addr);
859 table->bt_l0_dma_addr = NULL;
863 struct hns_roce_hem_table *table)
870 if (hns_roce_check_whether_mhop(hr_dev, table->type)) {
871 hns_roce_cleanup_mhop_hem_table(hr_dev, table);
872 mutex_destroy(&table->mutex);
876 for (i = 0; i < table->num_hem; ++i)
877 if (table->hem[i]) {
878 obj = i * table->table_chunk_size / table->obj_size;
879 ret = hr_dev->hw->clear_hem(hr_dev, table, obj, 0);
884 hns_roce_free_hem(hr_dev, table->hem[i]);
887 mutex_destroy(&table->mutex);
888 kfree(table->hem);
895 &hr_dev->srq_table.table);
896 hns_roce_cleanup_hem_table(hr_dev, &hr_dev->cq_table.table);
990 /* assign L0 table address to hem from root bt */
1023 * hopnum base address table levels
1035 * @bt_level: base address table level
1361 /* construct the base address table and link them by address hop config */