Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2014 09:35:53 +0000 (UTC)
From:      Kashyap D Desai <kadesai@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272740 - head/sys/dev/mrsas
Message-ID:  <201410080935.s989Zrf1077472@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kadesai
Date: Wed Oct  8 09:35:52 2014
New Revision: 272740
URL: https://svnweb.freebsd.org/changeset/base/272740

Log:
  d_poll() callback function is the entry point for poll system call for the application.
  It is meant to notify the applications which will be waiting for some
  controller events to be occured.
  
  Reviewed by:	ambrisko
  MFC after:	2 weeks
  Sponsored by:	AVAGO Technologies

Modified:
  head/sys/dev/mrsas/mrsas.c
  head/sys/dev/mrsas/mrsas.h

Modified: head/sys/dev/mrsas/mrsas.c
==============================================================================
--- head/sys/dev/mrsas/mrsas.c	Wed Oct  8 09:34:25 2014	(r272739)
+++ head/sys/dev/mrsas/mrsas.c	Wed Oct  8 09:35:52 2014	(r272740)
@@ -65,6 +65,7 @@ static d_close_t    mrsas_close;
 static d_read_t     mrsas_read;
 static d_write_t    mrsas_write;
 static d_ioctl_t    mrsas_ioctl;
+static d_poll_t	    mrsas_poll;
 
 static struct mrsas_mgmt_info mrsas_mgmt_info;
 static struct mrsas_ident *mrsas_find_ident(device_t);
@@ -184,6 +185,7 @@ static struct cdevsw mrsas_cdevsw = {
     .d_read =   mrsas_read,
     .d_write =  mrsas_write,
     .d_ioctl =  mrsas_ioctl,
+    .d_poll =	mrsas_poll,
     .d_name =   "mrsas",
 };
 
@@ -1265,6 +1267,36 @@ do_ioctl:
 }
 
 /**
+ * mrsas_poll:       poll entry point for mrsas driver fd
+ *
+ * This function is the entry point for poll from the OS.  It waits for
+ * some AEN events to be triggered from the controller and notifies back.
+ */
+static int
+mrsas_poll(struct cdev *dev, int poll_events, struct thread *td)
+{
+	struct mrsas_softc *sc;
+	int revents = 0;
+
+	sc = dev->si_drv1;
+
+	if (poll_events & (POLLIN | POLLRDNORM)) {
+		if (sc->mrsas_aen_triggered) {
+			revents |= poll_events & (POLLIN | POLLRDNORM);
+		}
+	}
+
+	if (revents == 0) {
+		if (poll_events & (POLLIN | POLLRDNORM)) {
+			sc->mrsas_poll_waiting = 1;
+			selrecord(td, &sc->mrsas_select);
+		}
+	}
+
+	return revents;
+}
+
+/**
  * mrsas_setup_irq:   Set up interrupt. 
  * input:             Adapter instance soft state
  * 
@@ -3274,13 +3306,12 @@ mrsas_complete_mptmfi_passthru(struct mr
                 mtx_unlock(&sc->raidmap_lock);
                 break;
             }
-#if 0 //currently not supporting event handling, so commenting out
             if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET_INFO ||
                     cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET) {
-                mrsas_poll_wait_aen = 0;
+				sc->mrsas_aen_triggered = 0;
             }
-#endif
-            /* See if got an event notification */
+
+			/* See if got an event notification */
             if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_WAIT)
                 mrsas_complete_aen(sc, cmd);
             else
@@ -3967,7 +3998,11 @@ void mrsas_complete_aen(struct mrsas_sof
 	* Don't signal app if it is just an aborted previously registered aen
 	*/
 	if ((!cmd->abort_aen) && (sc->remove_in_progress == 0)) {
-		/* TO DO (?) */
+		sc->mrsas_aen_triggered = 1;
+		if (sc->mrsas_poll_waiting) {
+			sc->mrsas_poll_waiting = 0;
+			selwakeup(&sc->mrsas_select);
+		}
 	}
 	else
 		cmd->abort_aen = 0;

Modified: head/sys/dev/mrsas/mrsas.h
==============================================================================
--- head/sys/dev/mrsas/mrsas.h	Wed Oct  8 09:34:25 2014	(r272739)
+++ head/sys/dev/mrsas/mrsas.h	Wed Oct  8 09:35:52 2014	(r272740)
@@ -2491,6 +2491,9 @@ struct mrsas_softc {
     struct mtx mfi_cmd_pool_lock;         // lock for cmd pool linked list
     struct mtx raidmap_lock;              // lock for raid map access/update
     struct mtx aen_lock;                  // aen lock
+    struct selinfo mrsas_select;	  // poll select interface for application
+    uint32_t mrsas_aen_triggered;
+    uint32_t mrsas_poll_waiting;
     uint32_t           max_fw_cmds;       // Max commands from FW
     uint32_t           max_num_sge;       // Max number of SGEs
     struct resource    *mrsas_irq[MAX_MSIX_COUNT];        // interrupt interface window



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410080935.s989Zrf1077472>