]> Git Repo - J-linux.git/blobdiff - drivers/fpga/fpga-mgr.c
Merge tag 'mlx5-fixes-2021-09-07' of git://git.kernel.org/pub/scm/linux/kernel/git...
[J-linux.git] / drivers / fpga / fpga-mgr.c
index 43518b6eed21e64b9cf53e152db5eb3b3cbd46e7..aa30889e23208316cc55e6991c9c52f4bdd08d51 100644 (file)
@@ -25,6 +25,19 @@ struct fpga_mgr_devres {
        struct fpga_manager *mgr;
 };
 
+static inline void fpga_mgr_fpga_remove(struct fpga_manager *mgr)
+{
+       if (mgr->mops->fpga_remove)
+               mgr->mops->fpga_remove(mgr);
+}
+
+static inline enum fpga_mgr_states fpga_mgr_state(struct fpga_manager *mgr)
+{
+       if (mgr->mops->state)
+               return  mgr->mops->state(mgr);
+       return FPGA_MGR_STATE_UNKNOWN;
+}
+
 static inline u64 fpga_mgr_status(struct fpga_manager *mgr)
 {
        if (mgr->mops->status)
@@ -70,6 +83,14 @@ static inline int fpga_mgr_write_init(struct fpga_manager *mgr,
        return 0;
 }
 
+static inline int fpga_mgr_write_sg(struct fpga_manager *mgr,
+                                   struct sg_table *sgt)
+{
+       if (mgr->mops->write_sg)
+               return  mgr->mops->write_sg(mgr, sgt);
+       return -EOPNOTSUPP;
+}
+
 /**
  * fpga_image_info_alloc - Allocate an FPGA image info struct
  * @dev: owning device
@@ -212,7 +233,7 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr,
        /* Write the FPGA image to the FPGA. */
        mgr->state = FPGA_MGR_STATE_WRITE;
        if (mgr->mops->write_sg) {
-               ret = mgr->mops->write_sg(mgr, sgt);
+               ret = fpga_mgr_write_sg(mgr, sgt);
        } else {
                struct sg_mapping_iter miter;
 
@@ -589,7 +610,7 @@ struct fpga_manager *fpga_mgr_create(struct device *parent, const char *name,
        struct fpga_manager *mgr;
        int id, ret;
 
-       if (!mops || !mops->state) {
+       if (!mops) {
                dev_err(parent, "Attempt to register without fpga_manager_ops\n");
                return NULL;
        }
@@ -707,7 +728,7 @@ int fpga_mgr_register(struct fpga_manager *mgr)
         * from device.  FPGA may be in reset mode or may have been programmed
         * by bootloader or EEPROM.
         */
-       mgr->state = mgr->mops->state(mgr);
+       mgr->state = fpga_mgr_state(mgr);
 
        ret = device_add(&mgr->dev);
        if (ret)
@@ -738,8 +759,7 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)
         * If the low level driver provides a method for putting fpga into
         * a desired state upon unregister, do it.
         */
-       if (mgr->mops->fpga_remove)
-               mgr->mops->fpga_remove(mgr);
+       fpga_mgr_fpga_remove(mgr);
 
        device_unregister(&mgr->dev);
 }
This page took 0.034007 seconds and 4 git commands to generate.