55 * GPL LICENSE SUMMARY
66 *
77 * Copyright(c) 2012 Intel Corporation. All rights reserved.
8+ * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
89 *
910 * This program is free software; you can redistribute it and/or modify
1011 * it under the terms of version 2 of the GNU General Public License as
1314 * BSD LICENSE
1415 *
1516 * Copyright(c) 2012 Intel Corporation. All rights reserved.
17+ * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
1618 *
1719 * Redistribution and use in source and binary forms, with or without
1820 * modification, are permitted provided that the following conditions
4042 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4143 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4244 *
43- * Intel PCIe NTB Network Linux driver
45+ * PCIe NTB Network Linux driver
4446 *
4547 * Contact Information:
46484951#include <linux/ethtool.h>
5052#include <linux/module.h>
5153#include <linux/pci.h>
54+ #include <linux/ntb.h>
5255#include <linux/ntb_transport.h>
5356
5457#define NTB_NETDEV_VER "0.7"
@@ -70,26 +73,19 @@ struct ntb_netdev {
7073
7174static LIST_HEAD (dev_list );
7275
73- static void ntb_netdev_event_handler (void * data , int status )
76+ static void ntb_netdev_event_handler (void * data , int link_is_up )
7477{
7578 struct net_device * ndev = data ;
7679 struct ntb_netdev * dev = netdev_priv (ndev );
7780
78- netdev_dbg (ndev , "Event %x, Link %x\n" , status ,
81+ netdev_dbg (ndev , "Event %x, Link %x\n" , link_is_up ,
7982 ntb_transport_link_query (dev -> qp ));
8083
81- switch (status ) {
82- case NTB_LINK_DOWN :
84+ if (link_is_up ) {
85+ if (ntb_transport_link_query (dev -> qp ))
86+ netif_carrier_on (ndev );
87+ } else {
8388 netif_carrier_off (ndev );
84- break ;
85- case NTB_LINK_UP :
86- if (!ntb_transport_link_query (dev -> qp ))
87- return ;
88-
89- netif_carrier_on (ndev );
90- break ;
91- default :
92- netdev_warn (ndev , "Unsupported event type %d\n" , status );
9389 }
9490}
9591
@@ -160,8 +156,6 @@ static netdev_tx_t ntb_netdev_start_xmit(struct sk_buff *skb,
160156 struct ntb_netdev * dev = netdev_priv (ndev );
161157 int rc ;
162158
163- netdev_dbg (ndev , "%s: skb len %d\n" , __func__ , skb -> len );
164-
165159 rc = ntb_transport_tx_enqueue (dev -> qp , skb , skb -> data , skb -> len );
166160 if (rc )
167161 goto err ;
@@ -322,20 +316,26 @@ static const struct ntb_queue_handlers ntb_netdev_handlers = {
322316 .event_handler = ntb_netdev_event_handler ,
323317};
324318
325- static int ntb_netdev_probe (struct pci_dev * pdev )
319+ static int ntb_netdev_probe (struct device * client_dev )
326320{
321+ struct ntb_dev * ntb ;
327322 struct net_device * ndev ;
323+ struct pci_dev * pdev ;
328324 struct ntb_netdev * dev ;
329325 int rc ;
330326
331- ndev = alloc_etherdev (sizeof (struct ntb_netdev ));
327+ ntb = dev_ntb (client_dev -> parent );
328+ pdev = ntb -> pdev ;
329+ if (!pdev )
330+ return - ENODEV ;
331+
332+ ndev = alloc_etherdev (sizeof (* dev ));
332333 if (!ndev )
333334 return - ENOMEM ;
334335
335336 dev = netdev_priv (ndev );
336337 dev -> ndev = ndev ;
337338 dev -> pdev = pdev ;
338- BUG_ON (!dev -> pdev );
339339 ndev -> features = NETIF_F_HIGHDMA ;
340340
341341 ndev -> priv_flags |= IFF_LIVE_ADDR_CHANGE ;
@@ -349,7 +349,8 @@ static int ntb_netdev_probe(struct pci_dev *pdev)
349349 ndev -> netdev_ops = & ntb_netdev_ops ;
350350 ndev -> ethtool_ops = & ntb_ethtool_ops ;
351351
352- dev -> qp = ntb_transport_create_queue (ndev , pdev , & ntb_netdev_handlers );
352+ dev -> qp = ntb_transport_create_queue (ndev , client_dev ,
353+ & ntb_netdev_handlers );
353354 if (!dev -> qp ) {
354355 rc = - EIO ;
355356 goto err ;
@@ -372,12 +373,17 @@ static int ntb_netdev_probe(struct pci_dev *pdev)
372373 return rc ;
373374}
374375
375- static void ntb_netdev_remove (struct pci_dev * pdev )
376+ static void ntb_netdev_remove (struct device * client_dev )
376377{
378+ struct ntb_dev * ntb ;
377379 struct net_device * ndev ;
380+ struct pci_dev * pdev ;
378381 struct ntb_netdev * dev ;
379382 bool found = false;
380383
384+ ntb = dev_ntb (client_dev -> parent );
385+ pdev = ntb -> pdev ;
386+
381387 list_for_each_entry (dev , & dev_list , list ) {
382388 if (dev -> pdev == pdev ) {
383389 found = true;
@@ -396,7 +402,7 @@ static void ntb_netdev_remove(struct pci_dev *pdev)
396402 free_netdev (ndev );
397403}
398404
399- static struct ntb_client ntb_netdev_client = {
405+ static struct ntb_transport_client ntb_netdev_client = {
400406 .driver .name = KBUILD_MODNAME ,
401407 .driver .owner = THIS_MODULE ,
402408 .probe = ntb_netdev_probe ,
@@ -407,7 +413,7 @@ static int __init ntb_netdev_init_module(void)
407413{
408414 int rc ;
409415
410- rc = ntb_register_client_dev (KBUILD_MODNAME );
416+ rc = ntb_transport_register_client_dev (KBUILD_MODNAME );
411417 if (rc )
412418 return rc ;
413419 return ntb_transport_register_client (& ntb_netdev_client );
@@ -417,6 +423,6 @@ module_init(ntb_netdev_init_module);
417423static void __exit ntb_netdev_exit_module (void )
418424{
419425 ntb_transport_unregister_client (& ntb_netdev_client );
420- ntb_unregister_client_dev (KBUILD_MODNAME );
426+ ntb_transport_unregister_client_dev (KBUILD_MODNAME );
421427}
422428module_exit (ntb_netdev_exit_module );
0 commit comments