Lines Matching refs:dev

34 static int find_dvsec(struct pci_dev *dev, int dvsec_id)  in find_dvsec()  argument
36 return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_IBM, dvsec_id); in find_dvsec()
39 static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx) in find_dvsec_afu_ctrl() argument
45 while ((vsec = pci_find_next_ext_capability(dev, vsec, in find_dvsec_afu_ctrl()
47 pci_read_config_word(dev, vsec + OCXL_DVSEC_VENDOR_OFFSET, in find_dvsec_afu_ctrl()
49 pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, &id); in find_dvsec_afu_ctrl()
53 pci_read_config_byte(dev, in find_dvsec_afu_ctrl()
69 static struct pci_dev *get_function_0(struct pci_dev *dev) in get_function_0() argument
71 unsigned int devfn = PCI_DEVFN(PCI_SLOT(dev->devfn), 0); in get_function_0()
73 return pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), in get_function_0()
74 dev->bus->number, devfn); in get_function_0()
77 static void read_pasid(struct pci_dev *dev, struct ocxl_fn_config *fn) in read_pasid() argument
82 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PASID); in read_pasid()
88 dev_dbg(&dev->dev, "Function doesn't require any PASID\n"); in read_pasid()
92 pci_read_config_word(dev, pos + PCI_PASID_CAP, &val); in read_pasid()
96 dev_dbg(&dev->dev, "PASID capability:\n"); in read_pasid()
97 dev_dbg(&dev->dev, " Max PASID log = %d\n", fn->max_pasid_log); in read_pasid()
100 static int read_dvsec_tl(struct pci_dev *dev, struct ocxl_fn_config *fn) in read_dvsec_tl() argument
104 pos = find_dvsec(dev, OCXL_DVSEC_TL_ID); in read_dvsec_tl()
105 if (!pos && PCI_FUNC(dev->devfn) == 0) { in read_dvsec_tl()
106 dev_err(&dev->dev, "Can't find TL DVSEC\n"); in read_dvsec_tl()
109 if (pos && PCI_FUNC(dev->devfn) != 0) { in read_dvsec_tl()
110 dev_err(&dev->dev, "TL DVSEC is only allowed on function 0\n"); in read_dvsec_tl()
117 static int read_dvsec_function(struct pci_dev *dev, struct ocxl_fn_config *fn) in read_dvsec_function() argument
122 pos = find_dvsec(dev, OCXL_DVSEC_FUNC_ID); in read_dvsec_function()
124 dev_err(&dev->dev, "Can't find function DVSEC\n"); in read_dvsec_function()
129 pci_read_config_dword(dev, pos + OCXL_DVSEC_FUNC_OFF_INDEX, &val); in read_dvsec_function()
133 dev_dbg(&dev->dev, "Function doesn't define any AFU\n"); in read_dvsec_function()
139 dev_dbg(&dev->dev, "Function DVSEC:\n"); in read_dvsec_function()
140 dev_dbg(&dev->dev, " Max AFU index = %d\n", fn->max_afu_index); in read_dvsec_function()
144 static int read_dvsec_afu_info(struct pci_dev *dev, struct ocxl_fn_config *fn) in read_dvsec_afu_info() argument
153 pos = find_dvsec(dev, OCXL_DVSEC_AFU_INFO_ID); in read_dvsec_afu_info()
155 dev_err(&dev->dev, "Can't find AFU information DVSEC\n"); in read_dvsec_afu_info()
162 static int read_dvsec_vendor(struct pci_dev *dev) in read_dvsec_vendor() argument
175 if (PCI_FUNC(dev->devfn) != 0) in read_dvsec_vendor()
178 pos = find_dvsec(dev, OCXL_DVSEC_VENDOR_ID); in read_dvsec_vendor()
182 pci_read_config_dword(dev, pos + OCXL_DVSEC_VENDOR_CFG_VERS, &cfg); in read_dvsec_vendor()
183 pci_read_config_dword(dev, pos + OCXL_DVSEC_VENDOR_TLX_VERS, &tlx); in read_dvsec_vendor()
184 pci_read_config_dword(dev, pos + OCXL_DVSEC_VENDOR_DLX_VERS, &dlx); in read_dvsec_vendor()
185 pci_read_config_dword(dev, pos + OCXL_DVSEC_VENDOR_RESET_RELOAD, in read_dvsec_vendor()
188 dev_dbg(&dev->dev, "Vendor specific DVSEC:\n"); in read_dvsec_vendor()
189 dev_dbg(&dev->dev, " CFG version = 0x%x\n", cfg); in read_dvsec_vendor()
190 dev_dbg(&dev->dev, " TLX version = 0x%x\n", tlx); in read_dvsec_vendor()
191 dev_dbg(&dev->dev, " DLX version = 0x%x\n", dlx); in read_dvsec_vendor()
192 dev_dbg(&dev->dev, " ResetReload = 0x%x\n", reset_reload); in read_dvsec_vendor()
208 static int get_dvsec_vendor0(struct pci_dev *dev, struct pci_dev **dev0, in get_dvsec_vendor0() argument
213 if (PCI_FUNC(dev->devfn) != 0) { in get_dvsec_vendor0()
214 dev = get_function_0(dev); in get_dvsec_vendor0()
215 if (!dev) in get_dvsec_vendor0()
218 dev = pci_dev_get(dev); in get_dvsec_vendor0()
220 pos = find_dvsec(dev, OCXL_DVSEC_VENDOR_ID); in get_dvsec_vendor0()
222 pci_dev_put(dev); in get_dvsec_vendor0()
225 *dev0 = dev; in get_dvsec_vendor0()
230 int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val) in ocxl_config_get_reset_reload() argument
236 if (get_dvsec_vendor0(dev, &dev0, &pos)) in ocxl_config_get_reset_reload()
246 int ocxl_config_set_reset_reload(struct pci_dev *dev, int val) in ocxl_config_set_reset_reload() argument
252 if (get_dvsec_vendor0(dev, &dev0, &pos)) in ocxl_config_set_reset_reload()
267 static int validate_function(struct pci_dev *dev, struct ocxl_fn_config *fn) in validate_function() argument
270 dev_err(&dev->dev, in validate_function()
276 dev_err(&dev->dev, in validate_function()
284 int ocxl_config_read_function(struct pci_dev *dev, struct ocxl_fn_config *fn) in ocxl_config_read_function() argument
288 read_pasid(dev, fn); in ocxl_config_read_function()
290 rc = read_dvsec_tl(dev, fn); in ocxl_config_read_function()
292 dev_err(&dev->dev, in ocxl_config_read_function()
298 rc = read_dvsec_function(dev, fn); in ocxl_config_read_function()
300 dev_err(&dev->dev, in ocxl_config_read_function()
305 rc = read_dvsec_afu_info(dev, fn); in ocxl_config_read_function()
307 dev_err(&dev->dev, "Invalid AFU configuration: %d\n", rc); in ocxl_config_read_function()
311 rc = read_dvsec_vendor(dev); in ocxl_config_read_function()
313 dev_err(&dev->dev, in ocxl_config_read_function()
319 rc = validate_function(dev, fn); in ocxl_config_read_function()
324 static int read_afu_info(struct pci_dev *dev, struct ocxl_fn_config *fn, in read_afu_info() argument
333 dev_err(&dev->dev, "Invalid offset in AFU info DVSEC\n"); in read_afu_info()
337 pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, offset); in read_afu_info()
338 pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, &val); in read_afu_info()
341 dev_err(&dev->dev, in read_afu_info()
347 pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_OFF, &val); in read_afu_info()
349 pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_INFO_DATA, data); in read_afu_info()
362 static int read_template_version(struct pci_dev *dev, struct ocxl_fn_config *fn, in read_template_version() argument
369 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_VERSION, &val32); in read_template_version()
380 int ocxl_config_check_afu_index(struct pci_dev *dev, in ocxl_config_check_afu_index() argument
387 pci_write_config_byte(dev, in ocxl_config_check_afu_index()
391 rc = read_template_version(dev, fn, &len, &templ_version); in ocxl_config_check_afu_index()
399 dev_dbg(&dev->dev, "AFU descriptor template version %d.%d\n", in ocxl_config_check_afu_index()
411 dev_warn(&dev->dev, "Unknown AFU template version %#x\n", in ocxl_config_check_afu_index()
416 dev_warn(&dev->dev, in ocxl_config_check_afu_index()
422 static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn, in read_afu_name() argument
430 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_NAME + i, &val); in read_afu_name()
440 static int read_afu_mmio(struct pci_dev *dev, struct ocxl_fn_config *fn, in read_afu_mmio() argument
449 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_GLOBAL, &val); in read_afu_mmio()
455 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_GLOBAL + 4, &val); in read_afu_mmio()
460 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_GLOBAL_SZ, &val); in read_afu_mmio()
468 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_PP, &val); in read_afu_mmio()
474 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_PP + 4, &val); in read_afu_mmio()
479 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_MMIO_PP_SZ, &val); in read_afu_mmio()
487 static int read_afu_control(struct pci_dev *dev, struct ocxl_afu_config *afu) in read_afu_control() argument
493 pos = find_dvsec_afu_ctrl(dev, afu->idx); in read_afu_control()
495 dev_err(&dev->dev, "Can't find AFU control DVSEC for AFU %d\n", in read_afu_control()
501 pci_read_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_SUP, &val8); in read_afu_control()
504 pci_read_config_word(dev, pos + OCXL_DVSEC_AFU_CTRL_ACTAG_SUP, &val16); in read_afu_control()
525 static int validate_afu(struct pci_dev *dev, struct ocxl_afu_config *afu) in validate_afu() argument
530 dev_err(&dev->dev, "Empty AFU name\n"); in validate_afu()
535 dev_err(&dev->dev, in validate_afu()
544 dev_err(&dev->dev, "Invalid global MMIO bar number\n"); in validate_afu()
550 dev_err(&dev->dev, "Invalid per-process MMIO bar number\n"); in validate_afu()
564 static int read_afu_lpc_memory_info(struct pci_dev *dev, in read_afu_lpc_memory_info() argument
590 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_ALL_MEM_SZ, &val32); in read_afu_lpc_memory_info()
610 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_LPC_MEM_START, &val32); in read_afu_lpc_memory_info()
616 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_LPC_MEM_START + 4, &val32); in read_afu_lpc_memory_info()
622 rc = read_template_version(dev, fn, &templ_len, &templ_version); in read_afu_lpc_memory_info()
627 rc = read_afu_info(dev, fn, in read_afu_lpc_memory_info()
633 rc = read_afu_info(dev, fn, in read_afu_lpc_memory_info()
652 int ocxl_config_read_afu(struct pci_dev *dev, struct ocxl_fn_config *fn, in ocxl_config_read_afu() argument
664 pci_write_config_byte(dev, in ocxl_config_read_afu()
668 rc = read_afu_name(dev, fn, afu); in ocxl_config_read_afu()
672 rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_AFU_VERSION, &val32); in ocxl_config_read_afu()
681 rc = read_afu_mmio(dev, fn, afu); in ocxl_config_read_afu()
685 rc = read_afu_lpc_memory_info(dev, fn, afu); in ocxl_config_read_afu()
689 rc = read_afu_control(dev, afu); in ocxl_config_read_afu()
693 dev_dbg(&dev->dev, "AFU configuration:\n"); in ocxl_config_read_afu()
694 dev_dbg(&dev->dev, " name = %s\n", afu->name); in ocxl_config_read_afu()
695 dev_dbg(&dev->dev, " version = %d.%d\n", afu->version_major, in ocxl_config_read_afu()
697 dev_dbg(&dev->dev, " global mmio bar = %hhu\n", afu->global_mmio_bar); in ocxl_config_read_afu()
698 dev_dbg(&dev->dev, " global mmio offset = %#llx\n", in ocxl_config_read_afu()
700 dev_dbg(&dev->dev, " global mmio size = %#x\n", afu->global_mmio_size); in ocxl_config_read_afu()
701 dev_dbg(&dev->dev, " pp mmio bar = %hhu\n", afu->pp_mmio_bar); in ocxl_config_read_afu()
702 dev_dbg(&dev->dev, " pp mmio offset = %#llx\n", afu->pp_mmio_offset); in ocxl_config_read_afu()
703 dev_dbg(&dev->dev, " pp mmio stride = %#x\n", afu->pp_mmio_stride); in ocxl_config_read_afu()
704 dev_dbg(&dev->dev, " lpc_mem offset = %#llx\n", afu->lpc_mem_offset); in ocxl_config_read_afu()
705 dev_dbg(&dev->dev, " lpc_mem size = %#llx\n", afu->lpc_mem_size); in ocxl_config_read_afu()
706 dev_dbg(&dev->dev, " special purpose mem offset = %#llx\n", in ocxl_config_read_afu()
708 dev_dbg(&dev->dev, " special purpose mem size = %#llx\n", in ocxl_config_read_afu()
710 dev_dbg(&dev->dev, " pasid supported (log) = %u\n", in ocxl_config_read_afu()
712 dev_dbg(&dev->dev, " actag supported = %u\n", in ocxl_config_read_afu()
715 rc = validate_afu(dev, afu); in ocxl_config_read_afu()
720 int ocxl_config_get_actag_info(struct pci_dev *dev, u16 *base, u16 *enabled, in ocxl_config_get_actag_info() argument
730 rc = pnv_ocxl_get_actag(dev, base, enabled, supported); in ocxl_config_get_actag_info()
732 dev_err(&dev->dev, "Can't get actag for device: %d\n", rc); in ocxl_config_get_actag_info()
739 void ocxl_config_set_afu_actag(struct pci_dev *dev, int pos, int actag_base, in ocxl_config_set_afu_actag() argument
745 pci_write_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_ACTAG_EN, val); in ocxl_config_set_afu_actag()
748 pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_ACTAG_BASE, val); in ocxl_config_set_afu_actag()
752 int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count) in ocxl_config_get_pasid_info() argument
754 return pnv_ocxl_get_pasid_count(dev, count); in ocxl_config_get_pasid_info()
757 void ocxl_config_set_afu_pasid(struct pci_dev *dev, int pos, int pasid_base, in ocxl_config_set_afu_pasid() argument
764 pci_write_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_EN, val8); in ocxl_config_set_afu_pasid()
766 pci_read_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_BASE, in ocxl_config_set_afu_pasid()
770 pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_BASE, in ocxl_config_set_afu_pasid()
775 void ocxl_config_set_afu_state(struct pci_dev *dev, int pos, int enable) in ocxl_config_set_afu_state() argument
779 pci_read_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_ENABLE, &val); in ocxl_config_set_afu_state()
784 pci_write_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_ENABLE, val); in ocxl_config_set_afu_state()
788 int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec) in ocxl_config_set_TL() argument
800 if (PCI_FUNC(dev->devfn) != 0) in ocxl_config_set_TL()
824 rc = pnv_ocxl_get_tl_cap(dev, &recv_cap, recv_rate, in ocxl_config_set_TL()
831 pci_write_config_dword(dev, in ocxl_config_set_TL()
836 pci_write_config_dword(dev, tl_dvsec + OCXL_DVSEC_TL_SEND_CAP, val); in ocxl_config_set_TL()
838 pci_write_config_dword(dev, tl_dvsec + OCXL_DVSEC_TL_SEND_CAP + 4, val); in ocxl_config_set_TL()
844 pci_read_config_dword(dev, in ocxl_config_set_TL()
850 pci_read_config_dword(dev, tl_dvsec + OCXL_DVSEC_TL_RECV_CAP, &val); in ocxl_config_set_TL()
852 pci_read_config_dword(dev, tl_dvsec + OCXL_DVSEC_TL_RECV_CAP + 4, &val); in ocxl_config_set_TL()
855 rc = pnv_ocxl_set_tl_conf(dev, recv_cap, __pa(recv_rate), in ocxl_config_set_TL()
877 pci_write_config_byte(dev, tl_dvsec + OCXL_DVSEC_TL_BACKOFF_TIMERS, in ocxl_config_set_TL()
887 int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, int pasid) in ocxl_config_terminate_pasid() argument
892 pci_read_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, in ocxl_config_terminate_pasid()
895 dev_err(&dev->dev, in ocxl_config_terminate_pasid()
904 pci_write_config_dword(dev, in ocxl_config_terminate_pasid()
909 pci_read_config_dword(dev, afu_control + OCXL_DVSEC_AFU_CTRL_TERM_PASID, in ocxl_config_terminate_pasid()
913 dev_err(&dev->dev, in ocxl_config_terminate_pasid()
919 pci_read_config_dword(dev, in ocxl_config_terminate_pasid()
927 void ocxl_config_set_actag(struct pci_dev *dev, int func_dvsec, u32 tag_first, in ocxl_config_set_actag() argument
934 pci_write_config_dword(dev, func_dvsec + OCXL_DVSEC_FUNC_OFF_ACTAG, in ocxl_config_set_actag()