static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info) { int status = 0; u8 lstate = 0; struct ocrdma_dev *dev; dev = ib_alloc_device(ocrdma_dev, ibdev); if (!dev) { pr_err("Unable to allocate ib device\n"); return NULL; } dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL); if (!dev->mbx_cmd) goto init_err; memcpy(&dev->nic_info, dev_info, sizeof(*dev_info)); dev->id = PCI_FUNC(dev->nic_info.pdev->devfn); status = ocrdma_init_hw(dev); if (status) goto init_err; status = ocrdma_alloc_resources(dev); if (status) goto alloc_err; ocrdma_init_service_level(dev); status = ocrdma_register_device(dev); if (status) goto alloc_err; /* Query Link state and update */ status = ocrdma_mbx_get_link_speed(dev, NULL, &lstate); if (!status) ocrdma_update_link_state(dev, lstate); /* Init stats */ ocrdma_add_port_stats(dev); /* Interrupt Moderation */ INIT_DELAYED_WORK(&dev->eqd_work, ocrdma_eqd_set_task); schedule_delayed_work(&dev->eqd_work, msecs_to_jiffies(1000)); pr_info("%s %s: %s \"%s\" port %d\n", dev_name(&dev->nic_info.pdev->dev), hca_name(dev), port_speed_string(dev), dev->model_number, dev->hba_port_num); pr_info("%s ocrdma%d driver loaded successfully\n", dev_name(&dev->nic_info.pdev->dev), dev->id); return dev; alloc_err: ocrdma_free_resources(dev); ocrdma_cleanup_hw(dev); init_err: kfree(dev->mbx_cmd); ib_dealloc_device(&dev->ibdev); pr_err("%s() leaving. ret=%d\n", __func__, status); return NULL; }
static void ocrdma_remove(struct ocrdma_dev *dev) { /* first unregister with stack to stop all the active traffic * of the registered clients. */ cancel_delayed_work_sync(&dev->eqd_work); ib_unregister_device(&dev->ibdev); ocrdma_rem_port_stats(dev); ocrdma_free_resources(dev); ocrdma_cleanup_hw(dev); ocrdma_remove_free(dev); }