aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-09-26 13:09:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-26 13:09:39 -0400
commitd8f654ef6a55495e548427b997a388e0d5a1ffb4 (patch)
tree31ee0a2aeccf23aeda562932d8d7c37a55a8653c /drivers/net
parent052a0cf6f85a136dc0654ec3c2d25ddd4495c65d (diff)
parent99c4a6344f6574c97019ac16e8d54bfe5ad21f2d (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6: at91_can: Forgotten git 'add' of at91_can.c TI Davinci EMAC: Fix in vector definition for EMAC_VERSION_2 ax25: Fix ax25_cb refcounting in ax25_ctl_ioctl virtio_net: Check for room in the vq before adding buffer virtio_net: avoid (most) NETDEV_TX_BUSY by stopping queue early. virtio_net: formalize skb_vnet_hdr virtio_net: don't free buffers in xmit ring virtio_net: return NETDEV_TX_BUSY instead of queueing an extra skb. virtio_net: skb_orphan() and nf_reset() in xmit path.
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/can/at91_can.c1186
-rw-r--r--drivers/net/davinci_emac.c9
-rw-r--r--drivers/net/virtio_net.c229
3 files changed, 1282 insertions, 142 deletions
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
new file mode 100644
index 000000000000..f67ae285a35a
--- /dev/null
+++ b/drivers/net/can/at91_can.c
@@ -0,0 +1,1186 @@
1/*
2 * at91_can.c - CAN network driver for AT91 SoC CAN controller
3 *
4 * (C) 2007 by Hans J. Koch <hjk@linutronix.de>
5 * (C) 2008, 2009 by Marc Kleine-Budde <kernel@pengutronix.de>
6 *
7 * This software may be distributed under the terms of the GNU General
8 * Public License ("GPL") version 2 as distributed in the 'COPYING'
9 * file from the main directory of the linux kernel source.
10 *
11 * Send feedback to <socketcan-users@lists.berlios.de>
12 *
13 *
14 * Your platform definition file should specify something like:
15 *
16 * static struct at91_can_data ek_can_data = {
17 * transceiver_switch = sam9263ek_transceiver_switch,
18 * };
19 *
20 * at91_add_device_can(&ek_can_data);
21 *
22 */
23
24#include <linux/clk.h>
25#include <linux/errno.h>
26#include <linux/if_arp.h>
27#include <linux/init.h>
28#include <linux/interrupt.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/netdevice.h>
32#include <linux/platform_device.h>
33#include <linux/skbuff.h>
34#include <linux/spinlock.h>
35#include <linux/string.h>
36#include <linux/types.h>
37
38#include <linux/can.h>
39#include <linux/can/dev.h>
40#include <linux/can/error.h>
41
42#include <mach/board.h>
43
44#define DRV_NAME "at91_can"
45#define AT91_NAPI_WEIGHT 12
46
47/*
48 * RX/TX Mailbox split
49 * don't dare to touch
50 */
51#define AT91_MB_RX_NUM 12
52#define AT91_MB_TX_SHIFT 2
53
54#define AT91_MB_RX_FIRST 0
55#define AT91_MB_RX_LAST (AT91_MB_RX_FIRST + AT91_MB_RX_NUM - 1)
56
57#define AT91_MB_RX_MASK(i) ((1 << (i)) - 1)
58#define AT91_MB_RX_SPLIT 8
59#define AT91_MB_RX_LOW_LAST (AT91_MB_RX_SPLIT - 1)
60#define AT91_MB_RX_LOW_MASK (AT91_MB_RX_MASK(AT91_MB_RX_SPLIT))
61
62#define AT91_MB_TX_NUM (1 << AT91_MB_TX_SHIFT)
63#define AT91_MB_TX_FIRST (AT91_MB_RX_LAST + 1)
64#define AT91_MB_TX_LAST (AT91_MB_TX_FIRST + AT91_MB_TX_NUM - 1)
65
66#define AT91_NEXT_PRIO_SHIFT (AT91_MB_TX_SHIFT)
67#define AT91_NEXT_PRIO_MASK (0xf << AT91_MB_TX_SHIFT)
68#define AT91_NEXT_MB_MASK (AT91_MB_TX_NUM - 1)
69#define AT91_NEXT_MASK ((AT91_MB_TX_NUM - 1) | AT91_NEXT_PRIO_MASK)
70
71/* Common registers */
72enum at91_reg {
73 AT91_MR = 0x000,
74 AT91_IER = 0x004,
75 AT91_IDR = 0x008,
76 AT91_IMR = 0x00C,
77 AT91_SR = 0x010,
78 AT91_BR = 0x014,
79 AT91_TIM = 0x018,
80 AT91_TIMESTP = 0x01C,
81 AT91_ECR = 0x020,
82 AT91_TCR = 0x024,
83 AT91_ACR = 0x028,
84};
85
86/* Mailbox registers (0 <= i <= 15) */
87#define AT91_MMR(i) (enum at91_reg)(0x200 + ((i) * 0x20))
88#define AT91_MAM(i) (enum at91_reg)(0x204 + ((i) * 0x20))
89#define AT91_MID(i) (enum at91_reg)(0x208 + ((i) * 0x20))
90#define AT91_MFID(i) (enum at91_reg)(0x20C + ((i) * 0x20))
91#define AT91_MSR(i) (enum at91_reg)(0x210 + ((i) * 0x20))
92#define AT91_MDL(i) (enum at91_reg)(0x214 + ((i) * 0x20))
93#define AT91_MDH(i) (enum at91_reg)(0x218 + ((i) * 0x20))
94#define AT91_MCR(i) (enum at91_reg)(0x21C + ((i) * 0x20))
95
96/* Register bits */
97#define AT91_MR_CANEN BIT(0)
98#define AT91_MR_LPM BIT(1)
99#define AT91_MR_ABM BIT(2)
100#define AT91_MR_OVL BIT(3)
101#define AT91_MR_TEOF BIT(4)
102#define AT91_MR_TTM BIT(5)
103#define AT91_MR_TIMFRZ BIT(6)
104#define AT91_MR_DRPT BIT(7)
105
106#define AT91_SR_RBSY BIT(29)
107
108#define AT91_MMR_PRIO_SHIFT (16)
109
110#define AT91_MID_MIDE BIT(29)
111
112#define AT91_MSR_MRTR BIT(20)
113#define AT91_MSR_MABT BIT(22)
114#define AT91_MSR_MRDY BIT(23)
115#define AT91_MSR_MMI BIT(24)
116
117#define AT91_MCR_MRTR BIT(20)
118#define AT91_MCR_MTCR BIT(23)
119
120/* Mailbox Modes */
121enum at91_mb_mode {
122 AT91_MB_MODE_DISABLED = 0,
123 AT91_MB_MODE_RX = 1,
124 AT91_MB_MODE_RX_OVRWR = 2,
125 AT91_MB_MODE_TX = 3,
126 AT91_MB_MODE_CONSUMER = 4,
127 AT91_MB_MODE_PRODUCER = 5,
128};
129
130/* Interrupt mask bits */
131#define AT91_IRQ_MB_RX ((1 << (AT91_MB_RX_LAST + 1)) \
132 - (1 << AT91_MB_RX_FIRST))
133#define AT91_IRQ_MB_TX ((1 << (AT91_MB_TX_LAST + 1)) \
134 - (1 << AT91_MB_TX_FIRST))
135#define AT91_IRQ_MB_ALL (AT91_IRQ_MB_RX | AT91_IRQ_MB_TX)
136
137#define AT91_IRQ_ERRA (1 << 16)
138#define AT91_IRQ_WARN (1 << 17)
139#define AT91_IRQ_ERRP (1 << 18)
140#define AT91_IRQ_BOFF (1 << 19)
141#define AT91_IRQ_SLEEP (1 << 20)
142#define AT91_IRQ_WAKEUP (1 << 21)
143#define AT91_IRQ_TOVF (1 << 22)
144#define AT91_IRQ_TSTP (1 << 23)
145#define AT91_IRQ_CERR (1 << 24)
146#define AT91_IRQ_SERR (1 << 25)
147#define AT91_IRQ_AERR (1 << 26)
148#define AT91_IRQ_FERR (1 << 27)
149#define AT91_IRQ_BERR (1 << 28)
150
151#define AT91_IRQ_ERR_ALL (0x1fff0000)
152#define AT91_IRQ_ERR_FRAME (AT91_IRQ_CERR | AT91_IRQ_SERR | \
153 AT91_IRQ_AERR | AT91_IRQ_FERR | AT91_IRQ_BERR)
154#define AT91_IRQ_ERR_LINE (AT91_IRQ_ERRA | AT91_IRQ_WARN | \
155 AT91_IRQ_ERRP | AT91_IRQ_BOFF)
156
157#define AT91_IRQ_ALL (0x1fffffff)
158
159struct at91_priv {
160 struct can_priv can; /* must be the first member! */
161 struct net_device *dev;
162 struct napi_struct napi;
163
164 void __iomem *reg_base;
165
166 u32 reg_sr;
167 unsigned int tx_next;
168 unsigned int tx_echo;
169 unsigned int rx_next;
170
171 struct clk *clk;
172 struct at91_can_data *pdata;
173};
174
175static struct can_bittiming_const at91_bittiming_const = {
176 .tseg1_min = 4,
177 .tseg1_max = 16,
178 .tseg2_min = 2,
179 .tseg2_max = 8,
180 .sjw_max = 4,
181 .brp_min = 2,
182 .brp_max = 128,
183 .brp_inc = 1,
184};
185
186static inline int get_tx_next_mb(const struct at91_priv *priv)
187{
188 return (priv->tx_next & AT91_NEXT_MB_MASK) + AT91_MB_TX_FIRST;
189}
190
191static inline int get_tx_next_prio(const struct at91_priv *priv)
192{
193 return (priv->tx_next >> AT91_NEXT_PRIO_SHIFT) & 0xf;
194}
195
196static inline int get_tx_echo_mb(const struct at91_priv *priv)
197{
198 return (priv->tx_echo & AT91_NEXT_MB_MASK) + AT91_MB_TX_FIRST;
199}
200
201static inline u32 at91_read(const struct at91_priv *priv, enum at91_reg reg)
202{
203 return readl(priv->reg_base + reg);
204}
205
206static inline void at91_write(const struct at91_priv *priv, enum at91_reg reg,
207 u32 value)
208{
209 writel(value, priv->reg_base + reg);
210}
211
212static inline void set_mb_mode_prio(const struct at91_priv *priv,
213 unsigned int mb, enum at91_mb_mode mode, int prio)
214{
215 at91_write(priv, AT91_MMR(mb), (mode << 24) | (prio << 16));
216}
217
218static inline void set_mb_mode(const struct at91_priv *priv, unsigned int mb,
219 enum at91_mb_mode mode)
220{
221 set_mb_mode_prio(priv, mb, mode, 0);
222}
223
224static struct sk_buff *alloc_can_skb(struct net_device *dev,
225 struct can_frame **cf)
226{
227 struct sk_buff *skb;
228
229 skb = netdev_alloc_skb(dev, sizeof(struct can_frame));
230 if (unlikely(!skb))
231 return NULL;
232
233 skb->protocol = htons(ETH_P_CAN);
234 skb->ip_summed = CHECKSUM_UNNECESSARY;
235 *cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
236
237 return skb;
238}
239
240static struct sk_buff *alloc_can_err_skb(struct net_device *dev,
241 struct can_frame **cf)
242{
243 struct sk_buff *skb;
244
245 skb = alloc_can_skb(dev, cf);
246 if (unlikely(!skb))
247 return NULL;
248
249 memset(*cf, 0, sizeof(struct can_frame));
250 (*cf)->can_id = CAN_ERR_FLAG;
251 (*cf)->can_dlc = CAN_ERR_DLC;
252
253 return skb;
254}
255
256/*
257 * Swtich transceiver on or off
258 */
259static void at91_transceiver_switch(const struct at91_priv *priv, int on)
260{
261 if (priv->pdata && priv->pdata->transceiver_switch)
262 priv->pdata->transceiver_switch(on);
263}
264
265static void at91_setup_mailboxes(struct net_device *dev)
266{
267 struct at91_priv *priv = netdev_priv(dev);
268 unsigned int i;
269
270 /*
271 * The first 12 mailboxes are used as a reception FIFO. The
272 * last mailbox is configured with overwrite option. The
273 * overwrite flag indicates a FIFO overflow.
274 */
275 for (i = AT91_MB_RX_FIRST; i < AT91_MB_RX_LAST; i++)
276 set_mb_mode(priv, i, AT91_MB_MODE_RX);
277 set_mb_mode(priv, AT91_MB_RX_LAST, AT91_MB_MODE_RX_OVRWR);
278
279 /* The last 4 mailboxes are used for transmitting. */
280 for (i = AT91_MB_TX_FIRST; i <= AT91_MB_TX_LAST; i++)
281 set_mb_mode_prio(priv, i, AT91_MB_MODE_TX, 0);
282
283 /* Reset tx and rx helper pointers */
284 priv->tx_next = priv->tx_echo = priv->rx_next = 0;
285}
286
287static int at91_set_bittiming(struct net_device *dev)
288{
289 const struct at91_priv *priv = netdev_priv(dev);
290 const struct can_bittiming *bt = &priv->can.bittiming;
291 u32 reg_br;
292
293 reg_br = ((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) << 24) |
294 ((bt->brp - 1) << 16) | ((bt->sjw - 1) << 12) |
295 ((bt->prop_seg - 1) << 8) | ((bt->phase_seg1 - 1) << 4) |
296 ((bt->phase_seg2 - 1) << 0);
297
298 dev_info(dev->dev.parent, "writing AT91_BR: 0x%08x\n", reg_br);
299
300 at91_write(priv, AT91_BR, reg_br);
301
302 return 0;
303}
304
305static void at91_chip_start(struct net_device *dev)
306{
307 struct at91_priv *priv = netdev_priv(dev);
308 u32 reg_mr, reg_ier;
309
310 /* disable interrupts */
311 at91_write(priv, AT91_IDR, AT91_IRQ_ALL);
312
313 /* disable chip */
314 reg_mr = at91_read(priv, AT91_MR);
315 at91_write(priv, AT91_MR, reg_mr & ~AT91_MR_CANEN);
316
317 at91_setup_mailboxes(dev);
318 at91_transceiver_switch(priv, 1);
319
320 /* enable chip */
321 at91_write(priv, AT91_MR, AT91_MR_CANEN);
322
323 priv->can.state = CAN_STATE_ERROR_ACTIVE;
324
325 /* Enable interrupts */
326 reg_ier = AT91_IRQ_MB_RX | AT91_IRQ_ERRP | AT91_IRQ_ERR_FRAME;
327 at91_write(priv, AT91_IDR, AT91_IRQ_ALL);
328 at91_write(priv, AT91_IER, reg_ier);
329}
330
331static void at91_chip_stop(struct net_device *dev, enum can_state state)
332{
333 struct at91_priv *priv = netdev_priv(dev);
334 u32 reg_mr;
335
336 /* disable interrupts */
337 at91_write(priv, AT91_IDR, AT91_IRQ_ALL);
338
339 reg_mr = at91_read(priv, AT91_MR);
340 at91_write(priv, AT91_MR, reg_mr & ~AT91_MR_CANEN);
341
342 at91_transceiver_switch(priv, 0);
343 priv->can.state = state;
344}
345
346/*
347 * theory of operation:
348 *
349 * According to the datasheet priority 0 is the highest priority, 15
350 * is the lowest. If two mailboxes have the same priority level the
351 * message of the mailbox with the lowest number is sent first.
352 *
353 * We use the first TX mailbox (AT91_MB_TX_FIRST) with prio 0, then
354 * the next mailbox with prio 0, and so on, until all mailboxes are
355 * used. Then we start from the beginning with mailbox
356 * AT91_MB_TX_FIRST, but with prio 1, mailbox AT91_MB_TX_FIRST + 1
357 * prio 1. When we reach the last mailbox with prio 15, we have to
358 * stop sending, waiting for all messages to be delivered, then start
359 * again with mailbox AT91_MB_TX_FIRST prio 0.
360 *
361 * We use the priv->tx_next as counter for the next transmission
362 * mailbox, but without the offset AT91_MB_TX_FIRST. The lower bits
363 * encode the mailbox number, the upper 4 bits the mailbox priority:
364 *
365 * priv->tx_next = (prio << AT91_NEXT_PRIO_SHIFT) ||
366 * (mb - AT91_MB_TX_FIRST);
367 *
368 */
369static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev)
370{
371 struct at91_priv *priv = netdev_priv(dev);
372 struct net_device_stats *stats = &dev->stats;
373 struct can_frame *cf = (struct can_frame *)skb->data;
374 unsigned int mb, prio;
375 u32 reg_mid, reg_mcr;
376
377 mb = get_tx_next_mb(priv);
378 prio = get_tx_next_prio(priv);
379
380 if (unlikely(!(at91_read(priv, AT91_MSR(mb)) & AT91_MSR_MRDY))) {
381 netif_stop_queue(dev);
382
383 dev_err(dev->dev.parent,
384 "BUG! TX buffer full when queue awake!\n");
385 return NETDEV_TX_BUSY;
386 }
387
388 if (cf->can_id & CAN_EFF_FLAG)
389 reg_mid = (cf->can_id & CAN_EFF_MASK) | AT91_MID_MIDE;
390 else
391 reg_mid = (cf->can_id & CAN_SFF_MASK) << 18;
392
393 reg_mcr = ((cf->can_id & CAN_RTR_FLAG) ? AT91_MCR_MRTR : 0) |
394 (cf->can_dlc << 16) | AT91_MCR_MTCR;
395
396 /* disable MB while writing ID (see datasheet) */
397 set_mb_mode(priv, mb, AT91_MB_MODE_DISABLED);
398 at91_write(priv, AT91_MID(mb), reg_mid);
399 set_mb_mode_prio(priv, mb, AT91_MB_MODE_TX, prio);
400
401 at91_write(priv, AT91_MDL(mb), *(u32 *)(cf->data + 0));
402 at91_write(priv, AT91_MDH(mb), *(u32 *)(cf->data + 4));
403
404 /* This triggers transmission */
405 at91_write(priv, AT91_MCR(mb), reg_mcr);
406
407 stats->tx_bytes += cf->can_dlc;
408 dev->trans_start = jiffies;
409
410 /* _NOTE_: substract AT91_MB_TX_FIRST offset from mb! */
411 can_put_echo_skb(skb, dev, mb - AT91_MB_TX_FIRST);
412
413 /*
414 * we have to stop the queue and deliver all messages in case
415 * of a prio+mb counter wrap around. This is the case if
416 * tx_next buffer prio and mailbox equals 0.
417 *
418 * also stop the queue if next buffer is still in use
419 * (== not ready)
420 */
421 priv->tx_next++;
422 if (!(at91_read(priv, AT91_MSR(get_tx_next_mb(priv))) &
423 AT91_MSR_MRDY) ||
424 (priv->tx_next & AT91_NEXT_MASK) == 0)
425 netif_stop_queue(dev);
426
427 /* Enable interrupt for this mailbox */
428 at91_write(priv, AT91_IER, 1 << mb);
429
430 return NETDEV_TX_OK;
431}
432
433/**
434 * at91_activate_rx_low - activate lower rx mailboxes
435 * @priv: a91 context
436 *
437 * Reenables the lower mailboxes for reception of new CAN messages
438 */
439static inline void at91_activate_rx_low(const struct at91_priv *priv)
440{
441 u32 mask = AT91_MB_RX_LOW_MASK;
442 at91_write(priv, AT91_TCR, mask);
443}
444
445/**
446 * at91_activate_rx_mb - reactive single rx mailbox
447 * @priv: a91 context
448 * @mb: mailbox to reactivate
449 *
450 * Reenables given mailbox for reception of new CAN messages
451 */
452static inline void at91_activate_rx_mb(const struct at91_priv *priv,
453 unsigned int mb)
454{
455 u32 mask = 1 << mb;
456 at91_write(priv, AT91_TCR, mask);
457}
458
459/**
460 * at91_rx_overflow_err - send error frame due to rx overflow
461 * @dev: net device
462 */
463static void at91_rx_overflow_err(struct net_device *dev)
464{
465 struct net_device_stats *stats = &dev->stats;
466 struct sk_buff *skb;
467 struct can_frame *cf;
468
469 dev_dbg(dev->dev.parent, "RX buffer overflow\n");
470 stats->rx_over_errors++;
471 stats->rx_errors++;
472
473 skb = alloc_can_err_skb(dev, &cf);
474 if (unlikely(!skb))
475 return;
476
477 cf->can_id |= CAN_ERR_CRTL;
478 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
479 netif_receive_skb(skb);
480
481 stats->rx_packets++;
482 stats->rx_bytes += cf->can_dlc;
483}
484
485/**
486 * at91_read_mb - read CAN msg from mailbox (lowlevel impl)
487 * @dev: net device
488 * @mb: mailbox number to read from
489 * @cf: can frame where to store message
490 *
491 * Reads a CAN message from the given mailbox and stores data into
492 * given can frame. "mb" and "cf" must be valid.
493 */
494static void at91_read_mb(struct net_device *dev, unsigned int mb,
495 struct can_frame *cf)
496{
497 const struct at91_priv *priv = netdev_priv(dev);
498 u32 reg_msr, reg_mid;
499
500 reg_mid = at91_read(priv, AT91_MID(mb));
501 if (reg_mid & AT91_MID_MIDE)
502 cf->can_id = ((reg_mid >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
503 else
504 cf->can_id = (reg_mid >> 18) & CAN_SFF_MASK;
505
506 reg_msr = at91_read(priv, AT91_MSR(mb));
507 if (reg_msr & AT91_MSR_MRTR)
508 cf->can_id |= CAN_RTR_FLAG;
509 cf->can_dlc = min_t(__u8, (reg_msr >> 16) & 0xf, 8);
510
511 *(u32 *)(cf->data + 0) = at91_read(priv, AT91_MDL(mb));
512 *(u32 *)(cf->data + 4) = at91_read(priv, AT91_MDH(mb));
513
514 if (unlikely(mb == AT91_MB_RX_LAST && reg_msr & AT91_MSR_MMI))
515 at91_rx_overflow_err(dev);
516}
517
518/**
519 * at91_read_msg - read CAN message from mailbox
520 * @dev: net device
521 * @mb: mail box to read from
522 *
523 * Reads a CAN message from given mailbox, and put into linux network
524 * RX queue, does all housekeeping chores (stats, ...)
525 */
526static void at91_read_msg(struct net_device *dev, unsigned int mb)
527{
528 struct net_device_stats *stats = &dev->stats;
529 struct can_frame *cf;
530 struct sk_buff *skb;
531
532 skb = alloc_can_skb(dev, &cf);
533 if (unlikely(!skb)) {
534 stats->rx_dropped++;
535 return;
536 }
537
538 at91_read_mb(dev, mb, cf);
539 netif_receive_skb(skb);
540
541 stats->rx_packets++;
542 stats->rx_bytes += cf->can_dlc;
543}
544
545/**
546 * at91_poll_rx - read multiple CAN messages from mailboxes
547 * @dev: net device
548 * @quota: max number of pkgs we're allowed to receive
549 *
550 * Theory of Operation:
551 *
552 * 12 of the 16 mailboxes on the chip are reserved for RX. we split
553 * them into 2 groups. The lower group holds 8 and upper 4 mailboxes.
554 *
555 * Like it or not, but the chip always saves a received CAN message
556 * into the first free mailbox it finds (starting with the
557 * lowest). This makes it very difficult to read the messages in the
558 * right order from the chip. This is how we work around that problem:
559 *
560 * The first message goes into mb nr. 0 and issues an interrupt. All
561 * rx ints are disabled in the interrupt handler and a napi poll is
562 * scheduled. We read the mailbox, but do _not_ reenable the mb (to
563 * receive another message).
564 *
565 * lower mbxs upper
566 * ______^______ __^__
567 * / \ / \
568 * +-+-+-+-+-+-+-+-++-+-+-+-+
569 * |x|x|x|x|x|x|x|x|| | | | |
570 * +-+-+-+-+-+-+-+-++-+-+-+-+
571 * 0 0 0 0 0 0 0 0 0 0 1 1 \ mail
572 * 0 1 2 3 4 5 6 7 8 9 0 1 / box
573 *
574 * The variable priv->rx_next points to the next mailbox to read a
575 * message from. As long we're in the lower mailboxes we just read the
576 * mailbox but not reenable it.
577 *
578 * With completion of the last of the lower mailboxes, we reenable the
579 * whole first group, but continue to look for filled mailboxes in the
580 * upper mailboxes. Imagine the second group like overflow mailboxes,
581 * which takes CAN messages if the lower goup is full. While in the
582 * upper group we reenable the mailbox right after reading it. Giving
583 * the chip more room to store messages.
584 *
585 * After finishing we look again in the lower group if we've still
586 * quota.
587 *
588 */
589static int at91_poll_rx(struct net_device *dev, int quota)
590{
591 struct at91_priv *priv = netdev_priv(dev);
592 u32 reg_sr = at91_read(priv, AT91_SR);
593 const unsigned long *addr = (unsigned long *)&reg_sr;
594 unsigned int mb;
595 int received = 0;
596
597 if (priv->rx_next > AT91_MB_RX_LOW_LAST &&
598 reg_sr & AT91_MB_RX_LOW_MASK)
599 dev_info(dev->dev.parent,
600 "order of incoming frames cannot be guaranteed\n");
601
602 again:
603 for (mb = find_next_bit(addr, AT91_MB_RX_NUM, priv->rx_next);
604 mb < AT91_MB_RX_NUM && quota > 0;
605 reg_sr = at91_read(priv, AT91_SR),
606 mb = find_next_bit(addr, AT91_MB_RX_NUM, ++priv->rx_next)) {
607 at91_read_msg(dev, mb);
608
609 /* reactivate mailboxes */
610 if (mb == AT91_MB_RX_LOW_LAST)
611 /* all lower mailboxed, if just finished it */
612 at91_activate_rx_low(priv);
613 else if (mb > AT91_MB_RX_LOW_LAST)
614 /* only the mailbox we read */
615 at91_activate_rx_mb(priv, mb);
616
617 received++;
618 quota--;
619 }
620
621 /* upper group completed, look again in lower */
622 if (priv->rx_next > AT91_MB_RX_LOW_LAST &&
623 quota > 0 && mb >= AT91_MB_RX_NUM) {
624 priv->rx_next = 0;
625 goto again;
626 }
627
628 return received;
629}
630
631static void at91_poll_err_frame(struct net_device *dev,
632 struct can_frame *cf, u32 reg_sr)
633{
634 struct at91_priv *priv = netdev_priv(dev);
635
636 /* CRC error */
637 if (reg_sr & AT91_IRQ_CERR) {
638 dev_dbg(dev->dev.parent, "CERR irq\n");
639 dev->stats.rx_errors++;
640 priv->can.can_stats.bus_error++;
641 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
642 }
643
644 /* Stuffing Error */
645 if (reg_sr & AT91_IRQ_SERR) {
646 dev_dbg(dev->dev.parent, "SERR irq\n");
647 dev->stats.rx_errors++;
648 priv->can.can_stats.bus_error++;
649 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
650 cf->data[2] |= CAN_ERR_PROT_STUFF;
651 }
652
653 /* Acknowledgement Error */
654 if (reg_sr & AT91_IRQ_AERR) {
655 dev_dbg(dev->dev.parent, "AERR irq\n");
656 dev->stats.tx_errors++;
657 cf->can_id |= CAN_ERR_ACK;
658 }
659
660 /* Form error */
661 if (reg_sr & AT91_IRQ_FERR) {
662 dev_dbg(dev->dev.parent, "FERR irq\n");
663 dev->stats.rx_errors++;
664 priv->can.can_stats.bus_error++;
665 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
666 cf->data[2] |= CAN_ERR_PROT_FORM;
667 }
668
669 /* Bit Error */
670 if (reg_sr & AT91_IRQ_BERR) {
671 dev_dbg(dev->dev.parent, "BERR irq\n");
672 dev->stats.tx_errors++;
673 priv->can.can_stats.bus_error++;
674 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
675 cf->data[2] |= CAN_ERR_PROT_BIT;
676 }
677}
678
679static int at91_poll_err(struct net_device *dev, int quota, u32 reg_sr)
680{
681 struct sk_buff *skb;
682 struct can_frame *cf;
683
684 if (quota == 0)
685 return 0;
686
687 skb = alloc_can_err_skb(dev, &cf);
688 if (unlikely(!skb))
689 return 0;
690
691 at91_poll_err_frame(dev, cf, reg_sr);
692 netif_receive_skb(skb);
693
694 dev->last_rx = jiffies;
695 dev->stats.rx_packets++;
696 dev->stats.rx_bytes += cf->can_dlc;
697
698 return 1;
699}
700
701static int at91_poll(struct napi_struct *napi, int quota)
702{
703 struct net_device *dev = napi->dev;
704 const struct at91_priv *priv = netdev_priv(dev);
705 u32 reg_sr = at91_read(priv, AT91_SR);
706 int work_done = 0;
707
708 if (reg_sr & AT91_IRQ_MB_RX)
709 work_done += at91_poll_rx(dev, quota - work_done);
710
711 /*
712 * The error bits are clear on read,
713 * so use saved value from irq handler.
714 */
715 reg_sr |= priv->reg_sr;
716 if (reg_sr & AT91_IRQ_ERR_FRAME)
717 work_done += at91_poll_err(dev, quota - work_done, reg_sr);
718
719 if (work_done < quota) {
720 /* enable IRQs for frame errors and all mailboxes >= rx_next */
721 u32 reg_ier = AT91_IRQ_ERR_FRAME;
722 reg_ier |= AT91_IRQ_MB_RX & ~AT91_MB_RX_MASK(priv->rx_next);
723
724 napi_complete(napi);
725 at91_write(priv, AT91_IER, reg_ier);
726 }
727
728 return work_done;
729}
730
731/*
732 * theory of operation:
733 *
734 * priv->tx_echo holds the number of the oldest can_frame put for
735 * transmission into the hardware, but not yet ACKed by the CAN tx
736 * complete IRQ.
737 *
738 * We iterate from priv->tx_echo to priv->tx_next and check if the
739 * packet has been transmitted, echo it back to the CAN framework. If
740 * we discover a not yet transmitted package, stop looking for more.
741 *
742 */
743static void at91_irq_tx(struct net_device *dev, u32 reg_sr)
744{
745 struct at91_priv *priv = netdev_priv(dev);
746 u32 reg_msr;
747 unsigned int mb;
748
749 /* masking of reg_sr not needed, already done by at91_irq */
750
751 for (/* nix */; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) {
752 mb = get_tx_echo_mb(priv);
753
754 /* no event in mailbox? */
755 if (!(reg_sr & (1 << mb)))
756 break;
757
758 /* Disable irq for this TX mailbox */
759 at91_write(priv, AT91_IDR, 1 << mb);
760
761 /*
762 * only echo if mailbox signals us a transfer
763 * complete (MSR_MRDY). Otherwise it's a tansfer
764 * abort. "can_bus_off()" takes care about the skbs
765 * parked in the echo queue.
766 */
767 reg_msr = at91_read(priv, AT91_MSR(mb));
768 if (likely(reg_msr & AT91_MSR_MRDY &&
769 ~reg_msr & AT91_MSR_MABT)) {
770 /* _NOTE_: substract AT91_MB_TX_FIRST offset from mb! */
771 can_get_echo_skb(dev, mb - AT91_MB_TX_FIRST);
772 dev->stats.tx_packets++;
773 }
774 }
775
776 /*
777 * restart queue if we don't have a wrap around but restart if
778 * we get a TX int for the last can frame directly before a
779 * wrap around.
780 */
781 if ((priv->tx_next & AT91_NEXT_MASK) != 0 ||
782 (priv->tx_echo & AT91_NEXT_MASK) == 0)
783 netif_wake_queue(dev);
784}
785
786static void at91_irq_err_state(struct net_device *dev,
787 struct can_frame *cf, enum can_state new_state)
788{
789 struct at91_priv *priv = netdev_priv(dev);
790 u32 reg_idr, reg_ier, reg_ecr;
791 u8 tec, rec;
792
793 reg_ecr = at91_read(priv, AT91_ECR);
794 rec = reg_ecr & 0xff;
795 tec = reg_ecr >> 16;
796
797 switch (priv->can.state) {
798 case CAN_STATE_ERROR_ACTIVE:
799 /*
800 * from: ERROR_ACTIVE
801 * to : ERROR_WARNING, ERROR_PASSIVE, BUS_OFF
802 * => : there was a warning int
803 */
804 if (new_state >= CAN_STATE_ERROR_WARNING &&
805 new_state <= CAN_STATE_BUS_OFF) {
806 dev_dbg(dev->dev.parent, "Error Warning IRQ\n");
807 priv->can.can_stats.error_warning++;
808
809 cf->can_id |= CAN_ERR_CRTL;
810 cf->data[1] = (tec > rec) ?
811 CAN_ERR_CRTL_TX_WARNING :
812 CAN_ERR_CRTL_RX_WARNING;
813 }
814 case CAN_STATE_ERROR_WARNING: /* fallthrough */
815 /*
816 * from: ERROR_ACTIVE, ERROR_WARNING
817 * to : ERROR_PASSIVE, BUS_OFF
818 * => : error passive int
819 */
820 if (new_state >= CAN_STATE_ERROR_PASSIVE &&
821 new_state <= CAN_STATE_BUS_OFF) {
822 dev_dbg(dev->dev.parent, "Error Passive IRQ\n");
823 priv->can.can_stats.error_passive++;
824
825 cf->can_id |= CAN_ERR_CRTL;
826 cf->data[1] = (tec > rec) ?
827 CAN_ERR_CRTL_TX_PASSIVE :
828 CAN_ERR_CRTL_RX_PASSIVE;
829 }
830 break;
831 case CAN_STATE_BUS_OFF:
832 /*
833 * from: BUS_OFF
834 * to : ERROR_ACTIVE, ERROR_WARNING, ERROR_PASSIVE
835 */
836 if (new_state <= CAN_STATE_ERROR_PASSIVE) {
837 cf->can_id |= CAN_ERR_RESTARTED;
838
839 dev_dbg(dev->dev.parent, "restarted\n");
840 priv->can.can_stats.restarts++;
841
842 netif_carrier_on(dev);
843 netif_wake_queue(dev);
844 }
845 break;
846 default:
847 break;
848 }
849
850
851 /* process state changes depending on the new state */
852 switch (new_state) {
853 case CAN_STATE_ERROR_ACTIVE:
854 /*
855 * actually we want to enable AT91_IRQ_WARN here, but
856 * it screws up the system under certain
857 * circumstances. so just enable AT91_IRQ_ERRP, thus
858 * the "fallthrough"
859 */
860 dev_dbg(dev->dev.parent, "Error Active\n");
861 cf->can_id |= CAN_ERR_PROT;
862 cf->data[2] = CAN_ERR_PROT_ACTIVE;
863 case CAN_STATE_ERROR_WARNING: /* fallthrough */
864 reg_idr = AT91_IRQ_ERRA | AT91_IRQ_WARN | AT91_IRQ_BOFF;
865 reg_ier = AT91_IRQ_ERRP;
866 break;
867 case CAN_STATE_ERROR_PASSIVE:
868 reg_idr = AT91_IRQ_ERRA | AT91_IRQ_WARN | AT91_IRQ_ERRP;
869 reg_ier = AT91_IRQ_BOFF;
870 break;
871 case CAN_STATE_BUS_OFF:
872 reg_idr = AT91_IRQ_ERRA | AT91_IRQ_ERRP |
873 AT91_IRQ_WARN | AT91_IRQ_BOFF;
874 reg_ier = 0;
875
876 cf->can_id |= CAN_ERR_BUSOFF;
877
878 dev_dbg(dev->dev.parent, "bus-off\n");
879 netif_carrier_off(dev);
880 priv->can.can_stats.bus_off++;
881
882 /* turn off chip, if restart is disabled */
883 if (!priv->can.restart_ms) {
884 at91_chip_stop(dev, CAN_STATE_BUS_OFF);
885 return;
886 }
887 break;
888 default:
889 break;
890 }
891
892 at91_write(priv, AT91_IDR, reg_idr);
893 at91_write(priv, AT91_IER, reg_ier);
894}
895
896static void at91_irq_err(struct net_device *dev)
897{
898 struct at91_priv *priv = netdev_priv(dev);
899 struct sk_buff *skb;
900 struct can_frame *cf;
901 enum can_state new_state;
902 u32 reg_sr;
903
904 reg_sr = at91_read(priv, AT91_SR);
905
906 /* we need to look at the unmasked reg_sr */
907 if (unlikely(reg_sr & AT91_IRQ_BOFF))
908 new_state = CAN_STATE_BUS_OFF;
909 else if (unlikely(reg_sr & AT91_IRQ_ERRP))
910 new_state = CAN_STATE_ERROR_PASSIVE;
911 else if (unlikely(reg_sr & AT91_IRQ_WARN))
912 new_state = CAN_STATE_ERROR_WARNING;
913 else if (likely(reg_sr & AT91_IRQ_ERRA))
914 new_state = CAN_STATE_ERROR_ACTIVE;
915 else {
916 dev_err(dev->dev.parent, "BUG! hardware in undefined state\n");
917 return;
918 }
919
920 /* state hasn't changed */
921 if (likely(new_state == priv->can.state))
922 return;
923
924 skb = alloc_can_err_skb(dev, &cf);
925 if (unlikely(!skb))
926 return;
927
928 at91_irq_err_state(dev, cf, new_state);
929 netif_rx(skb);
930
931 dev->last_rx = jiffies;
932 dev->stats.rx_packets++;
933 dev->stats.rx_bytes += cf->can_dlc;
934
935 priv->can.state = new_state;
936}
937
938/*
939 * interrupt handler
940 */
941static irqreturn_t at91_irq(int irq, void *dev_id)
942{
943 struct net_device *dev = dev_id;
944 struct at91_priv *priv = netdev_priv(dev);
945 irqreturn_t handled = IRQ_NONE;
946 u32 reg_sr, reg_imr;
947
948 reg_sr = at91_read(priv, AT91_SR);
949 reg_imr = at91_read(priv, AT91_IMR);
950
951 /* Ignore masked interrupts */
952 reg_sr &= reg_imr;
953 if (!reg_sr)
954 goto exit;
955
956 handled = IRQ_HANDLED;
957
958 /* Receive or error interrupt? -> napi */
959 if (reg_sr & (AT91_IRQ_MB_RX | AT91_IRQ_ERR_FRAME)) {
960 /*
961 * The error bits are clear on read,
962 * save for later use.
963 */
964 priv->reg_sr = reg_sr;
965 at91_write(priv, AT91_IDR,
966 AT91_IRQ_MB_RX | AT91_IRQ_ERR_FRAME);
967 napi_schedule(&priv->napi);
968 }
969
970 /* Transmission complete interrupt */
971 if (reg_sr & AT91_IRQ_MB_TX)
972 at91_irq_tx(dev, reg_sr);
973
974 at91_irq_err(dev);
975
976 exit:
977 return handled;
978}
979
980static int at91_open(struct net_device *dev)
981{
982 struct at91_priv *priv = netdev_priv(dev);
983 int err;
984
985 clk_enable(priv->clk);
986
987 /* check or determine and set bittime */
988 err = open_candev(dev);
989 if (err)
990 goto out;
991
992 /* register interrupt handler */
993 if (request_irq(dev->irq, at91_irq, IRQF_SHARED,
994 dev->name, dev)) {
995 err = -EAGAIN;
996 goto out_close;
997 }
998
999 /* start chip and queuing */
1000 at91_chip_start(dev);
1001 napi_enable(&priv->napi);
1002 netif_start_queue(dev);
1003
1004 return 0;
1005
1006 out_close:
1007 close_candev(dev);
1008 out:
1009 clk_disable(priv->clk);
1010
1011 return err;
1012}
1013
1014/*
1015 * stop CAN bus activity
1016 */
1017static int at91_close(struct net_device *dev)
1018{
1019 struct at91_priv *priv = netdev_priv(dev);
1020
1021 netif_stop_queue(dev);
1022 napi_disable(&priv->napi);
1023 at91_chip_stop(dev, CAN_STATE_STOPPED);
1024
1025 free_irq(dev->irq, dev);
1026 clk_disable(priv->clk);
1027
1028 close_candev(dev);
1029
1030 return 0;
1031}
1032
1033static int at91_set_mode(struct net_device *dev, enum can_mode mode)
1034{
1035 switch (mode) {
1036 case CAN_MODE_START:
1037 at91_chip_start(dev);
1038 netif_wake_queue(dev);
1039 break;
1040
1041 default:
1042 return -EOPNOTSUPP;
1043 }
1044
1045 return 0;
1046}
1047
1048static const struct net_device_ops at91_netdev_ops = {
1049 .ndo_open = at91_open,
1050 .ndo_stop = at91_close,
1051 .ndo_start_xmit = at91_start_xmit,
1052};
1053
1054static int __init at91_can_probe(struct platform_device *pdev)
1055{
1056 struct net_device *dev;
1057 struct at91_priv *priv;
1058 struct resource *res;
1059 struct clk *clk;
1060 void __iomem *addr;
1061 int err, irq;
1062
1063 clk = clk_get(&pdev->dev, "can_clk");
1064 if (IS_ERR(clk)) {
1065 dev_err(&pdev->dev, "no clock defined\n");
1066 err = -ENODEV;
1067 goto exit;
1068 }
1069
1070 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1071 irq = platform_get_irq(pdev, 0);
1072 if (!res || !irq) {
1073 err = -ENODEV;
1074 goto exit_put;
1075 }
1076
1077 if (!request_mem_region(res->start,
1078 resource_size(res),
1079 pdev->name)) {
1080 err = -EBUSY;
1081 goto exit_put;
1082 }
1083
1084 addr = ioremap_nocache(res->start, resource_size(res));
1085 if (!addr) {
1086 err = -ENOMEM;
1087 goto exit_release;
1088 }
1089
1090 dev = alloc_candev(sizeof(struct at91_priv));
1091 if (!dev) {
1092 err = -ENOMEM;
1093 goto exit_iounmap;
1094 }
1095
1096 dev->netdev_ops = &at91_netdev_ops;
1097 dev->irq = irq;
1098 dev->flags |= IFF_ECHO;
1099
1100 priv = netdev_priv(dev);
1101 priv->can.clock.freq = clk_get_rate(clk);
1102 priv->can.bittiming_const = &at91_bittiming_const;
1103 priv->can.do_set_bittiming = at91_set_bittiming;
1104 priv->can.do_set_mode = at91_set_mode;
1105 priv->reg_base = addr;
1106 priv->dev = dev;
1107 priv->clk = clk;
1108 priv->pdata = pdev->dev.platform_data;
1109
1110 netif_napi_add(dev, &priv->napi, at91_poll, AT91_NAPI_WEIGHT);
1111
1112 dev_set_drvdata(&pdev->dev, dev);
1113 SET_NETDEV_DEV(dev, &pdev->dev);
1114
1115 err = register_candev(dev);
1116 if (err) {
1117 dev_err(&pdev->dev, "registering netdev failed\n");
1118 goto exit_free;
1119 }
1120
1121 dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
1122 priv->reg_base, dev->irq);
1123
1124 return 0;
1125
1126 exit_free:
1127 free_netdev(dev);
1128 exit_iounmap:
1129 iounmap(addr);
1130 exit_release:
1131 release_mem_region(res->start, resource_size(res));
1132 exit_put:
1133 clk_put(clk);
1134 exit:
1135 return err;
1136}
1137
1138static int __devexit at91_can_remove(struct platform_device *pdev)
1139{
1140 struct net_device *dev = platform_get_drvdata(pdev);
1141 struct at91_priv *priv = netdev_priv(dev);
1142 struct resource *res;
1143
1144 unregister_netdev(dev);
1145
1146 platform_set_drvdata(pdev, NULL);
1147
1148 free_netdev(dev);
1149
1150 iounmap(priv->reg_base);
1151
1152 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1153 release_mem_region(res->start, resource_size(res));
1154
1155 clk_put(priv->clk);
1156
1157 return 0;
1158}
1159
1160static struct platform_driver at91_can_driver = {
1161 .probe = at91_can_probe,
1162 .remove = __devexit_p(at91_can_remove),
1163 .driver = {
1164 .name = DRV_NAME,
1165 .owner = THIS_MODULE,
1166 },
1167};
1168
1169static int __init at91_can_module_init(void)
1170{
1171 printk(KERN_INFO "%s netdevice driver\n", DRV_NAME);
1172 return platform_driver_register(&at91_can_driver);
1173}
1174
1175static void __exit at91_can_module_exit(void)
1176{
1177 platform_driver_unregister(&at91_can_driver);
1178 printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
1179}
1180
1181module_init(at91_can_module_init);
1182module_exit(at91_can_module_exit);
1183
1184MODULE_AUTHOR("Marc Kleine-Budde <mkl@pengutronix.de>");
1185MODULE_LICENSE("GPL v2");
1186MODULE_DESCRIPTION(DRV_NAME " CAN netdevice driver");
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index d465eaa796c4..65a2d0ba64e2 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -200,6 +200,9 @@ static const char emac_version_string[] = "TI DaVinci EMAC Linux v6.1";
200/** NOTE:: For DM646x the IN_VECTOR has changed */ 200/** NOTE:: For DM646x the IN_VECTOR has changed */
201#define EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC BIT(EMAC_DEF_RX_CH) 201#define EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC BIT(EMAC_DEF_RX_CH)
202#define EMAC_DM646X_MAC_IN_VECTOR_TX_INT_VEC BIT(16 + EMAC_DEF_TX_CH) 202#define EMAC_DM646X_MAC_IN_VECTOR_TX_INT_VEC BIT(16 + EMAC_DEF_TX_CH)
203#define EMAC_DM646X_MAC_IN_VECTOR_HOST_INT BIT(26)
204#define EMAC_DM646X_MAC_IN_VECTOR_STATPEND_INT BIT(27)
205
203 206
204/* CPPI bit positions */ 207/* CPPI bit positions */
205#define EMAC_CPPI_SOP_BIT BIT(31) 208#define EMAC_CPPI_SOP_BIT BIT(31)
@@ -2167,7 +2170,11 @@ static int emac_poll(struct napi_struct *napi, int budget)
2167 emac_int_enable(priv); 2170 emac_int_enable(priv);
2168 } 2171 }
2169 2172
2170 if (unlikely(status & EMAC_DM644X_MAC_IN_VECTOR_HOST_INT)) { 2173 mask = EMAC_DM644X_MAC_IN_VECTOR_HOST_INT;
2174 if (priv->version == EMAC_VERSION_2)
2175 mask = EMAC_DM646X_MAC_IN_VECTOR_HOST_INT;
2176
2177 if (unlikely(status & mask)) {
2171 u32 ch, cause; 2178 u32 ch, cause;
2172 dev_err(emac_dev, "DaVinci EMAC: Fatal Hardware Error\n"); 2179 dev_err(emac_dev, "DaVinci EMAC: Fatal Hardware Error\n");
2173 netif_stop_queue(ndev); 2180 netif_stop_queue(ndev);
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 5c498d2b043f..d445845f2779 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1,4 +1,4 @@
1/* A simple network driver using virtio. 1/* A network driver using virtio.
2 * 2 *
3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation 3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 * 4 *
@@ -48,19 +48,9 @@ struct virtnet_info
48 struct napi_struct napi; 48 struct napi_struct napi;
49 unsigned int status; 49 unsigned int status;
50 50
51 /* The skb we couldn't send because buffers were full. */
52 struct sk_buff *last_xmit_skb;
53
54 /* If we need to free in a timer, this is it. */
55 struct timer_list xmit_free_timer;
56
57 /* Number of input buffers, and max we've ever had. */ 51 /* Number of input buffers, and max we've ever had. */
58 unsigned int num, max; 52 unsigned int num, max;
59 53
60 /* For cleaning up after transmission. */
61 struct tasklet_struct tasklet;
62 bool free_in_tasklet;
63
64 /* I like... big packets and I cannot lie! */ 54 /* I like... big packets and I cannot lie! */
65 bool big_packets; 55 bool big_packets;
66 56
@@ -78,9 +68,17 @@ struct virtnet_info
78 struct page *pages; 68 struct page *pages;
79}; 69};
80 70
81static inline void *skb_vnet_hdr(struct sk_buff *skb) 71struct skb_vnet_hdr {
72 union {
73 struct virtio_net_hdr hdr;
74 struct virtio_net_hdr_mrg_rxbuf mhdr;
75 };
76 unsigned int num_sg;
77};
78
79static inline struct skb_vnet_hdr *skb_vnet_hdr(struct sk_buff *skb)
82{ 80{
83 return (struct virtio_net_hdr *)skb->cb; 81 return (struct skb_vnet_hdr *)skb->cb;
84} 82}
85 83
86static void give_a_page(struct virtnet_info *vi, struct page *page) 84static void give_a_page(struct virtnet_info *vi, struct page *page)
@@ -119,17 +117,13 @@ static void skb_xmit_done(struct virtqueue *svq)
119 117
120 /* We were probably waiting for more output buffers. */ 118 /* We were probably waiting for more output buffers. */
121 netif_wake_queue(vi->dev); 119 netif_wake_queue(vi->dev);
122
123 /* Make sure we re-xmit last_xmit_skb: if there are no more packets
124 * queued, start_xmit won't be called. */
125 tasklet_schedule(&vi->tasklet);
126} 120}
127 121
128static void receive_skb(struct net_device *dev, struct sk_buff *skb, 122static void receive_skb(struct net_device *dev, struct sk_buff *skb,
129 unsigned len) 123 unsigned len)
130{ 124{
131 struct virtnet_info *vi = netdev_priv(dev); 125 struct virtnet_info *vi = netdev_priv(dev);
132 struct virtio_net_hdr *hdr = skb_vnet_hdr(skb); 126 struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb);
133 int err; 127 int err;
134 int i; 128 int i;
135 129
@@ -140,7 +134,6 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
140 } 134 }
141 135
142 if (vi->mergeable_rx_bufs) { 136 if (vi->mergeable_rx_bufs) {
143 struct virtio_net_hdr_mrg_rxbuf *mhdr = skb_vnet_hdr(skb);
144 unsigned int copy; 137 unsigned int copy;
145 char *p = page_address(skb_shinfo(skb)->frags[0].page); 138 char *p = page_address(skb_shinfo(skb)->frags[0].page);
146 139
@@ -148,8 +141,8 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
148 len = PAGE_SIZE; 141 len = PAGE_SIZE;
149 len -= sizeof(struct virtio_net_hdr_mrg_rxbuf); 142 len -= sizeof(struct virtio_net_hdr_mrg_rxbuf);
150 143
151 memcpy(hdr, p, sizeof(*mhdr)); 144 memcpy(&hdr->mhdr, p, sizeof(hdr->mhdr));
152 p += sizeof(*mhdr); 145 p += sizeof(hdr->mhdr);
153 146
154 copy = len; 147 copy = len;
155 if (copy > skb_tailroom(skb)) 148 if (copy > skb_tailroom(skb))
@@ -164,13 +157,13 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
164 skb_shinfo(skb)->nr_frags--; 157 skb_shinfo(skb)->nr_frags--;
165 } else { 158 } else {
166 skb_shinfo(skb)->frags[0].page_offset += 159 skb_shinfo(skb)->frags[0].page_offset +=
167 sizeof(*mhdr) + copy; 160 sizeof(hdr->mhdr) + copy;
168 skb_shinfo(skb)->frags[0].size = len; 161 skb_shinfo(skb)->frags[0].size = len;
169 skb->data_len += len; 162 skb->data_len += len;
170 skb->len += len; 163 skb->len += len;
171 } 164 }
172 165
173 while (--mhdr->num_buffers) { 166 while (--hdr->mhdr.num_buffers) {
174 struct sk_buff *nskb; 167 struct sk_buff *nskb;
175 168
176 i = skb_shinfo(skb)->nr_frags; 169 i = skb_shinfo(skb)->nr_frags;
@@ -184,7 +177,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
184 nskb = vi->rvq->vq_ops->get_buf(vi->rvq, &len); 177 nskb = vi->rvq->vq_ops->get_buf(vi->rvq, &len);
185 if (!nskb) { 178 if (!nskb) {
186 pr_debug("%s: rx error: %d buffers missing\n", 179 pr_debug("%s: rx error: %d buffers missing\n",
187 dev->name, mhdr->num_buffers); 180 dev->name, hdr->mhdr.num_buffers);
188 dev->stats.rx_length_errors++; 181 dev->stats.rx_length_errors++;
189 goto drop; 182 goto drop;
190 } 183 }
@@ -205,7 +198,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
205 skb->len += len; 198 skb->len += len;
206 } 199 }
207 } else { 200 } else {
208 len -= sizeof(struct virtio_net_hdr); 201 len -= sizeof(hdr->hdr);
209 202
210 if (len <= MAX_PACKET_LEN) 203 if (len <= MAX_PACKET_LEN)
211 trim_pages(vi, skb); 204 trim_pages(vi, skb);
@@ -223,9 +216,11 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
223 dev->stats.rx_bytes += skb->len; 216 dev->stats.rx_bytes += skb->len;
224 dev->stats.rx_packets++; 217 dev->stats.rx_packets++;
225 218
226 if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { 219 if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
227 pr_debug("Needs csum!\n"); 220 pr_debug("Needs csum!\n");
228 if (!skb_partial_csum_set(skb,hdr->csum_start,hdr->csum_offset)) 221 if (!skb_partial_csum_set(skb,
222 hdr->hdr.csum_start,
223 hdr->hdr.csum_offset))
229 goto frame_err; 224 goto frame_err;
230 } 225 }
231 226
@@ -233,9 +228,9 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
233 pr_debug("Receiving skb proto 0x%04x len %i type %i\n", 228 pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
234 ntohs(skb->protocol), skb->len, skb->pkt_type); 229 ntohs(skb->protocol), skb->len, skb->pkt_type);
235 230
236 if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { 231 if (hdr->hdr.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
237 pr_debug("GSO!\n"); 232 pr_debug("GSO!\n");
238 switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { 233 switch (hdr->hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
239 case VIRTIO_NET_HDR_GSO_TCPV4: 234 case VIRTIO_NET_HDR_GSO_TCPV4:
240 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; 235 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
241 break; 236 break;
@@ -248,14 +243,14 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
248 default: 243 default:
249 if (net_ratelimit()) 244 if (net_ratelimit())
250 printk(KERN_WARNING "%s: bad gso type %u.\n", 245 printk(KERN_WARNING "%s: bad gso type %u.\n",
251 dev->name, hdr->gso_type); 246 dev->name, hdr->hdr.gso_type);
252 goto frame_err; 247 goto frame_err;
253 } 248 }
254 249
255 if (hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN) 250 if (hdr->hdr.gso_type & VIRTIO_NET_HDR_GSO_ECN)
256 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; 251 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
257 252
258 skb_shinfo(skb)->gso_size = hdr->gso_size; 253 skb_shinfo(skb)->gso_size = hdr->hdr.gso_size;
259 if (skb_shinfo(skb)->gso_size == 0) { 254 if (skb_shinfo(skb)->gso_size == 0) {
260 if (net_ratelimit()) 255 if (net_ratelimit())
261 printk(KERN_WARNING "%s: zero gso size.\n", 256 printk(KERN_WARNING "%s: zero gso size.\n",
@@ -285,8 +280,8 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
285 bool oom = false; 280 bool oom = false;
286 281
287 sg_init_table(sg, 2+MAX_SKB_FRAGS); 282 sg_init_table(sg, 2+MAX_SKB_FRAGS);
288 for (;;) { 283 do {
289 struct virtio_net_hdr *hdr; 284 struct skb_vnet_hdr *hdr;
290 285
291 skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN + NET_IP_ALIGN); 286 skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN + NET_IP_ALIGN);
292 if (unlikely(!skb)) { 287 if (unlikely(!skb)) {
@@ -298,7 +293,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
298 skb_put(skb, MAX_PACKET_LEN); 293 skb_put(skb, MAX_PACKET_LEN);
299 294
300 hdr = skb_vnet_hdr(skb); 295 hdr = skb_vnet_hdr(skb);
301 sg_set_buf(sg, hdr, sizeof(*hdr)); 296 sg_set_buf(sg, &hdr->hdr, sizeof(hdr->hdr));
302 297
303 if (vi->big_packets) { 298 if (vi->big_packets) {
304 for (i = 0; i < MAX_SKB_FRAGS; i++) { 299 for (i = 0; i < MAX_SKB_FRAGS; i++) {
@@ -328,7 +323,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
328 break; 323 break;
329 } 324 }
330 vi->num++; 325 vi->num++;
331 } 326 } while (err >= num);
332 if (unlikely(vi->num > vi->max)) 327 if (unlikely(vi->num > vi->max))
333 vi->max = vi->num; 328 vi->max = vi->num;
334 vi->rvq->vq_ops->kick(vi->rvq); 329 vi->rvq->vq_ops->kick(vi->rvq);
@@ -346,7 +341,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp)
346 if (!vi->mergeable_rx_bufs) 341 if (!vi->mergeable_rx_bufs)
347 return try_fill_recv_maxbufs(vi, gfp); 342 return try_fill_recv_maxbufs(vi, gfp);
348 343
349 for (;;) { 344 do {
350 skb_frag_t *f; 345 skb_frag_t *f;
351 346
352 skb = netdev_alloc_skb(vi->dev, GOOD_COPY_LEN + NET_IP_ALIGN); 347 skb = netdev_alloc_skb(vi->dev, GOOD_COPY_LEN + NET_IP_ALIGN);
@@ -380,7 +375,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp)
380 break; 375 break;
381 } 376 }
382 vi->num++; 377 vi->num++;
383 } 378 } while (err > 0);
384 if (unlikely(vi->num > vi->max)) 379 if (unlikely(vi->num > vi->max))
385 vi->max = vi->num; 380 vi->max = vi->num;
386 vi->rvq->vq_ops->kick(vi->rvq); 381 vi->rvq->vq_ops->kick(vi->rvq);
@@ -448,42 +443,26 @@ again:
448 return received; 443 return received;
449} 444}
450 445
451static void free_old_xmit_skbs(struct virtnet_info *vi) 446static unsigned int free_old_xmit_skbs(struct virtnet_info *vi)
452{ 447{
453 struct sk_buff *skb; 448 struct sk_buff *skb;
454 unsigned int len; 449 unsigned int len, tot_sgs = 0;
455 450
456 while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) { 451 while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) {
457 pr_debug("Sent skb %p\n", skb); 452 pr_debug("Sent skb %p\n", skb);
458 __skb_unlink(skb, &vi->send); 453 __skb_unlink(skb, &vi->send);
459 vi->dev->stats.tx_bytes += skb->len; 454 vi->dev->stats.tx_bytes += skb->len;
460 vi->dev->stats.tx_packets++; 455 vi->dev->stats.tx_packets++;
456 tot_sgs += skb_vnet_hdr(skb)->num_sg;
461 kfree_skb(skb); 457 kfree_skb(skb);
462 } 458 }
463} 459 return tot_sgs;
464
465/* If the virtio transport doesn't always notify us when all in-flight packets
466 * are consumed, we fall back to using this function on a timer to free them. */
467static void xmit_free(unsigned long data)
468{
469 struct virtnet_info *vi = (void *)data;
470
471 netif_tx_lock(vi->dev);
472
473 free_old_xmit_skbs(vi);
474
475 if (!skb_queue_empty(&vi->send))
476 mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10));
477
478 netif_tx_unlock(vi->dev);
479} 460}
480 461
481static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) 462static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
482{ 463{
483 int num, err;
484 struct scatterlist sg[2+MAX_SKB_FRAGS]; 464 struct scatterlist sg[2+MAX_SKB_FRAGS];
485 struct virtio_net_hdr_mrg_rxbuf *mhdr = skb_vnet_hdr(skb); 465 struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb);
486 struct virtio_net_hdr *hdr = skb_vnet_hdr(skb);
487 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; 466 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
488 467
489 sg_init_table(sg, 2+MAX_SKB_FRAGS); 468 sg_init_table(sg, 2+MAX_SKB_FRAGS);
@@ -491,108 +470,89 @@ static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
491 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); 470 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest);
492 471
493 if (skb->ip_summed == CHECKSUM_PARTIAL) { 472 if (skb->ip_summed == CHECKSUM_PARTIAL) {
494 hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; 473 hdr->hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
495 hdr->csum_start = skb->csum_start - skb_headroom(skb); 474 hdr->hdr.csum_start = skb->csum_start - skb_headroom(skb);
496 hdr->csum_offset = skb->csum_offset; 475 hdr->hdr.csum_offset = skb->csum_offset;
497 } else { 476 } else {
498 hdr->flags = 0; 477 hdr->hdr.flags = 0;
499 hdr->csum_offset = hdr->csum_start = 0; 478 hdr->hdr.csum_offset = hdr->hdr.csum_start = 0;
500 } 479 }
501 480
502 if (skb_is_gso(skb)) { 481 if (skb_is_gso(skb)) {
503 hdr->hdr_len = skb_headlen(skb); 482 hdr->hdr.hdr_len = skb_headlen(skb);
504 hdr->gso_size = skb_shinfo(skb)->gso_size; 483 hdr->hdr.gso_size = skb_shinfo(skb)->gso_size;
505 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) 484 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
506 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; 485 hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
507 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 486 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
508 hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; 487 hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
509 else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) 488 else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
510 hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP; 489 hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP;
511 else 490 else
512 BUG(); 491 BUG();
513 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN) 492 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
514 hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN; 493 hdr->hdr.gso_type |= VIRTIO_NET_HDR_GSO_ECN;
515 } else { 494 } else {
516 hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE; 495 hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
517 hdr->gso_size = hdr->hdr_len = 0; 496 hdr->hdr.gso_size = hdr->hdr.hdr_len = 0;
518 } 497 }
519 498
520 mhdr->num_buffers = 0; 499 hdr->mhdr.num_buffers = 0;
521 500
522 /* Encode metadata header at front. */ 501 /* Encode metadata header at front. */
523 if (vi->mergeable_rx_bufs) 502 if (vi->mergeable_rx_bufs)
524 sg_set_buf(sg, mhdr, sizeof(*mhdr)); 503 sg_set_buf(sg, &hdr->mhdr, sizeof(hdr->mhdr));
525 else 504 else
526 sg_set_buf(sg, hdr, sizeof(*hdr)); 505 sg_set_buf(sg, &hdr->hdr, sizeof(hdr->hdr));
527 506
528 num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; 507 hdr->num_sg = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
529 508 return vi->svq->vq_ops->add_buf(vi->svq, sg, hdr->num_sg, 0, skb);
530 err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb);
531 if (err >= 0 && !vi->free_in_tasklet)
532 mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10));
533
534 return err;
535}
536
537static void xmit_tasklet(unsigned long data)
538{
539 struct virtnet_info *vi = (void *)data;
540
541 netif_tx_lock_bh(vi->dev);
542 if (vi->last_xmit_skb && xmit_skb(vi, vi->last_xmit_skb) >= 0) {
543 vi->svq->vq_ops->kick(vi->svq);
544 vi->last_xmit_skb = NULL;
545 }
546 if (vi->free_in_tasklet)
547 free_old_xmit_skbs(vi);
548 netif_tx_unlock_bh(vi->dev);
549} 509}
550 510
551static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) 511static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
552{ 512{
553 struct virtnet_info *vi = netdev_priv(dev); 513 struct virtnet_info *vi = netdev_priv(dev);
514 int capacity;
554 515
555again: 516again:
556 /* Free up any pending old buffers before queueing new ones. */ 517 /* Free up any pending old buffers before queueing new ones. */
557 free_old_xmit_skbs(vi); 518 free_old_xmit_skbs(vi);
558 519
559 /* If we has a buffer left over from last time, send it now. */
560 if (unlikely(vi->last_xmit_skb) &&
561 xmit_skb(vi, vi->last_xmit_skb) < 0)
562 goto stop_queue;
563
564 vi->last_xmit_skb = NULL;
565
566 /* Put new one in send queue and do transmit */ 520 /* Put new one in send queue and do transmit */
567 if (likely(skb)) { 521 __skb_queue_head(&vi->send, skb);
568 __skb_queue_head(&vi->send, skb); 522 capacity = xmit_skb(vi, skb);
569 if (xmit_skb(vi, skb) < 0) { 523
570 vi->last_xmit_skb = skb; 524 /* This can happen with OOM and indirect buffers. */
571 skb = NULL; 525 if (unlikely(capacity < 0)) {
572 goto stop_queue; 526 netif_stop_queue(dev);
527 dev_warn(&dev->dev, "Unexpected full queue\n");
528 if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) {
529 vi->svq->vq_ops->disable_cb(vi->svq);
530 netif_start_queue(dev);
531 goto again;
573 } 532 }
533 return NETDEV_TX_BUSY;
574 } 534 }
575done:
576 vi->svq->vq_ops->kick(vi->svq);
577 return NETDEV_TX_OK;
578 535
579stop_queue: 536 vi->svq->vq_ops->kick(vi->svq);
580 pr_debug("%s: virtio not prepared to send\n", dev->name); 537 /* Don't wait up for transmitted skbs to be freed. */
581 netif_stop_queue(dev); 538 skb_orphan(skb);
582 539 nf_reset(skb);
583 /* Activate callback for using skbs: if this returns false it 540
584 * means some were used in the meantime. */ 541 /* Apparently nice girls don't return TX_BUSY; stop the queue
585 if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) { 542 * before it gets out of hand. Naturally, this wastes entries. */
586 vi->svq->vq_ops->disable_cb(vi->svq); 543 if (capacity < 2+MAX_SKB_FRAGS) {
587 netif_start_queue(dev); 544 netif_stop_queue(dev);
588 goto again; 545 if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) {
589 } 546 /* More just got used, free them then recheck. */
590 if (skb) { 547 capacity += free_old_xmit_skbs(vi);
591 /* Drop this skb: we only queue one. */ 548 if (capacity >= 2+MAX_SKB_FRAGS) {
592 vi->dev->stats.tx_dropped++; 549 netif_start_queue(dev);
593 kfree_skb(skb); 550 vi->svq->vq_ops->disable_cb(vi->svq);
551 }
552 }
594 } 553 }
595 goto done; 554
555 return NETDEV_TX_OK;
596} 556}
597 557
598static int virtnet_set_mac_address(struct net_device *dev, void *p) 558static int virtnet_set_mac_address(struct net_device *dev, void *p)
@@ -925,10 +885,6 @@ static int virtnet_probe(struct virtio_device *vdev)
925 vi->pages = NULL; 885 vi->pages = NULL;
926 INIT_DELAYED_WORK(&vi->refill, refill_work); 886 INIT_DELAYED_WORK(&vi->refill, refill_work);
927 887
928 /* If they give us a callback when all buffers are done, we don't need
929 * the timer. */
930 vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY);
931
932 /* If we can receive ANY GSO packets, we must allocate large ones. */ 888 /* If we can receive ANY GSO packets, we must allocate large ones. */
933 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) 889 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4)
934 || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) 890 || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)
@@ -960,11 +916,6 @@ static int virtnet_probe(struct virtio_device *vdev)
960 skb_queue_head_init(&vi->recv); 916 skb_queue_head_init(&vi->recv);
961 skb_queue_head_init(&vi->send); 917 skb_queue_head_init(&vi->send);
962 918
963 tasklet_init(&vi->tasklet, xmit_tasklet, (unsigned long)vi);
964
965 if (!vi->free_in_tasklet)
966 setup_timer(&vi->xmit_free_timer, xmit_free, (unsigned long)vi);
967
968 err = register_netdev(dev); 919 err = register_netdev(dev);
969 if (err) { 920 if (err) {
970 pr_debug("virtio_net: registering device failed\n"); 921 pr_debug("virtio_net: registering device failed\n");
@@ -1005,9 +956,6 @@ static void virtnet_remove(struct virtio_device *vdev)
1005 /* Stop all the virtqueues. */ 956 /* Stop all the virtqueues. */
1006 vdev->config->reset(vdev); 957 vdev->config->reset(vdev);
1007 958
1008 if (!vi->free_in_tasklet)
1009 del_timer_sync(&vi->xmit_free_timer);
1010
1011 /* Free our skbs in send and recv queues, if any. */ 959 /* Free our skbs in send and recv queues, if any. */
1012 while ((skb = __skb_dequeue(&vi->recv)) != NULL) { 960 while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
1013 kfree_skb(skb); 961 kfree_skb(skb);
@@ -1041,7 +989,6 @@ static unsigned int features[] = {
1041 VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, 989 VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO,
1042 VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, 990 VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
1043 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, 991 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
1044 VIRTIO_F_NOTIFY_ON_EMPTY,
1045}; 992};
1046 993
1047static struct virtio_driver virtio_net = { 994static struct virtio_driver virtio_net = {