Commit e542aa6b authored by Jan-Bernd Themann's avatar Jan-Bernd Themann Committed by Jeff Garzik

ehea: code cleanup

This patch includes:

- code cleanup related to resource management
- extended error data gathering for resource management
- removing trailing whitespaces
Signed-off-by: default avatarJan-Bernd Themann <themann@de.ibm.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 1eef4e04
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <asm/io.h> #include <asm/io.h>
#define DRV_NAME "ehea" #define DRV_NAME "ehea"
#define DRV_VERSION "EHEA_0053" #define DRV_VERSION "EHEA_0054"
#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
| NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
...@@ -309,6 +309,7 @@ struct ehea_cq { ...@@ -309,6 +309,7 @@ struct ehea_cq {
* Memory Region * Memory Region
*/ */
struct ehea_mr { struct ehea_mr {
struct ehea_adapter *adapter;
u64 handle; u64 handle;
u64 vaddr; u64 vaddr;
u32 lkey; u32 lkey;
......
...@@ -1033,52 +1033,35 @@ out: ...@@ -1033,52 +1033,35 @@ out:
return ret; return ret;
} }
static int ehea_gen_smrs(struct ehea_port_res *pr) int ehea_gen_smrs(struct ehea_port_res *pr)
{ {
u64 hret; int ret;
struct ehea_adapter *adapter = pr->port->adapter; struct ehea_adapter *adapter = pr->port->adapter;
hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle, ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
adapter->mr.vaddr, EHEA_MR_ACC_CTRL, if (ret)
adapter->pd, &pr->send_mr);
if (hret != H_SUCCESS)
goto out; goto out;
hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle, ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
adapter->mr.vaddr, EHEA_MR_ACC_CTRL, if (ret)
adapter->pd, &pr->recv_mr); goto out_free;
if (hret != H_SUCCESS)
goto out_freeres;
return 0; return 0;
out_freeres: out_free:
hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle); ehea_rem_mr(&pr->send_mr);
if (hret != H_SUCCESS)
ehea_error("failed freeing SMR");
out: out:
ehea_error("Generating SMRS failed\n");
return -EIO; return -EIO;
} }
static int ehea_rem_smrs(struct ehea_port_res *pr) int ehea_rem_smrs(struct ehea_port_res *pr)
{ {
struct ehea_adapter *adapter = pr->port->adapter; if ((ehea_rem_mr(&pr->send_mr))
int ret = 0; || (ehea_rem_mr(&pr->recv_mr)))
u64 hret; return -EIO;
else
hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle); return 0;
if (hret != H_SUCCESS) {
ret = -EIO;
ehea_error("failed freeing send SMR for pr=%p", pr);
}
hret = ehea_h_free_resource(adapter->handle, pr->recv_mr.handle);
if (hret != H_SUCCESS) {
ret = -EIO;
ehea_error("failed freeing recv SMR for pr=%p", pr);
}
return ret;
} }
static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries) static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
...@@ -2748,7 +2731,7 @@ static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev, ...@@ -2748,7 +2731,7 @@ static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
dev->ofdev.dev.driver_data = adapter; dev->ofdev.dev.driver_data = adapter;
ret = ehea_reg_mr_adapter(adapter); ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
if (ret) { if (ret) {
dev_err(&dev->ofdev.dev, "reg_mr_adapter failed\n"); dev_err(&dev->ofdev.dev, "reg_mr_adapter failed\n");
goto out_free_ad; goto out_free_ad;
...@@ -2813,7 +2796,7 @@ out_kill_eq: ...@@ -2813,7 +2796,7 @@ out_kill_eq:
ehea_destroy_eq(adapter->neq); ehea_destroy_eq(adapter->neq);
out_free_res: out_free_res:
ehea_h_free_resource(adapter->handle, adapter->mr.handle); ehea_rem_mr(&adapter->mr);
out_free_ad: out_free_ad:
kfree(adapter); kfree(adapter);
...@@ -2824,7 +2807,6 @@ out: ...@@ -2824,7 +2807,6 @@ out:
static int __devexit ehea_remove(struct ibmebus_dev *dev) static int __devexit ehea_remove(struct ibmebus_dev *dev)
{ {
struct ehea_adapter *adapter = dev->ofdev.dev.driver_data; struct ehea_adapter *adapter = dev->ofdev.dev.driver_data;
u64 hret;
int i; int i;
for (i = 0; i < EHEA_MAX_PORTS; i++) for (i = 0; i < EHEA_MAX_PORTS; i++)
...@@ -2841,12 +2823,7 @@ static int __devexit ehea_remove(struct ibmebus_dev *dev) ...@@ -2841,12 +2823,7 @@ static int __devexit ehea_remove(struct ibmebus_dev *dev)
tasklet_kill(&adapter->neq_tasklet); tasklet_kill(&adapter->neq_tasklet);
ehea_destroy_eq(adapter->neq); ehea_destroy_eq(adapter->neq);
ehea_rem_mr(&adapter->mr);
hret = ehea_h_free_resource(adapter->handle, adapter->mr.handle);
if (hret) {
dev_err(&dev->ofdev.dev, "free_resource_mr failed");
return -EIO;
}
kfree(adapter); kfree(adapter);
return 0; return 0;
} }
......
...@@ -478,12 +478,14 @@ u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle) ...@@ -478,12 +478,14 @@ u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle)
0, 0, 0, 0, 0, 0); /* R7-R12 */ 0, 0, 0, 0, 0, 0); /* R7-R12 */
} }
u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle) u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle,
u64 force_bit)
{ {
return ehea_plpar_hcall_norets(H_FREE_RESOURCE, return ehea_plpar_hcall_norets(H_FREE_RESOURCE,
adapter_handle, /* R4 */ adapter_handle, /* R4 */
res_handle, /* R5 */ res_handle, /* R5 */
0, 0, 0, 0, 0); /* R6-R10 */ force_bit,
0, 0, 0, 0); /* R7-R10 */
} }
u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr, u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr,
......
...@@ -414,7 +414,11 @@ u64 ehea_h_register_rpage(const u64 adapter_handle, ...@@ -414,7 +414,11 @@ u64 ehea_h_register_rpage(const u64 adapter_handle,
u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle); u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle);
u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle); #define FORCE_FREE 1
#define NORMAL_FREE 0
u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle,
u64 force_bit);
u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr, u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr,
const u64 length, const u32 access_ctrl, const u64 length, const u32 access_ctrl,
......
...@@ -197,7 +197,7 @@ out_kill_hwq: ...@@ -197,7 +197,7 @@ out_kill_hwq:
hw_queue_dtor(&cq->hw_queue); hw_queue_dtor(&cq->hw_queue);
out_freeres: out_freeres:
ehea_h_free_resource(adapter->handle, cq->fw_handle); ehea_h_free_resource(adapter->handle, cq->fw_handle, FORCE_FREE);
out_freemem: out_freemem:
kfree(cq); kfree(cq);
...@@ -206,25 +206,38 @@ out_nomem: ...@@ -206,25 +206,38 @@ out_nomem:
return NULL; return NULL;
} }
int ehea_destroy_cq(struct ehea_cq *cq) u64 ehea_destroy_cq_res(struct ehea_cq *cq, u64 force)
{ {
u64 adapter_handle, hret; u64 hret;
u64 adapter_handle = cq->adapter->handle;
/* deregister all previous registered pages */
hret = ehea_h_free_resource(adapter_handle, cq->fw_handle, force);
if (hret != H_SUCCESS)
return hret;
hw_queue_dtor(&cq->hw_queue);
kfree(cq);
return hret;
}
int ehea_destroy_cq(struct ehea_cq *cq)
{
u64 hret;
if (!cq) if (!cq)
return 0; return 0;
adapter_handle = cq->adapter->handle; if ((hret = ehea_destroy_cq_res(cq, NORMAL_FREE)) == H_R_STATE) {
ehea_error_data(cq->adapter, cq->fw_handle);
hret = ehea_destroy_cq_res(cq, FORCE_FREE);
}
/* deregister all previous registered pages */
hret = ehea_h_free_resource(adapter_handle, cq->fw_handle);
if (hret != H_SUCCESS) { if (hret != H_SUCCESS) {
ehea_error("destroy CQ failed"); ehea_error("destroy CQ failed");
return -EIO; return -EIO;
} }
hw_queue_dtor(&cq->hw_queue);
kfree(cq);
return 0; return 0;
} }
...@@ -297,7 +310,7 @@ out_kill_hwq: ...@@ -297,7 +310,7 @@ out_kill_hwq:
hw_queue_dtor(&eq->hw_queue); hw_queue_dtor(&eq->hw_queue);
out_freeres: out_freeres:
ehea_h_free_resource(adapter->handle, eq->fw_handle); ehea_h_free_resource(adapter->handle, eq->fw_handle, FORCE_FREE);
out_freemem: out_freemem:
kfree(eq); kfree(eq);
...@@ -316,27 +329,41 @@ struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq) ...@@ -316,27 +329,41 @@ struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq)
return eqe; return eqe;
} }
int ehea_destroy_eq(struct ehea_eq *eq) u64 ehea_destroy_eq_res(struct ehea_eq *eq, u64 force)
{ {
u64 hret; u64 hret;
unsigned long flags; unsigned long flags;
if (!eq)
return 0;
spin_lock_irqsave(&eq->spinlock, flags); spin_lock_irqsave(&eq->spinlock, flags);
hret = ehea_h_free_resource(eq->adapter->handle, eq->fw_handle); hret = ehea_h_free_resource(eq->adapter->handle, eq->fw_handle, force);
spin_unlock_irqrestore(&eq->spinlock, flags); spin_unlock_irqrestore(&eq->spinlock, flags);
if (hret != H_SUCCESS) { if (hret != H_SUCCESS)
ehea_error("destroy_eq failed"); return hret;
return -EIO;
}
hw_queue_dtor(&eq->hw_queue); hw_queue_dtor(&eq->hw_queue);
kfree(eq); kfree(eq);
return hret;
}
int ehea_destroy_eq(struct ehea_eq *eq)
{
u64 hret;
if (!eq)
return 0;
if ((hret = ehea_destroy_eq_res(eq, NORMAL_FREE)) == H_R_STATE) {
ehea_error_data(eq->adapter, eq->fw_handle);
hret = ehea_destroy_eq_res(eq, FORCE_FREE);
}
if (hret != H_SUCCESS) {
ehea_error("destroy EQ failed");
return -EIO;
}
return 0; return 0;
} }
...@@ -471,27 +498,23 @@ out_kill_hwsq: ...@@ -471,27 +498,23 @@ out_kill_hwsq:
out_freeres: out_freeres:
ehea_h_disable_and_get_hea(adapter->handle, qp->fw_handle); ehea_h_disable_and_get_hea(adapter->handle, qp->fw_handle);
ehea_h_free_resource(adapter->handle, qp->fw_handle); ehea_h_free_resource(adapter->handle, qp->fw_handle, FORCE_FREE);
out_freemem: out_freemem:
kfree(qp); kfree(qp);
return NULL; return NULL;
} }
int ehea_destroy_qp(struct ehea_qp *qp) u64 ehea_destroy_qp_res(struct ehea_qp *qp, u64 force)
{ {
u64 hret; u64 hret;
struct ehea_qp_init_attr *qp_attr = &qp->init_attr; struct ehea_qp_init_attr *qp_attr = &qp->init_attr;
if (!qp)
return 0;
ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle); ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle);
hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle); hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle, force);
if (hret != H_SUCCESS) { if (hret != H_SUCCESS)
ehea_error("destroy_qp failed"); return hret;
return -EIO;
}
hw_queue_dtor(&qp->hw_squeue); hw_queue_dtor(&qp->hw_squeue);
hw_queue_dtor(&qp->hw_rqueue1); hw_queue_dtor(&qp->hw_rqueue1);
...@@ -502,10 +525,29 @@ int ehea_destroy_qp(struct ehea_qp *qp) ...@@ -502,10 +525,29 @@ int ehea_destroy_qp(struct ehea_qp *qp)
hw_queue_dtor(&qp->hw_rqueue3); hw_queue_dtor(&qp->hw_rqueue3);
kfree(qp); kfree(qp);
return hret;
}
int ehea_destroy_qp(struct ehea_qp *qp)
{
u64 hret;
if (!qp)
return 0;
if ((hret = ehea_destroy_qp_res(qp, NORMAL_FREE)) == H_R_STATE) {
ehea_error_data(qp->adapter, qp->fw_handle);
hret = ehea_destroy_qp_res(qp, FORCE_FREE);
}
if (hret != H_SUCCESS) {
ehea_error("destroy QP failed");
return -EIO;
}
return 0; return 0;
} }
int ehea_reg_mr_adapter(struct ehea_adapter *adapter) int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr)
{ {
int i, k, ret; int i, k, ret;
u64 hret, pt_abs, start, end, nr_pages; u64 hret, pt_abs, start, end, nr_pages;
...@@ -526,14 +568,14 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter) ...@@ -526,14 +568,14 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter)
hret = ehea_h_alloc_resource_mr(adapter->handle, start, end - start, hret = ehea_h_alloc_resource_mr(adapter->handle, start, end - start,
acc_ctrl, adapter->pd, acc_ctrl, adapter->pd,
&adapter->mr.handle, &adapter->mr.lkey); &mr->handle, &mr->lkey);
if (hret != H_SUCCESS) { if (hret != H_SUCCESS) {
ehea_error("alloc_resource_mr failed"); ehea_error("alloc_resource_mr failed");
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
adapter->mr.vaddr = KERNELBASE; mr->vaddr = KERNELBASE;
k = 0; k = 0;
while (nr_pages > 0) { while (nr_pages > 0) {
...@@ -545,7 +587,7 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter) ...@@ -545,7 +587,7 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter)
EHEA_PAGESIZE))); EHEA_PAGESIZE)));
hret = ehea_h_register_rpage_mr(adapter->handle, hret = ehea_h_register_rpage_mr(adapter->handle,
adapter->mr.handle, 0, mr->handle, 0,
0, (u64)pt_abs, 0, (u64)pt_abs,
num_pages); num_pages);
nr_pages -= num_pages; nr_pages -= num_pages;
...@@ -554,34 +596,68 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter) ...@@ -554,34 +596,68 @@ int ehea_reg_mr_adapter(struct ehea_adapter *adapter)
(k * EHEA_PAGESIZE))); (k * EHEA_PAGESIZE)));
hret = ehea_h_register_rpage_mr(adapter->handle, hret = ehea_h_register_rpage_mr(adapter->handle,
adapter->mr.handle, 0, mr->handle, 0,
0, abs_adr,1); 0, abs_adr,1);
nr_pages--; nr_pages--;
} }
if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) { if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) {
ehea_h_free_resource(adapter->handle, ehea_h_free_resource(adapter->handle,
adapter->mr.handle); mr->handle, FORCE_FREE);
ehea_error("register_rpage_mr failed: hret = %lX", ehea_error("register_rpage_mr failed");
hret);
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
} }
if (hret != H_SUCCESS) { if (hret != H_SUCCESS) {
ehea_h_free_resource(adapter->handle, adapter->mr.handle); ehea_h_free_resource(adapter->handle, mr->handle,
ehea_error("register_rpage failed for last page: hret = %lX", FORCE_FREE);
hret); ehea_error("register_rpage failed for last page");
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
mr->adapter = adapter;
ret = 0; ret = 0;
out: out:
kfree(pt); kfree(pt);
return ret; return ret;
} }
int ehea_rem_mr(struct ehea_mr *mr)
{
u64 hret;
if (!mr || !mr->adapter)
return -EINVAL;
hret = ehea_h_free_resource(mr->adapter->handle, mr->handle,
FORCE_FREE);
if (hret != H_SUCCESS) {
ehea_error("destroy MR failed");
return -EIO;
}
return 0;
}
int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr,
struct ehea_mr *shared_mr)
{
u64 hret;
hret = ehea_h_register_smr(adapter->handle, old_mr->handle,
old_mr->vaddr, EHEA_MR_ACC_CTRL,
adapter->pd, shared_mr);
if (hret != H_SUCCESS)
return -EIO;
shared_mr->adapter = adapter;
return 0;
}
void print_error_data(u64 *data) void print_error_data(u64 *data)
{ {
int length; int length;
...@@ -597,6 +673,14 @@ void print_error_data(u64 *data) ...@@ -597,6 +673,14 @@ void print_error_data(u64 *data)
ehea_error("QP (resource=%lX) state: AER=0x%lX, AERR=0x%lX, " ehea_error("QP (resource=%lX) state: AER=0x%lX, AERR=0x%lX, "
"port=%lX", resource, data[6], data[12], data[22]); "port=%lX", resource, data[6], data[12], data[22]);
if (type == 0x4) /* Completion Queue */
ehea_error("CQ (resource=%lX) state: AER=0x%lX", resource,
data[6]);
if (type == 0x3) /* Event Queue */
ehea_error("EQ (resource=%lX) state: AER=0x%lX", resource,
data[6]);
ehea_dump(data, length, "error data"); ehea_dump(data, length, "error data");
} }
......
...@@ -361,7 +361,12 @@ struct ehea_qp *ehea_create_qp(struct ehea_adapter * adapter, u32 pd, ...@@ -361,7 +361,12 @@ struct ehea_qp *ehea_create_qp(struct ehea_adapter * adapter, u32 pd,
int ehea_destroy_qp(struct ehea_qp *qp); int ehea_destroy_qp(struct ehea_qp *qp);
int ehea_reg_mr_adapter(struct ehea_adapter *adapter); int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr);
int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr,
struct ehea_mr *shared_mr);
int ehea_rem_mr(struct ehea_mr *mr);
void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle); void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment