Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 31543
b: refs/heads/master
c: a2acb2f
h: refs/heads/master
i:
  31541: a2401c1
  31539: 46e7739
  31535: 55e1aff
v: v3
  • Loading branch information
Bryan O'Sullivan authored and Linus Torvalds committed Jul 1, 2006
1 parent 446c1b5 commit a535d0f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 88 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6700efdfc06d2dc9ef77988a00182c2ede0f1be0
refs/heads/master: a2acb2ff36876fdfa5f7a8bf811765aadc74c1c1
85 changes: 28 additions & 57 deletions trunk/drivers/infiniband/hw/ipath/ipath_diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,20 @@ static struct file_operations diag_file_ops = {
.release = ipath_diag_release
};

static struct cdev *diag_cdev;
static struct class_device *diag_class_dev;

int ipath_diag_init(void)
int ipath_diag_add(struct ipath_devdata *dd)
{
return ipath_cdev_init(IPATH_DIAG_MINOR, "ipath_diag",
&diag_file_ops, &diag_cdev, &diag_class_dev);
char name[16];

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);
}

/**
Expand All @@ -102,8 +104,7 @@ static int ipath_read_umem64(struct ipath_devdata *dd, void __user *uaddr,
int ret;

/* not very efficient, but it works for now */
if (reg_addr < dd->ipath_kregbase ||
reg_end > dd->ipath_kregend) {
if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
ret = -EINVAL;
goto bail;
}
Expand Down Expand Up @@ -140,8 +141,7 @@ static int ipath_write_umem64(struct ipath_devdata *dd, void __iomem *caddr,
int ret;

/* not very efficient, but it works for now */
if (reg_addr < dd->ipath_kregbase ||
reg_end > dd->ipath_kregend) {
if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
ret = -EINVAL;
goto bail;
}
Expand Down Expand Up @@ -240,77 +240,56 @@ static int ipath_write_umem32(struct ipath_devdata *dd, void __iomem *caddr,

static int ipath_diag_open(struct inode *in, struct file *fp)
{
int unit = iminor(in) - IPATH_DIAG_MINOR_BASE;
struct ipath_devdata *dd;
int unit = 0; /* XXX this is bogus */
unsigned long flags;
int ret;

dd = ipath_lookup(unit);

mutex_lock(&ipath_mutex);
spin_lock_irqsave(&ipath_devs_lock, flags);

if (ipath_diag_inuse) {
ret = -EBUSY;
goto bail;
}

list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
/*
* 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) ||
!dd->ipath_kregbase)
continue;

ipath_diag_inuse = 1;
diag_set_link = 0;
ret = 0;
dd = ipath_lookup(unit);

if (dd == NULL || !(dd->ipath_flags & IPATH_PRESENT) ||
!dd->ipath_kregbase) {
ret = -ENODEV;
goto bail;
}

ret = -ENODEV;

bail:
spin_unlock_irqrestore(&ipath_devs_lock, flags);
fp->private_data = dd;
ipath_diag_inuse = 1;
diag_set_link = 0;
ret = 0;

/* Only expose a way to reset the device if we
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);

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);
ipath_diag_inuse = 0;
fp->private_data = NULL;
mutex_unlock(&ipath_mutex);
return 0;
}

static ssize_t ipath_diag_read(struct file *fp, char __user *data,
size_t count, loff_t *off)
{
int unit = 0; /* XXX provide for reads on other units some day */
struct ipath_devdata *dd;
struct ipath_devdata *dd = fp->private_data;
void __iomem *kreg_base;
ssize_t ret;

dd = ipath_lookup(unit);
if (!dd) {
ret = -ENODEV;
goto bail;
}

kreg_base = dd->ipath_kregbase;

if (count == 0)
Expand All @@ -329,23 +308,16 @@ static ssize_t ipath_diag_read(struct file *fp, char __user *data,
ret = count;
}

bail:
return ret;
}

static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
size_t count, loff_t *off)
{
int unit = 0; /* XXX this is bogus */
struct ipath_devdata *dd;
struct ipath_devdata *dd = fp->private_data;
void __iomem *kreg_base;
ssize_t ret;

dd = ipath_lookup(unit);
if (!dd) {
ret = -ENODEV;
goto bail;
}
kreg_base = dd->ipath_kregbase;

if (count == 0)
Expand All @@ -364,6 +336,5 @@ static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
ret = count;
}

bail:
return ret;
}
6 changes: 4 additions & 2 deletions trunk/drivers/infiniband/hw/ipath/ipath_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ static int __devinit ipath_init_one(struct pci_dev *pdev,
ipath_device_create_group(&pdev->dev, dd);
ipathfs_add_device(dd);
ipath_user_add(dd);
ipath_diag_add(dd);
ipath_layer_add(dd);

goto bail;
Expand Down Expand Up @@ -578,8 +579,9 @@ static void __devexit ipath_remove_one(struct pci_dev *pdev)
return;

dd = pci_get_drvdata(pdev);
ipath_layer_del(dd);
ipath_user_del(dd);
ipath_layer_remove(dd);
ipath_diag_remove(dd);
ipath_user_remove(dd);
ipathfs_remove_device(dd);
ipath_device_remove_group(&pdev->dev, dd);
ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
Expand Down
28 changes: 9 additions & 19 deletions trunk/drivers/infiniband/hw/ipath/ipath_file_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,16 +1443,16 @@ static int find_best_unit(struct file *fp)

static int ipath_open(struct inode *in, struct file *fp)
{
int ret, minor;
int ret, user_minor;

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",
(long)in->i_rdev, minor);
(long)in->i_rdev, user_minor);

