2 * Copyright (C) 2005 - 2010 ServerEngines
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@serverengines.com
14 * 209 N. Fair Oaks Ave
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 unsigned int rx_frag_size
= 2048;
29 module_param(rx_frag_size
, uint
, S_IRUGO
);
30 MODULE_PARM_DESC(rx_frag_size
, "Size of a fragment that holds rcvd data.");
32 static DEFINE_PCI_DEVICE_TABLE(be_dev_ids
) = {
33 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
34 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
35 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
36 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
39 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
41 static void be_queue_free(struct be_adapter
*adapter
, struct be_queue_info
*q
)
43 struct be_dma_mem
*mem
= &q
->dma_mem
;
45 pci_free_consistent(adapter
->pdev
, mem
->size
,
49 static int be_queue_alloc(struct be_adapter
*adapter
, struct be_queue_info
*q
,
50 u16 len
, u16 entry_size
)
52 struct be_dma_mem
*mem
= &q
->dma_mem
;
54 memset(q
, 0, sizeof(*q
));
56 q
->entry_size
= entry_size
;
57 mem
->size
= len
* entry_size
;
58 mem
->va
= pci_alloc_consistent(adapter
->pdev
, mem
->size
, &mem
->dma
);
61 memset(mem
->va
, 0, mem
->size
);
65 static void be_intr_set(struct be_adapter
*adapter
, bool enable
)
67 u8 __iomem
*addr
= adapter
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
68 u32 reg
= ioread32(addr
);
69 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
74 if (!enabled
&& enable
)
75 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
76 else if (enabled
&& !enable
)
77 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
84 static void be_rxq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
87 val
|= qid
& DB_RQ_RING_ID_MASK
;
88 val
|= posted
<< DB_RQ_NUM_POSTED_SHIFT
;
89 iowrite32(val
, adapter
->db
+ DB_RQ_OFFSET
);
92 static void be_txq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
95 val
|= qid
& DB_TXULP_RING_ID_MASK
;
96 val
|= (posted
& DB_TXULP_NUM_POSTED_MASK
) << DB_TXULP_NUM_POSTED_SHIFT
;
97 iowrite32(val
, adapter
->db
+ DB_TXULP1_OFFSET
);
100 static void be_eq_notify(struct be_adapter
*adapter
, u16 qid
,
101 bool arm
, bool clear_int
, u16 num_popped
)
104 val
|= qid
& DB_EQ_RING_ID_MASK
;
106 if (adapter
->eeh_err
)
110 val
|= 1 << DB_EQ_REARM_SHIFT
;
112 val
|= 1 << DB_EQ_CLR_SHIFT
;
113 val
|= 1 << DB_EQ_EVNT_SHIFT
;
114 val
|= num_popped
<< DB_EQ_NUM_POPPED_SHIFT
;
115 iowrite32(val
, adapter
->db
+ DB_EQ_OFFSET
);
118 void be_cq_notify(struct be_adapter
*adapter
, u16 qid
, bool arm
, u16 num_popped
)
121 val
|= qid
& DB_CQ_RING_ID_MASK
;
123 if (adapter
->eeh_err
)
127 val
|= 1 << DB_CQ_REARM_SHIFT
;
128 val
|= num_popped
<< DB_CQ_NUM_POPPED_SHIFT
;
129 iowrite32(val
, adapter
->db
+ DB_CQ_OFFSET
);
132 static int be_mac_addr_set(struct net_device
*netdev
, void *p
)
134 struct be_adapter
*adapter
= netdev_priv(netdev
);
135 struct sockaddr
*addr
= p
;
138 if (!is_valid_ether_addr(addr
->sa_data
))
139 return -EADDRNOTAVAIL
;
141 status
= be_cmd_pmac_del(adapter
, adapter
->if_handle
, adapter
->pmac_id
);
145 status
= be_cmd_pmac_add(adapter
, (u8
*)addr
->sa_data
,
146 adapter
->if_handle
, &adapter
->pmac_id
);
148 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
153 void netdev_stats_update(struct be_adapter
*adapter
)
155 struct be_hw_stats
*hw_stats
= hw_stats_from_cmd(adapter
->stats
.cmd
.va
);
156 struct be_rxf_stats
*rxf_stats
= &hw_stats
->rxf
;
157 struct be_port_rxf_stats
*port_stats
=
158 &rxf_stats
->port
[adapter
->port_num
];
159 struct net_device_stats
*dev_stats
= &adapter
->netdev
->stats
;
160 struct be_erx_stats
*erx_stats
= &hw_stats
->erx
;
162 dev_stats
->rx_packets
= drvr_stats(adapter
)->be_rx_pkts
;
163 dev_stats
->tx_packets
= drvr_stats(adapter
)->be_tx_pkts
;
164 dev_stats
->rx_bytes
= drvr_stats(adapter
)->be_rx_bytes
;
165 dev_stats
->tx_bytes
= drvr_stats(adapter
)->be_tx_bytes
;
167 /* bad pkts received */
168 dev_stats
->rx_errors
= port_stats
->rx_crc_errors
+
169 port_stats
->rx_alignment_symbol_errors
+
170 port_stats
->rx_in_range_errors
+
171 port_stats
->rx_out_range_errors
+
172 port_stats
->rx_frame_too_long
+
173 port_stats
->rx_dropped_too_small
+
174 port_stats
->rx_dropped_too_short
+
175 port_stats
->rx_dropped_header_too_small
+
176 port_stats
->rx_dropped_tcp_length
+
177 port_stats
->rx_dropped_runt
+
178 port_stats
->rx_tcp_checksum_errs
+
179 port_stats
->rx_ip_checksum_errs
+
180 port_stats
->rx_udp_checksum_errs
;
182 /* no space in linux buffers: best possible approximation */
183 dev_stats
->rx_dropped
=
184 erx_stats
->rx_drops_no_fragments
[adapter
->rx_obj
.q
.id
];
186 /* detailed rx errors */
187 dev_stats
->rx_length_errors
= port_stats
->rx_in_range_errors
+
188 port_stats
->rx_out_range_errors
+
189 port_stats
->rx_frame_too_long
;
191 /* receive ring buffer overflow */
192 dev_stats
->rx_over_errors
= 0;
194 dev_stats
->rx_crc_errors
= port_stats
->rx_crc_errors
;
196 /* frame alignment errors */
197 dev_stats
->rx_frame_errors
= port_stats
->rx_alignment_symbol_errors
;
199 /* receiver fifo overrun */
200 /* drops_no_pbuf is no per i/f, it's per BE card */
201 dev_stats
->rx_fifo_errors
= port_stats
->rx_fifo_overflow
+
202 port_stats
->rx_input_fifo_overflow
+
203 rxf_stats
->rx_drops_no_pbuf
;
204 /* receiver missed packetd */
205 dev_stats
->rx_missed_errors
= 0;
207 /* packet transmit problems */
208 dev_stats
->tx_errors
= 0;
210 /* no space available in linux */
211 dev_stats
->tx_dropped
= 0;
213 dev_stats
->multicast
= port_stats
->rx_multicast_frames
;
214 dev_stats
->collisions
= 0;
216 /* detailed tx_errors */
217 dev_stats
->tx_aborted_errors
= 0;
218 dev_stats
->tx_carrier_errors
= 0;
219 dev_stats
->tx_fifo_errors
= 0;
220 dev_stats
->tx_heartbeat_errors
= 0;
221 dev_stats
->tx_window_errors
= 0;
224 void be_link_status_update(struct be_adapter
*adapter
, bool link_up
)
226 struct net_device
*netdev
= adapter
->netdev
;
228 /* If link came up or went down */
229 if (adapter
->link_up
!= link_up
) {
230 adapter
->link_speed
= -1;
232 netif_start_queue(netdev
);
233 netif_carrier_on(netdev
);
234 printk(KERN_INFO
"%s: Link up\n", netdev
->name
);
236 netif_stop_queue(netdev
);
237 netif_carrier_off(netdev
);
238 printk(KERN_INFO
"%s: Link down\n", netdev
->name
);
240 adapter
->link_up
= link_up
;
244 /* Update the EQ delay n BE based on the RX frags consumed / sec */
245 static void be_rx_eqd_update(struct be_adapter
*adapter
)
247 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
248 struct be_drvr_stats
*stats
= &adapter
->stats
.drvr_stats
;
252 if (!rx_eq
->enable_aic
)
256 if (time_before(now
, stats
->rx_fps_jiffies
)) {
257 stats
->rx_fps_jiffies
= now
;
261 /* Update once a second */
262 if ((now
- stats
->rx_fps_jiffies
) < HZ
)
265 stats
->be_rx_fps
= (stats
->be_rx_frags
- stats
->be_prev_rx_frags
) /
266 ((now
- stats
->rx_fps_jiffies
) / HZ
);
268 stats
->rx_fps_jiffies
= now
;
269 stats
->be_prev_rx_frags
= stats
->be_rx_frags
;
270 eqd
= stats
->be_rx_fps
/ 110000;
272 if (eqd
> rx_eq
->max_eqd
)
273 eqd
= rx_eq
->max_eqd
;
274 if (eqd
< rx_eq
->min_eqd
)
275 eqd
= rx_eq
->min_eqd
;
278 if (eqd
!= rx_eq
->cur_eqd
)
279 be_cmd_modify_eqd(adapter
, rx_eq
->q
.id
, eqd
);
281 rx_eq
->cur_eqd
= eqd
;
284 static struct net_device_stats
*be_get_stats(struct net_device
*dev
)
289 static u32
be_calc_rate(u64 bytes
, unsigned long ticks
)
293 do_div(rate
, ticks
/ HZ
);
294 rate
<<= 3; /* bytes/sec -> bits/sec */
295 do_div(rate
, 1000000ul); /* MB/Sec */
300 static void be_tx_rate_update(struct be_adapter
*adapter
)
302 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
305 /* Wrapped around? */
306 if (time_before(now
, stats
->be_tx_jiffies
)) {
307 stats
->be_tx_jiffies
= now
;
311 /* Update tx rate once in two seconds */
312 if ((now
- stats
->be_tx_jiffies
) > 2 * HZ
) {
313 stats
->be_tx_rate
= be_calc_rate(stats
->be_tx_bytes
314 - stats
->be_tx_bytes_prev
,
315 now
- stats
->be_tx_jiffies
);
316 stats
->be_tx_jiffies
= now
;
317 stats
->be_tx_bytes_prev
= stats
->be_tx_bytes
;
321 static void be_tx_stats_update(struct be_adapter
*adapter
,
322 u32 wrb_cnt
, u32 copied
, u32 gso_segs
, bool stopped
)
324 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
326 stats
->be_tx_wrbs
+= wrb_cnt
;
327 stats
->be_tx_bytes
+= copied
;
328 stats
->be_tx_pkts
+= (gso_segs
? gso_segs
: 1);
330 stats
->be_tx_stops
++;
333 /* Determine number of WRB entries needed to xmit data in an skb */
334 static u32
wrb_cnt_for_skb(struct sk_buff
*skb
, bool *dummy
)
336 int cnt
= (skb
->len
> skb
->data_len
);
338 cnt
+= skb_shinfo(skb
)->nr_frags
;
340 /* to account for hdr wrb */
343 /* add a dummy to make it an even num */
348 BUG_ON(cnt
> BE_MAX_TX_FRAG_COUNT
);
352 static inline void wrb_fill(struct be_eth_wrb
*wrb
, u64 addr
, int len
)
354 wrb
->frag_pa_hi
= upper_32_bits(addr
);
355 wrb
->frag_pa_lo
= addr
& 0xFFFFFFFF;
356 wrb
->frag_len
= len
& ETH_WRB_FRAG_LEN_MASK
;
359 static void wrb_fill_hdr(struct be_eth_hdr_wrb
*hdr
, struct sk_buff
*skb
,
360 bool vlan
, u32 wrb_cnt
, u32 len
)
362 memset(hdr
, 0, sizeof(*hdr
));
364 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, crc
, hdr
, 1);
366 if (skb_shinfo(skb
)->gso_segs
> 1 && skb_shinfo(skb
)->gso_size
) {
367 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso
, hdr
, 1);
368 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso_mss
,
369 hdr
, skb_shinfo(skb
)->gso_size
);
370 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
372 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, tcpcs
, hdr
, 1);
373 else if (is_udp_pkt(skb
))
374 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, udpcs
, hdr
, 1);
377 if (vlan
&& vlan_tx_tag_present(skb
)) {
378 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan
, hdr
, 1);
379 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan_tag
,
380 hdr
, vlan_tx_tag_get(skb
));
383 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, event
, hdr
, 1);
384 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, complete
, hdr
, 1);
385 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, num_wrb
, hdr
, wrb_cnt
);
386 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, len
, hdr
, len
);
390 static int make_tx_wrbs(struct be_adapter
*adapter
,
391 struct sk_buff
*skb
, u32 wrb_cnt
, bool dummy_wrb
)
395 struct pci_dev
*pdev
= adapter
->pdev
;
396 struct sk_buff
*first_skb
= skb
;
397 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
398 struct be_eth_wrb
*wrb
;
399 struct be_eth_hdr_wrb
*hdr
;
401 hdr
= queue_head_node(txq
);
402 atomic_add(wrb_cnt
, &txq
->used
);
405 if (skb
->len
> skb
->data_len
) {
406 int len
= skb
->len
- skb
->data_len
;
407 busaddr
= pci_map_single(pdev
, skb
->data
, len
,
409 wrb
= queue_head_node(txq
);
410 wrb_fill(wrb
, busaddr
, len
);
411 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
416 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
417 struct skb_frag_struct
*frag
=
418 &skb_shinfo(skb
)->frags
[i
];
419 busaddr
= pci_map_page(pdev
, frag
->page
,
421 frag
->size
, PCI_DMA_TODEVICE
);
422 wrb
= queue_head_node(txq
);
423 wrb_fill(wrb
, busaddr
, frag
->size
);
424 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
426 copied
+= frag
->size
;
430 wrb
= queue_head_node(txq
);
432 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
436 wrb_fill_hdr(hdr
, first_skb
, adapter
->vlan_grp
? true : false,
438 be_dws_cpu_to_le(hdr
, sizeof(*hdr
));
443 static netdev_tx_t
be_xmit(struct sk_buff
*skb
,
444 struct net_device
*netdev
)
446 struct be_adapter
*adapter
= netdev_priv(netdev
);
447 struct be_tx_obj
*tx_obj
= &adapter
->tx_obj
;
448 struct be_queue_info
*txq
= &tx_obj
->q
;
449 u32 wrb_cnt
= 0, copied
= 0;
450 u32 start
= txq
->head
;
451 bool dummy_wrb
, stopped
= false;
453 wrb_cnt
= wrb_cnt_for_skb(skb
, &dummy_wrb
);
455 copied
= make_tx_wrbs(adapter
, skb
, wrb_cnt
, dummy_wrb
);
457 /* record the sent skb in the sent_skb table */
458 BUG_ON(tx_obj
->sent_skb_list
[start
]);
459 tx_obj
->sent_skb_list
[start
] = skb
;
461 /* Ensure txq has space for the next skb; Else stop the queue
462 * *BEFORE* ringing the tx doorbell, so that we serialze the
463 * tx compls of the current transmit which'll wake up the queue
465 if ((BE_MAX_TX_FRAG_COUNT
+ atomic_read(&txq
->used
)) >=
467 netif_stop_queue(netdev
);
471 be_txq_notify(adapter
, txq
->id
, wrb_cnt
);
473 be_tx_stats_update(adapter
, wrb_cnt
, copied
,
474 skb_shinfo(skb
)->gso_segs
, stopped
);
477 dev_kfree_skb_any(skb
);
482 static int be_change_mtu(struct net_device
*netdev
, int new_mtu
)
484 struct be_adapter
*adapter
= netdev_priv(netdev
);
485 if (new_mtu
< BE_MIN_MTU
||
486 new_mtu
> (BE_MAX_JUMBO_FRAME_SIZE
-
487 (ETH_HLEN
+ ETH_FCS_LEN
))) {
488 dev_info(&adapter
->pdev
->dev
,
489 "MTU must be between %d and %d bytes\n",
491 (BE_MAX_JUMBO_FRAME_SIZE
- (ETH_HLEN
+ ETH_FCS_LEN
)));
494 dev_info(&adapter
->pdev
->dev
, "MTU changed from %d to %d bytes\n",
495 netdev
->mtu
, new_mtu
);
496 netdev
->mtu
= new_mtu
;
501 * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE.
502 * If the user configures more, place BE in vlan promiscuous mode.
504 static int be_vid_config(struct be_adapter
*adapter
)
506 u16 vtag
[BE_NUM_VLANS_SUPPORTED
];
510 if (adapter
->vlans_added
<= adapter
->max_vlans
) {
511 /* Construct VLAN Table to give to HW */
512 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
513 if (adapter
->vlan_tag
[i
]) {
514 vtag
[ntags
] = cpu_to_le16(i
);
518 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
521 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
527 static void be_vlan_register(struct net_device
*netdev
, struct vlan_group
*grp
)
529 struct be_adapter
*adapter
= netdev_priv(netdev
);
530 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
531 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
533 be_eq_notify(adapter
, rx_eq
->q
.id
, false, false, 0);
534 be_eq_notify(adapter
, tx_eq
->q
.id
, false, false, 0);
535 adapter
->vlan_grp
= grp
;
536 be_eq_notify(adapter
, rx_eq
->q
.id
, true, false, 0);
537 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
540 static void be_vlan_add_vid(struct net_device
*netdev
, u16 vid
)
542 struct be_adapter
*adapter
= netdev_priv(netdev
);
544 adapter
->vlan_tag
[vid
] = 1;
545 adapter
->vlans_added
++;
546 if (adapter
->vlans_added
<= (adapter
->max_vlans
+ 1))
547 be_vid_config(adapter
);
550 static void be_vlan_rem_vid(struct net_device
*netdev
, u16 vid
)
552 struct be_adapter
*adapter
= netdev_priv(netdev
);
554 adapter
->vlan_tag
[vid
] = 0;
555 vlan_group_set_device(adapter
->vlan_grp
, vid
, NULL
);
556 adapter
->vlans_added
--;
557 if (adapter
->vlans_added
<= adapter
->max_vlans
)
558 be_vid_config(adapter
);
561 static void be_set_multicast_list(struct net_device
*netdev
)
563 struct be_adapter
*adapter
= netdev_priv(netdev
);
565 if (netdev
->flags
& IFF_PROMISC
) {
566 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 1);
567 adapter
->promiscuous
= true;
571 /* BE was previously in promiscous mode; disable it */
572 if (adapter
->promiscuous
) {
573 adapter
->promiscuous
= false;
574 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 0);
577 /* Enable multicast promisc if num configured exceeds what we support */
578 if (netdev
->flags
& IFF_ALLMULTI
||
579 netdev_mc_count(netdev
) > BE_MAX_MC
) {
580 be_cmd_multicast_set(adapter
, adapter
->if_handle
, NULL
,
581 &adapter
->mc_cmd_mem
);
585 be_cmd_multicast_set(adapter
, adapter
->if_handle
, netdev
,
586 &adapter
->mc_cmd_mem
);
591 static void be_rx_rate_update(struct be_adapter
*adapter
)
593 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
597 if (time_before(now
, stats
->be_rx_jiffies
)) {
598 stats
->be_rx_jiffies
= now
;
602 /* Update the rate once in two seconds */
603 if ((now
- stats
->be_rx_jiffies
) < 2 * HZ
)
606 stats
->be_rx_rate
= be_calc_rate(stats
->be_rx_bytes
607 - stats
->be_rx_bytes_prev
,
608 now
- stats
->be_rx_jiffies
);
609 stats
->be_rx_jiffies
= now
;
610 stats
->be_rx_bytes_prev
= stats
->be_rx_bytes
;
613 static void be_rx_stats_update(struct be_adapter
*adapter
,
614 u32 pktsize
, u16 numfrags
)
616 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
618 stats
->be_rx_compl
++;
619 stats
->be_rx_frags
+= numfrags
;
620 stats
->be_rx_bytes
+= pktsize
;
624 static inline bool do_pkt_csum(struct be_eth_rx_compl
*rxcp
, bool cso
)
626 u8 l4_cksm
, ip_version
, ipcksm
, tcpf
= 0, udpf
= 0, ipv6_chk
;
628 l4_cksm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, l4_cksm
, rxcp
);
629 ipcksm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, ipcksm
, rxcp
);
630 ip_version
= AMAP_GET_BITS(struct amap_eth_rx_compl
, ip_version
, rxcp
);
632 tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, tcpf
, rxcp
);
633 udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, udpf
, rxcp
);
635 ipv6_chk
= (ip_version
&& (tcpf
|| udpf
));
637 return ((l4_cksm
&& ipv6_chk
&& ipcksm
) && cso
) ? false : true;
640 static struct be_rx_page_info
*
641 get_rx_page_info(struct be_adapter
*adapter
, u16 frag_idx
)
643 struct be_rx_page_info
*rx_page_info
;
644 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
646 rx_page_info
= &adapter
->rx_obj
.page_info_tbl
[frag_idx
];
647 BUG_ON(!rx_page_info
->page
);
649 if (rx_page_info
->last_page_user
) {
650 pci_unmap_page(adapter
->pdev
, pci_unmap_addr(rx_page_info
, bus
),
651 adapter
->big_page_size
, PCI_DMA_FROMDEVICE
);
652 rx_page_info
->last_page_user
= false;
655 atomic_dec(&rxq
->used
);
659 /* Throwaway the data in the Rx completion */
660 static void be_rx_compl_discard(struct be_adapter
*adapter
,
661 struct be_eth_rx_compl
*rxcp
)
663 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
664 struct be_rx_page_info
*page_info
;
665 u16 rxq_idx
, i
, num_rcvd
;
667 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
668 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
670 for (i
= 0; i
< num_rcvd
; i
++) {
671 page_info
= get_rx_page_info(adapter
, rxq_idx
);
672 put_page(page_info
->page
);
673 memset(page_info
, 0, sizeof(*page_info
));
674 index_inc(&rxq_idx
, rxq
->len
);
679 * skb_fill_rx_data forms a complete skb for an ether frame
682 static void skb_fill_rx_data(struct be_adapter
*adapter
,
683 struct sk_buff
*skb
, struct be_eth_rx_compl
*rxcp
,
686 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
687 struct be_rx_page_info
*page_info
;
689 u32 pktsize
, hdr_len
, curr_frag_len
, size
;
692 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
693 pktsize
= AMAP_GET_BITS(struct amap_eth_rx_compl
, pktsize
, rxcp
);
695 page_info
= get_rx_page_info(adapter
, rxq_idx
);
697 start
= page_address(page_info
->page
) + page_info
->page_offset
;
700 /* Copy data in the first descriptor of this completion */
701 curr_frag_len
= min(pktsize
, rx_frag_size
);
703 /* Copy the header portion into skb_data */
704 hdr_len
= min((u32
)BE_HDR_LEN
, curr_frag_len
);
705 memcpy(skb
->data
, start
, hdr_len
);
706 skb
->len
= curr_frag_len
;
707 if (curr_frag_len
<= BE_HDR_LEN
) { /* tiny packet */
708 /* Complete packet has now been moved to data */
709 put_page(page_info
->page
);
711 skb
->tail
+= curr_frag_len
;
713 skb_shinfo(skb
)->nr_frags
= 1;
714 skb_shinfo(skb
)->frags
[0].page
= page_info
->page
;
715 skb_shinfo(skb
)->frags
[0].page_offset
=
716 page_info
->page_offset
+ hdr_len
;
717 skb_shinfo(skb
)->frags
[0].size
= curr_frag_len
- hdr_len
;
718 skb
->data_len
= curr_frag_len
- hdr_len
;
719 skb
->tail
+= hdr_len
;
721 page_info
->page
= NULL
;
723 if (pktsize
<= rx_frag_size
) {
724 BUG_ON(num_rcvd
!= 1);
728 /* More frags present for this completion */
730 for (i
= 1, j
= 0; i
< num_rcvd
; i
++) {
731 size
-= curr_frag_len
;
732 index_inc(&rxq_idx
, rxq
->len
);
733 page_info
= get_rx_page_info(adapter
, rxq_idx
);
735 curr_frag_len
= min(size
, rx_frag_size
);
737 /* Coalesce all frags from the same physical page in one slot */
738 if (page_info
->page_offset
== 0) {
741 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
742 skb_shinfo(skb
)->frags
[j
].page_offset
=
743 page_info
->page_offset
;
744 skb_shinfo(skb
)->frags
[j
].size
= 0;
745 skb_shinfo(skb
)->nr_frags
++;
747 put_page(page_info
->page
);
750 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
751 skb
->len
+= curr_frag_len
;
752 skb
->data_len
+= curr_frag_len
;
754 page_info
->page
= NULL
;
756 BUG_ON(j
> MAX_SKB_FRAGS
);
759 be_rx_stats_update(adapter
, pktsize
, num_rcvd
);
763 /* Process the RX completion indicated by rxcp when GRO is disabled */
764 static void be_rx_compl_process(struct be_adapter
*adapter
,
765 struct be_eth_rx_compl
*rxcp
)
772 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
773 /* Is it a flush compl that has no data */
774 if (unlikely(num_rcvd
== 0))
777 skb
= netdev_alloc_skb_ip_align(adapter
->netdev
, BE_HDR_LEN
);
778 if (unlikely(!skb
)) {
780 dev_warn(&adapter
->pdev
->dev
, "skb alloc failed\n");
781 be_rx_compl_discard(adapter
, rxcp
);
785 skb_fill_rx_data(adapter
, skb
, rxcp
, num_rcvd
);
787 if (do_pkt_csum(rxcp
, adapter
->rx_csum
))
788 skb
->ip_summed
= CHECKSUM_NONE
;
790 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
792 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
793 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
794 skb
->dev
= adapter
->netdev
;
796 vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtp
, rxcp
);
797 vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtm
, rxcp
);
799 /* vlanf could be wrongly set in some cards.
800 * ignore if vtm is not set */
801 if ((adapter
->cap
& 0x400) && !vtm
)
804 if (unlikely(vlanf
)) {
805 if (!adapter
->vlan_grp
|| adapter
->vlans_added
== 0) {
809 vid
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vlan_tag
, rxcp
);
811 vlan_hwaccel_receive_skb(skb
, adapter
->vlan_grp
, vid
);
813 netif_receive_skb(skb
);
819 /* Process the RX completion indicated by rxcp when GRO is enabled */
820 static void be_rx_compl_process_gro(struct be_adapter
*adapter
,
821 struct be_eth_rx_compl
*rxcp
)
823 struct be_rx_page_info
*page_info
;
824 struct sk_buff
*skb
= NULL
;
825 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
826 struct be_eq_obj
*eq_obj
= &adapter
->rx_eq
;
827 u32 num_rcvd
, pkt_size
, remaining
, vlanf
, curr_frag_len
;
828 u16 i
, rxq_idx
= 0, vid
, j
;
831 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
832 /* Is it a flush compl that has no data */
833 if (unlikely(num_rcvd
== 0))
836 pkt_size
= AMAP_GET_BITS(struct amap_eth_rx_compl
, pktsize
, rxcp
);
837 vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtp
, rxcp
);
838 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
839 vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtm
, rxcp
);
841 /* vlanf could be wrongly set in some cards.
842 * ignore if vtm is not set */
843 if ((adapter
->cap
& 0x400) && !vtm
)
846 skb
= napi_get_frags(&eq_obj
->napi
);
848 be_rx_compl_discard(adapter
, rxcp
);
852 remaining
= pkt_size
;
853 for (i
= 0, j
= -1; i
< num_rcvd
; i
++) {
854 page_info
= get_rx_page_info(adapter
, rxq_idx
);
856 curr_frag_len
= min(remaining
, rx_frag_size
);
858 /* Coalesce all frags from the same physical page in one slot */
859 if (i
== 0 || page_info
->page_offset
== 0) {
860 /* First frag or Fresh page */
862 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
863 skb_shinfo(skb
)->frags
[j
].page_offset
=
864 page_info
->page_offset
;
865 skb_shinfo(skb
)->frags
[j
].size
= 0;
867 put_page(page_info
->page
);
869 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
871 remaining
-= curr_frag_len
;
872 index_inc(&rxq_idx
, rxq
->len
);
873 memset(page_info
, 0, sizeof(*page_info
));
875 BUG_ON(j
> MAX_SKB_FRAGS
);
877 skb_shinfo(skb
)->nr_frags
= j
+ 1;
879 skb
->data_len
= pkt_size
;
880 skb
->truesize
+= pkt_size
;
881 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
883 if (likely(!vlanf
)) {
884 napi_gro_frags(&eq_obj
->napi
);
886 vid
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vlan_tag
, rxcp
);
889 if (!adapter
->vlan_grp
|| adapter
->vlans_added
== 0)
892 vlan_gro_frags(&eq_obj
->napi
, adapter
->vlan_grp
, vid
);
895 be_rx_stats_update(adapter
, pkt_size
, num_rcvd
);
899 static struct be_eth_rx_compl
*be_rx_compl_get(struct be_adapter
*adapter
)
901 struct be_eth_rx_compl
*rxcp
= queue_tail_node(&adapter
->rx_obj
.cq
);
903 if (rxcp
->dw
[offsetof(struct amap_eth_rx_compl
, valid
) / 32] == 0)
906 be_dws_le_to_cpu(rxcp
, sizeof(*rxcp
));
908 queue_tail_inc(&adapter
->rx_obj
.cq
);
912 /* To reset the valid bit, we need to reset the whole word as
913 * when walking the queue the valid entries are little-endian
914 * and invalid entries are host endian
916 static inline void be_rx_compl_reset(struct be_eth_rx_compl
*rxcp
)
918 rxcp
->dw
[offsetof(struct amap_eth_rx_compl
, valid
) / 32] = 0;
921 static inline struct page
*be_alloc_pages(u32 size
)
923 gfp_t alloc_flags
= GFP_ATOMIC
;
924 u32 order
= get_order(size
);
926 alloc_flags
|= __GFP_COMP
;
927 return alloc_pages(alloc_flags
, order
);
931 * Allocate a page, split it to fragments of size rx_frag_size and post as
932 * receive buffers to BE
934 static void be_post_rx_frags(struct be_adapter
*adapter
)
936 struct be_rx_page_info
*page_info_tbl
= adapter
->rx_obj
.page_info_tbl
;
937 struct be_rx_page_info
*page_info
= NULL
, *prev_page_info
= NULL
;
938 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
939 struct page
*pagep
= NULL
;
940 struct be_eth_rx_d
*rxd
;
941 u64 page_dmaaddr
= 0, frag_dmaaddr
;
942 u32 posted
, page_offset
= 0;
944 page_info
= &page_info_tbl
[rxq
->head
];
945 for (posted
= 0; posted
< MAX_RX_POST
&& !page_info
->page
; posted
++) {
947 pagep
= be_alloc_pages(adapter
->big_page_size
);
948 if (unlikely(!pagep
)) {
949 drvr_stats(adapter
)->be_ethrx_post_fail
++;
952 page_dmaaddr
= pci_map_page(adapter
->pdev
, pagep
, 0,
953 adapter
->big_page_size
,
955 page_info
->page_offset
= 0;
958 page_info
->page_offset
= page_offset
+ rx_frag_size
;
960 page_offset
= page_info
->page_offset
;
961 page_info
->page
= pagep
;
962 pci_unmap_addr_set(page_info
, bus
, page_dmaaddr
);
963 frag_dmaaddr
= page_dmaaddr
+ page_info
->page_offset
;
965 rxd
= queue_head_node(rxq
);
966 rxd
->fragpa_lo
= cpu_to_le32(frag_dmaaddr
& 0xFFFFFFFF);
967 rxd
->fragpa_hi
= cpu_to_le32(upper_32_bits(frag_dmaaddr
));
969 /* Any space left in the current big page for another frag? */
970 if ((page_offset
+ rx_frag_size
+ rx_frag_size
) >
971 adapter
->big_page_size
) {
973 page_info
->last_page_user
= true;
976 prev_page_info
= page_info
;
978 page_info
= &page_info_tbl
[rxq
->head
];
981 prev_page_info
->last_page_user
= true;
984 atomic_add(posted
, &rxq
->used
);
985 be_rxq_notify(adapter
, rxq
->id
, posted
);
986 } else if (atomic_read(&rxq
->used
) == 0) {
987 /* Let be_worker replenish when memory is available */
988 adapter
->rx_post_starved
= true;
994 static struct be_eth_tx_compl
*be_tx_compl_get(struct be_queue_info
*tx_cq
)
996 struct be_eth_tx_compl
*txcp
= queue_tail_node(tx_cq
);
998 if (txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] == 0)
1001 be_dws_le_to_cpu(txcp
, sizeof(*txcp
));
1003 txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] = 0;
1005 queue_tail_inc(tx_cq
);
1009 static void be_tx_compl_process(struct be_adapter
*adapter
, u16 last_index
)
1011 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1012 struct be_eth_wrb
*wrb
;
1013 struct sk_buff
**sent_skbs
= adapter
->tx_obj
.sent_skb_list
;
1014 struct sk_buff
*sent_skb
;
1016 u16 cur_index
, num_wrbs
= 0;
1018 cur_index
= txq
->tail
;
1019 sent_skb
= sent_skbs
[cur_index
];
1021 sent_skbs
[cur_index
] = NULL
;
1022 wrb
= queue_tail_node(txq
);
1023 be_dws_le_to_cpu(wrb
, sizeof(*wrb
));
1024 busaddr
= ((u64
)wrb
->frag_pa_hi
<< 32) | (u64
)wrb
->frag_pa_lo
;
1026 pci_unmap_single(adapter
->pdev
, busaddr
,
1027 wrb
->frag_len
, PCI_DMA_TODEVICE
);
1030 queue_tail_inc(txq
);
1032 while (cur_index
!= last_index
) {
1033 cur_index
= txq
->tail
;
1034 wrb
= queue_tail_node(txq
);
1035 be_dws_le_to_cpu(wrb
, sizeof(*wrb
));
1036 busaddr
= ((u64
)wrb
->frag_pa_hi
<< 32) | (u64
)wrb
->frag_pa_lo
;
1038 pci_unmap_page(adapter
->pdev
, busaddr
,
1039 wrb
->frag_len
, PCI_DMA_TODEVICE
);
1042 queue_tail_inc(txq
);
1045 atomic_sub(num_wrbs
, &txq
->used
);
1047 kfree_skb(sent_skb
);
1050 static inline struct be_eq_entry
*event_get(struct be_eq_obj
*eq_obj
)
1052 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1057 eqe
->evt
= le32_to_cpu(eqe
->evt
);
1058 queue_tail_inc(&eq_obj
->q
);
1062 static int event_handle(struct be_adapter
*adapter
,
1063 struct be_eq_obj
*eq_obj
)
1065 struct be_eq_entry
*eqe
;
1068 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1073 /* Deal with any spurious interrupts that come
1076 be_eq_notify(adapter
, eq_obj
->q
.id
, true, true, num
);
1078 napi_schedule(&eq_obj
->napi
);
1083 /* Just read and notify events without processing them.
1084 * Used at the time of destroying event queues */
1085 static void be_eq_clean(struct be_adapter
*adapter
,
1086 struct be_eq_obj
*eq_obj
)
1088 struct be_eq_entry
*eqe
;
1091 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1097 be_eq_notify(adapter
, eq_obj
->q
.id
, false, true, num
);
1100 static void be_rx_q_clean(struct be_adapter
*adapter
)
1102 struct be_rx_page_info
*page_info
;
1103 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
1104 struct be_queue_info
*rx_cq
= &adapter
->rx_obj
.cq
;
1105 struct be_eth_rx_compl
*rxcp
;
1108 /* First cleanup pending rx completions */
1109 while ((rxcp
= be_rx_compl_get(adapter
)) != NULL
) {
1110 be_rx_compl_discard(adapter
, rxcp
);
1111 be_rx_compl_reset(rxcp
);
1112 be_cq_notify(adapter
, rx_cq
->id
, true, 1);
1115 /* Then free posted rx buffer that were not used */
1116 tail
= (rxq
->head
+ rxq
->len
- atomic_read(&rxq
->used
)) % rxq
->len
;
1117 for (; atomic_read(&rxq
->used
) > 0; index_inc(&tail
, rxq
->len
)) {
1118 page_info
= get_rx_page_info(adapter
, tail
);
1119 put_page(page_info
->page
);
1120 memset(page_info
, 0, sizeof(*page_info
));
1122 BUG_ON(atomic_read(&rxq
->used
));
1125 static void be_tx_compl_clean(struct be_adapter
*adapter
)
1127 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1128 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1129 struct be_eth_tx_compl
*txcp
;
1130 u16 end_idx
, cmpl
= 0, timeo
= 0;
1131 struct sk_buff
**sent_skbs
= adapter
->tx_obj
.sent_skb_list
;
1132 struct sk_buff
*sent_skb
;
1135 /* Wait for a max of 200ms for all the tx-completions to arrive. */
1137 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1138 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1140 be_tx_compl_process(adapter
, end_idx
);
1144 be_cq_notify(adapter
, tx_cq
->id
, false, cmpl
);
1148 if (atomic_read(&txq
->used
) == 0 || ++timeo
> 200)
1154 if (atomic_read(&txq
->used
))
1155 dev_err(&adapter
->pdev
->dev
, "%d pending tx-completions\n",
1156 atomic_read(&txq
->used
));
1158 /* free posted tx for which compls will never arrive */
1159 while (atomic_read(&txq
->used
)) {
1160 sent_skb
= sent_skbs
[txq
->tail
];
1161 end_idx
= txq
->tail
;
1163 wrb_cnt_for_skb(sent_skb
, &dummy_wrb
) - 1, txq
->len
);
1164 be_tx_compl_process(adapter
, end_idx
);
1168 static void be_mcc_queues_destroy(struct be_adapter
*adapter
)
1170 struct be_queue_info
*q
;
1172 q
= &adapter
->mcc_obj
.q
;
1174 be_cmd_q_destroy(adapter
, q
, QTYPE_MCCQ
);
1175 be_queue_free(adapter
, q
);
1177 q
= &adapter
->mcc_obj
.cq
;
1179 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1180 be_queue_free(adapter
, q
);
1183 /* Must be called only after TX qs are created as MCC shares TX EQ */
1184 static int be_mcc_queues_create(struct be_adapter
*adapter
)
1186 struct be_queue_info
*q
, *cq
;
1188 /* Alloc MCC compl queue */
1189 cq
= &adapter
->mcc_obj
.cq
;
1190 if (be_queue_alloc(adapter
, cq
, MCC_CQ_LEN
,
1191 sizeof(struct be_mcc_compl
)))
1194 /* Ask BE to create MCC compl queue; share TX's eq */
1195 if (be_cmd_cq_create(adapter
, cq
, &adapter
->tx_eq
.q
, false, true, 0))
1198 /* Alloc MCC queue */
1199 q
= &adapter
->mcc_obj
.q
;
1200 if (be_queue_alloc(adapter
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
1201 goto mcc_cq_destroy
;
1203 /* Ask BE to create MCC queue */
1204 if (be_cmd_mccq_create(adapter
, q
, cq
))
1210 be_queue_free(adapter
, q
);
1212 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1214 be_queue_free(adapter
, cq
);
1219 static void be_tx_queues_destroy(struct be_adapter
*adapter
)
1221 struct be_queue_info
*q
;
1223 q
= &adapter
->tx_obj
.q
;
1225 be_cmd_q_destroy(adapter
, q
, QTYPE_TXQ
);
1226 be_queue_free(adapter
, q
);
1228 q
= &adapter
->tx_obj
.cq
;
1230 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1231 be_queue_free(adapter
, q
);
1233 /* Clear any residual events */
1234 be_eq_clean(adapter
, &adapter
->tx_eq
);
1236 q
= &adapter
->tx_eq
.q
;
1238 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1239 be_queue_free(adapter
, q
);
1242 static int be_tx_queues_create(struct be_adapter
*adapter
)
1244 struct be_queue_info
*eq
, *q
, *cq
;
1246 adapter
->tx_eq
.max_eqd
= 0;
1247 adapter
->tx_eq
.min_eqd
= 0;
1248 adapter
->tx_eq
.cur_eqd
= 96;
1249 adapter
->tx_eq
.enable_aic
= false;
1250 /* Alloc Tx Event queue */
1251 eq
= &adapter
->tx_eq
.q
;
1252 if (be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
, sizeof(struct be_eq_entry
)))
1255 /* Ask BE to create Tx Event queue */
1256 if (be_cmd_eq_create(adapter
, eq
, adapter
->tx_eq
.cur_eqd
))
1258 /* Alloc TX eth compl queue */
1259 cq
= &adapter
->tx_obj
.cq
;
1260 if (be_queue_alloc(adapter
, cq
, TX_CQ_LEN
,
1261 sizeof(struct be_eth_tx_compl
)))
1264 /* Ask BE to create Tx eth compl queue */
1265 if (be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3))
1268 /* Alloc TX eth queue */
1269 q
= &adapter
->tx_obj
.q
;
1270 if (be_queue_alloc(adapter
, q
, TX_Q_LEN
, sizeof(struct be_eth_wrb
)))
1273 /* Ask BE to create Tx eth queue */
1274 if (be_cmd_txq_create(adapter
, q
, cq
))
1279 be_queue_free(adapter
, q
);
1281 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1283 be_queue_free(adapter
, cq
);
1285 be_cmd_q_destroy(adapter
, eq
, QTYPE_EQ
);
1287 be_queue_free(adapter
, eq
);
1291 static void be_rx_queues_destroy(struct be_adapter
*adapter
)
1293 struct be_queue_info
*q
;
1295 q
= &adapter
->rx_obj
.q
;
1297 be_cmd_q_destroy(adapter
, q
, QTYPE_RXQ
);
1299 /* After the rxq is invalidated, wait for a grace time
1300 * of 1ms for all dma to end and the flush compl to arrive
1303 be_rx_q_clean(adapter
);
1305 be_queue_free(adapter
, q
);
1307 q
= &adapter
->rx_obj
.cq
;
1309 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1310 be_queue_free(adapter
, q
);
1312 /* Clear any residual events */
1313 be_eq_clean(adapter
, &adapter
->rx_eq
);
1315 q
= &adapter
->rx_eq
.q
;
1317 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1318 be_queue_free(adapter
, q
);
1321 static int be_rx_queues_create(struct be_adapter
*adapter
)
1323 struct be_queue_info
*eq
, *q
, *cq
;
1326 adapter
->big_page_size
= (1 << get_order(rx_frag_size
)) * PAGE_SIZE
;
1327 adapter
->rx_eq
.max_eqd
= BE_MAX_EQD
;
1328 adapter
->rx_eq
.min_eqd
= 0;
1329 adapter
->rx_eq
.cur_eqd
= 0;
1330 adapter
->rx_eq
.enable_aic
= true;
1332 /* Alloc Rx Event queue */
1333 eq
= &adapter
->rx_eq
.q
;
1334 rc
= be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
,
1335 sizeof(struct be_eq_entry
));
1339 /* Ask BE to create Rx Event queue */
1340 rc
= be_cmd_eq_create(adapter
, eq
, adapter
->rx_eq
.cur_eqd
);
1344 /* Alloc RX eth compl queue */
1345 cq
= &adapter
->rx_obj
.cq
;
1346 rc
= be_queue_alloc(adapter
, cq
, RX_CQ_LEN
,
1347 sizeof(struct be_eth_rx_compl
));
1351 /* Ask BE to create Rx eth compl queue */
1352 rc
= be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3);
1356 /* Alloc RX eth queue */
1357 q
= &adapter
->rx_obj
.q
;
1358 rc
= be_queue_alloc(adapter
, q
, RX_Q_LEN
, sizeof(struct be_eth_rx_d
));
1362 /* Ask BE to create Rx eth queue */
1363 rc
= be_cmd_rxq_create(adapter
, q
, cq
->id
, rx_frag_size
,
1364 BE_MAX_JUMBO_FRAME_SIZE
, adapter
->if_handle
, false);
1370 be_queue_free(adapter
, q
);
1372 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1374 be_queue_free(adapter
, cq
);
1376 be_cmd_q_destroy(adapter
, eq
, QTYPE_EQ
);
1378 be_queue_free(adapter
, eq
);
1382 /* There are 8 evt ids per func. Retruns the evt id's bit number */
1383 static inline int be_evt_bit_get(struct be_adapter
*adapter
, u32 eq_id
)
1388 static irqreturn_t
be_intx(int irq
, void *dev
)
1390 struct be_adapter
*adapter
= dev
;
1393 isr
= ioread32(adapter
->csr
+ CEV_ISR0_OFFSET
+
1394 (adapter
->tx_eq
.q
.id
/ 8) * CEV_ISR_SIZE
);
1398 event_handle(adapter
, &adapter
->tx_eq
);
1399 event_handle(adapter
, &adapter
->rx_eq
);
1404 static irqreturn_t
be_msix_rx(int irq
, void *dev
)
1406 struct be_adapter
*adapter
= dev
;
1408 event_handle(adapter
, &adapter
->rx_eq
);
1413 static irqreturn_t
be_msix_tx_mcc(int irq
, void *dev
)
1415 struct be_adapter
*adapter
= dev
;
1417 event_handle(adapter
, &adapter
->tx_eq
);
1422 static inline bool do_gro(struct be_adapter
*adapter
,
1423 struct be_eth_rx_compl
*rxcp
)
1425 int err
= AMAP_GET_BITS(struct amap_eth_rx_compl
, err
, rxcp
);
1426 int tcp_frame
= AMAP_GET_BITS(struct amap_eth_rx_compl
, tcpf
, rxcp
);
1429 drvr_stats(adapter
)->be_rxcp_err
++;
1431 return (tcp_frame
&& !err
) ? true : false;
1434 int be_poll_rx(struct napi_struct
*napi
, int budget
)
1436 struct be_eq_obj
*rx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1437 struct be_adapter
*adapter
=
1438 container_of(rx_eq
, struct be_adapter
, rx_eq
);
1439 struct be_queue_info
*rx_cq
= &adapter
->rx_obj
.cq
;
1440 struct be_eth_rx_compl
*rxcp
;
1443 adapter
->stats
.drvr_stats
.be_rx_polls
++;
1444 for (work_done
= 0; work_done
< budget
; work_done
++) {
1445 rxcp
= be_rx_compl_get(adapter
);
1449 if (do_gro(adapter
, rxcp
))
1450 be_rx_compl_process_gro(adapter
, rxcp
);
1452 be_rx_compl_process(adapter
, rxcp
);
1454 be_rx_compl_reset(rxcp
);
1457 /* Refill the queue */
1458 if (atomic_read(&adapter
->rx_obj
.q
.used
) < RX_FRAGS_REFILL_WM
)
1459 be_post_rx_frags(adapter
);
1462 if (work_done
< budget
) {
1463 napi_complete(napi
);
1464 be_cq_notify(adapter
, rx_cq
->id
, true, work_done
);
1466 /* More to be consumed; continue with interrupts disabled */
1467 be_cq_notify(adapter
, rx_cq
->id
, false, work_done
);
1472 /* As TX and MCC share the same EQ check for both TX and MCC completions.
1473 * For TX/MCC we don't honour budget; consume everything
1475 static int be_poll_tx_mcc(struct napi_struct
*napi
, int budget
)
1477 struct be_eq_obj
*tx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1478 struct be_adapter
*adapter
=
1479 container_of(tx_eq
, struct be_adapter
, tx_eq
);
1480 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1481 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1482 struct be_eth_tx_compl
*txcp
;
1483 int tx_compl
= 0, mcc_compl
, status
= 0;
1486 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1487 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1489 be_tx_compl_process(adapter
, end_idx
);
1493 mcc_compl
= be_process_mcc(adapter
, &status
);
1495 napi_complete(napi
);
1498 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
1499 be_cq_notify(adapter
, mcc_obj
->cq
.id
, true, mcc_compl
);
1503 be_cq_notify(adapter
, adapter
->tx_obj
.cq
.id
, true, tx_compl
);
1505 /* As Tx wrbs have been freed up, wake up netdev queue if
1506 * it was stopped due to lack of tx wrbs.
1508 if (netif_queue_stopped(adapter
->netdev
) &&
1509 atomic_read(&txq
->used
) < txq
->len
/ 2) {
1510 netif_wake_queue(adapter
->netdev
);
1513 drvr_stats(adapter
)->be_tx_events
++;
1514 drvr_stats(adapter
)->be_tx_compl
+= tx_compl
;
1520 static void be_worker(struct work_struct
*work
)
1522 struct be_adapter
*adapter
=
1523 container_of(work
, struct be_adapter
, work
.work
);
1525 be_cmd_get_stats(adapter
, &adapter
->stats
.cmd
);
1528 be_rx_eqd_update(adapter
);
1530 be_tx_rate_update(adapter
);
1531 be_rx_rate_update(adapter
);
1533 if (adapter
->rx_post_starved
) {
1534 adapter
->rx_post_starved
= false;
1535 be_post_rx_frags(adapter
);
1538 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(1000));
1541 static void be_msix_disable(struct be_adapter
*adapter
)
1543 if (adapter
->msix_enabled
) {
1544 pci_disable_msix(adapter
->pdev
);
1545 adapter
->msix_enabled
= false;
1549 static void be_msix_enable(struct be_adapter
*adapter
)
1553 for (i
= 0; i
< BE_NUM_MSIX_VECTORS
; i
++)
1554 adapter
->msix_entries
[i
].entry
= i
;
1556 status
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1557 BE_NUM_MSIX_VECTORS
);
1559 adapter
->msix_enabled
= true;
1563 static inline int be_msix_vec_get(struct be_adapter
*adapter
, u32 eq_id
)
1565 return adapter
->msix_entries
[
1566 be_evt_bit_get(adapter
, eq_id
)].vector
;
1569 static int be_request_irq(struct be_adapter
*adapter
,
1570 struct be_eq_obj
*eq_obj
,
1571 void *handler
, char *desc
)
1573 struct net_device
*netdev
= adapter
->netdev
;
1576 sprintf(eq_obj
->desc
, "%s-%s", netdev
->name
, desc
);
1577 vec
= be_msix_vec_get(adapter
, eq_obj
->q
.id
);
1578 return request_irq(vec
, handler
, 0, eq_obj
->desc
, adapter
);
1581 static void be_free_irq(struct be_adapter
*adapter
, struct be_eq_obj
*eq_obj
)
1583 int vec
= be_msix_vec_get(adapter
, eq_obj
->q
.id
);
1584 free_irq(vec
, adapter
);
1587 static int be_msix_register(struct be_adapter
*adapter
)
1591 status
= be_request_irq(adapter
, &adapter
->tx_eq
, be_msix_tx_mcc
, "tx");
1595 status
= be_request_irq(adapter
, &adapter
->rx_eq
, be_msix_rx
, "rx");
1602 be_free_irq(adapter
, &adapter
->tx_eq
);
1604 dev_warn(&adapter
->pdev
->dev
,
1605 "MSIX Request IRQ failed - err %d\n", status
);
1606 pci_disable_msix(adapter
->pdev
);
1607 adapter
->msix_enabled
= false;
1611 static int be_irq_register(struct be_adapter
*adapter
)
1613 struct net_device
*netdev
= adapter
->netdev
;
1616 if (adapter
->msix_enabled
) {
1617 status
= be_msix_register(adapter
);
1623 netdev
->irq
= adapter
->pdev
->irq
;
1624 status
= request_irq(netdev
->irq
, be_intx
, IRQF_SHARED
, netdev
->name
,
1627 dev_err(&adapter
->pdev
->dev
,
1628 "INTx request IRQ failed - err %d\n", status
);
1632 adapter
->isr_registered
= true;
1636 static void be_irq_unregister(struct be_adapter
*adapter
)
1638 struct net_device
*netdev
= adapter
->netdev
;
1640 if (!adapter
->isr_registered
)
1644 if (!adapter
->msix_enabled
) {
1645 free_irq(netdev
->irq
, adapter
);
1650 be_free_irq(adapter
, &adapter
->tx_eq
);
1651 be_free_irq(adapter
, &adapter
->rx_eq
);
1653 adapter
->isr_registered
= false;
1657 static int be_open(struct net_device
*netdev
)
1659 struct be_adapter
*adapter
= netdev_priv(netdev
);
1660 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
1661 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
1667 /* First time posting */
1668 be_post_rx_frags(adapter
);
1670 napi_enable(&rx_eq
->napi
);
1671 napi_enable(&tx_eq
->napi
);
1673 be_irq_register(adapter
);
1675 be_intr_set(adapter
, true);
1677 /* The evt queues are created in unarmed state; arm them */
1678 be_eq_notify(adapter
, rx_eq
->q
.id
, true, false, 0);
1679 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
1681 /* Rx compl queue may be in unarmed state; rearm it */
1682 be_cq_notify(adapter
, adapter
->rx_obj
.cq
.id
, true, 0);
1684 /* Now that interrupts are on we can process async mcc */
1685 be_async_mcc_enable(adapter
);
1687 status
= be_cmd_link_status_query(adapter
, &link_up
, &mac_speed
,
1691 be_link_status_update(adapter
, link_up
);
1693 status
= be_vid_config(adapter
);
1697 status
= be_cmd_set_flow_control(adapter
,
1698 adapter
->tx_fc
, adapter
->rx_fc
);
1702 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
1707 static int be_setup_wol(struct be_adapter
*adapter
, bool enable
)
1709 struct be_dma_mem cmd
;
1713 memset(mac
, 0, ETH_ALEN
);
1715 cmd
.size
= sizeof(struct be_cmd_req_acpi_wol_magic_config
);
1716 cmd
.va
= pci_alloc_consistent(adapter
->pdev
, cmd
.size
, &cmd
.dma
);
1719 memset(cmd
.va
, 0, cmd
.size
);
1722 status
= pci_write_config_dword(adapter
->pdev
,
1723 PCICFG_PM_CONTROL_OFFSET
, PCICFG_PM_CONTROL_MASK
);
1725 dev_err(&adapter
->pdev
->dev
,
1726 "Could not enable Wake-on-lan \n");
1727 pci_free_consistent(adapter
->pdev
, cmd
.size
, cmd
.va
,
1731 status
= be_cmd_enable_magic_wol(adapter
,
1732 adapter
->netdev
->dev_addr
, &cmd
);
1733 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 1);
1734 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 1);
1736 status
= be_cmd_enable_magic_wol(adapter
, mac
, &cmd
);
1737 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 0);
1738 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 0);
1741 pci_free_consistent(adapter
->pdev
, cmd
.size
, cmd
.va
, cmd
.dma
);
1745 static int be_setup(struct be_adapter
*adapter
)
1747 struct net_device
*netdev
= adapter
->netdev
;
1748 u32 cap_flags
, en_flags
;
1751 cap_flags
= BE_IF_FLAGS_UNTAGGED
| BE_IF_FLAGS_BROADCAST
|
1752 BE_IF_FLAGS_MCAST_PROMISCUOUS
|
1753 BE_IF_FLAGS_PROMISCUOUS
|
1754 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
1755 en_flags
= BE_IF_FLAGS_UNTAGGED
| BE_IF_FLAGS_BROADCAST
|
1756 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
1758 status
= be_cmd_if_create(adapter
, cap_flags
, en_flags
,
1759 netdev
->dev_addr
, false/* pmac_invalid */,
1760 &adapter
->if_handle
, &adapter
->pmac_id
);
1764 status
= be_tx_queues_create(adapter
);
1768 status
= be_rx_queues_create(adapter
);
1772 status
= be_mcc_queues_create(adapter
);
1776 adapter
->link_speed
= -1;
1781 be_rx_queues_destroy(adapter
);
1783 be_tx_queues_destroy(adapter
);
1785 be_cmd_if_destroy(adapter
, adapter
->if_handle
);
1790 static int be_clear(struct be_adapter
*adapter
)
1792 be_mcc_queues_destroy(adapter
);
1793 be_rx_queues_destroy(adapter
);
1794 be_tx_queues_destroy(adapter
);
1796 be_cmd_if_destroy(adapter
, adapter
->if_handle
);
1798 /* tell fw we're done with firing cmds */
1799 be_cmd_fw_clean(adapter
);
1803 static int be_close(struct net_device
*netdev
)
1805 struct be_adapter
*adapter
= netdev_priv(netdev
);
1806 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
1807 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
1810 cancel_delayed_work_sync(&adapter
->work
);
1812 be_async_mcc_disable(adapter
);
1814 netif_stop_queue(netdev
);
1815 netif_carrier_off(netdev
);
1816 adapter
->link_up
= false;
1818 be_intr_set(adapter
, false);
1820 if (adapter
->msix_enabled
) {
1821 vec
= be_msix_vec_get(adapter
, tx_eq
->q
.id
);
1822 synchronize_irq(vec
);
1823 vec
= be_msix_vec_get(adapter
, rx_eq
->q
.id
);
1824 synchronize_irq(vec
);
1826 synchronize_irq(netdev
->irq
);
1828 be_irq_unregister(adapter
);
1830 napi_disable(&rx_eq
->napi
);
1831 napi_disable(&tx_eq
->napi
);
1833 /* Wait for all pending tx completions to arrive so that
1834 * all tx skbs are freed.
1836 be_tx_compl_clean(adapter
);
1841 #define FW_FILE_HDR_SIGN "ServerEngines Corp. "
1842 char flash_cookie
[2][16] = {"*** SE FLAS",
1843 "H DIRECTORY *** "};
1845 static bool be_flash_redboot(struct be_adapter
*adapter
,
1846 const u8
*p
, u32 img_start
, int image_size
,
1853 crc_offset
= hdr_size
+ img_start
+ image_size
- 4;
1857 status
= be_cmd_get_flash_crc(adapter
, flashed_crc
,
1860 dev_err(&adapter
->pdev
->dev
,
1861 "could not get crc from flash, not flashing redboot\n");
1865 /*update redboot only if crc does not match*/
1866 if (!memcmp(flashed_crc
, p
, 4))
1872 static int be_flash_data(struct be_adapter
*adapter
,
1873 const struct firmware
*fw
,
1874 struct be_dma_mem
*flash_cmd
, int num_of_images
)
1877 int status
= 0, i
, filehdr_size
= 0;
1878 u32 total_bytes
= 0, flash_op
;
1880 const u8
*p
= fw
->data
;
1881 struct be_cmd_write_flashrom
*req
= flash_cmd
->va
;
1882 struct flash_comp
*pflashcomp
;
1885 struct flash_comp gen3_flash_types
[9] = {
1886 { FLASH_iSCSI_PRIMARY_IMAGE_START_g3
, IMG_TYPE_ISCSI_ACTIVE
,
1887 FLASH_IMAGE_MAX_SIZE_g3
},
1888 { FLASH_REDBOOT_START_g3
, IMG_TYPE_REDBOOT
,
1889 FLASH_REDBOOT_IMAGE_MAX_SIZE_g3
},
1890 { FLASH_iSCSI_BIOS_START_g3
, IMG_TYPE_BIOS
,
1891 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
1892 { FLASH_PXE_BIOS_START_g3
, IMG_TYPE_PXE_BIOS
,
1893 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
1894 { FLASH_FCoE_BIOS_START_g3
, IMG_TYPE_FCOE_BIOS
,
1895 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
1896 { FLASH_iSCSI_BACKUP_IMAGE_START_g3
, IMG_TYPE_ISCSI_BACKUP
,
1897 FLASH_IMAGE_MAX_SIZE_g3
},
1898 { FLASH_FCoE_PRIMARY_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_ACTIVE
,
1899 FLASH_IMAGE_MAX_SIZE_g3
},
1900 { FLASH_FCoE_BACKUP_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_BACKUP
,
1901 FLASH_IMAGE_MAX_SIZE_g3
},
1902 { FLASH_NCSI_START_g3
, IMG_TYPE_NCSI_FW
,
1903 FLASH_NCSI_IMAGE_MAX_SIZE_g3
}
1905 struct flash_comp gen2_flash_types
[8] = {
1906 { FLASH_iSCSI_PRIMARY_IMAGE_START_g2
, IMG_TYPE_ISCSI_ACTIVE
,
1907 FLASH_IMAGE_MAX_SIZE_g2
},
1908 { FLASH_REDBOOT_START_g2
, IMG_TYPE_REDBOOT
,
1909 FLASH_REDBOOT_IMAGE_MAX_SIZE_g2
},
1910 { FLASH_iSCSI_BIOS_START_g2
, IMG_TYPE_BIOS
,
1911 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
1912 { FLASH_PXE_BIOS_START_g2
, IMG_TYPE_PXE_BIOS
,
1913 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
1914 { FLASH_FCoE_BIOS_START_g2
, IMG_TYPE_FCOE_BIOS
,
1915 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
1916 { FLASH_iSCSI_BACKUP_IMAGE_START_g2
, IMG_TYPE_ISCSI_BACKUP
,
1917 FLASH_IMAGE_MAX_SIZE_g2
},
1918 { FLASH_FCoE_PRIMARY_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_ACTIVE
,
1919 FLASH_IMAGE_MAX_SIZE_g2
},
1920 { FLASH_FCoE_BACKUP_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_BACKUP
,
1921 FLASH_IMAGE_MAX_SIZE_g2
}
1924 if (adapter
->generation
== BE_GEN3
) {
1925 pflashcomp
= gen3_flash_types
;
1926 filehdr_size
= sizeof(struct flash_file_hdr_g3
);
1929 pflashcomp
= gen2_flash_types
;
1930 filehdr_size
= sizeof(struct flash_file_hdr_g2
);
1933 for (i
= 0; i
< num_comp
; i
++) {
1934 if ((pflashcomp
[i
].optype
== IMG_TYPE_NCSI_FW
) &&
1935 memcmp(adapter
->fw_ver
, "3.102.148.0", 11) < 0)
1937 if ((pflashcomp
[i
].optype
== IMG_TYPE_REDBOOT
) &&
1938 (!be_flash_redboot(adapter
, fw
->data
,
1939 pflashcomp
[i
].offset
, pflashcomp
[i
].size
,
1943 p
+= filehdr_size
+ pflashcomp
[i
].offset
1944 + (num_of_images
* sizeof(struct image_hdr
));
1945 if (p
+ pflashcomp
[i
].size
> fw
->data
+ fw
->size
)
1947 total_bytes
= pflashcomp
[i
].size
;
1948 while (total_bytes
) {
1949 if (total_bytes
> 32*1024)
1950 num_bytes
= 32*1024;
1952 num_bytes
= total_bytes
;
1953 total_bytes
-= num_bytes
;
1956 flash_op
= FLASHROM_OPER_FLASH
;
1958 flash_op
= FLASHROM_OPER_SAVE
;
1959 memcpy(req
->params
.data_buf
, p
, num_bytes
);
1961 status
= be_cmd_write_flashrom(adapter
, flash_cmd
,
1962 pflashcomp
[i
].optype
, flash_op
, num_bytes
);
1964 dev_err(&adapter
->pdev
->dev
,
1965 "cmd to write to flash rom failed.\n");
1974 static int get_ufigen_type(struct flash_file_hdr_g2
*fhdr
)
1978 if (fhdr
->build
[0] == '3')
1980 else if (fhdr
->build
[0] == '2')
1986 int be_load_fw(struct be_adapter
*adapter
, u8
*func
)
1988 char fw_file
[ETHTOOL_FLASH_MAX_FILENAME
];
1989 const struct firmware
*fw
;
1990 struct flash_file_hdr_g2
*fhdr
;
1991 struct flash_file_hdr_g3
*fhdr3
;
1992 struct image_hdr
*img_hdr_ptr
= NULL
;
1993 struct be_dma_mem flash_cmd
;
1994 int status
, i
= 0, num_imgs
= 0;
1997 strcpy(fw_file
, func
);
1999 status
= request_firmware(&fw
, fw_file
, &adapter
->pdev
->dev
);
2004 fhdr
= (struct flash_file_hdr_g2
*) p
;
2005 dev_info(&adapter
->pdev
->dev
, "Flashing firmware file %s\n", fw_file
);
2007 flash_cmd
.size
= sizeof(struct be_cmd_write_flashrom
) + 32*1024;
2008 flash_cmd
.va
= pci_alloc_consistent(adapter
->pdev
, flash_cmd
.size
,
2010 if (!flash_cmd
.va
) {
2012 dev_err(&adapter
->pdev
->dev
,
2013 "Memory allocation failure while flashing\n");
2017 if ((adapter
->generation
== BE_GEN3
) &&
2018 (get_ufigen_type(fhdr
) == BE_GEN3
)) {
2019 fhdr3
= (struct flash_file_hdr_g3
*) fw
->data
;
2020 num_imgs
= le32_to_cpu(fhdr3
->num_imgs
);
2021 for (i
= 0; i
< num_imgs
; i
++) {
2022 img_hdr_ptr
= (struct image_hdr
*) (fw
->data
+
2023 (sizeof(struct flash_file_hdr_g3
) +
2024 i
* sizeof(struct image_hdr
)));
2025 if (le32_to_cpu(img_hdr_ptr
->imageid
) == 1)
2026 status
= be_flash_data(adapter
, fw
, &flash_cmd
,
2029 } else if ((adapter
->generation
== BE_GEN2
) &&
2030 (get_ufigen_type(fhdr
) == BE_GEN2
)) {
2031 status
= be_flash_data(adapter
, fw
, &flash_cmd
, 0);
2033 dev_err(&adapter
->pdev
->dev
,
2034 "UFI and Interface are not compatible for flashing\n");
2038 pci_free_consistent(adapter
->pdev
, flash_cmd
.size
, flash_cmd
.va
,
2041 dev_err(&adapter
->pdev
->dev
, "Firmware load error\n");
2045 dev_info(&adapter
->pdev
->dev
, "Firmware flashed successfully\n");
2048 release_firmware(fw
);
2052 static struct net_device_ops be_netdev_ops
= {
2053 .ndo_open
= be_open
,
2054 .ndo_stop
= be_close
,
2055 .ndo_start_xmit
= be_xmit
,
2056 .ndo_get_stats
= be_get_stats
,
2057 .ndo_set_rx_mode
= be_set_multicast_list
,
2058 .ndo_set_mac_address
= be_mac_addr_set
,
2059 .ndo_change_mtu
= be_change_mtu
,
2060 .ndo_validate_addr
= eth_validate_addr
,
2061 .ndo_vlan_rx_register
= be_vlan_register
,
2062 .ndo_vlan_rx_add_vid
= be_vlan_add_vid
,
2063 .ndo_vlan_rx_kill_vid
= be_vlan_rem_vid
,
2066 static void be_netdev_init(struct net_device
*netdev
)
2068 struct be_adapter
*adapter
= netdev_priv(netdev
);
2070 netdev
->features
|= NETIF_F_SG
| NETIF_F_HW_VLAN_RX
| NETIF_F_TSO
|
2071 NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_FILTER
| NETIF_F_HW_CSUM
|
2074 netdev
->vlan_features
|= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_HW_CSUM
;
2076 netdev
->flags
|= IFF_MULTICAST
;
2078 adapter
->rx_csum
= true;
2080 /* Default settings for Rx and Tx flow control */
2081 adapter
->rx_fc
= true;
2082 adapter
->tx_fc
= true;
2084 netif_set_gso_max_size(netdev
, 65535);
2086 BE_SET_NETDEV_OPS(netdev
, &be_netdev_ops
);
2088 SET_ETHTOOL_OPS(netdev
, &be_ethtool_ops
);
2090 netif_napi_add(netdev
, &adapter
->rx_eq
.napi
, be_poll_rx
,
2092 netif_napi_add(netdev
, &adapter
->tx_eq
.napi
, be_poll_tx_mcc
,
2095 netif_carrier_off(netdev
);
2096 netif_stop_queue(netdev
);
2099 static void be_unmap_pci_bars(struct be_adapter
*adapter
)
2102 iounmap(adapter
->csr
);
2104 iounmap(adapter
->db
);
2105 if (adapter
->pcicfg
)
2106 iounmap(adapter
->pcicfg
);
2109 static int be_map_pci_bars(struct be_adapter
*adapter
)
2114 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 2),
2115 pci_resource_len(adapter
->pdev
, 2));
2118 adapter
->csr
= addr
;
2120 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 4),
2126 if (adapter
->generation
== BE_GEN2
)
2131 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, pcicfg_reg
),
2132 pci_resource_len(adapter
->pdev
, pcicfg_reg
));
2135 adapter
->pcicfg
= addr
;
2139 be_unmap_pci_bars(adapter
);
2144 static void be_ctrl_cleanup(struct be_adapter
*adapter
)
2146 struct be_dma_mem
*mem
= &adapter
->mbox_mem_alloced
;
2148 be_unmap_pci_bars(adapter
);
2151 pci_free_consistent(adapter
->pdev
, mem
->size
,
2154 mem
= &adapter
->mc_cmd_mem
;
2156 pci_free_consistent(adapter
->pdev
, mem
->size
,
2160 static int be_ctrl_init(struct be_adapter
*adapter
)
2162 struct be_dma_mem
*mbox_mem_alloc
= &adapter
->mbox_mem_alloced
;
2163 struct be_dma_mem
*mbox_mem_align
= &adapter
->mbox_mem
;
2164 struct be_dma_mem
*mc_cmd_mem
= &adapter
->mc_cmd_mem
;
2167 status
= be_map_pci_bars(adapter
);
2171 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
2172 mbox_mem_alloc
->va
= pci_alloc_consistent(adapter
->pdev
,
2173 mbox_mem_alloc
->size
, &mbox_mem_alloc
->dma
);
2174 if (!mbox_mem_alloc
->va
) {
2176 goto unmap_pci_bars
;
2179 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
2180 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
2181 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
2182 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
2184 mc_cmd_mem
->size
= sizeof(struct be_cmd_req_mcast_mac_config
);
2185 mc_cmd_mem
->va
= pci_alloc_consistent(adapter
->pdev
, mc_cmd_mem
->size
,
2187 if (mc_cmd_mem
->va
== NULL
) {
2191 memset(mc_cmd_mem
->va
, 0, mc_cmd_mem
->size
);
2193 spin_lock_init(&adapter
->mbox_lock
);
2194 spin_lock_init(&adapter
->mcc_lock
);
2195 spin_lock_init(&adapter
->mcc_cq_lock
);
2197 pci_save_state(adapter
->pdev
);
2201 pci_free_consistent(adapter
->pdev
, mbox_mem_alloc
->size
,
2202 mbox_mem_alloc
->va
, mbox_mem_alloc
->dma
);
2205 be_unmap_pci_bars(adapter
);
2211 static void be_stats_cleanup(struct be_adapter
*adapter
)
2213 struct be_stats_obj
*stats
= &adapter
->stats
;
2214 struct be_dma_mem
*cmd
= &stats
->cmd
;
2217 pci_free_consistent(adapter
->pdev
, cmd
->size
,
2221 static int be_stats_init(struct be_adapter
*adapter
)
2223 struct be_stats_obj
*stats
= &adapter
->stats
;
2224 struct be_dma_mem
*cmd
= &stats
->cmd
;
2226 cmd
->size
= sizeof(struct be_cmd_req_get_stats
);
2227 cmd
->va
= pci_alloc_consistent(adapter
->pdev
, cmd
->size
, &cmd
->dma
);
2228 if (cmd
->va
== NULL
)
2230 memset(cmd
->va
, 0, cmd
->size
);
2234 static void __devexit
be_remove(struct pci_dev
*pdev
)
2236 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2241 unregister_netdev(adapter
->netdev
);
2245 be_stats_cleanup(adapter
);
2247 be_ctrl_cleanup(adapter
);
2249 be_msix_disable(adapter
);
2251 pci_set_drvdata(pdev
, NULL
);
2252 pci_release_regions(pdev
);
2253 pci_disable_device(pdev
);
2255 free_netdev(adapter
->netdev
);
2258 static int be_get_config(struct be_adapter
*adapter
)
2263 status
= be_cmd_get_fw_ver(adapter
, adapter
->fw_ver
);
2267 status
= be_cmd_query_fw_cfg(adapter
,
2268 &adapter
->port_num
, &adapter
->cap
);
2272 memset(mac
, 0, ETH_ALEN
);
2273 status
= be_cmd_mac_addr_query(adapter
, mac
,
2274 MAC_ADDRESS_TYPE_NETWORK
, true /*permanent */, 0);
2278 if (!is_valid_ether_addr(mac
))
2279 return -EADDRNOTAVAIL
;
2281 memcpy(adapter
->netdev
->dev_addr
, mac
, ETH_ALEN
);
2282 memcpy(adapter
->netdev
->perm_addr
, mac
, ETH_ALEN
);
2284 if (adapter
->cap
& 0x400)
2285 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
/4;
2287 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
;
2292 static int __devinit
be_probe(struct pci_dev
*pdev
,
2293 const struct pci_device_id
*pdev_id
)
2296 struct be_adapter
*adapter
;
2297 struct net_device
*netdev
;
2299 status
= pci_enable_device(pdev
);
2303 status
= pci_request_regions(pdev
, DRV_NAME
);
2306 pci_set_master(pdev
);
2308 netdev
= alloc_etherdev(sizeof(struct be_adapter
));
2309 if (netdev
== NULL
) {
2313 adapter
= netdev_priv(netdev
);
2315 switch (pdev
->device
) {
2318 adapter
->generation
= BE_GEN2
;
2322 adapter
->generation
= BE_GEN3
;
2325 adapter
->generation
= 0;
2328 adapter
->pdev
= pdev
;
2329 pci_set_drvdata(pdev
, adapter
);
2330 adapter
->netdev
= netdev
;
2331 be_netdev_init(netdev
);
2332 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2334 be_msix_enable(adapter
);
2336 status
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
2338 netdev
->features
|= NETIF_F_HIGHDMA
;
2340 status
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2342 dev_err(&pdev
->dev
, "Could not set PCI DMA Mask\n");
2347 status
= be_ctrl_init(adapter
);
2351 /* sync up with fw's ready state */
2352 status
= be_cmd_POST(adapter
);
2356 /* tell fw we're ready to fire cmds */
2357 status
= be_cmd_fw_init(adapter
);
2361 status
= be_cmd_reset_function(adapter
);
2365 status
= be_stats_init(adapter
);
2369 status
= be_get_config(adapter
);
2373 INIT_DELAYED_WORK(&adapter
->work
, be_worker
);
2375 status
= be_setup(adapter
);
2379 status
= register_netdev(netdev
);
2383 dev_info(&pdev
->dev
, "%s port %d\n", nic_name(pdev
), adapter
->port_num
);
2389 be_stats_cleanup(adapter
);
2391 be_ctrl_cleanup(adapter
);
2393 be_msix_disable(adapter
);
2394 free_netdev(adapter
->netdev
);
2395 pci_set_drvdata(pdev
, NULL
);
2397 pci_release_regions(pdev
);
2399 pci_disable_device(pdev
);
2401 dev_err(&pdev
->dev
, "%s initialization failed\n", nic_name(pdev
));
2405 static int be_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2407 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2408 struct net_device
*netdev
= adapter
->netdev
;
2411 be_setup_wol(adapter
, true);
2413 netif_device_detach(netdev
);
2414 if (netif_running(netdev
)) {
2419 be_cmd_get_flow_control(adapter
, &adapter
->tx_fc
, &adapter
->rx_fc
);
2422 pci_save_state(pdev
);
2423 pci_disable_device(pdev
);
2424 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2428 static int be_resume(struct pci_dev
*pdev
)
2431 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2432 struct net_device
*netdev
= adapter
->netdev
;
2434 netif_device_detach(netdev
);
2436 status
= pci_enable_device(pdev
);
2440 pci_set_power_state(pdev
, 0);
2441 pci_restore_state(pdev
);
2443 /* tell fw we're ready to fire cmds */
2444 status
= be_cmd_fw_init(adapter
);
2449 if (netif_running(netdev
)) {
2454 netif_device_attach(netdev
);
2457 be_setup_wol(adapter
, false);
2462 * An FLR will stop BE from DMAing any data.
2464 static void be_shutdown(struct pci_dev
*pdev
)
2466 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2467 struct net_device
*netdev
= adapter
->netdev
;
2469 netif_device_detach(netdev
);
2471 be_cmd_reset_function(adapter
);
2474 be_setup_wol(adapter
, true);
2476 pci_disable_device(pdev
);
2481 static pci_ers_result_t
be_eeh_err_detected(struct pci_dev
*pdev
,
2482 pci_channel_state_t state
)
2484 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2485 struct net_device
*netdev
= adapter
->netdev
;
2487 dev_err(&adapter
->pdev
->dev
, "EEH error detected\n");
2489 adapter
->eeh_err
= true;
2491 netif_device_detach(netdev
);
2493 if (netif_running(netdev
)) {
2500 if (state
== pci_channel_io_perm_failure
)
2501 return PCI_ERS_RESULT_DISCONNECT
;
2503 pci_disable_device(pdev
);
2505 return PCI_ERS_RESULT_NEED_RESET
;
2508 static pci_ers_result_t
be_eeh_reset(struct pci_dev
*pdev
)
2510 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2513 dev_info(&adapter
->pdev
->dev
, "EEH reset\n");
2514 adapter
->eeh_err
= false;
2516 status
= pci_enable_device(pdev
);
2518 return PCI_ERS_RESULT_DISCONNECT
;
2520 pci_set_master(pdev
);
2521 pci_set_power_state(pdev
, 0);
2522 pci_restore_state(pdev
);
2524 /* Check if card is ok and fw is ready */
2525 status
= be_cmd_POST(adapter
);
2527 return PCI_ERS_RESULT_DISCONNECT
;
2529 return PCI_ERS_RESULT_RECOVERED
;
2532 static void be_eeh_resume(struct pci_dev
*pdev
)
2535 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2536 struct net_device
*netdev
= adapter
->netdev
;
2538 dev_info(&adapter
->pdev
->dev
, "EEH resume\n");
2540 pci_save_state(pdev
);
2542 /* tell fw we're ready to fire cmds */
2543 status
= be_cmd_fw_init(adapter
);
2547 status
= be_setup(adapter
);
2551 if (netif_running(netdev
)) {
2552 status
= be_open(netdev
);
2556 netif_device_attach(netdev
);
2559 dev_err(&adapter
->pdev
->dev
, "EEH resume failed\n");
2563 static struct pci_error_handlers be_eeh_handlers
= {
2564 .error_detected
= be_eeh_err_detected
,
2565 .slot_reset
= be_eeh_reset
,
2566 .resume
= be_eeh_resume
,
2569 static struct pci_driver be_driver
= {
2571 .id_table
= be_dev_ids
,
2573 .remove
= be_remove
,
2574 .suspend
= be_suspend
,
2575 .resume
= be_resume
,
2576 .shutdown
= be_shutdown
,
2577 .err_handler
= &be_eeh_handlers
2580 static int __init
be_init_module(void)
2582 if (rx_frag_size
!= 8192 && rx_frag_size
!= 4096 &&
2583 rx_frag_size
!= 2048) {
2584 printk(KERN_WARNING DRV_NAME
2585 " : Module param rx_frag_size must be 2048/4096/8192."
2587 rx_frag_size
= 2048;
2590 return pci_register_driver(&be_driver
);
2592 module_init(be_init_module
);
2594 static void __exit
be_exit_module(void)
2596 pci_unregister_driver(&be_driver
);
2598 module_exit(be_exit_module
);