Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / eq.c
index 8aabd23..ee04aab 100644 (file)
@@ -74,6 +74,9 @@ struct mlx5_eq_table {
 
        struct atomic_notifier_head nh[MLX5_EVENT_TYPE_MAX];
 
+       /* Since CQ DB is stored in async_eq */
+       struct mlx5_nb          cq_err_nb;
+
        struct mutex            lock; /* sync async eqs creations */
        int                     num_comp_vectors;
        struct mlx5_irq_info    *irq_info;
@@ -105,121 +108,6 @@ static int mlx5_cmd_destroy_eq(struct mlx5_core_dev *dev, u8 eqn)
        return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
-static const char *eqe_type_str(u8 type)
-{
-       switch (type) {
-       case MLX5_EVENT_TYPE_COMP:
-               return "MLX5_EVENT_TYPE_COMP";
-       case MLX5_EVENT_TYPE_PATH_MIG:
-               return "MLX5_EVENT_TYPE_PATH_MIG";
-       case MLX5_EVENT_TYPE_COMM_EST:
-               return "MLX5_EVENT_TYPE_COMM_EST";
-       case MLX5_EVENT_TYPE_SQ_DRAINED:
-               return "MLX5_EVENT_TYPE_SQ_DRAINED";
-       case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
-               return "MLX5_EVENT_TYPE_SRQ_LAST_WQE";
-       case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
-               return "MLX5_EVENT_TYPE_SRQ_RQ_LIMIT";
-       case MLX5_EVENT_TYPE_CQ_ERROR:
-               return "MLX5_EVENT_TYPE_CQ_ERROR";
-       case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
-               return "MLX5_EVENT_TYPE_WQ_CATAS_ERROR";
-       case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
-               return "MLX5_EVENT_TYPE_PATH_MIG_FAILED";
-       case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
-               return "MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR";
-       case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
-               return "MLX5_EVENT_TYPE_WQ_ACCESS_ERROR";
-       case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
-               return "MLX5_EVENT_TYPE_SRQ_CATAS_ERROR";
-       case MLX5_EVENT_TYPE_INTERNAL_ERROR:
-               return "MLX5_EVENT_TYPE_INTERNAL_ERROR";
-       case MLX5_EVENT_TYPE_PORT_CHANGE:
-               return "MLX5_EVENT_TYPE_PORT_CHANGE";
-       case MLX5_EVENT_TYPE_GPIO_EVENT:
-               return "MLX5_EVENT_TYPE_GPIO_EVENT";
-       case MLX5_EVENT_TYPE_PORT_MODULE_EVENT:
-               return "MLX5_EVENT_TYPE_PORT_MODULE_EVENT";
-       case MLX5_EVENT_TYPE_TEMP_WARN_EVENT:
-               return "MLX5_EVENT_TYPE_TEMP_WARN_EVENT";
-       case MLX5_EVENT_TYPE_REMOTE_CONFIG:
-               return "MLX5_EVENT_TYPE_REMOTE_CONFIG";
-       case MLX5_EVENT_TYPE_DB_BF_CONGESTION:
-               return "MLX5_EVENT_TYPE_DB_BF_CONGESTION";
-       case MLX5_EVENT_TYPE_STALL_EVENT:
-               return "MLX5_EVENT_TYPE_STALL_EVENT";
-       case MLX5_EVENT_TYPE_CMD:
-               return "MLX5_EVENT_TYPE_CMD";
-       case MLX5_EVENT_TYPE_PAGE_REQUEST:
-               return "MLX5_EVENT_TYPE_PAGE_REQUEST";
-       case MLX5_EVENT_TYPE_PAGE_FAULT:
-               return "MLX5_EVENT_TYPE_PAGE_FAULT";
-       case MLX5_EVENT_TYPE_PPS_EVENT:
-               return "MLX5_EVENT_TYPE_PPS_EVENT";
-       case MLX5_EVENT_TYPE_NIC_VPORT_CHANGE:
-               return "MLX5_EVENT_TYPE_NIC_VPORT_CHANGE";
-       case MLX5_EVENT_TYPE_FPGA_ERROR:
-               return "MLX5_EVENT_TYPE_FPGA_ERROR";
-       case MLX5_EVENT_TYPE_FPGA_QP_ERROR:
-               return "MLX5_EVENT_TYPE_FPGA_QP_ERROR";
-       case MLX5_EVENT_TYPE_GENERAL_EVENT:
-               return "MLX5_EVENT_TYPE_GENERAL_EVENT";
-       case MLX5_EVENT_TYPE_DEVICE_TRACER:
-               return "MLX5_EVENT_TYPE_DEVICE_TRACER";
-       default:
-               return "Unrecognized event";
-       }
-}
-
-static enum mlx5_dev_event port_subtype_event(u8 subtype)
-{
-       switch (subtype) {
-       case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
-               return MLX5_DEV_EVENT_PORT_DOWN;
-       case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-               return MLX5_DEV_EVENT_PORT_UP;
-       case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
-               return MLX5_DEV_EVENT_PORT_INITIALIZED;
-       case MLX5_PORT_CHANGE_SUBTYPE_LID:
-               return MLX5_DEV_EVENT_LID_CHANGE;
-       case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
-               return MLX5_DEV_EVENT_PKEY_CHANGE;
-       case MLX5_PORT_CHANGE_SUBTYPE_GUID:
-               return MLX5_DEV_EVENT_GUID_CHANGE;
-       case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
-               return MLX5_DEV_EVENT_CLIENT_REREG;
-       }
-       return -1;
-}
-
-static void general_event_handler(struct mlx5_core_dev *dev,
-                                 struct mlx5_eqe *eqe)
-{
-       switch (eqe->sub_type) {
-       case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT:
-               if (dev->event)
-                       dev->event(dev, MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT, 0);
-               break;
-       default:
-               mlx5_core_dbg(dev, "General event with unrecognized subtype: sub_type %d\n",
-                             eqe->sub_type);
-       }
-}
-
-static void mlx5_temp_warning_event(struct mlx5_core_dev *dev,
-                                   struct mlx5_eqe *eqe)
-{
-       u64 value_lsb;
-       u64 value_msb;
-
-       value_lsb = be64_to_cpu(eqe->data.temp_warning.sensor_warning_lsb);
-       value_msb = be64_to_cpu(eqe->data.temp_warning.sensor_warning_msb);
-
-       mlx5_core_warn(dev,
-                      "High temperature on sensors with bit set %llx %llx",
-                      value_msb, value_lsb);
-}
-
 /* caller must eventually call mlx5_cq_put on the returned cq */
 static struct mlx5_core_cq *mlx5_eq_cq_get(struct mlx5_eq *eq, u32 cqn)
 {
@@ -235,20 +123,6 @@ static struct mlx5_core_cq *mlx5_eq_cq_get(struct mlx5_eq *eq, u32 cqn)
        return cq;
 }
 
-static void mlx5_eq_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type)
-{
-       struct mlx5_core_cq *cq = mlx5_eq_cq_get(eq, cqn);
-
-       if (unlikely(!cq)) {
-               mlx5_core_warn(eq->dev, "Async event for bogus CQ 0x%x\n", cqn);
-               return;
-       }
-
-       cq->event(cq, event_type);
-
-       mlx5_cq_put(cq);
-}
-
 static irqreturn_t mlx5_eq_comp_int(int irq, void *eq_ptr)
 {
        struct mlx5_eq_comp *eq_comp = eq_ptr;
@@ -323,9 +197,6 @@ static irqreturn_t mlx5_eq_async_int(int irq, void *eq_ptr)
        struct mlx5_core_dev *dev;
        struct mlx5_eqe *eqe;
        int set_ci = 0;
-       u32 cqn = -1;
-       u32 rsn;
-       u8 port;
 
        dev = eq->dev;
        eqt = dev->priv.eq_table;
@@ -337,104 +208,6 @@ static irqreturn_t mlx5_eq_async_int(int irq, void *eq_ptr)
                 */
                dma_rmb();
 
-               mlx5_core_dbg(eq->dev, "eqn %d, eqe type %s\n",
-                             eq->eqn, eqe_type_str(eqe->type));
-               switch (eqe->type) {
-               case MLX5_EVENT_TYPE_DCT_DRAINED:
-                       rsn = be32_to_cpu(eqe->data.dct.dctn) & 0xffffff;
-                       rsn |= (MLX5_RES_DCT << MLX5_USER_INDEX_LEN);
-                       mlx5_rsc_event(dev, rsn, eqe->type);
-                       break;
-               case MLX5_EVENT_TYPE_PATH_MIG:
-               case MLX5_EVENT_TYPE_COMM_EST:
-               case MLX5_EVENT_TYPE_SQ_DRAINED:
-               case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
-               case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
-               case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
-               case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
-               case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
-                       rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
-                       rsn |= (eqe->data.qp_srq.type << MLX5_USER_INDEX_LEN);
-                       mlx5_core_dbg(dev, "event %s(%d) arrived on resource 0x%x\n",
-                                     eqe_type_str(eqe->type), eqe->type, rsn);
-                       mlx5_rsc_event(dev, rsn, eqe->type);
-                       break;
-
-               case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
-               case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
-                       rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
-                       mlx5_core_dbg(dev, "SRQ event %s(%d): srqn 0x%x\n",
-                                     eqe_type_str(eqe->type), eqe->type, rsn);
-                       mlx5_srq_event(dev, rsn, eqe->type);
-                       break;
-
-               case MLX5_EVENT_TYPE_CMD:
-                       mlx5_cmd_comp_handler(dev, be32_to_cpu(eqe->data.cmd.vector), false);
-                       break;
-
-               case MLX5_EVENT_TYPE_PORT_CHANGE:
-                       port = (eqe->data.port.port >> 4) & 0xf;
-                       switch (eqe->sub_type) {
-                       case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
-                       case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-                       case MLX5_PORT_CHANGE_SUBTYPE_LID:
-                       case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
-                       case MLX5_PORT_CHANGE_SUBTYPE_GUID:
-                       case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
-                       case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
-                               if (dev->event)
-                                       dev->event(dev, port_subtype_event(eqe->sub_type),
-                                                  (unsigned long)port);
-                               break;
-                       default:
-                               mlx5_core_warn(dev, "Port event with unrecognized subtype: port %d, sub_type %d\n",
-                                              port, eqe->sub_type);
-                       }
-                       break;
-               case MLX5_EVENT_TYPE_CQ_ERROR:
-                       cqn = be32_to_cpu(eqe->data.cq_err.cqn) & 0xffffff;
-                       mlx5_core_warn(dev, "CQ error on CQN 0x%x, syndrome 0x%x\n",
-                                      cqn, eqe->data.cq_err.syndrome);
-                       mlx5_eq_cq_event(eq, cqn, eqe->type);
-                       break;
-
-               case MLX5_EVENT_TYPE_PAGE_REQUEST:
-                       {
-                               u16 func_id = be16_to_cpu(eqe->data.req_pages.func_id);
-                               s32 npages = be32_to_cpu(eqe->data.req_pages.num_pages);
-
-                               mlx5_core_dbg(dev, "page request for func 0x%x, npages %d\n",
-                                             func_id, npages);
-                               mlx5_core_req_pages_handler(dev, func_id, npages);
-                       }
-                       break;
-
-               case MLX5_EVENT_TYPE_NIC_VPORT_CHANGE:
-                       mlx5_eswitch_vport_event(dev->priv.eswitch, eqe);
-                       break;
-
-               case MLX5_EVENT_TYPE_PORT_MODULE_EVENT:
-                       mlx5_port_module_event(dev, eqe);
-                       break;
-
-               case MLX5_EVENT_TYPE_PPS_EVENT:
-                       mlx5_pps_event(dev, eqe);
-                       break;
-
-               case MLX5_EVENT_TYPE_TEMP_WARN_EVENT:
-                       mlx5_temp_warning_event(dev, eqe);
-                       break;
-
-               case MLX5_EVENT_TYPE_GENERAL_EVENT:
-                       general_event_handler(dev, eqe);
-                       break;
-
-               default:
-                       mlx5_core_warn(dev, "Unhandled event 0x%x on EQ 0x%x\n",
-                                      eqe->type, eq->eqn);
-                       break;
-               }
-
                if (likely(eqe->type < MLX5_EVENT_TYPE_MAX))
                        atomic_notifier_call_chain(&eqt->nh[eqe->type], eqe->type, eqe);
                else
@@ -691,6 +464,38 @@ static int destroy_async_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
        return err;
 }
 
