Lines Matching refs:mgr

25 	struct fpga_manager *mgr;  member
28 static inline void fpga_mgr_fpga_remove(struct fpga_manager *mgr) in fpga_mgr_fpga_remove() argument
30 if (mgr->mops->fpga_remove) in fpga_mgr_fpga_remove()
31 mgr->mops->fpga_remove(mgr); in fpga_mgr_fpga_remove()
34 static inline enum fpga_mgr_states fpga_mgr_state(struct fpga_manager *mgr) in fpga_mgr_state() argument
36 if (mgr->mops->state) in fpga_mgr_state()
37 return mgr->mops->state(mgr); in fpga_mgr_state()
41 static inline u64 fpga_mgr_status(struct fpga_manager *mgr) in fpga_mgr_status() argument
43 if (mgr->mops->status) in fpga_mgr_status()
44 return mgr->mops->status(mgr); in fpga_mgr_status()
48 static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count) in fpga_mgr_write() argument
50 if (mgr->mops->write) in fpga_mgr_write()
51 return mgr->mops->write(mgr, buf, count); in fpga_mgr_write()
59 static inline int fpga_mgr_write_complete(struct fpga_manager *mgr, in fpga_mgr_write_complete() argument
64 mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE; in fpga_mgr_write_complete()
65 if (mgr->mops->write_complete) in fpga_mgr_write_complete()
66 ret = mgr->mops->write_complete(mgr, info); in fpga_mgr_write_complete()
68 dev_err(&mgr->dev, "Error after writing image data to FPGA\n"); in fpga_mgr_write_complete()
69 mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR; in fpga_mgr_write_complete()
72 mgr->state = FPGA_MGR_STATE_OPERATING; in fpga_mgr_write_complete()
77 static inline int fpga_mgr_parse_header(struct fpga_manager *mgr, in fpga_mgr_parse_header() argument
81 if (mgr->mops->parse_header) in fpga_mgr_parse_header()
82 return mgr->mops->parse_header(mgr, info, buf, count); in fpga_mgr_parse_header()
86 static inline int fpga_mgr_write_init(struct fpga_manager *mgr, in fpga_mgr_write_init() argument
90 if (mgr->mops->write_init) in fpga_mgr_write_init()
91 return mgr->mops->write_init(mgr, info, buf, count); in fpga_mgr_write_init()
95 static inline int fpga_mgr_write_sg(struct fpga_manager *mgr, in fpga_mgr_write_sg() argument
98 if (mgr->mops->write_sg) in fpga_mgr_write_sg()
99 return mgr->mops->write_sg(mgr, sgt); in fpga_mgr_write_sg()
151 static int fpga_mgr_parse_header_mapped(struct fpga_manager *mgr, in fpga_mgr_parse_header_mapped() argument
157 mgr->state = FPGA_MGR_STATE_PARSE_HEADER; in fpga_mgr_parse_header_mapped()
158 ret = fpga_mgr_parse_header(mgr, info, buf, count); in fpga_mgr_parse_header_mapped()
161 dev_err(&mgr->dev, "Bitstream data outruns FPGA image\n"); in fpga_mgr_parse_header_mapped()
166 dev_err(&mgr->dev, "Error while parsing FPGA image header\n"); in fpga_mgr_parse_header_mapped()
167 mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR; in fpga_mgr_parse_header_mapped()
180 static int fpga_mgr_parse_header_sg_first(struct fpga_manager *mgr, in fpga_mgr_parse_header_sg_first() argument
187 mgr->state = FPGA_MGR_STATE_PARSE_HEADER; in fpga_mgr_parse_header_sg_first()
192 ret = fpga_mgr_parse_header(mgr, info, miter.addr, miter.length); in fpga_mgr_parse_header_sg_first()
198 dev_err(&mgr->dev, "Error while parsing FPGA image header\n"); in fpga_mgr_parse_header_sg_first()
199 mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR; in fpga_mgr_parse_header_sg_first()
212 static void *fpga_mgr_parse_header_sg(struct fpga_manager *mgr, in fpga_mgr_parse_header_sg() argument
223 dev_err(&mgr->dev, "Requested invalid header size\n"); in fpga_mgr_parse_header_sg()
246 ret = fpga_mgr_parse_header(mgr, info, buf, header_size); in fpga_mgr_parse_header_sg()
250 dev_err(&mgr->dev, "Error while parsing FPGA image header\n"); in fpga_mgr_parse_header_sg()
251 mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR; in fpga_mgr_parse_header_sg()
268 static int fpga_mgr_write_init_buf(struct fpga_manager *mgr, in fpga_mgr_write_init_buf() argument
275 mgr->state = FPGA_MGR_STATE_WRITE_INIT; in fpga_mgr_write_init_buf()
280 ret = fpga_mgr_write_init(mgr, info, NULL, 0); in fpga_mgr_write_init_buf()
282 ret = fpga_mgr_write_init(mgr, info, buf, count); in fpga_mgr_write_init_buf()
285 dev_err(&mgr->dev, "Error preparing FPGA for writing\n"); in fpga_mgr_write_init_buf()
286 mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR; in fpga_mgr_write_init_buf()
293 static int fpga_mgr_prepare_sg(struct fpga_manager *mgr, in fpga_mgr_prepare_sg() argument
303 if (!mgr->mops->initial_header_size && !mgr->mops->parse_header) in fpga_mgr_prepare_sg()
304 return fpga_mgr_write_init_buf(mgr, info, NULL, 0); in fpga_mgr_prepare_sg()
310 ret = fpga_mgr_parse_header_sg_first(mgr, info, sgt); in fpga_mgr_prepare_sg()
315 ret = fpga_mgr_write_init_buf(mgr, info, miter.addr, in fpga_mgr_prepare_sg()
333 buf = fpga_mgr_parse_header_sg(mgr, info, sgt, &len); in fpga_mgr_prepare_sg()
337 ret = fpga_mgr_write_init_buf(mgr, info, buf, len); in fpga_mgr_prepare_sg()
361 static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, in fpga_mgr_buf_load_sg() argument
367 ret = fpga_mgr_prepare_sg(mgr, info, sgt); in fpga_mgr_buf_load_sg()
372 mgr->state = FPGA_MGR_STATE_WRITE; in fpga_mgr_buf_load_sg()
373 if (mgr->mops->write_sg) { in fpga_mgr_buf_load_sg()
374 ret = fpga_mgr_write_sg(mgr, sgt); in fpga_mgr_buf_load_sg()
381 if (mgr->mops->skip_header && in fpga_mgr_buf_load_sg()
393 ret = fpga_mgr_write(mgr, miter.addr, length); in fpga_mgr_buf_load_sg()
406 dev_err(&mgr->dev, "Error while writing image data to FPGA\n"); in fpga_mgr_buf_load_sg()
407 mgr->state = FPGA_MGR_STATE_WRITE_ERR; in fpga_mgr_buf_load_sg()
411 return fpga_mgr_write_complete(mgr, info); in fpga_mgr_buf_load_sg()
414 static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, in fpga_mgr_buf_load_mapped() argument
420 ret = fpga_mgr_parse_header_mapped(mgr, info, buf, count); in fpga_mgr_buf_load_mapped()
424 ret = fpga_mgr_write_init_buf(mgr, info, buf, count); in fpga_mgr_buf_load_mapped()
428 if (mgr->mops->skip_header) { in fpga_mgr_buf_load_mapped()
439 mgr->state = FPGA_MGR_STATE_WRITE; in fpga_mgr_buf_load_mapped()
440 ret = fpga_mgr_write(mgr, buf, count); in fpga_mgr_buf_load_mapped()
442 dev_err(&mgr->dev, "Error while writing image data to FPGA\n"); in fpga_mgr_buf_load_mapped()
443 mgr->state = FPGA_MGR_STATE_WRITE_ERR; in fpga_mgr_buf_load_mapped()
447 return fpga_mgr_write_complete(mgr, info); in fpga_mgr_buf_load_mapped()
464 static int fpga_mgr_buf_load(struct fpga_manager *mgr, in fpga_mgr_buf_load() argument
480 if (mgr->mops->write) in fpga_mgr_buf_load()
481 return fpga_mgr_buf_load_mapped(mgr, info, buf, count); in fpga_mgr_buf_load()
516 rc = fpga_mgr_buf_load_sg(mgr, info, &sgt); in fpga_mgr_buf_load()
536 static int fpga_mgr_firmware_load(struct fpga_manager *mgr, in fpga_mgr_firmware_load() argument
540 struct device *dev = &mgr->dev; in fpga_mgr_firmware_load()
544 dev_info(dev, "writing %s to %s\n", image_name, mgr->name); in fpga_mgr_firmware_load()
546 mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ; in fpga_mgr_firmware_load()
550 mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR; in fpga_mgr_firmware_load()
555 ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size); in fpga_mgr_firmware_load()
572 int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info) in fpga_mgr_load() argument
574 info->header_size = mgr->mops->initial_header_size; in fpga_mgr_load()
577 return fpga_mgr_buf_load_sg(mgr, info, info->sgt); in fpga_mgr_load()
579 return fpga_mgr_buf_load(mgr, info, info->buf, info->count); in fpga_mgr_load()
581 return fpga_mgr_firmware_load(mgr, info, info->firmware_name); in fpga_mgr_load()
619 struct fpga_manager *mgr = to_fpga_manager(dev); in name_show() local
621 return sprintf(buf, "%s\n", mgr->name); in name_show()
627 struct fpga_manager *mgr = to_fpga_manager(dev); in state_show() local
629 return sprintf(buf, "%s\n", state_str[mgr->state]); in state_show()
635 struct fpga_manager *mgr = to_fpga_manager(dev); in status_show() local
639 status = fpga_mgr_status(mgr); in status_show()
669 struct fpga_manager *mgr; in __fpga_mgr_get() local
671 mgr = to_fpga_manager(dev); in __fpga_mgr_get()
676 return mgr; in __fpga_mgr_get()
728 void fpga_mgr_put(struct fpga_manager *mgr) in fpga_mgr_put() argument
730 module_put(mgr->dev.parent->driver->owner); in fpga_mgr_put()
731 put_device(&mgr->dev); in fpga_mgr_put()
747 int fpga_mgr_lock(struct fpga_manager *mgr) in fpga_mgr_lock() argument
749 if (!mutex_trylock(&mgr->ref_mutex)) { in fpga_mgr_lock()
750 dev_err(&mgr->dev, "FPGA manager is in use.\n"); in fpga_mgr_lock()
762 void fpga_mgr_unlock(struct fpga_manager *mgr) in fpga_mgr_unlock() argument
764 mutex_unlock(&mgr->ref_mutex); in fpga_mgr_unlock()
782 struct fpga_manager *mgr; in fpga_mgr_register_full() local
795 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); in fpga_mgr_register_full()
796 if (!mgr) in fpga_mgr_register_full()
805 mutex_init(&mgr->ref_mutex); in fpga_mgr_register_full()
807 mgr->name = info->name; in fpga_mgr_register_full()
808 mgr->mops = info->mops; in fpga_mgr_register_full()
809 mgr->priv = info->priv; in fpga_mgr_register_full()
810 mgr->compat_id = info->compat_id; in fpga_mgr_register_full()
812 mgr->dev.class = fpga_mgr_class; in fpga_mgr_register_full()
813 mgr->dev.groups = mops->groups; in fpga_mgr_register_full()
814 mgr->dev.parent = parent; in fpga_mgr_register_full()
815 mgr->dev.of_node = parent->of_node; in fpga_mgr_register_full()
816 mgr->dev.id = id; in fpga_mgr_register_full()
818 ret = dev_set_name(&mgr->dev, "fpga%d", id); in fpga_mgr_register_full()
827 mgr->state = fpga_mgr_state(mgr); in fpga_mgr_register_full()
829 ret = device_register(&mgr->dev); in fpga_mgr_register_full()
831 put_device(&mgr->dev); in fpga_mgr_register_full()
835 return mgr; in fpga_mgr_register_full()
840 kfree(mgr); in fpga_mgr_register_full()
881 void fpga_mgr_unregister(struct fpga_manager *mgr) in fpga_mgr_unregister() argument
883 dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name); in fpga_mgr_unregister()
889 fpga_mgr_fpga_remove(mgr); in fpga_mgr_unregister()
891 device_unregister(&mgr->dev); in fpga_mgr_unregister()
899 fpga_mgr_unregister(dr->mgr); in devm_fpga_mgr_unregister()
916 struct fpga_manager *mgr; in devm_fpga_mgr_register_full() local
922 mgr = fpga_mgr_register_full(parent, info); in devm_fpga_mgr_register_full()
923 if (IS_ERR(mgr)) { in devm_fpga_mgr_register_full()
925 return mgr; in devm_fpga_mgr_register_full()
928 dr->mgr = mgr; in devm_fpga_mgr_register_full()
931 return mgr; in devm_fpga_mgr_register_full()
964 struct fpga_manager *mgr = to_fpga_manager(dev); in fpga_mgr_dev_release() local
966 ida_free(&fpga_mgr_ida, mgr->dev.id); in fpga_mgr_dev_release()
967 kfree(mgr); in fpga_mgr_dev_release()