2 * Copyright (C) 2005 - 2011 Emulex
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@emulex.com
15 * Costa Mesa, CA 92626
20 #include <asm/div64.h>
22 MODULE_VERSION(DRV_VER
);
23 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
24 MODULE_DESCRIPTION(DRV_DESC
" " DRV_VER
);
25 MODULE_AUTHOR("ServerEngines Corporation");
26 MODULE_LICENSE("GPL");
28 static ushort rx_frag_size
= 2048;
29 static unsigned int num_vfs
;
30 module_param(rx_frag_size
, ushort
, S_IRUGO
);
31 module_param(num_vfs
, uint
, S_IRUGO
);
32 MODULE_PARM_DESC(rx_frag_size
, "Size of a fragment that holds rcvd data.");
33 MODULE_PARM_DESC(num_vfs
, "Number of PCI VFs to initialize");
35 static bool multi_rxq
= true;
36 module_param(multi_rxq
, bool, S_IRUGO
| S_IWUSR
);
37 MODULE_PARM_DESC(multi_rxq
, "Multi Rx Queue support. Enabled by default");
39 static DEFINE_PCI_DEVICE_TABLE(be_dev_ids
) = {
40 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
41 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
42 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
43 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
44 { PCI_DEVICE(EMULEX_VENDOR_ID
, OC_DEVICE_ID3
)},
47 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
48 /* UE Status Low CSR */
49 static char *ue_status_low_desc
[] = {
83 /* UE Status High CSR */
84 static char *ue_status_hi_desc
[] = {
119 static void be_queue_free(struct be_adapter
*adapter
, struct be_queue_info
*q
)
121 struct be_dma_mem
*mem
= &q
->dma_mem
;
123 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
127 static int be_queue_alloc(struct be_adapter
*adapter
, struct be_queue_info
*q
,
128 u16 len
, u16 entry_size
)
130 struct be_dma_mem
*mem
= &q
->dma_mem
;
132 memset(q
, 0, sizeof(*q
));
134 q
->entry_size
= entry_size
;
135 mem
->size
= len
* entry_size
;
136 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
, &mem
->dma
,
140 memset(mem
->va
, 0, mem
->size
);
144 static void be_intr_set(struct be_adapter
*adapter
, bool enable
)
146 u8 __iomem
*addr
= adapter
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
147 u32 reg
= ioread32(addr
);
148 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
150 if (adapter
->eeh_err
)
153 if (!enabled
&& enable
)
154 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
155 else if (enabled
&& !enable
)
156 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
160 iowrite32(reg
, addr
);
163 static void be_rxq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
166 val
|= qid
& DB_RQ_RING_ID_MASK
;
167 val
|= posted
<< DB_RQ_NUM_POSTED_SHIFT
;
170 iowrite32(val
, adapter
->db
+ DB_RQ_OFFSET
);
173 static void be_txq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
176 val
|= qid
& DB_TXULP_RING_ID_MASK
;
177 val
|= (posted
& DB_TXULP_NUM_POSTED_MASK
) << DB_TXULP_NUM_POSTED_SHIFT
;
180 iowrite32(val
, adapter
->db
+ DB_TXULP1_OFFSET
);
183 static void be_eq_notify(struct be_adapter
*adapter
, u16 qid
,
184 bool arm
, bool clear_int
, u16 num_popped
)
187 val
|= qid
& DB_EQ_RING_ID_MASK
;
188 val
|= ((qid
& DB_EQ_RING_ID_EXT_MASK
) <<
189 DB_EQ_RING_ID_EXT_MASK_SHIFT
);
191 if (adapter
->eeh_err
)
195 val
|= 1 << DB_EQ_REARM_SHIFT
;
197 val
|= 1 << DB_EQ_CLR_SHIFT
;
198 val
|= 1 << DB_EQ_EVNT_SHIFT
;
199 val
|= num_popped
<< DB_EQ_NUM_POPPED_SHIFT
;
200 iowrite32(val
, adapter
->db
+ DB_EQ_OFFSET
);
203 void be_cq_notify(struct be_adapter
*adapter
, u16 qid
, bool arm
, u16 num_popped
)
206 val
|= qid
& DB_CQ_RING_ID_MASK
;
207 val
|= ((qid
& DB_CQ_RING_ID_EXT_MASK
) <<
208 DB_CQ_RING_ID_EXT_MASK_SHIFT
);
210 if (adapter
->eeh_err
)
214 val
|= 1 << DB_CQ_REARM_SHIFT
;
215 val
|= num_popped
<< DB_CQ_NUM_POPPED_SHIFT
;
216 iowrite32(val
, adapter
->db
+ DB_CQ_OFFSET
);
219 static int be_mac_addr_set(struct net_device
*netdev
, void *p
)
221 struct be_adapter
*adapter
= netdev_priv(netdev
);
222 struct sockaddr
*addr
= p
;
225 if (!is_valid_ether_addr(addr
->sa_data
))
226 return -EADDRNOTAVAIL
;
228 /* MAC addr configuration will be done in hardware for VFs
229 * by their corresponding PFs. Just copy to netdev addr here
231 if (!be_physfn(adapter
))
234 status
= be_cmd_pmac_del(adapter
, adapter
->if_handle
,
235 adapter
->pmac_id
, 0);
239 status
= be_cmd_pmac_add(adapter
, (u8
*)addr
->sa_data
,
240 adapter
->if_handle
, &adapter
->pmac_id
, 0);
243 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
248 void netdev_stats_update(struct be_adapter
*adapter
)
250 struct be_hw_stats
*hw_stats
= hw_stats_from_cmd(adapter
->stats_cmd
.va
);
251 struct be_rxf_stats
*rxf_stats
= &hw_stats
->rxf
;
252 struct be_port_rxf_stats
*port_stats
=
253 &rxf_stats
->port
[adapter
->port_num
];
254 struct net_device_stats
*dev_stats
= &adapter
->netdev
->stats
;
255 struct be_erx_stats
*erx_stats
= &hw_stats
->erx
;
256 struct be_rx_obj
*rxo
;
259 memset(dev_stats
, 0, sizeof(*dev_stats
));
260 for_all_rx_queues(adapter
, rxo
, i
) {
261 dev_stats
->rx_packets
+= rx_stats(rxo
)->rx_pkts
;
262 dev_stats
->rx_bytes
+= rx_stats(rxo
)->rx_bytes
;
263 dev_stats
->multicast
+= rx_stats(rxo
)->rx_mcast_pkts
;
264 /* no space in linux buffers: best possible approximation */
265 dev_stats
->rx_dropped
+=
266 erx_stats
->rx_drops_no_fragments
[rxo
->q
.id
];
269 dev_stats
->tx_packets
= tx_stats(adapter
)->be_tx_pkts
;
270 dev_stats
->tx_bytes
= tx_stats(adapter
)->be_tx_bytes
;
272 /* bad pkts received */
273 dev_stats
->rx_errors
= port_stats
->rx_crc_errors
+
274 port_stats
->rx_alignment_symbol_errors
+
275 port_stats
->rx_in_range_errors
+
276 port_stats
->rx_out_range_errors
+
277 port_stats
->rx_frame_too_long
+
278 port_stats
->rx_dropped_too_small
+
279 port_stats
->rx_dropped_too_short
+
280 port_stats
->rx_dropped_header_too_small
+
281 port_stats
->rx_dropped_tcp_length
+
282 port_stats
->rx_dropped_runt
+
283 port_stats
->rx_tcp_checksum_errs
+
284 port_stats
->rx_ip_checksum_errs
+
285 port_stats
->rx_udp_checksum_errs
;
287 /* detailed rx errors */
288 dev_stats
->rx_length_errors
= port_stats
->rx_in_range_errors
+
289 port_stats
->rx_out_range_errors
+
290 port_stats
->rx_frame_too_long
;
292 dev_stats
->rx_crc_errors
= port_stats
->rx_crc_errors
;
294 /* frame alignment errors */
295 dev_stats
->rx_frame_errors
= port_stats
->rx_alignment_symbol_errors
;
297 /* receiver fifo overrun */
298 /* drops_no_pbuf is no per i/f, it's per BE card */
299 dev_stats
->rx_fifo_errors
= port_stats
->rx_fifo_overflow
+
300 port_stats
->rx_input_fifo_overflow
+
301 rxf_stats
->rx_drops_no_pbuf
;
304 void be_link_status_update(struct be_adapter
*adapter
, bool link_up
)
306 struct net_device
*netdev
= adapter
->netdev
;
308 /* If link came up or went down */
309 if (adapter
->link_up
!= link_up
) {
310 adapter
->link_speed
= -1;
312 netif_carrier_on(netdev
);
313 printk(KERN_INFO
"%s: Link up\n", netdev
->name
);
315 netif_carrier_off(netdev
);
316 printk(KERN_INFO
"%s: Link down\n", netdev
->name
);
318 adapter
->link_up
= link_up
;
322 /* Update the EQ delay n BE based on the RX frags consumed / sec */
323 static void be_rx_eqd_update(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
)
325 struct be_eq_obj
*rx_eq
= &rxo
->rx_eq
;
326 struct be_rx_stats
*stats
= &rxo
->stats
;
330 if (!rx_eq
->enable_aic
)
334 if (time_before(now
, stats
->rx_fps_jiffies
)) {
335 stats
->rx_fps_jiffies
= now
;
339 /* Update once a second */
340 if ((now
- stats
->rx_fps_jiffies
) < HZ
)
343 stats
->rx_fps
= (stats
->rx_frags
- stats
->prev_rx_frags
) /
344 ((now
- stats
->rx_fps_jiffies
) / HZ
);
346 stats
->rx_fps_jiffies
= now
;
347 stats
->prev_rx_frags
= stats
->rx_frags
;
348 eqd
= stats
->rx_fps
/ 110000;
350 if (eqd
> rx_eq
->max_eqd
)
351 eqd
= rx_eq
->max_eqd
;
352 if (eqd
< rx_eq
->min_eqd
)
353 eqd
= rx_eq
->min_eqd
;
356 if (eqd
!= rx_eq
->cur_eqd
)
357 be_cmd_modify_eqd(adapter
, rx_eq
->q
.id
, eqd
);
359 rx_eq
->cur_eqd
= eqd
;
362 static u32
be_calc_rate(u64 bytes
, unsigned long ticks
)
366 do_div(rate
, ticks
/ HZ
);
367 rate
<<= 3; /* bytes/sec -> bits/sec */
368 do_div(rate
, 1000000ul); /* MB/Sec */
373 static void be_tx_rate_update(struct be_adapter
*adapter
)
375 struct be_tx_stats
*stats
= tx_stats(adapter
);
378 /* Wrapped around? */
379 if (time_before(now
, stats
->be_tx_jiffies
)) {
380 stats
->be_tx_jiffies
= now
;
384 /* Update tx rate once in two seconds */
385 if ((now
- stats
->be_tx_jiffies
) > 2 * HZ
) {
386 stats
->be_tx_rate
= be_calc_rate(stats
->be_tx_bytes
387 - stats
->be_tx_bytes_prev
,
388 now
- stats
->be_tx_jiffies
);
389 stats
->be_tx_jiffies
= now
;
390 stats
->be_tx_bytes_prev
= stats
->be_tx_bytes
;
394 static void be_tx_stats_update(struct be_adapter
*adapter
,
395 u32 wrb_cnt
, u32 copied
, u32 gso_segs
, bool stopped
)
397 struct be_tx_stats
*stats
= tx_stats(adapter
);
399 stats
->be_tx_wrbs
+= wrb_cnt
;
400 stats
->be_tx_bytes
+= copied
;
401 stats
->be_tx_pkts
+= (gso_segs
? gso_segs
: 1);
403 stats
->be_tx_stops
++;
406 /* Determine number of WRB entries needed to xmit data in an skb */
407 static u32
wrb_cnt_for_skb(struct be_adapter
*adapter
, struct sk_buff
*skb
,
410 int cnt
= (skb
->len
> skb
->data_len
);
412 cnt
+= skb_shinfo(skb
)->nr_frags
;
414 /* to account for hdr wrb */
416 if (lancer_chip(adapter
) || !(cnt
& 1)) {
419 /* add a dummy to make it an even num */
423 BUG_ON(cnt
> BE_MAX_TX_FRAG_COUNT
);
427 static inline void wrb_fill(struct be_eth_wrb
*wrb
, u64 addr
, int len
)
429 wrb
->frag_pa_hi
= upper_32_bits(addr
);
430 wrb
->frag_pa_lo
= addr
& 0xFFFFFFFF;
431 wrb
->frag_len
= len
& ETH_WRB_FRAG_LEN_MASK
;
434 static void wrb_fill_hdr(struct be_adapter
*adapter
, struct be_eth_hdr_wrb
*hdr
,
435 struct sk_buff
*skb
, u32 wrb_cnt
, u32 len
)
440 memset(hdr
, 0, sizeof(*hdr
));
442 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, crc
, hdr
, 1);
444 if (skb_is_gso(skb
)) {
445 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso
, hdr
, 1);
446 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso_mss
,
447 hdr
, skb_shinfo(skb
)->gso_size
);
448 if (skb_is_gso_v6(skb
) && !lancer_chip(adapter
))
449 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso6
, hdr
, 1);
450 if (lancer_chip(adapter
) && adapter
->sli_family
==
451 LANCER_A0_SLI_FAMILY
) {
452 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, ipcs
, hdr
, 1);
454 AMAP_SET_BITS(struct amap_eth_hdr_wrb
,
456 else if (is_udp_pkt(skb
))
457 AMAP_SET_BITS(struct amap_eth_hdr_wrb
,
460 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
462 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, tcpcs
, hdr
, 1);
463 else if (is_udp_pkt(skb
))
464 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, udpcs
, hdr
, 1);
467 if (adapter
->vlan_grp
&& vlan_tx_tag_present(skb
)) {
468 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan
, hdr
, 1);
469 vlan_tag
= vlan_tx_tag_get(skb
);
470 vlan_prio
= (vlan_tag
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
471 /* If vlan priority provided by OS is NOT in available bmap */
472 if (!(adapter
->vlan_prio_bmap
& (1 << vlan_prio
)))
473 vlan_tag
= (vlan_tag
& ~VLAN_PRIO_MASK
) |
474 adapter
->recommended_prio
;
475 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan_tag
, hdr
, vlan_tag
);
478 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, event
, hdr
, 1);
479 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, complete
, hdr
, 1);
480 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, num_wrb
, hdr
, wrb_cnt
);
481 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, len
, hdr
, len
);
484 static void unmap_tx_frag(struct device
*dev
, struct be_eth_wrb
*wrb
,
489 be_dws_le_to_cpu(wrb
, sizeof(*wrb
));
491 dma
= (u64
)wrb
->frag_pa_hi
<< 32 | (u64
)wrb
->frag_pa_lo
;
494 dma_unmap_single(dev
, dma
, wrb
->frag_len
,
497 dma_unmap_page(dev
, dma
, wrb
->frag_len
, DMA_TO_DEVICE
);
501 static int make_tx_wrbs(struct be_adapter
*adapter
,
502 struct sk_buff
*skb
, u32 wrb_cnt
, bool dummy_wrb
)
506 struct device
*dev
= &adapter
->pdev
->dev
;
507 struct sk_buff
*first_skb
= skb
;
508 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
509 struct be_eth_wrb
*wrb
;
510 struct be_eth_hdr_wrb
*hdr
;
511 bool map_single
= false;
514 hdr
= queue_head_node(txq
);
516 map_head
= txq
->head
;
518 if (skb
->len
> skb
->data_len
) {
519 int len
= skb_headlen(skb
);
520 busaddr
= dma_map_single(dev
, skb
->data
, len
, DMA_TO_DEVICE
);
521 if (dma_mapping_error(dev
, busaddr
))
524 wrb
= queue_head_node(txq
);
525 wrb_fill(wrb
, busaddr
, len
);
526 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
531 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
532 struct skb_frag_struct
*frag
=
533 &skb_shinfo(skb
)->frags
[i
];
534 busaddr
= dma_map_page(dev
, frag
->page
, frag
->page_offset
,
535 frag
->size
, DMA_TO_DEVICE
);
536 if (dma_mapping_error(dev
, busaddr
))
538 wrb
= queue_head_node(txq
);
539 wrb_fill(wrb
, busaddr
, frag
->size
);
540 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
542 copied
+= frag
->size
;
546 wrb
= queue_head_node(txq
);
548 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
552 wrb_fill_hdr(adapter
, hdr
, first_skb
, wrb_cnt
, copied
);
553 be_dws_cpu_to_le(hdr
, sizeof(*hdr
));
557 txq
->head
= map_head
;
559 wrb
= queue_head_node(txq
);
560 unmap_tx_frag(dev
, wrb
, map_single
);
562 copied
-= wrb
->frag_len
;
568 static netdev_tx_t
be_xmit(struct sk_buff
*skb
,
569 struct net_device
*netdev
)
571 struct be_adapter
*adapter
= netdev_priv(netdev
);
572 struct be_tx_obj
*tx_obj
= &adapter
->tx_obj
;
573 struct be_queue_info
*txq
= &tx_obj
->q
;
574 u32 wrb_cnt
= 0, copied
= 0;
575 u32 start
= txq
->head
;
576 bool dummy_wrb
, stopped
= false;
578 wrb_cnt
= wrb_cnt_for_skb(adapter
, skb
, &dummy_wrb
);
580 copied
= make_tx_wrbs(adapter
, skb
, wrb_cnt
, dummy_wrb
);
582 /* record the sent skb in the sent_skb table */
583 BUG_ON(tx_obj
->sent_skb_list
[start
]);
584 tx_obj
->sent_skb_list
[start
] = skb
;
586 /* Ensure txq has space for the next skb; Else stop the queue
587 * *BEFORE* ringing the tx doorbell, so that we serialze the
588 * tx compls of the current transmit which'll wake up the queue
590 atomic_add(wrb_cnt
, &txq
->used
);
591 if ((BE_MAX_TX_FRAG_COUNT
+ atomic_read(&txq
->used
)) >=
593 netif_stop_queue(netdev
);
597 be_txq_notify(adapter
, txq
->id
, wrb_cnt
);
599 be_tx_stats_update(adapter
, wrb_cnt
, copied
,
600 skb_shinfo(skb
)->gso_segs
, stopped
);
603 dev_kfree_skb_any(skb
);
608 static int be_change_mtu(struct net_device
*netdev
, int new_mtu
)
610 struct be_adapter
*adapter
= netdev_priv(netdev
);
611 if (new_mtu
< BE_MIN_MTU
||
612 new_mtu
> (BE_MAX_JUMBO_FRAME_SIZE
-
613 (ETH_HLEN
+ ETH_FCS_LEN
))) {
614 dev_info(&adapter
->pdev
->dev
,
615 "MTU must be between %d and %d bytes\n",
617 (BE_MAX_JUMBO_FRAME_SIZE
- (ETH_HLEN
+ ETH_FCS_LEN
)));
620 dev_info(&adapter
->pdev
->dev
, "MTU changed from %d to %d bytes\n",
621 netdev
->mtu
, new_mtu
);
622 netdev
->mtu
= new_mtu
;
627 * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE.
628 * If the user configures more, place BE in vlan promiscuous mode.
630 static int be_vid_config(struct be_adapter
*adapter
, bool vf
, u32 vf_num
)
632 u16 vtag
[BE_NUM_VLANS_SUPPORTED
];
638 if_handle
= adapter
->vf_cfg
[vf_num
].vf_if_handle
;
639 vtag
[0] = cpu_to_le16(adapter
->vf_cfg
[vf_num
].vf_vlan_tag
);
640 status
= be_cmd_vlan_config(adapter
, if_handle
, vtag
, 1, 1, 0);
643 if (adapter
->vlans_added
<= adapter
->max_vlans
) {
644 /* Construct VLAN Table to give to HW */
645 for (i
= 0; i
< VLAN_N_VID
; i
++) {
646 if (adapter
->vlan_tag
[i
]) {
647 vtag
[ntags
] = cpu_to_le16(i
);
651 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
654 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
661 static void be_vlan_register(struct net_device
*netdev
, struct vlan_group
*grp
)
663 struct be_adapter
*adapter
= netdev_priv(netdev
);
665 adapter
->vlan_grp
= grp
;
668 static void be_vlan_add_vid(struct net_device
*netdev
, u16 vid
)
670 struct be_adapter
*adapter
= netdev_priv(netdev
);
672 adapter
->vlans_added
++;
673 if (!be_physfn(adapter
))
676 adapter
->vlan_tag
[vid
] = 1;
677 if (adapter
->vlans_added
<= (adapter
->max_vlans
+ 1))
678 be_vid_config(adapter
, false, 0);
681 static void be_vlan_rem_vid(struct net_device
*netdev
, u16 vid
)
683 struct be_adapter
*adapter
= netdev_priv(netdev
);
685 adapter
->vlans_added
--;
686 vlan_group_set_device(adapter
->vlan_grp
, vid
, NULL
);
688 if (!be_physfn(adapter
))
691 adapter
->vlan_tag
[vid
] = 0;
692 if (adapter
->vlans_added
<= adapter
->max_vlans
)
693 be_vid_config(adapter
, false, 0);
696 static void be_set_multicast_list(struct net_device
*netdev
)
698 struct be_adapter
*adapter
= netdev_priv(netdev
);
700 if (netdev
->flags
& IFF_PROMISC
) {
701 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 1);
702 adapter
->promiscuous
= true;
706 /* BE was previously in promiscuous mode; disable it */
707 if (adapter
->promiscuous
) {
708 adapter
->promiscuous
= false;
709 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 0);
712 /* Enable multicast promisc if num configured exceeds what we support */
713 if (netdev
->flags
& IFF_ALLMULTI
||
714 netdev_mc_count(netdev
) > BE_MAX_MC
) {
715 be_cmd_multicast_set(adapter
, adapter
->if_handle
, NULL
,
716 &adapter
->mc_cmd_mem
);
720 be_cmd_multicast_set(adapter
, adapter
->if_handle
, netdev
,
721 &adapter
->mc_cmd_mem
);
726 static int be_set_vf_mac(struct net_device
*netdev
, int vf
, u8
*mac
)
728 struct be_adapter
*adapter
= netdev_priv(netdev
);
731 if (!adapter
->sriov_enabled
)
734 if (!is_valid_ether_addr(mac
) || (vf
>= num_vfs
))
737 if (adapter
->vf_cfg
[vf
].vf_pmac_id
!= BE_INVALID_PMAC_ID
)
738 status
= be_cmd_pmac_del(adapter
,
739 adapter
->vf_cfg
[vf
].vf_if_handle
,
740 adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
742 status
= be_cmd_pmac_add(adapter
, mac
,
743 adapter
->vf_cfg
[vf
].vf_if_handle
,
744 &adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
747 dev_err(&adapter
->pdev
->dev
, "MAC %pM set on VF %d Failed\n",
750 memcpy(adapter
->vf_cfg
[vf
].vf_mac_addr
, mac
, ETH_ALEN
);
755 static int be_get_vf_config(struct net_device
*netdev
, int vf
,
756 struct ifla_vf_info
*vi
)
758 struct be_adapter
*adapter
= netdev_priv(netdev
);
760 if (!adapter
->sriov_enabled
)
767 vi
->tx_rate
= adapter
->vf_cfg
[vf
].vf_tx_rate
;
768 vi
->vlan
= adapter
->vf_cfg
[vf
].vf_vlan_tag
;
770 memcpy(&vi
->mac
, adapter
->vf_cfg
[vf
].vf_mac_addr
, ETH_ALEN
);
775 static int be_set_vf_vlan(struct net_device
*netdev
,
776 int vf
, u16 vlan
, u8 qos
)
778 struct be_adapter
*adapter
= netdev_priv(netdev
);
781 if (!adapter
->sriov_enabled
)
784 if ((vf
>= num_vfs
) || (vlan
> 4095))
788 adapter
->vf_cfg
[vf
].vf_vlan_tag
= vlan
;
789 adapter
->vlans_added
++;
791 adapter
->vf_cfg
[vf
].vf_vlan_tag
= 0;
792 adapter
->vlans_added
--;
795 status
= be_vid_config(adapter
, true, vf
);
798 dev_info(&adapter
->pdev
->dev
,
799 "VLAN %d config on VF %d failed\n", vlan
, vf
);
803 static int be_set_vf_tx_rate(struct net_device
*netdev
,
806 struct be_adapter
*adapter
= netdev_priv(netdev
);
809 if (!adapter
->sriov_enabled
)
812 if ((vf
>= num_vfs
) || (rate
< 0))
818 adapter
->vf_cfg
[vf
].vf_tx_rate
= rate
;
819 status
= be_cmd_set_qos(adapter
, rate
/ 10, vf
+ 1);
822 dev_info(&adapter
->pdev
->dev
,
823 "tx rate %d on VF %d failed\n", rate
, vf
);
827 static void be_rx_rate_update(struct be_rx_obj
*rxo
)
829 struct be_rx_stats
*stats
= &rxo
->stats
;
833 if (time_before(now
, stats
->rx_jiffies
)) {
834 stats
->rx_jiffies
= now
;
838 /* Update the rate once in two seconds */
839 if ((now
- stats
->rx_jiffies
) < 2 * HZ
)
842 stats
->rx_rate
= be_calc_rate(stats
->rx_bytes
- stats
->rx_bytes_prev
,
843 now
- stats
->rx_jiffies
);
844 stats
->rx_jiffies
= now
;
845 stats
->rx_bytes_prev
= stats
->rx_bytes
;
848 static void be_rx_stats_update(struct be_rx_obj
*rxo
,
849 struct be_rx_compl_info
*rxcp
)
851 struct be_rx_stats
*stats
= &rxo
->stats
;
854 stats
->rx_frags
+= rxcp
->num_rcvd
;
855 stats
->rx_bytes
+= rxcp
->pkt_size
;
857 if (rxcp
->pkt_type
== BE_MULTICAST_PACKET
)
858 stats
->rx_mcast_pkts
++;
863 static inline bool csum_passed(struct be_rx_compl_info
*rxcp
)
865 /* L4 checksum is not reliable for non TCP/UDP packets.
866 * Also ignore ipcksm for ipv6 pkts */
867 return (rxcp
->tcpf
|| rxcp
->udpf
) && rxcp
->l4_csum
&&
868 (rxcp
->ip_csum
|| rxcp
->ipv6
);
871 static struct be_rx_page_info
*
872 get_rx_page_info(struct be_adapter
*adapter
,
873 struct be_rx_obj
*rxo
,
876 struct be_rx_page_info
*rx_page_info
;
877 struct be_queue_info
*rxq
= &rxo
->q
;
879 rx_page_info
= &rxo
->page_info_tbl
[frag_idx
];
880 BUG_ON(!rx_page_info
->page
);
882 if (rx_page_info
->last_page_user
) {
883 dma_unmap_page(&adapter
->pdev
->dev
,
884 dma_unmap_addr(rx_page_info
, bus
),
885 adapter
->big_page_size
, DMA_FROM_DEVICE
);
886 rx_page_info
->last_page_user
= false;
889 atomic_dec(&rxq
->used
);
893 /* Throwaway the data in the Rx completion */
894 static void be_rx_compl_discard(struct be_adapter
*adapter
,
895 struct be_rx_obj
*rxo
,
896 struct be_rx_compl_info
*rxcp
)
898 struct be_queue_info
*rxq
= &rxo
->q
;
899 struct be_rx_page_info
*page_info
;
900 u16 i
, num_rcvd
= rxcp
->num_rcvd
;
902 for (i
= 0; i
< num_rcvd
; i
++) {
903 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
904 put_page(page_info
->page
);
905 memset(page_info
, 0, sizeof(*page_info
));
906 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
911 * skb_fill_rx_data forms a complete skb for an ether frame
914 static void skb_fill_rx_data(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
,
915 struct sk_buff
*skb
, struct be_rx_compl_info
*rxcp
)
917 struct be_queue_info
*rxq
= &rxo
->q
;
918 struct be_rx_page_info
*page_info
;
920 u16 hdr_len
, curr_frag_len
, remaining
;
923 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
924 start
= page_address(page_info
->page
) + page_info
->page_offset
;
927 /* Copy data in the first descriptor of this completion */
928 curr_frag_len
= min(rxcp
->pkt_size
, rx_frag_size
);
930 /* Copy the header portion into skb_data */
931 hdr_len
= min(BE_HDR_LEN
, curr_frag_len
);
932 memcpy(skb
->data
, start
, hdr_len
);
933 skb
->len
= curr_frag_len
;
934 if (curr_frag_len
<= BE_HDR_LEN
) { /* tiny packet */
935 /* Complete packet has now been moved to data */
936 put_page(page_info
->page
);
938 skb
->tail
+= curr_frag_len
;
940 skb_shinfo(skb
)->nr_frags
= 1;
941 skb_shinfo(skb
)->frags
[0].page
= page_info
->page
;
942 skb_shinfo(skb
)->frags
[0].page_offset
=
943 page_info
->page_offset
+ hdr_len
;
944 skb_shinfo(skb
)->frags
[0].size
= curr_frag_len
- hdr_len
;
945 skb
->data_len
= curr_frag_len
- hdr_len
;
946 skb
->tail
+= hdr_len
;
948 page_info
->page
= NULL
;
950 if (rxcp
->pkt_size
<= rx_frag_size
) {
951 BUG_ON(rxcp
->num_rcvd
!= 1);
955 /* More frags present for this completion */
956 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
957 remaining
= rxcp
->pkt_size
- curr_frag_len
;
958 for (i
= 1, j
= 0; i
< rxcp
->num_rcvd
; i
++) {
959 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
960 curr_frag_len
= min(remaining
, rx_frag_size
);
962 /* Coalesce all frags from the same physical page in one slot */
963 if (page_info
->page_offset
== 0) {
966 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
967 skb_shinfo(skb
)->frags
[j
].page_offset
=
968 page_info
->page_offset
;
969 skb_shinfo(skb
)->frags
[j
].size
= 0;
970 skb_shinfo(skb
)->nr_frags
++;
972 put_page(page_info
->page
);
975 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
976 skb
->len
+= curr_frag_len
;
977 skb
->data_len
+= curr_frag_len
;
979 remaining
-= curr_frag_len
;
980 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
981 page_info
->page
= NULL
;
983 BUG_ON(j
> MAX_SKB_FRAGS
);
986 /* Process the RX completion indicated by rxcp when GRO is disabled */
987 static void be_rx_compl_process(struct be_adapter
*adapter
,
988 struct be_rx_obj
*rxo
,
989 struct be_rx_compl_info
*rxcp
)
991 struct net_device
*netdev
= adapter
->netdev
;
994 skb
= netdev_alloc_skb_ip_align(netdev
, BE_HDR_LEN
);
995 if (unlikely(!skb
)) {
997 dev_warn(&adapter
->pdev
->dev
, "skb alloc failed\n");
998 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1002 skb_fill_rx_data(adapter
, rxo
, skb
, rxcp
);
1004 if (likely((netdev
->features
& NETIF_F_RXCSUM
) && csum_passed(rxcp
)))
1005 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1007 skb_checksum_none_assert(skb
);
1009 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1010 skb
->protocol
= eth_type_trans(skb
, netdev
);
1011 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1012 skb
->rxhash
= rxcp
->rss_hash
;
1015 if (unlikely(rxcp
->vlanf
)) {
1016 if (!adapter
->vlan_grp
|| adapter
->vlans_added
== 0) {
1020 vlan_hwaccel_receive_skb(skb
, adapter
->vlan_grp
, rxcp
->vid
);
1022 netif_receive_skb(skb
);
1026 /* Process the RX completion indicated by rxcp when GRO is enabled */
1027 static void be_rx_compl_process_gro(struct be_adapter
*adapter
,
1028 struct be_rx_obj
*rxo
,
1029 struct be_rx_compl_info
*rxcp
)
1031 struct be_rx_page_info
*page_info
;
1032 struct sk_buff
*skb
= NULL
;
1033 struct be_queue_info
*rxq
= &rxo
->q
;
1034 struct be_eq_obj
*eq_obj
= &rxo
->rx_eq
;
1035 u16 remaining
, curr_frag_len
;
1038 skb
= napi_get_frags(&eq_obj
->napi
);
1040 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1044 remaining
= rxcp
->pkt_size
;
1045 for (i
= 0, j
= -1; i
< rxcp
->num_rcvd
; i
++) {
1046 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
1048 curr_frag_len
= min(remaining
, rx_frag_size
);
1050 /* Coalesce all frags from the same physical page in one slot */
1051 if (i
== 0 || page_info
->page_offset
== 0) {
1052 /* First frag or Fresh page */
1054 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
1055 skb_shinfo(skb
)->frags
[j
].page_offset
=
1056 page_info
->page_offset
;
1057 skb_shinfo(skb
)->frags
[j
].size
= 0;
1059 put_page(page_info
->page
);
1061 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
1063 remaining
-= curr_frag_len
;
1064 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
1065 memset(page_info
, 0, sizeof(*page_info
));
1067 BUG_ON(j
> MAX_SKB_FRAGS
);
1069 skb_shinfo(skb
)->nr_frags
= j
+ 1;
1070 skb
->len
= rxcp
->pkt_size
;
1071 skb
->data_len
= rxcp
->pkt_size
;
1072 skb
->truesize
+= rxcp
->pkt_size
;
1073 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1074 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1075 skb
->rxhash
= rxcp
->rss_hash
;
1077 if (likely(!rxcp
->vlanf
))
1078 napi_gro_frags(&eq_obj
->napi
);
1080 vlan_gro_frags(&eq_obj
->napi
, adapter
->vlan_grp
, rxcp
->vid
);
1083 static void be_parse_rx_compl_v1(struct be_adapter
*adapter
,
1084 struct be_eth_rx_compl
*compl,
1085 struct be_rx_compl_info
*rxcp
)
1088 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, pktsize
, compl);
1089 rxcp
->vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vtp
, compl);
1090 rxcp
->err
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, err
, compl);
1091 rxcp
->tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, tcpf
, compl);
1092 rxcp
->udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, udpf
, compl);
1094 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, ipcksm
, compl);
1096 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, l4_cksm
, compl);
1098 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, ip_version
, compl);
1100 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, fragndx
, compl);
1102 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, numfrags
, compl);
1104 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, cast_enc
, compl);
1106 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, rsshash
, rxcp
);
1108 rxcp
->vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vtm
,
1110 rxcp
->vid
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vlan_tag
,
1115 static void be_parse_rx_compl_v0(struct be_adapter
*adapter
,
1116 struct be_eth_rx_compl
*compl,
1117 struct be_rx_compl_info
*rxcp
)
1120 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, pktsize
, compl);
1121 rxcp
->vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vtp
, compl);
1122 rxcp
->err
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, err
, compl);
1123 rxcp
->tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, tcpf
, compl);
1124 rxcp
->udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, udpf
, compl);
1126 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, ipcksm
, compl);
1128 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, l4_cksm
, compl);
1130 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, ip_version
, compl);
1132 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, fragndx
, compl);
1134 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, numfrags
, compl);
1136 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, cast_enc
, compl);
1138 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, rsshash
, rxcp
);
1140 rxcp
->vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vtm
,
1142 rxcp
->vid
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vlan_tag
,
1147 static struct be_rx_compl_info
*be_rx_compl_get(struct be_rx_obj
*rxo
)
1149 struct be_eth_rx_compl
*compl = queue_tail_node(&rxo
->cq
);
1150 struct be_rx_compl_info
*rxcp
= &rxo
->rxcp
;
1151 struct be_adapter
*adapter
= rxo
->adapter
;
1153 /* For checking the valid bit it is Ok to use either definition as the
1154 * valid bit is at the same position in both v0 and v1 Rx compl */
1155 if (compl->dw
[offsetof(struct amap_eth_rx_compl_v1
, valid
) / 32] == 0)
1159 be_dws_le_to_cpu(compl, sizeof(*compl));
1161 if (adapter
->be3_native
)
1162 be_parse_rx_compl_v1(adapter
, compl, rxcp
);
1164 be_parse_rx_compl_v0(adapter
, compl, rxcp
);
1167 /* vlanf could be wrongly set in some cards.
1168 * ignore if vtm is not set */
1169 if ((adapter
->function_mode
& 0x400) && !rxcp
->vtm
)
1172 if (!lancer_chip(adapter
))
1173 rxcp
->vid
= swab16(rxcp
->vid
);
1175 if ((adapter
->pvid
== rxcp
->vid
) &&
1176 !adapter
->vlan_tag
[rxcp
->vid
])
1180 /* As the compl has been parsed, reset it; we wont touch it again */
1181 compl->dw
[offsetof(struct amap_eth_rx_compl_v1
, valid
) / 32] = 0;
1183 queue_tail_inc(&rxo
->cq
);
1187 static inline struct page
*be_alloc_pages(u32 size
, gfp_t gfp
)
1189 u32 order
= get_order(size
);
1193 return alloc_pages(gfp
, order
);
1197 * Allocate a page, split it to fragments of size rx_frag_size and post as
1198 * receive buffers to BE
1200 static void be_post_rx_frags(struct be_rx_obj
*rxo
, gfp_t gfp
)
1202 struct be_adapter
*adapter
= rxo
->adapter
;
1203 struct be_rx_page_info
*page_info_tbl
= rxo
->page_info_tbl
;
1204 struct be_rx_page_info
*page_info
= NULL
, *prev_page_info
= NULL
;
1205 struct be_queue_info
*rxq
= &rxo
->q
;
1206 struct page
*pagep
= NULL
;
1207 struct be_eth_rx_d
*rxd
;
1208 u64 page_dmaaddr
= 0, frag_dmaaddr
;
1209 u32 posted
, page_offset
= 0;
1211 page_info
= &rxo
->page_info_tbl
[rxq
->head
];
1212 for (posted
= 0; posted
< MAX_RX_POST
&& !page_info
->page
; posted
++) {
1214 pagep
= be_alloc_pages(adapter
->big_page_size
, gfp
);
1215 if (unlikely(!pagep
)) {
1216 rxo
->stats
.rx_post_fail
++;
1219 page_dmaaddr
= dma_map_page(&adapter
->pdev
->dev
, pagep
,
1220 0, adapter
->big_page_size
,
1222 page_info
->page_offset
= 0;
1225 page_info
->page_offset
= page_offset
+ rx_frag_size
;
1227 page_offset
= page_info
->page_offset
;
1228 page_info
->page
= pagep
;
1229 dma_unmap_addr_set(page_info
, bus
, page_dmaaddr
);
1230 frag_dmaaddr
= page_dmaaddr
+ page_info
->page_offset
;
1232 rxd
= queue_head_node(rxq
);
1233 rxd
->fragpa_lo
= cpu_to_le32(frag_dmaaddr
& 0xFFFFFFFF);
1234 rxd
->fragpa_hi
= cpu_to_le32(upper_32_bits(frag_dmaaddr
));
1236 /* Any space left in the current big page for another frag? */
1237 if ((page_offset
+ rx_frag_size
+ rx_frag_size
) >
1238 adapter
->big_page_size
) {
1240 page_info
->last_page_user
= true;
1243 prev_page_info
= page_info
;
1244 queue_head_inc(rxq
);
1245 page_info
= &page_info_tbl
[rxq
->head
];
1248 prev_page_info
->last_page_user
= true;
1251 atomic_add(posted
, &rxq
->used
);
1252 be_rxq_notify(adapter
, rxq
->id
, posted
);
1253 } else if (atomic_read(&rxq
->used
) == 0) {
1254 /* Let be_worker replenish when memory is available */
1255 rxo
->rx_post_starved
= true;
1259 static struct be_eth_tx_compl
*be_tx_compl_get(struct be_queue_info
*tx_cq
)
1261 struct be_eth_tx_compl
*txcp
= queue_tail_node(tx_cq
);
1263 if (txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] == 0)
1267 be_dws_le_to_cpu(txcp
, sizeof(*txcp
));
1269 txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] = 0;
1271 queue_tail_inc(tx_cq
);
1275 static void be_tx_compl_process(struct be_adapter
*adapter
, u16 last_index
)
1277 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1278 struct be_eth_wrb
*wrb
;
1279 struct sk_buff
**sent_skbs
= adapter
->tx_obj
.sent_skb_list
;
1280 struct sk_buff
*sent_skb
;
1281 u16 cur_index
, num_wrbs
= 1; /* account for hdr wrb */
1282 bool unmap_skb_hdr
= true;
1284 sent_skb
= sent_skbs
[txq
->tail
];
1286 sent_skbs
[txq
->tail
] = NULL
;
1288 /* skip header wrb */
1289 queue_tail_inc(txq
);
1292 cur_index
= txq
->tail
;
1293 wrb
= queue_tail_node(txq
);
1294 unmap_tx_frag(&adapter
->pdev
->dev
, wrb
,
1295 (unmap_skb_hdr
&& skb_headlen(sent_skb
)));
1296 unmap_skb_hdr
= false;
1299 queue_tail_inc(txq
);
1300 } while (cur_index
!= last_index
);
1302 atomic_sub(num_wrbs
, &txq
->used
);
1304 kfree_skb(sent_skb
);
1307 static inline struct be_eq_entry
*event_get(struct be_eq_obj
*eq_obj
)
1309 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1315 eqe
->evt
= le32_to_cpu(eqe
->evt
);
1316 queue_tail_inc(&eq_obj
->q
);
1320 static int event_handle(struct be_adapter
*adapter
,
1321 struct be_eq_obj
*eq_obj
)
1323 struct be_eq_entry
*eqe
;
1326 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1331 /* Deal with any spurious interrupts that come
1334 be_eq_notify(adapter
, eq_obj
->q
.id
, true, true, num
);
1336 napi_schedule(&eq_obj
->napi
);
1341 /* Just read and notify events without processing them.
1342 * Used at the time of destroying event queues */
1343 static void be_eq_clean(struct be_adapter
*adapter
,
1344 struct be_eq_obj
*eq_obj
)
1346 struct be_eq_entry
*eqe
;
1349 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1355 be_eq_notify(adapter
, eq_obj
->q
.id
, false, true, num
);
1358 static void be_rx_q_clean(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
)
1360 struct be_rx_page_info
*page_info
;
1361 struct be_queue_info
*rxq
= &rxo
->q
;
1362 struct be_queue_info
*rx_cq
= &rxo
->cq
;
1363 struct be_rx_compl_info
*rxcp
;
1366 /* First cleanup pending rx completions */
1367 while ((rxcp
= be_rx_compl_get(rxo
)) != NULL
) {
1368 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1369 be_cq_notify(adapter
, rx_cq
->id
, false, 1);
1372 /* Then free posted rx buffer that were not used */
1373 tail
= (rxq
->head
+ rxq
->len
- atomic_read(&rxq
->used
)) % rxq
->len
;
1374 for (; atomic_read(&rxq
->used
) > 0; index_inc(&tail
, rxq
->len
)) {
1375 page_info
= get_rx_page_info(adapter
, rxo
, tail
);
1376 put_page(page_info
->page
);
1377 memset(page_info
, 0, sizeof(*page_info
));
1379 BUG_ON(atomic_read(&rxq
->used
));
1382 static void be_tx_compl_clean(struct be_adapter
*adapter
)
1384 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1385 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1386 struct be_eth_tx_compl
*txcp
;
1387 u16 end_idx
, cmpl
= 0, timeo
= 0;
1388 struct sk_buff
**sent_skbs
= adapter
->tx_obj
.sent_skb_list
;
1389 struct sk_buff
*sent_skb
;
1392 /* Wait for a max of 200ms for all the tx-completions to arrive. */
1394 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1395 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1397 be_tx_compl_process(adapter
, end_idx
);
1401 be_cq_notify(adapter
, tx_cq
->id
, false, cmpl
);
1405 if (atomic_read(&txq
->used
) == 0 || ++timeo
> 200)
1411 if (atomic_read(&txq
->used
))
1412 dev_err(&adapter
->pdev
->dev
, "%d pending tx-completions\n",
1413 atomic_read(&txq
->used
));
1415 /* free posted tx for which compls will never arrive */
1416 while (atomic_read(&txq
->used
)) {
1417 sent_skb
= sent_skbs
[txq
->tail
];
1418 end_idx
= txq
->tail
;
1420 wrb_cnt_for_skb(adapter
, sent_skb
, &dummy_wrb
) - 1,
1422 be_tx_compl_process(adapter
, end_idx
);
1426 static void be_mcc_queues_destroy(struct be_adapter
*adapter
)
1428 struct be_queue_info
*q
;
1430 q
= &adapter
->mcc_obj
.q
;
1432 be_cmd_q_destroy(adapter
, q
, QTYPE_MCCQ
);
1433 be_queue_free(adapter
, q
);
1435 q
= &adapter
->mcc_obj
.cq
;
1437 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1438 be_queue_free(adapter
, q
);
1441 /* Must be called only after TX qs are created as MCC shares TX EQ */
1442 static int be_mcc_queues_create(struct be_adapter
*adapter
)
1444 struct be_queue_info
*q
, *cq
;
1446 /* Alloc MCC compl queue */
1447 cq
= &adapter
->mcc_obj
.cq
;
1448 if (be_queue_alloc(adapter
, cq
, MCC_CQ_LEN
,
1449 sizeof(struct be_mcc_compl
)))
1452 /* Ask BE to create MCC compl queue; share TX's eq */
1453 if (be_cmd_cq_create(adapter
, cq
, &adapter
->tx_eq
.q
, false, true, 0))
1456 /* Alloc MCC queue */
1457 q
= &adapter
->mcc_obj
.q
;
1458 if (be_queue_alloc(adapter
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
1459 goto mcc_cq_destroy
;
1461 /* Ask BE to create MCC queue */
1462 if (be_cmd_mccq_create(adapter
, q
, cq
))
1468 be_queue_free(adapter
, q
);
1470 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1472 be_queue_free(adapter
, cq
);
1477 static void be_tx_queues_destroy(struct be_adapter
*adapter
)
1479 struct be_queue_info
*q
;
1481 q
= &adapter
->tx_obj
.q
;
1483 be_cmd_q_destroy(adapter
, q
, QTYPE_TXQ
);
1484 be_queue_free(adapter
, q
);
1486 q
= &adapter
->tx_obj
.cq
;
1488 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1489 be_queue_free(adapter
, q
);
1491 /* Clear any residual events */
1492 be_eq_clean(adapter
, &adapter
->tx_eq
);
1494 q
= &adapter
->tx_eq
.q
;
1496 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1497 be_queue_free(adapter
, q
);
1500 static int be_tx_queues_create(struct be_adapter
*adapter
)
1502 struct be_queue_info
*eq
, *q
, *cq
;
1504 adapter
->tx_eq
.max_eqd
= 0;
1505 adapter
->tx_eq
.min_eqd
= 0;
1506 adapter
->tx_eq
.cur_eqd
= 96;
1507 adapter
->tx_eq
.enable_aic
= false;
1508 /* Alloc Tx Event queue */
1509 eq
= &adapter
->tx_eq
.q
;
1510 if (be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
, sizeof(struct be_eq_entry
)))
1513 /* Ask BE to create Tx Event queue */
1514 if (be_cmd_eq_create(adapter
, eq
, adapter
->tx_eq
.cur_eqd
))
1517 adapter
->tx_eq
.eq_idx
= adapter
->eq_next_idx
++;
1520 /* Alloc TX eth compl queue */
1521 cq
= &adapter
->tx_obj
.cq
;
1522 if (be_queue_alloc(adapter
, cq
, TX_CQ_LEN
,
1523 sizeof(struct be_eth_tx_compl
)))
1526 /* Ask BE to create Tx eth compl queue */
1527 if (be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3))
1530 /* Alloc TX eth queue */
1531 q
= &adapter
->tx_obj
.q
;
1532 if (be_queue_alloc(adapter
, q
, TX_Q_LEN
, sizeof(struct be_eth_wrb
)))
1535 /* Ask BE to create Tx eth queue */
1536 if (be_cmd_txq_create(adapter
, q
, cq
))
1541 be_queue_free(adapter
, q
);
1543 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1545 be_queue_free(adapter
, cq
);
1547 be_cmd_q_destroy(adapter
, eq
, QTYPE_EQ
);
1549 be_queue_free(adapter
, eq
);
1553 static void be_rx_queues_destroy(struct be_adapter
*adapter
)
1555 struct be_queue_info
*q
;
1556 struct be_rx_obj
*rxo
;
1559 for_all_rx_queues(adapter
, rxo
, i
) {
1562 be_cmd_q_destroy(adapter
, q
, QTYPE_RXQ
);
1563 /* After the rxq is invalidated, wait for a grace time
1564 * of 1ms for all dma to end and the flush compl to
1568 be_rx_q_clean(adapter
, rxo
);
1570 be_queue_free(adapter
, q
);
1574 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1575 be_queue_free(adapter
, q
);
1577 /* Clear any residual events */
1580 be_eq_clean(adapter
, &rxo
->rx_eq
);
1581 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1583 be_queue_free(adapter
, q
);
1587 static u32
be_num_rxqs_want(struct be_adapter
*adapter
)
1589 if (multi_rxq
&& (adapter
->function_caps
& BE_FUNCTION_CAPS_RSS
) &&
1590 !adapter
->sriov_enabled
&& !(adapter
->function_mode
& 0x400)) {
1591 return 1 + MAX_RSS_QS
; /* one default non-RSS queue */
1593 dev_warn(&adapter
->pdev
->dev
,
1594 "No support for multiple RX queues\n");
1599 static int be_rx_queues_create(struct be_adapter
*adapter
)
1601 struct be_queue_info
*eq
, *q
, *cq
;
1602 struct be_rx_obj
*rxo
;
1605 adapter
->num_rx_qs
= min(be_num_rxqs_want(adapter
),
1606 msix_enabled(adapter
) ?
1607 adapter
->num_msix_vec
- 1 : 1);
1608 if (adapter
->num_rx_qs
!= MAX_RX_QS
)
1609 dev_warn(&adapter
->pdev
->dev
,
1610 "Can create only %d RX queues", adapter
->num_rx_qs
);
1612 adapter
->big_page_size
= (1 << get_order(rx_frag_size
)) * PAGE_SIZE
;
1613 for_all_rx_queues(adapter
, rxo
, i
) {
1614 rxo
->adapter
= adapter
;
1615 rxo
->rx_eq
.max_eqd
= BE_MAX_EQD
;
1616 rxo
->rx_eq
.enable_aic
= true;
1620 rc
= be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
,
1621 sizeof(struct be_eq_entry
));
1625 rc
= be_cmd_eq_create(adapter
, eq
, rxo
->rx_eq
.cur_eqd
);
1629 rxo
->rx_eq
.eq_idx
= adapter
->eq_next_idx
++;
1633 rc
= be_queue_alloc(adapter
, cq
, RX_CQ_LEN
,
1634 sizeof(struct be_eth_rx_compl
));
1638 rc
= be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3);
1643 rc
= be_queue_alloc(adapter
, q
, RX_Q_LEN
,
1644 sizeof(struct be_eth_rx_d
));
1648 rc
= be_cmd_rxq_create(adapter
, q
, cq
->id
, rx_frag_size
,
1649 BE_MAX_JUMBO_FRAME_SIZE
, adapter
->if_handle
,
1650 (i
> 0) ? 1 : 0/* rss enable */, &rxo
->rss_id
);
1655 if (be_multi_rxq(adapter
)) {
1656 u8 rsstable
[MAX_RSS_QS
];
1658 for_all_rss_queues(adapter
, rxo
, i
)
1659 rsstable
[i
] = rxo
->rss_id
;
1661 rc
= be_cmd_rss_config(adapter
, rsstable
,
1662 adapter
->num_rx_qs
- 1);
1669 be_rx_queues_destroy(adapter
);
1673 static bool event_peek(struct be_eq_obj
*eq_obj
)
1675 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1682 static irqreturn_t
be_intx(int irq
, void *dev
)
1684 struct be_adapter
*adapter
= dev
;
1685 struct be_rx_obj
*rxo
;
1686 int isr
, i
, tx
= 0 , rx
= 0;
1688 if (lancer_chip(adapter
)) {
1689 if (event_peek(&adapter
->tx_eq
))
1690 tx
= event_handle(adapter
, &adapter
->tx_eq
);
1691 for_all_rx_queues(adapter
, rxo
, i
) {
1692 if (event_peek(&rxo
->rx_eq
))
1693 rx
|= event_handle(adapter
, &rxo
->rx_eq
);
1700 isr
= ioread32(adapter
->csr
+ CEV_ISR0_OFFSET
+
1701 (adapter
->tx_eq
.q
.id
/ 8) * CEV_ISR_SIZE
);
1705 if ((1 << adapter
->tx_eq
.eq_idx
& isr
))
1706 event_handle(adapter
, &adapter
->tx_eq
);
1708 for_all_rx_queues(adapter
, rxo
, i
) {
1709 if ((1 << rxo
->rx_eq
.eq_idx
& isr
))
1710 event_handle(adapter
, &rxo
->rx_eq
);
1717 static irqreturn_t
be_msix_rx(int irq
, void *dev
)
1719 struct be_rx_obj
*rxo
= dev
;
1720 struct be_adapter
*adapter
= rxo
->adapter
;
1722 event_handle(adapter
, &rxo
->rx_eq
);
1727 static irqreturn_t
be_msix_tx_mcc(int irq
, void *dev
)
1729 struct be_adapter
*adapter
= dev
;
1731 event_handle(adapter
, &adapter
->tx_eq
);
1736 static inline bool do_gro(struct be_rx_compl_info
*rxcp
)
1738 return (rxcp
->tcpf
&& !rxcp
->err
) ? true : false;
1741 static int be_poll_rx(struct napi_struct
*napi
, int budget
)
1743 struct be_eq_obj
*rx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1744 struct be_rx_obj
*rxo
= container_of(rx_eq
, struct be_rx_obj
, rx_eq
);
1745 struct be_adapter
*adapter
= rxo
->adapter
;
1746 struct be_queue_info
*rx_cq
= &rxo
->cq
;
1747 struct be_rx_compl_info
*rxcp
;
1750 rxo
->stats
.rx_polls
++;
1751 for (work_done
= 0; work_done
< budget
; work_done
++) {
1752 rxcp
= be_rx_compl_get(rxo
);
1756 /* Ignore flush completions */
1757 if (rxcp
->num_rcvd
) {
1759 be_rx_compl_process_gro(adapter
, rxo
, rxcp
);
1761 be_rx_compl_process(adapter
, rxo
, rxcp
);
1763 be_rx_stats_update(rxo
, rxcp
);
1766 /* Refill the queue */
1767 if (atomic_read(&rxo
->q
.used
) < RX_FRAGS_REFILL_WM
)
1768 be_post_rx_frags(rxo
, GFP_ATOMIC
);
1771 if (work_done
< budget
) {
1772 napi_complete(napi
);
1773 be_cq_notify(adapter
, rx_cq
->id
, true, work_done
);
1775 /* More to be consumed; continue with interrupts disabled */
1776 be_cq_notify(adapter
, rx_cq
->id
, false, work_done
);
1781 /* As TX and MCC share the same EQ check for both TX and MCC completions.
1782 * For TX/MCC we don't honour budget; consume everything
1784 static int be_poll_tx_mcc(struct napi_struct
*napi
, int budget
)
1786 struct be_eq_obj
*tx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1787 struct be_adapter
*adapter
=
1788 container_of(tx_eq
, struct be_adapter
, tx_eq
);
1789 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1790 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1791 struct be_eth_tx_compl
*txcp
;
1792 int tx_compl
= 0, mcc_compl
, status
= 0;
1795 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1796 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1798 be_tx_compl_process(adapter
, end_idx
);
1802 mcc_compl
= be_process_mcc(adapter
, &status
);
1804 napi_complete(napi
);
1807 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
1808 be_cq_notify(adapter
, mcc_obj
->cq
.id
, true, mcc_compl
);
1812 be_cq_notify(adapter
, adapter
->tx_obj
.cq
.id
, true, tx_compl
);
1814 /* As Tx wrbs have been freed up, wake up netdev queue if
1815 * it was stopped due to lack of tx wrbs.
1817 if (netif_queue_stopped(adapter
->netdev
) &&
1818 atomic_read(&txq
->used
) < txq
->len
/ 2) {
1819 netif_wake_queue(adapter
->netdev
);
1822 tx_stats(adapter
)->be_tx_events
++;
1823 tx_stats(adapter
)->be_tx_compl
+= tx_compl
;
1829 void be_detect_dump_ue(struct be_adapter
*adapter
)
1831 u32 ue_status_lo
, ue_status_hi
, ue_status_lo_mask
, ue_status_hi_mask
;
1834 pci_read_config_dword(adapter
->pdev
,
1835 PCICFG_UE_STATUS_LOW
, &ue_status_lo
);
1836 pci_read_config_dword(adapter
->pdev
,
1837 PCICFG_UE_STATUS_HIGH
, &ue_status_hi
);
1838 pci_read_config_dword(adapter
->pdev
,
1839 PCICFG_UE_STATUS_LOW_MASK
, &ue_status_lo_mask
);
1840 pci_read_config_dword(adapter
->pdev
,
1841 PCICFG_UE_STATUS_HI_MASK
, &ue_status_hi_mask
);
1843 ue_status_lo
= (ue_status_lo
& (~ue_status_lo_mask
));
1844 ue_status_hi
= (ue_status_hi
& (~ue_status_hi_mask
));
1846 if (ue_status_lo
|| ue_status_hi
) {
1847 adapter
->ue_detected
= true;
1848 adapter
->eeh_err
= true;
1849 dev_err(&adapter
->pdev
->dev
, "UE Detected!!\n");
1853 for (i
= 0; ue_status_lo
; ue_status_lo
>>= 1, i
++) {
1854 if (ue_status_lo
& 1)
1855 dev_err(&adapter
->pdev
->dev
,
1856 "UE: %s bit set\n", ue_status_low_desc
[i
]);
1860 for (i
= 0; ue_status_hi
; ue_status_hi
>>= 1, i
++) {
1861 if (ue_status_hi
& 1)
1862 dev_err(&adapter
->pdev
->dev
,
1863 "UE: %s bit set\n", ue_status_hi_desc
[i
]);
1869 static void be_worker(struct work_struct
*work
)
1871 struct be_adapter
*adapter
=
1872 container_of(work
, struct be_adapter
, work
.work
);
1873 struct be_rx_obj
*rxo
;
1876 if (!adapter
->ue_detected
&& !lancer_chip(adapter
))
1877 be_detect_dump_ue(adapter
);
1879 /* when interrupts are not yet enabled, just reap any pending
1880 * mcc completions */
1881 if (!netif_running(adapter
->netdev
)) {
1882 int mcc_compl
, status
= 0;
1884 mcc_compl
= be_process_mcc(adapter
, &status
);
1887 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
1888 be_cq_notify(adapter
, mcc_obj
->cq
.id
, false, mcc_compl
);
1894 if (!adapter
->stats_cmd_sent
)
1895 be_cmd_get_stats(adapter
, &adapter
->stats_cmd
);
1897 be_tx_rate_update(adapter
);
1899 for_all_rx_queues(adapter
, rxo
, i
) {
1900 be_rx_rate_update(rxo
);
1901 be_rx_eqd_update(adapter
, rxo
);
1903 if (rxo
->rx_post_starved
) {
1904 rxo
->rx_post_starved
= false;
1905 be_post_rx_frags(rxo
, GFP_KERNEL
);
1910 adapter
->work_counter
++;
1911 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(1000));
1914 static void be_msix_disable(struct be_adapter
*adapter
)
1916 if (msix_enabled(adapter
)) {
1917 pci_disable_msix(adapter
->pdev
);
1918 adapter
->num_msix_vec
= 0;
1922 static void be_msix_enable(struct be_adapter
*adapter
)
1924 #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */
1925 int i
, status
, num_vec
;
1927 num_vec
= be_num_rxqs_want(adapter
) + 1;
1929 for (i
= 0; i
< num_vec
; i
++)
1930 adapter
->msix_entries
[i
].entry
= i
;
1932 status
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
, num_vec
);
1935 } else if (status
>= BE_MIN_MSIX_VECTORS
) {
1937 if (pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1943 adapter
->num_msix_vec
= num_vec
;
1947 static void be_sriov_enable(struct be_adapter
*adapter
)
1949 be_check_sriov_fn_type(adapter
);
1950 #ifdef CONFIG_PCI_IOV
1951 if (be_physfn(adapter
) && num_vfs
) {
1955 pos
= pci_find_ext_capability(adapter
->pdev
,
1956 PCI_EXT_CAP_ID_SRIOV
);
1957 pci_read_config_word(adapter
->pdev
,
1958 pos
+ PCI_SRIOV_TOTAL_VF
, &nvfs
);
1960 if (num_vfs
> nvfs
) {
1961 dev_info(&adapter
->pdev
->dev
,
1962 "Device supports %d VFs and not %d\n",
1967 status
= pci_enable_sriov(adapter
->pdev
, num_vfs
);
1968 adapter
->sriov_enabled
= status
? false : true;
1973 static void be_sriov_disable(struct be_adapter
*adapter
)
1975 #ifdef CONFIG_PCI_IOV
1976 if (adapter
->sriov_enabled
) {
1977 pci_disable_sriov(adapter
->pdev
);
1978 adapter
->sriov_enabled
= false;
1983 static inline int be_msix_vec_get(struct be_adapter
*adapter
,
1984 struct be_eq_obj
*eq_obj
)
1986 return adapter
->msix_entries
[eq_obj
->eq_idx
].vector
;
1989 static int be_request_irq(struct be_adapter
*adapter
,
1990 struct be_eq_obj
*eq_obj
,
1991 void *handler
, char *desc
, void *context
)
1993 struct net_device
*netdev
= adapter
->netdev
;
1996 sprintf(eq_obj
->desc
, "%s-%s", netdev
->name
, desc
);
1997 vec
= be_msix_vec_get(adapter
, eq_obj
);
1998 return request_irq(vec
, handler
, 0, eq_obj
->desc
, context
);
2001 static void be_free_irq(struct be_adapter
*adapter
, struct be_eq_obj
*eq_obj
,
2004 int vec
= be_msix_vec_get(adapter
, eq_obj
);
2005 free_irq(vec
, context
);
2008 static int be_msix_register(struct be_adapter
*adapter
)
2010 struct be_rx_obj
*rxo
;
2014 status
= be_request_irq(adapter
, &adapter
->tx_eq
, be_msix_tx_mcc
, "tx",
2019 for_all_rx_queues(adapter
, rxo
, i
) {
2020 sprintf(qname
, "rxq%d", i
);
2021 status
= be_request_irq(adapter
, &rxo
->rx_eq
, be_msix_rx
,
2030 be_free_irq(adapter
, &adapter
->tx_eq
, adapter
);
2032 for (i
--, rxo
= &adapter
->rx_obj
[i
]; i
>= 0; i
--, rxo
--)
2033 be_free_irq(adapter
, &rxo
->rx_eq
, rxo
);
2036 dev_warn(&adapter
->pdev
->dev
,
2037 "MSIX Request IRQ failed - err %d\n", status
);
2038 be_msix_disable(adapter
);
2042 static int be_irq_register(struct be_adapter
*adapter
)
2044 struct net_device
*netdev
= adapter
->netdev
;
2047 if (msix_enabled(adapter
)) {
2048 status
= be_msix_register(adapter
);
2051 /* INTx is not supported for VF */
2052 if (!be_physfn(adapter
))
2057 netdev
->irq
= adapter
->pdev
->irq
;
2058 status
= request_irq(netdev
->irq
, be_intx
, IRQF_SHARED
, netdev
->name
,
2061 dev_err(&adapter
->pdev
->dev
,
2062 "INTx request IRQ failed - err %d\n", status
);
2066 adapter
->isr_registered
= true;
2070 static void be_irq_unregister(struct be_adapter
*adapter
)
2072 struct net_device
*netdev
= adapter
->netdev
;
2073 struct be_rx_obj
*rxo
;
2076 if (!adapter
->isr_registered
)
2080 if (!msix_enabled(adapter
)) {
2081 free_irq(netdev
->irq
, adapter
);
2086 be_free_irq(adapter
, &adapter
->tx_eq
, adapter
);
2088 for_all_rx_queues(adapter
, rxo
, i
)
2089 be_free_irq(adapter
, &rxo
->rx_eq
, rxo
);
2092 adapter
->isr_registered
= false;
2095 static int be_close(struct net_device
*netdev
)
2097 struct be_adapter
*adapter
= netdev_priv(netdev
);
2098 struct be_rx_obj
*rxo
;
2099 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
2102 be_async_mcc_disable(adapter
);
2104 netif_carrier_off(netdev
);
2105 adapter
->link_up
= false;
2107 if (!lancer_chip(adapter
))
2108 be_intr_set(adapter
, false);
2110 for_all_rx_queues(adapter
, rxo
, i
)
2111 napi_disable(&rxo
->rx_eq
.napi
);
2113 napi_disable(&tx_eq
->napi
);
2115 if (lancer_chip(adapter
)) {
2116 be_cq_notify(adapter
, adapter
->tx_obj
.cq
.id
, false, 0);
2117 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, false, 0);
2118 for_all_rx_queues(adapter
, rxo
, i
)
2119 be_cq_notify(adapter
, rxo
->cq
.id
, false, 0);
2122 if (msix_enabled(adapter
)) {
2123 vec
= be_msix_vec_get(adapter
, tx_eq
);
2124 synchronize_irq(vec
);
2126 for_all_rx_queues(adapter
, rxo
, i
) {
2127 vec
= be_msix_vec_get(adapter
, &rxo
->rx_eq
);
2128 synchronize_irq(vec
);
2131 synchronize_irq(netdev
->irq
);
2133 be_irq_unregister(adapter
);
2135 /* Wait for all pending tx completions to arrive so that
2136 * all tx skbs are freed.
2138 be_tx_compl_clean(adapter
);
2143 static int be_open(struct net_device
*netdev
)
2145 struct be_adapter
*adapter
= netdev_priv(netdev
);
2146 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
2147 struct be_rx_obj
*rxo
;
2153 for_all_rx_queues(adapter
, rxo
, i
) {
2154 be_post_rx_frags(rxo
, GFP_KERNEL
);
2155 napi_enable(&rxo
->rx_eq
.napi
);
2157 napi_enable(&tx_eq
->napi
);
2159 be_irq_register(adapter
);
2161 if (!lancer_chip(adapter
))
2162 be_intr_set(adapter
, true);
2164 /* The evt queues are created in unarmed state; arm them */
2165 for_all_rx_queues(adapter
, rxo
, i
) {
2166 be_eq_notify(adapter
, rxo
->rx_eq
.q
.id
, true, false, 0);
2167 be_cq_notify(adapter
, rxo
->cq
.id
, true, 0);
2169 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
2171 /* Now that interrupts are on we can process async mcc */
2172 be_async_mcc_enable(adapter
);
2174 status
= be_cmd_link_status_query(adapter
, &link_up
, &mac_speed
,
2178 be_link_status_update(adapter
, link_up
);
2180 if (be_physfn(adapter
)) {
2181 status
= be_vid_config(adapter
, false, 0);
2185 status
= be_cmd_set_flow_control(adapter
,
2186 adapter
->tx_fc
, adapter
->rx_fc
);
2193 be_close(adapter
->netdev
);
2197 static int be_setup_wol(struct be_adapter
*adapter
, bool enable
)
2199 struct be_dma_mem cmd
;
2203 memset(mac
, 0, ETH_ALEN
);
2205 cmd
.size
= sizeof(struct be_cmd_req_acpi_wol_magic_config
);
2206 cmd
.va
= dma_alloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
2210 memset(cmd
.va
, 0, cmd
.size
);
2213 status
= pci_write_config_dword(adapter
->pdev
,
2214 PCICFG_PM_CONTROL_OFFSET
, PCICFG_PM_CONTROL_MASK
);
2216 dev_err(&adapter
->pdev
->dev
,
2217 "Could not enable Wake-on-lan\n");
2218 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
2222 status
= be_cmd_enable_magic_wol(adapter
,
2223 adapter
->netdev
->dev_addr
, &cmd
);
2224 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 1);
2225 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 1);
2227 status
= be_cmd_enable_magic_wol(adapter
, mac
, &cmd
);
2228 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 0);
2229 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 0);
2232 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
, cmd
.dma
);
2237 * Generate a seed MAC address from the PF MAC Address using jhash.
2238 * MAC Address for VFs are assigned incrementally starting from the seed.
2239 * These addresses are programmed in the ASIC by the PF and the VF driver
2240 * queries for the MAC address during its probe.
2242 static inline int be_vf_eth_addr_config(struct be_adapter
*adapter
)
2248 be_vf_eth_addr_generate(adapter
, mac
);
2250 for (vf
= 0; vf
< num_vfs
; vf
++) {
2251 status
= be_cmd_pmac_add(adapter
, mac
,
2252 adapter
->vf_cfg
[vf
].vf_if_handle
,
2253 &adapter
->vf_cfg
[vf
].vf_pmac_id
,
2256 dev_err(&adapter
->pdev
->dev
,
2257 "Mac address add failed for VF %d\n", vf
);
2259 memcpy(adapter
->vf_cfg
[vf
].vf_mac_addr
, mac
, ETH_ALEN
);
2266 static inline void be_vf_eth_addr_rem(struct be_adapter
*adapter
)
2270 for (vf
= 0; vf
< num_vfs
; vf
++) {
2271 if (adapter
->vf_cfg
[vf
].vf_pmac_id
!= BE_INVALID_PMAC_ID
)
2272 be_cmd_pmac_del(adapter
,
2273 adapter
->vf_cfg
[vf
].vf_if_handle
,
2274 adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
2278 static int be_setup(struct be_adapter
*adapter
)
2280 struct net_device
*netdev
= adapter
->netdev
;
2281 u32 cap_flags
, en_flags
, vf
= 0;
2285 cap_flags
= en_flags
= BE_IF_FLAGS_UNTAGGED
|
2286 BE_IF_FLAGS_BROADCAST
|
2287 BE_IF_FLAGS_MULTICAST
;
2289 if (be_physfn(adapter
)) {
2290 cap_flags
|= BE_IF_FLAGS_MCAST_PROMISCUOUS
|
2291 BE_IF_FLAGS_PROMISCUOUS
|
2292 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
2293 en_flags
|= BE_IF_FLAGS_PASS_L3L4_ERRORS
;
2295 if (adapter
->function_caps
& BE_FUNCTION_CAPS_RSS
) {
2296 cap_flags
|= BE_IF_FLAGS_RSS
;
2297 en_flags
|= BE_IF_FLAGS_RSS
;
2301 status
= be_cmd_if_create(adapter
, cap_flags
, en_flags
,
2302 netdev
->dev_addr
, false/* pmac_invalid */,
2303 &adapter
->if_handle
, &adapter
->pmac_id
, 0);
2307 if (be_physfn(adapter
)) {
2308 if (adapter
->sriov_enabled
) {
2309 while (vf
< num_vfs
) {
2310 cap_flags
= en_flags
= BE_IF_FLAGS_UNTAGGED
|
2311 BE_IF_FLAGS_BROADCAST
;
2312 status
= be_cmd_if_create(adapter
, cap_flags
,
2313 en_flags
, mac
, true,
2314 &adapter
->vf_cfg
[vf
].vf_if_handle
,
2317 dev_err(&adapter
->pdev
->dev
,
2318 "Interface Create failed for VF %d\n",
2322 adapter
->vf_cfg
[vf
].vf_pmac_id
=
2328 status
= be_cmd_mac_addr_query(adapter
, mac
,
2329 MAC_ADDRESS_TYPE_NETWORK
, false, adapter
->if_handle
);
2331 memcpy(adapter
->netdev
->dev_addr
, mac
, ETH_ALEN
);
2332 memcpy(adapter
->netdev
->perm_addr
, mac
, ETH_ALEN
);
2336 status
= be_tx_queues_create(adapter
);
2340 status
= be_rx_queues_create(adapter
);
2344 status
= be_mcc_queues_create(adapter
);
2348 adapter
->link_speed
= -1;
2353 be_rx_queues_destroy(adapter
);
2355 be_tx_queues_destroy(adapter
);
2357 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2358 for (vf
= 0; vf
< num_vfs
; vf
++)
2359 if (adapter
->vf_cfg
[vf
].vf_if_handle
)
2360 be_cmd_if_destroy(adapter
,
2361 adapter
->vf_cfg
[vf
].vf_if_handle
,
2363 be_cmd_if_destroy(adapter
, adapter
->if_handle
, 0);
2368 static int be_clear(struct be_adapter
*adapter
)
2372 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2373 be_vf_eth_addr_rem(adapter
);
2375 be_mcc_queues_destroy(adapter
);
2376 be_rx_queues_destroy(adapter
);
2377 be_tx_queues_destroy(adapter
);
2378 adapter
->eq_next_idx
= 0;
2380 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2381 for (vf
= 0; vf
< num_vfs
; vf
++)
2382 if (adapter
->vf_cfg
[vf
].vf_if_handle
)
2383 be_cmd_if_destroy(adapter
,
2384 adapter
->vf_cfg
[vf
].vf_if_handle
,
2387 be_cmd_if_destroy(adapter
, adapter
->if_handle
, 0);
2389 /* tell fw we're done with firing cmds */
2390 be_cmd_fw_clean(adapter
);
2395 #define FW_FILE_HDR_SIGN "ServerEngines Corp. "
2396 static bool be_flash_redboot(struct be_adapter
*adapter
,
2397 const u8
*p
, u32 img_start
, int image_size
,
2404 crc_offset
= hdr_size
+ img_start
+ image_size
- 4;
2408 status
= be_cmd_get_flash_crc(adapter
, flashed_crc
,
2411 dev_err(&adapter
->pdev
->dev
,
2412 "could not get crc from flash, not flashing redboot\n");
2416 /*update redboot only if crc does not match*/
2417 if (!memcmp(flashed_crc
, p
, 4))
2423 static int be_flash_data(struct be_adapter
*adapter
,
2424 const struct firmware
*fw
,
2425 struct be_dma_mem
*flash_cmd
, int num_of_images
)
2428 int status
= 0, i
, filehdr_size
= 0;
2429 u32 total_bytes
= 0, flash_op
;
2431 const u8
*p
= fw
->data
;
2432 struct be_cmd_write_flashrom
*req
= flash_cmd
->va
;
2433 const struct flash_comp
*pflashcomp
;
2436 static const struct flash_comp gen3_flash_types
[9] = {
2437 { FLASH_iSCSI_PRIMARY_IMAGE_START_g3
, IMG_TYPE_ISCSI_ACTIVE
,
2438 FLASH_IMAGE_MAX_SIZE_g3
},
2439 { FLASH_REDBOOT_START_g3
, IMG_TYPE_REDBOOT
,
2440 FLASH_REDBOOT_IMAGE_MAX_SIZE_g3
},
2441 { FLASH_iSCSI_BIOS_START_g3
, IMG_TYPE_BIOS
,
2442 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2443 { FLASH_PXE_BIOS_START_g3
, IMG_TYPE_PXE_BIOS
,
2444 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2445 { FLASH_FCoE_BIOS_START_g3
, IMG_TYPE_FCOE_BIOS
,
2446 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2447 { FLASH_iSCSI_BACKUP_IMAGE_START_g3
, IMG_TYPE_ISCSI_BACKUP
,
2448 FLASH_IMAGE_MAX_SIZE_g3
},
2449 { FLASH_FCoE_PRIMARY_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_ACTIVE
,
2450 FLASH_IMAGE_MAX_SIZE_g3
},
2451 { FLASH_FCoE_BACKUP_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_BACKUP
,
2452 FLASH_IMAGE_MAX_SIZE_g3
},
2453 { FLASH_NCSI_START_g3
, IMG_TYPE_NCSI_FW
,
2454 FLASH_NCSI_IMAGE_MAX_SIZE_g3
}
2456 static const struct flash_comp gen2_flash_types
[8] = {
2457 { FLASH_iSCSI_PRIMARY_IMAGE_START_g2
, IMG_TYPE_ISCSI_ACTIVE
,
2458 FLASH_IMAGE_MAX_SIZE_g2
},
2459 { FLASH_REDBOOT_START_g2
, IMG_TYPE_REDBOOT
,
2460 FLASH_REDBOOT_IMAGE_MAX_SIZE_g2
},
2461 { FLASH_iSCSI_BIOS_START_g2
, IMG_TYPE_BIOS
,
2462 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2463 { FLASH_PXE_BIOS_START_g2
, IMG_TYPE_PXE_BIOS
,
2464 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2465 { FLASH_FCoE_BIOS_START_g2
, IMG_TYPE_FCOE_BIOS
,
2466 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2467 { FLASH_iSCSI_BACKUP_IMAGE_START_g2
, IMG_TYPE_ISCSI_BACKUP
,
2468 FLASH_IMAGE_MAX_SIZE_g2
},
2469 { FLASH_FCoE_PRIMARY_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_ACTIVE
,
2470 FLASH_IMAGE_MAX_SIZE_g2
},
2471 { FLASH_FCoE_BACKUP_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_BACKUP
,
2472 FLASH_IMAGE_MAX_SIZE_g2
}
2475 if (adapter
->generation
== BE_GEN3
) {
2476 pflashcomp
= gen3_flash_types
;
2477 filehdr_size
= sizeof(struct flash_file_hdr_g3
);
2478 num_comp
= ARRAY_SIZE(gen3_flash_types
);
2480 pflashcomp
= gen2_flash_types
;
2481 filehdr_size
= sizeof(struct flash_file_hdr_g2
);
2482 num_comp
= ARRAY_SIZE(gen2_flash_types
);
2484 for (i
= 0; i
< num_comp
; i
++) {
2485 if ((pflashcomp
[i
].optype
== IMG_TYPE_NCSI_FW
) &&
2486 memcmp(adapter
->fw_ver
, "3.102.148.0", 11) < 0)
2488 if ((pflashcomp
[i
].optype
== IMG_TYPE_REDBOOT
) &&
2489 (!be_flash_redboot(adapter
, fw
->data
,
2490 pflashcomp
[i
].offset
, pflashcomp
[i
].size
, filehdr_size
+
2491 (num_of_images
* sizeof(struct image_hdr
)))))
2494 p
+= filehdr_size
+ pflashcomp
[i
].offset
2495 + (num_of_images
* sizeof(struct image_hdr
));
2496 if (p
+ pflashcomp
[i
].size
> fw
->data
+ fw
->size
)
2498 total_bytes
= pflashcomp
[i
].size
;
2499 while (total_bytes
) {
2500 if (total_bytes
> 32*1024)
2501 num_bytes
= 32*1024;
2503 num_bytes
= total_bytes
;
2504 total_bytes
-= num_bytes
;
2507 flash_op
= FLASHROM_OPER_FLASH
;
2509 flash_op
= FLASHROM_OPER_SAVE
;
2510 memcpy(req
->params
.data_buf
, p
, num_bytes
);
2512 status
= be_cmd_write_flashrom(adapter
, flash_cmd
,
2513 pflashcomp
[i
].optype
, flash_op
, num_bytes
);
2515 dev_err(&adapter
->pdev
->dev
,
2516 "cmd to write to flash rom failed.\n");
2525 static int get_ufigen_type(struct flash_file_hdr_g2
*fhdr
)
2529 if (fhdr
->build
[0] == '3')
2531 else if (fhdr
->build
[0] == '2')
2537 int be_load_fw(struct be_adapter
*adapter
, u8
*func
)
2539 char fw_file
[ETHTOOL_FLASH_MAX_FILENAME
];
2540 const struct firmware
*fw
;
2541 struct flash_file_hdr_g2
*fhdr
;
2542 struct flash_file_hdr_g3
*fhdr3
;
2543 struct image_hdr
*img_hdr_ptr
= NULL
;
2544 struct be_dma_mem flash_cmd
;
2545 int status
, i
= 0, num_imgs
= 0;
2548 if (!netif_running(adapter
->netdev
)) {
2549 dev_err(&adapter
->pdev
->dev
,
2550 "Firmware load not allowed (interface is down)\n");
2554 strcpy(fw_file
, func
);
2556 status
= request_firmware(&fw
, fw_file
, &adapter
->pdev
->dev
);
2561 fhdr
= (struct flash_file_hdr_g2
*) p
;
2562 dev_info(&adapter
->pdev
->dev
, "Flashing firmware file %s\n", fw_file
);
2564 flash_cmd
.size
= sizeof(struct be_cmd_write_flashrom
) + 32*1024;
2565 flash_cmd
.va
= dma_alloc_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
,
2566 &flash_cmd
.dma
, GFP_KERNEL
);
2567 if (!flash_cmd
.va
) {
2569 dev_err(&adapter
->pdev
->dev
,
2570 "Memory allocation failure while flashing\n");
2574 if ((adapter
->generation
== BE_GEN3
) &&
2575 (get_ufigen_type(fhdr
) == BE_GEN3
)) {
2576 fhdr3
= (struct flash_file_hdr_g3
*) fw
->data
;
2577 num_imgs
= le32_to_cpu(fhdr3
->num_imgs
);
2578 for (i
= 0; i
< num_imgs
; i
++) {
2579 img_hdr_ptr
= (struct image_hdr
*) (fw
->data
+
2580 (sizeof(struct flash_file_hdr_g3
) +
2581 i
* sizeof(struct image_hdr
)));
2582 if (le32_to_cpu(img_hdr_ptr
->imageid
) == 1)
2583 status
= be_flash_data(adapter
, fw
, &flash_cmd
,
2586 } else if ((adapter
->generation
== BE_GEN2
) &&
2587 (get_ufigen_type(fhdr
) == BE_GEN2
)) {
2588 status
= be_flash_data(adapter
, fw
, &flash_cmd
, 0);
2590 dev_err(&adapter
->pdev
->dev
,
2591 "UFI and Interface are not compatible for flashing\n");
2595 dma_free_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
, flash_cmd
.va
,
2598 dev_err(&adapter
->pdev
->dev
, "Firmware load error\n");
2602 dev_info(&adapter
->pdev
->dev
, "Firmware flashed successfully\n");
2605 release_firmware(fw
);
2609 static struct net_device_ops be_netdev_ops
= {
2610 .ndo_open
= be_open
,
2611 .ndo_stop
= be_close
,
2612 .ndo_start_xmit
= be_xmit
,
2613 .ndo_set_rx_mode
= be_set_multicast_list
,
2614 .ndo_set_mac_address
= be_mac_addr_set
,
2615 .ndo_change_mtu
= be_change_mtu
,
2616 .ndo_validate_addr
= eth_validate_addr
,
2617 .ndo_vlan_rx_register
= be_vlan_register
,
2618 .ndo_vlan_rx_add_vid
= be_vlan_add_vid
,
2619 .ndo_vlan_rx_kill_vid
= be_vlan_rem_vid
,
2620 .ndo_set_vf_mac
= be_set_vf_mac
,
2621 .ndo_set_vf_vlan
= be_set_vf_vlan
,
2622 .ndo_set_vf_tx_rate
= be_set_vf_tx_rate
,
2623 .ndo_get_vf_config
= be_get_vf_config
2626 static void be_netdev_init(struct net_device
*netdev
)
2628 struct be_adapter
*adapter
= netdev_priv(netdev
);
2629 struct be_rx_obj
*rxo
;
2632 netdev
->hw_features
|= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_TSO6
|
2633 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
|
2635 if (be_multi_rxq(adapter
))
2636 netdev
->hw_features
|= NETIF_F_RXHASH
;
2638 netdev
->features
|= netdev
->hw_features
|
2639 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
2641 netdev
->vlan_features
|= NETIF_F_SG
| NETIF_F_TSO
|
2642 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
2644 if (lancer_chip(adapter
))
2645 netdev
->vlan_features
|= NETIF_F_TSO6
;
2647 netdev
->flags
|= IFF_MULTICAST
;
2649 /* Default settings for Rx and Tx flow control */
2650 adapter
->rx_fc
= true;
2651 adapter
->tx_fc
= true;
2653 netif_set_gso_max_size(netdev
, 65535);
2655 BE_SET_NETDEV_OPS(netdev
, &be_netdev_ops
);
2657 SET_ETHTOOL_OPS(netdev
, &be_ethtool_ops
);
2659 for_all_rx_queues(adapter
, rxo
, i
)
2660 netif_napi_add(netdev
, &rxo
->rx_eq
.napi
, be_poll_rx
,
2663 netif_napi_add(netdev
, &adapter
->tx_eq
.napi
, be_poll_tx_mcc
,
2667 static void be_unmap_pci_bars(struct be_adapter
*adapter
)
2670 iounmap(adapter
->csr
);
2672 iounmap(adapter
->db
);
2673 if (adapter
->pcicfg
&& be_physfn(adapter
))
2674 iounmap(adapter
->pcicfg
);
2677 static int be_map_pci_bars(struct be_adapter
*adapter
)
2680 int pcicfg_reg
, db_reg
;
2682 if (lancer_chip(adapter
)) {
2683 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 0),
2684 pci_resource_len(adapter
->pdev
, 0));
2691 if (be_physfn(adapter
)) {
2692 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 2),
2693 pci_resource_len(adapter
->pdev
, 2));
2696 adapter
->csr
= addr
;
2699 if (adapter
->generation
== BE_GEN2
) {
2704 if (be_physfn(adapter
))
2709 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, db_reg
),
2710 pci_resource_len(adapter
->pdev
, db_reg
));
2715 if (be_physfn(adapter
)) {
2716 addr
= ioremap_nocache(
2717 pci_resource_start(adapter
->pdev
, pcicfg_reg
),
2718 pci_resource_len(adapter
->pdev
, pcicfg_reg
));
2721 adapter
->pcicfg
= addr
;
2723 adapter
->pcicfg
= adapter
->db
+ SRIOV_VF_PCICFG_OFFSET
;
2727 be_unmap_pci_bars(adapter
);
2732 static void be_ctrl_cleanup(struct be_adapter
*adapter
)
2734 struct be_dma_mem
*mem
= &adapter
->mbox_mem_alloced
;
2736 be_unmap_pci_bars(adapter
);
2739 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
2742 mem
= &adapter
->mc_cmd_mem
;
2744 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
2748 static int be_ctrl_init(struct be_adapter
*adapter
)
2750 struct be_dma_mem
*mbox_mem_alloc
= &adapter
->mbox_mem_alloced
;
2751 struct be_dma_mem
*mbox_mem_align
= &adapter
->mbox_mem
;
2752 struct be_dma_mem
*mc_cmd_mem
= &adapter
->mc_cmd_mem
;
2755 status
= be_map_pci_bars(adapter
);
2759 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
2760 mbox_mem_alloc
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2761 mbox_mem_alloc
->size
,
2762 &mbox_mem_alloc
->dma
,
2764 if (!mbox_mem_alloc
->va
) {
2766 goto unmap_pci_bars
;
2769 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
2770 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
2771 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
2772 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
2774 mc_cmd_mem
->size
= sizeof(struct be_cmd_req_mcast_mac_config
);
2775 mc_cmd_mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2776 mc_cmd_mem
->size
, &mc_cmd_mem
->dma
,
2778 if (mc_cmd_mem
->va
== NULL
) {
2782 memset(mc_cmd_mem
->va
, 0, mc_cmd_mem
->size
);
2784 mutex_init(&adapter
->mbox_lock
);
2785 spin_lock_init(&adapter
->mcc_lock
);
2786 spin_lock_init(&adapter
->mcc_cq_lock
);
2788 init_completion(&adapter
->flash_compl
);
2789 pci_save_state(adapter
->pdev
);
2793 dma_free_coherent(&adapter
->pdev
->dev
, mbox_mem_alloc
->size
,
2794 mbox_mem_alloc
->va
, mbox_mem_alloc
->dma
);
2797 be_unmap_pci_bars(adapter
);
2803 static void be_stats_cleanup(struct be_adapter
*adapter
)
2805 struct be_dma_mem
*cmd
= &adapter
->stats_cmd
;
2808 dma_free_coherent(&adapter
->pdev
->dev
, cmd
->size
,
2812 static int be_stats_init(struct be_adapter
*adapter
)
2814 struct be_dma_mem
*cmd
= &adapter
->stats_cmd
;
2816 cmd
->size
= sizeof(struct be_cmd_req_get_stats
);
2817 cmd
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, cmd
->size
, &cmd
->dma
,
2819 if (cmd
->va
== NULL
)
2821 memset(cmd
->va
, 0, cmd
->size
);
2825 static void __devexit
be_remove(struct pci_dev
*pdev
)
2827 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2832 cancel_delayed_work_sync(&adapter
->work
);
2834 unregister_netdev(adapter
->netdev
);
2838 be_stats_cleanup(adapter
);
2840 be_ctrl_cleanup(adapter
);
2842 kfree(adapter
->vf_cfg
);
2843 be_sriov_disable(adapter
);
2845 be_msix_disable(adapter
);
2847 pci_set_drvdata(pdev
, NULL
);
2848 pci_release_regions(pdev
);
2849 pci_disable_device(pdev
);
2851 free_netdev(adapter
->netdev
);
2854 static int be_get_config(struct be_adapter
*adapter
)
2859 status
= be_cmd_get_fw_ver(adapter
, adapter
->fw_ver
);
2863 status
= be_cmd_query_fw_cfg(adapter
, &adapter
->port_num
,
2864 &adapter
->function_mode
, &adapter
->function_caps
);
2868 memset(mac
, 0, ETH_ALEN
);
2870 if (be_physfn(adapter
)) {
2871 status
= be_cmd_mac_addr_query(adapter
, mac
,
2872 MAC_ADDRESS_TYPE_NETWORK
, true /*permanent */, 0);
2877 if (!is_valid_ether_addr(mac
))
2878 return -EADDRNOTAVAIL
;
2880 memcpy(adapter
->netdev
->dev_addr
, mac
, ETH_ALEN
);
2881 memcpy(adapter
->netdev
->perm_addr
, mac
, ETH_ALEN
);
2884 if (adapter
->function_mode
& 0x400)
2885 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
/4;
2887 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
;
2889 status
= be_cmd_get_cntl_attributes(adapter
);
2893 be_cmd_check_native_mode(adapter
);
2897 static int be_dev_family_check(struct be_adapter
*adapter
)
2899 struct pci_dev
*pdev
= adapter
->pdev
;
2900 u32 sli_intf
= 0, if_type
;
2902 switch (pdev
->device
) {
2905 adapter
->generation
= BE_GEN2
;
2909 adapter
->generation
= BE_GEN3
;
2912 pci_read_config_dword(pdev
, SLI_INTF_REG_OFFSET
, &sli_intf
);
2913 if_type
= (sli_intf
& SLI_INTF_IF_TYPE_MASK
) >>
2914 SLI_INTF_IF_TYPE_SHIFT
;
2916 if (((sli_intf
& SLI_INTF_VALID_MASK
) != SLI_INTF_VALID
) ||
2918 dev_err(&pdev
->dev
, "SLI_INTF reg val is not valid\n");
2922 dev_err(&pdev
->dev
, "VFs not supported\n");
2925 adapter
->sli_family
= ((sli_intf
& SLI_INTF_FAMILY_MASK
) >>
2926 SLI_INTF_FAMILY_SHIFT
);
2927 adapter
->generation
= BE_GEN3
;
2930 adapter
->generation
= 0;
2935 static int lancer_wait_ready(struct be_adapter
*adapter
)
2937 #define SLIPORT_READY_TIMEOUT 500
2941 for (i
= 0; i
< SLIPORT_READY_TIMEOUT
; i
++) {
2942 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
2943 if (sliport_status
& SLIPORT_STATUS_RDY_MASK
)
2949 if (i
== SLIPORT_READY_TIMEOUT
)
2955 static int lancer_test_and_set_rdy_state(struct be_adapter
*adapter
)
2958 u32 sliport_status
, err
, reset_needed
;
2959 status
= lancer_wait_ready(adapter
);
2961 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
2962 err
= sliport_status
& SLIPORT_STATUS_ERR_MASK
;
2963 reset_needed
= sliport_status
& SLIPORT_STATUS_RN_MASK
;
2964 if (err
&& reset_needed
) {
2965 iowrite32(SLI_PORT_CONTROL_IP_MASK
,
2966 adapter
->db
+ SLIPORT_CONTROL_OFFSET
);
2968 /* check adapter has corrected the error */
2969 status
= lancer_wait_ready(adapter
);
2970 sliport_status
= ioread32(adapter
->db
+
2971 SLIPORT_STATUS_OFFSET
);
2972 sliport_status
&= (SLIPORT_STATUS_ERR_MASK
|
2973 SLIPORT_STATUS_RN_MASK
);
2974 if (status
|| sliport_status
)
2976 } else if (err
|| reset_needed
) {
2983 static int __devinit
be_probe(struct pci_dev
*pdev
,
2984 const struct pci_device_id
*pdev_id
)
2987 struct be_adapter
*adapter
;
2988 struct net_device
*netdev
;
2990 status
= pci_enable_device(pdev
);
2994 status
= pci_request_regions(pdev
, DRV_NAME
);
2997 pci_set_master(pdev
);
2999 netdev
= alloc_etherdev(sizeof(struct be_adapter
));
3000 if (netdev
== NULL
) {
3004 adapter
= netdev_priv(netdev
);
3005 adapter
->pdev
= pdev
;
3006 pci_set_drvdata(pdev
, adapter
);
3008 status
= be_dev_family_check(adapter
);
3012 adapter
->netdev
= netdev
;
3013 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3015 status
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64));
3017 netdev
->features
|= NETIF_F_HIGHDMA
;
3019 status
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3021 dev_err(&pdev
->dev
, "Could not set PCI DMA Mask\n");
3026 be_sriov_enable(adapter
);
3027 if (adapter
->sriov_enabled
) {
3028 adapter
->vf_cfg
= kcalloc(num_vfs
,
3029 sizeof(struct be_vf_cfg
), GFP_KERNEL
);
3031 if (!adapter
->vf_cfg
)
3035 status
= be_ctrl_init(adapter
);
3039 if (lancer_chip(adapter
)) {
3040 status
= lancer_test_and_set_rdy_state(adapter
);
3042 dev_err(&pdev
->dev
, "Adapter in non recoverable error\n");
3047 /* sync up with fw's ready state */
3048 if (be_physfn(adapter
)) {
3049 status
= be_cmd_POST(adapter
);
3054 /* tell fw we're ready to fire cmds */
3055 status
= be_cmd_fw_init(adapter
);
3059 status
= be_cmd_reset_function(adapter
);
3063 status
= be_stats_init(adapter
);
3067 status
= be_get_config(adapter
);
3071 be_msix_enable(adapter
);
3073 INIT_DELAYED_WORK(&adapter
->work
, be_worker
);
3075 status
= be_setup(adapter
);
3079 be_netdev_init(netdev
);
3080 status
= register_netdev(netdev
);
3083 netif_carrier_off(netdev
);
3085 if (be_physfn(adapter
) && adapter
->sriov_enabled
) {
3090 status
= be_vf_eth_addr_config(adapter
);
3094 for (vf
= 0; vf
< num_vfs
; vf
++) {
3095 status
= be_cmd_link_status_query(adapter
, &link_up
,
3096 &mac_speed
, &lnk_speed
, vf
+ 1);
3098 adapter
->vf_cfg
[vf
].vf_tx_rate
= lnk_speed
* 10;
3104 dev_info(&pdev
->dev
, "%s port %d\n", nic_name(pdev
), adapter
->port_num
);
3105 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
3109 unregister_netdev(netdev
);
3113 be_msix_disable(adapter
);
3115 be_stats_cleanup(adapter
);
3117 be_ctrl_cleanup(adapter
);
3119 kfree(adapter
->vf_cfg
);
3121 be_sriov_disable(adapter
);
3122 free_netdev(netdev
);
3123 pci_set_drvdata(pdev
, NULL
);
3125 pci_release_regions(pdev
);
3127 pci_disable_device(pdev
);
3129 dev_err(&pdev
->dev
, "%s initialization failed\n", nic_name(pdev
));
3133 static int be_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3135 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3136 struct net_device
*netdev
= adapter
->netdev
;
3138 cancel_delayed_work_sync(&adapter
->work
);
3140 be_setup_wol(adapter
, true);
3142 netif_device_detach(netdev
);
3143 if (netif_running(netdev
)) {
3148 be_cmd_get_flow_control(adapter
, &adapter
->tx_fc
, &adapter
->rx_fc
);
3151 be_msix_disable(adapter
);
3152 pci_save_state(pdev
);
3153 pci_disable_device(pdev
);
3154 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
3158 static int be_resume(struct pci_dev
*pdev
)
3161 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3162 struct net_device
*netdev
= adapter
->netdev
;
3164 netif_device_detach(netdev
);
3166 status
= pci_enable_device(pdev
);
3170 pci_set_power_state(pdev
, 0);
3171 pci_restore_state(pdev
);
3173 be_msix_enable(adapter
);
3174 /* tell fw we're ready to fire cmds */
3175 status
= be_cmd_fw_init(adapter
);
3180 if (netif_running(netdev
)) {
3185 netif_device_attach(netdev
);
3188 be_setup_wol(adapter
, false);
3190 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
3195 * An FLR will stop BE from DMAing any data.
3197 static void be_shutdown(struct pci_dev
*pdev
)
3199 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3204 cancel_delayed_work_sync(&adapter
->work
);
3206 netif_device_detach(adapter
->netdev
);
3209 be_setup_wol(adapter
, true);
3211 be_cmd_reset_function(adapter
);
3213 pci_disable_device(pdev
);
3216 static pci_ers_result_t
be_eeh_err_detected(struct pci_dev
*pdev
,
3217 pci_channel_state_t state
)
3219 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3220 struct net_device
*netdev
= adapter
->netdev
;
3222 dev_err(&adapter
->pdev
->dev
, "EEH error detected\n");
3224 adapter
->eeh_err
= true;
3226 netif_device_detach(netdev
);
3228 if (netif_running(netdev
)) {
3235 if (state
== pci_channel_io_perm_failure
)
3236 return PCI_ERS_RESULT_DISCONNECT
;
3238 pci_disable_device(pdev
);
3240 return PCI_ERS_RESULT_NEED_RESET
;
3243 static pci_ers_result_t
be_eeh_reset(struct pci_dev
*pdev
)
3245 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3248 dev_info(&adapter
->pdev
->dev
, "EEH reset\n");
3249 adapter
->eeh_err
= false;
3251 status
= pci_enable_device(pdev
);
3253 return PCI_ERS_RESULT_DISCONNECT
;
3255 pci_set_master(pdev
);
3256 pci_set_power_state(pdev
, 0);
3257 pci_restore_state(pdev
);
3259 /* Check if card is ok and fw is ready */
3260 status
= be_cmd_POST(adapter
);
3262 return PCI_ERS_RESULT_DISCONNECT
;
3264 return PCI_ERS_RESULT_RECOVERED
;
3267 static void be_eeh_resume(struct pci_dev
*pdev
)
3270 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3271 struct net_device
*netdev
= adapter
->netdev
;
3273 dev_info(&adapter
->pdev
->dev
, "EEH resume\n");
3275 pci_save_state(pdev
);
3277 /* tell fw we're ready to fire cmds */
3278 status
= be_cmd_fw_init(adapter
);
3282 status
= be_setup(adapter
);
3286 if (netif_running(netdev
)) {
3287 status
= be_open(netdev
);
3291 netif_device_attach(netdev
);
3294 dev_err(&adapter
->pdev
->dev
, "EEH resume failed\n");
3297 static struct pci_error_handlers be_eeh_handlers
= {
3298 .error_detected
= be_eeh_err_detected
,
3299 .slot_reset
= be_eeh_reset
,
3300 .resume
= be_eeh_resume
,
3303 static struct pci_driver be_driver
= {
3305 .id_table
= be_dev_ids
,
3307 .remove
= be_remove
,
3308 .suspend
= be_suspend
,
3309 .resume
= be_resume
,
3310 .shutdown
= be_shutdown
,
3311 .err_handler
= &be_eeh_handlers
3314 static int __init
be_init_module(void)
3316 if (rx_frag_size
!= 8192 && rx_frag_size
!= 4096 &&
3317 rx_frag_size
!= 2048) {
3318 printk(KERN_WARNING DRV_NAME
3319 " : Module param rx_frag_size must be 2048/4096/8192."
3321 rx_frag_size
= 2048;
3324 return pci_register_driver(&be_driver
);
3326 module_init(be_init_module
);
3328 static void __exit
be_exit_module(void)
3330 pci_unregister_driver(&be_driver
);
3332 module_exit(be_exit_module
);