[PATCH] IB/ipath: allow diags on any unit
There is no longer a /dev/ipath_diag file; instead, there's /dev/ipath_diag0, 1, etc. It's still not possible to have diags run on more than one unit at a time, but that's easy to fix at some point. Signed-off-by: Bryan O'Sullivan <bryan.osullivan@qlogic.com> Cc: "Michael S. Tsirkin" <mst@mellanox.co.il> Cc: Roland Dreier <rolandd@cisco.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
committed by
Linus Torvalds
parent
6700efdfc0
commit
a2acb2ff36
@@ -67,18 +67,20 @@ static struct file_operations diag_file_ops = {
|
|||||||
.release = ipath_diag_release
|
.release = ipath_diag_release
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct cdev *diag_cdev;
|
int ipath_diag_add(struct ipath_devdata *dd)
|
||||||
static struct class_device *diag_class_dev;
|
|
||||||
|
|
||||||
int ipath_diag_init(void)
|
|
||||||
{
|
{
|
||||||
return ipath_cdev_init(IPATH_DIAG_MINOR, "ipath_diag",
|
char name[16];
|
||||||
&diag_file_ops, &diag_cdev, &diag_class_dev);
|
|
||||||
|
snprintf(name, sizeof(name), "ipath_diag%d", dd->ipath_unit);
|
||||||
|
|
||||||
|
return ipath_cdev_init(IPATH_DIAG_MINOR_BASE + dd->ipath_unit, name,
|
||||||
|
&diag_file_ops, &dd->diag_cdev,
|
||||||
|
&dd->diag_class_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipath_diag_cleanup(void)
|
void ipath_diag_remove(struct ipath_devdata *dd)
|
||||||
{
|
{
|
||||||
ipath_cdev_cleanup(&diag_cdev, &diag_class_dev);
|
ipath_cdev_cleanup(&dd->diag_cdev, &dd->diag_class_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,8 +104,7 @@ static int ipath_read_umem64(struct ipath_devdata *dd, void __user *uaddr,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* not very efficient, but it works for now */
|
/* not very efficient, but it works for now */
|
||||||
if (reg_addr < dd->ipath_kregbase ||
|
if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
|
||||||
reg_end > dd->ipath_kregend) {
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@@ -140,8 +141,7 @@ static int ipath_write_umem64(struct ipath_devdata *dd, void __iomem *caddr,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* not very efficient, but it works for now */
|
/* not very efficient, but it works for now */
|
||||||
if (reg_addr < dd->ipath_kregbase ||
|
if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
|
||||||
reg_end > dd->ipath_kregend) {
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@@ -240,59 +240,45 @@ bail:
|
|||||||
|
|
||||||
static int ipath_diag_open(struct inode *in, struct file *fp)
|
static int ipath_diag_open(struct inode *in, struct file *fp)
|
||||||
{
|
{
|
||||||
|
int unit = iminor(in) - IPATH_DIAG_MINOR_BASE;
|
||||||
struct ipath_devdata *dd;
|
struct ipath_devdata *dd;
|
||||||
int unit = 0; /* XXX this is bogus */
|
|
||||||
unsigned long flags;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dd = ipath_lookup(unit);
|
|
||||||
|
|
||||||
mutex_lock(&ipath_mutex);
|
mutex_lock(&ipath_mutex);
|
||||||
spin_lock_irqsave(&ipath_devs_lock, flags);
|
|
||||||
|
|
||||||
if (ipath_diag_inuse) {
|
if (ipath_diag_inuse) {
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
|
dd = ipath_lookup(unit);
|
||||||
/*
|
|
||||||
* we need at least one infinipath device to be present
|
|
||||||
* (don't use INITTED, because we want to be able to open
|
|
||||||
* even if device is in freeze mode, which cleared INITTED).
|
|
||||||
* There is a small amount of risk to this, which is why we
|
|
||||||
* also verify kregbase is set.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!(dd->ipath_flags & IPATH_PRESENT) ||
|
if (dd == NULL || !(dd->ipath_flags & IPATH_PRESENT) ||
|
||||||
!dd->ipath_kregbase)
|
!dd->ipath_kregbase) {
|
||||||
continue;
|
ret = -ENODEV;
|
||||||
|
|
||||||
ipath_diag_inuse = 1;
|
|
||||||
diag_set_link = 0;
|
|
||||||
ret = 0;
|
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -ENODEV;
|
fp->private_data = dd;
|
||||||
|
ipath_diag_inuse = 1;
|
||||||
bail:
|
diag_set_link = 0;
|
||||||
spin_unlock_irqrestore(&ipath_devs_lock, flags);
|
ret = 0;
|
||||||
|
|
||||||
/* Only expose a way to reset the device if we
|
/* Only expose a way to reset the device if we
|
||||||
make it into diag mode. */
|
make it into diag mode. */
|
||||||
if (ret == 0)
|
|
||||||
ipath_expose_reset(&dd->pcidev->dev);
|
ipath_expose_reset(&dd->pcidev->dev);
|
||||||
|
|
||||||
|
bail:
|
||||||
mutex_unlock(&ipath_mutex);
|
mutex_unlock(&ipath_mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ipath_diag_release(struct inode *i, struct file *f)
|
static int ipath_diag_release(struct inode *in, struct file *fp)
|
||||||
{
|
{
|
||||||
mutex_lock(&ipath_mutex);
|
mutex_lock(&ipath_mutex);
|
||||||
ipath_diag_inuse = 0;
|
ipath_diag_inuse = 0;
|
||||||
|
fp->private_data = NULL;
|
||||||
mutex_unlock(&ipath_mutex);
|
mutex_unlock(&ipath_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -300,17 +286,10 @@ static int ipath_diag_release(struct inode *i, struct file *f)
|
|||||||
static ssize_t ipath_diag_read(struct file *fp, char __user *data,
|
static ssize_t ipath_diag_read(struct file *fp, char __user *data,
|
||||||
size_t count, loff_t *off)
|
size_t count, loff_t *off)
|
||||||
{
|
{
|
||||||
int unit = 0; /* XXX provide for reads on other units some day */
|
struct ipath_devdata *dd = fp->private_data;
|
||||||
struct ipath_devdata *dd;
|
|
||||||
void __iomem *kreg_base;
|
void __iomem *kreg_base;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
dd = ipath_lookup(unit);
|
|
||||||
if (!dd) {
|
|
||||||
ret = -ENODEV;
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
|
|
||||||
kreg_base = dd->ipath_kregbase;
|
kreg_base = dd->ipath_kregbase;
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
@@ -329,23 +308,16 @@ static ssize_t ipath_diag_read(struct file *fp, char __user *data,
|
|||||||
ret = count;
|
ret = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
|
static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
|
||||||
size_t count, loff_t *off)
|
size_t count, loff_t *off)
|
||||||
{
|
{
|
||||||
int unit = 0; /* XXX this is bogus */
|
struct ipath_devdata *dd = fp->private_data;
|
||||||
struct ipath_devdata *dd;
|
|
||||||
void __iomem *kreg_base;
|
void __iomem *kreg_base;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
dd = ipath_lookup(unit);
|
|
||||||
if (!dd) {
|
|
||||||
ret = -ENODEV;
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
kreg_base = dd->ipath_kregbase;
|
kreg_base = dd->ipath_kregbase;
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
@@ -364,6 +336,5 @@ static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
|
|||||||
ret = count;
|
ret = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -546,6 +546,7 @@ static int __devinit ipath_init_one(struct pci_dev *pdev,
|
|||||||
ipath_device_create_group(&pdev->dev, dd);
|
ipath_device_create_group(&pdev->dev, dd);
|
||||||
ipathfs_add_device(dd);
|
ipathfs_add_device(dd);
|
||||||
ipath_user_add(dd);
|
ipath_user_add(dd);
|
||||||
|
ipath_diag_add(dd);
|
||||||
ipath_layer_add(dd);
|
ipath_layer_add(dd);
|
||||||
|
|
||||||
goto bail;
|
goto bail;
|
||||||
@@ -578,8 +579,9 @@ static void __devexit ipath_remove_one(struct pci_dev *pdev)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
dd = pci_get_drvdata(pdev);
|
dd = pci_get_drvdata(pdev);
|
||||||
ipath_layer_del(dd);
|
ipath_layer_remove(dd);
|
||||||
ipath_user_del(dd);
|
ipath_diag_remove(dd);
|
||||||
|
ipath_user_remove(dd);
|
||||||
ipathfs_remove_device(dd);
|
ipathfs_remove_device(dd);
|
||||||
ipath_device_remove_group(&pdev->dev, dd);
|
ipath_device_remove_group(&pdev->dev, dd);
|
||||||
ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
|
ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
|
||||||
|
@@ -1443,16 +1443,16 @@ done:
|
|||||||
|
|
||||||
static int ipath_open(struct inode *in, struct file *fp)
|
static int ipath_open(struct inode *in, struct file *fp)
|
||||||
{
|
{
|
||||||
int ret, minor;
|
int ret, user_minor;
|
||||||
|
|
||||||
mutex_lock(&ipath_mutex);
|
mutex_lock(&ipath_mutex);
|
||||||
|
|
||||||
minor = iminor(in);
|
user_minor = iminor(in) - IPATH_USER_MINOR_BASE;
|
||||||
ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
|
ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
|
||||||
(long)in->i_rdev, minor);
|
(long)in->i_rdev, user_minor);
|
||||||
|
|
||||||
if (minor)
|
if (user_minor)
|
||||||
ret = find_free_port(minor - 1, fp);
|
ret = find_free_port(user_minor - 1, fp);
|
||||||
else
|
else
|
||||||
ret = find_best_unit(fp);
|
ret = find_best_unit(fp);
|
||||||
|
|
||||||
@@ -1860,19 +1860,12 @@ int ipath_user_add(struct ipath_devdata *dd)
|
|||||||
"error %d\n", -ret);
|
"error %d\n", -ret);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
ret = ipath_diag_init();
|
|
||||||
if (ret < 0) {
|
|
||||||
ipath_dev_err(dd, "Unable to set up diag support: "
|
|
||||||
"error %d\n", -ret);
|
|
||||||
goto bail_sma;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = init_cdev(0, "ipath", &ipath_file_ops, &wildcard_cdev,
|
ret = init_cdev(0, "ipath", &ipath_file_ops, &wildcard_cdev,
|
||||||
&wildcard_class_dev);
|
&wildcard_class_dev);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ipath_dev_err(dd, "Could not create wildcard "
|
ipath_dev_err(dd, "Could not create wildcard "
|
||||||
"minor: error %d\n", -ret);
|
"minor: error %d\n", -ret);
|
||||||
goto bail_diag;
|
goto bail_sma;
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_set(&user_setup, 1);
|
atomic_set(&user_setup, 1);
|
||||||
@@ -1881,31 +1874,28 @@ int ipath_user_add(struct ipath_devdata *dd)
|
|||||||
snprintf(name, sizeof(name), "ipath%d", dd->ipath_unit);
|
snprintf(name, sizeof(name), "ipath%d", dd->ipath_unit);
|
||||||
|
|
||||||
ret = init_cdev(dd->ipath_unit + 1, name, &ipath_file_ops,
|
ret = init_cdev(dd->ipath_unit + 1, name, &ipath_file_ops,
|
||||||
&dd->cdev, &dd->class_dev);
|
&dd->user_cdev, &dd->user_class_dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
ipath_dev_err(dd, "Could not create user minor %d, %s\n",
|
ipath_dev_err(dd, "Could not create user minor %d, %s\n",
|
||||||
dd->ipath_unit + 1, name);
|
dd->ipath_unit + 1, name);
|
||||||
|
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
bail_diag:
|
|
||||||
ipath_diag_cleanup();
|
|
||||||
bail_sma:
|
bail_sma:
|
||||||
user_cleanup();
|
user_cleanup();
|
||||||
bail:
|
bail:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipath_user_del(struct ipath_devdata *dd)
|
void ipath_user_remove(struct ipath_devdata *dd)
|
||||||
{
|
{
|
||||||
cleanup_cdev(&dd->cdev, &dd->class_dev);
|
cleanup_cdev(&dd->user_cdev, &dd->user_class_dev);
|
||||||
|
|
||||||
if (atomic_dec_return(&user_count) == 0) {
|
if (atomic_dec_return(&user_count) == 0) {
|
||||||
if (atomic_read(&user_setup) == 0)
|
if (atomic_read(&user_setup) == 0)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
cleanup_cdev(&wildcard_cdev, &wildcard_class_dev);
|
cleanup_cdev(&wildcard_cdev, &wildcard_class_dev);
|
||||||
ipath_diag_cleanup();
|
|
||||||
user_cleanup();
|
user_cleanup();
|
||||||
|
|
||||||
atomic_set(&user_setup, 0);
|
atomic_set(&user_setup, 0);
|
||||||
|
@@ -355,8 +355,10 @@ struct ipath_devdata {
|
|||||||
char *ipath_freezemsg;
|
char *ipath_freezemsg;
|
||||||
/* pci access data structure */
|
/* pci access data structure */
|
||||||
struct pci_dev *pcidev;
|
struct pci_dev *pcidev;
|
||||||
struct cdev *cdev;
|
struct cdev *user_cdev;
|
||||||
struct class_device *class_dev;
|
struct cdev *diag_cdev;
|
||||||
|
struct class_device *user_class_dev;
|
||||||
|
struct class_device *diag_class_dev;
|
||||||
/* timer used to prevent stats overflow, error throttling, etc. */
|
/* timer used to prevent stats overflow, error throttling, etc. */
|
||||||
struct timer_list ipath_stats_timer;
|
struct timer_list ipath_stats_timer;
|
||||||
/* check for stale messages in rcv queue */
|
/* check for stale messages in rcv queue */
|
||||||
@@ -538,7 +540,7 @@ extern int __ipath_verbs_piobufavail(struct ipath_devdata *);
|
|||||||
extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
|
extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
|
||||||
|
|
||||||
void ipath_layer_add(struct ipath_devdata *);
|
void ipath_layer_add(struct ipath_devdata *);
|
||||||
void ipath_layer_del(struct ipath_devdata *);
|
void ipath_layer_remove(struct ipath_devdata *);
|
||||||
|
|
||||||
int ipath_init_chip(struct ipath_devdata *, int);
|
int ipath_init_chip(struct ipath_devdata *, int);
|
||||||
int ipath_enable_wc(struct ipath_devdata *dd);
|
int ipath_enable_wc(struct ipath_devdata *dd);
|
||||||
@@ -552,14 +554,14 @@ int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
|
|||||||
void ipath_cdev_cleanup(struct cdev **cdevp,
|
void ipath_cdev_cleanup(struct cdev **cdevp,
|
||||||
struct class_device **class_devp);
|
struct class_device **class_devp);
|
||||||
|
|
||||||
int ipath_diag_init(void);
|
int ipath_diag_add(struct ipath_devdata *);
|
||||||
void ipath_diag_cleanup(void);
|
void ipath_diag_remove(struct ipath_devdata *);
|
||||||
void ipath_diag_bringup_link(struct ipath_devdata *);
|
void ipath_diag_bringup_link(struct ipath_devdata *);
|
||||||
|
|
||||||
extern wait_queue_head_t ipath_sma_state_wait;
|
extern wait_queue_head_t ipath_sma_state_wait;
|
||||||
|
|
||||||
int ipath_user_add(struct ipath_devdata *dd);
|
int ipath_user_add(struct ipath_devdata *dd);
|
||||||
void ipath_user_del(struct ipath_devdata *dd);
|
void ipath_user_remove(struct ipath_devdata *dd);
|
||||||
|
|
||||||
struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
|
struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
|
||||||
|
|
||||||
@@ -843,9 +845,10 @@ extern struct mutex ipath_mutex;
|
|||||||
|
|
||||||
#define IPATH_DRV_NAME "ipath_core"
|
#define IPATH_DRV_NAME "ipath_core"
|
||||||
#define IPATH_MAJOR 233
|
#define IPATH_MAJOR 233
|
||||||
|
#define IPATH_USER_MINOR_BASE 0
|
||||||
#define IPATH_SMA_MINOR 128
|
#define IPATH_SMA_MINOR 128
|
||||||
#define IPATH_DIAG_MINOR 129
|
#define IPATH_DIAG_MINOR_BASE 129
|
||||||
#define IPATH_NMINORS 130
|
#define IPATH_NMINORS 255
|
||||||
|
|
||||||
#define ipath_dev_err(dd,fmt,...) \
|
#define ipath_dev_err(dd,fmt,...) \
|
||||||
do { \
|
do { \
|
||||||
|
@@ -404,7 +404,7 @@ void ipath_layer_add(struct ipath_devdata *dd)
|
|||||||
mutex_unlock(&ipath_layer_mutex);
|
mutex_unlock(&ipath_layer_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipath_layer_del(struct ipath_devdata *dd)
|
void ipath_layer_remove(struct ipath_devdata *dd)
|
||||||
{
|
{
|
||||||
mutex_lock(&ipath_layer_mutex);
|
mutex_lock(&ipath_layer_mutex);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user