All of lore.kernel.org
 help / color / mirror / Atom feed
From: Inaky Perez-Gonzalez <inaky@linux.intel.com>
To: netdev@vger.kernel.org
Cc: greg@kroah.com, wimax@linuxwimax.org
Subject: [PATCH 25/29] i2400m/SDIO: firmware upload backend
Date: Mon, 15 Dec 2008 04:58:20 -0800	[thread overview]
Message-ID: <f8e1f6d5acbdf6692f1d138139146cfd38705b31.1229345780.git.inaky@linux.intel.com> (raw)
In-Reply-To: <cover.1229345769.git.inaky@linux.intel.com>

This implements the backends for the generic driver (i2400m) to be
able to load firmware to the SDIO device.

Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
---
 drivers/net/wimax/i2400m/sdio-fw.c |  224 ++++++++++++++++++++++++++++++++++++
 1 files changed, 224 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/wimax/i2400m/sdio-fw.c

diff --git a/drivers/net/wimax/i2400m/sdio-fw.c b/drivers/net/wimax/i2400m/sdio-fw.c
new file mode 100644
index 0000000..3487205
--- /dev/null
+++ b/drivers/net/wimax/i2400m/sdio-fw.c
@@ -0,0 +1,224 @@
+/*
+ * Intel Wireless WiMAX Connection 2400m
+ * Firmware uploader's SDIO specifics
+ *
+ *
+ * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *   * Neither the name of Intel Corporation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * Intel Corporation <linux-wimax@intel.com>
+ * Yanir Lubetkin <yanirx.lubetkin@intel.com>
+ * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
+ *  - Initial implementation
+ *
+ * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
+ *  - Bus generic/specific split for USB
+ *
+ * Dirk Brandewie <dirk.j.brandewie@intel.com>
+ *  - Initial implementation for SDIO
+ *
+ * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
+ *  - SDIO rehash for changes in the bus-driver model
+ *
+ * THE PROCEDURE
+ *
+ * See fw.c for the generic description of this procedure.
+ *
+ * This file implements only the SDIO specifics. It boils down to how
+ * to send a command and waiting for an acknowledgement from the
+ * device. We do polled reads.
+ *
+ * COMMAND EXECUTION
+ *
+ * THe generic firmware upload code will call i2400m_bus_bm_cmd_send()
+ * to send commands.
+ *
+ * The SDIO devices expects things in 256 byte blocks, so it will pad
+ * it, compute the checksum (if needed) and pass it to SDIO.
+ *
+ * ACK RECEPTION
+ *
+ * This works in polling mode -- the fw loader says when to wait for
+ * data and for that it calls i2400ms_bus_bm_wait_for_ack().
+ *
+ * This will poll the device for data until it is received. We need to
+ * receive at least as much bytes as where asked for (although it'll
+ * always be a multiple of 256 bytes).
+ */
+#include <linux/mmc/sdio_func.h>
+#include "i2400m-sdio.h"
+
+
+#define D_SUBMODULE fw
+#include "sdio-debug-levels.h"
+
+/*
+ * Send a boot-mode command to the SDIO function
+ *
+ * We use a bounce buffer (i2400m->bm_cmd_buf) because we need to
+ * touch the header if the RAW flag is not set.
+ *
+ * @flags: pass thru from i2400m_bm_cmd()
+ * @return: cmd_size if ok, < 0 errno code on error.
+ *
+ * Note the command is padded to the SDIO block size for the device.
+ */
+ssize_t i2400ms_bus_bm_cmd_send(struct i2400m *i2400m,
+				const struct i2400m_bootrom_header *_cmd,
+				size_t cmd_size, int flags)
+{
+	ssize_t result;
+	struct device *dev = i2400m_dev(i2400m);
+	struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
+	int opcode = _cmd == NULL ? -1 : i2400m_brh_get_opcode(_cmd);
+	struct i2400m_bootrom_header *cmd;
+	/* SDIO restriction */
+	size_t cmd_size_a = ALIGN(cmd_size, I2400MS_BLK_SIZE);
+
+	d_fnstart(5, dev, "(i2400m %p cmd %p size %zu)\n",
+		  i2400m, _cmd, cmd_size);
+	result = -E2BIG;
+	if (cmd_size > I2400M_BM_CMD_BUF_SIZE)
+		goto error_too_big;
+
+	memcpy(i2400m->bm_cmd_buf, _cmd, cmd_size);	/* Prep command */
+	cmd = i2400m->bm_cmd_buf;
+	if (cmd_size_a > cmd_size)			/* Zero pad space */
+		memset(i2400m->bm_cmd_buf + cmd_size, 0, cmd_size_a - cmd_size);
+	if ((flags & I2400M_BM_CMD_RAW) == 0) {
+		if (WARN_ON(i2400m_brh_get_response_required(cmd) == 0))
+			dev_warn(dev, "SW BUG: response_required == 0\n");
+		i2400m_bm_cmd_prepare(cmd);
+	}
+	d_printf(4, dev, "BM cmd %d: %zu bytes (%zu padded)\n",
+		 opcode, cmd_size, cmd_size_a);
+	d_dump(5, dev, cmd, cmd_size);
+
+	sdio_claim_host(i2400ms->func);			/* Send & check */
+	result = sdio_memcpy_toio(i2400ms->func, I2400MS_DATA_ADDR,
+				  i2400m->bm_cmd_buf, cmd_size_a);
+	sdio_release_host(i2400ms->func);
+	if (result < 0) {
+		dev_err(dev, "BM cmd %d: cannot send: %ld\n",
+			opcode, (long) result);
+		goto error_cmd_send;
+	}
+	result = cmd_size;
+error_cmd_send:
+error_too_big:
+	d_fnend(5, dev, "(i2400m %p cmd %p size %zu) = %d\n",
+		i2400m, _cmd, cmd_size, (int) result);
+	return result;
+}
+
+
+/*
+ * Read an ack from the device's boot-mode (polling)
+ *
+ * @i2400m:
+ * @_ack: pointer to where to store the read data
+ * @ack_size: how many bytes we should read
+ *
+ * Returns: < 0 errno code on error; otherwise, amount of received bytes.
+ *
+ * The ACK for a BM command is always at least sizeof(*ack) bytes, so
+ * check for that. We don't need to check for device reboots
+ *
+ * NOTE: We do an artificial timeout of 1 sec over the SDIO timeout;
+ *     this way we have control over it...there is no way that I know
+ *     of setting an SDIO transaction timeout.
+ */
+ssize_t i2400ms_bus_bm_wait_for_ack(struct i2400m *i2400m,
+				    struct i2400m_bootrom_header *ack,
+				    size_t ack_size)
+{
+	int result;
+	ssize_t rx_size;
+	u64 timeout;
+	struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
+	struct sdio_func *func = i2400ms->func;
+	struct device *dev = &func->dev;
+
+	BUG_ON(sizeof(*ack) > ack_size);
+
+	d_fnstart(5, dev, "(i2400m %p ack %p size %zu)\n",
+		  i2400m, ack, ack_size);
+
+	timeout = get_jiffies_64() + 2 * HZ;
+	sdio_claim_host(func);
+	while (1) {
+		if (time_after64(get_jiffies_64(), timeout)) {
+			rx_size = -ETIMEDOUT;
+			dev_err(dev, "timeout waiting for ack data\n");
+			goto error_timedout;
+		}
+
+		/* Find the RX size, check if it fits or not -- it if
+		 * doesn't fit, fail, as we have no way to dispose of
+		 * the extra data. */
+		rx_size = __i2400ms_rx_get_size(i2400ms);
+		if (rx_size < 0)
+			goto error_rx_get_size;
+		result = -ENOSPC;		/* Check it fits */
+		if (rx_size < sizeof(*ack)) {
+			rx_size = -EIO;
+			dev_err(dev, "HW BUG? received is too small (%zu vs "
+				"%zu needed)\n", sizeof(*ack), rx_size);
+			goto error_too_small;
+		}
+		if (rx_size > I2400M_BM_ACK_BUF_SIZE) {
+			dev_err(dev, "SW BUG? BM_ACK_BUF is too small (%u vs "
+				"%zu needed)\n", I2400M_BM_ACK_BUF_SIZE,
+				rx_size);
+			goto error_too_small;
+		}
+
+		/* Read it */
+		result = sdio_memcpy_fromio(func, i2400m->bm_ack_buf,
+					    I2400MS_DATA_ADDR, rx_size);
+		if (result == -ETIMEDOUT || result == -ETIME)
+			continue;
+		if (result < 0) {
+			dev_err(dev, "BM SDIO receive (%zu B) failed: %d\n",
+				rx_size, result);
+			goto error_read;
+		} else
+			break;
+	}
+	rx_size = min((ssize_t)ack_size, rx_size);
+	memcpy(ack, i2400m->bm_ack_buf, rx_size);
+error_read:
+error_too_small:
+error_rx_get_size:
+error_timedout:
+	sdio_release_host(func);
+	d_fnend(5, dev, "(i2400m %p ack %p size %zu) = %ld\n",
+		i2400m, ack, ack_size, (long) rx_size);
+	return rx_size;
+}
-- 
1.5.6.5

  parent reply	other threads:[~2008-12-15 12:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-15 12:57 [PATCH 00/29] merge request for WiMAX kernel stack and i2400m driver v6 Inaky Perez-Gonzalez
2008-12-15 12:57 ` [PATCH 01/29] wimax: documentation for the stack Inaky Perez-Gonzalez
2008-12-15 12:57 ` [PATCH 02/29] wimax: headers for kernel API and user space interaction Inaky Perez-Gonzalez
2008-12-16  3:43   ` Wang Chen
2008-12-17 17:44     ` Inaky Perez-Gonzalez
2008-12-15 12:57 ` [PATCH 03/29] wimax: internal API for the kernel space WiMAX stack Inaky Perez-Gonzalez
2008-12-15 12:57 ` [PATCH 04/29] wimax: debug macros and debug settings for the " Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 05/29] wimax: generic device management (registration, deregistration, lookup) Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 06/29] genetlink: export genl_unregister_mc_group() Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 07/29] wimax: basic API: kernel/user messaging, rfkill and reset Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 08/29] debugfs: add helpers for exporting a size_t simple value Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 09/29] wimax: debugfs controls Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 10/29] wimax: Makefile, Kconfig and docbook linkage for the stack Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 11/29] i2400m: documentation and instructions for usage Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 12/29] i2400m: host/device procotol and core driver definitions Inaky Perez-Gonzalez
2008-12-16  3:43   ` Wang Chen
2008-12-15 12:58 ` [PATCH 13/29] i2400m: Generic probe/disconnect, reset and message passing Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 14/29] i2400m: linkage to the networking stack Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 15/29] i2400m: firmware loading and bootrom initialization Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 16/29] i2400m: RX and TX data/control paths Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 17/29] i2400m: various functions for device management Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 18/29] i2400m: debugfs controls Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 19/29] i2400m/USB: header for the USB bus driver Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 20/29] i2400m/USB: probe/disconnect, dev init/shutdown and reset backends Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 21/29] i2400m/USB: firmware upload backend Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 22/29] i2400m/USB: TX and RX path backends Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 23/29] i2400m/SDIO: header for the SDIO subdriver Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 24/29] i2400m/SDIO: probe/disconnect, dev init/shutdown and reset backends Inaky Perez-Gonzalez
2008-12-15 12:58 ` Inaky Perez-Gonzalez [this message]
2008-12-15 12:58 ` [PATCH 26/29] i2400m/SDIO: TX and RX path backends Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 27/29] i2400m: Makefile and Kconfig Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 28/29] wimax: export linux/wimax.h and linux/wimax/i2400m.h with headers_install Inaky Perez-Gonzalez
2008-12-15 12:58 ` [PATCH 29/29] wimax/i2400m: add CREDITS and MAINTAINERS entries Inaky Perez-Gonzalez
2008-12-15 22:54 ` [PATCH 00/29] merge request for WiMAX kernel stack and i2400m driver v6 David Miller
2008-12-17 17:37   ` Inaky Perez-Gonzalez
  -- strict thread matches above, loose matches on Subject: below --
2008-12-21  0:57 [PATCH 00/29] merge request for WiMAX kernel stack and i2400m driver v7 Inaky Perez-Gonzalez
2008-12-21  0:57 ` [PATCH 25/29] i2400m/SDIO: firmware upload backend Inaky Perez-Gonzalez
2008-12-10 23:12 [PATCH 00/29] merge request for WiMAX kernel stack and i2400m driver v4 Inaky Perez-Gonzalez
2008-12-10 23:13 ` [PATCH 25/29] i2400m/SDIO: firmware upload backend Inaky Perez-Gonzalez
2008-12-08 19:09 [PATCH 00/29] merge request for WiMAX kernel stack and i2400m driver v3 Inaky Perez-Gonzalez
2008-12-08 19:09 ` [PATCH 25/29] i2400m/SDIO: firmware upload backend Inaky Perez-Gonzalez

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=f8e1f6d5acbdf6692f1d138139146cfd38705b31.1229345780.git.inaky@linux.intel.com \
    --to=inaky@linux.intel.com \
    --cc=greg@kroah.com \
    --cc=netdev@vger.kernel.org \
    --cc=wimax@linuxwimax.org \
    /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.