2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
27 #include <net/ip6_checksum.h>
29 #include "vmxnet3_int.h"
31 char vmxnet3_driver_name
[] = "vmxnet3";
32 #define VMXNET3_DRIVER_DESC "VMware vmxnet3 virtual NIC driver"
36 * Last entry must be all 0s
38 static DEFINE_PCI_DEVICE_TABLE(vmxnet3_pciid_table
) = {
39 {PCI_VDEVICE(VMWARE
, PCI_DEVICE_ID_VMWARE_VMXNET3
)},
43 MODULE_DEVICE_TABLE(pci
, vmxnet3_pciid_table
);
45 static atomic_t devices_found
;
47 #define VMXNET3_MAX_DEVICES 10
48 static int enable_mq
= 1;
49 static int irq_share_mode
;
52 vmxnet3_write_mac_addr(struct vmxnet3_adapter
*adapter
, u8
*mac
);
55 * Enable/Disable the given intr
58 vmxnet3_enable_intr(struct vmxnet3_adapter
*adapter
, unsigned intr_idx
)
60 VMXNET3_WRITE_BAR0_REG(adapter
, VMXNET3_REG_IMR
+ intr_idx
* 8, 0);
65 vmxnet3_disable_intr(struct vmxnet3_adapter
*adapter
, unsigned intr_idx
)
67 VMXNET3_WRITE_BAR0_REG(adapter
, VMXNET3_REG_IMR
+ intr_idx
* 8, 1);
72 * Enable/Disable all intrs used by the device
75 vmxnet3_enable_all_intrs(struct vmxnet3_adapter
*adapter
)
79 for (i
= 0; i
< adapter
->intr
.num_intrs
; i
++)
80 vmxnet3_enable_intr(adapter
, i
);
81 adapter
->shared
->devRead
.intrConf
.intrCtrl
&=
82 cpu_to_le32(~VMXNET3_IC_DISABLE_ALL
);
87 vmxnet3_disable_all_intrs(struct vmxnet3_adapter
*adapter
)
91 adapter
->shared
->devRead
.intrConf
.intrCtrl
|=
92 cpu_to_le32(VMXNET3_IC_DISABLE_ALL
);
93 for (i
= 0; i
< adapter
->intr
.num_intrs
; i
++)
94 vmxnet3_disable_intr(adapter
, i
);
99 vmxnet3_ack_events(struct vmxnet3_adapter
*adapter
, u32 events
)
101 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_ECR
, events
);
106 vmxnet3_tq_stopped(struct vmxnet3_tx_queue
*tq
, struct vmxnet3_adapter
*adapter
)
113 vmxnet3_tq_start(struct vmxnet3_tx_queue
*tq
, struct vmxnet3_adapter
*adapter
)
116 netif_start_subqueue(adapter
->netdev
, tq
- adapter
->tx_queue
);
121 vmxnet3_tq_wake(struct vmxnet3_tx_queue
*tq
, struct vmxnet3_adapter
*adapter
)
124 netif_wake_subqueue(adapter
->netdev
, (tq
- adapter
->tx_queue
));
129 vmxnet3_tq_stop(struct vmxnet3_tx_queue
*tq
, struct vmxnet3_adapter
*adapter
)
133 netif_stop_subqueue(adapter
->netdev
, (tq
- adapter
->tx_queue
));
138 * Check the link state. This may start or stop the tx queue.
141 vmxnet3_check_link(struct vmxnet3_adapter
*adapter
, bool affectTxQueue
)
147 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
148 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_LINK
);
149 ret
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
150 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
152 adapter
->link_speed
= ret
>> 16;
153 if (ret
& 1) { /* Link is up. */
154 printk(KERN_INFO
"%s: NIC Link is Up %d Mbps\n",
155 adapter
->netdev
->name
, adapter
->link_speed
);
156 if (!netif_carrier_ok(adapter
->netdev
))
157 netif_carrier_on(adapter
->netdev
);
160 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
161 vmxnet3_tq_start(&adapter
->tx_queue
[i
],
165 printk(KERN_INFO
"%s: NIC Link is Down\n",
166 adapter
->netdev
->name
);
167 if (netif_carrier_ok(adapter
->netdev
))
168 netif_carrier_off(adapter
->netdev
);
171 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
172 vmxnet3_tq_stop(&adapter
->tx_queue
[i
], adapter
);
178 vmxnet3_process_events(struct vmxnet3_adapter
*adapter
)
181 u32 events
= le32_to_cpu(adapter
->shared
->ecr
);
185 vmxnet3_ack_events(adapter
, events
);
187 /* Check if link state has changed */
188 if (events
& VMXNET3_ECR_LINK
)
189 vmxnet3_check_link(adapter
, true);
191 /* Check if there is an error on xmit/recv queues */
192 if (events
& (VMXNET3_ECR_TQERR
| VMXNET3_ECR_RQERR
)) {
193 spin_lock(&adapter
->cmd_lock
);
194 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
195 VMXNET3_CMD_GET_QUEUE_STATUS
);
196 spin_unlock(&adapter
->cmd_lock
);
198 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
199 if (adapter
->tqd_start
[i
].status
.stopped
)
200 dev_err(&adapter
->netdev
->dev
,
201 "%s: tq[%d] error 0x%x\n",
202 adapter
->netdev
->name
, i
, le32_to_cpu(
203 adapter
->tqd_start
[i
].status
.error
));
204 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
205 if (adapter
->rqd_start
[i
].status
.stopped
)
206 dev_err(&adapter
->netdev
->dev
,
207 "%s: rq[%d] error 0x%x\n",
208 adapter
->netdev
->name
, i
,
209 adapter
->rqd_start
[i
].status
.error
);
211 schedule_work(&adapter
->work
);
215 #ifdef __BIG_ENDIAN_BITFIELD
217 * The device expects the bitfields in shared structures to be written in
218 * little endian. When CPU is big endian, the following routines are used to
219 * correctly read and write into ABI.
220 * The general technique used here is : double word bitfields are defined in
221 * opposite order for big endian architecture. Then before reading them in
222 * driver the complete double word is translated using le32_to_cpu. Similarly
223 * After the driver writes into bitfields, cpu_to_le32 is used to translate the
224 * double words into required format.
225 * In order to avoid touching bits in shared structure more than once, temporary
226 * descriptors are used. These are passed as srcDesc to following functions.
228 static void vmxnet3_RxDescToCPU(const struct Vmxnet3_RxDesc
*srcDesc
,
229 struct Vmxnet3_RxDesc
*dstDesc
)
231 u32
*src
= (u32
*)srcDesc
+ 2;
232 u32
*dst
= (u32
*)dstDesc
+ 2;
233 dstDesc
->addr
= le64_to_cpu(srcDesc
->addr
);
234 *dst
= le32_to_cpu(*src
);
235 dstDesc
->ext1
= le32_to_cpu(srcDesc
->ext1
);
238 static void vmxnet3_TxDescToLe(const struct Vmxnet3_TxDesc
*srcDesc
,
239 struct Vmxnet3_TxDesc
*dstDesc
)
242 u32
*src
= (u32
*)(srcDesc
+ 1);
243 u32
*dst
= (u32
*)(dstDesc
+ 1);
245 /* Working backwards so that the gen bit is set at the end. */
246 for (i
= 2; i
> 0; i
--) {
249 *dst
= cpu_to_le32(*src
);
254 static void vmxnet3_RxCompToCPU(const struct Vmxnet3_RxCompDesc
*srcDesc
,
255 struct Vmxnet3_RxCompDesc
*dstDesc
)
258 u32
*src
= (u32
*)srcDesc
;
259 u32
*dst
= (u32
*)dstDesc
;
260 for (i
= 0; i
< sizeof(struct Vmxnet3_RxCompDesc
) / sizeof(u32
); i
++) {
261 *dst
= le32_to_cpu(*src
);
268 /* Used to read bitfield values from double words. */
269 static u32
get_bitfield32(const __le32
*bitfield
, u32 pos
, u32 size
)
271 u32 temp
= le32_to_cpu(*bitfield
);
272 u32 mask
= ((1 << size
) - 1) << pos
;
280 #endif /* __BIG_ENDIAN_BITFIELD */
282 #ifdef __BIG_ENDIAN_BITFIELD
284 # define VMXNET3_TXDESC_GET_GEN(txdesc) get_bitfield32(((const __le32 *) \
285 txdesc) + VMXNET3_TXD_GEN_DWORD_SHIFT, \
286 VMXNET3_TXD_GEN_SHIFT, VMXNET3_TXD_GEN_SIZE)
287 # define VMXNET3_TXDESC_GET_EOP(txdesc) get_bitfield32(((const __le32 *) \
288 txdesc) + VMXNET3_TXD_EOP_DWORD_SHIFT, \
289 VMXNET3_TXD_EOP_SHIFT, VMXNET3_TXD_EOP_SIZE)
290 # define VMXNET3_TCD_GET_GEN(tcd) get_bitfield32(((const __le32 *)tcd) + \
291 VMXNET3_TCD_GEN_DWORD_SHIFT, VMXNET3_TCD_GEN_SHIFT, \
292 VMXNET3_TCD_GEN_SIZE)
293 # define VMXNET3_TCD_GET_TXIDX(tcd) get_bitfield32((const __le32 *)tcd, \
294 VMXNET3_TCD_TXIDX_SHIFT, VMXNET3_TCD_TXIDX_SIZE)
295 # define vmxnet3_getRxComp(dstrcd, rcd, tmp) do { \
297 vmxnet3_RxCompToCPU((rcd), (tmp)); \
299 # define vmxnet3_getRxDesc(dstrxd, rxd, tmp) do { \
301 vmxnet3_RxDescToCPU((rxd), (tmp)); \
306 # define VMXNET3_TXDESC_GET_GEN(txdesc) ((txdesc)->gen)
307 # define VMXNET3_TXDESC_GET_EOP(txdesc) ((txdesc)->eop)
308 # define VMXNET3_TCD_GET_GEN(tcd) ((tcd)->gen)
309 # define VMXNET3_TCD_GET_TXIDX(tcd) ((tcd)->txdIdx)
310 # define vmxnet3_getRxComp(dstrcd, rcd, tmp) (dstrcd) = (rcd)
311 # define vmxnet3_getRxDesc(dstrxd, rxd, tmp) (dstrxd) = (rxd)
313 #endif /* __BIG_ENDIAN_BITFIELD */
317 vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info
*tbi
,
318 struct pci_dev
*pdev
)
320 if (tbi
->map_type
== VMXNET3_MAP_SINGLE
)
321 pci_unmap_single(pdev
, tbi
->dma_addr
, tbi
->len
,
323 else if (tbi
->map_type
== VMXNET3_MAP_PAGE
)
324 pci_unmap_page(pdev
, tbi
->dma_addr
, tbi
->len
,
327 BUG_ON(tbi
->map_type
!= VMXNET3_MAP_NONE
);
329 tbi
->map_type
= VMXNET3_MAP_NONE
; /* to help debugging */
334 vmxnet3_unmap_pkt(u32 eop_idx
, struct vmxnet3_tx_queue
*tq
,
335 struct pci_dev
*pdev
, struct vmxnet3_adapter
*adapter
)
340 /* no out of order completion */
341 BUG_ON(tq
->buf_info
[eop_idx
].sop_idx
!= tq
->tx_ring
.next2comp
);
342 BUG_ON(VMXNET3_TXDESC_GET_EOP(&(tq
->tx_ring
.base
[eop_idx
].txd
)) != 1);
344 skb
= tq
->buf_info
[eop_idx
].skb
;
346 tq
->buf_info
[eop_idx
].skb
= NULL
;
348 VMXNET3_INC_RING_IDX_ONLY(eop_idx
, tq
->tx_ring
.size
);
350 while (tq
->tx_ring
.next2comp
!= eop_idx
) {
351 vmxnet3_unmap_tx_buf(tq
->buf_info
+ tq
->tx_ring
.next2comp
,
354 /* update next2comp w/o tx_lock. Since we are marking more,
355 * instead of less, tx ring entries avail, the worst case is
356 * that the tx routine incorrectly re-queues a pkt due to
357 * insufficient tx ring entries.
359 vmxnet3_cmd_ring_adv_next2comp(&tq
->tx_ring
);
363 dev_kfree_skb_any(skb
);
369 vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue
*tq
,
370 struct vmxnet3_adapter
*adapter
)
373 union Vmxnet3_GenericDesc
*gdesc
;
375 gdesc
= tq
->comp_ring
.base
+ tq
->comp_ring
.next2proc
;
376 while (VMXNET3_TCD_GET_GEN(&gdesc
->tcd
) == tq
->comp_ring
.gen
) {
377 completed
+= vmxnet3_unmap_pkt(VMXNET3_TCD_GET_TXIDX(
378 &gdesc
->tcd
), tq
, adapter
->pdev
,
381 vmxnet3_comp_ring_adv_next2proc(&tq
->comp_ring
);
382 gdesc
= tq
->comp_ring
.base
+ tq
->comp_ring
.next2proc
;
386 spin_lock(&tq
->tx_lock
);
387 if (unlikely(vmxnet3_tq_stopped(tq
, adapter
) &&
388 vmxnet3_cmd_ring_desc_avail(&tq
->tx_ring
) >
389 VMXNET3_WAKE_QUEUE_THRESHOLD(tq
) &&
390 netif_carrier_ok(adapter
->netdev
))) {
391 vmxnet3_tq_wake(tq
, adapter
);
393 spin_unlock(&tq
->tx_lock
);
400 vmxnet3_tq_cleanup(struct vmxnet3_tx_queue
*tq
,
401 struct vmxnet3_adapter
*adapter
)
405 while (tq
->tx_ring
.next2comp
!= tq
->tx_ring
.next2fill
) {
406 struct vmxnet3_tx_buf_info
*tbi
;
407 union Vmxnet3_GenericDesc
*gdesc
;
409 tbi
= tq
->buf_info
+ tq
->tx_ring
.next2comp
;
410 gdesc
= tq
->tx_ring
.base
+ tq
->tx_ring
.next2comp
;
412 vmxnet3_unmap_tx_buf(tbi
, adapter
->pdev
);
414 dev_kfree_skb_any(tbi
->skb
);
417 vmxnet3_cmd_ring_adv_next2comp(&tq
->tx_ring
);
420 /* sanity check, verify all buffers are indeed unmapped and freed */
421 for (i
= 0; i
< tq
->tx_ring
.size
; i
++) {
422 BUG_ON(tq
->buf_info
[i
].skb
!= NULL
||
423 tq
->buf_info
[i
].map_type
!= VMXNET3_MAP_NONE
);
426 tq
->tx_ring
.gen
= VMXNET3_INIT_GEN
;
427 tq
->tx_ring
.next2fill
= tq
->tx_ring
.next2comp
= 0;
429 tq
->comp_ring
.gen
= VMXNET3_INIT_GEN
;
430 tq
->comp_ring
.next2proc
= 0;
435 vmxnet3_tq_destroy(struct vmxnet3_tx_queue
*tq
,
436 struct vmxnet3_adapter
*adapter
)
438 if (tq
->tx_ring
.base
) {
439 pci_free_consistent(adapter
->pdev
, tq
->tx_ring
.size
*
440 sizeof(struct Vmxnet3_TxDesc
),
441 tq
->tx_ring
.base
, tq
->tx_ring
.basePA
);
442 tq
->tx_ring
.base
= NULL
;
444 if (tq
->data_ring
.base
) {
445 pci_free_consistent(adapter
->pdev
, tq
->data_ring
.size
*
446 sizeof(struct Vmxnet3_TxDataDesc
),
447 tq
->data_ring
.base
, tq
->data_ring
.basePA
);
448 tq
->data_ring
.base
= NULL
;
450 if (tq
->comp_ring
.base
) {
451 pci_free_consistent(adapter
->pdev
, tq
->comp_ring
.size
*
452 sizeof(struct Vmxnet3_TxCompDesc
),
453 tq
->comp_ring
.base
, tq
->comp_ring
.basePA
);
454 tq
->comp_ring
.base
= NULL
;
461 /* Destroy all tx queues */
463 vmxnet3_tq_destroy_all(struct vmxnet3_adapter
*adapter
)
467 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
468 vmxnet3_tq_destroy(&adapter
->tx_queue
[i
], adapter
);
473 vmxnet3_tq_init(struct vmxnet3_tx_queue
*tq
,
474 struct vmxnet3_adapter
*adapter
)
478 /* reset the tx ring contents to 0 and reset the tx ring states */
479 memset(tq
->tx_ring
.base
, 0, tq
->tx_ring
.size
*
480 sizeof(struct Vmxnet3_TxDesc
));
481 tq
->tx_ring
.next2fill
= tq
->tx_ring
.next2comp
= 0;
482 tq
->tx_ring
.gen
= VMXNET3_INIT_GEN
;
484 memset(tq
->data_ring
.base
, 0, tq
->data_ring
.size
*
485 sizeof(struct Vmxnet3_TxDataDesc
));
487 /* reset the tx comp ring contents to 0 and reset comp ring states */
488 memset(tq
->comp_ring
.base
, 0, tq
->comp_ring
.size
*
489 sizeof(struct Vmxnet3_TxCompDesc
));
490 tq
->comp_ring
.next2proc
= 0;
491 tq
->comp_ring
.gen
= VMXNET3_INIT_GEN
;
493 /* reset the bookkeeping data */
494 memset(tq
->buf_info
, 0, sizeof(tq
->buf_info
[0]) * tq
->tx_ring
.size
);
495 for (i
= 0; i
< tq
->tx_ring
.size
; i
++)
496 tq
->buf_info
[i
].map_type
= VMXNET3_MAP_NONE
;
498 /* stats are not reset */
503 vmxnet3_tq_create(struct vmxnet3_tx_queue
*tq
,
504 struct vmxnet3_adapter
*adapter
)
506 BUG_ON(tq
->tx_ring
.base
|| tq
->data_ring
.base
||
507 tq
->comp_ring
.base
|| tq
->buf_info
);
509 tq
->tx_ring
.base
= pci_alloc_consistent(adapter
->pdev
, tq
->tx_ring
.size
510 * sizeof(struct Vmxnet3_TxDesc
),
511 &tq
->tx_ring
.basePA
);
512 if (!tq
->tx_ring
.base
) {
513 printk(KERN_ERR
"%s: failed to allocate tx ring\n",
514 adapter
->netdev
->name
);
518 tq
->data_ring
.base
= pci_alloc_consistent(adapter
->pdev
,
520 sizeof(struct Vmxnet3_TxDataDesc
),
521 &tq
->data_ring
.basePA
);
522 if (!tq
->data_ring
.base
) {
523 printk(KERN_ERR
"%s: failed to allocate data ring\n",
524 adapter
->netdev
->name
);
528 tq
->comp_ring
.base
= pci_alloc_consistent(adapter
->pdev
,
530 sizeof(struct Vmxnet3_TxCompDesc
),
531 &tq
->comp_ring
.basePA
);
532 if (!tq
->comp_ring
.base
) {
533 printk(KERN_ERR
"%s: failed to allocate tx comp ring\n",
534 adapter
->netdev
->name
);
538 tq
->buf_info
= kcalloc(tq
->tx_ring
.size
, sizeof(tq
->buf_info
[0]),
541 printk(KERN_ERR
"%s: failed to allocate tx bufinfo\n",
542 adapter
->netdev
->name
);
549 vmxnet3_tq_destroy(tq
, adapter
);
554 vmxnet3_tq_cleanup_all(struct vmxnet3_adapter
*adapter
)
558 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
559 vmxnet3_tq_cleanup(&adapter
->tx_queue
[i
], adapter
);
563 * starting from ring->next2fill, allocate rx buffers for the given ring
564 * of the rx queue and update the rx desc. stop after @num_to_alloc buffers
565 * are allocated or allocation fails
569 vmxnet3_rq_alloc_rx_buf(struct vmxnet3_rx_queue
*rq
, u32 ring_idx
,
570 int num_to_alloc
, struct vmxnet3_adapter
*adapter
)
572 int num_allocated
= 0;
573 struct vmxnet3_rx_buf_info
*rbi_base
= rq
->buf_info
[ring_idx
];
574 struct vmxnet3_cmd_ring
*ring
= &rq
->rx_ring
[ring_idx
];
577 while (num_allocated
< num_to_alloc
) {
578 struct vmxnet3_rx_buf_info
*rbi
;
579 union Vmxnet3_GenericDesc
*gd
;
581 rbi
= rbi_base
+ ring
->next2fill
;
582 gd
= ring
->base
+ ring
->next2fill
;
584 if (rbi
->buf_type
== VMXNET3_RX_BUF_SKB
) {
585 if (rbi
->skb
== NULL
) {
586 rbi
->skb
= dev_alloc_skb(rbi
->len
+
588 if (unlikely(rbi
->skb
== NULL
)) {
589 rq
->stats
.rx_buf_alloc_failure
++;
592 rbi
->skb
->dev
= adapter
->netdev
;
594 skb_reserve(rbi
->skb
, NET_IP_ALIGN
);
595 rbi
->dma_addr
= pci_map_single(adapter
->pdev
,
596 rbi
->skb
->data
, rbi
->len
,
599 /* rx buffer skipped by the device */
601 val
= VMXNET3_RXD_BTYPE_HEAD
<< VMXNET3_RXD_BTYPE_SHIFT
;
603 BUG_ON(rbi
->buf_type
!= VMXNET3_RX_BUF_PAGE
||
604 rbi
->len
!= PAGE_SIZE
);
606 if (rbi
->page
== NULL
) {
607 rbi
->page
= alloc_page(GFP_ATOMIC
);
608 if (unlikely(rbi
->page
== NULL
)) {
609 rq
->stats
.rx_buf_alloc_failure
++;
612 rbi
->dma_addr
= pci_map_page(adapter
->pdev
,
613 rbi
->page
, 0, PAGE_SIZE
,
616 /* rx buffers skipped by the device */
618 val
= VMXNET3_RXD_BTYPE_BODY
<< VMXNET3_RXD_BTYPE_SHIFT
;
621 BUG_ON(rbi
->dma_addr
== 0);
622 gd
->rxd
.addr
= cpu_to_le64(rbi
->dma_addr
);
623 gd
->dword
[2] = cpu_to_le32((ring
->gen
<< VMXNET3_RXD_GEN_SHIFT
)
627 vmxnet3_cmd_ring_adv_next2fill(ring
);
629 rq
->uncommitted
[ring_idx
] += num_allocated
;
631 dev_dbg(&adapter
->netdev
->dev
,
632 "alloc_rx_buf: %d allocated, next2fill %u, next2comp "
633 "%u, uncommited %u\n", num_allocated
, ring
->next2fill
,
634 ring
->next2comp
, rq
->uncommitted
[ring_idx
]);
636 /* so that the device can distinguish a full ring and an empty ring */
637 BUG_ON(num_allocated
!= 0 && ring
->next2fill
== ring
->next2comp
);
639 return num_allocated
;
644 vmxnet3_append_frag(struct sk_buff
*skb
, struct Vmxnet3_RxCompDesc
*rcd
,
645 struct vmxnet3_rx_buf_info
*rbi
)
647 struct skb_frag_struct
*frag
= skb_shinfo(skb
)->frags
+
648 skb_shinfo(skb
)->nr_frags
;
650 BUG_ON(skb_shinfo(skb
)->nr_frags
>= MAX_SKB_FRAGS
);
652 frag
->page
= rbi
->page
;
653 frag
->page_offset
= 0;
654 frag
->size
= rcd
->len
;
655 skb
->data_len
+= frag
->size
;
656 skb_shinfo(skb
)->nr_frags
++;
661 vmxnet3_map_pkt(struct sk_buff
*skb
, struct vmxnet3_tx_ctx
*ctx
,
662 struct vmxnet3_tx_queue
*tq
, struct pci_dev
*pdev
,
663 struct vmxnet3_adapter
*adapter
)
666 unsigned long buf_offset
;
668 union Vmxnet3_GenericDesc
*gdesc
;
669 struct vmxnet3_tx_buf_info
*tbi
= NULL
;
671 BUG_ON(ctx
->copy_size
> skb_headlen(skb
));
673 /* use the previous gen bit for the SOP desc */
674 dw2
= (tq
->tx_ring
.gen
^ 0x1) << VMXNET3_TXD_GEN_SHIFT
;
676 ctx
->sop_txd
= tq
->tx_ring
.base
+ tq
->tx_ring
.next2fill
;
677 gdesc
= ctx
->sop_txd
; /* both loops below can be skipped */
679 /* no need to map the buffer if headers are copied */
680 if (ctx
->copy_size
) {
681 ctx
->sop_txd
->txd
.addr
= cpu_to_le64(tq
->data_ring
.basePA
+
682 tq
->tx_ring
.next2fill
*
683 sizeof(struct Vmxnet3_TxDataDesc
));
684 ctx
->sop_txd
->dword
[2] = cpu_to_le32(dw2
| ctx
->copy_size
);
685 ctx
->sop_txd
->dword
[3] = 0;
687 tbi
= tq
->buf_info
+ tq
->tx_ring
.next2fill
;
688 tbi
->map_type
= VMXNET3_MAP_NONE
;
690 dev_dbg(&adapter
->netdev
->dev
,
691 "txd[%u]: 0x%Lx 0x%x 0x%x\n",
692 tq
->tx_ring
.next2fill
,
693 le64_to_cpu(ctx
->sop_txd
->txd
.addr
),
694 ctx
->sop_txd
->dword
[2], ctx
->sop_txd
->dword
[3]);
695 vmxnet3_cmd_ring_adv_next2fill(&tq
->tx_ring
);
697 /* use the right gen for non-SOP desc */
698 dw2
= tq
->tx_ring
.gen
<< VMXNET3_TXD_GEN_SHIFT
;
701 /* linear part can use multiple tx desc if it's big */
702 len
= skb_headlen(skb
) - ctx
->copy_size
;
703 buf_offset
= ctx
->copy_size
;
707 if (len
< VMXNET3_MAX_TX_BUF_SIZE
) {
711 buf_size
= VMXNET3_MAX_TX_BUF_SIZE
;
712 /* spec says that for TxDesc.len, 0 == 2^14 */
715 tbi
= tq
->buf_info
+ tq
->tx_ring
.next2fill
;
716 tbi
->map_type
= VMXNET3_MAP_SINGLE
;
717 tbi
->dma_addr
= pci_map_single(adapter
->pdev
,
718 skb
->data
+ buf_offset
, buf_size
,
723 gdesc
= tq
->tx_ring
.base
+ tq
->tx_ring
.next2fill
;
724 BUG_ON(gdesc
->txd
.gen
== tq
->tx_ring
.gen
);
726 gdesc
->txd
.addr
= cpu_to_le64(tbi
->dma_addr
);
727 gdesc
->dword
[2] = cpu_to_le32(dw2
);
730 dev_dbg(&adapter
->netdev
->dev
,
731 "txd[%u]: 0x%Lx 0x%x 0x%x\n",
732 tq
->tx_ring
.next2fill
, le64_to_cpu(gdesc
->txd
.addr
),
733 le32_to_cpu(gdesc
->dword
[2]), gdesc
->dword
[3]);
734 vmxnet3_cmd_ring_adv_next2fill(&tq
->tx_ring
);
735 dw2
= tq
->tx_ring
.gen
<< VMXNET3_TXD_GEN_SHIFT
;
738 buf_offset
+= buf_size
;
741 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
742 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[i
];
744 tbi
= tq
->buf_info
+ tq
->tx_ring
.next2fill
;
745 tbi
->map_type
= VMXNET3_MAP_PAGE
;
746 tbi
->dma_addr
= pci_map_page(adapter
->pdev
, frag
->page
,
747 frag
->page_offset
, frag
->size
,
750 tbi
->len
= frag
->size
;
752 gdesc
= tq
->tx_ring
.base
+ tq
->tx_ring
.next2fill
;
753 BUG_ON(gdesc
->txd
.gen
== tq
->tx_ring
.gen
);
755 gdesc
->txd
.addr
= cpu_to_le64(tbi
->dma_addr
);
756 gdesc
->dword
[2] = cpu_to_le32(dw2
| frag
->size
);
759 dev_dbg(&adapter
->netdev
->dev
,
760 "txd[%u]: 0x%llu %u %u\n",
761 tq
->tx_ring
.next2fill
, le64_to_cpu(gdesc
->txd
.addr
),
762 le32_to_cpu(gdesc
->dword
[2]), gdesc
->dword
[3]);
763 vmxnet3_cmd_ring_adv_next2fill(&tq
->tx_ring
);
764 dw2
= tq
->tx_ring
.gen
<< VMXNET3_TXD_GEN_SHIFT
;
767 ctx
->eop_txd
= gdesc
;
769 /* set the last buf_info for the pkt */
771 tbi
->sop_idx
= ctx
->sop_txd
- tq
->tx_ring
.base
;
775 /* Init all tx queues */
777 vmxnet3_tq_init_all(struct vmxnet3_adapter
*adapter
)
781 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
782 vmxnet3_tq_init(&adapter
->tx_queue
[i
], adapter
);
787 * parse and copy relevant protocol headers:
788 * For a tso pkt, relevant headers are L2/3/4 including options
789 * For a pkt requesting csum offloading, they are L2/3 and may include L4
790 * if it's a TCP/UDP pkt
793 * -1: error happens during parsing
794 * 0: protocol headers parsed, but too big to be copied
795 * 1: protocol headers parsed and copied
798 * 1. related *ctx fields are updated.
799 * 2. ctx->copy_size is # of bytes copied
800 * 3. the portion copied is guaranteed to be in the linear part
804 vmxnet3_parse_and_copy_hdr(struct sk_buff
*skb
, struct vmxnet3_tx_queue
*tq
,
805 struct vmxnet3_tx_ctx
*ctx
,
806 struct vmxnet3_adapter
*adapter
)
808 struct Vmxnet3_TxDataDesc
*tdd
;
810 if (ctx
->mss
) { /* TSO */
811 ctx
->eth_ip_hdr_size
= skb_transport_offset(skb
);
812 ctx
->l4_hdr_size
= ((struct tcphdr
*)
813 skb_transport_header(skb
))->doff
* 4;
814 ctx
->copy_size
= ctx
->eth_ip_hdr_size
+ ctx
->l4_hdr_size
;
816 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
817 ctx
->eth_ip_hdr_size
= skb_checksum_start_offset(skb
);
820 struct iphdr
*iph
= (struct iphdr
*)
821 skb_network_header(skb
);
822 if (iph
->protocol
== IPPROTO_TCP
)
823 ctx
->l4_hdr_size
= ((struct tcphdr
*)
824 skb_transport_header(skb
))->doff
* 4;
825 else if (iph
->protocol
== IPPROTO_UDP
)
827 * Use tcp header size so that bytes to
828 * be copied are more than required by
832 sizeof(struct tcphdr
);
834 ctx
->l4_hdr_size
= 0;
836 /* for simplicity, don't copy L4 headers */
837 ctx
->l4_hdr_size
= 0;
839 ctx
->copy_size
= ctx
->eth_ip_hdr_size
+
842 ctx
->eth_ip_hdr_size
= 0;
843 ctx
->l4_hdr_size
= 0;
844 /* copy as much as allowed */
845 ctx
->copy_size
= min((unsigned int)VMXNET3_HDR_COPY_SIZE
849 /* make sure headers are accessible directly */
850 if (unlikely(!pskb_may_pull(skb
, ctx
->copy_size
)))
854 if (unlikely(ctx
->copy_size
> VMXNET3_HDR_COPY_SIZE
)) {
855 tq
->stats
.oversized_hdr
++;
860 tdd
= tq
->data_ring
.base
+ tq
->tx_ring
.next2fill
;
862 memcpy(tdd
->data
, skb
->data
, ctx
->copy_size
);
863 dev_dbg(&adapter
->netdev
->dev
,
864 "copy %u bytes to dataRing[%u]\n",
865 ctx
->copy_size
, tq
->tx_ring
.next2fill
);
874 vmxnet3_prepare_tso(struct sk_buff
*skb
,
875 struct vmxnet3_tx_ctx
*ctx
)
877 struct tcphdr
*tcph
= (struct tcphdr
*)skb_transport_header(skb
);
879 struct iphdr
*iph
= (struct iphdr
*)skb_network_header(skb
);
881 tcph
->check
= ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
, 0,
884 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb_network_header(skb
);
885 tcph
->check
= ~csum_ipv6_magic(&iph
->saddr
, &iph
->daddr
, 0,
892 * Transmits a pkt thru a given tq
894 * NETDEV_TX_OK: descriptors are setup successfully
895 * NETDEV_TX_OK: error occurred, the pkt is dropped
896 * NETDEV_TX_BUSY: tx ring is full, queue is stopped
899 * 1. tx ring may be changed
900 * 2. tq stats may be updated accordingly
901 * 3. shared->txNumDeferred may be updated
905 vmxnet3_tq_xmit(struct sk_buff
*skb
, struct vmxnet3_tx_queue
*tq
,
906 struct vmxnet3_adapter
*adapter
, struct net_device
*netdev
)
911 struct vmxnet3_tx_ctx ctx
;
912 union Vmxnet3_GenericDesc
*gdesc
;
913 #ifdef __BIG_ENDIAN_BITFIELD
914 /* Use temporary descriptor to avoid touching bits multiple times */
915 union Vmxnet3_GenericDesc tempTxDesc
;
918 /* conservatively estimate # of descriptors to use */
919 count
= VMXNET3_TXD_NEEDED(skb_headlen(skb
)) +
920 skb_shinfo(skb
)->nr_frags
+ 1;
922 ctx
.ipv4
= (skb
->protocol
== cpu_to_be16(ETH_P_IP
));
924 ctx
.mss
= skb_shinfo(skb
)->gso_size
;
926 if (skb_header_cloned(skb
)) {
927 if (unlikely(pskb_expand_head(skb
, 0, 0,
929 tq
->stats
.drop_tso
++;
932 tq
->stats
.copy_skb_header
++;
934 vmxnet3_prepare_tso(skb
, &ctx
);
936 if (unlikely(count
> VMXNET3_MAX_TXD_PER_PKT
)) {
938 /* non-tso pkts must not use more than
939 * VMXNET3_MAX_TXD_PER_PKT entries
941 if (skb_linearize(skb
) != 0) {
942 tq
->stats
.drop_too_many_frags
++;
945 tq
->stats
.linearized
++;
947 /* recalculate the # of descriptors to use */
948 count
= VMXNET3_TXD_NEEDED(skb_headlen(skb
)) + 1;
952 spin_lock_irqsave(&tq
->tx_lock
, flags
);
954 if (count
> vmxnet3_cmd_ring_desc_avail(&tq
->tx_ring
)) {
955 tq
->stats
.tx_ring_full
++;
956 dev_dbg(&adapter
->netdev
->dev
,
957 "tx queue stopped on %s, next2comp %u"
958 " next2fill %u\n", adapter
->netdev
->name
,
959 tq
->tx_ring
.next2comp
, tq
->tx_ring
.next2fill
);
961 vmxnet3_tq_stop(tq
, adapter
);
962 spin_unlock_irqrestore(&tq
->tx_lock
, flags
);
963 return NETDEV_TX_BUSY
;
967 ret
= vmxnet3_parse_and_copy_hdr(skb
, tq
, &ctx
, adapter
);
969 BUG_ON(ret
<= 0 && ctx
.copy_size
!= 0);
970 /* hdrs parsed, check against other limits */
972 if (unlikely(ctx
.eth_ip_hdr_size
+ ctx
.l4_hdr_size
>
973 VMXNET3_MAX_TX_BUF_SIZE
)) {
977 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
978 if (unlikely(ctx
.eth_ip_hdr_size
+
980 VMXNET3_MAX_CSUM_OFFSET
)) {
986 tq
->stats
.drop_hdr_inspect_err
++;
987 goto unlock_drop_pkt
;
990 /* fill tx descs related to addr & len */
991 vmxnet3_map_pkt(skb
, &ctx
, tq
, adapter
->pdev
, adapter
);
993 /* setup the EOP desc */
994 ctx
.eop_txd
->dword
[3] = cpu_to_le32(VMXNET3_TXD_CQ
| VMXNET3_TXD_EOP
);
996 /* setup the SOP desc */
997 #ifdef __BIG_ENDIAN_BITFIELD
999 gdesc
->dword
[2] = ctx
.sop_txd
->dword
[2];
1000 gdesc
->dword
[3] = ctx
.sop_txd
->dword
[3];
1002 gdesc
= ctx
.sop_txd
;
1005 gdesc
->txd
.hlen
= ctx
.eth_ip_hdr_size
+ ctx
.l4_hdr_size
;
1006 gdesc
->txd
.om
= VMXNET3_OM_TSO
;
1007 gdesc
->txd
.msscof
= ctx
.mss
;
1008 le32_add_cpu(&tq
->shared
->txNumDeferred
, (skb
->len
-
1009 gdesc
->txd
.hlen
+ ctx
.mss
- 1) / ctx
.mss
);
1011 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1012 gdesc
->txd
.hlen
= ctx
.eth_ip_hdr_size
;
1013 gdesc
->txd
.om
= VMXNET3_OM_CSUM
;
1014 gdesc
->txd
.msscof
= ctx
.eth_ip_hdr_size
+
1018 gdesc
->txd
.msscof
= 0;
1020 le32_add_cpu(&tq
->shared
->txNumDeferred
, 1);
1023 if (vlan_tx_tag_present(skb
)) {
1025 gdesc
->txd
.tci
= vlan_tx_tag_get(skb
);
1028 /* finally flips the GEN bit of the SOP desc. */
1029 gdesc
->dword
[2] = cpu_to_le32(le32_to_cpu(gdesc
->dword
[2]) ^
1031 #ifdef __BIG_ENDIAN_BITFIELD
1032 /* Finished updating in bitfields of Tx Desc, so write them in original
1035 vmxnet3_TxDescToLe((struct Vmxnet3_TxDesc
*)gdesc
,
1036 (struct Vmxnet3_TxDesc
*)ctx
.sop_txd
);
1037 gdesc
= ctx
.sop_txd
;
1039 dev_dbg(&adapter
->netdev
->dev
,
1040 "txd[%u]: SOP 0x%Lx 0x%x 0x%x\n",
1041 (u32
)((union Vmxnet3_GenericDesc
*)ctx
.sop_txd
-
1042 tq
->tx_ring
.base
), le64_to_cpu(gdesc
->txd
.addr
),
1043 le32_to_cpu(gdesc
->dword
[2]), le32_to_cpu(gdesc
->dword
[3]));
1045 spin_unlock_irqrestore(&tq
->tx_lock
, flags
);
1047 if (le32_to_cpu(tq
->shared
->txNumDeferred
) >=
1048 le32_to_cpu(tq
->shared
->txThreshold
)) {
1049 tq
->shared
->txNumDeferred
= 0;
1050 VMXNET3_WRITE_BAR0_REG(adapter
,
1051 VMXNET3_REG_TXPROD
+ tq
->qid
* 8,
1052 tq
->tx_ring
.next2fill
);
1055 return NETDEV_TX_OK
;
1058 tq
->stats
.drop_oversized_hdr
++;
1060 spin_unlock_irqrestore(&tq
->tx_lock
, flags
);
1062 tq
->stats
.drop_total
++;
1064 return NETDEV_TX_OK
;
1069 vmxnet3_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1071 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1073 BUG_ON(skb
->queue_mapping
> adapter
->num_tx_queues
);
1074 return vmxnet3_tq_xmit(skb
,
1075 &adapter
->tx_queue
[skb
->queue_mapping
],
1081 vmxnet3_rx_csum(struct vmxnet3_adapter
*adapter
,
1082 struct sk_buff
*skb
,
1083 union Vmxnet3_GenericDesc
*gdesc
)
1085 if (!gdesc
->rcd
.cnc
&& adapter
->netdev
->features
& NETIF_F_RXCSUM
) {
1086 /* typical case: TCP/UDP over IP and both csums are correct */
1087 if ((le32_to_cpu(gdesc
->dword
[3]) & VMXNET3_RCD_CSUM_OK
) ==
1088 VMXNET3_RCD_CSUM_OK
) {
1089 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1090 BUG_ON(!(gdesc
->rcd
.tcp
|| gdesc
->rcd
.udp
));
1091 BUG_ON(!(gdesc
->rcd
.v4
|| gdesc
->rcd
.v6
));
1092 BUG_ON(gdesc
->rcd
.frg
);
1094 if (gdesc
->rcd
.csum
) {
1095 skb
->csum
= htons(gdesc
->rcd
.csum
);
1096 skb
->ip_summed
= CHECKSUM_PARTIAL
;
1098 skb_checksum_none_assert(skb
);
1102 skb_checksum_none_assert(skb
);
1108 vmxnet3_rx_error(struct vmxnet3_rx_queue
*rq
, struct Vmxnet3_RxCompDesc
*rcd
,
1109 struct vmxnet3_rx_ctx
*ctx
, struct vmxnet3_adapter
*adapter
)
1111 rq
->stats
.drop_err
++;
1113 rq
->stats
.drop_fcs
++;
1115 rq
->stats
.drop_total
++;
1118 * We do not unmap and chain the rx buffer to the skb.
1119 * We basically pretend this buffer is not used and will be recycled
1120 * by vmxnet3_rq_alloc_rx_buf()
1124 * ctx->skb may be NULL if this is the first and the only one
1128 dev_kfree_skb_irq(ctx
->skb
);
1135 vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue
*rq
,
1136 struct vmxnet3_adapter
*adapter
, int quota
)
1138 static const u32 rxprod_reg
[2] = {
1139 VMXNET3_REG_RXPROD
, VMXNET3_REG_RXPROD2
1142 struct Vmxnet3_RxCompDesc
*rcd
;
1143 struct vmxnet3_rx_ctx
*ctx
= &rq
->rx_ctx
;
1144 #ifdef __BIG_ENDIAN_BITFIELD
1145 struct Vmxnet3_RxDesc rxCmdDesc
;
1146 struct Vmxnet3_RxCompDesc rxComp
;
1148 vmxnet3_getRxComp(rcd
, &rq
->comp_ring
.base
[rq
->comp_ring
.next2proc
].rcd
,
1150 while (rcd
->gen
== rq
->comp_ring
.gen
) {
1151 struct vmxnet3_rx_buf_info
*rbi
;
1152 struct sk_buff
*skb
;
1154 struct Vmxnet3_RxDesc
*rxd
;
1157 if (num_rxd
>= quota
) {
1158 /* we may stop even before we see the EOP desc of
1164 BUG_ON(rcd
->rqID
!= rq
->qid
&& rcd
->rqID
!= rq
->qid2
);
1166 ring_idx
= rcd
->rqID
< adapter
->num_rx_queues
? 0 : 1;
1167 vmxnet3_getRxDesc(rxd
, &rq
->rx_ring
[ring_idx
].base
[idx
].rxd
,
1169 rbi
= rq
->buf_info
[ring_idx
] + idx
;
1171 BUG_ON(rxd
->addr
!= rbi
->dma_addr
||
1172 rxd
->len
!= rbi
->len
);
1174 if (unlikely(rcd
->eop
&& rcd
->err
)) {
1175 vmxnet3_rx_error(rq
, rcd
, ctx
, adapter
);
1179 if (rcd
->sop
) { /* first buf of the pkt */
1180 BUG_ON(rxd
->btype
!= VMXNET3_RXD_BTYPE_HEAD
||
1181 rcd
->rqID
!= rq
->qid
);
1183 BUG_ON(rbi
->buf_type
!= VMXNET3_RX_BUF_SKB
);
1184 BUG_ON(ctx
->skb
!= NULL
|| rbi
->skb
== NULL
);
1186 if (unlikely(rcd
->len
== 0)) {
1187 /* Pretend the rx buffer is skipped. */
1188 BUG_ON(!(rcd
->sop
&& rcd
->eop
));
1189 dev_dbg(&adapter
->netdev
->dev
,
1190 "rxRing[%u][%u] 0 length\n",
1195 ctx
->skb
= rbi
->skb
;
1198 pci_unmap_single(adapter
->pdev
, rbi
->dma_addr
, rbi
->len
,
1199 PCI_DMA_FROMDEVICE
);
1201 skb_put(ctx
->skb
, rcd
->len
);
1203 BUG_ON(ctx
->skb
== NULL
);
1204 /* non SOP buffer must be type 1 in most cases */
1205 if (rbi
->buf_type
== VMXNET3_RX_BUF_PAGE
) {
1206 BUG_ON(rxd
->btype
!= VMXNET3_RXD_BTYPE_BODY
);
1209 pci_unmap_page(adapter
->pdev
,
1210 rbi
->dma_addr
, rbi
->len
,
1211 PCI_DMA_FROMDEVICE
);
1213 vmxnet3_append_frag(ctx
->skb
, rcd
, rbi
);
1218 * The only time a non-SOP buffer is type 0 is
1219 * when it's EOP and error flag is raised, which
1220 * has already been handled.
1228 skb
->len
+= skb
->data_len
;
1229 skb
->truesize
+= skb
->data_len
;
1231 vmxnet3_rx_csum(adapter
, skb
,
1232 (union Vmxnet3_GenericDesc
*)rcd
);
1233 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
1235 if (unlikely(adapter
->vlan_grp
&& rcd
->ts
)) {
1236 vlan_hwaccel_receive_skb(skb
,
1237 adapter
->vlan_grp
, rcd
->tci
);
1239 netif_receive_skb(skb
);
1246 /* device may skip some rx descs */
1247 rq
->rx_ring
[ring_idx
].next2comp
= idx
;
1248 VMXNET3_INC_RING_IDX_ONLY(rq
->rx_ring
[ring_idx
].next2comp
,
1249 rq
->rx_ring
[ring_idx
].size
);
1251 /* refill rx buffers frequently to avoid starving the h/w */
1252 num_to_alloc
= vmxnet3_cmd_ring_desc_avail(rq
->rx_ring
+
1254 if (unlikely(num_to_alloc
> VMXNET3_RX_ALLOC_THRESHOLD(rq
,
1255 ring_idx
, adapter
))) {
1256 vmxnet3_rq_alloc_rx_buf(rq
, ring_idx
, num_to_alloc
,
1259 /* if needed, update the register */
1260 if (unlikely(rq
->shared
->updateRxProd
)) {
1261 VMXNET3_WRITE_BAR0_REG(adapter
,
1262 rxprod_reg
[ring_idx
] + rq
->qid
* 8,
1263 rq
->rx_ring
[ring_idx
].next2fill
);
1264 rq
->uncommitted
[ring_idx
] = 0;
1268 vmxnet3_comp_ring_adv_next2proc(&rq
->comp_ring
);
1269 vmxnet3_getRxComp(rcd
,
1270 &rq
->comp_ring
.base
[rq
->comp_ring
.next2proc
].rcd
, &rxComp
);
1278 vmxnet3_rq_cleanup(struct vmxnet3_rx_queue
*rq
,
1279 struct vmxnet3_adapter
*adapter
)
1282 struct Vmxnet3_RxDesc
*rxd
;
1284 for (ring_idx
= 0; ring_idx
< 2; ring_idx
++) {
1285 for (i
= 0; i
< rq
->rx_ring
[ring_idx
].size
; i
++) {
1286 #ifdef __BIG_ENDIAN_BITFIELD
1287 struct Vmxnet3_RxDesc rxDesc
;
1289 vmxnet3_getRxDesc(rxd
,
1290 &rq
->rx_ring
[ring_idx
].base
[i
].rxd
, &rxDesc
);
1292 if (rxd
->btype
== VMXNET3_RXD_BTYPE_HEAD
&&
1293 rq
->buf_info
[ring_idx
][i
].skb
) {
1294 pci_unmap_single(adapter
->pdev
, rxd
->addr
,
1295 rxd
->len
, PCI_DMA_FROMDEVICE
);
1296 dev_kfree_skb(rq
->buf_info
[ring_idx
][i
].skb
);
1297 rq
->buf_info
[ring_idx
][i
].skb
= NULL
;
1298 } else if (rxd
->btype
== VMXNET3_RXD_BTYPE_BODY
&&
1299 rq
->buf_info
[ring_idx
][i
].page
) {
1300 pci_unmap_page(adapter
->pdev
, rxd
->addr
,
1301 rxd
->len
, PCI_DMA_FROMDEVICE
);
1302 put_page(rq
->buf_info
[ring_idx
][i
].page
);
1303 rq
->buf_info
[ring_idx
][i
].page
= NULL
;
1307 rq
->rx_ring
[ring_idx
].gen
= VMXNET3_INIT_GEN
;
1308 rq
->rx_ring
[ring_idx
].next2fill
=
1309 rq
->rx_ring
[ring_idx
].next2comp
= 0;
1310 rq
->uncommitted
[ring_idx
] = 0;
1313 rq
->comp_ring
.gen
= VMXNET3_INIT_GEN
;
1314 rq
->comp_ring
.next2proc
= 0;
1319 vmxnet3_rq_cleanup_all(struct vmxnet3_adapter
*adapter
)
1323 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1324 vmxnet3_rq_cleanup(&adapter
->rx_queue
[i
], adapter
);
1328 void vmxnet3_rq_destroy(struct vmxnet3_rx_queue
*rq
,
1329 struct vmxnet3_adapter
*adapter
)
1334 /* all rx buffers must have already been freed */
1335 for (i
= 0; i
< 2; i
++) {
1336 if (rq
->buf_info
[i
]) {
1337 for (j
= 0; j
< rq
->rx_ring
[i
].size
; j
++)
1338 BUG_ON(rq
->buf_info
[i
][j
].page
!= NULL
);
1343 kfree(rq
->buf_info
[0]);
1345 for (i
= 0; i
< 2; i
++) {
1346 if (rq
->rx_ring
[i
].base
) {
1347 pci_free_consistent(adapter
->pdev
, rq
->rx_ring
[i
].size
1348 * sizeof(struct Vmxnet3_RxDesc
),
1349 rq
->rx_ring
[i
].base
,
1350 rq
->rx_ring
[i
].basePA
);
1351 rq
->rx_ring
[i
].base
= NULL
;
1353 rq
->buf_info
[i
] = NULL
;
1356 if (rq
->comp_ring
.base
) {
1357 pci_free_consistent(adapter
->pdev
, rq
->comp_ring
.size
*
1358 sizeof(struct Vmxnet3_RxCompDesc
),
1359 rq
->comp_ring
.base
, rq
->comp_ring
.basePA
);
1360 rq
->comp_ring
.base
= NULL
;
1366 vmxnet3_rq_init(struct vmxnet3_rx_queue
*rq
,
1367 struct vmxnet3_adapter
*adapter
)
1371 /* initialize buf_info */
1372 for (i
= 0; i
< rq
->rx_ring
[0].size
; i
++) {
1374 /* 1st buf for a pkt is skbuff */
1375 if (i
% adapter
->rx_buf_per_pkt
== 0) {
1376 rq
->buf_info
[0][i
].buf_type
= VMXNET3_RX_BUF_SKB
;
1377 rq
->buf_info
[0][i
].len
= adapter
->skb_buf_size
;
1378 } else { /* subsequent bufs for a pkt is frag */
1379 rq
->buf_info
[0][i
].buf_type
= VMXNET3_RX_BUF_PAGE
;
1380 rq
->buf_info
[0][i
].len
= PAGE_SIZE
;
1383 for (i
= 0; i
< rq
->rx_ring
[1].size
; i
++) {
1384 rq
->buf_info
[1][i
].buf_type
= VMXNET3_RX_BUF_PAGE
;
1385 rq
->buf_info
[1][i
].len
= PAGE_SIZE
;
1388 /* reset internal state and allocate buffers for both rings */
1389 for (i
= 0; i
< 2; i
++) {
1390 rq
->rx_ring
[i
].next2fill
= rq
->rx_ring
[i
].next2comp
= 0;
1391 rq
->uncommitted
[i
] = 0;
1393 memset(rq
->rx_ring
[i
].base
, 0, rq
->rx_ring
[i
].size
*
1394 sizeof(struct Vmxnet3_RxDesc
));
1395 rq
->rx_ring
[i
].gen
= VMXNET3_INIT_GEN
;
1397 if (vmxnet3_rq_alloc_rx_buf(rq
, 0, rq
->rx_ring
[0].size
- 1,
1399 /* at least has 1 rx buffer for the 1st ring */
1402 vmxnet3_rq_alloc_rx_buf(rq
, 1, rq
->rx_ring
[1].size
- 1, adapter
);
1404 /* reset the comp ring */
1405 rq
->comp_ring
.next2proc
= 0;
1406 memset(rq
->comp_ring
.base
, 0, rq
->comp_ring
.size
*
1407 sizeof(struct Vmxnet3_RxCompDesc
));
1408 rq
->comp_ring
.gen
= VMXNET3_INIT_GEN
;
1411 rq
->rx_ctx
.skb
= NULL
;
1413 /* stats are not reset */
1419 vmxnet3_rq_init_all(struct vmxnet3_adapter
*adapter
)
1423 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1424 err
= vmxnet3_rq_init(&adapter
->rx_queue
[i
], adapter
);
1425 if (unlikely(err
)) {
1426 dev_err(&adapter
->netdev
->dev
, "%s: failed to "
1427 "initialize rx queue%i\n",
1428 adapter
->netdev
->name
, i
);
1438 vmxnet3_rq_create(struct vmxnet3_rx_queue
*rq
, struct vmxnet3_adapter
*adapter
)
1442 struct vmxnet3_rx_buf_info
*bi
;
1444 for (i
= 0; i
< 2; i
++) {
1446 sz
= rq
->rx_ring
[i
].size
* sizeof(struct Vmxnet3_RxDesc
);
1447 rq
->rx_ring
[i
].base
= pci_alloc_consistent(adapter
->pdev
, sz
,
1448 &rq
->rx_ring
[i
].basePA
);
1449 if (!rq
->rx_ring
[i
].base
) {
1450 printk(KERN_ERR
"%s: failed to allocate rx ring %d\n",
1451 adapter
->netdev
->name
, i
);
1456 sz
= rq
->comp_ring
.size
* sizeof(struct Vmxnet3_RxCompDesc
);
1457 rq
->comp_ring
.base
= pci_alloc_consistent(adapter
->pdev
, sz
,
1458 &rq
->comp_ring
.basePA
);
1459 if (!rq
->comp_ring
.base
) {
1460 printk(KERN_ERR
"%s: failed to allocate rx comp ring\n",
1461 adapter
->netdev
->name
);
1465 sz
= sizeof(struct vmxnet3_rx_buf_info
) * (rq
->rx_ring
[0].size
+
1466 rq
->rx_ring
[1].size
);
1467 bi
= kzalloc(sz
, GFP_KERNEL
);
1469 printk(KERN_ERR
"%s: failed to allocate rx bufinfo\n",
1470 adapter
->netdev
->name
);
1473 rq
->buf_info
[0] = bi
;
1474 rq
->buf_info
[1] = bi
+ rq
->rx_ring
[0].size
;
1479 vmxnet3_rq_destroy(rq
, adapter
);
1485 vmxnet3_rq_create_all(struct vmxnet3_adapter
*adapter
)
1489 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1490 err
= vmxnet3_rq_create(&adapter
->rx_queue
[i
], adapter
);
1491 if (unlikely(err
)) {
1492 dev_err(&adapter
->netdev
->dev
,
1493 "%s: failed to create rx queue%i\n",
1494 adapter
->netdev
->name
, i
);
1500 vmxnet3_rq_destroy_all(adapter
);
1505 /* Multiple queue aware polling function for tx and rx */
1508 vmxnet3_do_poll(struct vmxnet3_adapter
*adapter
, int budget
)
1510 int rcd_done
= 0, i
;
1511 if (unlikely(adapter
->shared
->ecr
))
1512 vmxnet3_process_events(adapter
);
1513 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1514 vmxnet3_tq_tx_complete(&adapter
->tx_queue
[i
], adapter
);
1516 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1517 rcd_done
+= vmxnet3_rq_rx_complete(&adapter
->rx_queue
[i
],
1524 vmxnet3_poll(struct napi_struct
*napi
, int budget
)
1526 struct vmxnet3_rx_queue
*rx_queue
= container_of(napi
,
1527 struct vmxnet3_rx_queue
, napi
);
1530 rxd_done
= vmxnet3_do_poll(rx_queue
->adapter
, budget
);
1532 if (rxd_done
< budget
) {
1533 napi_complete(napi
);
1534 vmxnet3_enable_all_intrs(rx_queue
->adapter
);
1540 * NAPI polling function for MSI-X mode with multiple Rx queues
1541 * Returns the # of the NAPI credit consumed (# of rx descriptors processed)
1545 vmxnet3_poll_rx_only(struct napi_struct
*napi
, int budget
)
1547 struct vmxnet3_rx_queue
*rq
= container_of(napi
,
1548 struct vmxnet3_rx_queue
, napi
);
1549 struct vmxnet3_adapter
*adapter
= rq
->adapter
;
1552 /* When sharing interrupt with corresponding tx queue, process
1553 * tx completions in that queue as well
1555 if (adapter
->share_intr
== VMXNET3_INTR_BUDDYSHARE
) {
1556 struct vmxnet3_tx_queue
*tq
=
1557 &adapter
->tx_queue
[rq
- adapter
->rx_queue
];
1558 vmxnet3_tq_tx_complete(tq
, adapter
);
1561 rxd_done
= vmxnet3_rq_rx_complete(rq
, adapter
, budget
);
1563 if (rxd_done
< budget
) {
1564 napi_complete(napi
);
1565 vmxnet3_enable_intr(adapter
, rq
->comp_ring
.intr_idx
);
1571 #ifdef CONFIG_PCI_MSI
1574 * Handle completion interrupts on tx queues
1575 * Returns whether or not the intr is handled
1579 vmxnet3_msix_tx(int irq
, void *data
)
1581 struct vmxnet3_tx_queue
*tq
= data
;
1582 struct vmxnet3_adapter
*adapter
= tq
->adapter
;
1584 if (adapter
->intr
.mask_mode
== VMXNET3_IMM_ACTIVE
)
1585 vmxnet3_disable_intr(adapter
, tq
->comp_ring
.intr_idx
);
1587 /* Handle the case where only one irq is allocate for all tx queues */
1588 if (adapter
->share_intr
== VMXNET3_INTR_TXSHARE
) {
1590 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1591 struct vmxnet3_tx_queue
*txq
= &adapter
->tx_queue
[i
];
1592 vmxnet3_tq_tx_complete(txq
, adapter
);
1595 vmxnet3_tq_tx_complete(tq
, adapter
);
1597 vmxnet3_enable_intr(adapter
, tq
->comp_ring
.intr_idx
);
1604 * Handle completion interrupts on rx queues. Returns whether or not the
1609 vmxnet3_msix_rx(int irq
, void *data
)
1611 struct vmxnet3_rx_queue
*rq
= data
;
1612 struct vmxnet3_adapter
*adapter
= rq
->adapter
;
1614 /* disable intr if needed */
1615 if (adapter
->intr
.mask_mode
== VMXNET3_IMM_ACTIVE
)
1616 vmxnet3_disable_intr(adapter
, rq
->comp_ring
.intr_idx
);
1617 napi_schedule(&rq
->napi
);
1623 *----------------------------------------------------------------------------
1625 * vmxnet3_msix_event --
1627 * vmxnet3 msix event intr handler
1630 * whether or not the intr is handled
1632 *----------------------------------------------------------------------------
1636 vmxnet3_msix_event(int irq
, void *data
)
1638 struct net_device
*dev
= data
;
1639 struct vmxnet3_adapter
*adapter
= netdev_priv(dev
);
1641 /* disable intr if needed */
1642 if (adapter
->intr
.mask_mode
== VMXNET3_IMM_ACTIVE
)
1643 vmxnet3_disable_intr(adapter
, adapter
->intr
.event_intr_idx
);
1645 if (adapter
->shared
->ecr
)
1646 vmxnet3_process_events(adapter
);
1648 vmxnet3_enable_intr(adapter
, adapter
->intr
.event_intr_idx
);
1653 #endif /* CONFIG_PCI_MSI */
1656 /* Interrupt handler for vmxnet3 */
1658 vmxnet3_intr(int irq
, void *dev_id
)
1660 struct net_device
*dev
= dev_id
;
1661 struct vmxnet3_adapter
*adapter
= netdev_priv(dev
);
1663 if (adapter
->intr
.type
== VMXNET3_IT_INTX
) {
1664 u32 icr
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_ICR
);
1665 if (unlikely(icr
== 0))
1671 /* disable intr if needed */
1672 if (adapter
->intr
.mask_mode
== VMXNET3_IMM_ACTIVE
)
1673 vmxnet3_disable_all_intrs(adapter
);
1675 napi_schedule(&adapter
->rx_queue
[0].napi
);
1680 #ifdef CONFIG_NET_POLL_CONTROLLER
1682 /* netpoll callback. */
1684 vmxnet3_netpoll(struct net_device
*netdev
)
1686 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1688 if (adapter
->intr
.mask_mode
== VMXNET3_IMM_ACTIVE
)
1689 vmxnet3_disable_all_intrs(adapter
);
1691 vmxnet3_do_poll(adapter
, adapter
->rx_queue
[0].rx_ring
[0].size
);
1692 vmxnet3_enable_all_intrs(adapter
);
1695 #endif /* CONFIG_NET_POLL_CONTROLLER */
1698 vmxnet3_request_irqs(struct vmxnet3_adapter
*adapter
)
1700 struct vmxnet3_intr
*intr
= &adapter
->intr
;
1704 #ifdef CONFIG_PCI_MSI
1705 if (adapter
->intr
.type
== VMXNET3_IT_MSIX
) {
1706 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1707 if (adapter
->share_intr
!= VMXNET3_INTR_BUDDYSHARE
) {
1708 sprintf(adapter
->tx_queue
[i
].name
, "%s-tx-%d",
1709 adapter
->netdev
->name
, vector
);
1711 intr
->msix_entries
[vector
].vector
,
1713 adapter
->tx_queue
[i
].name
,
1714 &adapter
->tx_queue
[i
]);
1716 sprintf(adapter
->tx_queue
[i
].name
, "%s-rxtx-%d",
1717 adapter
->netdev
->name
, vector
);
1720 dev_err(&adapter
->netdev
->dev
,
1721 "Failed to request irq for MSIX, %s, "
1723 adapter
->tx_queue
[i
].name
, err
);
1727 /* Handle the case where only 1 MSIx was allocated for
1729 if (adapter
->share_intr
== VMXNET3_INTR_TXSHARE
) {
1730 for (; i
< adapter
->num_tx_queues
; i
++)
1731 adapter
->tx_queue
[i
].comp_ring
.intr_idx
1736 adapter
->tx_queue
[i
].comp_ring
.intr_idx
1740 if (adapter
->share_intr
== VMXNET3_INTR_BUDDYSHARE
)
1743 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1744 if (adapter
->share_intr
!= VMXNET3_INTR_BUDDYSHARE
)
1745 sprintf(adapter
->rx_queue
[i
].name
, "%s-rx-%d",
1746 adapter
->netdev
->name
, vector
);
1748 sprintf(adapter
->rx_queue
[i
].name
, "%s-rxtx-%d",
1749 adapter
->netdev
->name
, vector
);
1750 err
= request_irq(intr
->msix_entries
[vector
].vector
,
1752 adapter
->rx_queue
[i
].name
,
1753 &(adapter
->rx_queue
[i
]));
1755 printk(KERN_ERR
"Failed to request irq for MSIX"
1757 adapter
->rx_queue
[i
].name
, err
);
1761 adapter
->rx_queue
[i
].comp_ring
.intr_idx
= vector
++;
1764 sprintf(intr
->event_msi_vector_name
, "%s-event-%d",
1765 adapter
->netdev
->name
, vector
);
1766 err
= request_irq(intr
->msix_entries
[vector
].vector
,
1767 vmxnet3_msix_event
, 0,
1768 intr
->event_msi_vector_name
, adapter
->netdev
);
1769 intr
->event_intr_idx
= vector
;
1771 } else if (intr
->type
== VMXNET3_IT_MSI
) {
1772 adapter
->num_rx_queues
= 1;
1773 err
= request_irq(adapter
->pdev
->irq
, vmxnet3_intr
, 0,
1774 adapter
->netdev
->name
, adapter
->netdev
);
1777 adapter
->num_rx_queues
= 1;
1778 err
= request_irq(adapter
->pdev
->irq
, vmxnet3_intr
,
1779 IRQF_SHARED
, adapter
->netdev
->name
,
1781 #ifdef CONFIG_PCI_MSI
1784 intr
->num_intrs
= vector
+ 1;
1786 printk(KERN_ERR
"Failed to request irq %s (intr type:%d), error"
1787 ":%d\n", adapter
->netdev
->name
, intr
->type
, err
);
1789 /* Number of rx queues will not change after this */
1790 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1791 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[i
];
1793 rq
->qid2
= i
+ adapter
->num_rx_queues
;
1798 /* init our intr settings */
1799 for (i
= 0; i
< intr
->num_intrs
; i
++)
1800 intr
->mod_levels
[i
] = UPT1_IML_ADAPTIVE
;
1801 if (adapter
->intr
.type
!= VMXNET3_IT_MSIX
) {
1802 adapter
->intr
.event_intr_idx
= 0;
1803 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1804 adapter
->tx_queue
[i
].comp_ring
.intr_idx
= 0;
1805 adapter
->rx_queue
[0].comp_ring
.intr_idx
= 0;
1808 printk(KERN_INFO
"%s: intr type %u, mode %u, %u vectors "
1809 "allocated\n", adapter
->netdev
->name
, intr
->type
,
1810 intr
->mask_mode
, intr
->num_intrs
);
1818 vmxnet3_free_irqs(struct vmxnet3_adapter
*adapter
)
1820 struct vmxnet3_intr
*intr
= &adapter
->intr
;
1821 BUG_ON(intr
->type
== VMXNET3_IT_AUTO
|| intr
->num_intrs
<= 0);
1823 switch (intr
->type
) {
1824 #ifdef CONFIG_PCI_MSI
1825 case VMXNET3_IT_MSIX
:
1829 if (adapter
->share_intr
!= VMXNET3_INTR_BUDDYSHARE
) {
1830 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1831 free_irq(intr
->msix_entries
[vector
++].vector
,
1832 &(adapter
->tx_queue
[i
]));
1833 if (adapter
->share_intr
== VMXNET3_INTR_TXSHARE
)
1838 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1839 free_irq(intr
->msix_entries
[vector
++].vector
,
1840 &(adapter
->rx_queue
[i
]));
1843 free_irq(intr
->msix_entries
[vector
].vector
,
1845 BUG_ON(vector
>= intr
->num_intrs
);
1849 case VMXNET3_IT_MSI
:
1850 free_irq(adapter
->pdev
->irq
, adapter
->netdev
);
1852 case VMXNET3_IT_INTX
:
1853 free_irq(adapter
->pdev
->irq
, adapter
->netdev
);
1861 vmxnet3_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
1863 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1864 struct Vmxnet3_DriverShared
*shared
= adapter
->shared
;
1865 u32
*vfTable
= adapter
->shared
->devRead
.rxFilterConf
.vfTable
;
1866 unsigned long flags
;
1869 /* add vlan rx stripping. */
1870 if (adapter
->netdev
->features
& NETIF_F_HW_VLAN_RX
) {
1872 adapter
->vlan_grp
= grp
;
1875 * Clear entire vfTable; then enable untagged pkts.
1876 * Note: setting one entry in vfTable to non-zero turns
1877 * on VLAN rx filtering.
1879 for (i
= 0; i
< VMXNET3_VFT_SIZE
; i
++)
1882 VMXNET3_SET_VFTABLE_ENTRY(vfTable
, 0);
1883 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1884 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1885 VMXNET3_CMD_UPDATE_VLAN_FILTERS
);
1886 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1888 printk(KERN_ERR
"%s: vlan_rx_register when device has "
1889 "no NETIF_F_HW_VLAN_RX\n", netdev
->name
);
1892 /* remove vlan rx stripping. */
1893 struct Vmxnet3_DSDevRead
*devRead
= &shared
->devRead
;
1894 adapter
->vlan_grp
= NULL
;
1896 if (devRead
->misc
.uptFeatures
& UPT1_F_RXVLAN
) {
1899 for (i
= 0; i
< VMXNET3_VFT_SIZE
; i
++) {
1900 /* clear entire vfTable; this also disables
1905 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1906 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1907 VMXNET3_CMD_UPDATE_VLAN_FILTERS
);
1908 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1915 vmxnet3_restore_vlan(struct vmxnet3_adapter
*adapter
)
1917 if (adapter
->vlan_grp
) {
1919 u32
*vfTable
= adapter
->shared
->devRead
.rxFilterConf
.vfTable
;
1920 bool activeVlan
= false;
1922 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
1923 if (vlan_group_get_device(adapter
->vlan_grp
, vid
)) {
1924 VMXNET3_SET_VFTABLE_ENTRY(vfTable
, vid
);
1929 /* continue to allow untagged pkts */
1930 VMXNET3_SET_VFTABLE_ENTRY(vfTable
, 0);
1937 vmxnet3_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1939 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1940 u32
*vfTable
= adapter
->shared
->devRead
.rxFilterConf
.vfTable
;
1941 unsigned long flags
;
1943 VMXNET3_SET_VFTABLE_ENTRY(vfTable
, vid
);
1944 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1945 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1946 VMXNET3_CMD_UPDATE_VLAN_FILTERS
);
1947 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1952 vmxnet3_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1954 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1955 u32
*vfTable
= adapter
->shared
->devRead
.rxFilterConf
.vfTable
;
1956 unsigned long flags
;
1958 VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable
, vid
);
1959 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1960 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1961 VMXNET3_CMD_UPDATE_VLAN_FILTERS
);
1962 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1967 vmxnet3_copy_mc(struct net_device
*netdev
)
1970 u32 sz
= netdev_mc_count(netdev
) * ETH_ALEN
;
1972 /* struct Vmxnet3_RxFilterConf.mfTableLen is u16. */
1974 /* We may be called with BH disabled */
1975 buf
= kmalloc(sz
, GFP_ATOMIC
);
1977 struct netdev_hw_addr
*ha
;
1980 netdev_for_each_mc_addr(ha
, netdev
)
1981 memcpy(buf
+ i
++ * ETH_ALEN
, ha
->addr
,
1990 vmxnet3_set_mc(struct net_device
*netdev
)
1992 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1993 unsigned long flags
;
1994 struct Vmxnet3_RxFilterConf
*rxConf
=
1995 &adapter
->shared
->devRead
.rxFilterConf
;
1996 u8
*new_table
= NULL
;
1997 u32 new_mode
= VMXNET3_RXM_UCAST
;
1999 if (netdev
->flags
& IFF_PROMISC
)
2000 new_mode
|= VMXNET3_RXM_PROMISC
;
2002 if (netdev
->flags
& IFF_BROADCAST
)
2003 new_mode
|= VMXNET3_RXM_BCAST
;
2005 if (netdev
->flags
& IFF_ALLMULTI
)
2006 new_mode
|= VMXNET3_RXM_ALL_MULTI
;
2008 if (!netdev_mc_empty(netdev
)) {
2009 new_table
= vmxnet3_copy_mc(netdev
);
2011 new_mode
|= VMXNET3_RXM_MCAST
;
2012 rxConf
->mfTableLen
= cpu_to_le16(
2013 netdev_mc_count(netdev
) * ETH_ALEN
);
2014 rxConf
->mfTablePA
= cpu_to_le64(virt_to_phys(
2017 printk(KERN_INFO
"%s: failed to copy mcast list"
2018 ", setting ALL_MULTI\n", netdev
->name
);
2019 new_mode
|= VMXNET3_RXM_ALL_MULTI
;
2024 if (!(new_mode
& VMXNET3_RXM_MCAST
)) {
2025 rxConf
->mfTableLen
= 0;
2026 rxConf
->mfTablePA
= 0;
2029 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
2030 if (new_mode
!= rxConf
->rxMode
) {
2031 rxConf
->rxMode
= cpu_to_le32(new_mode
);
2032 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
2033 VMXNET3_CMD_UPDATE_RX_MODE
);
2036 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
2037 VMXNET3_CMD_UPDATE_MAC_FILTERS
);
2038 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
2044 vmxnet3_rq_destroy_all(struct vmxnet3_adapter
*adapter
)
2048 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2049 vmxnet3_rq_destroy(&adapter
->rx_queue
[i
], adapter
);
2054 * Set up driver_shared based on settings in adapter.
2058 vmxnet3_setup_driver_shared(struct vmxnet3_adapter
*adapter
)
2060 struct Vmxnet3_DriverShared
*shared
= adapter
->shared
;
2061 struct Vmxnet3_DSDevRead
*devRead
= &shared
->devRead
;
2062 struct Vmxnet3_TxQueueConf
*tqc
;
2063 struct Vmxnet3_RxQueueConf
*rqc
;
2066 memset(shared
, 0, sizeof(*shared
));
2068 /* driver settings */
2069 shared
->magic
= cpu_to_le32(VMXNET3_REV1_MAGIC
);
2070 devRead
->misc
.driverInfo
.version
= cpu_to_le32(
2071 VMXNET3_DRIVER_VERSION_NUM
);
2072 devRead
->misc
.driverInfo
.gos
.gosBits
= (sizeof(void *) == 4 ?
2073 VMXNET3_GOS_BITS_32
: VMXNET3_GOS_BITS_64
);
2074 devRead
->misc
.driverInfo
.gos
.gosType
= VMXNET3_GOS_TYPE_LINUX
;
2075 *((u32
*)&devRead
->misc
.driverInfo
.gos
) = cpu_to_le32(
2076 *((u32
*)&devRead
->misc
.driverInfo
.gos
));
2077 devRead
->misc
.driverInfo
.vmxnet3RevSpt
= cpu_to_le32(1);
2078 devRead
->misc
.driverInfo
.uptVerSpt
= cpu_to_le32(1);
2080 devRead
->misc
.ddPA
= cpu_to_le64(virt_to_phys(adapter
));
2081 devRead
->misc
.ddLen
= cpu_to_le32(sizeof(struct vmxnet3_adapter
));
2083 /* set up feature flags */
2084 if (adapter
->netdev
->features
& NETIF_F_RXCSUM
)
2085 devRead
->misc
.uptFeatures
|= UPT1_F_RXCSUM
;
2087 if (adapter
->netdev
->features
& NETIF_F_LRO
) {
2088 devRead
->misc
.uptFeatures
|= UPT1_F_LRO
;
2089 devRead
->misc
.maxNumRxSG
= cpu_to_le16(1 + MAX_SKB_FRAGS
);
2091 if (adapter
->netdev
->features
& NETIF_F_HW_VLAN_RX
)
2092 devRead
->misc
.uptFeatures
|= UPT1_F_RXVLAN
;
2094 devRead
->misc
.mtu
= cpu_to_le32(adapter
->netdev
->mtu
);
2095 devRead
->misc
.queueDescPA
= cpu_to_le64(adapter
->queue_desc_pa
);
2096 devRead
->misc
.queueDescLen
= cpu_to_le32(
2097 adapter
->num_tx_queues
* sizeof(struct Vmxnet3_TxQueueDesc
) +
2098 adapter
->num_rx_queues
* sizeof(struct Vmxnet3_RxQueueDesc
));
2100 /* tx queue settings */
2101 devRead
->misc
.numTxQueues
= adapter
->num_tx_queues
;
2102 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2103 struct vmxnet3_tx_queue
*tq
= &adapter
->tx_queue
[i
];
2104 BUG_ON(adapter
->tx_queue
[i
].tx_ring
.base
== NULL
);
2105 tqc
= &adapter
->tqd_start
[i
].conf
;
2106 tqc
->txRingBasePA
= cpu_to_le64(tq
->tx_ring
.basePA
);
2107 tqc
->dataRingBasePA
= cpu_to_le64(tq
->data_ring
.basePA
);
2108 tqc
->compRingBasePA
= cpu_to_le64(tq
->comp_ring
.basePA
);
2109 tqc
->ddPA
= cpu_to_le64(virt_to_phys(tq
->buf_info
));
2110 tqc
->txRingSize
= cpu_to_le32(tq
->tx_ring
.size
);
2111 tqc
->dataRingSize
= cpu_to_le32(tq
->data_ring
.size
);
2112 tqc
->compRingSize
= cpu_to_le32(tq
->comp_ring
.size
);
2113 tqc
->ddLen
= cpu_to_le32(
2114 sizeof(struct vmxnet3_tx_buf_info
) *
2116 tqc
->intrIdx
= tq
->comp_ring
.intr_idx
;
2119 /* rx queue settings */
2120 devRead
->misc
.numRxQueues
= adapter
->num_rx_queues
;
2121 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2122 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[i
];
2123 rqc
= &adapter
->rqd_start
[i
].conf
;
2124 rqc
->rxRingBasePA
[0] = cpu_to_le64(rq
->rx_ring
[0].basePA
);
2125 rqc
->rxRingBasePA
[1] = cpu_to_le64(rq
->rx_ring
[1].basePA
);
2126 rqc
->compRingBasePA
= cpu_to_le64(rq
->comp_ring
.basePA
);
2127 rqc
->ddPA
= cpu_to_le64(virt_to_phys(
2129 rqc
->rxRingSize
[0] = cpu_to_le32(rq
->rx_ring
[0].size
);
2130 rqc
->rxRingSize
[1] = cpu_to_le32(rq
->rx_ring
[1].size
);
2131 rqc
->compRingSize
= cpu_to_le32(rq
->comp_ring
.size
);
2132 rqc
->ddLen
= cpu_to_le32(
2133 sizeof(struct vmxnet3_rx_buf_info
) *
2134 (rqc
->rxRingSize
[0] +
2135 rqc
->rxRingSize
[1]));
2136 rqc
->intrIdx
= rq
->comp_ring
.intr_idx
;
2140 memset(adapter
->rss_conf
, 0, sizeof(*adapter
->rss_conf
));
2143 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
2144 devRead
->misc
.uptFeatures
|= UPT1_F_RSS
;
2145 devRead
->misc
.numRxQueues
= adapter
->num_rx_queues
;
2146 rssConf
->hashType
= UPT1_RSS_HASH_TYPE_TCP_IPV4
|
2147 UPT1_RSS_HASH_TYPE_IPV4
|
2148 UPT1_RSS_HASH_TYPE_TCP_IPV6
|
2149 UPT1_RSS_HASH_TYPE_IPV6
;
2150 rssConf
->hashFunc
= UPT1_RSS_HASH_FUNC_TOEPLITZ
;
2151 rssConf
->hashKeySize
= UPT1_RSS_MAX_KEY_SIZE
;
2152 rssConf
->indTableSize
= VMXNET3_RSS_IND_TABLE_SIZE
;
2153 get_random_bytes(&rssConf
->hashKey
[0], rssConf
->hashKeySize
);
2154 for (i
= 0; i
< rssConf
->indTableSize
; i
++)
2155 rssConf
->indTable
[i
] = i
% adapter
->num_rx_queues
;
2157 devRead
->rssConfDesc
.confVer
= 1;
2158 devRead
->rssConfDesc
.confLen
= sizeof(*rssConf
);
2159 devRead
->rssConfDesc
.confPA
= virt_to_phys(rssConf
);
2162 #endif /* VMXNET3_RSS */
2165 devRead
->intrConf
.autoMask
= adapter
->intr
.mask_mode
==
2167 devRead
->intrConf
.numIntrs
= adapter
->intr
.num_intrs
;
2168 for (i
= 0; i
< adapter
->intr
.num_intrs
; i
++)
2169 devRead
->intrConf
.modLevels
[i
] = adapter
->intr
.mod_levels
[i
];
2171 devRead
->intrConf
.eventIntrIdx
= adapter
->intr
.event_intr_idx
;
2172 devRead
->intrConf
.intrCtrl
|= cpu_to_le32(VMXNET3_IC_DISABLE_ALL
);
2174 /* rx filter settings */
2175 devRead
->rxFilterConf
.rxMode
= 0;
2176 vmxnet3_restore_vlan(adapter
);
2177 vmxnet3_write_mac_addr(adapter
, adapter
->netdev
->dev_addr
);
2179 /* the rest are already zeroed */
2184 vmxnet3_activate_dev(struct vmxnet3_adapter
*adapter
)
2188 unsigned long flags
;
2190 dev_dbg(&adapter
->netdev
->dev
, "%s: skb_buf_size %d, rx_buf_per_pkt %d,"
2191 " ring sizes %u %u %u\n", adapter
->netdev
->name
,
2192 adapter
->skb_buf_size
, adapter
->rx_buf_per_pkt
,
2193 adapter
->tx_queue
[0].tx_ring
.size
,
2194 adapter
->rx_queue
[0].rx_ring
[0].size
,
2195 adapter
->rx_queue
[0].rx_ring
[1].size
);
2197 vmxnet3_tq_init_all(adapter
);
2198 err
= vmxnet3_rq_init_all(adapter
);
2200 printk(KERN_ERR
"Failed to init rx queue for %s: error %d\n",
2201 adapter
->netdev
->name
, err
);
2205 err
= vmxnet3_request_irqs(adapter
);
2207 printk(KERN_ERR
"Failed to setup irq for %s: error %d\n",
2208 adapter
->netdev
->name
, err
);
2212 vmxnet3_setup_driver_shared(adapter
);
2214 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DSAL
, VMXNET3_GET_ADDR_LO(
2215 adapter
->shared_pa
));
2216 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DSAH
, VMXNET3_GET_ADDR_HI(
2217 adapter
->shared_pa
));
2218 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
2219 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
2220 VMXNET3_CMD_ACTIVATE_DEV
);
2221 ret
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
2222 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
2225 printk(KERN_ERR
"Failed to activate dev %s: error %u\n",
2226 adapter
->netdev
->name
, ret
);
2231 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2232 VMXNET3_WRITE_BAR0_REG(adapter
,
2233 VMXNET3_REG_RXPROD
+ i
* VMXNET3_REG_ALIGN
,
2234 adapter
->rx_queue
[i
].rx_ring
[0].next2fill
);
2235 VMXNET3_WRITE_BAR0_REG(adapter
, (VMXNET3_REG_RXPROD2
+
2236 (i
* VMXNET3_REG_ALIGN
)),
2237 adapter
->rx_queue
[i
].rx_ring
[1].next2fill
);
2240 /* Apply the rx filter settins last. */
2241 vmxnet3_set_mc(adapter
->netdev
);
2244 * Check link state when first activating device. It will start the
2245 * tx queue if the link is up.
2247 vmxnet3_check_link(adapter
, true);
2248 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2249 napi_enable(&adapter
->rx_queue
[i
].napi
);
2250 vmxnet3_enable_all_intrs(adapter
);
2251 clear_bit(VMXNET3_STATE_BIT_QUIESCED
, &adapter
->state
);
2255 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DSAL
, 0);
2256 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DSAH
, 0);
2257 vmxnet3_free_irqs(adapter
);
2260 /* free up buffers we allocated */
2261 vmxnet3_rq_cleanup_all(adapter
);
2267 vmxnet3_reset_dev(struct vmxnet3_adapter
*adapter
)
2269 unsigned long flags
;
2270 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
2271 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_RESET_DEV
);
2272 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
2277 vmxnet3_quiesce_dev(struct vmxnet3_adapter
*adapter
)
2280 unsigned long flags
;
2281 if (test_and_set_bit(VMXNET3_STATE_BIT_QUIESCED
, &adapter
->state
))
2285 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
2286 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
2287 VMXNET3_CMD_QUIESCE_DEV
);
2288 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
2289 vmxnet3_disable_all_intrs(adapter
);
2291 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2292 napi_disable(&adapter
->rx_queue
[i
].napi
);
2293 netif_tx_disable(adapter
->netdev
);
2294 adapter
->link_speed
= 0;
2295 netif_carrier_off(adapter
->netdev
);
2297 vmxnet3_tq_cleanup_all(adapter
);
2298 vmxnet3_rq_cleanup_all(adapter
);
2299 vmxnet3_free_irqs(adapter
);
2305 vmxnet3_write_mac_addr(struct vmxnet3_adapter
*adapter
, u8
*mac
)
2310 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_MACL
, tmp
);
2312 tmp
= (mac
[5] << 8) | mac
[4];
2313 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_MACH
, tmp
);
2318 vmxnet3_set_mac_addr(struct net_device
*netdev
, void *p
)
2320 struct sockaddr
*addr
= p
;
2321 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
2323 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2324 vmxnet3_write_mac_addr(adapter
, addr
->sa_data
);
2330 /* ==================== initialization and cleanup routines ============ */
2333 vmxnet3_alloc_pci_resources(struct vmxnet3_adapter
*adapter
, bool *dma64
)
2336 unsigned long mmio_start
, mmio_len
;
2337 struct pci_dev
*pdev
= adapter
->pdev
;
2339 err
= pci_enable_device(pdev
);
2341 printk(KERN_ERR
"Failed to enable adapter %s: error %d\n",
2342 pci_name(pdev
), err
);
2346 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) == 0) {
2347 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0) {
2348 printk(KERN_ERR
"pci_set_consistent_dma_mask failed "
2349 "for adapter %s\n", pci_name(pdev
));
2355 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0) {
2356 printk(KERN_ERR
"pci_set_dma_mask failed for adapter "
2357 "%s\n", pci_name(pdev
));
2364 err
= pci_request_selected_regions(pdev
, (1 << 2) - 1,
2365 vmxnet3_driver_name
);
2367 printk(KERN_ERR
"Failed to request region for adapter %s: "
2368 "error %d\n", pci_name(pdev
), err
);
2372 pci_set_master(pdev
);
2374 mmio_start
= pci_resource_start(pdev
, 0);
2375 mmio_len
= pci_resource_len(pdev
, 0);
2376 adapter
->hw_addr0
= ioremap(mmio_start
, mmio_len
);
2377 if (!adapter
->hw_addr0
) {
2378 printk(KERN_ERR
"Failed to map bar0 for adapter %s\n",
2384 mmio_start
= pci_resource_start(pdev
, 1);
2385 mmio_len
= pci_resource_len(pdev
, 1);
2386 adapter
->hw_addr1
= ioremap(mmio_start
, mmio_len
);
2387 if (!adapter
->hw_addr1
) {
2388 printk(KERN_ERR
"Failed to map bar1 for adapter %s\n",
2396 iounmap(adapter
->hw_addr0
);
2398 pci_release_selected_regions(pdev
, (1 << 2) - 1);
2400 pci_disable_device(pdev
);
2406 vmxnet3_free_pci_resources(struct vmxnet3_adapter
*adapter
)
2408 BUG_ON(!adapter
->pdev
);
2410 iounmap(adapter
->hw_addr0
);
2411 iounmap(adapter
->hw_addr1
);
2412 pci_release_selected_regions(adapter
->pdev
, (1 << 2) - 1);
2413 pci_disable_device(adapter
->pdev
);
2418 vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter
*adapter
)
2420 size_t sz
, i
, ring0_size
, ring1_size
, comp_size
;
2421 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[0];
2424 if (adapter
->netdev
->mtu
<= VMXNET3_MAX_SKB_BUF_SIZE
-
2425 VMXNET3_MAX_ETH_HDR_SIZE
) {
2426 adapter
->skb_buf_size
= adapter
->netdev
->mtu
+
2427 VMXNET3_MAX_ETH_HDR_SIZE
;
2428 if (adapter
->skb_buf_size
< VMXNET3_MIN_T0_BUF_SIZE
)
2429 adapter
->skb_buf_size
= VMXNET3_MIN_T0_BUF_SIZE
;
2431 adapter
->rx_buf_per_pkt
= 1;
2433 adapter
->skb_buf_size
= VMXNET3_MAX_SKB_BUF_SIZE
;
2434 sz
= adapter
->netdev
->mtu
- VMXNET3_MAX_SKB_BUF_SIZE
+
2435 VMXNET3_MAX_ETH_HDR_SIZE
;
2436 adapter
->rx_buf_per_pkt
= 1 + (sz
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
2440 * for simplicity, force the ring0 size to be a multiple of
2441 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
2443 sz
= adapter
->rx_buf_per_pkt
* VMXNET3_RING_SIZE_ALIGN
;
2444 ring0_size
= adapter
->rx_queue
[0].rx_ring
[0].size
;
2445 ring0_size
= (ring0_size
+ sz
- 1) / sz
* sz
;
2446 ring0_size
= min_t(u32
, ring0_size
, VMXNET3_RX_RING_MAX_SIZE
/
2448 ring1_size
= adapter
->rx_queue
[0].rx_ring
[1].size
;
2449 comp_size
= ring0_size
+ ring1_size
;
2451 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2452 rq
= &adapter
->rx_queue
[i
];
2453 rq
->rx_ring
[0].size
= ring0_size
;
2454 rq
->rx_ring
[1].size
= ring1_size
;
2455 rq
->comp_ring
.size
= comp_size
;
2461 vmxnet3_create_queues(struct vmxnet3_adapter
*adapter
, u32 tx_ring_size
,
2462 u32 rx_ring_size
, u32 rx_ring2_size
)
2466 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2467 struct vmxnet3_tx_queue
*tq
= &adapter
->tx_queue
[i
];
2468 tq
->tx_ring
.size
= tx_ring_size
;
2469 tq
->data_ring
.size
= tx_ring_size
;
2470 tq
->comp_ring
.size
= tx_ring_size
;
2471 tq
->shared
= &adapter
->tqd_start
[i
].ctrl
;
2473 tq
->adapter
= adapter
;
2475 err
= vmxnet3_tq_create(tq
, adapter
);
2477 * Too late to change num_tx_queues. We cannot do away with
2478 * lesser number of queues than what we asked for
2484 adapter
->rx_queue
[0].rx_ring
[0].size
= rx_ring_size
;
2485 adapter
->rx_queue
[0].rx_ring
[1].size
= rx_ring2_size
;
2486 vmxnet3_adjust_rx_ring_size(adapter
);
2487 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2488 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[i
];
2489 /* qid and qid2 for rx queues will be assigned later when num
2490 * of rx queues is finalized after allocating intrs */
2491 rq
->shared
= &adapter
->rqd_start
[i
].ctrl
;
2492 rq
->adapter
= adapter
;
2493 err
= vmxnet3_rq_create(rq
, adapter
);
2496 printk(KERN_ERR
"Could not allocate any rx"
2497 "queues. Aborting.\n");
2500 printk(KERN_INFO
"Number of rx queues changed "
2502 adapter
->num_rx_queues
= i
;
2510 vmxnet3_tq_destroy_all(adapter
);
2515 vmxnet3_open(struct net_device
*netdev
)
2517 struct vmxnet3_adapter
*adapter
;
2520 adapter
= netdev_priv(netdev
);
2522 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2523 spin_lock_init(&adapter
->tx_queue
[i
].tx_lock
);
2525 err
= vmxnet3_create_queues(adapter
, VMXNET3_DEF_TX_RING_SIZE
,
2526 VMXNET3_DEF_RX_RING_SIZE
,
2527 VMXNET3_DEF_RX_RING_SIZE
);
2531 err
= vmxnet3_activate_dev(adapter
);
2538 vmxnet3_rq_destroy_all(adapter
);
2539 vmxnet3_tq_destroy_all(adapter
);
2546 vmxnet3_close(struct net_device
*netdev
)
2548 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
2551 * Reset_work may be in the middle of resetting the device, wait for its
2554 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
))
2557 vmxnet3_quiesce_dev(adapter
);
2559 vmxnet3_rq_destroy_all(adapter
);
2560 vmxnet3_tq_destroy_all(adapter
);
2562 clear_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
);
2570 vmxnet3_force_close(struct vmxnet3_adapter
*adapter
)
2575 * we must clear VMXNET3_STATE_BIT_RESETTING, otherwise
2576 * vmxnet3_close() will deadlock.
2578 BUG_ON(test_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
));
2580 /* we need to enable NAPI, otherwise dev_close will deadlock */
2581 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2582 napi_enable(&adapter
->rx_queue
[i
].napi
);
2583 dev_close(adapter
->netdev
);
2588 vmxnet3_change_mtu(struct net_device
*netdev
, int new_mtu
)
2590 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
2593 if (new_mtu
< VMXNET3_MIN_MTU
|| new_mtu
> VMXNET3_MAX_MTU
)
2596 netdev
->mtu
= new_mtu
;
2599 * Reset_work may be in the middle of resetting the device, wait for its
2602 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
))
2605 if (netif_running(netdev
)) {
2606 vmxnet3_quiesce_dev(adapter
);
2607 vmxnet3_reset_dev(adapter
);
2609 /* we need to re-create the rx queue based on the new mtu */
2610 vmxnet3_rq_destroy_all(adapter
);
2611 vmxnet3_adjust_rx_ring_size(adapter
);
2612 err
= vmxnet3_rq_create_all(adapter
);
2614 printk(KERN_ERR
"%s: failed to re-create rx queues,"
2615 " error %d. Closing it.\n", netdev
->name
, err
);
2619 err
= vmxnet3_activate_dev(adapter
);
2621 printk(KERN_ERR
"%s: failed to re-activate, error %d. "
2622 "Closing it\n", netdev
->name
, err
);
2628 clear_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
);
2630 vmxnet3_force_close(adapter
);
2637 vmxnet3_declare_features(struct vmxnet3_adapter
*adapter
, bool dma64
)
2639 struct net_device
*netdev
= adapter
->netdev
;
2641 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_RXCSUM
|
2642 NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_TX
|
2643 NETIF_F_TSO
| NETIF_F_TSO6
| NETIF_F_LRO
;
2645 netdev
->features
|= NETIF_F_HIGHDMA
;
2646 netdev
->vlan_features
= netdev
->hw_features
& ~NETIF_F_HW_VLAN_TX
;
2647 netdev
->features
= netdev
->hw_features
|
2648 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
2650 netdev_info(adapter
->netdev
,
2651 "features: sg csum vlan jf tso tsoIPv6 lro%s\n",
2652 dma64
? " highDMA" : "");
2657 vmxnet3_read_mac_addr(struct vmxnet3_adapter
*adapter
, u8
*mac
)
2661 tmp
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACL
);
2664 tmp
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACH
);
2665 mac
[4] = tmp
& 0xff;
2666 mac
[5] = (tmp
>> 8) & 0xff;
2669 #ifdef CONFIG_PCI_MSI
2672 * Enable MSIx vectors.
2674 * 0 on successful enabling of required vectors,
2675 * VMXNET3_LINUX_MIN_MSIX_VECT when only minimum number of vectors required
2677 * number of vectors which can be enabled otherwise (this number is smaller
2678 * than VMXNET3_LINUX_MIN_MSIX_VECT)
2682 vmxnet3_acquire_msix_vectors(struct vmxnet3_adapter
*adapter
,
2685 int err
= 0, vector_threshold
;
2686 vector_threshold
= VMXNET3_LINUX_MIN_MSIX_VECT
;
2688 while (vectors
>= vector_threshold
) {
2689 err
= pci_enable_msix(adapter
->pdev
, adapter
->intr
.msix_entries
,
2692 adapter
->intr
.num_intrs
= vectors
;
2694 } else if (err
< 0) {
2695 printk(KERN_ERR
"Failed to enable MSI-X for %s, error"
2696 " %d\n", adapter
->netdev
->name
, err
);
2698 } else if (err
< vector_threshold
) {
2701 /* If fails to enable required number of MSI-x vectors
2702 * try enabling minimum number of vectors required.
2704 vectors
= vector_threshold
;
2705 printk(KERN_ERR
"Failed to enable %d MSI-X for %s, try"
2706 " %d instead\n", vectors
, adapter
->netdev
->name
,
2711 printk(KERN_INFO
"Number of MSI-X interrupts which can be allocatedi"
2712 " are lower than min threshold required.\n");
2717 #endif /* CONFIG_PCI_MSI */
2720 vmxnet3_alloc_intr_resources(struct vmxnet3_adapter
*adapter
)
2725 spin_lock(&adapter
->cmd_lock
);
2726 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
2727 VMXNET3_CMD_GET_CONF_INTR
);
2728 cfg
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
2729 spin_unlock(&adapter
->cmd_lock
);
2730 adapter
->intr
.type
= cfg
& 0x3;
2731 adapter
->intr
.mask_mode
= (cfg
>> 2) & 0x3;
2733 if (adapter
->intr
.type
== VMXNET3_IT_AUTO
) {
2734 adapter
->intr
.type
= VMXNET3_IT_MSIX
;
2737 #ifdef CONFIG_PCI_MSI
2738 if (adapter
->intr
.type
== VMXNET3_IT_MSIX
) {
2739 int vector
, err
= 0;
2741 adapter
->intr
.num_intrs
= (adapter
->share_intr
==
2742 VMXNET3_INTR_TXSHARE
) ? 1 :
2743 adapter
->num_tx_queues
;
2744 adapter
->intr
.num_intrs
+= (adapter
->share_intr
==
2745 VMXNET3_INTR_BUDDYSHARE
) ? 0 :
2746 adapter
->num_rx_queues
;
2747 adapter
->intr
.num_intrs
+= 1; /* for link event */
2749 adapter
->intr
.num_intrs
= (adapter
->intr
.num_intrs
>
2750 VMXNET3_LINUX_MIN_MSIX_VECT
2751 ? adapter
->intr
.num_intrs
:
2752 VMXNET3_LINUX_MIN_MSIX_VECT
);
2754 for (vector
= 0; vector
< adapter
->intr
.num_intrs
; vector
++)
2755 adapter
->intr
.msix_entries
[vector
].entry
= vector
;
2757 err
= vmxnet3_acquire_msix_vectors(adapter
,
2758 adapter
->intr
.num_intrs
);
2759 /* If we cannot allocate one MSIx vector per queue
2760 * then limit the number of rx queues to 1
2762 if (err
== VMXNET3_LINUX_MIN_MSIX_VECT
) {
2763 if (adapter
->share_intr
!= VMXNET3_INTR_BUDDYSHARE
2764 || adapter
->num_rx_queues
!= 1) {
2765 adapter
->share_intr
= VMXNET3_INTR_TXSHARE
;
2766 printk(KERN_ERR
"Number of rx queues : 1\n");
2767 adapter
->num_rx_queues
= 1;
2768 adapter
->intr
.num_intrs
=
2769 VMXNET3_LINUX_MIN_MSIX_VECT
;
2776 /* If we cannot allocate MSIx vectors use only one rx queue */
2777 printk(KERN_INFO
"Failed to enable MSI-X for %s, error %d."
2778 "#rx queues : 1, try MSI\n", adapter
->netdev
->name
, err
);
2780 adapter
->intr
.type
= VMXNET3_IT_MSI
;
2783 if (adapter
->intr
.type
== VMXNET3_IT_MSI
) {
2785 err
= pci_enable_msi(adapter
->pdev
);
2787 adapter
->num_rx_queues
= 1;
2788 adapter
->intr
.num_intrs
= 1;
2792 #endif /* CONFIG_PCI_MSI */
2794 adapter
->num_rx_queues
= 1;
2795 printk(KERN_INFO
"Using INTx interrupt, #Rx queues: 1.\n");
2796 adapter
->intr
.type
= VMXNET3_IT_INTX
;
2798 /* INT-X related setting */
2799 adapter
->intr
.num_intrs
= 1;
2804 vmxnet3_free_intr_resources(struct vmxnet3_adapter
*adapter
)
2806 if (adapter
->intr
.type
== VMXNET3_IT_MSIX
)
2807 pci_disable_msix(adapter
->pdev
);
2808 else if (adapter
->intr
.type
== VMXNET3_IT_MSI
)
2809 pci_disable_msi(adapter
->pdev
);
2811 BUG_ON(adapter
->intr
.type
!= VMXNET3_IT_INTX
);
2816 vmxnet3_tx_timeout(struct net_device
*netdev
)
2818 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
2819 adapter
->tx_timeout_count
++;
2821 printk(KERN_ERR
"%s: tx hang\n", adapter
->netdev
->name
);
2822 schedule_work(&adapter
->work
);
2823 netif_wake_queue(adapter
->netdev
);
2828 vmxnet3_reset_work(struct work_struct
*data
)
2830 struct vmxnet3_adapter
*adapter
;
2832 adapter
= container_of(data
, struct vmxnet3_adapter
, work
);
2834 /* if another thread is resetting the device, no need to proceed */
2835 if (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
))
2838 /* if the device is closed, we must leave it alone */
2840 if (netif_running(adapter
->netdev
)) {
2841 printk(KERN_INFO
"%s: resetting\n", adapter
->netdev
->name
);
2842 vmxnet3_quiesce_dev(adapter
);
2843 vmxnet3_reset_dev(adapter
);
2844 vmxnet3_activate_dev(adapter
);
2846 printk(KERN_INFO
"%s: already closed\n", adapter
->netdev
->name
);
2850 clear_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
);
2854 static int __devinit
2855 vmxnet3_probe_device(struct pci_dev
*pdev
,
2856 const struct pci_device_id
*id
)
2858 static const struct net_device_ops vmxnet3_netdev_ops
= {
2859 .ndo_open
= vmxnet3_open
,
2860 .ndo_stop
= vmxnet3_close
,
2861 .ndo_start_xmit
= vmxnet3_xmit_frame
,
2862 .ndo_set_mac_address
= vmxnet3_set_mac_addr
,
2863 .ndo_change_mtu
= vmxnet3_change_mtu
,
2864 .ndo_set_features
= vmxnet3_set_features
,
2865 .ndo_get_stats
= vmxnet3_get_stats
,
2866 .ndo_tx_timeout
= vmxnet3_tx_timeout
,
2867 .ndo_set_multicast_list
= vmxnet3_set_mc
,
2868 .ndo_vlan_rx_register
= vmxnet3_vlan_rx_register
,
2869 .ndo_vlan_rx_add_vid
= vmxnet3_vlan_rx_add_vid
,
2870 .ndo_vlan_rx_kill_vid
= vmxnet3_vlan_rx_kill_vid
,
2871 #ifdef CONFIG_NET_POLL_CONTROLLER
2872 .ndo_poll_controller
= vmxnet3_netpoll
,
2876 bool dma64
= false; /* stupid gcc */
2878 struct net_device
*netdev
;
2879 struct vmxnet3_adapter
*adapter
;
2887 num_rx_queues
= min(VMXNET3_DEVICE_MAX_RX_QUEUES
,
2888 (int)num_online_cpus());
2894 num_tx_queues
= min(VMXNET3_DEVICE_MAX_TX_QUEUES
,
2895 (int)num_online_cpus());
2899 netdev
= alloc_etherdev_mq(sizeof(struct vmxnet3_adapter
),
2900 max(num_tx_queues
, num_rx_queues
));
2901 printk(KERN_INFO
"# of Tx queues : %d, # of Rx queues : %d\n",
2902 num_tx_queues
, num_rx_queues
);
2905 printk(KERN_ERR
"Failed to alloc ethernet device for adapter "
2906 "%s\n", pci_name(pdev
));
2910 pci_set_drvdata(pdev
, netdev
);
2911 adapter
= netdev_priv(netdev
);
2912 adapter
->netdev
= netdev
;
2913 adapter
->pdev
= pdev
;
2915 spin_lock_init(&adapter
->cmd_lock
);
2916 adapter
->shared
= pci_alloc_consistent(adapter
->pdev
,
2917 sizeof(struct Vmxnet3_DriverShared
),
2918 &adapter
->shared_pa
);
2919 if (!adapter
->shared
) {
2920 printk(KERN_ERR
"Failed to allocate memory for %s\n",
2923 goto err_alloc_shared
;
2926 adapter
->num_rx_queues
= num_rx_queues
;
2927 adapter
->num_tx_queues
= num_tx_queues
;
2929 size
= sizeof(struct Vmxnet3_TxQueueDesc
) * adapter
->num_tx_queues
;
2930 size
+= sizeof(struct Vmxnet3_RxQueueDesc
) * adapter
->num_rx_queues
;
2931 adapter
->tqd_start
= pci_alloc_consistent(adapter
->pdev
, size
,
2932 &adapter
->queue_desc_pa
);
2934 if (!adapter
->tqd_start
) {
2935 printk(KERN_ERR
"Failed to allocate memory for %s\n",
2938 goto err_alloc_queue_desc
;
2940 adapter
->rqd_start
= (struct Vmxnet3_RxQueueDesc
*)(adapter
->tqd_start
+
2941 adapter
->num_tx_queues
);
2943 adapter
->pm_conf
= kmalloc(sizeof(struct Vmxnet3_PMConf
), GFP_KERNEL
);
2944 if (adapter
->pm_conf
== NULL
) {
2945 printk(KERN_ERR
"Failed to allocate memory for %s\n",
2953 adapter
->rss_conf
= kmalloc(sizeof(struct UPT1_RSSConf
), GFP_KERNEL
);
2954 if (adapter
->rss_conf
== NULL
) {
2955 printk(KERN_ERR
"Failed to allocate memory for %s\n",
2960 #endif /* VMXNET3_RSS */
2962 err
= vmxnet3_alloc_pci_resources(adapter
, &dma64
);
2966 ver
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_VRRS
);
2968 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_VRRS
, 1);
2970 printk(KERN_ERR
"Incompatible h/w version (0x%x) for adapter"
2971 " %s\n", ver
, pci_name(pdev
));
2976 ver
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_UVRS
);
2978 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_UVRS
, 1);
2980 printk(KERN_ERR
"Incompatible upt version (0x%x) for "
2981 "adapter %s\n", ver
, pci_name(pdev
));
2986 vmxnet3_declare_features(adapter
, dma64
);
2988 adapter
->dev_number
= atomic_read(&devices_found
);
2990 adapter
->share_intr
= irq_share_mode
;
2991 if (adapter
->share_intr
== VMXNET3_INTR_BUDDYSHARE
&&
2992 adapter
->num_tx_queues
!= adapter
->num_rx_queues
)
2993 adapter
->share_intr
= VMXNET3_INTR_DONTSHARE
;
2995 vmxnet3_alloc_intr_resources(adapter
);
2998 if (adapter
->num_rx_queues
> 1 &&
2999 adapter
->intr
.type
== VMXNET3_IT_MSIX
) {
3000 adapter
->rss
= true;
3001 printk(KERN_INFO
"RSS is enabled.\n");
3003 adapter
->rss
= false;
3007 vmxnet3_read_mac_addr(adapter
, mac
);
3008 memcpy(netdev
->dev_addr
, mac
, netdev
->addr_len
);
3010 netdev
->netdev_ops
= &vmxnet3_netdev_ops
;
3011 vmxnet3_set_ethtool_ops(netdev
);
3012 netdev
->watchdog_timeo
= 5 * HZ
;
3014 INIT_WORK(&adapter
->work
, vmxnet3_reset_work
);
3016 if (adapter
->intr
.type
== VMXNET3_IT_MSIX
) {
3018 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3019 netif_napi_add(adapter
->netdev
,
3020 &adapter
->rx_queue
[i
].napi
,
3021 vmxnet3_poll_rx_only
, 64);
3024 netif_napi_add(adapter
->netdev
, &adapter
->rx_queue
[0].napi
,
3028 netif_set_real_num_tx_queues(adapter
->netdev
, adapter
->num_tx_queues
);
3029 netif_set_real_num_rx_queues(adapter
->netdev
, adapter
->num_rx_queues
);
3031 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3032 err
= register_netdev(netdev
);
3035 printk(KERN_ERR
"Failed to register adapter %s\n",
3040 set_bit(VMXNET3_STATE_BIT_QUIESCED
, &adapter
->state
);
3041 vmxnet3_check_link(adapter
, false);
3042 atomic_inc(&devices_found
);
3046 vmxnet3_free_intr_resources(adapter
);
3048 vmxnet3_free_pci_resources(adapter
);
3051 kfree(adapter
->rss_conf
);
3054 kfree(adapter
->pm_conf
);
3056 pci_free_consistent(adapter
->pdev
, size
, adapter
->tqd_start
,
3057 adapter
->queue_desc_pa
);
3058 err_alloc_queue_desc
:
3059 pci_free_consistent(adapter
->pdev
, sizeof(struct Vmxnet3_DriverShared
),
3060 adapter
->shared
, adapter
->shared_pa
);
3062 pci_set_drvdata(pdev
, NULL
);
3063 free_netdev(netdev
);
3068 static void __devexit
3069 vmxnet3_remove_device(struct pci_dev
*pdev
)
3071 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3072 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
3078 num_rx_queues
= min(VMXNET3_DEVICE_MAX_RX_QUEUES
,
3079 (int)num_online_cpus());
3084 cancel_work_sync(&adapter
->work
);
3086 unregister_netdev(netdev
);
3088 vmxnet3_free_intr_resources(adapter
);
3089 vmxnet3_free_pci_resources(adapter
);
3091 kfree(adapter
->rss_conf
);
3093 kfree(adapter
->pm_conf
);
3095 size
= sizeof(struct Vmxnet3_TxQueueDesc
) * adapter
->num_tx_queues
;
3096 size
+= sizeof(struct Vmxnet3_RxQueueDesc
) * num_rx_queues
;
3097 pci_free_consistent(adapter
->pdev
, size
, adapter
->tqd_start
,
3098 adapter
->queue_desc_pa
);
3099 pci_free_consistent(adapter
->pdev
, sizeof(struct Vmxnet3_DriverShared
),
3100 adapter
->shared
, adapter
->shared_pa
);
3101 free_netdev(netdev
);
3108 vmxnet3_suspend(struct device
*device
)
3110 struct pci_dev
*pdev
= to_pci_dev(device
);
3111 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3112 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
3113 struct Vmxnet3_PMConf
*pmConf
;
3114 struct ethhdr
*ehdr
;
3115 struct arphdr
*ahdr
;
3117 struct in_device
*in_dev
;
3118 struct in_ifaddr
*ifa
;
3119 unsigned long flags
;
3122 if (!netif_running(netdev
))
3125 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3126 napi_disable(&adapter
->rx_queue
[i
].napi
);
3128 vmxnet3_disable_all_intrs(adapter
);
3129 vmxnet3_free_irqs(adapter
);
3130 vmxnet3_free_intr_resources(adapter
);
3132 netif_device_detach(netdev
);
3133 netif_tx_stop_all_queues(netdev
);
3135 /* Create wake-up filters. */
3136 pmConf
= adapter
->pm_conf
;
3137 memset(pmConf
, 0, sizeof(*pmConf
));
3139 if (adapter
->wol
& WAKE_UCAST
) {
3140 pmConf
->filters
[i
].patternSize
= ETH_ALEN
;
3141 pmConf
->filters
[i
].maskSize
= 1;
3142 memcpy(pmConf
->filters
[i
].pattern
, netdev
->dev_addr
, ETH_ALEN
);
3143 pmConf
->filters
[i
].mask
[0] = 0x3F; /* LSB ETH_ALEN bits */
3145 pmConf
->wakeUpEvents
|= VMXNET3_PM_WAKEUP_FILTER
;
3149 if (adapter
->wol
& WAKE_ARP
) {
3150 in_dev
= in_dev_get(netdev
);
3154 ifa
= (struct in_ifaddr
*)in_dev
->ifa_list
;
3158 pmConf
->filters
[i
].patternSize
= ETH_HLEN
+ /* Ethernet header*/
3159 sizeof(struct arphdr
) + /* ARP header */
3160 2 * ETH_ALEN
+ /* 2 Ethernet addresses*/
3161 2 * sizeof(u32
); /*2 IPv4 addresses */
3162 pmConf
->filters
[i
].maskSize
=
3163 (pmConf
->filters
[i
].patternSize
- 1) / 8 + 1;
3165 /* ETH_P_ARP in Ethernet header. */
3166 ehdr
= (struct ethhdr
*)pmConf
->filters
[i
].pattern
;
3167 ehdr
->h_proto
= htons(ETH_P_ARP
);
3169 /* ARPOP_REQUEST in ARP header. */
3170 ahdr
= (struct arphdr
*)&pmConf
->filters
[i
].pattern
[ETH_HLEN
];
3171 ahdr
->ar_op
= htons(ARPOP_REQUEST
);
3172 arpreq
= (u8
*)(ahdr
+ 1);
3174 /* The Unicast IPv4 address in 'tip' field. */
3175 arpreq
+= 2 * ETH_ALEN
+ sizeof(u32
);
3176 *(u32
*)arpreq
= ifa
->ifa_address
;
3178 /* The mask for the relevant bits. */
3179 pmConf
->filters
[i
].mask
[0] = 0x00;
3180 pmConf
->filters
[i
].mask
[1] = 0x30; /* ETH_P_ARP */
3181 pmConf
->filters
[i
].mask
[2] = 0x30; /* ARPOP_REQUEST */
3182 pmConf
->filters
[i
].mask
[3] = 0x00;
3183 pmConf
->filters
[i
].mask
[4] = 0xC0; /* IPv4 TIP */
3184 pmConf
->filters
[i
].mask
[5] = 0x03; /* IPv4 TIP */
3187 pmConf
->wakeUpEvents
|= VMXNET3_PM_WAKEUP_FILTER
;
3192 if (adapter
->wol
& WAKE_MAGIC
)
3193 pmConf
->wakeUpEvents
|= VMXNET3_PM_WAKEUP_MAGIC
;
3195 pmConf
->numFilters
= i
;
3197 adapter
->shared
->devRead
.pmConfDesc
.confVer
= cpu_to_le32(1);
3198 adapter
->shared
->devRead
.pmConfDesc
.confLen
= cpu_to_le32(sizeof(
3200 adapter
->shared
->devRead
.pmConfDesc
.confPA
= cpu_to_le64(virt_to_phys(
3203 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
3204 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
3205 VMXNET3_CMD_UPDATE_PMCFG
);
3206 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
3208 pci_save_state(pdev
);
3209 pci_enable_wake(pdev
, pci_choose_state(pdev
, PMSG_SUSPEND
),
3211 pci_disable_device(pdev
);
3212 pci_set_power_state(pdev
, pci_choose_state(pdev
, PMSG_SUSPEND
));
3219 vmxnet3_resume(struct device
*device
)
3222 unsigned long flags
;
3223 struct pci_dev
*pdev
= to_pci_dev(device
);
3224 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3225 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
3226 struct Vmxnet3_PMConf
*pmConf
;
3228 if (!netif_running(netdev
))
3231 /* Destroy wake-up filters. */
3232 pmConf
= adapter
->pm_conf
;
3233 memset(pmConf
, 0, sizeof(*pmConf
));
3235 adapter
->shared
->devRead
.pmConfDesc
.confVer
= cpu_to_le32(1);
3236 adapter
->shared
->devRead
.pmConfDesc
.confLen
= cpu_to_le32(sizeof(
3238 adapter
->shared
->devRead
.pmConfDesc
.confPA
= cpu_to_le64(virt_to_phys(
3241 netif_device_attach(netdev
);
3242 pci_set_power_state(pdev
, PCI_D0
);
3243 pci_restore_state(pdev
);
3244 err
= pci_enable_device_mem(pdev
);
3248 pci_enable_wake(pdev
, PCI_D0
, 0);
3250 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
3251 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
3252 VMXNET3_CMD_UPDATE_PMCFG
);
3253 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
3254 vmxnet3_alloc_intr_resources(adapter
);
3255 vmxnet3_request_irqs(adapter
);
3256 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3257 napi_enable(&adapter
->rx_queue
[i
].napi
);
3258 vmxnet3_enable_all_intrs(adapter
);
3263 static const struct dev_pm_ops vmxnet3_pm_ops
= {
3264 .suspend
= vmxnet3_suspend
,
3265 .resume
= vmxnet3_resume
,
3269 static struct pci_driver vmxnet3_driver
= {
3270 .name
= vmxnet3_driver_name
,
3271 .id_table
= vmxnet3_pciid_table
,
3272 .probe
= vmxnet3_probe_device
,
3273 .remove
= __devexit_p(vmxnet3_remove_device
),
3275 .driver
.pm
= &vmxnet3_pm_ops
,
3281 vmxnet3_init_module(void)
3283 printk(KERN_INFO
"%s - version %s\n", VMXNET3_DRIVER_DESC
,
3284 VMXNET3_DRIVER_VERSION_REPORT
);
3285 return pci_register_driver(&vmxnet3_driver
);
3288 module_init(vmxnet3_init_module
);
3292 vmxnet3_exit_module(void)
3294 pci_unregister_driver(&vmxnet3_driver
);
3297 module_exit(vmxnet3_exit_module
);
3299 MODULE_AUTHOR("VMware, Inc.");
3300 MODULE_DESCRIPTION(VMXNET3_DRIVER_DESC
);
3301 MODULE_LICENSE("GPL v2");
3302 MODULE_VERSION(VMXNET3_DRIVER_VERSION_STRING
);