1*d7b71fd2SJames Smart // SPDX-License-Identifier: GPL-2.0 2*d7b71fd2SJames Smart /* 3*d7b71fd2SJames Smart * Copyright (C) 2021 Broadcom. All Rights Reserved. The term 4*d7b71fd2SJames Smart * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 5*d7b71fd2SJames Smart */ 6*d7b71fd2SJames Smart 7*d7b71fd2SJames Smart /* 8*d7b71fd2SJames Smart * LIBEFC LOCKING 9*d7b71fd2SJames Smart * 10*d7b71fd2SJames Smart * The critical sections protected by the efc's spinlock are quite broad and 11*d7b71fd2SJames Smart * may be improved upon in the future. The libefc code and its locking doesn't 12*d7b71fd2SJames Smart * influence the I/O path, so excessive locking doesn't impact I/O performance. 13*d7b71fd2SJames Smart * 14*d7b71fd2SJames Smart * The strategy is to lock whenever processing a request from user driver. This 15*d7b71fd2SJames Smart * means that the entry points into the libefc library are protected by efc 16*d7b71fd2SJames Smart * lock. So all the state machine transitions are protected. 17*d7b71fd2SJames Smart */ 18*d7b71fd2SJames Smart 19*d7b71fd2SJames Smart #include <linux/module.h> 20*d7b71fd2SJames Smart #include <linux/kernel.h> 21*d7b71fd2SJames Smart #include "efc.h" 22*d7b71fd2SJames Smart 23*d7b71fd2SJames Smart int efcport_init(struct efc *efc) 24*d7b71fd2SJames Smart { 25*d7b71fd2SJames Smart u32 rc = 0; 26*d7b71fd2SJames Smart 27*d7b71fd2SJames Smart spin_lock_init(&efc->lock); 28*d7b71fd2SJames Smart INIT_LIST_HEAD(&efc->vport_list); 29*d7b71fd2SJames Smart efc->hold_frames = false; 30*d7b71fd2SJames Smart spin_lock_init(&efc->pend_frames_lock); 31*d7b71fd2SJames Smart INIT_LIST_HEAD(&efc->pend_frames); 32*d7b71fd2SJames Smart 33*d7b71fd2SJames Smart /* Create Node pool */ 34*d7b71fd2SJames Smart efc->node_pool = mempool_create_kmalloc_pool(EFC_MAX_REMOTE_NODES, 35*d7b71fd2SJames Smart sizeof(struct efc_node)); 36*d7b71fd2SJames Smart if (!efc->node_pool) { 37*d7b71fd2SJames Smart efc_log_err(efc, "Can't allocate node pool\n"); 38*d7b71fd2SJames Smart return -ENOMEM; 39*d7b71fd2SJames Smart } 40*d7b71fd2SJames Smart 41*d7b71fd2SJames Smart efc->node_dma_pool = dma_pool_create("node_dma_pool", &efc->pci->dev, 42*d7b71fd2SJames Smart NODE_SPARAMS_SIZE, 0, 0); 43*d7b71fd2SJames Smart if (!efc->node_dma_pool) { 44*d7b71fd2SJames Smart efc_log_err(efc, "Can't allocate node dma pool\n"); 45*d7b71fd2SJames Smart mempool_destroy(efc->node_pool); 46*d7b71fd2SJames Smart return -ENOMEM; 47*d7b71fd2SJames Smart } 48*d7b71fd2SJames Smart 49*d7b71fd2SJames Smart efc->els_io_pool = mempool_create_kmalloc_pool(EFC_ELS_IO_POOL_SZ, 50*d7b71fd2SJames Smart sizeof(struct efc_els_io_req)); 51*d7b71fd2SJames Smart if (!efc->els_io_pool) { 52*d7b71fd2SJames Smart efc_log_err(efc, "Can't allocate els io pool\n"); 53*d7b71fd2SJames Smart return -ENOMEM; 54*d7b71fd2SJames Smart } 55*d7b71fd2SJames Smart 56*d7b71fd2SJames Smart return rc; 57*d7b71fd2SJames Smart } 58*d7b71fd2SJames Smart 59*d7b71fd2SJames Smart static void 60*d7b71fd2SJames Smart efc_purge_pending(struct efc *efc) 61*d7b71fd2SJames Smart { 62*d7b71fd2SJames Smart struct efc_hw_sequence *frame, *next; 63*d7b71fd2SJames Smart unsigned long flags = 0; 64*d7b71fd2SJames Smart 65*d7b71fd2SJames Smart spin_lock_irqsave(&efc->pend_frames_lock, flags); 66*d7b71fd2SJames Smart 67*d7b71fd2SJames Smart list_for_each_entry_safe(frame, next, &efc->pend_frames, list_entry) { 68*d7b71fd2SJames Smart list_del(&frame->list_entry); 69*d7b71fd2SJames Smart efc->tt.hw_seq_free(efc, frame); 70*d7b71fd2SJames Smart } 71*d7b71fd2SJames Smart 72*d7b71fd2SJames Smart spin_unlock_irqrestore(&efc->pend_frames_lock, flags); 73*d7b71fd2SJames Smart } 74*d7b71fd2SJames Smart 75*d7b71fd2SJames Smart void efcport_destroy(struct efc *efc) 76*d7b71fd2SJames Smart { 77*d7b71fd2SJames Smart efc_purge_pending(efc); 78*d7b71fd2SJames Smart mempool_destroy(efc->els_io_pool); 79*d7b71fd2SJames Smart mempool_destroy(efc->node_pool); 80*d7b71fd2SJames Smart dma_pool_destroy(efc->node_dma_pool); 81*d7b71fd2SJames Smart } 82