if (minor)
ret = find_free_port(minor - 1, fp);
if (user_minor)
ret = find_free_port(user_minor - 1, fp);
else
ret = find_best_unit(fp);

Expand Down Expand Up @@ -1860,19 +1860,12 @@ int ipath_user_add(struct ipath_devdata *dd)
"error %d\n", -ret);
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,
&wildcard_class_dev);
if (ret < 0) {
ipath_dev_err(dd, "Could not create wildcard "
"minor: error %d\n", -ret);
goto bail_diag;
goto bail_sma;
}

atomic_set(&user_setup, 1);
Expand All @@ -1881,31 +1874,28 @@ int ipath_user_add(struct ipath_devdata *dd)
snprintf(name, sizeof(name), "ipath%d", dd->ipath_unit);

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)
ipath_dev_err(dd, "Could not create user minor %d, %s\n",
dd->ipath_unit + 1, name);

goto bail;

bail_diag:
ipath_diag_cleanup();
bail_sma:
user_cleanup();
bail:
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_read(&user_setup) == 0)
goto bail;

cleanup_cdev(&wildcard_cdev, &wildcard_class_dev);
ipath_diag_cleanup();
user_cleanup();

atomic_set(&user_setup, 0);
Expand Down
19 changes: 11 additions & 8 deletions trunk/drivers/infiniband/hw/ipath/ipath_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ struct ipath_devdata {
char *ipath_freezemsg;
/* pci access data structure */
struct pci_dev *pcidev;
struct cdev *cdev;
struct class_device *class_dev;
struct cdev *user_cdev;
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. */
struct timer_list ipath_stats_timer;
/* check for stale messages in rcv queue */
Expand Down Expand Up @@ -538,7 +540,7 @@ extern int __ipath_verbs_piobufavail(struct ipath_devdata *);
extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);

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_enable_wc(struct ipath_devdata *dd);
Expand All @@ -552,14 +554,14 @@ int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
void ipath_cdev_cleanup(struct cdev **cdevp,
struct class_device **class_devp);

int ipath_diag_init(void);
void ipath_diag_cleanup(void);
int ipath_diag_add(struct ipath_devdata *);
void ipath_diag_remove(struct ipath_devdata *);
void ipath_diag_bringup_link(struct ipath_devdata *);

extern wait_queue_head_t ipath_sma_state_wait;

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);

Expand Down Expand Up @@ -843,9 +845,10 @@ extern struct mutex ipath_mutex;

#define IPATH_DRV_NAME "ipath_core"
#define IPATH_MAJOR 233
#define IPATH_USER_MINOR_BASE 0
#define IPATH_SMA_MINOR 128
#define IPATH_DIAG_MINOR 129
#define IPATH_NMINORS 130
#define IPATH_DIAG_MINOR_BASE 129
#define IPATH_NMINORS 255

#define ipath_dev_err(dd,fmt,...) \
do { \
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/infiniband/hw/ipath/ipath_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void ipath_layer_add(struct ipath_devdata *dd)
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);

Expand Down

0 comments on commit a535d0f

Please sign in to comment.