]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/ehea/ehea_main.c
ehea: simplify conditional
[net-next-2.6.git] / drivers / net / ehea / ehea_main.c
index 897719b49f96859b11a1f01f4f45e46c03c4cd71..6932578816d35b6a4fc407f1a36055ca64ba5ed7 100644 (file)
@@ -180,7 +180,7 @@ static void ehea_update_firmware_handles(void)
                         num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
 
        if (num_fw_handles) {
-               arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
+               arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
                if (!arr)
                        goto out;  /* Keep the existing array */
        } else
@@ -265,7 +265,7 @@ static void ehea_update_bcmc_registrations(void)
                }
 
        if (num_registrations) {
-               arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
+               arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
                if (!arr)
                        goto out;  /* Keep the existing array */
        } else
@@ -776,6 +776,54 @@ static int ehea_proc_rwqes(struct net_device *dev,
        return processed;
 }
 
+#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
+
+static void reset_sq_restart_flag(struct ehea_port *port)
+{
+       int i;
+
+       for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
+               struct ehea_port_res *pr = &port->port_res[i];
+               pr->sq_restart_flag = 0;
+       }
+       wake_up(&port->restart_wq);
+}
+
+static void check_sqs(struct ehea_port *port)
+{
+       struct ehea_swqe *swqe;
+       int swqe_index;
+       int i, k;
+
+       for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
+               struct ehea_port_res *pr = &port->port_res[i];
+               int ret;
+               k = 0;
+               swqe = ehea_get_swqe(pr->qp, &swqe_index);
+               memset(swqe, 0, SWQE_HEADER_SIZE);
+               atomic_dec(&pr->swqe_avail);
+
+               swqe->tx_control |= EHEA_SWQE_PURGE;
+               swqe->wr_id = SWQE_RESTART_CHECK;
+               swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
+               swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
+               swqe->immediate_data_length = 80;
+
+               ehea_post_swqe(pr->qp, swqe);
+
+               ret = wait_event_timeout(port->restart_wq,
+                                        pr->sq_restart_flag == 0,
+                                        msecs_to_jiffies(100));
+
+               if (!ret) {
+                       ehea_error("HW/SW queues out of sync");
+                       ehea_schedule_port_reset(pr->port);
+                       return;
+               }
+       }
+}
+
+
 static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
 {
        struct sk_buff *skb;
@@ -793,6 +841,13 @@ static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
 
                cqe_counter++;
                rmb();
+
+               if (cqe->wr_id == SWQE_RESTART_CHECK) {
+                       pr->sq_restart_flag = 1;
+                       swqe_av++;
+                       break;
+               }
+
                if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
                        ehea_error("Bad send completion status=0x%04X",
                                   cqe->status);
@@ -836,6 +891,7 @@ static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
                pr->queue_stopped = 0;
        }
        spin_unlock_irqrestore(&pr->netif_queue, flags);
+       wake_up(&pr->port->swqe_avail_wq);
 
        return cqe;
 }
@@ -1862,7 +1918,7 @@ static void ehea_promiscuous(struct net_device *dev, int enable)
        struct hcp_ehea_port_cb7 *cb7;
        u64 hret;
 
-       if ((enable && port->promisc) || (!enable && !port->promisc))
+       if (enable == port->promisc)
                return;
 
        cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
@@ -2600,6 +2656,9 @@ static int ehea_open(struct net_device *dev)
                netif_start_queue(dev);
        }
 
+       init_waitqueue_head(&port->swqe_avail_wq);
+       init_waitqueue_head(&port->restart_wq);
+
        mutex_unlock(&port->port_lock);
 
        return ret;
@@ -2672,11 +2731,15 @@ static void ehea_flush_sq(struct ehea_port *port)
        for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
                struct ehea_port_res *pr = &port->port_res[i];
                int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
-               int k = 0;
-               while (atomic_read(&pr->swqe_avail) < swqe_max) {
-                       msleep(5);
-                       if (++k == 20)
-                               break;
+               int ret;
+
+               ret = wait_event_timeout(port->swqe_avail_wq,
+                        atomic_read(&pr->swqe_avail) >= swqe_max,
+                        msecs_to_jiffies(100));
+
+               if (!ret) {
+                       ehea_error("WARNING: sq not flushed completely");
+                       break;
                }
        }
 }
@@ -2917,6 +2980,7 @@ static void ehea_rereg_mrs(struct work_struct *work)
                                        port_napi_disable(port);
                                        mutex_unlock(&port->port_lock);
                                }
+                               reset_sq_restart_flag(port);
                        }
 
                        /* Unregister old memory region */
@@ -2951,6 +3015,7 @@ static void ehea_rereg_mrs(struct work_struct *work)
                                                mutex_lock(&port->port_lock);
                                                port_napi_enable(port);
                                                ret = ehea_restart_qps(dev);
+                                               check_sqs(port);
                                                if (!ret)
                                                        netif_wake_queue(dev);
                                                mutex_unlock(&port->port_lock);
@@ -3663,7 +3728,7 @@ int __init ehea_module_init(void)
        if (ret)
                ehea_info("failed registering memory remove notifier");
 
-       ret = crash_shutdown_register(&ehea_crash_handler);
+       ret = crash_shutdown_register(ehea_crash_handler);
        if (ret)
                ehea_info("failed registering crash handler");
 
@@ -3688,7 +3753,7 @@ out3:
 out2:
        unregister_memory_notifier(&ehea_mem_nb);
        unregister_reboot_notifier(&ehea_reboot_nb);
-       crash_shutdown_unregister(&ehea_crash_handler);
+       crash_shutdown_unregister(ehea_crash_handler);
 out:
        return ret;
 }
@@ -3701,7 +3766,7 @@ static void __exit ehea_module_exit(void)
        driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
        ibmebus_unregister_driver(&ehea_driver);
        unregister_reboot_notifier(&ehea_reboot_nb);
-       ret = crash_shutdown_unregister(&ehea_crash_handler);
+       ret = crash_shutdown_unregister(ehea_crash_handler);
        if (ret)
                ehea_info("failed unregistering crash handler");
        unregister_memory_notifier(&ehea_mem_nb);