+static int cq_err_event_notifier(struct notifier_block *nb,
+                                unsigned long type, void *data)
+{
+       struct mlx5_eq_table *eqt;
+       struct mlx5_core_cq *cq;
+       struct mlx5_eqe *eqe;
+       struct mlx5_eq *eq;
+       u32 cqn;
+
+       /* type == MLX5_EVENT_TYPE_CQ_ERROR */
+
+       eqt = mlx5_nb_cof(nb, struct mlx5_eq_table, cq_err_nb);
+       eq  = &eqt->async_eq;
+       eqe = data;
+
+       cqn = be32_to_cpu(eqe->data.cq_err.cqn) & 0xffffff;
+       mlx5_core_warn(eq->dev, "CQ error on CQN 0x%x, syndrome 0x%x\n",
+                      cqn, eqe->data.cq_err.syndrome);
+
+       cq = mlx5_eq_cq_get(eq, cqn);
+       if (unlikely(!cq)) {
+               mlx5_core_warn(eq->dev, "Async event for bogus CQ 0x%x\n", cqn);
+               return NOTIFY_OK;
+       }
+
+       cq->event(cq, type);
+
+       mlx5_cq_put(cq);
+
+       return NOTIFY_OK;
+}
+
 static u64 gather_async_events_mask(struct mlx5_core_dev *dev)
 {
        u64 async_event_mask = MLX5_ASYNC_EVENT_MASK;
@@ -722,6 +527,9 @@ static u64 gather_async_events_mask(struct mlx5_core_dev *dev)
        if (MLX5_CAP_MCAM_REG(dev, tracer_registers))
                async_event_mask |= (1ull << MLX5_EVENT_TYPE_DEVICE_TRACER);
 
+       if (MLX5_CAP_GEN(dev, max_num_of_monitor_counters))
+               async_event_mask |= (1ull << MLX5_EVENT_TYPE_MONITOR_COUNTER);
+
        return async_event_mask;
 }
 
