All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raghava Aditya Renukunta <RaghavaAditya.Renukunta@microsemi.com>
To: jejb@linux.vnet.ibm.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org
Cc: David.Carroll@microsemi.com, Gana.Sridaran@microsemi.com,
	RaghavaAditya.Renukunta@microsemi.com,
	Scott.Banesh@microsemi.com
Subject: [PATCH 10/24] aacraid: Reworked aac_command_thread
Date: Mon, 23 Jan 2017 10:08:54 -0800	[thread overview]
Message-ID: <20170123180908.3465-11-RaghavaAditya.Renukunta@microsemi.com> (raw)
In-Reply-To: <20170123180908.3465-1-RaghavaAditya.Renukunta@microsemi.com>

Reworked aac_command_thread into aac_process_events

Signed-off-by: Raghava Aditya Renukunta <RaghavaAditya.Renukunta@microsemi.com>
Signed-off-by: Dave Carroll <David.Carroll@microsemi.com>
---
 drivers/scsi/aacraid/commsup.c | 410 ++++++++++++++++++++++-------------------
 1 file changed, 217 insertions(+), 193 deletions(-)

diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 31c65ca..dd5819c 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1729,6 +1729,222 @@ int aac_check_health(struct aac_dev * aac)
 	return BlinkLED;
 }
 
