master/ioctl.c
branchstable-1.5
changeset 2447 e93efb4af231
parent 2443 2c3ccdde3919
child 2453 d461b1f07296
equal deleted inserted replaced
2446:3425c621ee46 2447:e93efb4af231
  1560     return 0;
  1560     return 0;
  1561 }
  1561 }
  1562 
  1562 
  1563 /*****************************************************************************/
  1563 /*****************************************************************************/
  1564 
  1564 
       
  1565 /** Select the DC reference clock.
       
  1566  */
       
  1567 static int ec_ioctl_select_ref_clock(
       
  1568         ec_master_t *master, /**< EtherCAT master. */
       
  1569         void *arg, /**< ioctl() argument. */
       
  1570         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
       
  1571         )
       
  1572 {
       
  1573     uint32_t config_index = (uint32_t) arg;
       
  1574     ec_slave_config_t *sc = NULL;
       
  1575     int ret = 0;
       
  1576 
       
  1577     if (unlikely(!ctx->requested)) {
       
  1578         ret = -EPERM;
       
  1579         goto out_return;
       
  1580     }
       
  1581 
       
  1582     if (down_interruptible(&master->master_sem)) {
       
  1583         ret = -EINTR;
       
  1584         goto out_return;
       
  1585     }
       
  1586 
       
  1587     if (config_index != 0xFFFFFFFF) {
       
  1588         if (!(sc = ec_master_get_config(master, config_index))) {
       
  1589             ret = -ENOENT;
       
  1590             goto out_up;
       
  1591         }
       
  1592     }
       
  1593 
       
  1594     ecrt_master_select_reference_clock(master, sc);
       
  1595 
       
  1596 out_up:
       
  1597     up(&master->master_sem);
       
  1598 out_return:
       
  1599     return ret;
       
  1600 }
       
  1601 
       
  1602 /*****************************************************************************/
       
  1603 
  1565 /** Activates the master.
  1604 /** Activates the master.
  1566  */
  1605  */
  1567 static int ec_ioctl_activate(
  1606 static int ec_ioctl_activate(
  1568         ec_master_t *master, /**< EtherCAT master. */
  1607         ec_master_t *master, /**< EtherCAT master. */
  1569         void *arg, /**< ioctl() argument. */
  1608         void *arg, /**< ioctl() argument. */
  1835         return -EPERM;
  1874         return -EPERM;
  1836 
  1875 
  1837     down(&master->io_sem);
  1876     down(&master->io_sem);
  1838     ecrt_master_sync_slave_clocks(master);
  1877     ecrt_master_sync_slave_clocks(master);
  1839     up(&master->io_sem);
  1878     up(&master->io_sem);
       
  1879     return 0;
       
  1880 }
       
  1881 
       
  1882 /*****************************************************************************/
       
  1883 
       
  1884 /** Get the system time of the reference clock.
       
  1885  */
       
  1886 static int ec_ioctl_ref_clock_time(
       
  1887         ec_master_t *master, /**< EtherCAT master. */
       
  1888         void *arg, /**< ioctl() argument. */
       
  1889         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
       
  1890         )
       
  1891 {
       
  1892     uint32_t time;
       
  1893     int ret;
       
  1894 
       
  1895     if (unlikely(!ctx->requested)) {
       
  1896         return -EPERM;
       
  1897     }
       
  1898 
       
  1899     ret = ecrt_master_reference_clock_time(master, &time);
       
  1900     if (ret) {
       
  1901         return ret;
       
  1902     }
       
  1903 
       
  1904     if (copy_to_user((void __user *) arg, &time, sizeof(time))) {
       
  1905         return -EFAULT;
       
  1906     }
       
  1907 
  1840     return 0;
  1908     return 0;
  1841 }
  1909 }
  1842 
  1910 
  1843 /*****************************************************************************/
  1911 /*****************************************************************************/
  1844 
  1912 
  3921                 ret = -EPERM;
  3989                 ret = -EPERM;
  3922                 break;
  3990                 break;
  3923             }
  3991             }
  3924             ret = ec_ioctl_create_slave_config(master, arg, ctx);
  3992             ret = ec_ioctl_create_slave_config(master, arg, ctx);
  3925             break;
  3993             break;
       
  3994         case EC_IOCTL_SELECT_REF_CLOCK:
       
  3995             if (!ctx->writable) {
       
  3996                 ret = -EPERM;
       
  3997                 break;
       
  3998             }
       
  3999             ret = ec_ioctl_select_ref_clock(master, arg, ctx);
       
  4000             break;
  3926         case EC_IOCTL_ACTIVATE:
  4001         case EC_IOCTL_ACTIVATE:
  3927             if (!ctx->writable) {
  4002             if (!ctx->writable) {
  3928                 ret = -EPERM;
  4003                 ret = -EPERM;
  3929                 break;
  4004                 break;
  3930             }
  4005             }
  3975             if (!ctx->writable) {
  4050             if (!ctx->writable) {
  3976                 ret = -EPERM;
  4051                 ret = -EPERM;
  3977                 break;
  4052                 break;
  3978             }
  4053             }
  3979             ret = ec_ioctl_sync_slaves(master, arg, ctx);
  4054             ret = ec_ioctl_sync_slaves(master, arg, ctx);
       
  4055             break;
       
  4056         case EC_IOCTL_REF_CLOCK_TIME:
       
  4057             if (!ctx->writable) {
       
  4058                 ret = -EPERM;
       
  4059                 break;
       
  4060             }
       
  4061             ret = ec_ioctl_ref_clock_time(master, arg, ctx);
  3980             break;
  4062             break;
  3981         case EC_IOCTL_SYNC_MON_QUEUE:
  4063         case EC_IOCTL_SYNC_MON_QUEUE:
  3982             if (!ctx->writable) {
  4064             if (!ctx->writable) {
  3983                 ret = -EPERM;
  4065                 ret = -EPERM;
  3984                 break;
  4066                 break;