2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
18 #include "scif_main.h"
20 static int scif_fdopen(struct inode *inode, struct file *f)
22 struct scif_endpt *priv = scif_open();
26 f->private_data = priv;
30 static int scif_fdclose(struct inode *inode, struct file *f)
32 struct scif_endpt *priv = f->private_data;
34 return scif_close(priv);
37 static int scif_fdflush(struct file *f, fl_owner_t id)
39 struct scif_endpt *ep = f->private_data;
43 * The listening endpoint stashes the open file information before
44 * waiting for incoming connections. The release callback would never be
45 * called if the application closed the endpoint, while waiting for
46 * incoming connections from a separate thread since the file descriptor
47 * reference count is bumped up in the accept IOCTL. Call the flush
48 * routine if the id matches the endpoint open file information so that
49 * the listening endpoint can be woken up and the fd released.
53 spin_unlock(&ep->lock);
57 static __always_inline void scif_err_debug(int err, const char *str)
60 * ENOTCONN is a common uninteresting error which is
61 * flooding debug messages to the console unnecessarily.
63 if (err < 0 && err != -ENOTCONN)
64 dev_dbg(scif_info.mdev.this_device, "%s err %d\n", str, err);
67 static long scif_fdioctl(struct file *f, unsigned int cmd, unsigned long arg)
69 struct scif_endpt *priv = f->private_data;
70 void __user *argp = (void __user *)arg;
71 bool non_block = false;
73 non_block = !!(f->f_flags & O_NONBLOCK);
80 if (copy_from_user(&pn, argp, sizeof(pn)))
83 pn = scif_bind(priv, pn);
87 if (copy_to_user(argp, &pn, sizeof(pn)))
93 return scif_listen(priv, arg);
98 const struct file_operations scif_fops = {
100 .release = scif_fdclose,
101 .unlocked_ioctl = scif_fdioctl,
102 .flush = scif_fdflush,
103 .owner = THIS_MODULE,