Skip to content

Commit 97bde5c

Browse files
David VomLehndavem330
authored andcommitted
net: ethernet: aquantia: Support for NIC-specific code
Add support for code specific to the Atlantic NIC. Signed-off-by: Alexander Loktionov <[email protected]> Signed-off-by: Dmitrii Tarakanov <[email protected]> Signed-off-by: Pavel Belous <[email protected]> Signed-off-by: Dmitry Bezrukov <[email protected]> Signed-off-by: David M. VomLehn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ef81153 commit 97bde5c

File tree

5 files changed

+1381
-0
lines changed

5 files changed

+1381
-0
lines changed
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/*
2+
* aQuantia Corporation Network Driver
3+
* Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4+
*
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.
8+
*/
9+
10+
/* File aq_main.c: Main file for aQuantia Linux driver. */
11+
12+
#include "aq_main.h"
13+
#include "aq_nic.h"
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"
18+
19+
#include <linux/netdevice.h>
20+
#include <linux/module.h>
21+
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), },
28+
{}
29+
};
30+
31+
MODULE_DEVICE_TABLE(pci, aq_pci_tbl);
32+
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);
37+
38+
static struct aq_hw_ops *aq_pci_probe_get_hw_ops_by_id(struct pci_dev *pdev)
39+
{
40+
struct aq_hw_ops *ops = NULL;
41+
42+
ops = hw_atl_a0_get_ops_by_id(pdev);
43+
if (!ops)
44+
ops = hw_atl_b0_get_ops_by_id(pdev);
45+
46+
return ops;
47+
}
48+
49+
static int aq_ndev_open(struct net_device *ndev)
50+
{
51+
struct aq_nic_s *aq_nic = NULL;
52+
int err = 0;
53+
54+
aq_nic = aq_nic_alloc_hot(ndev);
55+
if (!aq_nic) {
56+
err = -ENOMEM;
57+
goto err_exit;
58+
}
59+
err = aq_nic_init(aq_nic);
60+
if (err < 0)
61+
goto err_exit;
62+
err = aq_nic_start(aq_nic);
63+
if (err < 0)
64+
goto err_exit;
65+
66+
err_exit:
67+
if (err < 0)
68+
aq_nic_deinit(aq_nic);
69+
return err;
70+
}
71+
72+
static int aq_ndev_close(struct net_device *ndev)
73+
{
74+
int err = 0;
75+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
76+
77+
err = aq_nic_stop(aq_nic);
78+
if (err < 0)
79+
goto err_exit;
80+
aq_nic_deinit(aq_nic);
81+
aq_nic_free_hot_resources(aq_nic);
82+
83+
err_exit:
84+
return err;
85+
}
86+
87+
static int aq_ndev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
88+
{
89+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
90+
int err = 0;
91+
92+
err = aq_nic_xmit(aq_nic, skb);
93+
if (err < 0)
94+
goto err_exit;
95+
96+
err_exit:
97+
return err;
98+
}
99+
100+
static int aq_ndev_change_mtu(struct net_device *ndev, int new_mtu)
101+
{
102+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
103+
int err = 0;
104+
105+
if (new_mtu == ndev->mtu) {
106+
err = 0;
107+
goto err_exit;
108+
}
109+
if (new_mtu < 68) {
110+
err = -EINVAL;
111+
goto err_exit;
112+
}
113+
err = aq_nic_set_mtu(aq_nic, new_mtu + ETH_HLEN);
114+
if (err < 0)
115+
goto err_exit;
116+
ndev->mtu = new_mtu;
117+
118+
if (netif_running(ndev)) {
119+
aq_ndev_close(ndev);
120+
aq_ndev_open(ndev);
121+
}
122+
123+
err_exit:
124+
return err;
125+
}
126+
127+
static int aq_ndev_set_features(struct net_device *ndev,
128+
netdev_features_t features)
129+
{
130+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
131+
struct aq_nic_cfg_s *aq_cfg = aq_nic_get_cfg(aq_nic);
132+
bool is_lro = false;
133+
134+
if (aq_cfg->hw_features & NETIF_F_LRO) {
135+
is_lro = features & NETIF_F_LRO;
136+
137+
if (aq_cfg->is_lro != is_lro) {
138+
aq_cfg->is_lro = is_lro;
139+
140+
if (netif_running(ndev)) {
141+
aq_ndev_close(ndev);
142+
aq_ndev_open(ndev);
143+
}
144+
}
145+
}
146+
147+
return 0;
148+
}
149+
150+
static int aq_ndev_set_mac_address(struct net_device *ndev, void *addr)
151+
{
152+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
153+
int err = 0;
154+
155+
err = eth_mac_addr(ndev, addr);
156+
if (err < 0)
157+
goto err_exit;
158+
err = aq_nic_set_mac(aq_nic, ndev);
159+
if (err < 0)
160+
goto err_exit;
161+
162+
err_exit:
163+
return err;
164+
}
165+
166+
static void aq_ndev_set_multicast_settings(struct net_device *ndev)
167+
{
168+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
169+
int err = 0;
170+
171+
err = aq_nic_set_packet_filter(aq_nic, ndev->flags);
172+
if (err < 0)
173+
goto err_exit;
174+
175+
if (netdev_mc_count(ndev)) {
176+
err = aq_nic_set_multicast_list(aq_nic, ndev);
177+
if (err < 0)
178+
goto err_exit;
179+
}
180+
181+
err_exit:;
182+
}
183+
184+
static const struct net_device_ops aq_ndev_ops = {
185+
.ndo_open = aq_ndev_open,
186+
.ndo_stop = aq_ndev_close,
187+
.ndo_start_xmit = aq_ndev_start_xmit,
188+
.ndo_set_rx_mode = aq_ndev_set_multicast_settings,
189+
.ndo_change_mtu = aq_ndev_change_mtu,
190+
.ndo_set_mac_address = aq_ndev_set_mac_address,
191+
.ndo_set_features = aq_ndev_set_features
192+
};
193+
194+
static int aq_pci_probe(struct pci_dev *pdev,
195+
const struct pci_device_id *pci_id)
196+
{
197+
struct aq_hw_ops *aq_hw_ops = NULL;
198+
struct aq_pci_func_s *aq_pci_func = NULL;
199+
int err = 0;
200+
201+
err = pci_enable_device(pdev);
202+
if (err < 0)
203+
goto err_exit;
204+
aq_hw_ops = aq_pci_probe_get_hw_ops_by_id(pdev);
205+
aq_pci_func = aq_pci_func_alloc(aq_hw_ops, pdev,
206+
&aq_ndev_ops, &aq_ethtool_ops);
207+
if (!aq_pci_func) {
208+
err = -ENOMEM;
209+
goto err_exit;
210+
}
211+
err = aq_pci_func_init(aq_pci_func);
212+
if (err < 0)
213+
goto err_exit;
214+
215+
err_exit:
216+
if (err < 0) {
217+
if (aq_pci_func)
218+
aq_pci_func_free(aq_pci_func);
219+
}
220+
return err;
221+
}
222+
223+
static void aq_pci_remove(struct pci_dev *pdev)
224+
{
225+
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev);
226+
227+
aq_pci_func_deinit(aq_pci_func);
228+
aq_pci_func_free(aq_pci_func);
229+
}
230+
231+
static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg)
232+
{
233+
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev);
234+
235+
return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg);
236+
}
237+
238+
static int aq_pci_resume(struct pci_dev *pdev)
239+
{
240+
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev);
241+
pm_message_t pm_msg = PMSG_RESTORE;
242+
243+
return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg);
244+
}
245+
246+
static struct pci_driver aq_pci_ops = {
247+
.name = AQ_CFG_DRV_NAME,
248+
.id_table = aq_pci_tbl,
249+
.probe = aq_pci_probe,
250+
.remove = aq_pci_remove,
251+
.suspend = aq_pci_suspend,
252+
.resume = aq_pci_resume,
253+
};
254+
255+
static int __init aq_module_init(void)
256+
{
257+
int err = 0;
258+
259+
err = pci_register_driver(&aq_pci_ops);
260+
if (err < 0)
261+
goto err_exit;
262+
263+
err_exit:
264+
return err;
265+
}
266+
267+
static void __exit aq_module_exit(void)
268+
{
269+
pci_unregister_driver(&aq_pci_ops);
270+
}
271+
272+
module_init(aq_module_init);
273+
module_exit(aq_module_exit);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* aQuantia Corporation Network Driver
3+
* Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4+
*
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.
8+
*/
9+
10+
/* File aq_main.h: Main file for aQuantia Linux driver. */
11+
12+
#ifndef AQ_MAIN_H
13+
#define AQ_MAIN_H
14+
15+
#include "aq_common.h"
16+
17+
#endif /* AQ_MAIN_H */

0 commit comments

Comments
 (0)