+static void aac_process_events(struct aac_dev *dev)
+{
+	struct hw_fib *hw_fib, *hw_newfib;
+	struct fib *fib, *newfib;
+	struct aac_fib_context *fibctx;
+	unsigned long flags;
+	spinlock_t *t_lock;
+
+	spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
+	while (!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
+		struct list_head *entry;
+		struct aac_aifcmd *aifcmd;
+		u32 time_now, time_last;
+		unsigned long flagv;
+		unsigned int  num;
+		struct hw_fib **hw_fib_pool, **hw_fib_p;
+		struct fib **fib_pool, **fib_p;
+
+		set_current_state(TASK_RUNNING);
+
+		entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
+		list_del(entry);
+
+
+		t_lock = dev->queues->queue[HostNormCmdQueue].lock;
+		spin_unlock_irqrestore(t_lock, flags);
+
+		fib = list_entry(entry, struct fib, fiblink);
+		hw_fib = fib->hw_fib_va;
+		/*
+		 *	We will process the FIB here or pass it to a
+		 *	worker thread that is TBD. We Really can't
+		 *	do anything at this point since we don't have
+		 *	anything defined for this thread to do.
+		 */
+		memset(fib, 0, sizeof(struct fib));
+		fib->type = FSAFS_NTC_FIB_CONTEXT;
+		fib->size = sizeof(struct fib);
+		fib->hw_fib_va = hw_fib;
+		fib->data = hw_fib->data;
+		fib->dev = dev;
+		/*
+		 *	We only handle AifRequest fibs from the adapter.
+		 */
+
+		aifcmd = (struct aac_aifcmd *) hw_fib->data;
+		if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
+			/* Handle Driver Notify Events */
+			aac_handle_aif(dev, fib);
+			*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
+			aac_fib_adapter_complete(fib, (u16)sizeof(u32));
+			continue;
+		}
+		/*
+		 * The u32 here is important and intended. We are using
+		 * 32bit wrapping time to fit the adapter field
+		 */
+
+
+		/* Sniff events */
+		if ((aifcmd->command ==	cpu_to_le32(AifCmdEventNotify)) ||
+				(aifcmd->command ==
+				cpu_to_le32(AifCmdJobProgress))) {
+			aac_handle_aif(dev, fib);
+		}
+
+		time_now = jiffies/HZ;
+
+		/*
+		 * Warning: no sleep allowed while
+		 * holding spinlock. We take the estimate
+		 * and pre-allocate a set of fibs outside the
+		 * lock.
+		 */
+		num = le32_to_cpu(dev->init->r7.AdapterFibsSize)
+				/ sizeof(struct hw_fib); /* some extra */
+		spin_lock_irqsave(&dev->fib_lock, flagv);
+		entry = dev->fib_list.next;
+		while (entry != &dev->fib_list) {
+			entry = entry->next;
+			++num;
+		}
+		spin_unlock_irqrestore(&dev->fib_lock, flagv);
+		hw_fib_pool = kmalloc_array(num, sizeof(struct hw_fib *),
+						GFP_KERNEL);
+		fib_pool = kmalloc_array(num, sizeof(struct fib *),
+						GFP_KERNEL);
+		if (num	&& fib_pool && hw_fib_pool) {
+			hw_fib_p = hw_fib_pool;
+			fib_p = fib_pool;
+			while (hw_fib_p < &hw_fib_pool[num]) {
+				*(hw_fib_p) = kmalloc(sizeof(struct hw_fib),
+						GFP_KERNEL);
+				if (!(*(hw_fib_p++))) {
+					--hw_fib_p;
+					break;
+				}
+				*(fib_p) = kmalloc(sizeof(struct fib),
+						GFP_KERNEL);
+				if (!(*(fib_p++))) {
+					kfree(*(--hw_fib_p));
+					break;
+				}
+			}
+			num = hw_fib_p - hw_fib_pool;
+			if (!num) {
+				kfree(fib_pool);
+				fib_pool = NULL;
+				kfree(hw_fib_pool);
+				hw_fib_pool = NULL;
+				continue;
+			}
+		} else {
+			kfree(hw_fib_pool);
+			hw_fib_pool = NULL;
+			kfree(fib_pool);
+			fib_pool = NULL;
+		}
+		spin_lock_irqsave(&dev->fib_lock, flagv);
+		entry = dev->fib_list.next;
+		/*
+		 * For each Context that is on the
+		 * fibctxList, make a copy of the
+		 * fib, and then set the event to wake up the
+		 * thread that is waiting for it.
+		 */
+		hw_fib_p = hw_fib_pool;
+		fib_p = fib_pool;
+		while (entry != &dev->fib_list) {
+			/*
+			 * Extract the fibctx
+			 */
+			fibctx = list_entry(entry, struct aac_fib_context,
+					next);
+			/*
+			 * Check if the queue is getting
+			 * backlogged
+			 */
+			if (fibctx->count > 20) {
+				/*
+				 * It's *not* jiffies folks,
+				 * but jiffies / HZ so do not
+				 * panic ...
+				 */
+				time_last = fibctx->jiffies;
+				/*
+				 * Has it been > 2 minutes
+				 * since the last read off
+				 * the queue?
+				 */
+				if ((time_now - time_last) > aif_timeout) {
+					entry = entry->next;
+					aac_close_fib_context(dev, fibctx);
+					continue;
+				}
+			}
+			/*
+			 * Warning: no sleep allowed while
+			 * holding spinlock
+			 */
+			if (hw_fib_p < &hw_fib_pool[num]) {
+				hw_newfib = *hw_fib_p;
+				*(hw_fib_p++) = NULL;
+				newfib = *fib_p;
+				*(fib_p++) = NULL;
+				/*
+				 * Make the copy of the FIB
+				 */
+				memcpy(hw_newfib, hw_fib,
+					sizeof(struct hw_fib));
+				memcpy(newfib, fib, sizeof(struct fib));
+				newfib->hw_fib_va = hw_newfib;
+				/*
+				 * Put the FIB onto the
+				 * fibctx's fibs
+				 */
+				list_add_tail(&newfib->fiblink,
+					&fibctx->fib_list);
+				fibctx->count++;
+				/*
+				 * Set the event to wake up the
+				 * thread that is waiting.
+				 */
+				up(&fibctx->wait_sem);
+			} else {
+				pr_warn("aifd: didn't allocate NewFib.\n");
+			}
+			entry = entry->next;
+		}
+		/*
+		 *	Set the status of this FIB
+		 */
+		*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
+		aac_fib_adapter_complete(fib, sizeof(u32));
+		spin_unlock_irqrestore(&dev->fib_lock, flagv);
+		/* Free up the remaining resources */
+		hw_fib_p = hw_fib_pool;
+		fib_p = fib_pool;
+		while (hw_fib_p < &hw_fib_pool[num]) {
+			kfree(*hw_fib_p);
+			kfree(*fib_p);
+			++fib_p;
+			++hw_fib_p;
+		}
+		kfree(hw_fib_pool);
+		kfree(fib_pool);
+		kfree(fib);
+		spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock,
+				flags);
+	}
+	/*
+	 *	There are no more AIF's
+	 */
+	spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock,
+			flags);
+}
 
 /**
  *	aac_command_thread	-	command processing thread
@@ -1743,10 +1959,6 @@ int aac_check_health(struct aac_dev * aac)
 int aac_command_thread(void *data)
 {
 	struct aac_dev *dev = data;
-	struct hw_fib *hw_fib, *hw_newfib;
-	struct fib *fib, *newfib;
-	struct aac_fib_context *fibctx;
-	unsigned long flags;
 	DECLARE_WAITQUEUE(wait, current);
 	unsigned long next_jiffies = jiffies + HZ;
 	unsigned long next_check_jiffies = next_jiffies;
@@ -1766,196 +1978,8 @@ int aac_command_thread(void *data)
 	set_current_state(TASK_INTERRUPTIBLE);
 	dprintk ((KERN_INFO "aac_command_thread start\n"));
 	while (1) {
-		spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
-		while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
-			struct list_head *entry;
-			struct aac_aifcmd * aifcmd;
 
-			set_current_state(TASK_RUNNING);
-
-			entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
-			list_del(entry);
-
-			spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
-			fib = list_entry(entry, struct fib, fiblink);
-			/*
-			 *	We will process the FIB here or pass it to a
-			 *	worker thread that is TBD. We Really can't
-			 *	do anything at this point since we don't have
-			 *	anything defined for this thread to do.
-			 */
-			hw_fib = fib->hw_fib_va;
-			memset(fib, 0, sizeof(struct fib));
-			fib->type = FSAFS_NTC_FIB_CONTEXT;
-			fib->size = sizeof(struct fib);
-			fib->hw_fib_va = hw_fib;
-			fib->data = hw_fib->data;
-			fib->dev = dev;
-			/*
-			 *	We only handle AifRequest fibs from the adapter.
-			 */
-			aifcmd = (struct aac_aifcmd *) hw_fib->data;
-			if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
-				/* Handle Driver Notify Events */
-				aac_handle_aif(dev, fib);
-				*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
-				aac_fib_adapter_complete(fib, (u16)sizeof(u32));
-			} else {
-				/* The u32 here is important and intended. We are using
-				   32bit wrapping time to fit the adapter field */
-
-				u32 time_now, time_last;
-				unsigned long flagv;
-				unsigned num;
-				struct hw_fib ** hw_fib_pool, ** hw_fib_p;
-				struct fib ** fib_pool, ** fib_p;
-
-				/* Sniff events */
-				if ((aifcmd->command ==
-				     cpu_to_le32(AifCmdEventNotify)) ||
-				    (aifcmd->command ==
-				     cpu_to_le32(AifCmdJobProgress))) {
-					aac_handle_aif(dev, fib);
-				}
-
-				time_now = jiffies/HZ;
-
-				/*
-				 * Warning: no sleep allowed while
-				 * holding spinlock. We take the estimate
-				 * and pre-allocate a set of fibs outside the
-				 * lock.
-				 */
-				num = le32_to_cpu(dev->init->r7.AdapterFibsSize)
-				    / sizeof(struct hw_fib); /* some extra */
-				spin_lock_irqsave(&dev->fib_lock, flagv);
-				entry = dev->fib_list.next;
-				while (entry != &dev->fib_list) {
-					entry = entry->next;
-					++num;
-				}
-				spin_unlock_irqrestore(&dev->fib_lock, flagv);
-				hw_fib_pool = NULL;
-				fib_pool = NULL;
-				if (num
-				 && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
-				 && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
-					hw_fib_p = hw_fib_pool;
-					fib_p = fib_pool;
-					while (hw_fib_p < &hw_fib_pool[num]) {
-						if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
-							--hw_fib_p;
-							break;
-						}
-						if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
-							kfree(*(--hw_fib_p));
-							break;
-						}
-					}
-					if ((num = hw_fib_p - hw_fib_pool) == 0) {
-						kfree(fib_pool);
-						fib_pool = NULL;
-						kfree(hw_fib_pool);
-						hw_fib_pool = NULL;
-					}
-				} else {
-					kfree(hw_fib_pool);
-					hw_fib_pool = NULL;
-				}
-				spin_lock_irqsave(&dev->fib_lock, flagv);
-				entry = dev->fib_list.next;
-				/*
-				 * For each Context that is on the
-				 * fibctxList, make a copy of the
-				 * fib, and then set the event to wake up the
-				 * thread that is waiting for it.
-				 */
-				hw_fib_p = hw_fib_pool;
-				fib_p = fib_pool;
-				while (entry != &dev->fib_list) {
-					/*
-					 * Extract the fibctx
-					 */
-					fibctx = list_entry(entry, struct aac_fib_context, next);
-					/*
-					 * Check if the queue is getting
-					 * backlogged
-					 */
-					if (fibctx->count > 20)
-					{
-						/*
-						 * It's *not* jiffies folks,
-						 * but jiffies / HZ so do not
-						 * panic ...
-						 */
-						time_last = fibctx->jiffies;
-						/*
-						 * Has it been > 2 minutes
-						 * since the last read off
-						 * the queue?
-						 */
-						if ((time_now - time_last) > aif_timeout) {
-							entry = entry->next;
-							aac_close_fib_context(dev, fibctx);
-							continue;
-						}
-					}
-					/*
-					 * Warning: no sleep allowed while
-					 * holding spinlock
-					 */
-					if (hw_fib_p < &hw_fib_pool[num]) {
-						hw_newfib = *hw_fib_p;
-						*(hw_fib_p++) = NULL;
-						newfib = *fib_p;
-						*(fib_p++) = NULL;
-						/*
-						 * Make the copy of the FIB
-						 */
-						memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
-						memcpy(newfib, fib, sizeof(struct fib));
-						newfib->hw_fib_va = hw_newfib;
-						/*
-						 * Put the FIB onto the
-						 * fibctx's fibs
-						 */
-						list_add_tail(&newfib->fiblink, &fibctx->fib_list);
-						fibctx->count++;
-						/*
-						 * Set the event to wake up the
-						 * thread that is waiting.
-						 */
-						up(&fibctx->wait_sem);
-					} else {
-						printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
-					}
-					entry = entry->next;
-				}
-				/*
-				 *	Set the status of this FIB
-				 */
-				*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
-				aac_fib_adapter_complete(fib, sizeof(u32));
-				spin_unlock_irqrestore(&dev->fib_lock, flagv);
-				/* Free up the remaining resources */
-				hw_fib_p = hw_fib_pool;
-				fib_p = fib_pool;
-				while (hw_fib_p < &hw_fib_pool[num]) {
-					kfree(*hw_fib_p);
-					kfree(*fib_p);
-					++fib_p;
-					++hw_fib_p;
-				}
-				kfree(hw_fib_pool);
-				kfree(fib_pool);
-			}
-			kfree(fib);
-			spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
-		}
-		/*
-		 *	There are no more AIF's
-		 */
-		spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
+		aac_process_events(dev);
 
 		/*
 		 *	Background activity
-- 
2.7.4


  parent reply	other threads:[~2017-01-24  0:47 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-23 18:08 [PATCH 00/24] aacraid: Patchset for Smart Family card support Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 01/24] aacraid: Remove duplicate irq management code Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 02/24] aacraid: Added aacraid.h include guard Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 03/24] aacraid: added support for init_struct_8 Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 04/24] aacraid: Added sa firmware support Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 05/24] aacraid: Retrieve and update the device types Raghava Aditya Renukunta
2017-01-24  1:53   ` kbuild test robot
2017-01-23 18:08 ` [PATCH 06/24] aacraid: Reworked scsi command submission path Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 07/24] aacraid: Process Error for response I/O Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 08/24] aacraid: Added support for response path Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 09/24] aacraid: Added support for read medium error Raghava Aditya Renukunta
2017-01-23 18:08 ` Raghava Aditya Renukunta [this message]
2017-01-23 18:08 ` [PATCH 11/24] aacraid: Added support for periodic wellness sync Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 12/24] aacraid: Retrieve Queue Depth from Adapter FW Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 13/24] aacraid: Added support to set QD of attached drives Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 14/24] aacraid: Added support for hotplug Raghava Aditya Renukunta
2017-01-23 18:08 ` [PATCH 15/24] aacraid: Include HBA direct interface Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 16/24] aacraid: Add task management functionality Raghava Aditya Renukunta
2017-01-24  3:39   ` kbuild test robot
2017-01-23 18:09 ` [PATCH 17/24] aacraid: Added support to abort cmd and reset lun Raghava Aditya Renukunta
2017-01-24  2:24   ` kbuild test robot
2017-01-23 18:09 ` [PATCH 18/24] aacraid: VPD 83 type3 support Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 19/24] aacraid: Added new IWBR reset Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 20/24] aacraid: Added ioctl to trigger IOP/IWBR reset Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 21/24] aacraid: Retrieve HBA host information ioctl Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 22/24] aacraid: Update copyrights Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 23/24] aacraid: Change Driver Version Prefix Raghava Aditya Renukunta
2017-01-23 18:09 ` [PATCH 24/24] aacraid: update version Raghava Aditya Renukunta
2017-01-25 23:31 ` [PATCH 00/24] aacraid: Patchset for Smart Family card support Martin K. Petersen
2017-01-26  0:29   ` Raghava Aditya Renukunta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170123180908.3465-11-RaghavaAditya.Renukunta@microsemi.com \
    --to=raghavaaditya.renukunta@microsemi.com \
    --cc=David.Carroll@microsemi.com \
    --cc=Gana.Sridaran@microsemi.com \
    --cc=Scott.Banesh@microsemi.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.