include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / infiniband / hw / amso1100 / c2_provider.c
index 21fb46d..c47f618 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/if_arp.h>
 #include <linux/vmalloc.h>
+#include <linux/slab.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -245,6 +246,9 @@ static struct ib_qp *c2_create_qp(struct ib_pd *pd,
 
        pr_debug("%s:%u\n", __func__, __LINE__);
 
+       if (init_attr->create_flags)
+               return ERR_PTR(-EINVAL);
+
        switch (init_attr->qp_type) {
        case IB_QPT_RC:
                qp = kzalloc(sizeof(*qp), GFP_KERNEL);
@@ -269,7 +273,6 @@ static struct ib_qp *c2_create_qp(struct ib_pd *pd,
                pr_debug("%s: Invalid QP type: %d\n", __func__,
                        init_attr->qp_type);
                return ERR_PTR(-EINVAL);
-               break;
        }
 
        if (err) {
@@ -449,7 +452,7 @@ static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
                return ERR_PTR(-ENOMEM);
        c2mr->pd = c2pd;
 
-       c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc);
+       c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0);
        if (IS_ERR(c2mr->umem)) {
                err = PTR_ERR(c2mr->umem);
                kfree(c2mr);
@@ -520,45 +523,49 @@ static int c2_dereg_mr(struct ib_mr *ib_mr)
        return err;
 }
 
-static ssize_t show_rev(struct class_device *cdev, char *buf)
+static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
+                       char *buf)
 {
-       struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev);
+       struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);
        pr_debug("%s:%u\n", __func__, __LINE__);
-       return sprintf(buf, "%x\n", dev->props.hw_ver);
+       return sprintf(buf, "%x\n", c2dev->props.hw_ver);
 }
 
-static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
+static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
-       struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev);
+       struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);
        pr_debug("%s:%u\n", __func__, __LINE__);
        return sprintf(buf, "%x.%x.%x\n",
-                      (int) (dev->props.fw_ver >> 32),
-                      (int) (dev->props.fw_ver >> 16) & 0xffff,
-                      (int) (dev->props.fw_ver & 0xffff));
+                      (int) (c2dev->props.fw_ver >> 32),
+                      (int) (c2dev->props.fw_ver >> 16) & 0xffff,
+                      (int) (c2dev->props.fw_ver & 0xffff));
 }
 
-static ssize_t show_hca(struct class_device *cdev, char *buf)
+static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
+                       char *buf)
 {
        pr_debug("%s:%u\n", __func__, __LINE__);
        return sprintf(buf, "AMSO1100\n");
 }
 
-static ssize_t show_board(struct class_device *cdev, char *buf)
+static ssize_t show_board(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
        pr_debug("%s:%u\n", __func__, __LINE__);
        return sprintf(buf, "%.*s\n", 32, "AMSO1100 Board ID");
 }
 
-static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
-static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
-static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
-static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
+static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
+static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
+static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
+static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
 
