Index: uspace/drv/usbmouse/mouse.c
===================================================================
--- uspace/drv/usbmouse/mouse.c	(revision 489c3e717b06bedddbc086e518d7a166c02aa28c)
+++ uspace/drv/usbmouse/mouse.c	(revision ff34e5aa0ca881086c2c718f37808d217179c40f)
@@ -40,124 +40,82 @@
 #include <ipc/mouse.h>
 
-/** Fibril function for polling the mouse device.
+/** Mouse polling callback.
  *
- * This function shall not terminate unless the device breaks and fails
- * to send data (e.g. stalls on data request).
- *
- * @param arg ddf_dev_t type representing the mouse device.
- * @return EOK Always.
+ * @param dev Device that is being polled.
+ * @param buffer Data buffer.
+ * @param buffer_size Buffer size in bytes.
+ * @param arg Custom argument - points to usb_mouse_t.
+ * @return Always true.
  */
-int usb_mouse_polling_fibril(void *arg)
+bool usb_mouse_polling_callback(usb_device_t *dev,
+    uint8_t *buffer, size_t buffer_size, void *arg)
 {
-	assert(arg != NULL);
-	usb_device_t *dev = (usb_device_t *) arg;
-	usb_mouse_t *mouse = (usb_mouse_t *) dev->driver_data;
+	usb_mouse_t *mouse = (usb_mouse_t *) arg;
 
-	assert(mouse);
+	usb_log_debug2("got buffer: %s.\n",
+	    usb_debug_str_buffer(buffer, buffer_size, 0));
 
-	size_t buffer_size = POLL_PIPE(dev)->max_packet_size;
+	uint8_t butt = buffer[0];
+	char str_buttons[4] = {
+		butt & 1 ? '#' : '.',
+		butt & 2 ? '#' : '.',
+		butt & 4 ? '#' : '.',
+		0
+	};
 
-	if (buffer_size < 4) {
-		usb_log_error("Weird mouse, results will be skewed.\n");
-		buffer_size = 4;
+	int shift_x = ((int) buffer[1]) - 127;
+	int shift_y = ((int) buffer[2]) - 127;
+	int wheel = ((int) buffer[3]) - 127;
+
+	if (buffer[1] == 0) {
+		shift_x = 0;
+	}
+	if (buffer[2] == 0) {
+		shift_y = 0;
+	}
+	if (buffer[3] == 0) {
+		wheel = 0;
 	}
 
-	uint8_t *buffer = malloc(buffer_size);
-	if (buffer == NULL) {
-		usb_log_error("Out of memory, poll fibril aborted.\n");
-		return ENOMEM;
+	if (mouse->console_phone >= 0) {
+		if ((shift_x != 0) || (shift_y != 0)) {
+			/* FIXME: guessed for QEMU */
+			async_req_2_0(mouse->console_phone,
+			    MEVENT_MOVE,
+			    - shift_x / 10,  - shift_y / 10);
+		}
+		if (butt) {
+			/* FIXME: proper button clicking. */
+			async_req_2_0(mouse->console_phone,
+			    MEVENT_BUTTON, 1, 1);
+			async_req_2_0(mouse->console_phone,
+			    MEVENT_BUTTON, 1, 0);
+		}
 	}
 
-	while (true) {
-		async_usleep(mouse->poll_interval_us);
+	usb_log_debug("buttons=%s  dX=%+3d  dY=%+3d  wheel=%+3d\n",
+	    str_buttons, shift_x, shift_y, wheel);
 
-		size_t actual_size;
-		int rc;
+	/* Guess. */
+	async_usleep(1000);
 
-		/*
-		 * Error checking note:
-		 * - failure when starting a session is considered
-		 *   temporary (e.g. out of phones, next try might succeed)
-		 * - failure of transfer considered fatal (probably the
-		 *   device was unplugged)
-		 * - session closing not checked (shall not fail anyway)
-		 */
+	return true;
+}
 
-		rc = usb_endpoint_pipe_start_session(POLL_PIPE(dev));
-		if (rc != EOK) {
-			usb_log_warning("Failed to start session, will try again: %s.\n",
-			    str_error(rc));
-			continue;
-		}
+/** Callback when polling is terminated.
+ *
+ * @param dev Device where the polling terminated.
+ * @param recurring_errors Whether the polling was terminated due to
+ *	recurring errors.
+ * @param arg Custom argument - points to usb_mouse_t.
+ */
+void usb_mouse_polling_ended_callback(usb_device_t *dev,
+    bool recurring_errors, void *arg)
+{
+	usb_mouse_t *mouse = (usb_mouse_t *) arg;
 
-		rc = usb_endpoint_pipe_read(POLL_PIPE(dev),
-		    buffer, buffer_size, &actual_size);
-
-		usb_endpoint_pipe_end_session(POLL_PIPE(dev));
-
-		if (rc != EOK) {
-			usb_log_error("Failed reading mouse input: %s.\n",
-			    str_error(rc));
-			break;
-		}
-
-		usb_log_debug2("got buffer: %s.\n",
-		    usb_debug_str_buffer(buffer, buffer_size, 0));
-
-		uint8_t butt = buffer[0];
-		char str_buttons[4] = {
-			butt & 1 ? '#' : '.',
-			butt & 2 ? '#' : '.',
-			butt & 4 ? '#' : '.',
-			0
-		};
-
-		int shift_x = ((int) buffer[1]) - 127;
-		int shift_y = ((int) buffer[2]) - 127;
-		int wheel = ((int) buffer[3]) - 127;
-
-		if (buffer[1] == 0) {
-			shift_x = 0;
-		}
-		if (buffer[2] == 0) {
-			shift_y = 0;
-		}
-		if (buffer[3] == 0) {
-			wheel = 0;
-		}
-
-		if (mouse->console_phone >= 0) {
-			if ((shift_x != 0) || (shift_y != 0)) {
-				/* FIXME: guessed for QEMU */
-				async_req_2_0(mouse->console_phone,
-				    MEVENT_MOVE,
-				    - shift_x / 10,  - shift_y / 10);
-			}
-			if (butt) {
-				/* FIXME: proper button clicking. */
-				async_req_2_0(mouse->console_phone,
-				    MEVENT_BUTTON, 1, 1);
-				async_req_2_0(mouse->console_phone,
-				    MEVENT_BUTTON, 1, 0);
-			}
-		}
-
-		usb_log_debug("buttons=%s  dX=%+3d  dY=%+3d  wheel=%+3d\n",
-		   str_buttons, shift_x, shift_y, wheel);
-	}
-
-	/*
-	 * Device was probably unplugged.
-	 * Hang-up the phone to the console.
-	 * FIXME: release allocated memory.
-	 */
 	async_hangup(mouse->console_phone);
 	mouse->console_phone = -1;
-
-	usb_log_error("Mouse polling fibril terminated.\n");
-
-	return EOK;
 }
-
 
 /**
