Merge branch 'e1000-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[pandora-kernel.git] / drivers / infiniband / hw / ehca / ehca_hca.c
index 5eae6ac..32b55a4 100644 (file)
@@ -40,6 +40,7 @@
  */
 
 #include "ehca_tools.h"
+#include "ehca_iverbs.h"
 #include "hcp_if.h"
 
 int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
@@ -49,7 +50,7 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
                                              ib_device);
        struct hipz_query_hca *rblock;
 
-       rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
+       rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
        if (!rblock) {
                ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
                return -ENOMEM;
@@ -96,7 +97,7 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
                = min_t(int, rblock->max_total_mcast_qp_attach, INT_MAX);
 
 query_device1:
-       kfree(rblock);
+       ehca_free_fw_ctrlblock(rblock);
 
        return ret;
 }
@@ -109,7 +110,7 @@ int ehca_query_port(struct ib_device *ibdev,
                                              ib_device);
        struct hipz_query_port *rblock;
 
-       rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
+       rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
        if (!rblock) {
                ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
                return -ENOMEM;
@@ -146,6 +147,7 @@ int ehca_query_port(struct ib_device *ibdev,
                break;
        }
 
+       props->port_cap_flags  = rblock->capability_mask;
        props->gid_tbl_len     = rblock->gid_tbl_len;
        props->max_msg_sz      = rblock->max_msg_sz;
        props->bad_pkey_cntr   = rblock->bad_pkey_cntr;
@@ -161,8 +163,11 @@ int ehca_query_port(struct ib_device *ibdev,
        props->active_width    = IB_WIDTH_12X;
        props->active_speed    = 0x1;
 
+       /* at the moment (logical) link state is always LINK_UP */
+       props->phys_state      = 0x5;
+
 query_port1:
-       kfree(rblock);
+       ehca_free_fw_ctrlblock(rblock);
 
        return ret;
 }
@@ -178,7 +183,7 @@ int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
                return -EINVAL;
        }
 
-       rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
+       rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
        if (!rblock) {
                ehca_err(&shca->ib_device,  "Can't allocate rblock memory.");
                return -ENOMEM;
@@ -193,7 +198,7 @@ int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
        memcpy(pkey, &rblock->pkey_entries + index, sizeof(u16));
 
 query_pkey1:
-       kfree(rblock);
+       ehca_free_fw_ctrlblock(rblock);
 
        return ret;
 }
@@ -211,7 +216,7 @@ int ehca_query_gid(struct ib_device *ibdev, u8 port,
                return -EINVAL;
        }
 
-       rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
+       rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
        if (!rblock) {
                ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
                return -ENOMEM;
@@ -227,15 +232,65 @@ int ehca_query_gid(struct ib_device *ibdev, u8 port,
        memcpy(&gid->raw[8], &rblock->guid_entries[index], sizeof(u64));
 
 query_gid1:
-       kfree(rblock);
+       ehca_free_fw_ctrlblock(rblock);
 
        return ret;
 }
 
+const u32 allowed_port_caps = (
+       IB_PORT_SM | IB_PORT_LED_INFO_SUP | IB_PORT_CM_SUP |
+       IB_PORT_SNMP_TUNNEL_SUP | IB_PORT_DEVICE_MGMT_SUP |
+       IB_PORT_VENDOR_CLASS_SUP);
+
 int ehca_modify_port(struct ib_device *ibdev,
                     u8 port, int port_modify_mask,
                     struct ib_port_modify *props)
 {
-       /* Not implemented yet */
-       return -EFAULT;
+       int ret = 0;
+       struct ehca_shca *shca = container_of(ibdev, struct ehca_shca, ib_device);
+       struct hipz_query_port *rblock;
+       u32 cap;
+       u64 hret;
+
+       if ((props->set_port_cap_mask | props->clr_port_cap_mask)
+           & ~allowed_port_caps) {
+               ehca_err(&shca->ib_device, "Non-changeable bits set in masks  "
+                        "set=%x  clr=%x  allowed=%x", props->set_port_cap_mask,
+                        props->clr_port_cap_mask, allowed_port_caps);
+               return -EINVAL;
+       }
+
+       if (mutex_lock_interruptible(&shca->modify_mutex))
+                return -ERESTARTSYS;
+
+       rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
+       if (!rblock) {
+               ehca_err(&shca->ib_device,  "Can't allocate rblock memory.");
+               ret = -ENOMEM;
+               goto modify_port1;
+       }
+
+       if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
+               ehca_err(&shca->ib_device, "Can't query port properties");
+               ret = -EINVAL;
+               goto modify_port2;
+       }
+
+       cap = (rblock->capability_mask | props->set_port_cap_mask)
+               & ~props->clr_port_cap_mask;
+
+       hret = hipz_h_modify_port(shca->ipz_hca_handle, port,
+                                 cap, props->init_type, port_modify_mask);
+       if (hret != H_SUCCESS) {
+               ehca_err(&shca->ib_device, "Modify port failed  hret=%lx", hret);
+               ret = -EINVAL;
+       }
+
+modify_port2:
+       ehca_free_fw_ctrlblock(rblock);
+
+modify_port1:
+        mutex_unlock(&shca->modify_mutex);
+
+       return ret;
 }