* [PATCH 3/7] can: mcp251x: allow to read two registers in one spi transfer
From: Marc Kleine-Budde @ 2010-10-15 10:49 UTC (permalink / raw)
To: socketcan-core-0fE9KPoRgkgATYTw5x5z8w
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, Marc Kleine-Budde,
Uwe Kleine-König
In-Reply-To: <1287139762-23356-1-git-send-email-mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
From: Sascha Hauer <s.hauer@pengutronix.de>
This patch bases on work done earlier by David Jander.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: David Jander <david@protonic.nl>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/mcp251x.c | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index fdea752..9b3466a 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -319,6 +319,20 @@ static u8 mcp251x_read_reg(struct spi_device *spi, uint8_t reg)
return val;
}
+static void mcp251x_read_2regs(struct spi_device *spi, uint8_t reg,
+ uint8_t *v1, uint8_t *v2)
+{
+ struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev);
+
+ priv->spi_tx_buf[0] = INSTRUCTION_READ;
+ priv->spi_tx_buf[1] = reg;
+
+ mcp251x_spi_trans(spi, 4);
+
+ *v1 = priv->spi_rx_buf[2];
+ *v2 = priv->spi_rx_buf[3];
+}
+
static void mcp251x_write_reg(struct spi_device *spi, u8 reg, uint8_t val)
{
struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev);
@@ -754,10 +768,11 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
mutex_lock(&priv->mcp_lock);
while (!priv->force_quit) {
enum can_state new_state;
- u8 intf = mcp251x_read_reg(spi, CANINTF);
- u8 eflag;
+ u8 intf, eflag;
int can_id = 0, data1 = 0;
+ mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
+
if (intf & CANINTF_RX0IF) {
mcp251x_hw_rx(spi, 0);
/* Free one buffer ASAP */
@@ -770,7 +785,6 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
mcp251x_write_bits(spi, CANINTF, intf, 0x00);
- eflag = mcp251x_read_reg(spi, EFLG);
mcp251x_write_reg(spi, EFLG, 0x00);
/* Update can state */
--
1.7.0.4
_______________________________________________
Socketcan-core mailing list
Socketcan-core@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/socketcan-core
^ permalink raw reply related
* [PATCH 4/7] can: mcp251x: read-modify-write eflag only when needed
From: Marc Kleine-Budde @ 2010-10-15 10:49 UTC (permalink / raw)
To: socketcan-core-0fE9KPoRgkgATYTw5x5z8w
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, Marc Kleine-Budde
In-Reply-To: <1287139762-23356-1-git-send-email-mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
From: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Use read-modify-write instead of a simple write to change the register
contents, to close existing the race window between the original manual
read and write.
Signed-off-by: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Signed-off-by: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
drivers/net/can/mcp251x.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 9b3466a..7e2f951 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -785,7 +785,8 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
mcp251x_write_bits(spi, CANINTF, intf, 0x00);
- mcp251x_write_reg(spi, EFLG, 0x00);
+ if (eflag)
+ mcp251x_write_bits(spi, EFLG, eflag, 0x00);
/* Update can state */
if (eflag & EFLG_TXBO) {
--
1.7.0.4
^ permalink raw reply related
* [PATCH 6/7] can: mcp251x: define helper functions mcp251x_is_2510, mcp251x_is_2515
From: Marc Kleine-Budde @ 2010-10-15 10:49 UTC (permalink / raw)
To: socketcan-core-0fE9KPoRgkgATYTw5x5z8w
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, Marc Kleine-Budde
In-Reply-To: <1287139762-23356-1-git-send-email-mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Signed-off-by: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
drivers/net/can/mcp251x.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index f5e2edd..28281f9 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -252,6 +252,16 @@ struct mcp251x_priv {
int restart_tx;
};
+#define MCP251X_IS(_model) \
+static inline int mcp251x_is_##_model(struct spi_device *spi) \
+{ \
+ struct mcp251x_platform_data *pdata = spi->dev.platform_data; \
+ return pdata->model == CAN_MCP251X_MCP##_model; \
+}
+
+MCP251X_IS(2510);
+MCP251X_IS(2515);
+
static void mcp251x_clean(struct net_device *net)
{
struct mcp251x_priv *priv = netdev_priv(net);
@@ -362,10 +372,9 @@ static void mcp251x_write_bits(struct spi_device *spi, u8 reg,
static void mcp251x_hw_tx_frame(struct spi_device *spi, u8 *buf,
int len, int tx_buf_idx)
{
- struct mcp251x_platform_data *pdata = spi->dev.platform_data;
struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev);
- if (pdata->model == CAN_MCP251X_MCP2510) {
+ if (mcp251x_is_2510(spi)) {
int i;
for (i = 1; i < TXBDAT_OFF + len; i++)
@@ -408,9 +417,8 @@ static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf,
int buf_idx)
{
struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev);
- struct mcp251x_platform_data *pdata = spi->dev.platform_data;
- if (pdata->model == CAN_MCP251X_MCP2510) {
+ if (mcp251x_is_2510(spi)) {
int i, len;
for (i = 1; i < RXBDAT_OFF; i++)
--
1.7.0.4
^ permalink raw reply related
* [PATCH 7/7] can: mcp251x: optimize 2515, rx int gets cleared automatically
From: Marc Kleine-Budde @ 2010-10-15 10:49 UTC (permalink / raw)
To: socketcan-core; +Cc: netdev, Marc Kleine-Budde
In-Reply-To: <1287139762-23356-1-git-send-email-mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/mcp251x.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 28281f9..a42c3fa 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -787,15 +787,20 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
/* receive buffer 0 */
if (intf & CANINTF_RX0IF) {
mcp251x_hw_rx(spi, 0);
- /* Free one buffer ASAP */
- mcp251x_write_bits(spi, CANINTF, intf & CANINTF_RX0IF,
- 0x00);
+ /*
+ * Free one buffer ASAP
+ * (The MCP2515 does this automatically.)
+ */
+ if (mcp251x_is_2510(spi))
+ mcp251x_write_bits(spi, CANINTF, CANINTF_RX0IF, 0x00);
}
/* receive buffer 1 */
if (intf & CANINTF_RX1IF) {
mcp251x_hw_rx(spi, 1);
- clear_intf |= CANINTF_RX1IF;
+ /* the MCP2515 does this automatically */
+ if (mcp251x_is_2510(spi))
+ clear_intf |= CANINTF_RX1IF;
}
/* any error or tx interrupt we need to clear? */
--
1.7.0.4
^ permalink raw reply related
* [PATCH 5/7] can: mcp251x: write intf only when needed
From: Marc Kleine-Budde @ 2010-10-15 10:49 UTC (permalink / raw)
To: socketcan-core; +Cc: netdev, Marc Kleine-Budde
In-Reply-To: <1287139762-23356-1-git-send-email-mkl@pengutronix.de>
This patch introduces a variable "clear_intf" that hold the bits that
should be cleared. Only read-modify-write register if "clear_intf"
is set.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/mcp251x.c | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 7e2f951..f5e2edd 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -125,6 +125,8 @@
# define CANINTF_TX0IF 0x04
# define CANINTF_RX1IF 0x02
# define CANINTF_RX0IF 0x01
+# define CANINTF_ERR_TX \
+ (CANINTF_ERRIF | CANINTF_TX2IF | CANINTF_TX1IF | CANINTF_TX0IF)
#define EFLG 0x2d
# define EFLG_EWARN 0x01
# define EFLG_RXWAR 0x02
@@ -769,10 +771,12 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
while (!priv->force_quit) {
enum can_state new_state;
u8 intf, eflag;
+ u8 clear_intf = 0;
int can_id = 0, data1 = 0;
mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
+ /* receive buffer 0 */
if (intf & CANINTF_RX0IF) {
mcp251x_hw_rx(spi, 0);
/* Free one buffer ASAP */
@@ -780,10 +784,17 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
0x00);
}
- if (intf & CANINTF_RX1IF)
+ /* receive buffer 1 */
+ if (intf & CANINTF_RX1IF) {
mcp251x_hw_rx(spi, 1);
+ clear_intf |= CANINTF_RX1IF;
+ }
- mcp251x_write_bits(spi, CANINTF, intf, 0x00);
+ /* any error or tx interrupt we need to clear? */
+ if (intf & CANINTF_ERR_TX)
+ clear_intf |= intf & CANINTF_ERR_TX;
+ if (clear_intf)
+ mcp251x_write_bits(spi, CANINTF, clear_intf, 0x00);
if (eflag)
mcp251x_write_bits(spi, EFLG, eflag, 0x00);
--
1.7.0.4
^ permalink raw reply related
* Re: [PATCH net-next 3/5] tipc: Optimizations to bearer enabling logic
From: Neil Horman @ 2010-10-15 11:00 UTC (permalink / raw)
To: Paul Gortmaker; +Cc: davem, netdev, allan.stephens
In-Reply-To: <20101015011139.GB5048@windriver.com>
On Thu, Oct 14, 2010 at 09:11:51PM -0400, Paul Gortmaker wrote:
> [Re: [PATCH net-next 3/5] tipc: Optimizations to bearer enabling logic] On 13/10/2010 (Wed 10:58) Neil Horman wrote:
>
> > On Tue, Oct 12, 2010 at 08:25:56PM -0400, Paul Gortmaker wrote:
> > > From: Allan Stephens <allan.stephens@windriver.com>
> > >
> > > Introduces "enabling" state during activation of a new TIPC bearer,
> > > which supplements the existing "disabled" and "enabled" states.
> > > This change allows the new bearer to be added without having to
> > > temporarily block the processing of incoming packets on existing
> > > bearers during the binding of the new bearer to its associated
> > > interface. It also makes it unnecessary to zero out the entire
> > > bearer structure at the start of activation.
> > >
>
> [...]
>
> > > + b_ptr->state = BEARER_ENABLING;
> > > strcpy(b_ptr->publ.name, name);
> > > + b_ptr->priority = priority;
> > > +
> > > + write_unlock_bh(&tipc_net_lock);
> > Why the 3rd state? Doesn't seem needed.
>
> I'm a bit disappointed in myself for also not noticing that it
> was set but never tested for. The following should give the
> same end result but without the obfuscation of an extra state.
>
> This one also doesn't explicitly depend on any other changes,
> so if it is now OK, the option is there for it to be applied
> independently of the others that haven't been reworked yet.
>
> Thanks,
> Paul.
>
>
> From 86d0d5c92439d0a3f5a0f165aa8bd842d377dae9 Mon Sep 17 00:00:00 2001
> From: Allan Stephens <allan.stephens@windriver.com>
> Date: Thu, 14 Oct 2010 16:09:23 -0400
> Subject: [PATCH] tipc: Optimizations to bearer enabling logic
>
> Allow new bearers to be added without having to temporarily block
> the processing of incoming packets on existing bearers during the
> binding of the new bearer to its associated interface. Eliminates
> zeroing out of the new bearer structure at the start of activation,
> since it is already in that state.
>
> Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
> ---
> net/tipc/bearer.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
> index fd9c06c..2ff8181 100644
> --- a/net/tipc/bearer.c
> +++ b/net/tipc/bearer.c
> @@ -556,14 +556,15 @@ restart:
> }
>
> b_ptr = &tipc_bearers[bearer_id];
> - memset(b_ptr, 0, sizeof(struct bearer));
> -
> strcpy(b_ptr->publ.name, name);
> +
> + write_unlock_bh(&tipc_net_lock);
> res = m_ptr->enable_bearer(&b_ptr->publ);
> if (res) {
> warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
> - goto failed;
> + return res;
> }
> + write_lock_bh(&tipc_net_lock);
>
This definately looks more concise, but I don't see why its necessecary to drop
the tipc_net_lock around the call to enable_bearer. The only caler of
tipc_register_media sets the enable_bearer pointer to the enable_bearer
function, and I' don't see any path through that function which would
potentially retake that lock. In fact it seems dropping it might be dangerous,
if other paths (like from cfg_named_msg_event), tried to enable a bearer in
parallel with a user space directive from the netlink socket). With out the
protection of tipc_net_lock, you could use the same eth_bearer twice, and
corrupt that array.
Neil
> b_ptr->identity = bearer_id;
> b_ptr->media = m_ptr;
> --
> 1.7.2.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply
* Re: [PATCH net-next] tipc: cleanup function namespace
From: Neil Horman @ 2010-10-15 11:01 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Paul Gortmaker, David Miller, netdev, allan.stephens, Jon Maloy
In-Reply-To: <20101014151333.1446a90c@nehalam>
On Thu, Oct 14, 2010 at 03:13:33PM -0700, Stephen Hemminger wrote:
> On Thu, 14 Oct 2010 17:44:27 -0400
> Paul Gortmaker <paul.gortmaker@windriver.com> wrote:
>
> > [Re: [PATCH net-next] tipc: cleanup function namespace] On 14/10/2010 (Thu 11:33) Stephen Hemminger wrote:
> >
> > > On Thu, 14 Oct 2010 13:53:21 -0400
> > > Paul Gortmaker <paul.gortmaker@windriver.com> wrote:
> > >
> > > > On 10-10-13 09:29 PM, Neil Horman wrote:
> > > > > On Wed, Oct 13, 2010 at 08:23:24PM -0400, Paul Gortmaker wrote:
> > > > >> On 10-10-13 07:20 PM, Stephen Hemminger wrote:
> > > > >>> Do some cleanups of TIPC based on make namespacecheck
> > > > >>> 1. Don't export unused symbols
> > > > >>> 2. Eliminate dead code
> > > > >>> 3. Make functions and variables local
> > > > >>> 4. Rename buf_acquire to tipc_buf_acquire since it is used in several files
> > > > >>>
> > > > >>> Compile tested only.
> > > > >>> This make break out of tree kernel modules that depend on TIPC routines.
> > > > >>
> > > > >> Hi Stephen,
> > > > >>
> > > > >> When I first started looking at TIPC code, I too came to the
> > > > >> same conclusion as you did and was about to do #1,2,3 -- but
> > > > >> then I was told that the exported symbols were part of an API
> > > > >> and might be in use by folks here and there as per this thread:
> > > > >>
> > > > >> http://www.mail-archive.com/netdev@vger.kernel.org/msg30208.html
> > > > >>
> > > > > I think its telling the the argument in the above thread for keeping the API
> > > > > were that users of it were out there and 'likely to contribute' in the future.
> > > > > That thread was 3 years ago. They might be using the API from outside the
> > > > > kernel tree, but they're not planning on contributing. As Christoph noted,
> > > > > they're freeloaders. The community really doesn't need or want to maintain an
> > > > > API like that. If these users are your customers, and removing the API is
> > > > > unacceptable, perhaps its time to move the entire TIPC module out of tree.
> > > >
> > > > As I'd said -- I don't know what the use cases of these API users are,
> > > > and so as far as I know they aren't customers either. For what it is
> > > > worth, know that I personally wouldn't try and use a business case to
> > > > justify a technically wrong decision here on netdev anyway.
> > > >
> > > > I was just describing the history of the situation, and suggesting
> > > > one possible slower approach of phasing it out as a courtesy to those
> > > > users, in the same way that the kernel community has extended that
> > > > same courtesy with other things in feature-removal.txt
> > > >
> > > > In the end, since Jon is OK with the removal, and is in the process of
> > > > communicating this to the API users he is aware of, I sure don't have
> > > > any reason to try and save the API. If folks are good with having it
> > > > just go away overnight, then great -- I'll be just as happy to see it
> > > > disappear as you and Stephen. So, a long winded way of saying...
> > > >
> > > > Acked-by: Paul Gortmaker <paul.gortmaker@windriver.com>
> > >
> > > How about putting an entry in feature-removal.txt with a short (6 month)
> > > window?
> >
> > I'm fine with that too.
> >
> > P.
> >
> > From 5a15a26de63a29fcb6cb7a7fb83b6d2fc63cbadb Mon Sep 17 00:00:00 2001
> > From: Paul Gortmaker <paul.gortmaker@windriver.com>
> > Date: Thu, 14 Oct 2010 17:29:08 -0400
> > Subject: [PATCH] TIPC: Document the demise of the Native API for March 2011
> >
> > The native API in the TIPC code exists as a bunch of functions
> > and exported symbols that aren't actually used by any currently
> > in-tree kernel code/modules.
> >
> > Since this code is anomalous to the general guiding principle that
> > the kernel should not be libc, coverage tools and people intending
> > to do general cleanups keep finding this code and suggesting that
> > it be removed.
> >
> > It seems the right thing to do is to just finally delete it once
> > and for all, after giving a reasonable window for any existing
> > users to find alternative solutions to their custom use case(s).
> >
> > Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
> > ---
> > Documentation/feature-removal-schedule.txt | 12 ++++++++++++
> > 1 files changed, 12 insertions(+), 0 deletions(-)
> >
> > diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
> > index f456389..1def37e 100644
> > --- a/Documentation/feature-removal-schedule.txt
> > +++ b/Documentation/feature-removal-schedule.txt
> > @@ -573,3 +573,15 @@ Why: Hareware scan is the prefer method for iwlwifi devices for
> > Who: Wey-Yi Guy <wey-yi.w.guy@intel.com>
> >
> > ----------------------------
> > +
> > +What: TIPC: Delete all code and exported symbols specific to Native API
> > +When: March 2011
> > +Why: The TIPC Native API, as described here:
> > + http://tipc.sourceforge.net/doc/tipc_1.7_prog_guide.html#native_api
> > + is implemented by exporting a bunch of otherwise unused functions
> > + for possible modular linkage by custom end-user code. This goes
> > + against the general concept that the kernel should not be libc.
> > +
> > +Who: Paul Gortmaker <paul.gortmaker@windriver.com>
> > +
> > +----------------------------
>
> Acked-by: Stephen Hemminger <shemminger@vyatta.com>
>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply
* openvswitch/flow WAS ( Re: [rfc] Merging the Open vSwitch datapath
From: jamal @ 2010-10-15 11:31 UTC (permalink / raw)
To: Ben Pfaff, Jesse Gross; +Cc: netdev
In-Reply-To: <87k4n8ow1r.fsf@benpfaff.org>
Sorry, slightly off topic - and this old (catching up
with netdev randomly going backwards)..
I was curious after seeing the exchange with Eric D. on
the tunnels and how you have your own tree so i glossed
over what your project is doing.
It seems to me that you reinvented things that exist in
Linux already such as bridging, tunnels and what really
caught my attention: ability to do flows (tc actions).
It is possible Linux is missing something you wanted or was
not efficient enough?
[For example: I couldnt see anything you needed
on flow-action management that Linux couldnt do already
(with already very nice well structured netlink APIs)]
cheers,
jamal
^ permalink raw reply
* Re: Couple tc filter questions.
From: Jarek Poplawski @ 2010-10-15 11:44 UTC (permalink / raw)
To: Jonathan Thibault; +Cc: netdev
In-Reply-To: <4CB792E0.5030704@navigue.com>
On 2010-10-15 01:31, Jonathan Thibault wrote:
> Since the lartc mailing list appears to be dead, I'll ask here and hope not to offend anyone.
>
> 1- This page:
> http://lartc.org/howto/lartc.qdisc.filters.html
> States: "Also, with HTB, you should attach all filters to the root!"
>
> Why? Is it still true? My setup would be a lot easier with cascading filters. If it's just a matter of there not being any efficiency gains from cascading filters, that's fine. If there is a risk of things exploding randomly and without notice, I'd be keen to know. Testing shows that cascading works okay, but I haven't tried under any serious load.
It's not true.
>
> 2- Are filter flowid (classify) actions terminating? Meaning if two consecutive filters would match the same packet, only the first match would ever apply and no further filter is evaluated? Are there actions for which this isn't the case? Intuitively and experimentally, I'd answer no but if anyone knowledgeable in the matter would care to expand on that topic I'd be grateful. Especially considering cascading classes/filters.
>
> Another area where termination isn't entirely clear is when using mirred and ifb devices. I might want to send a copy of all my traffic to an ifb device, but then I would still want subsequent filters to match in the current qdisc. In such a case, a filter that matches all traffic with a mirred action should probably not be terminating.
>
> Maybe I'm thinking too much in terms of iptables here :P
Could you try doc/actions from iproute2 sources? Generally, anything
reasonable, not forbidden and working in tests is allowed. If still
problems please CC Jamal, the maintainer of tc classifiers (according
to linux MAINTAINERS).
Jarek P.
^ permalink raw reply
* [PATCH 1/6] r8169: check dma mapping failures
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
Check possible dma mapping errors and do clean up if it happens,
when sending frames stop the tx queue.
Fix overwrap bug in rtl8169_tx_clear on the way.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
All patches in series was tested on RTL8111/8168B
drivers/net/r8169.c | 69 ++++++++++++++++++++++++++++++++++-----------------
1 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index bc669a4..a6c4f90 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -4018,20 +4018,25 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
skb = __netdev_alloc_skb(dev, rx_buf_sz + pad, gfp);
if (!skb)
- goto err_out;
+ goto err_out_0;
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
mapping = dma_map_single(&pdev->dev, skb->data, rx_buf_sz,
PCI_DMA_FROMDEVICE);
+ if (dma_mapping_error(&pdev->dev, mapping))
+ goto err_free_skb_1;
rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
-out:
+
return skb;
-err_out:
+err_free_skb_1:
+ dev_kfree_skb(skb);
+
+err_out_0:
rtl8169_make_unusable_by_asic(desc);
- goto out;
+ return NULL;
}
static void rtl8169_rx_clear(struct rtl8169_private *tp)
@@ -4115,12 +4120,12 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
tx_skb->len = 0;
}
-static void rtl8169_tx_clear(struct rtl8169_private *tp)
+static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, int n)
{
- unsigned int i;
+ int i;
- for (i = tp->dirty_tx; i < tp->dirty_tx + NUM_TX_DESC; i++) {
- unsigned int entry = i % NUM_TX_DESC;
+ for (i = 0; i < n; i++) {
+ unsigned int entry = (start + i) % NUM_TX_DESC;
struct ring_info *tx_skb = tp->tx_skb + entry;
unsigned int len = tx_skb->len;
@@ -4136,6 +4141,11 @@ static void rtl8169_tx_clear(struct rtl8169_private *tp)
tp->dev->stats.tx_dropped++;
}
}
+}
+
+static void rtl8169_tx_clear(struct rtl8169_private *tp)
+{
+ rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC);
tp->cur_tx = tp->dirty_tx = 0;
}
@@ -4254,6 +4264,8 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
addr = ((void *) page_address(frag->page)) + frag->page_offset;
mapping = dma_map_single(&tp->pci_dev->dev, addr, len,
PCI_DMA_TODEVICE);
+ if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
+ goto err_out;
/* anti gcc 2.95.3 bugware (sic) */
status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
@@ -4270,6 +4282,10 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
}
return cur_frag;
+
+err_out:
+ rtl8169_tx_clear_range(tp, tp->cur_tx, cur_frag);
+ return -EIO;
}
static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev)
@@ -4296,40 +4312,44 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
struct net_device *dev)
{
struct rtl8169_private *tp = netdev_priv(dev);
- unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC;
+ unsigned int entry = tp->cur_tx % NUM_TX_DESC;
struct TxDesc *txd = tp->TxDescArray + entry;
void __iomem *ioaddr = tp->mmio_addr;
dma_addr_t mapping;
u32 status, len;
u32 opts1;
+ int frags;
if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
- goto err_stop;
+ goto err_stop_0;
}
if (unlikely(le32_to_cpu(txd->opts1) & DescOwn))
- goto err_stop;
+ goto err_stop_0;
+
+ len = skb_headlen(skb);
+ mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
+ PCI_DMA_TODEVICE);
+ if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
+ goto err_stop_0;
+
+ tp->tx_skb[entry].len = len;
+ txd->addr = cpu_to_le64(mapping);
+ txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
opts1 = DescOwn | rtl8169_tso_csum(skb, dev);
frags = rtl8169_xmit_frags(tp, skb, opts1);
- if (frags) {
- len = skb_headlen(skb);
+ if (frags < 0)
+ goto err_dma_1;
+ else if (frags)
opts1 |= FirstFrag;
- } else {
- len = skb->len;
+ else {
opts1 |= FirstFrag | LastFrag;
tp->tx_skb[entry].skb = skb;
}
- mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
- PCI_DMA_TODEVICE);
-
- tp->tx_skb[entry].len = len;
- txd->addr = cpu_to_le64(mapping);
- txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
-
wmb();
/* anti gcc 2.95.3 bugware (sic) */
@@ -4351,7 +4371,10 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
return NETDEV_TX_OK;
-err_stop:
+err_dma_1:
+ rtl8169_unmap_tx_skb(tp->pci_dev, tp->tx_skb + entry, txd);
+
+err_stop_0:
netif_stop_queue(dev);
dev->stats.tx_dropped++;
return NETDEV_TX_BUSY;
--
1.7.1
^ permalink raw reply related
* [PATCH 2/6] r8169: reduce number of functions arguments
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
In-Reply-To: <1287144922-3297-1-git-send-email-sgruszka@redhat.com>
We don't need to pass arguments on stack since we have them in per
device private structure.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/net/r8169.c | 30 ++++++++++++------------------
1 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index a6c4f90..86be06c 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -4005,29 +4005,26 @@ static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
rtl8169_mark_to_asic(desc, rx_buf_sz);
}
-static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
- struct net_device *dev,
- struct RxDesc *desc, int rx_buf_sz,
- unsigned int align, gfp_t gfp)
+static struct sk_buff *rtl8169_alloc_rx_skb(struct rtl8169_private *tp,
+ struct RxDesc *desc, gfp_t gfp)
{
struct sk_buff *skb;
dma_addr_t mapping;
- unsigned int pad;
+ unsigned int align = tp->align;
+ unsigned int pad = align ? align : NET_IP_ALIGN;
- pad = align ? align : NET_IP_ALIGN;
-
- skb = __netdev_alloc_skb(dev, rx_buf_sz + pad, gfp);
+ skb = __netdev_alloc_skb(tp->dev, tp->rx_buf_sz + pad, gfp);
if (!skb)
goto err_out_0;
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
- mapping = dma_map_single(&pdev->dev, skb->data, rx_buf_sz,
+ mapping = dma_map_single(&tp->pci_dev->dev, skb->data, tp->rx_buf_sz,
PCI_DMA_FROMDEVICE);
- if (dma_mapping_error(&pdev->dev, mapping))
+ if (dma_mapping_error(&tp->pci_dev->dev, mapping))
goto err_free_skb_1;
- rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
+ rtl8169_map_to_asic(desc, mapping, tp->rx_buf_sz);
return skb;
@@ -4051,8 +4048,7 @@ static void rtl8169_rx_clear(struct rtl8169_private *tp)
}
}
-static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
- u32 start, u32 end, gfp_t gfp)
+static u32 rtl8169_rx_fill(struct rtl8169_private *tp, u32 start, u32 end, gfp_t gfp)
{
u32 cur;
@@ -4065,9 +4061,7 @@ static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
if (tp->Rx_skbuff[i])
continue;
- skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev,
- tp->RxDescArray + i,
- tp->rx_buf_sz, tp->align, gfp);
+ skb = rtl8169_alloc_rx_skb(tp, tp->RxDescArray + i, gfp);
if (!skb)
break;
@@ -4095,7 +4089,7 @@ static int rtl8169_init_ring(struct net_device *dev)
memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *));
- if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC, GFP_KERNEL) != NUM_RX_DESC)
+ if (rtl8169_rx_fill(tp, 0, NUM_RX_DESC, GFP_KERNEL) != NUM_RX_DESC)
goto err_out;
rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
@@ -4615,7 +4609,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
count = cur_rx - tp->cur_rx;
tp->cur_rx = cur_rx;
- delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx, GFP_ATOMIC);
+ delta = rtl8169_rx_fill(tp, tp->dirty_rx, tp->cur_rx, GFP_ATOMIC);
if (!delta && count)
netif_info(tp, intr, dev, "no Rx buffer allocated\n");
tp->dirty_rx += delta;
--
1.7.1
^ permalink raw reply related
* [PATCH 3/6] r8169: replace PCI_DMA_{TO,FROM}DEVICE to DMA_{TO,FROM}_DEVICE
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
In-Reply-To: <1287144922-3297-1-git-send-email-sgruszka@redhat.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/net/r8169.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 86be06c..1eafe9b 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -3984,7 +3984,7 @@ static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
struct pci_dev *pdev = tp->pci_dev;
dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
- PCI_DMA_FROMDEVICE);
+ DMA_FROM_DEVICE);
dev_kfree_skb(*sk_buff);
*sk_buff = NULL;
rtl8169_make_unusable_by_asic(desc);
@@ -4020,7 +4020,7 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct rtl8169_private *tp,
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
mapping = dma_map_single(&tp->pci_dev->dev, skb->data, tp->rx_buf_sz,
- PCI_DMA_FROMDEVICE);
+ DMA_FROM_DEVICE);
if (dma_mapping_error(&tp->pci_dev->dev, mapping))
goto err_free_skb_1;
@@ -4107,7 +4107,7 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
unsigned int len = tx_skb->len;
dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), len,
- PCI_DMA_TODEVICE);
+ DMA_TO_DEVICE);
desc->opts1 = 0x00;
desc->opts2 = 0x00;
desc->addr = 0x00;
@@ -4257,7 +4257,7 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
len = frag->size;
addr = ((void *) page_address(frag->page)) + frag->page_offset;
mapping = dma_map_single(&tp->pci_dev->dev, addr, len,
- PCI_DMA_TODEVICE);
+ DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
goto err_out;
@@ -4324,7 +4324,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
len = skb_headlen(skb);
mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
- PCI_DMA_TODEVICE);
+ DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
goto err_stop_0;
@@ -4505,7 +4505,7 @@ static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
goto out;
dma_sync_single_for_cpu(&tp->pci_dev->dev, addr, pkt_size,
- PCI_DMA_FROMDEVICE);
+ DMA_FROM_DEVICE);
skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
*sk_buff = skb;
done = true;
@@ -4575,11 +4575,11 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
dma_sync_single_for_device(&pdev->dev, addr,
- pkt_size, PCI_DMA_FROMDEVICE);
+ pkt_size, DMA_FROM_DEVICE);
rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
} else {
dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz,
- PCI_DMA_FROMDEVICE);
+ DMA_FROM_DEVICE);
tp->Rx_skbuff[entry] = NULL;
}
--
1.7.1
^ permalink raw reply related
* [PATCH 4/6] r8169: introduce some more local variables
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
In-Reply-To: <1287144922-3297-1-git-send-email-sgruszka@redhat.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/net/r8169.c | 50 ++++++++++++++++++++++++++------------------------
1 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 1eafe9b..f79ddb2 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -3981,9 +3981,9 @@ static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
struct sk_buff **sk_buff, struct RxDesc *desc)
{
- struct pci_dev *pdev = tp->pci_dev;
+ struct device *d = &tp->pci_dev->dev;
- dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
+ dma_unmap_single(d, le64_to_cpu(desc->addr), tp->rx_buf_sz,
DMA_FROM_DEVICE);
dev_kfree_skb(*sk_buff);
*sk_buff = NULL;
@@ -4010,21 +4010,22 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct rtl8169_private *tp,
{
struct sk_buff *skb;
dma_addr_t mapping;
+ struct device *d = &tp->pci_dev->dev;
+ unsigned int rx_buf_sz = tp->rx_buf_sz;
unsigned int align = tp->align;
unsigned int pad = align ? align : NET_IP_ALIGN;
- skb = __netdev_alloc_skb(tp->dev, tp->rx_buf_sz + pad, gfp);
+ skb = __netdev_alloc_skb(tp->dev, rx_buf_sz + pad, gfp);
if (!skb)
goto err_out_0;
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
- mapping = dma_map_single(&tp->pci_dev->dev, skb->data, tp->rx_buf_sz,
- DMA_FROM_DEVICE);
- if (dma_mapping_error(&tp->pci_dev->dev, mapping))
+ mapping = dma_map_single(d, skb->data, rx_buf_sz, DMA_FROM_DEVICE);
+ if (dma_mapping_error(d, mapping))
goto err_free_skb_1;
- rtl8169_map_to_asic(desc, mapping, tp->rx_buf_sz);
+ rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
return skb;
@@ -4101,13 +4102,13 @@ err_out:
return -ENOMEM;
}
-static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
+static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb,
struct TxDesc *desc)
{
unsigned int len = tx_skb->len;
- dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), len,
- DMA_TO_DEVICE);
+ dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE);
+
desc->opts1 = 0x00;
desc->opts2 = 0x00;
desc->addr = 0x00;
@@ -4117,6 +4118,7 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, int n)
{
int i;
+ struct device *d = &tp->pci_dev->dev;
for (i = 0; i < n; i++) {
unsigned int entry = (start + i) % NUM_TX_DESC;
@@ -4126,8 +4128,7 @@ static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, int n)
if (len) {
struct sk_buff *skb = tx_skb->skb;
- rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb,
- tp->TxDescArray + entry);
+ rtl8169_unmap_tx_skb(d, tx_skb, tp->TxDescArray + entry);
if (skb) {
dev_kfree_skb(skb);
tx_skb->skb = NULL;
@@ -4243,6 +4244,7 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
struct skb_shared_info *info = skb_shinfo(skb);
unsigned int cur_frag, entry;
struct TxDesc * uninitialized_var(txd);
+ struct device *d = &tp->pci_dev->dev;
entry = tp->cur_tx;
for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
@@ -4256,9 +4258,8 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
txd = tp->TxDescArray + entry;
len = frag->size;
addr = ((void *) page_address(frag->page)) + frag->page_offset;
- mapping = dma_map_single(&tp->pci_dev->dev, addr, len,
- DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
+ mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(d, mapping)))
goto err_out;
/* anti gcc 2.95.3 bugware (sic) */
@@ -4309,6 +4310,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
unsigned int entry = tp->cur_tx % NUM_TX_DESC;
struct TxDesc *txd = tp->TxDescArray + entry;
void __iomem *ioaddr = tp->mmio_addr;
+ struct device *d = &tp->pci_dev->dev;
dma_addr_t mapping;
u32 status, len;
u32 opts1;
@@ -4323,9 +4325,8 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
goto err_stop_0;
len = skb_headlen(skb);
- mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
- DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(&tp->pci_dev->dev, mapping)))
+ mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(d, mapping)))
goto err_stop_0;
tp->tx_skb[entry].len = len;
@@ -4366,7 +4367,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
return NETDEV_TX_OK;
err_dma_1:
- rtl8169_unmap_tx_skb(tp->pci_dev, tp->tx_skb + entry, txd);
+ rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd);
err_stop_0:
netif_stop_queue(dev);
@@ -4444,7 +4445,8 @@ static void rtl8169_tx_interrupt(struct net_device *dev,
dev->stats.tx_bytes += len;
dev->stats.tx_packets++;
- rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, tp->TxDescArray + entry);
+ rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
+ tp->TxDescArray + entry);
if (status & LastFrag) {
dev_kfree_skb(tx_skb->skb);
@@ -4559,7 +4561,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
struct sk_buff *skb = tp->Rx_skbuff[entry];
dma_addr_t addr = le64_to_cpu(desc->addr);
int pkt_size = (status & 0x00001FFF) - 4;
- struct pci_dev *pdev = tp->pci_dev;
+ struct device *d = &tp->pci_dev->dev;
/*
* The driver does not support incoming fragmented
@@ -4574,11 +4576,11 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
}
if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
- dma_sync_single_for_device(&pdev->dev, addr,
- pkt_size, DMA_FROM_DEVICE);
+ dma_sync_single_for_device(d, addr, pkt_size,
+ DMA_FROM_DEVICE);
rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
} else {
- dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz,
+ dma_unmap_single(d, addr, tp->rx_buf_sz,
DMA_FROM_DEVICE);
tp->Rx_skbuff[entry] = NULL;
}
--
1.7.1
^ permalink raw reply related
* [PATCH 5/6] r8169: do not account fragments as packets
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
In-Reply-To: <1287144922-3297-1-git-send-email-sgruszka@redhat.com>
Only increase tx_{packets,dropped} statistics when transmit or drop
full skb, not just fragment.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/net/r8169.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index f79ddb2..0ef49b4 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -4130,10 +4130,10 @@ static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, int n)
rtl8169_unmap_tx_skb(d, tx_skb, tp->TxDescArray + entry);
if (skb) {
+ tp->dev->stats.tx_dropped++;
dev_kfree_skb(skb);
tx_skb->skb = NULL;
}
- tp->dev->stats.tx_dropped++;
}
}
}
@@ -4443,12 +4443,12 @@ static void rtl8169_tx_interrupt(struct net_device *dev,
break;
dev->stats.tx_bytes += len;
- dev->stats.tx_packets++;
rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
tp->TxDescArray + entry);
if (status & LastFrag) {
+ dev->stats.tx_packets++;
dev_kfree_skb(tx_skb->skb);
tx_skb->skb = NULL;
}
--
1.7.1
^ permalink raw reply related
* [PATCH 6/6] r8169: print errors when dma mapping fail
From: Stanislaw Gruszka @ 2010-10-15 12:15 UTC (permalink / raw)
To: Francois Romieu, netdev; +Cc: Denis Kirjanov, Stanislaw Gruszka
In-Reply-To: <1287144922-3297-1-git-send-email-sgruszka@redhat.com>
Print errors because dma mapping failures can cause device to stop
working and will need user intervention to recover.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/net/r8169.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 0ef49b4..b27b989 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -4022,8 +4022,10 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct rtl8169_private *tp,
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
mapping = dma_map_single(d, skb->data, rx_buf_sz, DMA_FROM_DEVICE);
- if (dma_mapping_error(d, mapping))
+ if (dma_mapping_error(d, mapping)) {
+ netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
goto err_free_skb_1;
+ }
rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
@@ -4259,8 +4261,11 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
len = frag->size;
addr = ((void *) page_address(frag->page)) + frag->page_offset;
mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(d, mapping)))
+ if (unlikely(dma_mapping_error(d, mapping))) {
+ netif_err(tp, drv, tp->dev,
+ "Failed to map TX fragments DMA!\n");
goto err_out;
+ }
/* anti gcc 2.95.3 bugware (sic) */
status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
@@ -4326,8 +4331,10 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
len = skb_headlen(skb);
mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(d, mapping)))
+ if (unlikely(dma_mapping_error(d, mapping))) {
+ netif_err(tp, drv, dev, "Failed to map TX DMA!\n");
goto err_stop_0;
+ }
tp->tx_skb[entry].len = len;
txd->addr = cpu_to_le64(mapping);
--
1.7.1
^ permalink raw reply related
* netns patches WAS( Re: [PATCH 8/8] net: Implement socketat.
From: jamal @ 2010-10-15 12:30 UTC (permalink / raw)
To: Daniel Lezcano, Eric W. Biederman
Cc: Pavel Emelyanov, linux-kernel, Linux Containers, netdev,
netfilter-devel, linux-fsdevel, Linus Torvalds, Michael Kerrisk,
Ulrich Drepper, Al Viro, David Miller, Serge E. Hallyn,
Pavel Emelyanov, Ben Greear, Matt Helsley, Jonathan Corbet,
Sukadev Bhattiprolu, Jan Engelhardt, Patrick McHardy
In-Reply-To: <1286113441.3812.229.camel@bigi>
Eric et al,
Did these patches make it in? I was looking at
two Davem net trees and i dont see them.
cheers,
jamal
^ permalink raw reply
* ip6_tunnel. mtu/pmtu problems.
From: Anders Franzen @ 2010-10-15 12:40 UTC (permalink / raw)
To: Eric Dumazet; +Cc: netdev
Hi, I've noticed that the ip6_tunnel driver completly ignore to update
the route when a ''bearer'' has a lower mtu then whats expected by the
tunnel device.
Comparing to the ipip tunnel I found that ip6_tunnel is missing the
following line in the ip6_tnl_dev_setup:
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE
Since it's not there, all code that are dependent on an skb_dst(skb)
returning something, can be removed.
this is update_pmtu and icmp_send.
Any how adding the flag to tell the device layer not to release skb->dst
at dev_hard_start_xmit, made things better.
But encap limit is on by default and it consumes 8 bytes, so true mtu
for an ip6_tunnel over a 1500 bytes ethernet shall be 1452 not 1460.
Is it is now I loose the first packet everytime a new route is created.
I updated the driver to take encap_limit into account, if enabled, now
it works even better.
But I have one problem left, and I can reproduce it on the ipv4 ipip
tunnel aswell.
With a bit asymmetric routing setup, I can get the driver to generate an
icmp FRAG_NEEDED. If i configure the routing in such a way that the
forwarding towards the src of the oversized packet, is via the tunnel.
This happends:
Dead loop on virtual device vip4, fix it urgently!
It is because the dev layer has taken a lock on the tx queue for the
device selected for the primary packet (the tunnel), and the tunnel
wants to send an icmp, also on the same device, the lock is held for
transmission of the primary packet, and the icmp gets discarded, with a
nasty kernel msg.
I think this case is a valid case, and the Dead loop is just an
implementation limitation.
Maybe we should try to schedule the icmp do delay it until the primary
packet sending has returned and released the lock.
This is the routing setup I use to trigger the Dead loop, both on ipip
tunnels and ip6_tunnels.
We have 4 nodes A,B,C,D
C is a router, routing AB to/from D
B has a tunnel toward C
B has a default route using the tunnel to C
A has a route to D pointing to B
I raise the MTU of the tunnel endpoint at B by a couple of bytes, to
simulate the encap_limit 8 bytes effect when left out. Or actually
having a bearer device indicate a lower mtu than was expected.
let A ping -M do -s 1470 D
A sends to B, B forwards to tunnel, which will calculate it's mtu to
1480 (ipv4) based on its own overhead and the route mtu of the bearer
route. Since we set the MTU of the tunnel higher than that, the tunnel
will send an icmp back to A, but the route here says that you reach A
via the tunnel it self, and Dead loop......
If the lock in the device layer shall be there, then I think the icmp
should be run from a kthread or something?
Any comments?
Best regards
Anders
^ permalink raw reply
* [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure
From: Julia Lawall @ 2010-10-15 13:00 UTC (permalink / raw)
To: Samuel Ortiz; +Cc: kernel-janitors, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.
The initial value of ret as 0 is never used, so drop the initialization.
A simplified version of the semantic match that finds the first problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@
ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
return ret;
}
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/net/irda/irtty-sir.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff -u -p a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -426,7 +426,7 @@ static int irtty_open(struct tty_struct
{
struct sir_dev *dev;
struct sirtty_cb *priv;
- int ret = 0;
+ int ret;
/* Module stuff handled via irda_ldisc.owner - Jean II */
@@ -459,8 +459,10 @@ static int irtty_open(struct tty_struct
/* allocate private device info block */
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (!priv)
+ if (!priv) {
+ ret = -ENOMEM;
goto out_put;
+ }
priv->magic = IRTTY_MAGIC;
priv->tty = tty;
^ permalink raw reply
* [PATCH 3/7] drivers/net/wireless/p54/eeprom.c: Return -ENOMEM on memory allocation failure
From: Julia Lawall @ 2010-10-15 13:00 UTC (permalink / raw)
To: Christian Lamparter
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA, John W. Linville,
linux-wireless-u79uwXL29TY76Z2rM5mHXA,
netdev-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.
A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@
ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
return ret;
}
// </smpl>
Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
---
drivers/net/wireless/p54/eeprom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff -u -p a/drivers/net/wireless/p54/eeprom.c b/drivers/net/wireless/p54/eeprom.c
--- a/drivers/net/wireless/p54/eeprom.c
+++ b/drivers/net/wireless/p54/eeprom.c
@@ -261,8 +261,10 @@ static int p54_generate_channel_lists(st
list->max_entries = max_channel_num;
list->channels = kzalloc(sizeof(struct p54_channel_entry) *
max_channel_num, GFP_KERNEL);
- if (!list->channels)
+ if (!list->channels) {
+ ret = -ENOMEM;
goto free;
+ }
for (i = 0; i < max_channel_num; i++) {
if (i < priv->iq_autocal_len) {
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* [PATCH net-next-2.6 v1] can: Topcliff: Update PCH_CAN driver to 2.6.35
From: Masayuki Ohtak @ 2010-10-15 13:00 UTC (permalink / raw)
To: Wolfgang Grandegger, David S. Miller, Wolfram Sang,
Christian Pellegrin, Barry Song
Cc: qi.wang, yong.y.wang, andrew.chih.howe.khor, joel.clark,
kok.howg.ewe, Tomoya MORINAGA, Masayuki Ohtake, margie.foster
Hi Wolfgang,
We have modified for your indications.
Please check below.
Thanks, Ohtake(OKISemi)
---
CAN driver of Topcliff PCH
Topcliff PCH is the platform controller hub that is going to be used in
Intel's upcoming general embedded platform. All IO peripherals in
Topcliff PCH are actually devices sitting on AMBA bus.
Topcliff PCH has CAN I/F. This driver enables CAN function.
Signed-off-by: Masayuki Ohtake <masa-korg@dsn.okisemi.com>
---
drivers/net/can/Kconfig | 8 +
drivers/net/can/Makefile | 1 +
drivers/net/can/pch_can.c | 1463 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 1472 insertions(+), 0 deletions(-)
create mode 100644 drivers/net/can/pch_can.c
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 2c5227c..5c98a20 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -73,6 +73,14 @@ config CAN_JANZ_ICAN3
This driver can also be built as a module. If so, the module will be
called janz-ican3.ko.
+config PCH_CAN
+ tristate "PCH CAN"
+ depends on CAN_DEV
+ ---help---
+ This driver is for PCH CAN of Topcliff which is an IOH for x86
+ embedded processor.
+ This driver can access CAN bus.
+
source "drivers/net/can/mscan/Kconfig"
source "drivers/net/can/sja1000/Kconfig"
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 9047cd0..3ddc6a7 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -16,5 +16,6 @@ obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
obj-$(CONFIG_CAN_BFIN) += bfin_can.o
obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
+obj-$(CONFIG_PCH_CAN) += pch_can.o
ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
new file mode 100644
index 0000000..55ec324
--- /dev/null
+++ b/drivers/net/can/pch_can.c
@@ -0,0 +1,1463 @@
+/*
+ * Copyright (C) 1999 - 2010 Intel Corporation.
+ * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/can.h>
+#include <linux/can/dev.h>
+#include <linux/can/error.h>
+
+#define MAX_MSG_OBJ 32
+#define MSG_OBJ_RX 0 /* The receive message object flag. */
+#define MSG_OBJ_TX 1 /* The transmit message object flag. */
+
+#define ENABLE 1 /* The enable flag */
+#define DISABLE 0 /* The disable flag */
+#define CAN_CTRL_INIT 0x0001 /* The INIT bit of CANCONT register. */
+#define CAN_CTRL_IE 0x0002 /* The IE bit of CAN control register */
+#define CAN_CTRL_IE_SIE_EIE 0x000e
+#define CAN_CTRL_CCE 0x0040
+#define CAN_CTRL_OPT 0x0080 /* The OPT bit of CANCONT register. */
+#define CAN_OPT_SILENT 0x0008 /* The Silent bit of CANOPT reg. */
+#define CAN_OPT_LBACK 0x0010 /* The LoopBack bit of CANOPT reg. */
+#define CAN_CMASK_RX_TX_SET 0x00f3
+#define CAN_CMASK_RX_TX_GET 0x0073
+#define CAN_CMASK_ALL 0xff
+#define CAN_CMASK_RDWR 0x80
+#define CAN_CMASK_ARB 0x20
+#define CAN_CMASK_CTRL 0x10
+#define CAN_CMASK_MASK 0x40
+#define CAN_CMASK_NEWDAT 0x04
+#define CAN_CMASK_CLRINTPND 0x08
+
+#define CAN_IF_MCONT_NEWDAT 0x8000
+#define CAN_IF_MCONT_INTPND 0x2000
+#define CAN_IF_MCONT_UMASK 0x1000
+#define CAN_IF_MCONT_TXIE 0x0800
+#define CAN_IF_MCONT_RXIE 0x0400
+#define CAN_IF_MCONT_RMTEN 0x0200
+#define CAN_IF_MCONT_TXRQXT 0x0100
+#define CAN_IF_MCONT_EOB 0x0080
+#define CAN_IF_MCONT_DLC 0x000f
+#define CAN_IF_MCONT_MSGLOST 0x4000
+#define CAN_MASK2_MDIR_MXTD 0xc000
+#define CAN_ID2_DIR 0x2000
+#define CAN_ID_MSGVAL 0x8000
+
+#define CAN_STATUS_INT 0x8000
+#define CAN_IF_CREQ_BUSY 0x8000
+#define CAN_ID2_XTD 0x4000
+
+#define CAN_REC 0x00007f00
+#define CAN_TEC 0x000000ff
+
+#define PCH_RX_OK 0x00000010
+#define PCH_TX_OK 0x00000008
+#define PCH_BUS_OFF 0x00000080
+#define PCH_EWARN 0x00000040
+#define PCH_EPASSIV 0x00000020
+#define PCH_LEC0 0x00000001
+#define PCH_LEC1 0x00000002
+#define PCH_LEC2 0x00000004
+#define PCH_LEC_ALL (PCH_LEC0 | PCH_LEC1 | PCH_LEC2)
+#define PCH_STUF_ERR PCH_LEC0
+#define PCH_FORM_ERR PCH_LEC1
+#define PCH_ACK_ERR (PCH_LEC0 | PCH_LEC1)
+#define PCH_BIT1_ERR PCH_LEC2
+#define PCH_BIT0_ERR (PCH_LEC0 | PCH_LEC2)
+#define PCH_CRC_ERR (PCH_LEC1 | PCH_LEC2)
+
+/* bit position of certain controller bits. */
+#define BIT_BITT_BRP 0
+#define BIT_BITT_SJW 6
+#define BIT_BITT_TSEG1 8
+#define BIT_BITT_TSEG2 12
+#define BIT_IF1_MCONT_RXIE 10
+#define BIT_IF2_MCONT_TXIE 11
+#define BIT_BRPE_BRPE 6
+#define BIT_ES_TXERRCNT 0
+#define BIT_ES_RXERRCNT 8
+#define MSK_BITT_BRP 0x3f
+#define MSK_BITT_SJW 0xc0
+#define MSK_BITT_TSEG1 0xf00
+#define MSK_BITT_TSEG2 0x7000
+#define MSK_BRPE_BRPE 0x3c0
+#define MSK_BRPE_GET 0x0f
+#define MSK_CTRL_IE_SIE_EIE 0x07
+#define MSK_MCONT_TXIE 0x08
+#define MSK_MCONT_RXIE 0x10
+#define PCH_CAN_NO_TX_BUFF 1
+#define COUNTER_LIMIT 10
+
+#define PCH_CAN_CLK 50000000 /* 50MHz */
+
+/* Define the number of message object.
+ * PCH CAN communications are done via Message RAM.
+ * The Message RAM consists of 32 message objects. */
+#define PCH_RX_OBJ_NUM 26 /* 1~ PCH_RX_OBJ_NUM is Rx*/
+#define PCH_TX_OBJ_NUM 6 /* PCH_RX_OBJ_NUM is RX ~ Tx*/
+#define PCH_OBJ_NUM (PCH_TX_OBJ_NUM + PCH_RX_OBJ_NUM)
+
+#define PCH_FIFO_THRESH 16
+
+enum pch_can_mode {
+ PCH_CAN_ENABLE,
+ PCH_CAN_DISABLE,
+ PCH_CAN_ALL,
+ PCH_CAN_NONE,
+ PCH_CAN_STOP,
+ PCH_CAN_RUN
+};
+
+struct pch_can_regs {
+ u32 cont;
+ u32 stat;
+ u32 errc;
+ u32 bitt;
+ u32 intr;
+ u32 opt;
+ u32 brpe;
+ u32 reserve1;
+ u32 if1_creq;
+ u32 if1_cmask;
+ u32 if1_mask1;
+ u32 if1_mask2;
+ u32 if1_id1;
+ u32 if1_id2;
+ u32 if1_mcont;
+ u32 if1_dataa1;
+ u32 if1_dataa2;
+ u32 if1_datab1;
+ u32 if1_datab2;
+ u32 reserve2;
+ u32 reserve3[12];
+ u32 if2_creq;
+ u32 if2_cmask;
+ u32 if2_mask1;
+ u32 if2_mask2;
+ u32 if2_id1;
+ u32 if2_id2;
+ u32 if2_mcont;
+ u32 if2_dataa1;
+ u32 if2_dataa2;
+ u32 if2_datab1;
+ u32 if2_datab2;
+ u32 reserve4;
+ u32 reserve5[20];
+ u32 treq1;
+ u32 treq2;
+ u32 reserve6[2];
+ u32 reserve7[56];
+ u32 reserve8[3];
+ u32 srst;
+};
+
+struct pch_can_priv {
+ struct can_priv can;
+ unsigned int can_num;
+ struct pci_dev *dev;
+ unsigned int tx_enable[MAX_MSG_OBJ];
+ unsigned int rx_enable[MAX_MSG_OBJ];
+ unsigned int rx_link[MAX_MSG_OBJ];
+ unsigned int int_enables;
+ unsigned int int_stat;
+ struct net_device *ndev;
+ spinlock_t msgif_reg_lock; /* Message Interface Registers Access Lock*/
+ unsigned int msg_obj[MAX_MSG_OBJ];
+ struct pch_can_regs __iomem *regs;
+ struct napi_struct napi;
+ unsigned int tx_obj; /* Point next Tx Obj index */
+ unsigned int use_msi;
+};
+
+static struct can_bittiming_const pch_can_bittiming_const = {
+ .name = KBUILD_MODNAME,
+ .tseg1_min = 1,
+ .tseg1_max = 16,
+ .tseg2_min = 1,
+ .tseg2_max = 8,
+ .sjw_max = 4,
+ .brp_min = 1,
+ .brp_max = 1024, /* 6bit + extended 4bit */
+ .brp_inc = 1,
+};
+
+static DEFINE_PCI_DEVICE_TABLE(pch_pci_tbl) = {
+ {PCI_VENDOR_ID_INTEL, 0x8818, PCI_ANY_ID, PCI_ANY_ID,},
+ {0,}
+};
+MODULE_DEVICE_TABLE(pci, pch_pci_tbl);
+
+static inline void pch_can_bit_set(u32 *addr, u32 mask)
+{
+ iowrite32(ioread32(addr) | mask, addr);
+}
+
+static inline void pch_can_bit_clear(u32 *addr, u32 mask)
+{
+ iowrite32(ioread32(addr) & ~mask, addr);
+}
+
+static void pch_can_set_run_mode(struct pch_can_priv *priv,
+ enum pch_can_mode mode)
+{
+ switch (mode) {
+ case PCH_CAN_RUN:
+ pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_INIT);
+ break;
+
+ case PCH_CAN_STOP:
+ pch_can_bit_set(&priv->regs->cont, CAN_CTRL_INIT);
+ break;
+
+ default:
+ dev_err(&priv->ndev->dev, "%s -> Invalid Mode.\n", __func__);
+ break;
+ }
+}
+
+static void pch_can_set_optmode(struct pch_can_priv *priv)
+{
+ u32 reg_val = ioread32(&priv->regs->opt);
+
+ if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+ reg_val |= CAN_OPT_SILENT;
+
+ if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
+ reg_val |= CAN_OPT_LBACK;
+
+ pch_can_bit_set(&priv->regs->cont, CAN_CTRL_OPT);
+ iowrite32(reg_val, &priv->regs->opt);
+}
+
+static void pch_can_set_int_custom(struct pch_can_priv *priv)
+{
+ /* Clearing the IE, SIE and EIE bits of Can control register. */
+ pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
+
+ /* Appropriately setting them. */
+ pch_can_bit_set(&priv->regs->cont,
+ ((priv->int_enables & MSK_CTRL_IE_SIE_EIE) << 1));
+}
+
+/* This function retrieves interrupt enabled for the CAN device. */
+static void pch_can_get_int_enables(struct pch_can_priv *priv, u32 *enables)
+{
+ /* Obtaining the status of IE, SIE and EIE interrupt bits. */
+ *enables = ((ioread32(&priv->regs->cont) & CAN_CTRL_IE_SIE_EIE) >> 1);
+}
+
+static void pch_can_set_int_enables(struct pch_can_priv *priv,
+ enum pch_can_mode interrupt_no)
+{
+ switch (interrupt_no) {
+ case PCH_CAN_ENABLE:
+ pch_can_bit_set(&priv->regs->cont, CAN_CTRL_IE);
+ break;
+
+ case PCH_CAN_DISABLE:
+ pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE);
+ break;
+
+ case PCH_CAN_ALL:
+ pch_can_bit_set(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
+ break;
+
+ case PCH_CAN_NONE:
+ pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
+ break;
+
+ default:
+ dev_err(&priv->ndev->dev, "Invalid interrupt number.\n");
+ break;
+ }
+}
+
+static void pch_can_check_if_busy(u32 __iomem *creq_addr, u32 num)
+{
+ u32 counter = COUNTER_LIMIT;
+ u32 ifx_creq;
+
+ iowrite32(num, creq_addr);
+ while (counter) {
+ ifx_creq = ioread32(creq_addr) & CAN_IF_CREQ_BUSY;
+ if (!ifx_creq)
+ break;
+ counter--;
+ udelay(1);
+ }
+ if (!counter)
+ pr_err("%s:IF1 BUSY Flag is set forever.\n", __func__);
+}
+
+static void pch_can_set_rx_enable(struct pch_can_priv *priv, u32 buff_num,
+ u32 set)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ /* Reading the receive buffer data from RAM to Interface1 registers */
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
+
+ /* Setting the IF1MASK1 register to access MsgVal and RxIE bits */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if1_cmask);
+
+ if (set == ENABLE) {
+ /* Setting the MsgVal and RxIE bits */
+ pch_can_bit_set(&priv->regs->if1_mcont, CAN_IF_MCONT_RXIE);
+ pch_can_bit_set(&priv->regs->if1_id2, CAN_ID_MSGVAL);
+
+ } else if (set == DISABLE) {
+ /* Resetting the MsgVal and RxIE bits */
+ pch_can_bit_clear(&priv->regs->if1_mcont, CAN_IF_MCONT_RXIE);
+ pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID_MSGVAL);
+ }
+
+ pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_rx_enable_all(struct pch_can_priv *priv)
+{
+ int i;
+
+ /* Traversing to obtain the object configured as receivers. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_RX)
+ pch_can_set_rx_enable(priv, i + 1, ENABLE);
+ }
+}
+
+static void pch_can_rx_disable_all(struct pch_can_priv *priv)
+{
+ int i;
+
+ /* Traversing to obtain the object configured as receivers. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_RX)
+ pch_can_set_rx_enable(priv, i + 1, DISABLE);
+ }
+}
+
+static void pch_can_set_tx_enable(struct pch_can_priv *priv, u32 buff_num,
+ u32 set)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ /* Reading the Msg buffer from Message RAM to Interface2 registers. */
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
+
+ /* Setting the IF2CMASK register for accessing the
+ MsgVal and TxIE bits */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if2_cmask);
+
+ if (set == ENABLE) {
+ /* Setting the MsgVal and TxIE bits */
+ pch_can_bit_set(&priv->regs->if2_mcont, CAN_IF_MCONT_TXIE);
+ pch_can_bit_set(&priv->regs->if2_id2, CAN_ID_MSGVAL);
+ } else if (set == DISABLE) {
+ /* Resetting the MsgVal and TxIE bits. */
+ pch_can_bit_clear(&priv->regs->if2_mcont, CAN_IF_MCONT_TXIE);
+ pch_can_bit_clear(&priv->regs->if2_id2, CAN_ID_MSGVAL);
+ }
+
+ pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_tx_enable_all(struct pch_can_priv *priv)
+{
+ int i;
+
+ /* Traversing to obtain the object configured as transmit object. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_TX)
+ pch_can_set_tx_enable(priv, i + 1, ENABLE);
+ }
+}
+
+static void pch_can_tx_disable_all(struct pch_can_priv *priv)
+{
+ int i;
+
+ /* Traversing to obtain the object configured as transmit object. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_TX)
+ pch_can_set_tx_enable(priv, i + 1, DISABLE);
+ }
+}
+
+static void pch_can_get_rx_enable(struct pch_can_priv *priv, u32 buff_num,
+ u32 *enable)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
+
+ if (((ioread32(&priv->regs->if1_id2)) & CAN_ID_MSGVAL) &&
+ ((ioread32(&priv->regs->if1_mcont)) &
+ CAN_IF_MCONT_RXIE))
+ *enable = ENABLE;
+ else
+ *enable = DISABLE;
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_get_tx_enable(struct pch_can_priv *priv, u32 buff_num,
+ u32 *enable)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
+
+ if (((ioread32(&priv->regs->if2_id2)) & CAN_ID_MSGVAL) &&
+ ((ioread32(&priv->regs->if2_mcont)) &
+ CAN_IF_MCONT_TXIE)) {
+ *enable = ENABLE;
+ } else {
+ *enable = DISABLE;
+ }
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static int pch_can_int_pending(struct pch_can_priv *priv)
+{
+ return ioread32(&priv->regs->intr) & 0xffff;
+}
+
+static void pch_can_set_rx_buffer_link(struct pch_can_priv *priv,
+ u32 buffer_num, u32 set)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL, &priv->regs->if1_cmask);
+ if (set == ENABLE)
+ pch_can_bit_clear(&priv->regs->if1_mcont, CAN_IF_MCONT_EOB);
+ else
+ pch_can_bit_set(&priv->regs->if1_mcont, CAN_IF_MCONT_EOB);
+
+ pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_get_rx_buffer_link(struct pch_can_priv *priv,
+ u32 buffer_num, u32 *link)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
+
+ if (ioread32(&priv->regs->if1_mcont) & CAN_IF_MCONT_EOB)
+ *link = DISABLE;
+ else
+ *link = ENABLE;
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_clear_buffers(struct pch_can_priv *priv)
+{
+ int i;
+
+ for (i = 0; i < PCH_RX_OBJ_NUM; i++) {
+ iowrite32(CAN_CMASK_RX_TX_SET, &priv->regs->if1_cmask);
+ iowrite32(0xffff, &priv->regs->if1_mask1);
+ iowrite32(0xffff, &priv->regs->if1_mask2);
+ iowrite32(0x0, &priv->regs->if1_id1);
+ iowrite32(0x0, &priv->regs->if1_id2);
+ iowrite32(0x0, &priv->regs->if1_mcont);
+ iowrite32(0x0, &priv->regs->if1_dataa1);
+ iowrite32(0x0, &priv->regs->if1_dataa2);
+ iowrite32(0x0, &priv->regs->if1_datab1);
+ iowrite32(0x0, &priv->regs->if1_datab2);
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
+ CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
+ }
+
+ for (i = i; i < PCH_OBJ_NUM; i++) {
+ iowrite32(CAN_CMASK_RX_TX_SET, &priv->regs->if2_cmask);
+ iowrite32(0xffff, &priv->regs->if2_mask1);
+ iowrite32(0xffff, &priv->regs->if2_mask2);
+ iowrite32(0x0, &priv->regs->if2_id1);
+ iowrite32(0x0, &priv->regs->if2_id2);
+ iowrite32(0x0, &priv->regs->if2_mcont);
+ iowrite32(0x0, &priv->regs->if2_dataa1);
+ iowrite32(0x0, &priv->regs->if2_dataa2);
+ iowrite32(0x0, &priv->regs->if2_datab1);
+ iowrite32(0x0, &priv->regs->if2_datab2);
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
+ CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
+ }
+}
+
+static void pch_can_config_rx_tx_buffers(struct pch_can_priv *priv)
+{
+ int i;
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_RX) {
+ iowrite32(CAN_CMASK_RX_TX_GET,
+ &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
+
+ iowrite32(0x0, &priv->regs->if1_id1);
+ iowrite32(0x0, &priv->regs->if1_id2);
+
+ pch_can_bit_set(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_UMASK);
+
+ /* Set FIFO mode set to 0 except last Rx Obj*/
+ pch_can_bit_clear(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_EOB);
+ /* In case FIFO mode, Last EoB of Rx Obj must be 1 */
+ if (i == (PCH_RX_OBJ_NUM - 1))
+ pch_can_bit_set(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_EOB);
+
+ iowrite32(0, &priv->regs->if1_mask1);
+ pch_can_bit_clear(&priv->regs->if1_mask2,
+ 0x1fff | CAN_MASK2_MDIR_MXTD);
+
+ /* Setting CMASK for writing */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
+ CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if1_cmask);
+
+ pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
+ } else if (priv->msg_obj[i] == MSG_OBJ_TX) {
+ iowrite32(CAN_CMASK_RX_TX_GET,
+ &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
+
+ /* Resetting DIR bit for reception */
+ iowrite32(0x0, &priv->regs->if2_id1);
+ iowrite32(0x0, &priv->regs->if2_id2);
+ pch_can_bit_set(&priv->regs->if2_id2, CAN_ID2_DIR);
+
+ /* Setting EOB bit for transmitter */
+ iowrite32(CAN_IF_MCONT_EOB, &priv->regs->if2_mcont);
+
+ pch_can_bit_set(&priv->regs->if2_mcont,
+ CAN_IF_MCONT_UMASK);
+
+ iowrite32(0, &priv->regs->if2_mask1);
+ pch_can_bit_clear(&priv->regs->if2_mask2, 0x1fff);
+
+ /* Setting CMASK for writing */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
+ CAN_CMASK_ARB | CAN_CMASK_CTRL,
+ &priv->regs->if2_cmask);
+
+ pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
+ }
+ }
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+}
+
+static void pch_can_init(struct pch_can_priv *priv)
+{
+ /* Stopping the Can device. */
+ pch_can_set_run_mode(priv, PCH_CAN_STOP);
+
+ /* Clearing all the message object buffers. */
+ pch_can_clear_buffers(priv);
+
+ /* Configuring the respective message object as either rx/tx object. */
+ pch_can_config_rx_tx_buffers(priv);
+
+ /* Enabling the interrupts. */
+ pch_can_set_int_enables(priv, PCH_CAN_ALL);
+}
+
+static void pch_can_release(struct pch_can_priv *priv)
+{
+ /* Stooping the CAN device. */
+ pch_can_set_run_mode(priv, PCH_CAN_STOP);
+
+ /* Disabling the interrupts. */
+ pch_can_set_int_enables(priv, PCH_CAN_NONE);
+
+ /* Disabling all the receive object. */
+ pch_can_rx_disable_all(priv);
+
+ /* Disabling all the transmit object. */
+ pch_can_tx_disable_all(priv);
+}
+
+/* This function clears interrupt(s) from the CAN device. */
+static void pch_can_int_clr(struct pch_can_priv *priv, u32 mask)
+{
+ if (mask == CAN_STATUS_INT) {
+ ioread32(&priv->regs->stat);
+ return;
+ }
+
+ /* Clear interrupt for transmit object */
+ if (priv->msg_obj[mask - 1] == MSG_OBJ_TX) {
+ /* Setting CMASK for clearing interrupts for
+ frame transmission. */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL | CAN_CMASK_ARB,
+ &priv->regs->if2_cmask);
+
+ /* Resetting the ID registers. */
+ pch_can_bit_set(&priv->regs->if2_id2,
+ CAN_ID2_DIR | (0x7ff << 2));
+ iowrite32(0x0, &priv->regs->if2_id1);
+
+ /* Claring NewDat, TxRqst & IntPnd */
+ pch_can_bit_clear(&priv->regs->if2_mcont,
+ CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND |
+ CAN_IF_MCONT_TXRQXT);
+ pch_can_check_if_busy(&priv->regs->if2_creq, mask);
+ } else if (priv->msg_obj[mask - 1] == MSG_OBJ_RX) {
+ /* Setting CMASK for clearing the reception interrupts. */
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL | CAN_CMASK_ARB,
+ &priv->regs->if1_cmask);
+
+ /* Clearing the Dir bit. */
+ pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID2_DIR);
+
+ /* Clearing NewDat & IntPnd */
+ pch_can_bit_clear(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND);
+
+ pch_can_check_if_busy(&priv->regs->if1_creq, mask);
+ }
+}
+
+static int pch_can_get_buffer_status(struct pch_can_priv *priv)
+{
+ return (ioread32(&priv->regs->treq1) & 0xffff) |
+ ((ioread32(&priv->regs->treq2) & 0xffff) << 16);
+}
+
+static void pch_can_reset(struct pch_can_priv *priv)
+{
+ /* write to sw reset register */
+ iowrite32(1, &priv->regs->srst);
+ iowrite32(0, &priv->regs->srst);
+}
+
+static void pch_can_error(struct net_device *ndev, u32 status)
+{
+ struct sk_buff *skb;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ struct can_frame *cf;
+ u32 errc;
+ struct net_device_stats *stats = &(priv->ndev->stats);
+ enum can_state state = priv->can.state;
+
+ skb = alloc_can_err_skb(ndev, &cf);
+ if (!skb)
+ return;
+
+ if (status & PCH_BUS_OFF) {
+ pch_can_tx_disable_all(priv);
+ pch_can_rx_disable_all(priv);
+ state = CAN_STATE_BUS_OFF;
+ cf->can_id |= CAN_ERR_BUSOFF;
+ can_bus_off(ndev);
+ pch_can_set_run_mode(priv, PCH_CAN_RUN);
+ dev_err(&ndev->dev, "%s -> Bus Off occurres.\n", __func__);
+ }
+
+ /* Warning interrupt. */
+ if (status & PCH_EWARN) {
+ state = CAN_STATE_ERROR_WARNING;
+ priv->can.can_stats.error_warning++;
+ cf->can_id |= CAN_ERR_CRTL;
+ errc = ioread32(&priv->regs->errc);
+ if (((errc & CAN_REC) >> 8) > 96)
+ cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
+ if ((errc & CAN_TEC) > 96)
+ cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;
+ dev_warn(&ndev->dev,
+ "%s -> Error Counter is more than 96.\n", __func__);
+ }
+ /* Error passive interrupt. */
+ if (status & PCH_EPASSIV) {
+ priv->can.can_stats.error_passive++;
+ state = CAN_STATE_ERROR_PASSIVE;
+ cf->can_id |= CAN_ERR_CRTL;
+ errc = ioread32(&priv->regs->errc);
+ if (((errc & CAN_REC) >> 8) > 127)
+ cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
+ if ((errc & CAN_TEC) > 127)
+ cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
+ dev_err(&ndev->dev,
+ "%s -> CAN controller is ERROR PASSIVE .\n", __func__);
+ }
+
+ if (status & PCH_LEC_ALL) {
+ priv->can.can_stats.bus_error++;
+ stats->rx_errors++;
+ switch (status & PCH_LEC_ALL) {
+ case PCH_STUF_ERR:
+ cf->data[2] |= CAN_ERR_PROT_STUFF;
+ break;
+ case PCH_FORM_ERR:
+ cf->data[2] |= CAN_ERR_PROT_FORM;
+ break;
+ case PCH_ACK_ERR:
+ cf->data[2] |= CAN_ERR_PROT_LOC_ACK |
+ CAN_ERR_PROT_LOC_ACK_DEL;
+ break;
+ case PCH_BIT1_ERR:
+ case PCH_BIT0_ERR:
+ cf->data[2] |= CAN_ERR_PROT_BIT;
+ break;
+ case PCH_CRC_ERR:
+ cf->data[2] |= CAN_ERR_PROT_LOC_CRC_SEQ |
+ CAN_ERR_PROT_LOC_CRC_DEL;
+ break;
+ default:
+ iowrite32(status | PCH_LEC_ALL, &priv->regs->stat);
+ break;
+ }
+
+ }
+
+ priv->can.state = state;
+ netif_rx(skb);
+
+ stats->rx_packets++;
+ stats->rx_bytes += cf->can_dlc;
+}
+
+static irqreturn_t pch_can_interrupt(int irq, void *dev_id)
+{
+ struct net_device *ndev = (struct net_device *)dev_id;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+
+ pch_can_set_int_enables(priv, PCH_CAN_NONE);
+
+ napi_schedule(&priv->napi);
+
+ return IRQ_HANDLED;
+}
+
+static int pch_can_rx_normal(struct net_device *ndev, u32 int_stat)
+{
+ u32 reg;
+ canid_t id;
+ u32 ide;
+ u32 rtr;
+ int i, j, k;
+ int rcv_pkts = 0;
+ struct sk_buff *skb;
+ struct can_frame *cf;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ struct net_device_stats *stats = &(priv->ndev->stats);
+
+ /* Reading the messsage object from the Message RAM */
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, int_stat);
+
+ /* Reading the MCONT register. */
+ reg = ioread32(&priv->regs->if1_mcont);
+ reg &= 0xffff;
+
+ for (k = int_stat; !(reg & CAN_IF_MCONT_EOB); k++) {
+ /* If MsgLost bit set. */
+ if (reg & CAN_IF_MCONT_MSGLOST) {
+ dev_err(&priv->ndev->dev, "Msg Obj is overwritten.\n");
+ pch_can_bit_clear(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_MSGLOST);
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL,
+ &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, k);
+
+ skb = alloc_can_err_skb(ndev, &cf);
+ if (!skb)
+ return -ENOMEM;
+
+ priv->can.can_stats.error_passive++;
+ priv->can.state = CAN_STATE_ERROR_PASSIVE;
+ cf->can_id |= CAN_ERR_CRTL;
+ cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
+ cf->data[2] |= CAN_ERR_PROT_OVERLOAD;
+ stats->rx_packets++;
+ stats->rx_bytes += cf->can_dlc;
+
+ netif_receive_skb(skb);
+ rcv_pkts++;
+ goto RX_NEXT;
+ }
+ if (!(reg & CAN_IF_MCONT_NEWDAT))
+ goto RX_NEXT;
+
+ skb = alloc_can_skb(priv->ndev, &cf);
+ if (!skb)
+ return -ENOMEM;
+
+ /* Get Received data */
+ ide = ((ioread32(&priv->regs->if1_id2)) & CAN_ID2_XTD) >> 14;
+ if (ide) {
+ id = (ioread32(&priv->regs->if1_id1) & 0xffff);
+ id |= (((ioread32(&priv->regs->if1_id2)) &
+ 0x1fff) << 16);
+ cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
+ } else {
+ id = (((ioread32(&priv->regs->if1_id2)) &
+ (CAN_SFF_MASK << 2)) >> 2);
+ cf->can_id = (id & CAN_SFF_MASK);
+ }
+
+ rtr = (ioread32(&priv->regs->if1_id2) & CAN_ID2_DIR);
+ if (rtr) {
+ cf->can_dlc = 0;
+ cf->can_id |= CAN_RTR_FLAG;
+ } else {
+ cf->can_dlc = ((ioread32(&priv->regs->if1_mcont)) &
+ 0x0f);
+ }
+
+ for (i = 0, j = 0; i < cf->can_dlc; j++) {
+ reg = ioread32(&priv->regs->if1_dataa1 + j*4);
+ cf->data[i++] = cpu_to_le32(reg & 0xff);
+ if (i == cf->can_dlc)
+ break;
+ cf->data[i++] = cpu_to_le32((reg >> 8) & 0xff);
+ }
+
+ netif_receive_skb(skb);
+ rcv_pkts++;
+ stats->rx_packets++;
+ stats->rx_bytes += cf->can_dlc;
+
+ if (k < PCH_FIFO_THRESH) {
+ iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL |
+ CAN_CMASK_ARB, &priv->regs->if1_cmask);
+
+ /* Clearing the Dir bit. */
+ pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID2_DIR);
+
+ /* Clearing NewDat & IntPnd */
+ pch_can_bit_clear(&priv->regs->if1_mcont,
+ CAN_IF_MCONT_INTPND);
+ pch_can_check_if_busy(&priv->regs->if1_creq, k);
+ } else if (k > PCH_FIFO_THRESH) {
+ pch_can_int_clr(priv, k);
+ } else if (k == PCH_FIFO_THRESH) {
+ int cnt;
+ for (cnt = 0; cnt < PCH_FIFO_THRESH; cnt++)
+ pch_can_int_clr(priv, cnt+1);
+ }
+RX_NEXT:
+ /* Reading the messsage object from the Message RAM */
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
+ pch_can_check_if_busy(&priv->regs->if1_creq, k + 1);
+ reg = ioread32(&priv->regs->if1_mcont);
+ }
+
+ return rcv_pkts;
+}
+static int pch_can_rx_poll(struct napi_struct *napi, int quota)
+{
+ struct net_device *ndev = napi->dev;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ struct net_device_stats *stats = &(priv->ndev->stats);
+ u32 dlc;
+ u32 int_stat;
+ int rcv_pkts = 0;
+ u32 reg_stat;
+ unsigned long flags;
+
+ int_stat = pch_can_int_pending(priv);
+ if (!int_stat)
+ return 0;
+
+INT_STAT:
+ if (int_stat == CAN_STATUS_INT) {
+ reg_stat = ioread32(&priv->regs->stat);
+ if (reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) {
+ if ((reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL)
+ pch_can_error(ndev, reg_stat);
+ }
+
+ if (reg_stat & PCH_TX_OK) {
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq,
+ ioread32(&priv->regs->intr));
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+ pch_can_bit_clear(&priv->regs->stat, PCH_TX_OK);
+ }
+
+ if (reg_stat & PCH_RX_OK)
+ pch_can_bit_clear(&priv->regs->stat, PCH_RX_OK);
+
+ int_stat = pch_can_int_pending(priv);
+ if (int_stat == CAN_STATUS_INT)
+ goto INT_STAT;
+ }
+
+MSG_OBJ:
+ if ((int_stat >= 1) && (int_stat <= PCH_RX_OBJ_NUM)) {
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ rcv_pkts = pch_can_rx_normal(ndev, int_stat);
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+ if (rcv_pkts < 0)
+ return 0;
+ } else if ((int_stat > PCH_RX_OBJ_NUM) && (int_stat <= PCH_OBJ_NUM)) {
+ if (priv->msg_obj[int_stat - 1] == MSG_OBJ_TX) {
+ /* Handle transmission interrupt */
+ can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_NUM - 1);
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+ iowrite32(CAN_CMASK_RX_TX_GET | CAN_CMASK_CLRINTPND,
+ &priv->regs->if2_cmask);
+ dlc = ioread32(&priv->regs->if2_mcont) &
+ CAN_IF_MCONT_DLC;
+ pch_can_check_if_busy(&priv->regs->if2_creq, int_stat);
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+ if (dlc > 8)
+ dlc = 8;
+ stats->tx_bytes += dlc;
+ stats->tx_packets++;
+ }
+ }
+
+ int_stat = pch_can_int_pending(priv);
+ if (int_stat == CAN_STATUS_INT)
+ goto INT_STAT;
+ else if (int_stat >= 1 && int_stat <= 32)
+ goto MSG_OBJ;
+
+ napi_complete(napi);
+ pch_can_set_int_enables(priv, PCH_CAN_ALL);
+
+ return rcv_pkts;
+}
+
+static int pch_set_bittiming(struct net_device *ndev)
+{
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ const struct can_bittiming *bt = &priv->can.bittiming;
+ u32 canbit;
+ u32 bepe;
+ u32 brp;
+
+ /* Setting the CCE bit for accessing the Can Timing register. */
+ pch_can_bit_set(&priv->regs->cont, CAN_CTRL_CCE);
+
+ brp = (bt->tq) / (1000000000/PCH_CAN_CLK) - 1;
+ canbit = brp & MSK_BITT_BRP;
+ canbit |= (bt->sjw - 1) << BIT_BITT_SJW;
+ canbit |= (bt->phase_seg1 + bt->prop_seg - 1) << BIT_BITT_TSEG1;
+ canbit |= (bt->phase_seg2 - 1) << BIT_BITT_TSEG2;
+ bepe = (brp & MSK_BRPE_BRPE) >> BIT_BRPE_BRPE;
+ iowrite32(canbit, &priv->regs->bitt);
+ iowrite32(bepe, &priv->regs->brpe);
+ pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_CCE);
+
+ return 0;
+}
+
+static void pch_can_start(struct net_device *ndev)
+{
+ struct pch_can_priv *priv = netdev_priv(ndev);
+
+ if (priv->can.state != CAN_STATE_STOPPED)
+ pch_can_reset(priv);
+
+ pch_set_bittiming(ndev);
+ pch_can_set_optmode(priv);
+
+ pch_can_tx_enable_all(priv);
+ pch_can_rx_enable_all(priv);
+
+ /* Setting the CAN to run mode. */
+ pch_can_set_run_mode(priv, PCH_CAN_RUN);
+
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
+
+ return;
+}
+
+static int pch_can_do_set_mode(struct net_device *ndev, enum can_mode mode)
+{
+ int ret = 0;
+
+ switch (mode) {
+ case CAN_MODE_START:
+ pch_can_start(ndev);
+ netif_wake_queue(ndev);
+ break;
+ default:
+ ret = -EOPNOTSUPP;
+ break;
+ }
+
+ return ret;
+}
+
+static int pch_can_open(struct net_device *ndev)
+{
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ int retval;
+
+ retval = pci_enable_msi(priv->dev);
+ if (retval) {
+ dev_info(&ndev->dev, "PCH CAN opened without MSI\n");
+ priv->use_msi = 0;
+ } else {
+ dev_info(&ndev->dev, "PCH CAN opened with MSI\n");
+ priv->use_msi = 1;
+ }
+
+ /* Regsitering the interrupt. */
+ retval = request_irq(priv->dev->irq, pch_can_interrupt, IRQF_SHARED,
+ ndev->name, ndev);
+ if (retval) {
+ dev_err(&ndev->dev, "request_irq failed.\n");
+ goto req_irq_err;
+ }
+
+ /* Open common can device */
+ retval = open_candev(ndev);
+ if (retval) {
+ dev_err(ndev->dev.parent, "open_candev() failed %d\n", retval);
+ goto err_open_candev;
+ }
+
+ pch_can_init(priv);
+ pch_can_start(ndev);
+ napi_enable(&priv->napi);
+ netif_start_queue(ndev);
+
+ return 0;
+
+err_open_candev:
+ free_irq(priv->dev->irq, ndev);
+req_irq_err:
+ if (priv->use_msi)
+ pci_disable_msi(priv->dev);
+
+ pch_can_release(priv);
+
+ return retval;
+}
+
+static int pch_close(struct net_device *ndev)
+{
+ struct pch_can_priv *priv = netdev_priv(ndev);
+
+ netif_stop_queue(ndev);
+ napi_disable(&priv->napi);
+ pch_can_release(priv);
+ free_irq(priv->dev->irq, ndev);
+ if (priv->use_msi)
+ pci_disable_msi(priv->dev);
+ close_candev(ndev);
+ priv->can.state = CAN_STATE_STOPPED;
+ return 0;
+}
+
+static int pch_get_msg_obj_sts(struct net_device *ndev, u32 obj_id)
+{
+ u32 buffer_status = 0;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+
+ /* Getting the message object status. */
+ buffer_status = (u32) pch_can_get_buffer_status(priv);
+
+ return buffer_status & obj_id;
+}
+
+
+static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
+{
+ int i, j;
+ unsigned long flags;
+ struct pch_can_priv *priv = netdev_priv(ndev);
+ struct can_frame *cf = (struct can_frame *)skb->data;
+ int tx_buffer_avail = 0;
+
+ if (can_dropped_invalid_skb(ndev, skb))
+ return NETDEV_TX_OK;
+
+ if (priv->tx_obj == (PCH_OBJ_NUM + 1)) { /* Point tail Obj */
+ while (pch_get_msg_obj_sts(ndev, (((1 << PCH_TX_OBJ_NUM)-1) <<
+ PCH_RX_OBJ_NUM)))
+ udelay(500);
+
+ priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj ID */
+ tx_buffer_avail = priv->tx_obj; /* Point Tail of Tx Obj */
+ } else {
+ tx_buffer_avail = priv->tx_obj;
+ }
+ priv->tx_obj++;
+
+ /* Attaining the lock. */
+ spin_lock_irqsave(&priv->msgif_reg_lock, flags);
+
+ /* Reading the Msg Obj from the Msg RAM to the Interface register. */
+ iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
+ pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
+
+ /* Setting the CMASK register. */
+ pch_can_bit_set(&priv->regs->if2_cmask, CAN_CMASK_ALL);
+
+ /* If ID extended is set. */
+ pch_can_bit_clear(&priv->regs->if2_id1, 0xffff);
+ pch_can_bit_clear(&priv->regs->if2_id2, 0x1fff | CAN_ID2_XTD);
+ if (cf->can_id & CAN_EFF_FLAG) {
+ pch_can_bit_set(&priv->regs->if2_id1, cf->can_id & 0xffff);
+ pch_can_bit_set(&priv->regs->if2_id2,
+ ((cf->can_id >> 16) & 0x1fff) | CAN_ID2_XTD);
+ } else {
+ pch_can_bit_set(&priv->regs->if2_id1, 0);
+ pch_can_bit_set(&priv->regs->if2_id2,
+ (cf->can_id & CAN_SFF_MASK) << 2);
+ }
+
+ /* If remote frame has to be transmitted.. */
+ if (cf->can_id & CAN_RTR_FLAG)
+ pch_can_bit_clear(&priv->regs->if2_id2, CAN_ID2_DIR);
+
+ for (i = 0, j = 0; i < cf->can_dlc; j++) {
+ iowrite32(le32_to_cpu(cf->data[i++]),
+ (&priv->regs->if2_dataa1) + j*4);
+ if (i == cf->can_dlc)
+ break;
+ iowrite32(le32_to_cpu(cf->data[i++] << 8),
+ (&priv->regs->if2_dataa1) + j*4);
+ }
+
+ can_put_echo_skb(skb, ndev, tx_buffer_avail - PCH_RX_OBJ_NUM - 1);
+
+ /* Updating the size of the data. */
+ pch_can_bit_clear(&priv->regs->if2_mcont, 0x0f);
+ pch_can_bit_set(&priv->regs->if2_mcont, cf->can_dlc);
+
+ /* Clearing IntPend, NewDat & TxRqst */
+ pch_can_bit_clear(&priv->regs->if2_mcont,
+ CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND |
+ CAN_IF_MCONT_TXRQXT);
+
+ /* Setting NewDat, TxRqst bits */
+ pch_can_bit_set(&priv->regs->if2_mcont,
+ CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_TXRQXT);
+
+ pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
+
+ spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
+
+ return NETDEV_TX_OK;
+}
+
+static const struct net_device_ops pch_can_netdev_ops = {
+ .ndo_open = pch_can_open,
+ .ndo_stop = pch_close,
+ .ndo_start_xmit = pch_xmit,
+};
+
+static void __devexit pch_can_remove(struct pci_dev *pdev)
+{
+ struct net_device *ndev = pci_get_drvdata(pdev);
+ struct pch_can_priv *priv = netdev_priv(ndev);
+
+ unregister_candev(priv->ndev);
+ free_candev(priv->ndev);
+ pci_iounmap(pdev, priv->regs);
+ pci_release_regions(pdev);
+ pci_disable_device(pdev);
+ pci_set_drvdata(pdev, NULL);
+ pch_can_reset(priv);
+}
+
+#ifdef CONFIG_PM
+static int pch_can_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+ int i; /* Counter variable. */
+ int retval; /* Return value. */
+ u32 buf_stat; /* Variable for reading the transmit buffer status. */
+ u32 counter = 0xFFFFFF;
+
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct pch_can_priv *priv = netdev_priv(dev);
+
+ /* Stop the CAN controller */
+ pch_can_set_run_mode(priv, PCH_CAN_STOP);
+
+ /* Indicate that we are aboutto/in suspend */
+ priv->can.state = CAN_STATE_SLEEPING;
+
+ /* Waiting for all transmission to complete. */
+ while (counter) {
+ buf_stat = pch_can_get_buffer_status(priv);
+ if (!buf_stat)
+ break;
+ counter--;
+ udelay(1);
+ }
+ if (!counter)
+ dev_err(&pdev->dev, "%s -> Transmission time out.\n", __func__);
+
+ /* Save interrupt configuration and then disable them */
+ pch_can_get_int_enables(priv, &(priv->int_enables));
+ pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
+
+ /* Save Tx buffer enable state */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_TX)
+ pch_can_get_tx_enable(priv, i + 1,
+ &(priv->tx_enable[i]));
+ }
+
+ /* Disable all Transmit buffers */
+ pch_can_tx_disable_all(priv);
+
+ /* Save Rx buffer enable state */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_RX) {
+ pch_can_get_rx_enable(priv, i + 1,
+ &(priv->rx_enable[i]));
+ pch_can_get_rx_buffer_link(priv, i + 1,
+ &(priv->rx_link[i]));
+ }
+ }
+
+ /* Disable all Receive buffers */
+ pch_can_rx_disable_all(priv);
+ retval = pci_save_state(pdev);
+ if (retval) {
+ dev_err(&pdev->dev, "pci_save_state failed.\n");
+ } else {
+ pci_enable_wake(pdev, PCI_D3hot, 0);
+ pci_disable_device(pdev);
+ pci_set_power_state(pdev, pci_choose_state(pdev, state));
+ }
+
+ return retval;
+}
+
+static int pch_can_resume(struct pci_dev *pdev)
+{
+ int i; /* Counter variable. */
+ int retval; /* Return variable. */
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct pch_can_priv *priv = netdev_priv(dev);
+
+ pci_set_power_state(pdev, PCI_D0);
+ pci_restore_state(pdev);
+ retval = pci_enable_device(pdev);
+ if (retval) {
+ dev_err(&pdev->dev, "pci_enable_device failed.\n");
+ return retval;
+ }
+
+ pci_enable_wake(pdev, PCI_D3hot, 0);
+
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
+
+ /* Disabling all interrupts. */
+ pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
+
+ /* Setting the CAN device in Stop Mode. */
+ pch_can_set_run_mode(priv, PCH_CAN_STOP);
+
+ /* Configuring the transmit and receive buffers. */
+ pch_can_config_rx_tx_buffers(priv);
+
+ /* Restore the CAN state */
+ pch_set_bittiming(dev);
+
+ /* Listen/Active */
+ pch_can_set_optmode(priv);
+
+ /* Enabling the transmit buffer. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_TX) {
+ pch_can_set_tx_enable(priv, i + 1,
+ priv->tx_enable[i]);
+ }
+ }
+
+ /* Configuring the receive buffer and enabling them. */
+ for (i = 0; i < PCH_OBJ_NUM; i++) {
+ if (priv->msg_obj[i] == MSG_OBJ_RX) {
+ /* Restore buffer link */
+ pch_can_set_rx_buffer_link(priv, i + 1,
+ priv->rx_link[i]);
+
+ /* Restore buffer enables */
+ pch_can_set_rx_enable(priv, i + 1, priv->rx_enable[i]);
+ }
+ }
+
+ /* Enable CAN Interrupts */
+ pch_can_set_int_custom(priv);
+
+ /* Restore Run Mode */
+ pch_can_set_run_mode(priv, PCH_CAN_RUN);
+
+ return retval;
+}
+#else
+#define pch_can_suspend NULL
+#define pch_can_resume NULL
+#endif
+
+static int pch_can_get_berr_counter(const struct net_device *dev,
+ struct can_berr_counter *bec)
+{
+ struct pch_can_priv *priv = netdev_priv(dev);
+
+ bec->txerr = ioread32(&priv->regs->errc) & CAN_TEC;
+ bec->rxerr = (ioread32(&priv->regs->errc) & CAN_REC) >> 8;
+
+ return 0;
+}
+
+static int __devinit pch_can_probe(struct pci_dev *pdev,
+ const struct pci_device_id *id)
+{
+ struct net_device *ndev;
+ struct pch_can_priv *priv;
+ int rc;
+ int index;
+ void __iomem *addr;
+
+ rc = pci_enable_device(pdev);
+ if (rc) {
+ dev_err(&pdev->dev, "Failed pci_enable_device %d\n", rc);
+ goto probe_exit_endev;
+ }
+
+ rc = pci_request_regions(pdev, KBUILD_MODNAME);
+ if (rc) {
+ dev_err(&pdev->dev, "Failed pci_request_regions %d\n", rc);
+ goto probe_exit_pcireq;
+ }
+
+ addr = pci_iomap(pdev, 1, 0);
+ if (!addr) {
+ rc = -EIO;
+ dev_err(&pdev->dev, "Failed pci_iomap\n");
+ goto probe_exit_ipmap;
+ }
+
+ ndev = alloc_candev(sizeof(struct pch_can_priv), PCH_TX_OBJ_NUM);
+ if (!ndev) {
+ rc = -ENOMEM;
+ dev_err(&pdev->dev, "Failed alloc_candev\n");
+ goto probe_exit_alloc_candev;
+ }
+
+ priv = netdev_priv(ndev);
+ priv->ndev = ndev;
+ priv->regs = addr;
+ priv->dev = pdev;
+ priv->can.bittiming_const = &pch_can_bittiming_const;
+ priv->can.do_set_mode = pch_can_do_set_mode;
+ priv->can.do_get_berr_counter = pch_can_get_berr_counter;
+ priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
+ CAN_CTRLMODE_LOOPBACK;
+ priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj */
+
+ ndev->irq = pdev->irq;
+ ndev->flags |= IFF_ECHO;
+
+ pci_set_drvdata(pdev, ndev);
+ SET_NETDEV_DEV(ndev, &pdev->dev);
+ ndev->netdev_ops = &pch_can_netdev_ops;
+
+ priv->can.clock.freq = PCH_CAN_CLK; /* Hz */
+ for (index = 0; index < PCH_RX_OBJ_NUM;)
+ priv->msg_obj[index++] = MSG_OBJ_RX;
+
+ for (index = index; index < PCH_OBJ_NUM;)
+ priv->msg_obj[index++] = MSG_OBJ_TX;
+
+ netif_napi_add(ndev, &priv->napi, pch_can_rx_poll, PCH_RX_OBJ_NUM);
+
+ rc = register_candev(ndev);
+ if (rc) {
+ dev_err(&pdev->dev, "Failed register_candev %d\n", rc);
+ goto probe_exit_reg_candev;
+ }
+
+ return 0;
+
+probe_exit_reg_candev:
+ free_candev(ndev);
+probe_exit_alloc_candev:
+ pci_iounmap(pdev, addr);
+probe_exit_ipmap:
+ pci_release_regions(pdev);
+probe_exit_pcireq:
+ pci_disable_device(pdev);
+probe_exit_endev:
+ return rc;
+}
+
+static struct pci_driver pch_can_pcidev = {
+ .name = "pch_can",
+ .id_table = pch_pci_tbl,
+ .probe = pch_can_probe,
+ .remove = __devexit_p(pch_can_remove),
+ .suspend = pch_can_suspend,
+ .resume = pch_can_resume,
+};
+
+static int __init pch_can_pci_init(void)
+{
+ return pci_register_driver(&pch_can_pcidev);
+}
+module_init(pch_can_pci_init);
+
+static void __exit pch_can_pci_exit(void)
+{
+ pci_unregister_driver(&pch_can_pcidev);
+}
+module_exit(pch_can_pci_exit);
+
+MODULE_DESCRIPTION("Controller Area Network Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_VERSION("0.94");
--
1.6.2.2
^ permalink raw reply related
* Re: ip6_tunnel. mtu/pmtu problems.
From: Eric Dumazet @ 2010-10-15 13:09 UTC (permalink / raw)
To: Anders Franzen; +Cc: netdev
In-Reply-To: <1287146439.27134.491.camel@seasc7941.dyn.rnd.as.sw.ericsson.se>
Le vendredi 15 octobre 2010 à 14:40 +0200, Anders Franzen a écrit :
> Hi, I've noticed that the ip6_tunnel driver completly ignore to update
> the route when a ''bearer'' has a lower mtu then whats expected by the
> tunnel device.
>
> Comparing to the ipip tunnel I found that ip6_tunnel is missing the
> following line in the ip6_tnl_dev_setup:
> dev->priv_flags &= ~IFF_XMIT_DST_RELEASE
>
Good catch :)
> Since it's not there, all code that are dependent on an skb_dst(skb)
> returning something, can be removed.
> this is update_pmtu and icmp_send.
>
> Any how adding the flag to tell the device layer not to release skb->dst
> at dev_hard_start_xmit, made things better.
>
> But encap limit is on by default and it consumes 8 bytes, so true mtu
> for an ip6_tunnel over a 1500 bytes ethernet shall be 1452 not 1460.
>
> Is it is now I loose the first packet everytime a new route is created.
>
> I updated the driver to take encap_limit into account, if enabled, now
> it works even better.
>
> But I have one problem left, and I can reproduce it on the ipv4 ipip
> tunnel aswell.
>
> With a bit asymmetric routing setup, I can get the driver to generate an
> icmp FRAG_NEEDED. If i configure the routing in such a way that the
> forwarding towards the src of the oversized packet, is via the tunnel.
>
> This happends:
>
> Dead loop on virtual device vip4, fix it urgently!
>
> It is because the dev layer has taken a lock on the tx queue for the
> device selected for the primary packet (the tunnel), and the tunnel
> wants to send an icmp, also on the same device, the lock is held for
> transmission of the primary packet, and the icmp gets discarded, with a
> nasty kernel msg.
>
> I think this case is a valid case, and the Dead loop is just an
> implementation limitation.
>
> Maybe we should try to schedule the icmp do delay it until the primary
> packet sending has returned and released the lock.
>
>
>
> This is the routing setup I use to trigger the Dead loop, both on ipip
> tunnels and ip6_tunnels.
>
>
>
> We have 4 nodes A,B,C,D
>
>
> C is a router, routing AB to/from D
>
> B has a tunnel toward C
> B has a default route using the tunnel to C
>
> A has a route to D pointing to B
>
> I raise the MTU of the tunnel endpoint at B by a couple of bytes, to
> simulate the encap_limit 8 bytes effect when left out. Or actually
> having a bearer device indicate a lower mtu than was expected.
>
> let A ping -M do -s 1470 D
>
> A sends to B, B forwards to tunnel, which will calculate it's mtu to
> 1480 (ipv4) based on its own overhead and the route mtu of the bearer
> route. Since we set the MTU of the tunnel higher than that, the tunnel
> will send an icmp back to A, but the route here says that you reach A
> via the tunnel it self, and Dead loop......
>
>
> If the lock in the device layer shall be there, then I think the icmp
> should be run from a kthread or something?
If the only thing blocking you is the dead loop, please try following
patch from net-next-2.6, currently a candidate for net-2.6
commit 745e20f1b626b1be4b100af5d4bf7b3439392f8f
Author: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed Sep 29 13:23:09 2010 -0700
net: add a recursion limit in xmit path
As tunnel devices are going to be lockless, we need to make sure a
misconfigured machine wont enter an infinite loop.
Add a percpu variable, and limit to three the number of stacked xmits.
Reported-by: Jesse Gross <jesse@nicira.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
http://git2.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=745e20f1b626b1be4b100af5d4bf7b3439392f8f
^ permalink raw reply
* Re: [PATCH v2] Add Qualcomm Gobi 2000 driver.
From: Elly Jones @ 2010-10-15 13:17 UTC (permalink / raw)
To: David Miller; +Cc: netdev, jglasgow, mjg59, msb, olofj
In-Reply-To: <20101008.102803.104075511.davem@davemloft.net>
On Fri, Oct 08, 2010 at 10:28:03AM -0700, David Miller wrote:
> From: Elly Jones <ellyjones@google.com>
> Date: Wed, 6 Oct 2010 11:12:09 -0400
>
> > From: Elizabeth Jones <ellyjones@google.com>
> >
> > This driver is a rewrite of the original Qualcomm GPL driver, released as part
> > of Qualcomm's "Code Aurora" initiative. The driver has been transformed into
> > Linux kernel style and made to use kernel APIs where appropriate; some bugs have
> > also been fixed. Note that the device in question requires firmware and a
> > firmware loader; the latter has been written by mjg (see
> > http://www.codon.org.uk/~mjg59/gobi_loader/).
> >
> > Special thanks go to Joe Perches <joe@perches.com> for major cleanup.
> >
> > Signed-off-by: Elizabeth Jones <ellyjones@google.com>
> > Signed-off-by: Jason Glasgow <jglasgow@google.com>
>
> I really think the firmware handling belongs in the kernel.
>
> I've looked at the gobi_loader code and it's simpler than many
> of the gigabit ethernet driver firmware loader sequences in
> the tree already.
>
> Requiring udev et al. magic only makes this networking device
> that much harder to use from an initrd.
>
> I understand how this might be a bit clumsy since we'd need to make a
> dependency on the serial device since that is the mechanism by which
> the firmware is uploaded, but really I'd like you to consider it
> seriously.
Just to respond definitively to this: I believe the reasons mjg59 brought up are
valid and I will not try to put a firmware loader for this device in kernel
space. Additionally, Google could not in good conscience produce such a firmware
loader, as we have access to Qualcomm's closed-source firmware loader. Expect a
v3 of this patch shortly to address Joe Perches' concerns.
-- Elly
^ permalink raw reply
* Re: [PATCH] connector: remove lazy workqueue creation
From: Evgeniy Polyakov @ 2010-10-15 13:06 UTC (permalink / raw)
To: Tejun Heo; +Cc: netdev@vger.kernel.org, Frederic Weisbecker, David S. Miller
In-Reply-To: <4CB8250A.7040902@kernel.org>
Hi Tejun.
On Fri, Oct 15, 2010 at 11:55:22AM +0200, Tejun Heo (tj@kernel.org) wrote:
> Commit 1a5645bc (connector: create connector workqueue only while
> needed once) implements lazy workqueue creation for connector
> workqueue. With cmwq now in place, lazy workqueue creation doesn't
> make much sense while adding a lot of complexity. Remove it and
> allocate an ordered workqueue during initialization.
>
> This also removes a call to flush_scheduled_work() which is deprecated
> and scheduled to be removed.
Looks good, thank you.
Ack.
--
Evgeniy Polyakov
^ permalink raw reply
* Re: [PATCH] connector: remove lazy workqueue creation
From: Tejun Heo @ 2010-10-15 13:38 UTC (permalink / raw)
To: Evgeniy Polyakov
Cc: netdev@vger.kernel.org, Frederic Weisbecker, David S. Miller
In-Reply-To: <20101015130604.GA1751@ioremap.net>
Hello,
On 10/15/2010 03:06 PM, Evgeniy Polyakov wrote:
> On Fri, Oct 15, 2010 at 11:55:22AM +0200, Tejun Heo (tj@kernel.org) wrote:
>> Commit 1a5645bc (connector: create connector workqueue only while
>> needed once) implements lazy workqueue creation for connector
>> workqueue. With cmwq now in place, lazy workqueue creation doesn't
>> make much sense while adding a lot of complexity. Remove it and
>> allocate an ordered workqueue during initialization.
>>
>> This also removes a call to flush_scheduled_work() which is deprecated
>> and scheduled to be removed.
>
> Looks good, thank you.
> Ack.
Are you gonna route this patch? If not, I can route it through
workqueue tree.
Thank you.
--
tejun
^ permalink raw reply
* [PATCH v3] Add Qualcomm Gobi 2000 driver.
From: Elly Jones @ 2010-10-15 13:42 UTC (permalink / raw)
To: netdev; +Cc: jglasgow, mjg59, msb, olofj
From: Elizabeth Jones <ellyjones@google.com>
This driver is a rewrite of the original Qualcomm GPL driver, released as part
of Qualcomm's "Code Aurora" initiative. The driver has been transformed into
Linux kernel style and made to use kernel APIs where appropriate; some bugs have
also been fixed. Note that the device in question requires firmware and a
firmware loader; the latter has been written by mjg (see
http://www.codon.org.uk/~mjg59/gobi_loader/).
Special thanks go to Joe Perches <joe@perches.com> for major cleanup.
Signed-off-by: Elizabeth Jones <ellyjones@google.com>
Signed-off-by: Jason Glasgow <jglasgow@google.com>
---
drivers/net/usb/Kconfig | 6 +
drivers/net/usb/Makefile | 2 +-
drivers/net/usb/gobi/Makefile | 2 +
drivers/net/usb/gobi/README | 30 +
drivers/net/usb/gobi/qcusbnet.c | 649 ++++++++++++++++
drivers/net/usb/gobi/qcusbnet.h | 24 +
drivers/net/usb/gobi/qmi.c | 358 +++++++++
drivers/net/usb/gobi/qmi.h | 67 ++
drivers/net/usb/gobi/qmidevice.c | 1590 ++++++++++++++++++++++++++++++++++++++
drivers/net/usb/gobi/qmidevice.h | 35 +
drivers/net/usb/gobi/structs.h | 92 +++
11 files changed, 2854 insertions(+), 1 deletions(-)
create mode 100644 drivers/net/usb/gobi/Makefile
create mode 100644 drivers/net/usb/gobi/README
create mode 100644 drivers/net/usb/gobi/qcusbnet.c
create mode 100644 drivers/net/usb/gobi/qcusbnet.h
create mode 100644 drivers/net/usb/gobi/qmi.c
create mode 100644 drivers/net/usb/gobi/qmi.h
create mode 100644 drivers/net/usb/gobi/qmidevice.c
create mode 100644 drivers/net/usb/gobi/qmidevice.h
create mode 100644 drivers/net/usb/gobi/structs.h
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index d7b7018..8a210d9 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -406,4 +406,10 @@ config USB_SIERRA_NET
To compile this driver as a module, choose M here: the
module will be called sierra_net.
+config USB_NET_GOBI
+ tristate "Qualcomm Gobi"
+ depends on USB_USBNET
+ help
+ Choose this option if you have a Qualcomm Gobi 2000 cellular modem.
+
endmenu
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index b13a279..c80e037 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -25,4 +25,4 @@ obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o
obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o
obj-$(CONFIG_USB_IPHETH) += ipheth.o
obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o
-
+obj-$(CONFIG_USB_NET_GOBI) += gobi/
diff --git a/drivers/net/usb/gobi/Makefile b/drivers/net/usb/gobi/Makefile
new file mode 100644
index 0000000..a6635f6
--- /dev/null
+++ b/drivers/net/usb/gobi/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_USB_NET_GOBI) += gobi.o
+gobi-objs += qcusbnet.o qmidevice.o qmi.o
diff --git a/drivers/net/usb/gobi/README b/drivers/net/usb/gobi/README
new file mode 100644
index 0000000..113c523
--- /dev/null
+++ b/drivers/net/usb/gobi/README
@@ -0,0 +1,30 @@
+Qualcomm Gobi 2000 driver
+-------------------------
+
+This directory contains a driver for the Qualcomm Gobi 2000 CDMA/GSM modem. The
+device speaks a protocol called QMI with its host; this driver's responsibility
+is to multiplex transactions over QMI connections. Note that the relatively
+simple encoding defined in qmi.h and qmi.c is only the encapsulating protocol;
+the device speaks a more complex set of protocols embodied in the closed-source
+Gobi SDK which are necessary to use advanced features of the device.
+Furthermore, firmware (also proprietary) is needed to make the device useful. An
+open-source firmware loader exists: http://www.codon.org.uk/~mjg59/gobi_loader/.
+
+Interfaces:
+This driver presents two separate interfaces to userspace:
+- usbN, an ordinary usb network interface
+- /dev/qcqmiN, a channel to speak to the device using QMI messages
+The latter is for use by the Gobi SDK.
+
+History:
+This driver's original incarnation (of which this is a rewrite) was released
+under GPLv2 by Qualcomm on their Code Aurora site:
+https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=commit;h=b5135a880f8942f990e8c2e383f7f876beacc55b
+
+Issues:
+Help and commentary on any of the issues below would be appreciated.
+- The locking in devqmi_close() is not threadsafe: we're walking a list of tasks
+ without holding a lock on the list. The original driver did this and I have
+ left it intact because I do not fully understand what's going on here.
+- The driver seems to deadlock very occasionally (one in ~6000 reboots during
+ stress testing). I've had no luck tracking this problem down.
diff --git a/drivers/net/usb/gobi/qcusbnet.c b/drivers/net/usb/gobi/qcusbnet.c
new file mode 100644
index 0000000..7e218a8
--- /dev/null
+++ b/drivers/net/usb/gobi/qcusbnet.c
@@ -0,0 +1,649 @@
+/* qcusbnet.c - gobi network device
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "structs.h"
+#include "qmidevice.h"
+#include "qmi.h"
+#include "qcusbnet.h"
+
+#define DRIVER_VERSION "1.0.110"
+#define DRIVER_AUTHOR "Qualcomm Innovation Center"
+#define DRIVER_DESC "QCUSBNet2k"
+
+int qcusbnet_debug;
+static struct class *devclass;
+
+int qc_suspend(struct usb_interface *iface, pm_message_t event)
+{
+ struct usbnet *usbnet;
+ struct qcusbnet *dev;
+
+ if (!iface)
+ return -ENOMEM;
+
+ usbnet = usb_get_intfdata(iface);
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get netdevice\n");
+ return -ENXIO;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return -ENXIO;
+ }
+
+ if (!(event.event & PM_EVENT_AUTO)) {
+ DBG("device suspended to power level %d\n",
+ event.event);
+ qc_setdown(dev, DOWN_DRIVER_SUSPENDED);
+ } else {
+ DBG("device autosuspend\n");
+ }
+
+ if (event.event & PM_EVENT_SUSPEND) {
+ qc_stopread(dev);
+ usbnet->udev->reset_resume = 0;
+ iface->dev.power.power_state.event = event.event;
+ } else {
+ usbnet->udev->reset_resume = 1;
+ }
+
+ return usbnet_suspend(iface, event);
+}
+
+static int qc_resume(struct usb_interface *iface)
+{
+ struct usbnet *usbnet;
+ struct qcusbnet *dev;
+ int ret;
+ int oldstate;
+
+ if (iface == 0)
+ return -ENOMEM;
+
+ usbnet = usb_get_intfdata(iface);
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get netdevice\n");
+ return -ENXIO;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return -ENXIO;
+ }
+
+ oldstate = iface->dev.power.power_state.event;
+ iface->dev.power.power_state.event = PM_EVENT_ON;
+ DBG("resuming from power mode %d\n", oldstate);
+
+ if (oldstate & PM_EVENT_SUSPEND) {
+ qc_cleardown(dev, DOWN_DRIVER_SUSPENDED);
+
+ ret = usbnet_resume(iface);
+ if (ret) {
+ DBG("usbnet_resume error %d\n", ret);
+ return ret;
+ }
+
+ ret = qc_startread(dev);
+ if (ret) {
+ DBG("qc_startread error %d\n", ret);
+ return ret;
+ }
+
+ complete(&dev->worker.work);
+ } else {
+ DBG("nothing to resume\n");
+ return 0;
+ }
+
+ return ret;
+}
+
+static int qcnet_bind(struct usbnet *usbnet, struct usb_interface *iface)
+{
+ int numends;
+ int i;
+ struct usb_host_endpoint *endpoint = NULL;
+ struct usb_host_endpoint *in = NULL;
+ struct usb_host_endpoint *out = NULL;
+
+ if (iface->num_altsetting != 1) {
+ DBG("invalid num_altsetting %u\n", iface->num_altsetting);
+ return -EINVAL;
+ }
+
+ if (iface->cur_altsetting->desc.bInterfaceNumber != 0) {
+ DBG("invalid interface %d\n",
+ iface->cur_altsetting->desc.bInterfaceNumber);
+ return -EINVAL;
+ }
+
+ numends = iface->cur_altsetting->desc.bNumEndpoints;
+ for (i = 0; i < numends; i++) {
+ endpoint = iface->cur_altsetting->endpoint + i;
+ if (!endpoint) {
+ DBG("invalid endpoint %u\n", i);
+ return -EINVAL;
+ }
+
+ if (usb_endpoint_dir_in(&endpoint->desc)
+ && !usb_endpoint_xfer_int(&endpoint->desc)) {
+ in = endpoint;
+ } else if (!usb_endpoint_dir_out(&endpoint->desc)) {
+ out = endpoint;
+ }
+ }
+
+ if (!in || !out) {
+ DBG("invalid endpoints\n");
+ return -EINVAL;
+ }
+
+ if (usb_set_interface(usbnet->udev,
+ iface->cur_altsetting->desc.bInterfaceNumber, 0)) {
+ DBG("unable to set interface\n");
+ return -EINVAL;
+ }
+
+ usbnet->in = usb_rcvbulkpipe(usbnet->udev, in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
+ usbnet->out = usb_sndbulkpipe(usbnet->udev, out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
+
+ DBG("in %x, out %x\n",
+ in->desc.bEndpointAddress,
+ out->desc.bEndpointAddress);
+
+ return 0;
+}
+
+static void qcnet_unbind(struct usbnet *usbnet, struct usb_interface *iface)
+{
+ struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
+
+ netif_carrier_off(usbnet->net);
+ qc_deregister(dev);
+
+ kfree(usbnet->net->netdev_ops);
+ usbnet->net->netdev_ops = NULL;
+
+ kfree(dev);
+}
+
+static void qcnet_urbhook(struct urb *urb)
+{
+ unsigned long flags;
+ struct worker *worker = urb->context;
+ if (!worker) {
+ DBG("bad context\n");
+ return;
+ }
+
+ if (urb->status) {
+ DBG("urb finished with error %d\n", urb->status);
+ }
+
+ spin_lock_irqsave(&worker->active_lock, flags);
+ worker->active = ERR_PTR(-EAGAIN);
+ spin_unlock_irqrestore(&worker->active_lock, flags);
+ /* XXX-fix race against qcnet_stop()? */
+ complete(&worker->work);
+ usb_free_urb(urb);
+}
+
+static void qcnet_txtimeout(struct net_device *netdev)
+{
+ struct list_head *node, *tmp;
+ struct qcusbnet *dev;
+ struct worker *worker;
+ struct urbreq *req;
+ unsigned long activeflags, listflags;
+ struct usbnet *usbnet = netdev_priv(netdev);
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get usbnet device\n");
+ return;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return;
+ }
+ worker = &dev->worker;
+
+ DBG("\n");
+
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ if (worker->active)
+ usb_kill_urb(worker->active);
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+
+ spin_lock_irqsave(&worker->urbs_lock, listflags);
+ list_for_each_safe(node, tmp, &worker->urbs) {
+ req = list_entry(node, struct urbreq, node);
+ usb_free_urb(req->urb);
+ list_del(&req->node);
+ kfree(req);
+ }
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+
+ complete(&worker->work);
+}
+
+static int qcnet_worker(void *arg)
+{
+ struct list_head *node, *tmp;
+ unsigned long activeflags, listflags;
+ struct urbreq *req;
+ int status;
+ struct usb_device *usbdev;
+ struct worker *worker = arg;
+ if (!worker) {
+ DBG("passed null pointer\n");
+ return -EINVAL;
+ }
+
+ usbdev = interface_to_usbdev(worker->iface);
+
+ DBG("traffic thread started\n");
+
+ while (!kthread_should_stop()) {
+ wait_for_completion_interruptible(&worker->work);
+
+ if (kthread_should_stop()) {
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ if (worker->active) {
+ usb_kill_urb(worker->active);
+ }
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+
+ spin_lock_irqsave(&worker->urbs_lock, listflags);
+ list_for_each_safe(node, tmp, &worker->urbs) {
+ req = list_entry(node, struct urbreq, node);
+ usb_free_urb(req->urb);
+ list_del(&req->node);
+ kfree(req);
+ }
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+
+ break;
+ }
+
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ if (IS_ERR(worker->active) && PTR_ERR(worker->active) == -EAGAIN) {
+ worker->active = NULL;
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+ usb_autopm_put_interface(worker->iface);
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ }
+
+ if (worker->active) {
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+ continue;
+ }
+
+ spin_lock_irqsave(&worker->urbs_lock, listflags);
+ if (list_empty(&worker->urbs)) {
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+ continue;
+ }
+
+ req = list_first_entry(&worker->urbs, struct urbreq, node);
+ list_del(&req->node);
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+
+ worker->active = req->urb;
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+
+ status = usb_autopm_get_interface(worker->iface);
+ if (status < 0) {
+ DBG("unable to autoresume interface: %d\n", status);
+ if (status == -EPERM) {
+ qc_suspend(worker->iface, PMSG_SUSPEND);
+ }
+
+ spin_lock_irqsave(&worker->urbs_lock, listflags);
+ list_add(&req->node, &worker->urbs);
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ worker->active = NULL;
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+
+ continue;
+ }
+
+ status = usb_submit_urb(worker->active, GFP_KERNEL);
+ if (status < 0) {
+ DBG("Failed to submit URB: %d. Packet dropped\n", status);
+ spin_lock_irqsave(&worker->active_lock, activeflags);
+ usb_free_urb(worker->active);
+ worker->active = NULL;
+ spin_unlock_irqrestore(&worker->active_lock, activeflags);
+ usb_autopm_put_interface(worker->iface);
+ complete(&worker->work);
+ }
+
+ kfree(req);
+ }
+
+ DBG("traffic thread exiting\n");
+ worker->thread = NULL;
+ return 0;
+}
+
+static int qcnet_startxmit(struct sk_buff *skb, struct net_device *netdev)
+{
+ unsigned long listflags;
+ struct qcusbnet *dev;
+ struct worker *worker;
+ struct urbreq *req;
+ void *data;
+ struct usbnet *usbnet = netdev_priv(netdev);
+
+ DBG("\n");
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get usbnet device\n");
+ return NETDEV_TX_BUSY;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return NETDEV_TX_BUSY;
+ }
+ worker = &dev->worker;
+
+ if (qc_isdown(dev, DOWN_DRIVER_SUSPENDED)) {
+ DBG("device is suspended\n");
+ dump_stack();
+ return NETDEV_TX_BUSY;
+ }
+
+ req = kmalloc(sizeof(*req), GFP_ATOMIC);
+ if (!req) {
+ DBG("unable to allocate URBList memory\n");
+ return NETDEV_TX_BUSY;
+ }
+
+ req->urb = usb_alloc_urb(0, GFP_ATOMIC);
+
+ if (!req->urb) {
+ kfree(req);
+ DBG("unable to allocate URB\n");
+ return NETDEV_TX_BUSY;
+ }
+
+ data = kmalloc(skb->len, GFP_ATOMIC);
+ if (!data) {
+ usb_free_urb(req->urb);
+ kfree(req);
+ DBG("unable to allocate URB data\n");
+ return NETDEV_TX_BUSY;
+ }
+ memcpy(data, skb->data, skb->len);
+
+ usb_fill_bulk_urb(req->urb, dev->usbnet->udev, dev->usbnet->out,
+ data, skb->len, qcnet_urbhook, worker);
+
+ spin_lock_irqsave(&worker->urbs_lock, listflags);
+ list_add_tail(&req->node, &worker->urbs);
+ spin_unlock_irqrestore(&worker->urbs_lock, listflags);
+
+ complete(&worker->work);
+
+ netdev->trans_start = jiffies;
+ dev_kfree_skb_any(skb);
+
+ return NETDEV_TX_OK;
+}
+
+static int qcnet_open(struct net_device *netdev)
+{
+ int status = 0;
+ struct qcusbnet *dev;
+ struct usbnet *usbnet = netdev_priv(netdev);
+
+ if (!usbnet) {
+ DBG("failed to get usbnet device\n");
+ return -ENXIO;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return -ENXIO;
+ }
+
+ DBG("\n");
+
+ dev->worker.iface = dev->iface;
+ INIT_LIST_HEAD(&dev->worker.urbs);
+ dev->worker.active = NULL;
+ spin_lock_init(&dev->worker.urbs_lock);
+ spin_lock_init(&dev->worker.active_lock);
+ init_completion(&dev->worker.work);
+
+ dev->worker.thread = kthread_run(qcnet_worker, &dev->worker, "qcnet_worker");
+ if (IS_ERR(dev->worker.thread)) {
+ DBG("AutoPM thread creation error\n");
+ return PTR_ERR(dev->worker.thread);
+ }
+
+ qc_cleardown(dev, DOWN_NET_IFACE_STOPPED);
+ if (dev->open) {
+ status = dev->open(netdev);
+ if (status == 0) {
+ usb_autopm_put_interface(dev->iface);
+ }
+ } else {
+ DBG("no USBNetOpen defined\n");
+ }
+
+ return status;
+}
+
+int qcnet_stop(struct net_device *netdev)
+{
+ struct qcusbnet *dev;
+ struct usbnet *usbnet = netdev_priv(netdev);
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get netdevice\n");
+ return -ENXIO;
+ }
+
+ dev = (struct qcusbnet *)usbnet->data[0];
+ if (!dev) {
+ DBG("failed to get QMIDevice\n");
+ return -ENXIO;
+ }
+
+ qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
+ complete(&dev->worker.work);
+ kthread_stop(dev->worker.thread);
+ DBG("thread stopped\n");
+
+ if (dev->stop != NULL)
+ return dev->stop(netdev);
+ return 0;
+}
+
+static const struct driver_info qc_netinfo = {
+ .description = "QCUSBNet Ethernet Device",
+ .flags = FLAG_ETHER,
+ .bind = qcnet_bind,
+ .unbind = qcnet_unbind,
+ .data = 0,
+};
+
+#define MKVIDPID(v, p) \
+{ \
+ USB_DEVICE(v, p), \
+ .driver_info = (unsigned long)&qc_netinfo, \
+}
+
+static const struct usb_device_id qc_vidpids[] = {
+ MKVIDPID(0x05c6, 0x9215), /* Acer Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9265), /* Asus Gobi 2000 */
+ MKVIDPID(0x16d8, 0x8002), /* CMOTech Gobi 2000 */
+ MKVIDPID(0x413c, 0x8186), /* Dell Gobi 2000 */
+ MKVIDPID(0x1410, 0xa010), /* Entourage Gobi 2000 */
+ MKVIDPID(0x1410, 0xa011), /* Entourage Gobi 2000 */
+ MKVIDPID(0x1410, 0xa012), /* Entourage Gobi 2000 */
+ MKVIDPID(0x1410, 0xa013), /* Entourage Gobi 2000 */
+ MKVIDPID(0x03f0, 0x251d), /* HP Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9205), /* Lenovo Gobi 2000 */
+ MKVIDPID(0x05c6, 0x920b), /* Generic Gobi 2000 */
+ MKVIDPID(0x04da, 0x250f), /* Panasonic Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9245), /* Samsung Gobi 2000 */
+ MKVIDPID(0x1199, 0x9001), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9002), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9003), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9004), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9005), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9006), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9007), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9008), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x9009), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x1199, 0x900a), /* Sierra Wireless Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9225), /* Sony Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9235), /* Top Global Gobi 2000 */
+ MKVIDPID(0x05c6, 0x9275), /* iRex Technologies Gobi 2000 */
+ { }
+};
+
+MODULE_DEVICE_TABLE(usb, qc_vidpids);
+
+int qcnet_probe(struct usb_interface *iface, const struct usb_device_id *vidpids)
+{
+ int status;
+ struct usbnet *usbnet;
+ struct qcusbnet *dev;
+ struct net_device_ops *netdevops;
+
+ status = usbnet_probe(iface, vidpids);
+ if (status < 0) {
+ DBG("usbnet_probe failed %d\n", status);
+ return status;
+ }
+
+ usbnet = usb_get_intfdata(iface);
+
+ if (!usbnet || !usbnet->net) {
+ DBG("failed to get netdevice\n");
+ return -ENXIO;
+ }
+
+ dev = kmalloc(sizeof(struct qcusbnet), GFP_KERNEL);
+ if (!dev) {
+ DBG("failed to allocate device buffers\n");
+ return -ENOMEM;
+ }
+
+ usbnet->data[0] = (unsigned long)dev;
+
+ dev->usbnet = usbnet;
+
+ netdevops = kmalloc(sizeof(struct net_device_ops), GFP_KERNEL);
+ if (!netdevops) {
+ DBG("failed to allocate net device ops\n");
+ return -ENOMEM;
+ }
+ memcpy(netdevops, usbnet->net->netdev_ops, sizeof(struct net_device_ops));
+
+ dev->open = netdevops->ndo_open;
+ netdevops->ndo_open = qcnet_open;
+ dev->stop = netdevops->ndo_stop;
+ netdevops->ndo_stop = qcnet_stop;
+ netdevops->ndo_start_xmit = qcnet_startxmit;
+ netdevops->ndo_tx_timeout = qcnet_txtimeout;
+
+ usbnet->net->netdev_ops = netdevops;
+
+ memset(&(dev->usbnet->net->stats), 0, sizeof(struct net_device_stats));
+
+ dev->iface = iface;
+ memset(&(dev->meid), '0', 14);
+
+ DBG("Mac Address: %pM\n", dev->usbnet->net->dev_addr);
+
+ dev->valid = false;
+ memset(&dev->qmi, 0, sizeof(struct qmidev));
+
+ dev->qmi.devclass = devclass;
+
+ INIT_LIST_HEAD(&dev->qmi.clients);
+ init_completion(&dev->worker.work);
+ spin_lock_init(&dev->qmi.clients_lock);
+
+ dev->down = 0;
+ qc_setdown(dev, DOWN_NO_NDIS_CONNECTION);
+ qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
+
+ status = qc_register(dev);
+ if (status) {
+ qc_deregister(dev);
+ }
+
+ return status;
+}
+EXPORT_SYMBOL_GPL(qcnet_probe);
+
+static struct usb_driver qcusbnet = {
+ .name = "QCUSBNet2k",
+ .id_table = qc_vidpids,
+ .probe = qcnet_probe,
+ .disconnect = usbnet_disconnect,
+ .suspend = qc_suspend,
+ .resume = qc_resume,
+ .supports_autosuspend = true,
+};
+
+static int __init modinit(void)
+{
+ devclass = class_create(THIS_MODULE, "QCQMI");
+ if (IS_ERR(devclass)) {
+ DBG("error at class_create %ld\n", PTR_ERR(devclass));
+ return -ENOMEM;
+ }
+ printk(KERN_INFO "%s: %s\n", DRIVER_DESC, DRIVER_VERSION);
+ return usb_register(&qcusbnet);
+}
+module_init(modinit);
+
+static void __exit modexit(void)
+{
+ usb_deregister(&qcusbnet);
+ class_destroy(devclass);
+}
+module_exit(modexit);
+
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("Dual BSD/GPL");
+
+module_param(qcusbnet_debug, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(qcusbnet_debug, "Debugging enabled or not");
diff --git a/drivers/net/usb/gobi/qcusbnet.h b/drivers/net/usb/gobi/qcusbnet.h
new file mode 100644
index 0000000..2f20868
--- /dev/null
+++ b/drivers/net/usb/gobi/qcusbnet.h
@@ -0,0 +1,24 @@
+/* qcusbnet.h - gobi network device header
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef QCUSBNET_QCUSBNET_H
+#define QCUSBNET_QCUSBNET_H
+
+extern int qc_suspend(struct usb_interface *iface, pm_message_t event);
+
+#endif /* !QCUSBNET_QCUSBNET_H */
diff --git a/drivers/net/usb/gobi/qmi.c b/drivers/net/usb/gobi/qmi.c
new file mode 100644
index 0000000..cdbdbaf
--- /dev/null
+++ b/drivers/net/usb/gobi/qmi.c
@@ -0,0 +1,358 @@
+/* qmi.c - QMI protocol implementation
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "qmi.h"
+
+#include <linux/slab.h>
+
+struct qmux {
+ u8 tf; /* always 1 */
+ u16 len;
+ u8 ctrl;
+ u8 service;
+ u8 qmicid;
+} __attribute__((__packed__));
+
+struct getcid_req {
+ struct qmux header;
+ u8 req;
+ u8 tid;
+ u16 msgid;
+ u16 tlvsize;
+ u8 service;
+ u16 size;
+ u8 qmisvc;
+} __attribute__((__packed__));
+
+struct releasecid_req {
+ struct qmux header;
+ u8 req;
+ u8 tid;
+ u16 msgid;
+ u16 tlvsize;
+ u8 rlscid;
+ u16 size;
+ u16 cid;
+} __attribute__((__packed__));
+
+struct ready_req {
+ struct qmux header;
+ u8 req;
+ u8 tid;
+ u16 msgid;
+ u16 tlvsize;
+} __attribute__((__packed__));
+
+struct seteventreport_req {
+ struct qmux header;
+ u8 req;
+ u16 tid;
+ u16 msgid;
+ u16 tlvsize;
+ u8 reportchanrate;
+ u16 size;
+ u8 period;
+ u32 mask;
+} __attribute__((__packed__));
+
+struct getpkgsrvcstatus_req {
+ struct qmux header;
+ u8 req;
+ u16 tid;
+ u16 msgid;
+ u16 tlvsize;
+} __attribute__((__packed__));
+
+struct getmeid_req {
+ struct qmux header;
+ u8 req;
+ u16 tid;
+ u16 msgid;
+ u16 tlvsize;
+} __attribute__((__packed__));
+
+const size_t qmux_size = sizeof(struct qmux);
+
+void *qmictl_new_getcid(u8 tid, u8 svctype, size_t *size)
+{
+ struct getcid_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return NULL;
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x0022;
+ req->tlvsize = 0x0004;
+ req->service = 0x01;
+ req->size = 0x0001;
+ req->qmisvc = svctype;
+ *size = sizeof(*req);
+ return req;
+}
+
+void *qmictl_new_releasecid(u8 tid, u16 cid, size_t *size)
+{
+ struct releasecid_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return NULL;
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x0023;
+ req->tlvsize = 0x05;
+ req->rlscid = 0x01;
+ req->size = 0x0002;
+ req->cid = cid;
+ *size = sizeof(*req);
+ return req;
+}
+
+void *qmictl_new_ready(u8 tid, size_t *size)
+{
+ struct ready_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return NULL;
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x21;
+ req->tlvsize = 0;
+ *size = sizeof(*req);
+ return req;
+}
+
+void *qmiwds_new_seteventreport(u8 tid, size_t *size)
+{
+ struct seteventreport_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x0001;
+ req->tlvsize = 0x0008;
+ req->reportchanrate = 0x11;
+ req->size = 0x0005;
+ req->period = 0x01;
+ req->mask = 0x000000ff;
+ *size = sizeof(*req);
+ return req;
+}
+
+void *qmiwds_new_getpkgsrvcstatus(u8 tid, size_t *size)
+{
+ struct getpkgsrvcstatus_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return NULL;
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x22;
+ req->tlvsize = 0x0000;
+ *size = sizeof(*req);
+ return req;
+}
+
+void *qmidms_new_getmeid(u8 tid, size_t *size)
+{
+ struct getmeid_req *req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return NULL;
+ req->req = 0x00;
+ req->tid = tid;
+ req->msgid = 0x25;
+ req->tlvsize = 0x0000;
+ *size = sizeof(*req);
+ return req;
+}
+
+int qmux_parse(u16 *cid, void *buf, size_t size)
+{
+ struct qmux *qmux = buf;
+
+ if (!buf || size < 12)
+ return -ENOMEM;
+
+ if (qmux->tf != 1 || qmux->len != size - 1 || qmux->ctrl != 0x80)
+ return -EINVAL;
+
+ *cid = (qmux->qmicid << 8) + qmux->service;
+ return sizeof(*qmux);
+}
+
+int qmux_fill(u16 cid, void *buf, size_t size)
+{
+ struct qmux *qmux = buf;
+
+ if (!buf || size < sizeof(*qmux))
+ return -ENOMEM;
+
+ qmux->tf = 1;
+ qmux->len = size - 1;
+ qmux->ctrl = 0;
+ qmux->service = cid & 0xff;
+ qmux->qmicid = cid >> 8;
+ return 0;
+}
+
+static u16 tlv_get(void *msg, u16 msgsize, u8 type, void *buf, u16 bufsize)
+{
+ u16 pos;
+ u16 msize = 0;
+
+ if (!msg || !buf)
+ return -ENOMEM;
+
+ for (pos = 4; pos + 3 < msgsize; pos += msize + 3) {
+ msize = *(u16 *)(msg + pos + 1);
+ if (*(u8 *)(msg + pos) == type) {
+ if (bufsize < msize)
+ return -ENOMEM;
+
+ memcpy(buf, msg + pos + 3, msize);
+ return msize;
+ }
+ }
+
+ return -ENOMSG;
+}
+
+int qmi_msgisvalid(void *msg, u16 size)
+{
+ char tlv[4];
+
+ if (tlv_get(msg, size, 2, &tlv[0], 4) == 4) {
+ if (*(u16 *)&tlv[0] != 0)
+ return *(u16 *)&tlv[2];
+ else
+ return 0;
+ }
+ return -ENOMSG;
+}
+
+int qmi_msgid(void *msg, u16 size)
+{
+ return size < 2 ? -ENODATA : *(u16 *)msg;
+}
+
+int qmictl_alloccid_resp(void *buf, u16 size, u16 *cid)
+{
+ int result;
+ u8 offset = sizeof(struct qmux) + 2;
+
+ if (!buf || size < offset)
+ return -ENOMEM;
+
+ buf = buf + offset;
+ size -= offset;
+
+ result = qmi_msgid(buf, size);
+ if (result != 0x22)
+ return -EFAULT;
+
+ result = qmi_msgisvalid(buf, size);
+ if (result != 0)
+ return -EFAULT;
+
+ result = tlv_get(buf, size, 0x01, cid, 2);
+ if (result != 2)
+ return -EFAULT;
+
+ return 0;
+}
+
+int qmictl_freecid_resp(void *buf, u16 size)
+{
+ int result;
+ u8 offset = sizeof(struct qmux) + 2;
+
+ if (!buf || size < offset)
+ return -ENOMEM;
+
+ buf = buf + offset;
+ size -= offset;
+
+ result = qmi_msgid(buf, size);
+ if (result != 0x23)
+ return -EFAULT;
+
+ result = qmi_msgisvalid(buf, size);
+ if (result != 0)
+ return -EFAULT;
+
+ return 0;
+}
+
+int qmiwds_event_resp(void *buf, u16 size, struct qmiwds_stats *stats)
+{
+ int result;
+ u8 status[2];
+
+ u8 offset = sizeof(struct qmux) + 3;
+
+ if (!buf || size < offset || !stats)
+ return -ENOMEM;
+
+ buf = buf + offset;
+ size -= offset;
+
+ result = qmi_msgid(buf, size);
+ if (result == 0x01) {
+ tlv_get(buf, size, 0x10, &stats->txok, 4);
+ tlv_get(buf, size, 0x11, &stats->rxok, 4);
+ tlv_get(buf, size, 0x12, &stats->txerr, 4);
+ tlv_get(buf, size, 0x13, &stats->rxerr, 4);
+ tlv_get(buf, size, 0x14, &stats->txofl, 4);
+ tlv_get(buf, size, 0x15, &stats->rxofl, 4);
+ tlv_get(buf, size, 0x19, &stats->txbytesok, 8);
+ tlv_get(buf, size, 0x1A, &stats->rxbytesok, 8);
+ } else if (result == 0x22) {
+ result = tlv_get(buf, size, 0x01, &status[0], 2);
+ if (result >= 1)
+ stats->linkstate = status[0] == 0x02;
+ if (result == 2)
+ stats->reconfigure = status[1] == 0x01;
+
+ if (result < 0)
+ return result;
+ } else {
+ return -EFAULT;
+ }
+
+ return 0;
+}
+
+int qmidms_meid_resp(void *buf, u16 size, char *meid, int meidsize)
+{
+ int result;
+
+ u8 offset = sizeof(struct qmux) + 3;
+
+ if (!buf || size < offset || meidsize < 14)
+ return -ENOMEM;
+
+ buf = buf + offset;
+ size -= offset;
+
+ result = qmi_msgid(buf, size);
+ if (result != 0x25)
+ return -EFAULT;
+
+ result = qmi_msgisvalid(buf, size);
+ if (result)
+ return -EFAULT;
+
+ result = tlv_get(buf, size, 0x12, meid, 14);
+ if (result != 14)
+ return -EFAULT;
+
+ return 0;
+}
diff --git a/drivers/net/usb/gobi/qmi.h b/drivers/net/usb/gobi/qmi.h
new file mode 100644
index 0000000..7954790
--- /dev/null
+++ b/drivers/net/usb/gobi/qmi.h
@@ -0,0 +1,67 @@
+/* qmi.h - QMI protocol header
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef QCUSBNET_QMI_H
+#define QCUSBNET_QMI_H
+
+#include <linux/types.h>
+
+#define QMICTL 0
+#define QMIWDS 1
+#define QMIDMS 2
+
+#define true 1
+#define false 0
+
+#define ENOMEM 12
+#define EFAULT 14
+#define EINVAL 22
+#define ENOMSG 42
+#define ENODATA 61
+
+int qmux_parse(u16 *cid, void *buf, size_t size);
+int qmux_fill(u16 cid, void *buf, size_t size);
+
+extern const size_t qmux_size;
+
+void *qmictl_new_getcid(u8 tid, u8 svctype, size_t *size);
+void *qmictl_new_releasecid(u8 tid, u16 cid, size_t *size);
+void *qmictl_new_ready(u8 tid, size_t *size);
+void *qmiwds_new_seteventreport(u8 tid, size_t *size);
+void *qmiwds_new_getpkgsrvcstatus(u8 tid, size_t *size);
+void *qmidms_new_getmeid(u8 tid, size_t *size);
+
+struct qmiwds_stats {
+ u32 txok;
+ u32 rxok;
+ u32 txerr;
+ u32 rxerr;
+ u32 txofl;
+ u32 rxofl;
+ u64 txbytesok;
+ u64 rxbytesok;
+ bool linkstate;
+ bool reconfigure;
+};
+
+int qmictl_alloccid_resp(void *buf, u16 size, u16 *cid);
+int qmictl_freecid_resp(void *buf, u16 size);
+int qmiwds_event_resp(void *buf, u16 size, struct qmiwds_stats *stats);
+int qmidms_meid_resp(void *buf, u16 size, char *meid, int meidsize);
+
+#endif /* !QCUSBNET_QMI_H */
diff --git a/drivers/net/usb/gobi/qmidevice.c b/drivers/net/usb/gobi/qmidevice.c
new file mode 100644
index 0000000..d1cb341
--- /dev/null
+++ b/drivers/net/usb/gobi/qmidevice.c
@@ -0,0 +1,1590 @@
+/* qmidevice.c - gobi QMI device
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "qmidevice.h"
+#include "qcusbnet.h"
+
+struct readreq {
+ struct list_head node;
+ void *data;
+ u16 tid;
+ u16 size;
+};
+
+struct notifyreq {
+ struct list_head node;
+ void (*func)(struct qcusbnet *, u16, void *);
+ u16 tid;
+ void *data;
+};
+
+struct client {
+ struct list_head node;
+ u16 cid;
+ struct list_head reads;
+ struct list_head notifies;
+ struct list_head urbs;
+};
+
+struct urbsetup {
+ u8 type;
+ u8 code;
+ u16 value;
+ u16 index;
+ u16 len;
+};
+
+struct qmihandle {
+ u16 cid;
+ struct qcusbnet *dev;
+};
+
+extern int qcusbnet_debug;
+static int qcusbnet2k_fwdelay;
+
+static bool device_valid(struct qcusbnet *dev);
+static struct client *client_bycid(struct qcusbnet *dev, u16 cid);
+static bool client_addread(struct qcusbnet *dev, u16 cid, u16 tid, void *data, u16 size);
+static bool client_delread(struct qcusbnet *dev, u16 cid, u16 tid, void **data, u16 *size);
+static bool client_addnotify(struct qcusbnet *dev, u16 cid, u16 tid,
+ void (*hook)(struct qcusbnet *, u16 cid, void *),
+ void *data);
+static bool client_notify(struct qcusbnet *dev, u16 cid, u16 tid);
+static bool client_addurb(struct qcusbnet *dev, u16 cid, struct urb *urb);
+static struct urb *client_delurb(struct qcusbnet *dev, u16 cid);
+
+static int devqmi_open(struct inode *inode, struct file *file);
+static long devqmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+static int devqmi_close(struct file *file, fl_owner_t ftable);
+static ssize_t devqmi_read(struct file *file, char __user *buf, size_t size,
+ loff_t *pos);
+static ssize_t devqmi_write(struct file *file, const char __user *buf,
+ size_t size, loff_t *pos);
+
+static bool qmi_ready(struct qcusbnet *dev, u16 timeout);
+static void wds_callback(struct qcusbnet *dev, u16 cid, void *data);
+static int setup_wds_callback(struct qcusbnet *dev);
+static int qmidms_getmeid(struct qcusbnet *dev);
+
+#define IOCTL_QMI_GET_SERVICE_FILE (0x8BE0 + 1)
+#define IOCTL_QMI_GET_DEVICE_VIDPID (0x8BE0 + 2)
+#define IOCTL_QMI_GET_DEVICE_MEID (0x8BE0 + 3)
+#define CDC_GET_ENCAPSULATED_RESPONSE 0x01A1ll
+#define CDC_CONNECTION_SPEED_CHANGE 0x08000000002AA1ll
+
+static const struct file_operations devqmi_fops = {
+ .owner = THIS_MODULE,
+ .read = devqmi_read,
+ .write = devqmi_write,
+ .unlocked_ioctl = devqmi_ioctl,
+ .open = devqmi_open,
+ .flush = devqmi_close,
+};
+
+#ifdef CONFIG_SMP
+static inline void assert_locked(struct qcusbnet *dev)
+{
+ BUG_ON(!spin_is_locked(&dev->qmi.clients_lock));
+}
+#else
+static inline void assert_locked(struct qcusbnet *dev)
+{
+
+}
+#endif
+
+static bool device_valid(struct qcusbnet *dev)
+{
+ return dev && dev->valid;
+}
+
+void qc_setdown(struct qcusbnet *dev, u8 reason)
+{
+ set_bit(reason, &dev->down);
+ netif_carrier_off(dev->usbnet->net);
+}
+
+void qc_cleardown(struct qcusbnet *dev, u8 reason)
+{
+ clear_bit(reason, &dev->down);
+ if (!dev->down)
+ netif_carrier_on(dev->usbnet->net);
+}
+
+bool qc_isdown(struct qcusbnet *dev, u8 reason)
+{
+ return test_bit(reason, &dev->down);
+}
+
+static void read_callback(struct urb *urb)
+{
+ struct list_head *node;
+ int result;
+ u16 cid;
+ struct client *client;
+ void *data;
+ void *copy;
+ u16 size;
+ struct qcusbnet *dev;
+ unsigned long flags;
+ u16 tid;
+
+ if (!urb) {
+ DBG("bad read URB\n");
+ return;
+ }
+
+ dev = urb->context;
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return;
+ }
+
+ if (urb->status) {
+ DBG("Read status = %d\n", urb->status);
+ return;
+ }
+
+ DBG("Read %d bytes\n", urb->actual_length);
+
+ data = urb->transfer_buffer;
+ size = urb->actual_length;
+
+ print_hex_dump(KERN_INFO, "QCUSBNet2k: ", DUMP_PREFIX_OFFSET,
+ 16, 1, data, size, true);
+
+ result = qmux_parse(&cid, data, size);
+ if (result < 0) {
+ DBG("Read error parsing QMUX %d\n", result);
+ return;
+ }
+
+ if (size < result + 3) {
+ DBG("Data buffer too small to parse\n");
+ return;
+ }
+
+ if (cid == QMICTL)
+ tid = *(u8 *)(data + result + 1);
+ else
+ tid = *(u16 *)(data + result + 1);
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+
+ list_for_each(node, &dev->qmi.clients) {
+ client = list_entry(node, struct client, node);
+ if (client->cid == cid || (client->cid | 0xff00) == cid) {
+ copy = kmalloc(size, GFP_ATOMIC);
+ memcpy(copy, data, size);
+ if (!client_addread(dev, client->cid, tid, copy, size)) {
+ DBG("Error allocating pReadMemListEntry "
+ "read will be discarded\n");
+ kfree(copy);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return;
+ }
+
+ DBG("Creating new readListEntry for client 0x%04X, TID %x\n",
+ cid, tid);
+
+ client_notify(dev, client->cid, tid);
+
+ if (cid >> 8 != 0xff)
+ break;
+ }
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+}
+
+static void int_callback(struct urb *urb)
+{
+ int status;
+ int interval;
+ struct qcusbnet *dev = (struct qcusbnet *)urb->context;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return;
+ }
+
+ if (urb->status) {
+ DBG("Int status = %d\n", urb->status);
+ if (urb->status != -EOVERFLOW)
+ return;
+ } else {
+ if ((urb->actual_length == 8) &&
+ (*(u64 *)urb->transfer_buffer == CDC_GET_ENCAPSULATED_RESPONSE)) {
+ usb_fill_control_urb(dev->qmi.readurb, dev->usbnet->udev,
+ usb_rcvctrlpipe(dev->usbnet->udev, 0),
+ (unsigned char *)dev->qmi.readsetup,
+ dev->qmi.readbuf,
+ DEFAULT_READ_URB_LENGTH,
+ read_callback, dev);
+ status = usb_submit_urb(dev->qmi.readurb, GFP_ATOMIC);
+ if (status) {
+ DBG("Error submitting Read URB %d\n", status);
+ return;
+ }
+ } else if ((urb->actual_length == 16) &&
+ (*(u64 *)urb->transfer_buffer == CDC_CONNECTION_SPEED_CHANGE)) {
+ /* if upstream or downstream is 0, stop traffic.
+ * Otherwise resume it */
+ if ((*(u32 *)(urb->transfer_buffer + 8) == 0) ||
+ (*(u32 *)(urb->transfer_buffer + 12) == 0)) {
+ qc_setdown(dev, DOWN_CDC_CONNECTION_SPEED);
+ DBG("traffic stopping due to CONNECTION_SPEED_CHANGE\n");
+ } else {
+ qc_cleardown(dev, DOWN_CDC_CONNECTION_SPEED);
+ DBG("resuming traffic due to CONNECTION_SPEED_CHANGE\n");
+ }
+ } else {
+ DBG("ignoring invalid interrupt in packet\n");
+ print_hex_dump(KERN_INFO, "QCUSBNet2k: ",
+ DUMP_PREFIX_OFFSET, 16, 1,
+ urb->transfer_buffer,
+ urb->actual_length, true);
+ }
+ }
+
+ interval = (dev->usbnet->udev->speed == USB_SPEED_HIGH) ? 7 : 3;
+
+ usb_fill_int_urb(urb, urb->dev, urb->pipe, urb->transfer_buffer,
+ urb->transfer_buffer_length, urb->complete,
+ urb->context, interval);
+ status = usb_submit_urb(urb, GFP_ATOMIC);
+ if (status)
+ DBG("Error re-submitting Int URB %d\n", status);
+ return;
+}
+
+int qc_startread(struct qcusbnet *dev)
+{
+ int interval;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ dev->qmi.readurb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!dev->qmi.readurb) {
+ DBG("Error allocating read urb\n");
+ return -ENOMEM;
+ }
+
+ dev->qmi.inturb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!dev->qmi.inturb) {
+ usb_free_urb(dev->qmi.readurb);
+ DBG("Error allocating int urb\n");
+ return -ENOMEM;
+ }
+
+ dev->qmi.readbuf = kmalloc(DEFAULT_READ_URB_LENGTH, GFP_KERNEL);
+ if (!dev->qmi.readbuf) {
+ usb_free_urb(dev->qmi.readurb);
+ usb_free_urb(dev->qmi.inturb);
+ DBG("Error allocating read buffer\n");
+ return -ENOMEM;
+ }
+
+ dev->qmi.intbuf = kmalloc(DEFAULT_READ_URB_LENGTH, GFP_KERNEL);
+ if (!dev->qmi.intbuf) {
+ usb_free_urb(dev->qmi.readurb);
+ usb_free_urb(dev->qmi.inturb);
+ kfree(dev->qmi.readbuf);
+ DBG("Error allocating int buffer\n");
+ return -ENOMEM;
+ }
+
+ dev->qmi.readsetup = kmalloc(sizeof(*dev->qmi.readsetup), GFP_KERNEL);
+ if (!dev->qmi.readsetup) {
+ usb_free_urb(dev->qmi.readurb);
+ usb_free_urb(dev->qmi.inturb);
+ kfree(dev->qmi.readbuf);
+ kfree(dev->qmi.intbuf);
+ DBG("Error allocating setup packet buffer\n");
+ return -ENOMEM;
+ }
+
+ dev->qmi.readsetup->type = 0xA1;
+ dev->qmi.readsetup->code = 1;
+ dev->qmi.readsetup->value = 0;
+ dev->qmi.readsetup->index = 0;
+ dev->qmi.readsetup->len = DEFAULT_READ_URB_LENGTH;
+
+ interval = (dev->usbnet->udev->speed == USB_SPEED_HIGH) ? 7 : 3;
+
+ usb_fill_int_urb(dev->qmi.inturb, dev->usbnet->udev,
+ usb_rcvintpipe(dev->usbnet->udev, 0x81),
+ dev->qmi.intbuf, DEFAULT_READ_URB_LENGTH,
+ int_callback, dev, interval);
+ return usb_submit_urb(dev->qmi.inturb, GFP_KERNEL);
+}
+
+void qc_stopread(struct qcusbnet *dev)
+{
+ if (dev->qmi.readurb) {
+ DBG("Killing read URB\n");
+ usb_kill_urb(dev->qmi.readurb);
+ }
+
+ if (dev->qmi.inturb) {
+ DBG("Killing int URB\n");
+ usb_kill_urb(dev->qmi.inturb);
+ }
+
+ kfree(dev->qmi.readsetup);
+ dev->qmi.readsetup = NULL;
+ kfree(dev->qmi.readbuf);
+ dev->qmi.readbuf = NULL;
+ kfree(dev->qmi.intbuf);
+ dev->qmi.intbuf = NULL;
+
+ usb_free_urb(dev->qmi.readurb);
+ dev->qmi.readurb = NULL;
+ usb_free_urb(dev->qmi.inturb);
+ dev->qmi.inturb = NULL;
+}
+
+static int read_async(struct qcusbnet *dev, u16 cid, u16 tid,
+ void (*hook)(struct qcusbnet *, u16, void *),
+ void *data)
+{
+ struct list_head *node;
+ struct client *client;
+ struct readreq *readreq;
+
+ unsigned long flags;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find matching client ID 0x%04X\n", cid);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -ENXIO;
+ }
+
+ list_for_each(node, &client->reads) {
+ readreq = list_entry(node, struct readreq, node);
+ if (!tid || tid == readreq->tid) {
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ hook(dev, cid, data);
+ return 0;
+ }
+ }
+
+ if (!client_addnotify(dev, cid, tid, hook, data))
+ DBG("Unable to register for notification\n");
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return 0;
+}
+
+static void upsem(struct qcusbnet *dev, u16 cid, void *data)
+{
+ DBG("0x%04X\n", cid);
+ up((struct semaphore *)data);
+}
+
+static int read_sync(struct qcusbnet *dev, void **buf, u16 cid, u16 tid)
+{
+ struct list_head *node;
+ int result;
+ struct client *client;
+ struct notifyreq *notify;
+ struct semaphore sem;
+ void *data;
+ unsigned long flags;
+ u16 size;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find matching client ID 0x%04X\n", cid);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -ENXIO;
+ }
+
+ while (!client_delread(dev, cid, tid, &data, &size)) {
+ sema_init(&sem, 0);
+ if (!client_addnotify(dev, cid, tid, upsem, &sem)) {
+ DBG("unable to register for notification\n");
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -EFAULT;
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+
+ result = down_interruptible(&sem);
+ if (result) {
+ DBG("Interrupted %d\n", result);
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ list_for_each(node, &client->notifies) {
+ notify = list_entry(node, struct notifyreq, node);
+ if (notify->data == &sem) {
+ list_del(¬ify->node);
+ kfree(notify);
+ break;
+ }
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -EINTR;
+ }
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ *buf = data;
+ return size;
+}
+
+static void write_callback(struct urb *urb)
+{
+ if (!urb) {
+ DBG("null urb\n");
+ return;
+ }
+
+ DBG("Write status/size %d/%d\n", urb->status, urb->actual_length);
+ up((struct semaphore *)urb->context);
+}
+
+static int write_sync(struct qcusbnet *dev, char *buf, int size, u16 cid)
+{
+ int result;
+ struct semaphore sem;
+ struct urb *urb;
+ struct urbsetup setup;
+ unsigned long flags;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ urb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!urb) {
+ DBG("URB mem error\n");
+ return -ENOMEM;
+ }
+
+ result = qmux_fill(cid, buf, size);
+ if (result < 0) {
+ usb_free_urb(urb);
+ return result;
+ }
+
+ /* CDC Send Encapsulated Request packet */
+ setup.type = 0x21;
+ setup.code = 0;
+ setup.value = 0;
+ setup.index = 0;
+ setup.len = 0;
+ setup.len = size;
+
+ usb_fill_control_urb(urb, dev->usbnet->udev,
+ usb_sndctrlpipe(dev->usbnet->udev, 0),
+ (unsigned char *)&setup, (void *)buf, size,
+ NULL, dev);
+
+ DBG("Actual Write:\n");
+ print_hex_dump(KERN_INFO, "QCUSBNet2k: ", DUMP_PREFIX_OFFSET,
+ 16, 1, buf, size, true);
+
+ sema_init(&sem, 0);
+
+ urb->complete = write_callback;
+ urb->context = &sem;
+
+ result = usb_autopm_get_interface(dev->iface);
+ if (result < 0) {
+ DBG("unable to resume interface: %d\n", result);
+ if (result == -EPERM) {
+ qc_suspend(dev->iface, PMSG_SUSPEND);
+ }
+ return result;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+
+ if (!client_addurb(dev, cid, urb)) {
+ usb_free_urb(urb);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ usb_autopm_put_interface(dev->iface);
+ return -EINVAL;
+ }
+
+ result = usb_submit_urb(urb, GFP_KERNEL);
+ if (result < 0) {
+ DBG("submit URB error %d\n", result);
+ if (client_delurb(dev, cid) != urb) {
+ DBG("Didn't get write URB back\n");
+ }
+
+ usb_free_urb(urb);
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ usb_autopm_put_interface(dev->iface);
+ return result;
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ result = down_interruptible(&sem);
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ usb_autopm_put_interface(dev->iface);
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ if (client_delurb(dev, cid) != urb) {
+ DBG("Didn't get write URB back\n");
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -EINVAL;
+ }
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+
+ if (!result) {
+ if (!urb->status) {
+ result = size;
+ } else {
+ DBG("bad status = %d\n", urb->status);
+ result = urb->status;
+ }
+ } else {
+ DBG("Interrupted %d !!!\n", result);
+ DBG("Device may be in bad state and need reset !!!\n");
+ usb_kill_urb(urb);
+ }
+
+ usb_free_urb(urb);
+ return result;
+}
+
+static int client_alloc(struct qcusbnet *dev, u8 type)
+{
+ u16 cid;
+ struct client *client;
+ int result;
+ void *wbuf;
+ size_t wbufsize;
+ void *rbuf;
+ u16 rbufsize;
+ unsigned long flags;
+ u8 tid;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device!\n");
+ return -ENXIO;
+ }
+
+ if (type) {
+ tid = atomic_add_return(1, &dev->qmi.qmitid);
+ if (!tid)
+ atomic_add_return(1, &dev->qmi.qmitid);
+ wbuf = qmictl_new_getcid(tid, type, &wbufsize);
+ if (!wbuf)
+ return -ENOMEM;
+ result = write_sync(dev, wbuf, wbufsize, QMICTL);
+ kfree(wbuf);
+
+ if (result < 0)
+ return result;
+
+ result = read_sync(dev, &rbuf, QMICTL, tid);
+ if (result < 0) {
+ DBG("bad read data %d\n", result);
+ return result;
+ }
+ rbufsize = result;
+
+ result = qmictl_alloccid_resp(rbuf, rbufsize, &cid);
+ kfree(rbuf);
+
+ if (result < 0)
+ return result;
+ } else {
+ cid = 0;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ if (client_bycid(dev, cid)) {
+ DBG("Client memory already exists\n");
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -ETOOMANYREFS;
+ }
+
+ client = kmalloc(sizeof(*client), GFP_ATOMIC);
+ if (!client) {
+ DBG("Error allocating read list\n");
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return -ENOMEM;
+ }
+
+ list_add_tail(&client->node, &dev->qmi.clients);
+ client->cid = cid;
+ INIT_LIST_HEAD(&client->reads);
+ INIT_LIST_HEAD(&client->notifies);
+ INIT_LIST_HEAD(&client->urbs);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ return cid;
+}
+
+static void client_free(struct qcusbnet *dev, u16 cid)
+{
+ struct list_head *node, *tmp;
+ int result;
+ struct client *client;
+ struct urb *urb;
+ void *data;
+ u16 size;
+ void *wbuf;
+ size_t wbufsize;
+ void *rbuf;
+ u16 rbufsize;
+ unsigned long flags;
+ u8 tid;
+
+ if (!device_valid(dev)) {
+ DBG("invalid device\n");
+ return;
+ }
+
+ DBG("releasing 0x%04X\n", cid);
+
+ if (cid != QMICTL) {
+ tid = atomic_add_return(1, &dev->qmi.qmitid);
+ if (!tid)
+ tid = atomic_add_return(1, &dev->qmi.qmitid);
+ wbuf = qmictl_new_releasecid(tid, cid, &wbufsize);
+ if (!wbuf) {
+ DBG("memory error\n");
+ } else {
+ result = write_sync(dev, wbuf, wbufsize, QMICTL);
+ kfree(wbuf);
+
+ if (result < 0) {
+ DBG("bad write status %d\n", result);
+ } else {
+ result = read_sync(dev, &rbuf, QMICTL, tid);
+ if (result < 0) {
+ DBG("bad read status %d\n", result);
+ } else {
+ rbufsize = result;
+ result = qmictl_freecid_resp(rbuf, rbufsize);
+ kfree(rbuf);
+ if (result < 0)
+ DBG("error %d parsing response\n", result);
+ }
+ }
+ }
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ list_for_each_safe(node, tmp, &dev->qmi.clients) {
+ client = list_entry(node, struct client, node);
+ if (client->cid == cid) {
+ while (client_notify(dev, cid, 0)) {
+ ;
+ }
+
+ urb = client_delurb(dev, cid);
+ while (urb != NULL) {
+ usb_kill_urb(urb);
+ usb_free_urb(urb);
+ urb = client_delurb(dev, cid);
+ }
+
+ while (client_delread(dev, cid, 0, &data, &size))
+ kfree(data);
+
+ list_del(&client->node);
+ kfree(client);
+ }
+ }
+
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+}
+
+struct client *client_bycid(struct qcusbnet *dev, u16 cid)
+{
+ struct list_head *node;
+ struct client *client;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return NULL;
+ }
+
+ assert_locked(dev);
+
+ list_for_each(node, &dev->qmi.clients) {
+ client = list_entry(node, struct client, node);
+ if (client->cid == cid)
+ return client;
+ }
+
+ DBG("Could not find client mem 0x%04X\n", cid);
+ return NULL;
+}
+
+static bool client_addread(struct qcusbnet *dev, u16 cid, u16 tid, void *data,
+ u16 size)
+{
+ struct client *client;
+ struct readreq *req;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return false;
+ }
+
+ req = kmalloc(sizeof(*req), GFP_ATOMIC);
+ if (!req) {
+ DBG("Mem error\n");
+ return false;
+ }
+
+ req->data = data;
+ req->size = size;
+ req->tid = tid;
+
+ list_add_tail(&req->node, &client->reads);
+
+ return true;
+}
+
+static bool client_delread(struct qcusbnet *dev, u16 cid, u16 tid, void **data,
+ u16 *size)
+{
+ struct client *client;
+ struct readreq *req;
+ struct list_head *node;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return false;
+ }
+
+ list_for_each(node, &client->reads) {
+ req = list_entry(node, struct readreq, node);
+ if (!tid || tid == req->tid) {
+ *data = req->data;
+ *size = req->size;
+ list_del(&req->node);
+ kfree(req);
+ return true;
+ }
+
+ DBG("skipping 0x%04X data TID = %x\n", cid, req->tid);
+ }
+
+ DBG("No read memory to pop, Client 0x%04X, TID = %x\n", cid, tid);
+ return false;
+}
+
+static bool client_addnotify(struct qcusbnet *dev, u16 cid, u16 tid,
+ void (*hook)(struct qcusbnet *, u16, void *),
+ void *data)
+{
+ struct client *client;
+ struct notifyreq *req;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return false;
+ }
+
+ req = kmalloc(sizeof(*req), GFP_ATOMIC);
+ if (!req) {
+ DBG("Mem error\n");
+ return false;
+ }
+
+ list_add_tail(&req->node, &client->notifies);
+ req->func = hook;
+ req->data = data;
+ req->tid = tid;
+
+ return true;
+}
+
+static bool client_notify(struct qcusbnet *dev, u16 cid, u16 tid)
+{
+ struct client *client;
+ struct notifyreq *delnotify, *notify;
+ struct list_head *node;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return false;
+ }
+
+ delnotify = NULL;
+
+ list_for_each(node, &client->notifies) {
+ notify = list_entry(node, struct notifyreq, node);
+ if (!tid || !notify->tid || tid == notify->tid) {
+ delnotify = notify;
+ break;
+ }
+
+ DBG("skipping data TID = %x\n", notify->tid);
+ }
+
+ if (delnotify) {
+ list_del(&delnotify->node);
+ if (delnotify->func) {
+ spin_unlock(&dev->qmi.clients_lock);
+ delnotify->func(dev, cid, delnotify->data);
+ spin_lock(&dev->qmi.clients_lock);
+ }
+ kfree(delnotify);
+ return true;
+ }
+
+ DBG("no one to notify for TID %x\n", tid);
+ return false;
+}
+
+static bool client_addurb(struct qcusbnet *dev, u16 cid, struct urb *urb)
+{
+ struct client *client;
+ struct urbreq *req;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return false;
+ }
+
+ req = kmalloc(sizeof(*req), GFP_ATOMIC);
+ if (!req) {
+ DBG("Mem error\n");
+ return false;
+ }
+
+ req->urb = urb;
+ list_add_tail(&req->node, &client->urbs);
+
+ return true;
+}
+
+static struct urb *client_delurb(struct qcusbnet *dev, u16 cid)
+{
+ struct client *client;
+ struct urbreq *req;
+ struct urb *urb;
+
+ assert_locked(dev);
+
+ client = client_bycid(dev, cid);
+ if (!client) {
+ DBG("Could not find this client's memory 0x%04X\n", cid);
+ return NULL;
+ }
+
+ if (list_empty(&client->urbs)) {
+ DBG("No URB's to pop\n");
+ return NULL;
+ }
+
+ req = list_first_entry(&client->urbs, struct urbreq, node);
+ list_del(&req->node);
+ urb = req->urb;
+ kfree(req);
+ return urb;
+}
+
+static int devqmi_open(struct inode *inode, struct file *file)
+{
+ struct qmihandle *handle;
+ struct qmidev *qmidev = container_of(inode->i_cdev, struct qmidev, cdev);
+ struct qcusbnet *dev = container_of(qmidev, struct qcusbnet, qmi);
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return -ENXIO;
+ }
+
+ file->private_data = kmalloc(sizeof(struct qmihandle), GFP_KERNEL);
+ if (!file->private_data) {
+ DBG("Mem error\n");
+ return -ENOMEM;
+ }
+
+ handle = (struct qmihandle *)file->private_data;
+ handle->cid = (u16)-1;
+ handle->dev = dev;
+
+ return 0;
+}
+
+static long devqmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+ int result;
+ u32 vidpid;
+
+ struct qmihandle *handle = (struct qmihandle *)file->private_data;
+
+ if (!handle) {
+ DBG("Bad file data\n");
+ return -EBADF;
+ }
+
+ if (!device_valid(handle->dev)) {
+ DBG("Invalid device! Updating f_ops\n");
+ file->f_op = file->f_dentry->d_inode->i_fop;
+ return -ENXIO;
+ }
+
+ switch (cmd) {
+ case IOCTL_QMI_GET_SERVICE_FILE:
+
+ DBG("Setting up QMI for service %lu\n", arg);
+ if (!(u8)arg) {
+ DBG("Cannot use QMICTL from userspace\n");
+ return -EINVAL;
+ }
+
+ if (handle->cid != (u16)-1) {
+ DBG("Close the current connection before opening a new one\n");
+ return -EBADR;
+ }
+
+ result = client_alloc(handle->dev, (u8)arg);
+ if (result < 0)
+ return result;
+ handle->cid = result;
+
+ return 0;
+ break;
+
+
+ case IOCTL_QMI_GET_DEVICE_VIDPID:
+ if (!arg) {
+ DBG("Bad VIDPID buffer\n");
+ return -EINVAL;
+ }
+
+ if (!handle->dev->usbnet) {
+ DBG("Bad usbnet\n");
+ return -ENOMEM;
+ }
+
+ if (!handle->dev->usbnet->udev) {
+ DBG("Bad udev\n");
+ return -ENOMEM;
+ }
+
+ vidpid = ((le16_to_cpu(handle->dev->usbnet->udev->descriptor.idVendor) << 16)
+ + le16_to_cpu(handle->dev->usbnet->udev->descriptor.idProduct));
+
+ result = copy_to_user((unsigned int *)arg, &vidpid, 4);
+ if (result)
+ DBG("Copy to userspace failure\n");
+
+ return result;
+ break;
+
+ case IOCTL_QMI_GET_DEVICE_MEID:
+ if (!arg) {
+ DBG("Bad MEID buffer\n");
+ return -EINVAL;
+ }
+
+ result = copy_to_user((unsigned int *)arg, &handle->dev->meid[0], 14);
+ if (result)
+ DBG("copy to userspace failure\n");
+
+ return result;
+ break;
+ default:
+ return -EBADRQC;
+ }
+}
+
+static int devqmi_close(struct file *file, fl_owner_t ftable)
+{
+ struct qmihandle *handle = (struct qmihandle *)file->private_data;
+ struct list_head *tasks;
+ struct task_struct *task;
+ struct fdtable *fdtable;
+ int count = 0;
+ int used = 0;
+ unsigned long flags;
+
+ if (!handle) {
+ DBG("bad file data\n");
+ return -EBADF;
+ }
+
+ if (file_count(file) != 1) {
+ /* XXX: This can't possibly be safe. We don't hold any sort of
+ * lock here, and we're walking a list of threads... */
+ list_for_each(tasks, ¤t->group_leader->tasks) {
+ task = container_of(tasks, struct task_struct, tasks);
+ if (!task || !task->files)
+ continue;
+ spin_lock_irqsave(&task->files->file_lock, flags);
+ fdtable = files_fdtable(task->files);
+ for (count = 0; count < fdtable->max_fds; count++) {
+ /* Before this function was called, this file was removed
+ * from our task's file table so if we find it in a file
+ * table then it is being used by another task
+ */
+ if (fdtable->fd[count] == file) {
+ used++;
+ break;
+ }
+ }
+ spin_unlock_irqrestore(&task->files->file_lock, flags);
+ }
+
+ if (used > 0) {
+ DBG("not closing, as this FD is open by %d other process\n", used);
+ return 0;
+ }
+ }
+
+ if (!device_valid(handle->dev)) {
+ DBG("Invalid device! Updating f_ops\n");
+ file->f_op = file->f_dentry->d_inode->i_fop;
+ return -ENXIO;
+ }
+
+ DBG("0x%04X\n", handle->cid);
+
+ file->private_data = NULL;
+
+ if (handle->cid != (u16)-1)
+ client_free(handle->dev, handle->cid);
+
+ kfree(handle);
+ return 0;
+}
+
+static ssize_t devqmi_read(struct file *file, char __user *buf, size_t size,
+ loff_t *pos)
+{
+ int result;
+ void *data = NULL;
+ void *smalldata;
+ struct qmihandle *handle = (struct qmihandle *)file->private_data;
+
+ if (!handle) {
+ DBG("Bad file data\n");
+ return -EBADF;
+ }
+
+ if (!device_valid(handle->dev)) {
+ DBG("Invalid device! Updating f_ops\n");
+ file->f_op = file->f_dentry->d_inode->i_fop;
+ return -ENXIO;
+ }
+
+ if (handle->cid == (u16)-1) {
+ DBG("Client ID must be set before reading 0x%04X\n",
+ handle->cid);
+ return -EBADR;
+ }
+
+ result = read_sync(handle->dev, &data, handle->cid, 0);
+ if (result <= 0)
+ return result;
+
+ result -= qmux_size;
+ smalldata = data + qmux_size;
+
+ if (result > size) {
+ DBG("Read data is too large for amount user has requested\n");
+ kfree(data);
+ return -EOVERFLOW;
+ }
+
+ if (copy_to_user(buf, smalldata, result)) {
+ DBG("Error copying read data to user\n");
+ result = -EFAULT;
+ }
+
+ kfree(data);
+ return result;
+}
+
+static ssize_t devqmi_write(struct file *file, const char __user * buf,
+ size_t size, loff_t *pos)
+{
+ int status;
+ void *wbuf;
+ struct qmihandle *handle = (struct qmihandle *)file->private_data;
+
+ if (!handle) {
+ DBG("Bad file data\n");
+ return -EBADF;
+ }
+
+ if (!device_valid(handle->dev)) {
+ DBG("Invalid device! Updating f_ops\n");
+ file->f_op = file->f_dentry->d_inode->i_fop;
+ return -ENXIO;
+ }
+
+ if (handle->cid == (u16)-1) {
+ DBG("Client ID must be set before writing 0x%04X\n",
+ handle->cid);
+ return -EBADR;
+ }
+
+ wbuf = kmalloc(size + qmux_size, GFP_KERNEL);
+ if (!wbuf)
+ return -ENOMEM;
+ status = copy_from_user(wbuf + qmux_size, buf, size);
+ if (status) {
+ DBG("Unable to copy data from userspace %d\n", status);
+ kfree(wbuf);
+ return status;
+ }
+
+ status = write_sync(handle->dev, wbuf, size + qmux_size,
+ handle->cid);
+
+ kfree(wbuf);
+ if (status == size + qmux_size)
+ return size;
+ return status;
+}
+
+int qc_register(struct qcusbnet *dev)
+{
+ int result;
+ int qmiidx = 0;
+ dev_t devno;
+ char *name;
+
+ dev->valid = true;
+ result = client_alloc(dev, QMICTL);
+ if (result) {
+ dev->valid = false;
+ return result;
+ }
+ atomic_set(&dev->qmi.qmitid, 1);
+
+ result = qc_startread(dev);
+ if (result) {
+ dev->valid = false;
+ return result;
+ }
+
+ if (!qmi_ready(dev, 30000)) {
+ DBG("Device unresponsive to QMI\n");
+ return -ETIMEDOUT;
+ }
+
+ result = setup_wds_callback(dev);
+ if (result) {
+ dev->valid = false;
+ return result;
+ }
+
+ result = qmidms_getmeid(dev);
+ if (result) {
+ dev->valid = false;
+ return result;
+ }
+
+ result = alloc_chrdev_region(&devno, 0, 1, "qcqmi");
+ if (result < 0)
+ return result;
+
+ cdev_init(&dev->qmi.cdev, &devqmi_fops);
+ dev->qmi.cdev.owner = THIS_MODULE;
+ dev->qmi.cdev.ops = &devqmi_fops;
+
+ result = cdev_add(&dev->qmi.cdev, devno, 1);
+ if (result) {
+ DBG("error adding cdev\n");
+ return result;
+ }
+
+ name = strstr(dev->usbnet->net->name, "usb");
+ if (!name) {
+ DBG("Bad net name: %s\n", dev->usbnet->net->name);
+ return -ENXIO;
+ }
+ name += strlen("usb");
+ qmiidx = simple_strtoul(name, NULL, 10);
+ if (qmiidx < 0) {
+ DBG("Bad minor number\n");
+ return -ENXIO;
+ }
+
+ printk(KERN_INFO "creating qcqmi%d\n", qmiidx);
+ device_create(dev->qmi.devclass, NULL, devno, NULL, "qcqmi%d", qmiidx);
+
+ dev->qmi.devnum = devno;
+ return 0;
+}
+
+void qc_deregister(struct qcusbnet *dev)
+{
+ struct list_head *node;
+ struct client *client;
+ struct inode *inode;
+ struct list_head *inodes;
+ struct list_head *tasks;
+ struct task_struct *task;
+ struct fdtable *fdtable;
+ struct file *file;
+ unsigned long flags;
+ int count = 0;
+
+ if (!device_valid(dev)) {
+ DBG("wrong device\n");
+ return;
+ }
+
+ list_for_each(node, &dev->qmi.clients) {
+ client = list_entry(node, struct client, node);
+ DBG("release 0x%04X\n", client->cid);
+ client_free(dev, client->cid);
+ }
+
+ qc_stopread(dev);
+ dev->valid = false;
+ list_for_each(inodes, &dev->qmi.cdev.list) {
+ inode = container_of(inodes, struct inode, i_devices);
+ if (inode != NULL && !IS_ERR(inode)) {
+ list_for_each(tasks, ¤t->group_leader->tasks) {
+ task = container_of(tasks, struct task_struct, tasks);
+ if (!task || !task->files)
+ continue;
+ spin_lock_irqsave(&task->files->file_lock, flags);
+ fdtable = files_fdtable(task->files);
+ for (count = 0; count < fdtable->max_fds; count++) {
+ file = fdtable->fd[count];
+ if (file != NULL && file->f_dentry != NULL) {
+ if (file->f_dentry->d_inode == inode) {
+ rcu_assign_pointer(fdtable->fd[count], NULL);
+ spin_unlock_irqrestore(&task->files->file_lock, flags);
+ DBG("forcing close of open file handle\n");
+ filp_close(file, task->files);
+ spin_lock_irqsave(&task->files->file_lock, flags);
+ }
+ }
+ }
+ spin_unlock_irqrestore(&task->files->file_lock, flags);
+ }
+ }
+ }
+
+ if (!IS_ERR(dev->qmi.devclass))
+ device_destroy(dev->qmi.devclass, dev->qmi.devnum);
+ cdev_del(&dev->qmi.cdev);
+ unregister_chrdev_region(dev->qmi.devnum, 1);
+}
+
+static bool qmi_ready(struct qcusbnet *dev, u16 timeout)
+{
+ int result;
+ void *wbuf;
+ size_t wbufsize;
+ void *rbuf;
+ u16 rbufsize;
+ struct semaphore sem;
+ u16 now;
+ unsigned long flags;
+ u8 tid;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return -EFAULT;
+ }
+
+
+ for (now = 0; now < timeout; now += 100) {
+ sema_init(&sem, 0);
+
+ tid = atomic_add_return(1, &dev->qmi.qmitid);
+ if (!tid)
+ tid = atomic_add_return(1, &dev->qmi.qmitid);
+ kfree(wbuf);
+ wbuf = qmictl_new_ready(tid, &wbufsize);
+ if (!wbuf)
+ return -ENOMEM;
+
+ result = read_async(dev, QMICTL, tid, upsem, &sem);
+ if (result) {
+ kfree(wbuf);
+ return false;
+ }
+
+ write_sync(dev, wbuf, wbufsize, QMICTL);
+
+ msleep(100);
+ if (!down_trylock(&sem)) {
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ if (client_delread(dev, QMICTL, tid, &rbuf, &rbufsize)) {
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ kfree(rbuf);
+ break;
+ }
+ } else {
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ client_notify(dev, QMICTL, tid);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+ }
+ }
+
+ kfree(wbuf);
+
+ if (now >= timeout)
+ return false;
+
+ DBG("QMI Ready after %u milliseconds\n", now);
+
+ /* 3580 and newer doesn't need a delay; older needs 5000ms */
+ if (qcusbnet2k_fwdelay)
+ msleep(qcusbnet2k_fwdelay * 1000);
+
+ return true;
+}
+
+static void wds_callback(struct qcusbnet *dev, u16 cid, void *data)
+{
+ bool ret;
+ int result;
+ void *rbuf;
+ u16 rbufsize;
+
+ struct net_device_stats *stats = &(dev->usbnet->net->stats);
+
+ struct qmiwds_stats dstats = {
+ .txok = (u32)-1,
+ .rxok = (u32)-1,
+ .txerr = (u32)-1,
+ .rxerr = (u32)-1,
+ .txofl = (u32)-1,
+ .rxofl = (u32)-1,
+ .txbytesok = (u64)-1,
+ .rxbytesok = (u64)-1,
+ };
+ unsigned long flags;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return;
+ }
+
+ spin_lock_irqsave(&dev->qmi.clients_lock, flags);
+ ret = client_delread(dev, cid, 0, &rbuf, &rbufsize);
+ spin_unlock_irqrestore(&dev->qmi.clients_lock, flags);
+
+ if (!ret) {
+ DBG("WDS callback failed to get data\n");
+ return;
+ }
+
+ dstats.linkstate = !qc_isdown(dev, DOWN_NO_NDIS_CONNECTION);
+ dstats.reconfigure = false;
+
+ result = qmiwds_event_resp(rbuf, rbufsize, &dstats);
+ if (result < 0) {
+ DBG("bad WDS packet\n");
+ } else {
+ if (dstats.txofl != (u32)-1)
+ stats->tx_fifo_errors = dstats.txofl;
+
+ if (dstats.rxofl != (u32)-1)
+ stats->rx_fifo_errors = dstats.rxofl;
+
+ if (dstats.txerr != (u32)-1)
+ stats->tx_errors = dstats.txerr;
+
+ if (dstats.rxerr != (u32)-1)
+ stats->rx_errors = dstats.rxerr;
+
+ if (dstats.txok != (u32)-1)
+ stats->tx_packets = dstats.txok + stats->tx_errors;
+
+ if (dstats.rxok != (u32)-1)
+ stats->rx_packets = dstats.rxok + stats->rx_errors;
+
+ if (dstats.txbytesok != (u64)-1)
+ stats->tx_bytes = dstats.txbytesok;
+
+ if (dstats.rxbytesok != (u64)-1)
+ stats->rx_bytes = dstats.rxbytesok;
+
+ if (dstats.reconfigure) {
+ DBG("Net device link reset\n");
+ qc_setdown(dev, DOWN_NO_NDIS_CONNECTION);
+ qc_cleardown(dev, DOWN_NO_NDIS_CONNECTION);
+ } else {
+ if (dstats.linkstate) {
+ DBG("Net device link is connected\n");
+ qc_cleardown(dev, DOWN_NO_NDIS_CONNECTION);
+ } else {
+ DBG("Net device link is disconnected\n");
+ qc_setdown(dev, DOWN_NO_NDIS_CONNECTION);
+ }
+ }
+ }
+
+ kfree(rbuf);
+
+ result = read_async(dev, cid, 0, wds_callback, data);
+ if (result != 0)
+ DBG("unable to setup next async read\n");
+}
+
+static int setup_wds_callback(struct qcusbnet *dev)
+{
+ int result;
+ void *buf;
+ size_t size;
+ u16 cid;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return -EFAULT;
+ }
+
+ result = client_alloc(dev, QMIWDS);
+ if (result < 0)
+ return result;
+ cid = result;
+
+ buf = qmiwds_new_seteventreport(1, &size);
+ if (!buf)
+ return -ENOMEM;
+
+ result = write_sync(dev, buf, size, cid);
+ kfree(buf);
+
+ if (result < 0) {
+ return result;
+ }
+
+ buf = qmiwds_new_getpkgsrvcstatus(2, &size);
+ if (buf == NULL)
+ return -ENOMEM;
+
+ result = write_sync(dev, buf, size, cid);
+ kfree(buf);
+
+ if (result < 0)
+ return result;
+
+ result = read_async(dev, cid, 0, wds_callback, NULL);
+ if (result) {
+ DBG("unable to setup async read\n");
+ return result;
+ }
+
+ result = usb_control_msg(dev->usbnet->udev,
+ usb_sndctrlpipe(dev->usbnet->udev, 0),
+ 0x22, 0x21, 1, 0, NULL, 0, 100);
+ if (result < 0) {
+ DBG("Bad SetControlLineState status %d\n", result);
+ return result;
+ }
+
+ return 0;
+}
+
+static int qmidms_getmeid(struct qcusbnet *dev)
+{
+ int result;
+ void *wbuf;
+ size_t wbufsize;
+ void *rbuf;
+ u16 rbufsize;
+ u16 cid;
+
+ if (!device_valid(dev)) {
+ DBG("Invalid device\n");
+ return -EFAULT;
+ }
+
+ result = client_alloc(dev, QMIDMS);
+ if (result < 0)
+ return result;
+ cid = result;
+
+ wbuf = qmidms_new_getmeid(1, &wbufsize);
+ if (!wbuf)
+ return -ENOMEM;
+
+ result = write_sync(dev, wbuf, wbufsize, cid);
+ kfree(wbuf);
+
+ if (result < 0)
+ return result;
+
+ result = read_sync(dev, &rbuf, cid, 1);
+ if (result < 0)
+ return result;
+ rbufsize = result;
+
+ result = qmidms_meid_resp(rbuf, rbufsize, &dev->meid[0], 14);
+ kfree(rbuf);
+
+ if (result < 0) {
+ DBG("bad get MEID resp\n");
+ memset(&dev->meid[0], '0', 14);
+ }
+
+ client_free(dev, cid);
+ return 0;
+}
+
+module_param(qcusbnet2k_fwdelay, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(qcusbnet2k_fwdelay, "Delay for old firmware");
diff --git a/drivers/net/usb/gobi/qmidevice.h b/drivers/net/usb/gobi/qmidevice.h
new file mode 100644
index 0000000..5274a0d
--- /dev/null
+++ b/drivers/net/usb/gobi/qmidevice.h
@@ -0,0 +1,35 @@
+/* qmidevice.h - gobi QMI device header
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef QCUSBNET_QMIDEVICE_H
+#define QCUSBNET_QMIDEVICE_H
+
+#include "structs.h"
+#include "qmi.h"
+
+void qc_setdown(struct qcusbnet *dev, u8 reason);
+void qc_cleardown(struct qcusbnet *dev, u8 reason);
+bool qc_isdown(struct qcusbnet *dev, u8 reason);
+
+int qc_startread(struct qcusbnet *dev);
+void qc_stopread(struct qcusbnet *dev);
+
+int qc_register(struct qcusbnet *dev);
+void qc_deregister(struct qcusbnet *dev);
+
+#endif /* !QCUSBNET_QMIDEVICE_H */
diff --git a/drivers/net/usb/gobi/structs.h b/drivers/net/usb/gobi/structs.h
new file mode 100644
index 0000000..7a89c5c
--- /dev/null
+++ b/drivers/net/usb/gobi/structs.h
@@ -0,0 +1,92 @@
+/* structs.h - shared structures
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef QCUSBNET_STRUCTS_H
+#define QCUSBNET_STRUCTS_H
+
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/version.h>
+#include <linux/cdev.h>
+#include <linux/kthread.h>
+
+#include <linux/usb/usbnet.h>
+
+#include <linux/fdtable.h>
+
+#define DBG(fmt, arg...) \
+do { \
+ if (qcusbnet_debug == 1) \
+ printk(KERN_INFO "QCUSBNet2k::%s " fmt, __func__, ##arg); \
+} while (0)
+
+struct qcusbnet;
+
+struct urbreq {
+ struct list_head node;
+ struct urb *urb;
+};
+
+#define DEFAULT_READ_URB_LENGTH 0x1000
+
+struct worker {
+ struct task_struct *thread;
+ struct completion work;
+ struct list_head urbs;
+ spinlock_t urbs_lock;
+ struct urb *active;
+ spinlock_t active_lock;
+ struct usb_interface *iface;
+};
+
+struct qmidev {
+ dev_t devnum;
+ struct class *devclass;
+ struct cdev cdev;
+ struct urb *readurb;
+ struct urbsetup *readsetup;
+ void *readbuf;
+ struct urb *inturb;
+ void *intbuf;
+ struct list_head clients;
+ spinlock_t clients_lock;
+ atomic_t qmitid;
+};
+
+enum {
+ DOWN_NO_NDIS_CONNECTION = 0,
+ DOWN_CDC_CONNECTION_SPEED = 1,
+ DOWN_DRIVER_SUSPENDED = 2,
+ DOWN_NET_IFACE_STOPPED = 3,
+};
+
+struct qcusbnet {
+ struct usbnet *usbnet;
+ struct usb_interface *iface;
+ int (*open)(struct net_device *);
+ int (*stop)(struct net_device *);
+ unsigned long down;
+ bool valid;
+ struct qmidev qmi;
+ char meid[14];
+ struct worker worker;
+};
+
+#endif /* !QCUSBNET_STRUCTS_H */
--
1.7.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox