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_nic.c: Definition of common code for NIC. */
16 #include "aq_pci_func.h"
18 #include <linux/moduleparam.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/timer.h>
22 #include <linux/cpu.h>
24 #include <linux/tcp.h>
27 static unsigned int aq_itr
= AQ_CFG_INTERRUPT_MODERATION_AUTO
;
28 module_param_named(aq_itr
, aq_itr
, uint
, 0644);
29 MODULE_PARM_DESC(aq_itr
, "Interrupt throttling mode");
31 static unsigned int aq_itr_tx
;
32 module_param_named(aq_itr_tx
, aq_itr_tx
, uint
, 0644);
33 MODULE_PARM_DESC(aq_itr_tx
, "TX interrupt throttle rate");
35 static unsigned int aq_itr_rx
;
36 module_param_named(aq_itr_rx
, aq_itr_rx
, uint
, 0644);
37 MODULE_PARM_DESC(aq_itr_rx
, "RX interrupt throttle rate");
39 static void aq_nic_update_ndev_stats(struct aq_nic_s
*self
);
41 static void aq_nic_rss_init(struct aq_nic_s
*self
, unsigned int num_rss_queues
)
43 struct aq_nic_cfg_s
*cfg
= &self
->aq_nic_cfg
;
44 struct aq_rss_parameters
*rss_params
= &cfg
->aq_rss
;
47 static u8 rss_key
[AQ_CFG_RSS_HASHKEY_SIZE
] = {
48 0x1e, 0xad, 0x71, 0x87, 0x65, 0xfc, 0x26, 0x7d,
49 0x0d, 0x45, 0x67, 0x74, 0xcd, 0x06, 0x1a, 0x18,
50 0xb6, 0xc1, 0xf0, 0xc7, 0xbb, 0x18, 0xbe, 0xf8,
51 0x19, 0x13, 0x4b, 0xa9, 0xd0, 0x3e, 0xfe, 0x70,
52 0x25, 0x03, 0xab, 0x50, 0x6a, 0x8b, 0x82, 0x0c
55 rss_params
->hash_secret_key_size
= sizeof(rss_key
);
56 memcpy(rss_params
->hash_secret_key
, rss_key
, sizeof(rss_key
));
57 rss_params
->indirection_table_size
= AQ_CFG_RSS_INDIRECTION_TABLE_MAX
;
59 for (i
= rss_params
->indirection_table_size
; i
--;)
60 rss_params
->indirection_table
[i
] = i
& (num_rss_queues
- 1);
63 /* Checks hw_caps and 'corrects' aq_nic_cfg in runtime */
64 void aq_nic_cfg_start(struct aq_nic_s
*self
)
66 struct aq_nic_cfg_s
*cfg
= &self
->aq_nic_cfg
;
68 cfg
->tcs
= AQ_CFG_TCS_DEF
;
70 cfg
->is_polling
= AQ_CFG_IS_POLLING_DEF
;
73 cfg
->tx_itr
= aq_itr_tx
;
74 cfg
->rx_itr
= aq_itr_rx
;
76 cfg
->is_rss
= AQ_CFG_IS_RSS_DEF
;
77 cfg
->num_rss_queues
= AQ_CFG_NUM_RSS_QUEUES_DEF
;
78 cfg
->aq_rss
.base_cpu_number
= AQ_CFG_RSS_BASE_CPU_NUM_DEF
;
79 cfg
->flow_control
= AQ_CFG_FC_MODE
;
81 cfg
->mtu
= AQ_CFG_MTU_DEF
;
82 cfg
->link_speed_msk
= AQ_CFG_SPEED_MSK
;
83 cfg
->is_autoneg
= AQ_CFG_IS_AUTONEG_DEF
;
85 cfg
->is_lro
= AQ_CFG_IS_LRO_DEF
;
89 aq_nic_rss_init(self
, cfg
->num_rss_queues
);
92 cfg
->rxds
= min(cfg
->aq_hw_caps
->rxds_max
, AQ_CFG_RXDS_DEF
);
93 cfg
->txds
= min(cfg
->aq_hw_caps
->txds_max
, AQ_CFG_TXDS_DEF
);
96 cfg
->vecs
= min(cfg
->aq_hw_caps
->vecs
, AQ_CFG_VECS_DEF
);
97 cfg
->vecs
= min(cfg
->vecs
, num_online_cpus());
98 cfg
->vecs
= min(cfg
->vecs
, self
->irqvecs
);
99 /* cfg->vecs should be power of 2 for RSS */
102 else if (cfg
->vecs
>= 4U)
104 else if (cfg
->vecs
>= 2U)
109 cfg
->num_rss_queues
= min(cfg
->vecs
, AQ_CFG_NUM_RSS_QUEUES_DEF
);
111 cfg
->irq_type
= aq_pci_func_get_irq_type(self
);
113 if ((cfg
->irq_type
== AQ_HW_IRQ_LEGACY
) ||
114 (cfg
->aq_hw_caps
->vecs
== 1U) ||
120 cfg
->link_speed_msk
&= cfg
->aq_hw_caps
->link_speed_msk
;
121 cfg
->hw_features
= cfg
->aq_hw_caps
->hw_features
;
124 static int aq_nic_update_link_status(struct aq_nic_s
*self
)
126 int err
= self
->aq_fw_ops
->update_link_status(self
->aq_hw
);
131 if (self
->link_status
.mbps
!= self
->aq_hw
->aq_link_status
.mbps
) {
132 pr_info("%s: link change old %d new %d\n",
133 AQ_CFG_DRV_NAME
, self
->link_status
.mbps
,
134 self
->aq_hw
->aq_link_status
.mbps
);
135 aq_nic_update_interrupt_moderation_settings(self
);
138 self
->link_status
= self
->aq_hw
->aq_link_status
;
139 if (!netif_carrier_ok(self
->ndev
) && self
->link_status
.mbps
) {
140 aq_utils_obj_set(&self
->flags
,
141 AQ_NIC_FLAG_STARTED
);
142 aq_utils_obj_clear(&self
->flags
,
144 netif_carrier_on(self
->ndev
);
145 netif_tx_wake_all_queues(self
->ndev
);
147 if (netif_carrier_ok(self
->ndev
) && !self
->link_status
.mbps
) {
148 netif_carrier_off(self
->ndev
);
149 netif_tx_disable(self
->ndev
);
150 aq_utils_obj_set(&self
->flags
, AQ_NIC_LINK_DOWN
);
155 static void aq_nic_service_timer_cb(struct timer_list
*t
)
157 struct aq_nic_s
*self
= from_timer(self
, t
, service_timer
);
158 int ctimer
= AQ_CFG_SERVICE_TIMER_INTERVAL
;
161 if (aq_utils_obj_test(&self
->flags
, AQ_NIC_FLAGS_IS_NOT_READY
))
164 err
= aq_nic_update_link_status(self
);
168 if (self
->aq_fw_ops
->update_stats
)
169 self
->aq_fw_ops
->update_stats(self
->aq_hw
);
171 aq_nic_update_ndev_stats(self
);
173 /* If no link - use faster timer rate to detect link up asap */
174 if (!netif_carrier_ok(self
->ndev
))
175 ctimer
= max(ctimer
/ 2, 1);
178 mod_timer(&self
->service_timer
, jiffies
+ ctimer
);
181 static void aq_nic_polling_timer_cb(struct timer_list
*t
)
183 struct aq_nic_s
*self
= from_timer(self
, t
, polling_timer
);
184 struct aq_vec_s
*aq_vec
= NULL
;
187 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
188 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
])
189 aq_vec_isr(i
, (void *)aq_vec
);
191 mod_timer(&self
->polling_timer
, jiffies
+
192 AQ_CFG_POLLING_TIMER_INTERVAL
);
195 int aq_nic_ndev_register(struct aq_nic_s
*self
)
204 err
= hw_atl_utils_initfw(self
->aq_hw
, &self
->aq_fw_ops
);
208 err
= self
->aq_fw_ops
->get_mac_permanent(self
->aq_hw
,
209 self
->ndev
->dev_addr
);
213 #if defined(AQ_CFG_MAC_ADDR_PERMANENT)
215 static u8 mac_addr_permanent
[] = AQ_CFG_MAC_ADDR_PERMANENT
;
217 ether_addr_copy(self
->ndev
->dev_addr
, mac_addr_permanent
);
221 for (self
->aq_vecs
= 0; self
->aq_vecs
< aq_nic_get_cfg(self
)->vecs
;
223 self
->aq_vec
[self
->aq_vecs
] =
224 aq_vec_alloc(self
, self
->aq_vecs
, aq_nic_get_cfg(self
));
225 if (!self
->aq_vec
[self
->aq_vecs
]) {
231 netif_carrier_off(self
->ndev
);
233 netif_tx_disable(self
->ndev
);
235 err
= register_netdev(self
->ndev
);
243 void aq_nic_ndev_init(struct aq_nic_s
*self
)
245 const struct aq_hw_caps_s
*aq_hw_caps
= self
->aq_nic_cfg
.aq_hw_caps
;
246 struct aq_nic_cfg_s
*aq_nic_cfg
= &self
->aq_nic_cfg
;
248 self
->ndev
->hw_features
|= aq_hw_caps
->hw_features
;
249 self
->ndev
->features
= aq_hw_caps
->hw_features
;
250 self
->ndev
->vlan_features
|= NETIF_F_HW_CSUM
| NETIF_F_RXCSUM
|
251 NETIF_F_RXHASH
| NETIF_F_SG
| NETIF_F_LRO
;
252 self
->ndev
->priv_flags
= aq_hw_caps
->hw_priv_flags
;
253 self
->ndev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
255 self
->ndev
->mtu
= aq_nic_cfg
->mtu
- ETH_HLEN
;
256 self
->ndev
->max_mtu
= aq_hw_caps
->mtu
- ETH_FCS_LEN
- ETH_HLEN
;
260 void aq_nic_set_tx_ring(struct aq_nic_s
*self
, unsigned int idx
,
261 struct aq_ring_s
*ring
)
263 self
->aq_ring_tx
[idx
] = ring
;
266 struct net_device
*aq_nic_get_ndev(struct aq_nic_s
*self
)
271 int aq_nic_init(struct aq_nic_s
*self
)
273 struct aq_vec_s
*aq_vec
= NULL
;
277 self
->power_state
= AQ_HW_POWER_STATE_D0
;
278 err
= self
->aq_hw_ops
->hw_reset(self
->aq_hw
);
282 err
= self
->aq_hw_ops
->hw_init(self
->aq_hw
,
283 aq_nic_get_ndev(self
)->dev_addr
);
287 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
288 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
])
289 aq_vec_init(aq_vec
, self
->aq_hw_ops
, self
->aq_hw
);
291 netif_carrier_off(self
->ndev
);
297 int aq_nic_start(struct aq_nic_s
*self
)
299 struct aq_vec_s
*aq_vec
= NULL
;
303 err
= self
->aq_hw_ops
->hw_multicast_list_set(self
->aq_hw
,
305 self
->mc_list
.count
);
309 err
= self
->aq_hw_ops
->hw_packet_filter_set(self
->aq_hw
,
310 self
->packet_filter
);
314 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
315 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
]) {
316 err
= aq_vec_start(aq_vec
);
321 err
= self
->aq_hw_ops
->hw_start(self
->aq_hw
);
325 err
= aq_nic_update_interrupt_moderation_settings(self
);
328 timer_setup(&self
->service_timer
, aq_nic_service_timer_cb
, 0);
329 mod_timer(&self
->service_timer
, jiffies
+
330 AQ_CFG_SERVICE_TIMER_INTERVAL
);
332 if (self
->aq_nic_cfg
.is_polling
) {
333 timer_setup(&self
->polling_timer
, aq_nic_polling_timer_cb
, 0);
334 mod_timer(&self
->polling_timer
, jiffies
+
335 AQ_CFG_POLLING_TIMER_INTERVAL
);
337 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
338 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
]) {
339 err
= aq_pci_func_alloc_irq(self
, i
,
340 self
->ndev
->name
, aq_vec
,
341 aq_vec_get_affinity_mask(aq_vec
));
346 err
= self
->aq_hw_ops
->hw_irq_enable(self
->aq_hw
,
352 err
= netif_set_real_num_tx_queues(self
->ndev
, self
->aq_vecs
);
356 err
= netif_set_real_num_rx_queues(self
->ndev
, self
->aq_vecs
);
360 netif_tx_start_all_queues(self
->ndev
);
366 static unsigned int aq_nic_map_skb(struct aq_nic_s
*self
,
368 struct aq_ring_s
*ring
)
370 unsigned int ret
= 0U;
371 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
372 unsigned int frag_count
= 0U;
373 unsigned int dx
= ring
->sw_tail
;
374 struct aq_ring_buff_s
*first
= NULL
;
375 struct aq_ring_buff_s
*dx_buff
= &ring
->buff_ring
[dx
];
377 if (unlikely(skb_is_gso(skb
))) {
379 dx_buff
->len_pkt
= skb
->len
;
380 dx_buff
->len_l2
= ETH_HLEN
;
381 dx_buff
->len_l3
= ip_hdrlen(skb
);
382 dx_buff
->len_l4
= tcp_hdrlen(skb
);
383 dx_buff
->mss
= skb_shinfo(skb
)->gso_size
;
384 dx_buff
->is_txc
= 1U;
385 dx_buff
->eop_index
= 0xffffU
;
388 (ip_hdr(skb
)->version
== 6) ? 1U : 0U;
390 dx
= aq_ring_next_dx(ring
, dx
);
391 dx_buff
= &ring
->buff_ring
[dx
];
396 dx_buff
->len
= skb_headlen(skb
);
397 dx_buff
->pa
= dma_map_single(aq_nic_get_dev(self
),
402 if (unlikely(dma_mapping_error(aq_nic_get_dev(self
), dx_buff
->pa
))) {
408 dx_buff
->len_pkt
= skb
->len
;
409 dx_buff
->is_sop
= 1U;
410 dx_buff
->is_mapped
= 1U;
413 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
414 dx_buff
->is_ip_cso
= (htons(ETH_P_IP
) == skb
->protocol
) ?
417 if (ip_hdr(skb
)->version
== 4) {
418 dx_buff
->is_tcp_cso
=
419 (ip_hdr(skb
)->protocol
== IPPROTO_TCP
) ?
421 dx_buff
->is_udp_cso
=
422 (ip_hdr(skb
)->protocol
== IPPROTO_UDP
) ?
424 } else if (ip_hdr(skb
)->version
== 6) {
425 dx_buff
->is_tcp_cso
=
426 (ipv6_hdr(skb
)->nexthdr
== NEXTHDR_TCP
) ?
428 dx_buff
->is_udp_cso
=
429 (ipv6_hdr(skb
)->nexthdr
== NEXTHDR_UDP
) ?
434 for (; nr_frags
--; ++frag_count
) {
435 unsigned int frag_len
= 0U;
436 unsigned int buff_offset
= 0U;
437 unsigned int buff_size
= 0U;
439 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[frag_count
];
441 frag_len
= skb_frag_size(frag
);
444 if (frag_len
> AQ_CFG_TX_FRAME_MAX
)
445 buff_size
= AQ_CFG_TX_FRAME_MAX
;
447 buff_size
= frag_len
;
449 frag_pa
= skb_frag_dma_map(aq_nic_get_dev(self
),
455 if (unlikely(dma_mapping_error(aq_nic_get_dev(self
),
459 dx
= aq_ring_next_dx(ring
, dx
);
460 dx_buff
= &ring
->buff_ring
[dx
];
463 dx_buff
->len
= buff_size
;
464 dx_buff
->pa
= frag_pa
;
465 dx_buff
->is_mapped
= 1U;
466 dx_buff
->eop_index
= 0xffffU
;
468 frag_len
-= buff_size
;
469 buff_offset
+= buff_size
;
475 first
->eop_index
= dx
;
476 dx_buff
->is_eop
= 1U;
481 for (dx
= ring
->sw_tail
;
483 --ret
, dx
= aq_ring_next_dx(ring
, dx
)) {
484 dx_buff
= &ring
->buff_ring
[dx
];
486 if (!dx_buff
->is_txc
&& dx_buff
->pa
) {
487 if (unlikely(dx_buff
->is_sop
)) {
488 dma_unmap_single(aq_nic_get_dev(self
),
493 dma_unmap_page(aq_nic_get_dev(self
),
505 int aq_nic_xmit(struct aq_nic_s
*self
, struct sk_buff
*skb
)
507 struct aq_ring_s
*ring
= NULL
;
508 unsigned int frags
= 0U;
509 unsigned int vec
= skb
->queue_mapping
% self
->aq_nic_cfg
.vecs
;
510 unsigned int tc
= 0U;
511 int err
= NETDEV_TX_OK
;
513 frags
= skb_shinfo(skb
)->nr_frags
+ 1;
515 ring
= self
->aq_ring_tx
[AQ_NIC_TCVEC2RING(self
, tc
, vec
)];
517 if (frags
> AQ_CFG_SKB_FRAGS_MAX
) {
518 dev_kfree_skb_any(skb
);
522 aq_ring_update_queue_state(ring
);
524 /* Above status update may stop the queue. Check this. */
525 if (__netif_subqueue_stopped(self
->ndev
, ring
->idx
)) {
526 err
= NETDEV_TX_BUSY
;
530 frags
= aq_nic_map_skb(self
, skb
, ring
);
533 err
= self
->aq_hw_ops
->hw_ring_tx_xmit(self
->aq_hw
,
536 err
= NETDEV_TX_BUSY
;
543 int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s
*self
)
545 return self
->aq_hw_ops
->hw_interrupt_moderation_set(self
->aq_hw
);
548 int aq_nic_set_packet_filter(struct aq_nic_s
*self
, unsigned int flags
)
552 err
= self
->aq_hw_ops
->hw_packet_filter_set(self
->aq_hw
, flags
);
556 self
->packet_filter
= flags
;
562 int aq_nic_set_multicast_list(struct aq_nic_s
*self
, struct net_device
*ndev
)
564 unsigned int packet_filter
= self
->packet_filter
;
565 struct netdev_hw_addr
*ha
= NULL
;
568 self
->mc_list
.count
= 0;
569 if (netdev_uc_count(ndev
) > AQ_HW_MULTICAST_ADDRESS_MAX
) {
570 packet_filter
|= IFF_PROMISC
;
572 netdev_for_each_uc_addr(ha
, ndev
) {
573 ether_addr_copy(self
->mc_list
.ar
[i
++], ha
->addr
);
575 if (i
>= AQ_HW_MULTICAST_ADDRESS_MAX
)
580 if (i
+ netdev_mc_count(ndev
) > AQ_HW_MULTICAST_ADDRESS_MAX
) {
581 packet_filter
|= IFF_ALLMULTI
;
583 netdev_for_each_mc_addr(ha
, ndev
) {
584 ether_addr_copy(self
->mc_list
.ar
[i
++], ha
->addr
);
586 if (i
>= AQ_HW_MULTICAST_ADDRESS_MAX
)
591 if (i
> 0 && i
<= AQ_HW_MULTICAST_ADDRESS_MAX
) {
592 packet_filter
|= IFF_MULTICAST
;
593 self
->mc_list
.count
= i
;
594 self
->aq_hw_ops
->hw_multicast_list_set(self
->aq_hw
,
596 self
->mc_list
.count
);
598 return aq_nic_set_packet_filter(self
, packet_filter
);
601 int aq_nic_set_mtu(struct aq_nic_s
*self
, int new_mtu
)
603 self
->aq_nic_cfg
.mtu
= new_mtu
;
608 int aq_nic_set_mac(struct aq_nic_s
*self
, struct net_device
*ndev
)
610 return self
->aq_hw_ops
->hw_set_mac_address(self
->aq_hw
, ndev
->dev_addr
);
613 unsigned int aq_nic_get_link_speed(struct aq_nic_s
*self
)
615 return self
->link_status
.mbps
;
618 int aq_nic_get_regs(struct aq_nic_s
*self
, struct ethtool_regs
*regs
, void *p
)
623 if (unlikely(!self
->aq_hw_ops
->hw_get_regs
))
628 err
= self
->aq_hw_ops
->hw_get_regs(self
->aq_hw
,
629 self
->aq_nic_cfg
.aq_hw_caps
,
638 int aq_nic_get_regs_count(struct aq_nic_s
*self
)
640 if (unlikely(!self
->aq_hw_ops
->hw_get_regs
))
643 return self
->aq_nic_cfg
.aq_hw_caps
->mac_regs_count
;
646 void aq_nic_get_stats(struct aq_nic_s
*self
, u64
*data
)
649 unsigned int count
= 0U;
650 struct aq_vec_s
*aq_vec
= NULL
;
651 struct aq_stats_s
*stats
= self
->aq_hw_ops
->hw_get_hw_stats(self
->aq_hw
);
656 data
[i
] = stats
->uprc
+ stats
->mprc
+ stats
->bprc
;
657 data
[++i
] = stats
->uprc
;
658 data
[++i
] = stats
->mprc
;
659 data
[++i
] = stats
->bprc
;
660 data
[++i
] = stats
->erpt
;
661 data
[++i
] = stats
->uptc
+ stats
->mptc
+ stats
->bptc
;
662 data
[++i
] = stats
->uptc
;
663 data
[++i
] = stats
->mptc
;
664 data
[++i
] = stats
->bptc
;
665 data
[++i
] = stats
->ubrc
;
666 data
[++i
] = stats
->ubtc
;
667 data
[++i
] = stats
->mbrc
;
668 data
[++i
] = stats
->mbtc
;
669 data
[++i
] = stats
->bbrc
;
670 data
[++i
] = stats
->bbtc
;
671 data
[++i
] = stats
->ubrc
+ stats
->mbrc
+ stats
->bbrc
;
672 data
[++i
] = stats
->ubtc
+ stats
->mbtc
+ stats
->bbtc
;
673 data
[++i
] = stats
->dma_pkt_rc
;
674 data
[++i
] = stats
->dma_pkt_tc
;
675 data
[++i
] = stats
->dma_oct_rc
;
676 data
[++i
] = stats
->dma_oct_tc
;
677 data
[++i
] = stats
->dpc
;
683 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
684 aq_vec
&& self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
]) {
686 aq_vec_get_sw_stats(aq_vec
, data
, &count
);
692 static void aq_nic_update_ndev_stats(struct aq_nic_s
*self
)
694 struct net_device
*ndev
= self
->ndev
;
695 struct aq_stats_s
*stats
= self
->aq_hw_ops
->hw_get_hw_stats(self
->aq_hw
);
697 ndev
->stats
.rx_packets
= stats
->uprc
+ stats
->mprc
+ stats
->bprc
;
698 ndev
->stats
.rx_bytes
= stats
->ubrc
+ stats
->mbrc
+ stats
->bbrc
;
699 ndev
->stats
.rx_errors
= stats
->erpr
;
700 ndev
->stats
.tx_packets
= stats
->uptc
+ stats
->mptc
+ stats
->bptc
;
701 ndev
->stats
.tx_bytes
= stats
->ubtc
+ stats
->mbtc
+ stats
->bbtc
;
702 ndev
->stats
.tx_errors
= stats
->erpt
;
703 ndev
->stats
.multicast
= stats
->mprc
;
706 void aq_nic_get_link_ksettings(struct aq_nic_s
*self
,
707 struct ethtool_link_ksettings
*cmd
)
709 if (self
->aq_nic_cfg
.aq_hw_caps
->media_type
== AQ_HW_MEDIA_TYPE_FIBRE
)
710 cmd
->base
.port
= PORT_FIBRE
;
712 cmd
->base
.port
= PORT_TP
;
713 /* This driver supports only 10G capable adapters, so DUPLEX_FULL */
714 cmd
->base
.duplex
= DUPLEX_FULL
;
715 cmd
->base
.autoneg
= self
->aq_nic_cfg
.is_autoneg
;
717 ethtool_link_ksettings_zero_link_mode(cmd
, supported
);
719 if (self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& AQ_NIC_RATE_10G
)
720 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
723 if (self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& AQ_NIC_RATE_5G
)
724 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
727 if (self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& AQ_NIC_RATE_2GS
)
728 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
731 if (self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& AQ_NIC_RATE_1G
)
732 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
735 if (self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& AQ_NIC_RATE_100M
)
736 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
739 if (self
->aq_nic_cfg
.aq_hw_caps
->flow_control
)
740 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
743 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Autoneg
);
745 if (self
->aq_nic_cfg
.aq_hw_caps
->media_type
== AQ_HW_MEDIA_TYPE_FIBRE
)
746 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
748 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
750 ethtool_link_ksettings_zero_link_mode(cmd
, advertising
);
752 if (self
->aq_nic_cfg
.is_autoneg
)
753 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, Autoneg
);
755 if (self
->aq_nic_cfg
.link_speed_msk
& AQ_NIC_RATE_10G
)
756 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
759 if (self
->aq_nic_cfg
.link_speed_msk
& AQ_NIC_RATE_5G
)
760 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
763 if (self
->aq_nic_cfg
.link_speed_msk
& AQ_NIC_RATE_2GS
)
764 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
767 if (self
->aq_nic_cfg
.link_speed_msk
& AQ_NIC_RATE_1G
)
768 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
771 if (self
->aq_nic_cfg
.link_speed_msk
& AQ_NIC_RATE_100M
)
772 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
775 if (self
->aq_nic_cfg
.flow_control
& AQ_NIC_FC_RX
)
776 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
779 if (self
->aq_nic_cfg
.flow_control
& AQ_NIC_FC_TX
)
780 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
783 if (self
->aq_nic_cfg
.aq_hw_caps
->media_type
== AQ_HW_MEDIA_TYPE_FIBRE
)
784 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, FIBRE
);
786 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
789 int aq_nic_set_link_ksettings(struct aq_nic_s
*self
,
790 const struct ethtool_link_ksettings
*cmd
)
796 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
797 rate
= self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
;
798 self
->aq_nic_cfg
.is_autoneg
= true;
800 speed
= cmd
->base
.speed
;
804 rate
= AQ_NIC_RATE_100M
;
808 rate
= AQ_NIC_RATE_1G
;
812 rate
= AQ_NIC_RATE_2GS
;
816 rate
= AQ_NIC_RATE_5G
;
820 rate
= AQ_NIC_RATE_10G
;
828 if (!(self
->aq_nic_cfg
.aq_hw_caps
->link_speed_msk
& rate
)) {
833 self
->aq_nic_cfg
.is_autoneg
= false;
836 err
= self
->aq_fw_ops
->set_link_speed(self
->aq_hw
, rate
);
840 self
->aq_nic_cfg
.link_speed_msk
= rate
;
846 struct aq_nic_cfg_s
*aq_nic_get_cfg(struct aq_nic_s
*self
)
848 return &self
->aq_nic_cfg
;
851 u32
aq_nic_get_fw_version(struct aq_nic_s
*self
)
855 self
->aq_hw_ops
->hw_get_fw_version(self
->aq_hw
, &fw_version
);
860 int aq_nic_stop(struct aq_nic_s
*self
)
862 struct aq_vec_s
*aq_vec
= NULL
;
865 netif_tx_disable(self
->ndev
);
866 netif_carrier_off(self
->ndev
);
868 del_timer_sync(&self
->service_timer
);
870 self
->aq_hw_ops
->hw_irq_disable(self
->aq_hw
, AQ_CFG_IRQ_MASK
);
872 if (self
->aq_nic_cfg
.is_polling
)
873 del_timer_sync(&self
->polling_timer
);
875 aq_pci_func_free_irqs(self
);
877 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
878 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
])
881 return self
->aq_hw_ops
->hw_stop(self
->aq_hw
);
884 void aq_nic_deinit(struct aq_nic_s
*self
)
886 struct aq_vec_s
*aq_vec
= NULL
;
892 for (i
= 0U, aq_vec
= self
->aq_vec
[0];
893 self
->aq_vecs
> i
; ++i
, aq_vec
= self
->aq_vec
[i
])
894 aq_vec_deinit(aq_vec
);
896 if (self
->power_state
== AQ_HW_POWER_STATE_D0
) {
897 (void)self
->aq_fw_ops
->deinit(self
->aq_hw
);
899 (void)self
->aq_hw_ops
->hw_set_power(self
->aq_hw
,
906 void aq_nic_free_vectors(struct aq_nic_s
*self
)
913 for (i
= ARRAY_SIZE(self
->aq_vec
); i
--;) {
914 if (self
->aq_vec
[i
]) {
915 aq_vec_free(self
->aq_vec
[i
]);
916 self
->aq_vec
[i
] = NULL
;
923 int aq_nic_change_pm_state(struct aq_nic_s
*self
, pm_message_t
*pm_msg
)
927 if (!netif_running(self
->ndev
)) {
932 if (pm_msg
->event
& PM_EVENT_SLEEP
|| pm_msg
->event
& PM_EVENT_FREEZE
) {
933 self
->power_state
= AQ_HW_POWER_STATE_D3
;
934 netif_device_detach(self
->ndev
);
935 netif_tx_stop_all_queues(self
->ndev
);
937 err
= aq_nic_stop(self
);
943 err
= aq_nic_init(self
);
947 err
= aq_nic_start(self
);
951 netif_device_attach(self
->ndev
);
952 netif_tx_start_all_queues(self
->ndev
);
961 void aq_nic_shutdown(struct aq_nic_s
*self
)
970 netif_device_detach(self
->ndev
);
972 if (netif_running(self
->ndev
)) {
973 err
= aq_nic_stop(self
);