@@ -731,6 +539,9 @@ static int create_async_eqs(struct mlx5_core_dev *dev)
        struct mlx5_eq_param param = {};
        int err;
 
+       MLX5_NB_INIT(&table->cq_err_nb, cq_err_event_notifier, CQ_ERROR);
+       mlx5_eq_notifier_register(dev, &table->cq_err_nb);
+
        param = (struct mlx5_eq_param) {
                .index = MLX5_EQ_CMD_IDX,
                .mask = 1ull << MLX5_EVENT_TYPE_CMD,
@@ -741,7 +552,7 @@ static int create_async_eqs(struct mlx5_core_dev *dev)
        err = create_async_eq(dev, "mlx5_cmd_eq", &table->cmd_eq, &param);
        if (err) {
                mlx5_core_warn(dev, "failed to create cmd EQ %d\n", err);
-               return err;
+               goto err0;
        }
 
        mlx5_cmd_use_events(dev);
@@ -780,6 +591,8 @@ err2:
 err1:
        mlx5_cmd_use_polling(dev);
        destroy_async_eq(dev, &table->cmd_eq);
+err0:
+       mlx5_eq_notifier_unregister(dev, &table->cq_err_nb);
        return err;
 }
 
@@ -797,12 +610,15 @@ static void destroy_async_eqs(struct mlx5_core_dev *dev)
        if (err)
                mlx5_core_err(dev, "failed to destroy async eq, err(%d)\n",
                              err);
+
        mlx5_cmd_use_polling(dev);
 
        err = destroy_async_eq(dev, &table->cmd_eq);
        if (err)
                mlx5_core_err(dev, "failed to destroy command eq, err(%d)\n",
                              err);
+
+       mlx5_eq_notifier_unregister(dev, &table->cq_err_nb);
 }
 
 struct mlx5_eq *mlx5_get_async_eq(struct mlx5_core_dev *dev)