1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 Intel Corporation.
6 Copyright(c) 2010 Eric Keller <ekeller@princeton.edu>
7 Copyright(c) 2010 Red Hat Inc.
8 Alex Williamson <alex.williamson@redhat.com>
10 This program is free software; you can redistribute it and/or modify it
11 under the terms and conditions of the GNU General Public License,
12 version 2, as published by the Free Software Foundation.
14 This program is distributed in the hope it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 The full GNU General Public License is included in this distribution in
24 the file called "COPYING".
27 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
28 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *******************************************************************************/
32 FILE_LICENCE ( GPL2_ONLY );
37 * igbvf_setup_tx_resources - allocate Tx resources (Descriptors)
39 * @v adapter e1000 private structure
41 * @ret rc Returns 0 on success, negative on failure
43 int igbvf_setup_tx_resources ( struct igbvf_adapter *adapter )
45 DBG ( "igbvf_setup_tx_resources\n" );
47 /* Allocate transmit descriptor ring memory.
48 It must not cross a 64K boundary because of hardware errata #23
49 so we use malloc_dma() requesting a 128 byte block that is
50 128 byte aligned. This should guarantee that the memory
51 allocated will not cross a 64K boundary, because 128 is an
52 even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
53 allocations of 128 bytes on a 128 byte boundary will not
58 malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
60 if ( ! adapter->tx_base ) {
64 memset ( adapter->tx_base, 0, adapter->tx_ring_size );
66 DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
72 * igbvf_free_tx_resources - Free Tx Resources per Queue
73 * @adapter: board private structure
75 * Free all transmit software resources
77 void igbvf_free_tx_resources ( struct igbvf_adapter *adapter )
79 DBG ( "igbvf_free_tx_resources\n" );
81 free_dma ( adapter->tx_base, adapter->tx_ring_size );
85 * igbvf_free_rx_resources - Free Rx Resources
86 * @adapter: board private structure
88 * Free all receive software resources
90 void igbvf_free_rx_resources ( struct igbvf_adapter *adapter )
94 DBG ( "igbvf_free_rx_resources\n" );
96 free_dma ( adapter->rx_base, adapter->rx_ring_size );
98 for ( i = 0; i < NUM_RX_DESC; i++ ) {
99 free_iob ( adapter->rx_iobuf[i] );
104 * igbvf_refill_rx_ring - allocate Rx io_buffers
106 * @v adapter e1000 private structure
108 * @ret rc Returns 0 on success, negative on failure
110 static int igbvf_refill_rx_ring ( struct igbvf_adapter *adapter )
114 union e1000_adv_rx_desc *rx_curr_desc;
115 struct e1000_hw *hw = &adapter->hw;
116 struct io_buffer *iob;
118 DBGP ("igbvf_refill_rx_ring\n");
120 for ( i = 0; i < NUM_RX_DESC; i++ ) {
121 rx_curr = ( ( adapter->rx_curr + i ) % NUM_RX_DESC );
122 rx_curr_desc = adapter->rx_base + rx_curr;
124 if ( rx_curr_desc->wb.upper.status_error & E1000_RXD_STAT_DD )
127 if ( adapter->rx_iobuf[rx_curr] != NULL )
130 DBG2 ( "Refilling rx desc %d\n", rx_curr );
132 iob = alloc_iob ( MAXIMUM_ETHERNET_VLAN_SIZE );
133 adapter->rx_iobuf[rx_curr] = iob;
135 rx_curr_desc->wb.upper.status_error = 0;
138 DBG ( "alloc_iob failed\n" );
142 rx_curr_desc->read.pkt_addr = virt_to_bus ( iob->data );
143 rx_curr_desc->read.hdr_addr = 0;
144 ew32 ( RDT(0), rx_curr );
151 * igbvf_irq_disable - Mask off interrupt generation on the NIC
152 * @adapter: board private structure
154 static void igbvf_irq_disable ( struct igbvf_adapter *adapter )
156 struct e1000_hw *hw = &adapter->hw;
162 * igbvf_irq_enable - Enable default interrupt generation settings
163 * @adapter: board private structure
165 static void igbvf_irq_enable ( struct igbvf_adapter *adapter )
167 struct e1000_hw *hw = &adapter->hw;
169 ew32 ( EIAC, IMS_ENABLE_MASK );
170 ew32 ( EIAM, IMS_ENABLE_MASK );
171 ew32 ( EIMS, IMS_ENABLE_MASK );
175 * igbvf_irq - enable or Disable interrupts
177 * @v adapter e1000 adapter
178 * @v action requested interrupt action
180 static void igbvf_irq ( struct net_device *netdev, int enable )
182 struct igbvf_adapter *adapter = netdev_priv ( netdev );
184 DBG ( "igbvf_irq\n" );
187 igbvf_irq_enable ( adapter );
189 igbvf_irq_disable ( adapter );
194 * igbvf_process_tx_packets - process transmitted packets
196 * @v netdev network interface device structure
198 static void igbvf_process_tx_packets ( struct net_device *netdev )
200 struct igbvf_adapter *adapter = netdev_priv ( netdev );
203 union e1000_adv_tx_desc *tx_curr_desc;
205 /* Check status of transmitted packets
207 DBGP ( "process_tx_packets: tx_head = %d, tx_tail = %d\n", adapter->tx_head,
210 while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
212 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
213 ( i * sizeof ( *adapter->tx_base ) );
215 tx_status = tx_curr_desc->wb.status;
216 DBG ( " tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
217 DBG ( " tx_status = %#08x\n", tx_status );
219 /* if the packet at tx_head is not owned by hardware it is for us */
220 if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
223 DBG ( "Sent packet. tx_head: %d tx_tail: %d tx_status: %#08x\n",
224 adapter->tx_head, adapter->tx_tail, tx_status );
226 netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
227 DBG ( "Success transmitting packet, tx_status: %#08x\n",
230 /* Decrement count of used descriptors, clear this descriptor
232 adapter->tx_fill_ctr--;
233 memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
235 adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
240 * igbvf_process_rx_packets - process received packets
242 * @v netdev network interface device structure
244 static void igbvf_process_rx_packets ( struct net_device *netdev )
246 struct igbvf_adapter *adapter = netdev_priv ( netdev );
247 struct e1000_hw *hw = &adapter->hw;
252 union e1000_adv_rx_desc *rx_curr_desc;
254 DBGP ( "igbvf_process_rx_packets\n" );
256 /* Process received packets
259 i = adapter->rx_curr;
261 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
262 ( i * sizeof ( *adapter->rx_base ) );
263 rx_status = rx_curr_desc->wb.upper.status_error;
265 DBG2 ( "Before DD Check RX_status: %#08x, rx_curr: %d\n",
268 if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
271 if ( adapter->rx_iobuf[i] == NULL )
274 DBG ( "E1000_RCTL = %#08x\n", er32 (RCTL) );
276 rx_len = rx_curr_desc->wb.upper.length;
278 DBG ( "Received packet, rx_curr: %d rx_status: %#08x rx_len: %d\n",
279 i, rx_status, rx_len );
283 iob_put ( adapter->rx_iobuf[i], rx_len );
285 if ( rx_err & E1000_RXDEXT_ERR_FRAME_ERR_MASK ) {
287 netdev_rx_err ( netdev, adapter->rx_iobuf[i], -EINVAL );
288 DBG ( "igbvf_process_rx_packets: Corrupted packet received!"
289 " rx_err: %#08x\n", rx_err );
291 /* Add this packet to the receive queue. */
292 netdev_rx ( netdev, adapter->rx_iobuf[i] );
294 adapter->rx_iobuf[i] = NULL;
296 memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
298 adapter->rx_curr = ( adapter->rx_curr + 1 ) % NUM_RX_DESC;
303 * igbvf_poll - Poll for received packets
305 * @v netdev Network device
307 static void igbvf_poll ( struct net_device *netdev )
309 struct igbvf_adapter *adapter = netdev_priv ( netdev );
311 union e1000_adv_rx_desc *rx_curr_desc;
313 DBGP ( "igbvf_poll\n" );
315 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
316 ( adapter->rx_curr * sizeof ( *adapter->rx_base ) );
317 rx_status = rx_curr_desc->wb.upper.status_error;
319 if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
322 igbvf_process_tx_packets ( netdev );
324 igbvf_process_rx_packets ( netdev );
326 igbvf_refill_rx_ring ( adapter );
330 * igbvf_config_collision_dist_generic - Configure collision distance
331 * @hw: pointer to the HW structure
333 * Configures the collision distance to the default value and is used
334 * during link setup. Currently no func pointer exists and all
335 * implementations are handled in the generic version of this function.
337 void igbvf_config_collision_dist ( struct e1000_hw *hw )
341 DBG ("igbvf_config_collision_dist");
345 tctl &= ~E1000_TCTL_COLD;
346 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
353 * igbvf_configure_tx - Configure Transmit Unit after Reset
354 * @adapter: board private structure
356 * Configure the Tx unit of the MAC after a reset.
358 static void igbvf_configure_tx ( struct igbvf_adapter *adapter )
360 struct e1000_hw *hw = &adapter->hw;
363 DBG ( "igbvf_configure_tx\n" );
365 /* disable transmits while setting up the descriptors */
366 tctl = er32 ( TCTL );
367 ew32 ( TCTL, tctl & ~E1000_TCTL_EN );
371 ew32 ( TDBAH(0), 0 );
372 ew32 ( TDBAL(0), virt_to_bus ( adapter->tx_base ) );
373 ew32 ( TDLEN(0), adapter->tx_ring_size );
375 DBG ( "E1000_TDBAL(0): %#08x\n", er32 ( TDBAL(0) ) );
376 DBG ( "E1000_TDLEN(0): %d\n", er32 ( TDLEN(0) ) );
378 /* Setup the HW Tx Head and Tail descriptor pointers */
382 adapter->tx_head = 0;
383 adapter->tx_tail = 0;
384 adapter->tx_fill_ctr = 0;
386 txdctl = er32(TXDCTL(0));
387 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
388 ew32 ( TXDCTL(0), txdctl );
390 txdctl = er32 ( TXDCTL(0) );
391 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
392 ew32 ( TXDCTL(0), txdctl );
394 /* Setup Transmit Descriptor Settings for eop descriptor */
395 adapter->txd_cmd = E1000_ADVTXD_DCMD_EOP | E1000_ADVTXD_DCMD_IFCS;
397 /* Advanced descriptor */
398 adapter->txd_cmd |= E1000_ADVTXD_DCMD_DEXT;
400 /* (not part of cmd, but in same 32 bit word...) */
401 adapter->txd_cmd |= E1000_ADVTXD_DTYP_DATA;
403 /* enable Report Status bit */
404 adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS;
406 /* Program the Transmit Control Register */
407 tctl &= ~E1000_TCTL_CT;
408 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
409 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
411 igbvf_config_collision_dist ( hw );
413 /* Enable transmits */
414 tctl |= E1000_TCTL_EN;
419 /* igbvf_reset - bring the hardware into a known good state
421 * This function boots the hardware and enables some settings that
422 * require a configuration cycle of the hardware - those cannot be
423 * set/changed during runtime. After reset the device needs to be
424 * properly configured for Rx, Tx etc.
426 void igbvf_reset ( struct igbvf_adapter *adapter )
428 struct e1000_mac_info *mac = &adapter->hw.mac;
429 struct net_device *netdev = adapter->netdev;
430 struct e1000_hw *hw = &adapter->hw;
432 /* Allow time for pending master requests to run */
433 if ( mac->ops.reset_hw(hw) )
434 DBG ("PF still resetting\n");
436 mac->ops.init_hw ( hw );
438 if ( is_valid_ether_addr(adapter->hw.mac.addr) ) {
439 memcpy ( netdev->hw_addr, adapter->hw.mac.addr, ETH_ALEN );
443 extern void igbvf_init_function_pointers_vf(struct e1000_hw *hw);
446 * igbvf_sw_init - Initialize general software structures (struct igbvf_adapter)
447 * @adapter: board private structure to initialize
449 * igbvf_sw_init initializes the Adapter private data structure.
450 * Fields are initialized based on PCI device information and
451 * OS network device settings (MTU size).
453 static int __devinit igbvf_sw_init ( struct igbvf_adapter *adapter )
455 struct e1000_hw *hw = &adapter->hw;
456 struct pci_device *pdev = adapter->pdev;
459 /* PCI config space info */
461 hw->vendor_id = pdev->vendor;
462 hw->device_id = pdev->device;
464 pci_read_config_byte ( pdev, PCI_REVISION, &hw->revision_id );
466 pci_read_config_word ( pdev, PCI_COMMAND, &hw->bus.pci_cmd_word );
468 adapter->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE + ETH_HLEN + ETH_FCS_LEN;
469 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
471 /* Set various function pointers */
472 igbvf_init_function_pointers_vf ( &adapter->hw );
474 rc = adapter->hw.mac.ops.init_params ( &adapter->hw );
476 DBG ("hw.mac.ops.init_params(&adapter->hw) Failure\n");
480 rc = adapter->hw.mbx.ops.init_params ( &adapter->hw );
482 DBG ("hw.mbx.ops.init_params(&adapter->hw) Failure\n");
486 /* Explicitly disable IRQ since the NIC can be in any state. */
487 igbvf_irq_disable ( adapter );
493 * igbvf_setup_srrctl - configure the receive control registers
494 * @adapter: Board private structure
496 static void igbvf_setup_srrctl ( struct igbvf_adapter *adapter )
498 struct e1000_hw *hw = &adapter->hw;
501 DBG ( "igbvf_setup_srrctl\n" );
503 srrctl &= ~(E1000_SRRCTL_DESCTYPE_MASK |
504 E1000_SRRCTL_BSIZEHDR_MASK |
505 E1000_SRRCTL_BSIZEPKT_MASK);
507 /* Enable queue drop to avoid head of line blocking */
508 srrctl |= E1000_SRRCTL_DROP_EN;
510 /* Setup buffer sizes */
511 srrctl |= 2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
512 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
514 ew32 ( SRRCTL(0), srrctl );
518 * igbvf_configure_rx - Configure 8254x Receive Unit after Reset
519 * @adapter: board private structure
521 * Configure the Rx unit of the MAC after a reset.
523 static void igbvf_configure_rx ( struct igbvf_adapter *adapter )
525 struct e1000_hw *hw = &adapter->hw;
528 DBG ( "igbvf_configure_rx\n" );
530 /* disable receives */
531 rxdctl = er32 ( RXDCTL(0) );
532 ew32 ( RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE );
536 * Setup the HW Rx Head and Tail Descriptor Pointers and
537 * the Base and Length of the Rx Descriptor Ring
539 ew32 ( RDBAL(0), virt_to_bus (adapter->rx_base) );
540 ew32 ( RDBAH(0), 0 );
541 ew32 ( RDLEN(0), adapter->rx_ring_size );
542 adapter->rx_curr = 0;
546 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
547 rxdctl &= 0xFFF00000;
548 rxdctl |= IGBVF_RX_PTHRESH;
549 rxdctl |= IGBVF_RX_HTHRESH << 8;
550 rxdctl |= IGBVF_RX_WTHRESH << 16;
552 igbvf_rlpml_set_vf ( hw, adapter->max_frame_size );
554 /* enable receives */
555 ew32 ( RXDCTL(0), rxdctl );
556 ew32 ( RDT(0), NUM_RX_DESC );
560 * igbvf_setup_rx_resources - allocate Rx resources (Descriptors)
562 * @v adapter e1000 private structure
564 int igbvf_setup_rx_resources ( struct igbvf_adapter *adapter )
567 union e1000_adv_rx_desc *rx_curr_desc;
568 struct io_buffer *iob;
570 DBG ( "igbvf_setup_rx_resources\n" );
572 /* Allocate receive descriptor ring memory.
573 It must not cross a 64K boundary because of hardware errata
577 malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
579 if ( ! adapter->rx_base ) {
582 memset ( adapter->rx_base, 0, adapter->rx_ring_size );
584 for ( i = 0; i < NUM_RX_DESC; i++ ) {
585 rx_curr_desc = adapter->rx_base + i;
586 iob = alloc_iob ( MAXIMUM_ETHERNET_VLAN_SIZE );
587 adapter->rx_iobuf[i] = iob;
588 rx_curr_desc->wb.upper.status_error = 0;
590 DBG ( "alloc_iob failed\n" );
593 rx_curr_desc->read.pkt_addr = virt_to_bus ( iob->data );
594 rx_curr_desc->read.hdr_addr = 0;
602 * igbvf_open - Called when a network interface is made active
603 * @netdev: network interface device structure
605 * Returns 0 on success, negative value on failure
607 * The open entry point is called when a network interface is made
608 * active by the system (IFF_UP). At this point all resources needed
609 * for transmit and receive operations are allocated, the interrupt
610 * handler is registered with the OS, the watchdog timer is started,
611 * and the stack is notified that the interface is ready.
613 static int igbvf_open ( struct net_device *netdev )
615 struct igbvf_adapter *adapter = netdev_priv ( netdev );
618 DBG ("igbvf_open\n");
620 /* Update MAC address */
621 memcpy ( adapter->hw.mac.addr, netdev->ll_addr, ETH_ALEN );
622 igbvf_reset( adapter );
624 /* allocate transmit descriptors */
625 err = igbvf_setup_tx_resources ( adapter );
627 DBG ( "Error setting up TX resources!\n" );
631 igbvf_configure_tx ( adapter );
633 igbvf_setup_srrctl( adapter );
635 err = igbvf_setup_rx_resources( adapter );
637 DBG ( "Error setting up RX resources!\n" );
641 igbvf_configure_rx ( adapter );
646 DBG ( "err_setup_rx\n" );
647 igbvf_free_tx_resources ( adapter );
651 DBG ( "err_setup_tx\n" );
652 igbvf_reset ( adapter );
658 * igbvf_close - Disables a network interface
659 * @netdev: network interface device structure
661 * Returns 0, this is not allowed to fail
663 * The close entry point is called when an interface is de-activated
664 * by the OS. The hardware is still under the drivers control, but
665 * needs to be disabled. A global MAC reset is issued to stop the
666 * hardware, and all transmit and receive resources are freed.
668 static void igbvf_close ( struct net_device *netdev )
670 struct igbvf_adapter *adapter = netdev_priv ( netdev );
671 struct e1000_hw *hw = &adapter->hw;
674 DBG ( "igbvf_close\n" );
676 /* Disable and acknowledge interrupts */
677 igbvf_irq_disable ( adapter );
680 /* disable receives */
681 rxdctl = er32 ( RXDCTL(0) );
682 ew32 ( RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE );
685 igbvf_reset ( adapter );
687 igbvf_free_tx_resources( adapter );
688 igbvf_free_rx_resources( adapter );
692 * igbvf_transmit - Transmit a packet
694 * @v netdev Network device
695 * @v iobuf I/O buffer
697 * @ret rc Returns 0 on success, negative on failure
699 static int igbvf_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
701 struct igbvf_adapter *adapter = netdev_priv ( netdev );
702 struct e1000_hw *hw = &adapter->hw;
703 uint32_t tx_curr = adapter->tx_tail;
704 union e1000_adv_tx_desc *tx_curr_desc;
706 DBGP ("igbvf_transmit\n");
708 if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
709 DBG ("TX overflow\n");
713 /* Save pointer to iobuf we have been given to transmit,
714 netdev_tx_complete() will need it later
716 adapter->tx_iobuf[tx_curr] = iobuf;
718 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
719 ( tx_curr * sizeof ( *adapter->tx_base ) );
721 DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
722 DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
723 DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
725 /* Add the packet to TX ring
727 tx_curr_desc->read.buffer_addr = virt_to_bus ( iobuf->data );
728 tx_curr_desc->read.cmd_type_len = adapter->txd_cmd |(iob_len ( iobuf )) ;
729 // minus hdr_len ????
730 tx_curr_desc->read.olinfo_status = ((iob_len ( iobuf )) << E1000_ADVTXD_PAYLEN_SHIFT);
732 DBG ( "TX fill: %d tx_curr: %d addr: %#08lx len: %zd\n", adapter->tx_fill_ctr,
733 tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
735 /* Point to next free descriptor */
736 adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
737 adapter->tx_fill_ctr++;
739 /* Write new tail to NIC, making packet available for transmit
741 ew32 ( TDT(0), adapter->tx_tail );
747 /** igbvf net device operations */
748 static struct net_device_operations igbvf_operations = {
750 .close = igbvf_close,
751 .transmit = igbvf_transmit,
757 * igbvf_get_hw_control - get control of the h/w from f/w
758 * @adapter: address of board private structure
760 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
761 * For ASF and Pass Through versions of f/w this means that
762 * the driver is loaded.
765 void igbvf_get_hw_control ( struct igbvf_adapter *adapter )
767 struct e1000_hw *hw = &adapter->hw;
770 /* Let firmware know the driver has taken over */
771 ctrl_ext = er32 ( CTRL_EXT );
772 ew32 ( CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD );
776 * igbvf_probe - Device Initialization Routine
777 * @pdev: PCI device information struct
778 * @ent: entry in igbvf_pci_tbl
780 * Returns 0 on success, negative on failure
782 * igbvf_probe initializes an adapter identified by a pci_dev structure.
783 * The OS initialization, configuring of the adapter private structure,
784 * and a hardware reset occur.
786 int igbvf_probe ( struct pci_device *pdev )
789 struct net_device *netdev;
790 struct igbvf_adapter *adapter;
791 unsigned long mmio_start, mmio_len;
794 DBG ( "igbvf_probe\n" );
798 /* Allocate net device ( also allocates memory for netdev->priv
799 and makes netdev-priv point to it ) */
800 netdev = alloc_etherdev ( sizeof ( struct igbvf_adapter ) );
802 goto err_alloc_etherdev;
804 /* Associate igbvf-specific network operations operations with
805 * generic network device layer */
806 netdev_init ( netdev, &igbvf_operations );
808 /* Associate this network device with given PCI device */
809 pci_set_drvdata ( pdev, netdev );
810 netdev->dev = &pdev->dev;
812 /* Initialize driver private storage */
813 adapter = netdev_priv ( netdev );
814 memset ( adapter, 0, ( sizeof ( *adapter ) ) );
816 adapter->pdev = pdev;
818 adapter->ioaddr = pdev->ioaddr;
819 adapter->hw.io_base = pdev->ioaddr;
822 hw->vendor_id = pdev->vendor;
823 hw->device_id = pdev->device;
825 adapter->irqno = pdev->irq;
826 adapter->netdev = netdev;
827 adapter->hw.back = adapter;
829 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
830 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
832 adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC;
833 adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC;
835 /* Fix up PCI device */
836 adjust_pci_device ( pdev );
840 mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
841 mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
843 DBG ( "mmio_start: %#08lx\n", mmio_start );
844 DBG ( "mmio_len: %#08lx\n", mmio_len );
846 adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
847 DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
849 if ( ! adapter->hw.hw_addr ) {
850 DBG ( "err_ioremap\n" );
854 /* setup adapter struct */
855 err = igbvf_sw_init ( adapter );
857 DBG ( "err_sw_init\n" );
861 /* reset the controller to put the device in a known good state */
862 err = hw->mac.ops.reset_hw ( hw );
864 DBG ("PF still in reset state, assigning new address\n");
865 netdev->hw_addr[0] = 0x21;
866 netdev->hw_addr[1] = 0x21;
867 netdev->hw_addr[2] = 0x21;
868 netdev->hw_addr[3] = 0x21;
869 netdev->hw_addr[4] = 0x21;
870 netdev->hw_addr[5] = 0x21;
871 netdev->hw_addr[6] = 0x21;
873 err = hw->mac.ops.read_mac_addr(hw);
875 DBG ("Error reading MAC address\n");
878 if ( ! is_valid_ether_addr(adapter->hw.mac.addr) ) {
879 /* Assign random MAC address */
880 eth_random_addr(adapter->hw.mac.addr);
884 memcpy ( netdev->hw_addr, adapter->hw.mac.addr, ETH_ALEN );
886 /* reset the hardware with the new settings */
887 igbvf_reset ( adapter );
889 /* let the f/w know that the h/w is now under the control of the
891 igbvf_get_hw_control ( adapter );
893 /* Mark as link up; we don't yet handle link state */
894 netdev_link_up ( netdev );
896 if ( ( err = register_netdev ( netdev ) ) != 0) {
897 DBG ( "err_register\n" );
901 DBG ("igbvf_probe_succeeded\n");
908 iounmap ( adapter->hw.hw_addr );
910 netdev_put ( netdev );
916 * igbvf_remove - Device Removal Routine
917 * @pdev: PCI device information struct
919 * igbvf_remove is called by the PCI subsystem to alert the driver
920 * that it should release a PCI device. The could be caused by a
921 * Hot-Plug event, or because the driver is going to be removed from
924 void igbvf_remove ( struct pci_device *pdev )
926 struct net_device *netdev = pci_get_drvdata ( pdev );
927 struct igbvf_adapter *adapter = netdev_priv ( netdev );
929 DBG ( "igbvf_remove\n" );
931 if ( adapter->hw.flash_address )
932 iounmap ( adapter->hw.flash_address );
933 if ( adapter->hw.hw_addr )
934 iounmap ( adapter->hw.hw_addr );
936 unregister_netdev ( netdev );
937 igbvf_reset ( adapter );
938 netdev_nullify ( netdev );
939 netdev_put ( netdev );
942 static struct pci_device_id igbvf_pci_tbl[] = {
943 PCI_ROM(0x8086, 0x10CA, "igbvf", "E1000_DEV_ID_82576_VF", 0),
944 PCI_ROM(0x8086, 0x1520, "i350vf", "E1000_DEV_ID_I350_VF", 0),
948 struct pci_driver igbvf_driver __pci_driver = {
949 .ids = igbvf_pci_tbl,
950 .id_count = (sizeof(igbvf_pci_tbl) / sizeof(igbvf_pci_tbl[0])),
951 .probe = igbvf_probe,
952 .remove = igbvf_remove,