-static struct class_device_attribute *c2_class_attributes[] = {
-       &class_device_attr_hw_rev,
-       &class_device_attr_fw_ver,
-       &class_device_attr_hca_type,
-       &class_device_attr_board_id
+static struct device_attribute *c2_dev_attributes[] = {
+       &dev_attr_hw_rev,
+       &dev_attr_fw_ver,
+       &dev_attr_hca_type,
+       &dev_attr_board_id
 };
 
 static int c2_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
@@ -647,7 +654,7 @@ static int c2_service_destroy(struct iw_cm_id *cm_id)
 static int c2_pseudo_up(struct net_device *netdev)
 {
        struct in_device *ind;
-       struct c2_dev *c2dev = netdev->priv;
+       struct c2_dev *c2dev = netdev->ml_priv;
 
        ind = in_dev_get(netdev);
        if (!ind)
@@ -672,7 +679,7 @@ static int c2_pseudo_up(struct net_device *netdev)
 static int c2_pseudo_down(struct net_device *netdev)
 {
        struct in_device *ind;
-       struct c2_dev *c2dev = netdev->priv;
+       struct c2_dev *c2dev = netdev->ml_priv;
 
        ind = in_dev_get(netdev);
        if (!ind)
@@ -702,26 +709,27 @@ static int c2_pseudo_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
 static int c2_pseudo_change_mtu(struct net_device *netdev, int new_mtu)
 {
-       int ret = 0;
-
        if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
                return -EINVAL;
 
        netdev->mtu = new_mtu;
 
        /* TODO: Tell rnic about new rmda interface mtu */
-       return ret;
+       return 0;
 }
 
+static const struct net_device_ops c2_pseudo_netdev_ops = {
+       .ndo_open               = c2_pseudo_up,
+       .ndo_stop               = c2_pseudo_down,
+       .ndo_start_xmit         = c2_pseudo_xmit_frame,
+       .ndo_change_mtu         = c2_pseudo_change_mtu,
+       .ndo_validate_addr      = eth_validate_addr,
+};
+
 static void setup(struct net_device *netdev)
 {
-       netdev->open = c2_pseudo_up;
-       netdev->stop = c2_pseudo_down;
-       netdev->hard_start_xmit = c2_pseudo_xmit_frame;
-       netdev->get_stats = NULL;
-       netdev->tx_timeout = NULL;
-       netdev->set_mac_address = NULL;
-       netdev->change_mtu = c2_pseudo_change_mtu;
+       netdev->netdev_ops = &c2_pseudo_netdev_ops;
+
        netdev->watchdog_timeo = 0;
        netdev->type = ARPHRD_ETHER;
        netdev->mtu = 1500;
@@ -729,7 +737,6 @@ static void setup(struct net_device *netdev)
        netdev->addr_len = ETH_ALEN;
        netdev->tx_queue_len = 0;
        netdev->flags |= IFF_NOARP;
-       return;
 }
 
 static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)
@@ -740,14 +747,14 @@ static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)
        /* change ethxxx to iwxxx */
        strcpy(name, "iw");
        strcat(name, &c2dev->netdev->name[3]);
-       netdev = alloc_netdev(sizeof(*netdev), name, setup);
+       netdev = alloc_netdev(0, name, setup);
        if (!netdev) {
                printk(KERN_ERR PFX "%s -  etherdev alloc failed",
                        __func__);
                return NULL;
        }
 
-       netdev->priv = c2dev;
+       netdev->ml_priv = c2dev;
 
        SET_NETDEV_DEV(netdev, &c2dev->pcidev->dev);
 
@@ -774,11 +781,11 @@ int c2_register_device(struct c2_dev *dev)
        /* Register pseudo network device */
        dev->pseudo_netdev = c2_pseudo_netdev_init(dev);
        if (!dev->pseudo_netdev)
-               goto out3;
+               goto out;
 
        ret = register_netdev(dev->pseudo_netdev);
        if (ret)
-               goto out2;
+               goto out_free_netdev;
 
        pr_debug("%s:%u\n", __func__, __LINE__);
        strlcpy(dev->ibdev.name, "amso%d", IB_DEVICE_NAME_MAX);
@@ -845,6 +852,10 @@ int c2_register_device(struct c2_dev *dev)
        dev->ibdev.post_recv = c2_post_receive;
 
        dev->ibdev.iwcm = kmalloc(sizeof(*dev->ibdev.iwcm), GFP_KERNEL);
+       if (dev->ibdev.iwcm == NULL) {
+               ret = -ENOMEM;
+               goto out_unregister_netdev;
+       }
        dev->ibdev.iwcm->add_ref = c2_add_ref;
        dev->ibdev.iwcm->rem_ref = c2_rem_ref;
        dev->ibdev.iwcm->get_qp = c2_get_qp;
@@ -856,23 +867,25 @@ int c2_register_device(struct c2_dev *dev)
 
        ret = ib_register_device(&dev->ibdev);
        if (ret)
-               goto out1;
+               goto out_free_iwcm;
 
-       for (i = 0; i < ARRAY_SIZE(c2_class_attributes); ++i) {
-               ret = class_device_create_file(&dev->ibdev.class_dev,
-                                              c2_class_attributes[i]);
+       for (i = 0; i < ARRAY_SIZE(c2_dev_attributes); ++i) {
+               ret = device_create_file(&dev->ibdev.dev,
+                                              c2_dev_attributes[i]);
                if (ret)
-                       goto out0;
+                       goto out_unregister_ibdev;
        }
-       goto out3;
+       goto out;
 
-out0:
+out_unregister_ibdev:
        ib_unregister_device(&dev->ibdev);
-out1:
+out_free_iwcm:
+       kfree(dev->ibdev.iwcm);
+out_unregister_netdev:
        unregister_netdev(dev->pseudo_netdev);
-out2:
+out_free_netdev:
        free_netdev(dev->pseudo_netdev);
-out3:
+out:
        pr_debug("%s:%u ret=%d\n", __func__, __LINE__, ret);
        return ret;
 }