2 * aQuantia Corporation Network Driver
3 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
10 /* File aq_main.c: Main file for aQuantia Linux driver. */
14 #include "aq_pci_func.h"
15 #include "aq_ethtool.h"
16 #include "hw_atl/hw_atl_a0.h"
17 #include "hw_atl/hw_atl_b0.h"
19 #include <linux/netdevice.h>
20 #include <linux/module.h>
22 static const struct pci_device_id aq_pci_tbl
[] = {
23 { PCI_VDEVICE(AQUANTIA
, HW_ATL_DEVICE_ID_0001
), },
24 { PCI_VDEVICE(AQUANTIA
, HW_ATL_DEVICE_ID_D100
), },
25 { PCI_VDEVICE(AQUANTIA
, HW_ATL_DEVICE_ID_D107
), },
26 { PCI_VDEVICE(AQUANTIA
, HW_ATL_DEVICE_ID_D108
), },
27 { PCI_VDEVICE(AQUANTIA
, HW_ATL_DEVICE_ID_D109
), },
31 MODULE_DEVICE_TABLE(pci
, aq_pci_tbl
);
33 MODULE_LICENSE("GPL v2");
34 MODULE_VERSION(AQ_CFG_DRV_VERSION
);
35 MODULE_AUTHOR(AQ_CFG_DRV_AUTHOR
);
36 MODULE_DESCRIPTION(AQ_CFG_DRV_DESC
);
38 static struct aq_hw_ops
*aq_pci_probe_get_hw_ops_by_id(struct pci_dev
*pdev
)
40 struct aq_hw_ops
*ops
= NULL
;
42 ops
= hw_atl_a0_get_ops_by_id(pdev
);
44 ops
= hw_atl_b0_get_ops_by_id(pdev
);
49 static int aq_ndev_open(struct net_device
*ndev
)
51 struct aq_nic_s
*aq_nic
= NULL
;
54 aq_nic
= aq_nic_alloc_hot(ndev
);
59 err
= aq_nic_init(aq_nic
);
62 err
= aq_nic_start(aq_nic
);
68 aq_nic_deinit(aq_nic
);
72 static int aq_ndev_close(struct net_device
*ndev
)
75 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
77 err
= aq_nic_stop(aq_nic
);
80 aq_nic_deinit(aq_nic
);
81 aq_nic_free_hot_resources(aq_nic
);
87 static int aq_ndev_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
89 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
91 return aq_nic_xmit(aq_nic
, skb
);
94 static int aq_ndev_change_mtu(struct net_device
*ndev
, int new_mtu
)
96 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
97 int err
= aq_nic_set_mtu(aq_nic
, new_mtu
+ ETH_HLEN
);
102 if (netif_running(ndev
)) {
111 static int aq_ndev_set_features(struct net_device
*ndev
,
112 netdev_features_t features
)
114 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
115 struct aq_nic_cfg_s
*aq_cfg
= aq_nic_get_cfg(aq_nic
);
118 if (aq_cfg
->hw_features
& NETIF_F_LRO
) {
119 is_lro
= features
& NETIF_F_LRO
;
121 if (aq_cfg
->is_lro
!= is_lro
) {
122 aq_cfg
->is_lro
= is_lro
;
124 if (netif_running(ndev
)) {
134 static int aq_ndev_set_mac_address(struct net_device
*ndev
, void *addr
)
136 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
139 err
= eth_mac_addr(ndev
, addr
);
142 err
= aq_nic_set_mac(aq_nic
, ndev
);
150 static void aq_ndev_set_multicast_settings(struct net_device
*ndev
)
152 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
155 err
= aq_nic_set_packet_filter(aq_nic
, ndev
->flags
);
159 if (netdev_mc_count(ndev
)) {
160 err
= aq_nic_set_multicast_list(aq_nic
, ndev
);
168 static const struct net_device_ops aq_ndev_ops
= {
169 .ndo_open
= aq_ndev_open
,
170 .ndo_stop
= aq_ndev_close
,
171 .ndo_start_xmit
= aq_ndev_start_xmit
,
172 .ndo_set_rx_mode
= aq_ndev_set_multicast_settings
,
173 .ndo_change_mtu
= aq_ndev_change_mtu
,
174 .ndo_set_mac_address
= aq_ndev_set_mac_address
,
175 .ndo_set_features
= aq_ndev_set_features
178 static int aq_pci_probe(struct pci_dev
*pdev
,
179 const struct pci_device_id
*pci_id
)
181 struct aq_hw_ops
*aq_hw_ops
= NULL
;
182 struct aq_pci_func_s
*aq_pci_func
= NULL
;
185 err
= pci_enable_device(pdev
);
188 aq_hw_ops
= aq_pci_probe_get_hw_ops_by_id(pdev
);
189 aq_pci_func
= aq_pci_func_alloc(aq_hw_ops
, pdev
,
190 &aq_ndev_ops
, &aq_ethtool_ops
);
195 err
= aq_pci_func_init(aq_pci_func
);
202 aq_pci_func_free(aq_pci_func
);
207 static void aq_pci_remove(struct pci_dev
*pdev
)
209 struct aq_pci_func_s
*aq_pci_func
= pci_get_drvdata(pdev
);
211 aq_pci_func_deinit(aq_pci_func
);
212 aq_pci_func_free(aq_pci_func
);
215 static int aq_pci_suspend(struct pci_dev
*pdev
, pm_message_t pm_msg
)
217 struct aq_pci_func_s
*aq_pci_func
= pci_get_drvdata(pdev
);
219 return aq_pci_func_change_pm_state(aq_pci_func
, &pm_msg
);
222 static int aq_pci_resume(struct pci_dev
*pdev
)
224 struct aq_pci_func_s
*aq_pci_func
= pci_get_drvdata(pdev
);
225 pm_message_t pm_msg
= PMSG_RESTORE
;
227 return aq_pci_func_change_pm_state(aq_pci_func
, &pm_msg
);
230 static struct pci_driver aq_pci_ops
= {
231 .name
= AQ_CFG_DRV_NAME
,
232 .id_table
= aq_pci_tbl
,
233 .probe
= aq_pci_probe
,
234 .remove
= aq_pci_remove
,
235 .suspend
= aq_pci_suspend
,
236 .resume
= aq_pci_resume
,
239 module_pci_driver(aq_pci_ops
);