2 * Copyright (C) 2005 - 2009 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
, OC_DEVICE_ID1
) },
35 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
38 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
40 static void be_queue_free(struct be_adapter
*adapter
, struct be_queue_info
*q
)
42 struct be_dma_mem
*mem
= &q
->dma_mem
;
44 pci_free_consistent(adapter
->pdev
, mem
->size
,
48 static int be_queue_alloc(struct be_adapter
*adapter
, struct be_queue_info
*q
,
49 u16 len
, u16 entry_size
)
51 struct be_dma_mem
*mem
= &q
->dma_mem
;
53 memset(q
, 0, sizeof(*q
));
55 q
->entry_size
= entry_size
;
56 mem
->size
= len
* entry_size
;
57 mem
->va
= pci_alloc_consistent(adapter
->pdev
, mem
->size
, &mem
->dma
);
60 memset(mem
->va
, 0, mem
->size
);
64 static void be_intr_set(struct be_adapter
*adapter
, bool enable
)
66 u8 __iomem
*addr
= adapter
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
67 u32 reg
= ioread32(addr
);
68 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
70 if (!enabled
&& enable
)
71 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
72 else if (enabled
&& !enable
)
73 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
80 static void be_rxq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
83 val
|= qid
& DB_RQ_RING_ID_MASK
;
84 val
|= posted
<< DB_RQ_NUM_POSTED_SHIFT
;
85 iowrite32(val
, adapter
->db
+ DB_RQ_OFFSET
);
88 static void be_txq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
91 val
|= qid
& DB_TXULP_RING_ID_MASK
;
92 val
|= (posted
& DB_TXULP_NUM_POSTED_MASK
) << DB_TXULP_NUM_POSTED_SHIFT
;
93 iowrite32(val
, adapter
->db
+ DB_TXULP1_OFFSET
);
96 static void be_eq_notify(struct be_adapter
*adapter
, u16 qid
,
97 bool arm
, bool clear_int
, u16 num_popped
)
100 val
|= qid
& DB_EQ_RING_ID_MASK
;
102 val
|= 1 << DB_EQ_REARM_SHIFT
;
104 val
|= 1 << DB_EQ_CLR_SHIFT
;
105 val
|= 1 << DB_EQ_EVNT_SHIFT
;
106 val
|= num_popped
<< DB_EQ_NUM_POPPED_SHIFT
;
107 iowrite32(val
, adapter
->db
+ DB_EQ_OFFSET
);
110 void be_cq_notify(struct be_adapter
*adapter
, u16 qid
, bool arm
, u16 num_popped
)
113 val
|= qid
& DB_CQ_RING_ID_MASK
;
115 val
|= 1 << DB_CQ_REARM_SHIFT
;
116 val
|= num_popped
<< DB_CQ_NUM_POPPED_SHIFT
;
117 iowrite32(val
, adapter
->db
+ DB_CQ_OFFSET
);
120 static int be_mac_addr_set(struct net_device
*netdev
, void *p
)
122 struct be_adapter
*adapter
= netdev_priv(netdev
);
123 struct sockaddr
*addr
= p
;
126 status
= be_cmd_pmac_del(adapter
, adapter
->if_handle
, adapter
->pmac_id
);
130 status
= be_cmd_pmac_add(adapter
, (u8
*)addr
->sa_data
,
131 adapter
->if_handle
, &adapter
->pmac_id
);
133 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
138 void netdev_stats_update(struct be_adapter
*adapter
)
140 struct be_hw_stats
*hw_stats
= hw_stats_from_cmd(adapter
->stats
.cmd
.va
);
141 struct be_rxf_stats
*rxf_stats
= &hw_stats
->rxf
;
142 struct be_port_rxf_stats
*port_stats
=
143 &rxf_stats
->port
[adapter
->port_num
];
144 struct net_device_stats
*dev_stats
= &adapter
->stats
.net_stats
;
145 struct be_erx_stats
*erx_stats
= &hw_stats
->erx
;
147 dev_stats
->rx_packets
= port_stats
->rx_total_frames
;
148 dev_stats
->tx_packets
= port_stats
->tx_unicastframes
+
149 port_stats
->tx_multicastframes
+ port_stats
->tx_broadcastframes
;
150 dev_stats
->rx_bytes
= (u64
) port_stats
->rx_bytes_msd
<< 32 |
151 (u64
) port_stats
->rx_bytes_lsd
;
152 dev_stats
->tx_bytes
= (u64
) port_stats
->tx_bytes_msd
<< 32 |
153 (u64
) port_stats
->tx_bytes_lsd
;
155 /* bad pkts received */
156 dev_stats
->rx_errors
= port_stats
->rx_crc_errors
+
157 port_stats
->rx_alignment_symbol_errors
+
158 port_stats
->rx_in_range_errors
+
159 port_stats
->rx_out_range_errors
+
160 port_stats
->rx_frame_too_long
+
161 port_stats
->rx_dropped_too_small
+
162 port_stats
->rx_dropped_too_short
+
163 port_stats
->rx_dropped_header_too_small
+
164 port_stats
->rx_dropped_tcp_length
+
165 port_stats
->rx_dropped_runt
+
166 port_stats
->rx_tcp_checksum_errs
+
167 port_stats
->rx_ip_checksum_errs
+
168 port_stats
->rx_udp_checksum_errs
;
170 /* no space in linux buffers: best possible approximation */
171 dev_stats
->rx_dropped
= erx_stats
->rx_drops_no_fragments
[0];
173 /* detailed rx errors */
174 dev_stats
->rx_length_errors
= port_stats
->rx_in_range_errors
+
175 port_stats
->rx_out_range_errors
+
176 port_stats
->rx_frame_too_long
;
178 /* receive ring buffer overflow */
179 dev_stats
->rx_over_errors
= 0;
181 dev_stats
->rx_crc_errors
= port_stats
->rx_crc_errors
;
183 /* frame alignment errors */
184 dev_stats
->rx_frame_errors
= port_stats
->rx_alignment_symbol_errors
;
186 /* receiver fifo overrun */
187 /* drops_no_pbuf is no per i/f, it's per BE card */
188 dev_stats
->rx_fifo_errors
= port_stats
->rx_fifo_overflow
+
189 port_stats
->rx_input_fifo_overflow
+
190 rxf_stats
->rx_drops_no_pbuf
;
191 /* receiver missed packetd */
192 dev_stats
->rx_missed_errors
= 0;
194 /* packet transmit problems */
195 dev_stats
->tx_errors
= 0;
197 /* no space available in linux */
198 dev_stats
->tx_dropped
= 0;
200 dev_stats
->multicast
= port_stats
->rx_multicast_frames
;
201 dev_stats
->collisions
= 0;
203 /* detailed tx_errors */
204 dev_stats
->tx_aborted_errors
= 0;
205 dev_stats
->tx_carrier_errors
= 0;
206 dev_stats
->tx_fifo_errors
= 0;
207 dev_stats
->tx_heartbeat_errors
= 0;
208 dev_stats
->tx_window_errors
= 0;
211 void be_link_status_update(struct be_adapter
*adapter
, bool link_up
)
213 struct net_device
*netdev
= adapter
->netdev
;
215 /* If link came up or went down */
216 if (adapter
->link_up
!= link_up
) {
218 netif_start_queue(netdev
);
219 netif_carrier_on(netdev
);
220 printk(KERN_INFO
"%s: Link up\n", netdev
->name
);
222 netif_stop_queue(netdev
);
223 netif_carrier_off(netdev
);
224 printk(KERN_INFO
"%s: Link down\n", netdev
->name
);
226 adapter
->link_up
= link_up
;
230 /* Update the EQ delay n BE based on the RX frags consumed / sec */
231 static void be_rx_eqd_update(struct be_adapter
*adapter
)
233 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
234 struct be_drvr_stats
*stats
= &adapter
->stats
.drvr_stats
;
238 if (!rx_eq
->enable_aic
)
242 if (time_before(now
, stats
->rx_fps_jiffies
)) {
243 stats
->rx_fps_jiffies
= now
;
247 /* Update once a second */
248 if ((now
- stats
->rx_fps_jiffies
) < HZ
)
251 stats
->be_rx_fps
= (stats
->be_rx_frags
- stats
->be_prev_rx_frags
) /
252 ((now
- stats
->rx_fps_jiffies
) / HZ
);
254 stats
->rx_fps_jiffies
= now
;
255 stats
->be_prev_rx_frags
= stats
->be_rx_frags
;
256 eqd
= stats
->be_rx_fps
/ 110000;
258 if (eqd
> rx_eq
->max_eqd
)
259 eqd
= rx_eq
->max_eqd
;
260 if (eqd
< rx_eq
->min_eqd
)
261 eqd
= rx_eq
->min_eqd
;
264 if (eqd
!= rx_eq
->cur_eqd
)
265 be_cmd_modify_eqd(adapter
, rx_eq
->q
.id
, eqd
);
267 rx_eq
->cur_eqd
= eqd
;
270 static struct net_device_stats
*be_get_stats(struct net_device
*dev
)
272 struct be_adapter
*adapter
= netdev_priv(dev
);
274 return &adapter
->stats
.net_stats
;
277 static u32
be_calc_rate(u64 bytes
, unsigned long ticks
)
281 do_div(rate
, ticks
/ HZ
);
282 rate
<<= 3; /* bytes/sec -> bits/sec */
283 do_div(rate
, 1000000ul); /* MB/Sec */
288 static void be_tx_rate_update(struct be_adapter
*adapter
)
290 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
293 /* Wrapped around? */
294 if (time_before(now
, stats
->be_tx_jiffies
)) {
295 stats
->be_tx_jiffies
= now
;
299 /* Update tx rate once in two seconds */
300 if ((now
- stats
->be_tx_jiffies
) > 2 * HZ
) {
301 stats
->be_tx_rate
= be_calc_rate(stats
->be_tx_bytes
302 - stats
->be_tx_bytes_prev
,
303 now
- stats
->be_tx_jiffies
);
304 stats
->be_tx_jiffies
= now
;
305 stats
->be_tx_bytes_prev
= stats
->be_tx_bytes
;
309 static void be_tx_stats_update(struct be_adapter
*adapter
,
310 u32 wrb_cnt
, u32 copied
, bool stopped
)
312 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
314 stats
->be_tx_wrbs
+= wrb_cnt
;
315 stats
->be_tx_bytes
+= copied
;
317 stats
->be_tx_stops
++;
320 /* Determine number of WRB entries needed to xmit data in an skb */
321 static u32
wrb_cnt_for_skb(struct sk_buff
*skb
, bool *dummy
)
323 int cnt
= (skb
->len
> skb
->data_len
);
325 cnt
+= skb_shinfo(skb
)->nr_frags
;
327 /* to account for hdr wrb */
330 /* add a dummy to make it an even num */
335 BUG_ON(cnt
> BE_MAX_TX_FRAG_COUNT
);
339 static inline void wrb_fill(struct be_eth_wrb
*wrb
, u64 addr
, int len
)
341 wrb
->frag_pa_hi
= upper_32_bits(addr
);
342 wrb
->frag_pa_lo
= addr
& 0xFFFFFFFF;
343 wrb
->frag_len
= len
& ETH_WRB_FRAG_LEN_MASK
;
346 static void wrb_fill_hdr(struct be_eth_hdr_wrb
*hdr
, struct sk_buff
*skb
,
347 bool vlan
, u32 wrb_cnt
, u32 len
)
349 memset(hdr
, 0, sizeof(*hdr
));
351 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, crc
, hdr
, 1);
353 if (skb_shinfo(skb
)->gso_segs
> 1 && skb_shinfo(skb
)->gso_size
) {
354 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso
, hdr
, 1);
355 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso_mss
,
356 hdr
, skb_shinfo(skb
)->gso_size
);
357 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
359 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, tcpcs
, hdr
, 1);
360 else if (is_udp_pkt(skb
))
361 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, udpcs
, hdr
, 1);
364 if (vlan
&& vlan_tx_tag_present(skb
)) {
365 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan
, hdr
, 1);
366 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan_tag
,
367 hdr
, vlan_tx_tag_get(skb
));
370 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, event
, hdr
, 1);
371 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, complete
, hdr
, 1);
372 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, num_wrb
, hdr
, wrb_cnt
);
373 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, len
, hdr
, len
);
377 static int make_tx_wrbs(struct be_adapter
*adapter
,
378 struct sk_buff
*skb
, u32 wrb_cnt
, bool dummy_wrb
)
382 struct pci_dev
*pdev
= adapter
->pdev
;
383 struct sk_buff
*first_skb
= skb
;
384 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
385 struct be_eth_wrb
*wrb
;
386 struct be_eth_hdr_wrb
*hdr
;
388 hdr
= queue_head_node(txq
);
389 atomic_add(wrb_cnt
, &txq
->used
);
392 if (skb_dma_map(&pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
393 dev_err(&pdev
->dev
, "TX DMA mapping failed\n");
397 if (skb
->len
> skb
->data_len
) {
398 int len
= skb
->len
- skb
->data_len
;
399 wrb
= queue_head_node(txq
);
400 busaddr
= skb_shinfo(skb
)->dma_head
;
401 wrb_fill(wrb
, busaddr
, len
);
402 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
407 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
408 struct skb_frag_struct
*frag
=
409 &skb_shinfo(skb
)->frags
[i
];
411 busaddr
= skb_shinfo(skb
)->dma_maps
[i
];
412 wrb
= queue_head_node(txq
);
413 wrb_fill(wrb
, busaddr
, frag
->size
);
414 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
416 copied
+= frag
->size
;
420 wrb
= queue_head_node(txq
);
422 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
426 wrb_fill_hdr(hdr
, first_skb
, adapter
->vlan_grp
? true : false,
428 be_dws_cpu_to_le(hdr
, sizeof(*hdr
));
433 static netdev_tx_t
be_xmit(struct sk_buff
*skb
,
434 struct net_device
*netdev
)
436 struct be_adapter
*adapter
= netdev_priv(netdev
);
437 struct be_tx_obj
*tx_obj
= &adapter
->tx_obj
;
438 struct be_queue_info
*txq
= &tx_obj
->q
;
439 u32 wrb_cnt
= 0, copied
= 0;
440 u32 start
= txq
->head
;
441 bool dummy_wrb
, stopped
= false;
443 wrb_cnt
= wrb_cnt_for_skb(skb
, &dummy_wrb
);
445 copied
= make_tx_wrbs(adapter
, skb
, wrb_cnt
, dummy_wrb
);
447 /* record the sent skb in the sent_skb table */
448 BUG_ON(tx_obj
->sent_skb_list
[start
]);
449 tx_obj
->sent_skb_list
[start
] = skb
;
451 /* Ensure txq has space for the next skb; Else stop the queue
452 * *BEFORE* ringing the tx doorbell, so that we serialze the
453 * tx compls of the current transmit which'll wake up the queue
455 if ((BE_MAX_TX_FRAG_COUNT
+ atomic_read(&txq
->used
)) >=
457 netif_stop_queue(netdev
);
461 be_txq_notify(adapter
, txq
->id
, wrb_cnt
);
463 be_tx_stats_update(adapter
, wrb_cnt
, copied
, stopped
);
466 dev_kfree_skb_any(skb
);
471 static int be_change_mtu(struct net_device
*netdev
, int new_mtu
)
473 struct be_adapter
*adapter
= netdev_priv(netdev
);
474 if (new_mtu
< BE_MIN_MTU
||
475 new_mtu
> BE_MAX_JUMBO_FRAME_SIZE
) {
476 dev_info(&adapter
->pdev
->dev
,
477 "MTU must be between %d and %d bytes\n",
478 BE_MIN_MTU
, BE_MAX_JUMBO_FRAME_SIZE
);
481 dev_info(&adapter
->pdev
->dev
, "MTU changed from %d to %d bytes\n",
482 netdev
->mtu
, new_mtu
);
483 netdev
->mtu
= new_mtu
;
488 * if there are BE_NUM_VLANS_SUPPORTED or lesser number of VLANS configured,
489 * program them in BE. If more than BE_NUM_VLANS_SUPPORTED are configured,
490 * set the BE in promiscuous VLAN mode.
492 static int be_vid_config(struct be_adapter
*adapter
)
494 u16 vtag
[BE_NUM_VLANS_SUPPORTED
];
498 if (adapter
->num_vlans
<= BE_NUM_VLANS_SUPPORTED
) {
499 /* Construct VLAN Table to give to HW */
500 for (i
= 0; i
< VLAN_GROUP_ARRAY_LEN
; i
++) {
501 if (adapter
->vlan_tag
[i
]) {
502 vtag
[ntags
] = cpu_to_le16(i
);
506 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
509 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
515 static void be_vlan_register(struct net_device
*netdev
, struct vlan_group
*grp
)
517 struct be_adapter
*adapter
= netdev_priv(netdev
);
518 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
519 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
521 be_eq_notify(adapter
, rx_eq
->q
.id
, false, false, 0);
522 be_eq_notify(adapter
, tx_eq
->q
.id
, false, false, 0);
523 adapter
->vlan_grp
= grp
;
524 be_eq_notify(adapter
, rx_eq
->q
.id
, true, false, 0);
525 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
528 static void be_vlan_add_vid(struct net_device
*netdev
, u16 vid
)
530 struct be_adapter
*adapter
= netdev_priv(netdev
);
532 adapter
->num_vlans
++;
533 adapter
->vlan_tag
[vid
] = 1;
535 be_vid_config(adapter
);
538 static void be_vlan_rem_vid(struct net_device
*netdev
, u16 vid
)
540 struct be_adapter
*adapter
= netdev_priv(netdev
);
542 adapter
->num_vlans
--;
543 adapter
->vlan_tag
[vid
] = 0;
545 vlan_group_set_device(adapter
->vlan_grp
, vid
, NULL
);
546 be_vid_config(adapter
);
549 static void be_set_multicast_list(struct net_device
*netdev
)
551 struct be_adapter
*adapter
= netdev_priv(netdev
);
553 if (netdev
->flags
& IFF_PROMISC
) {
554 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 1);
555 adapter
->promiscuous
= true;
559 /* BE was previously in promiscous mode; disable it */
560 if (adapter
->promiscuous
) {
561 adapter
->promiscuous
= false;
562 be_cmd_promiscuous_config(adapter
, adapter
->port_num
, 0);
565 if (netdev
->flags
& IFF_ALLMULTI
) {
566 be_cmd_multicast_set(adapter
, adapter
->if_handle
, NULL
, 0);
570 be_cmd_multicast_set(adapter
, adapter
->if_handle
, netdev
->mc_list
,
576 static void be_rx_rate_update(struct be_adapter
*adapter
)
578 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
582 if (time_before(now
, stats
->be_rx_jiffies
)) {
583 stats
->be_rx_jiffies
= now
;
587 /* Update the rate once in two seconds */
588 if ((now
- stats
->be_rx_jiffies
) < 2 * HZ
)
591 stats
->be_rx_rate
= be_calc_rate(stats
->be_rx_bytes
592 - stats
->be_rx_bytes_prev
,
593 now
- stats
->be_rx_jiffies
);
594 stats
->be_rx_jiffies
= now
;
595 stats
->be_rx_bytes_prev
= stats
->be_rx_bytes
;
598 static void be_rx_stats_update(struct be_adapter
*adapter
,
599 u32 pktsize
, u16 numfrags
)
601 struct be_drvr_stats
*stats
= drvr_stats(adapter
);
603 stats
->be_rx_compl
++;
604 stats
->be_rx_frags
+= numfrags
;
605 stats
->be_rx_bytes
+= pktsize
;
608 static inline bool do_pkt_csum(struct be_eth_rx_compl
*rxcp
, bool cso
)
610 u8 l4_cksm
, ip_version
, ipcksm
, tcpf
= 0, udpf
= 0, ipv6_chk
;
612 l4_cksm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, l4_cksm
, rxcp
);
613 ipcksm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, ipcksm
, rxcp
);
614 ip_version
= AMAP_GET_BITS(struct amap_eth_rx_compl
, ip_version
, rxcp
);
616 tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, tcpf
, rxcp
);
617 udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, udpf
, rxcp
);
619 ipv6_chk
= (ip_version
&& (tcpf
|| udpf
));
621 return ((l4_cksm
&& ipv6_chk
&& ipcksm
) && cso
) ? false : true;
624 static struct be_rx_page_info
*
625 get_rx_page_info(struct be_adapter
*adapter
, u16 frag_idx
)
627 struct be_rx_page_info
*rx_page_info
;
628 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
630 rx_page_info
= &adapter
->rx_obj
.page_info_tbl
[frag_idx
];
631 BUG_ON(!rx_page_info
->page
);
633 if (rx_page_info
->last_page_user
)
634 pci_unmap_page(adapter
->pdev
, pci_unmap_addr(rx_page_info
, bus
),
635 adapter
->big_page_size
, PCI_DMA_FROMDEVICE
);
637 atomic_dec(&rxq
->used
);
641 /* Throwaway the data in the Rx completion */
642 static void be_rx_compl_discard(struct be_adapter
*adapter
,
643 struct be_eth_rx_compl
*rxcp
)
645 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
646 struct be_rx_page_info
*page_info
;
647 u16 rxq_idx
, i
, num_rcvd
;
649 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
650 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
652 for (i
= 0; i
< num_rcvd
; i
++) {
653 page_info
= get_rx_page_info(adapter
, rxq_idx
);
654 put_page(page_info
->page
);
655 memset(page_info
, 0, sizeof(*page_info
));
656 index_inc(&rxq_idx
, rxq
->len
);
661 * skb_fill_rx_data forms a complete skb for an ether frame
664 static void skb_fill_rx_data(struct be_adapter
*adapter
,
665 struct sk_buff
*skb
, struct be_eth_rx_compl
*rxcp
)
667 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
668 struct be_rx_page_info
*page_info
;
669 u16 rxq_idx
, i
, num_rcvd
, j
;
670 u32 pktsize
, hdr_len
, curr_frag_len
, size
;
673 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
674 pktsize
= AMAP_GET_BITS(struct amap_eth_rx_compl
, pktsize
, rxcp
);
675 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
677 page_info
= get_rx_page_info(adapter
, rxq_idx
);
679 start
= page_address(page_info
->page
) + page_info
->page_offset
;
682 /* Copy data in the first descriptor of this completion */
683 curr_frag_len
= min(pktsize
, rx_frag_size
);
685 /* Copy the header portion into skb_data */
686 hdr_len
= min((u32
)BE_HDR_LEN
, curr_frag_len
);
687 memcpy(skb
->data
, start
, hdr_len
);
688 skb
->len
= curr_frag_len
;
689 if (curr_frag_len
<= BE_HDR_LEN
) { /* tiny packet */
690 /* Complete packet has now been moved to data */
691 put_page(page_info
->page
);
693 skb
->tail
+= curr_frag_len
;
695 skb_shinfo(skb
)->nr_frags
= 1;
696 skb_shinfo(skb
)->frags
[0].page
= page_info
->page
;
697 skb_shinfo(skb
)->frags
[0].page_offset
=
698 page_info
->page_offset
+ hdr_len
;
699 skb_shinfo(skb
)->frags
[0].size
= curr_frag_len
- hdr_len
;
700 skb
->data_len
= curr_frag_len
- hdr_len
;
701 skb
->tail
+= hdr_len
;
703 memset(page_info
, 0, sizeof(*page_info
));
705 if (pktsize
<= rx_frag_size
) {
706 BUG_ON(num_rcvd
!= 1);
710 /* More frags present for this completion */
712 for (i
= 1, j
= 0; i
< num_rcvd
; i
++) {
713 size
-= curr_frag_len
;
714 index_inc(&rxq_idx
, rxq
->len
);
715 page_info
= get_rx_page_info(adapter
, rxq_idx
);
717 curr_frag_len
= min(size
, rx_frag_size
);
719 /* Coalesce all frags from the same physical page in one slot */
720 if (page_info
->page_offset
== 0) {
723 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
724 skb_shinfo(skb
)->frags
[j
].page_offset
=
725 page_info
->page_offset
;
726 skb_shinfo(skb
)->frags
[j
].size
= 0;
727 skb_shinfo(skb
)->nr_frags
++;
729 put_page(page_info
->page
);
732 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
733 skb
->len
+= curr_frag_len
;
734 skb
->data_len
+= curr_frag_len
;
736 memset(page_info
, 0, sizeof(*page_info
));
738 BUG_ON(j
> MAX_SKB_FRAGS
);
741 be_rx_stats_update(adapter
, pktsize
, num_rcvd
);
745 /* Process the RX completion indicated by rxcp when GRO is disabled */
746 static void be_rx_compl_process(struct be_adapter
*adapter
,
747 struct be_eth_rx_compl
*rxcp
)
753 vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtp
, rxcp
);
754 vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtm
, rxcp
);
756 /* vlanf could be wrongly set in some cards.
757 * ignore if vtm is not set */
758 if ((adapter
->cap
== 0x400) && !vtm
)
761 skb
= netdev_alloc_skb(adapter
->netdev
, BE_HDR_LEN
+ NET_IP_ALIGN
);
764 dev_warn(&adapter
->pdev
->dev
, "skb alloc failed\n");
765 be_rx_compl_discard(adapter
, rxcp
);
769 skb_reserve(skb
, NET_IP_ALIGN
);
771 skb_fill_rx_data(adapter
, skb
, rxcp
);
773 if (do_pkt_csum(rxcp
, adapter
->rx_csum
))
774 skb
->ip_summed
= CHECKSUM_NONE
;
776 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
778 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
779 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
780 skb
->dev
= adapter
->netdev
;
783 if (!adapter
->vlan_grp
|| adapter
->num_vlans
== 0) {
787 vid
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vlan_tag
, rxcp
);
788 vid
= be16_to_cpu(vid
);
789 vlan_hwaccel_receive_skb(skb
, adapter
->vlan_grp
, vid
);
791 netif_receive_skb(skb
);
797 /* Process the RX completion indicated by rxcp when GRO is enabled */
798 static void be_rx_compl_process_gro(struct be_adapter
*adapter
,
799 struct be_eth_rx_compl
*rxcp
)
801 struct be_rx_page_info
*page_info
;
802 struct sk_buff
*skb
= NULL
;
803 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
804 struct be_eq_obj
*eq_obj
= &adapter
->rx_eq
;
805 u32 num_rcvd
, pkt_size
, remaining
, vlanf
, curr_frag_len
;
806 u16 i
, rxq_idx
= 0, vid
, j
;
809 num_rcvd
= AMAP_GET_BITS(struct amap_eth_rx_compl
, numfrags
, rxcp
);
810 pkt_size
= AMAP_GET_BITS(struct amap_eth_rx_compl
, pktsize
, rxcp
);
811 vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtp
, rxcp
);
812 rxq_idx
= AMAP_GET_BITS(struct amap_eth_rx_compl
, fragndx
, rxcp
);
813 vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vtm
, rxcp
);
815 /* vlanf could be wrongly set in some cards.
816 * ignore if vtm is not set */
817 if ((adapter
->cap
== 0x400) && !vtm
)
820 skb
= napi_get_frags(&eq_obj
->napi
);
822 be_rx_compl_discard(adapter
, rxcp
);
826 remaining
= pkt_size
;
827 for (i
= 0, j
= -1; i
< num_rcvd
; i
++) {
828 page_info
= get_rx_page_info(adapter
, rxq_idx
);
830 curr_frag_len
= min(remaining
, rx_frag_size
);
832 /* Coalesce all frags from the same physical page in one slot */
833 if (i
== 0 || page_info
->page_offset
== 0) {
834 /* First frag or Fresh page */
836 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
837 skb_shinfo(skb
)->frags
[j
].page_offset
=
838 page_info
->page_offset
;
839 skb_shinfo(skb
)->frags
[j
].size
= 0;
841 put_page(page_info
->page
);
843 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
845 remaining
-= curr_frag_len
;
846 index_inc(&rxq_idx
, rxq
->len
);
847 memset(page_info
, 0, sizeof(*page_info
));
849 BUG_ON(j
> MAX_SKB_FRAGS
);
851 skb_shinfo(skb
)->nr_frags
= j
+ 1;
853 skb
->data_len
= pkt_size
;
854 skb
->truesize
+= pkt_size
;
855 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
857 if (likely(!vlanf
)) {
858 napi_gro_frags(&eq_obj
->napi
);
860 vid
= AMAP_GET_BITS(struct amap_eth_rx_compl
, vlan_tag
, rxcp
);
861 vid
= be16_to_cpu(vid
);
863 if (!adapter
->vlan_grp
|| adapter
->num_vlans
== 0)
866 vlan_gro_frags(&eq_obj
->napi
, adapter
->vlan_grp
, vid
);
869 be_rx_stats_update(adapter
, pkt_size
, num_rcvd
);
873 static struct be_eth_rx_compl
*be_rx_compl_get(struct be_adapter
*adapter
)
875 struct be_eth_rx_compl
*rxcp
= queue_tail_node(&adapter
->rx_obj
.cq
);
877 if (rxcp
->dw
[offsetof(struct amap_eth_rx_compl
, valid
) / 32] == 0)
880 be_dws_le_to_cpu(rxcp
, sizeof(*rxcp
));
882 queue_tail_inc(&adapter
->rx_obj
.cq
);
886 /* To reset the valid bit, we need to reset the whole word as
887 * when walking the queue the valid entries are little-endian
888 * and invalid entries are host endian
890 static inline void be_rx_compl_reset(struct be_eth_rx_compl
*rxcp
)
892 rxcp
->dw
[offsetof(struct amap_eth_rx_compl
, valid
) / 32] = 0;
895 static inline struct page
*be_alloc_pages(u32 size
)
897 gfp_t alloc_flags
= GFP_ATOMIC
;
898 u32 order
= get_order(size
);
900 alloc_flags
|= __GFP_COMP
;
901 return alloc_pages(alloc_flags
, order
);
905 * Allocate a page, split it to fragments of size rx_frag_size and post as
906 * receive buffers to BE
908 static void be_post_rx_frags(struct be_adapter
*adapter
)
910 struct be_rx_page_info
*page_info_tbl
= adapter
->rx_obj
.page_info_tbl
;
911 struct be_rx_page_info
*page_info
= NULL
;
912 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
913 struct page
*pagep
= NULL
;
914 struct be_eth_rx_d
*rxd
;
915 u64 page_dmaaddr
= 0, frag_dmaaddr
;
916 u32 posted
, page_offset
= 0;
918 page_info
= &page_info_tbl
[rxq
->head
];
919 for (posted
= 0; posted
< MAX_RX_POST
&& !page_info
->page
; posted
++) {
921 pagep
= be_alloc_pages(adapter
->big_page_size
);
922 if (unlikely(!pagep
)) {
923 drvr_stats(adapter
)->be_ethrx_post_fail
++;
926 page_dmaaddr
= pci_map_page(adapter
->pdev
, pagep
, 0,
927 adapter
->big_page_size
,
929 page_info
->page_offset
= 0;
932 page_info
->page_offset
= page_offset
+ rx_frag_size
;
934 page_offset
= page_info
->page_offset
;
935 page_info
->page
= pagep
;
936 pci_unmap_addr_set(page_info
, bus
, page_dmaaddr
);
937 frag_dmaaddr
= page_dmaaddr
+ page_info
->page_offset
;
939 rxd
= queue_head_node(rxq
);
940 rxd
->fragpa_lo
= cpu_to_le32(frag_dmaaddr
& 0xFFFFFFFF);
941 rxd
->fragpa_hi
= cpu_to_le32(upper_32_bits(frag_dmaaddr
));
944 /* Any space left in the current big page for another frag? */
945 if ((page_offset
+ rx_frag_size
+ rx_frag_size
) >
946 adapter
->big_page_size
) {
948 page_info
->last_page_user
= true;
950 page_info
= &page_info_tbl
[rxq
->head
];
953 page_info
->last_page_user
= true;
956 atomic_add(posted
, &rxq
->used
);
957 be_rxq_notify(adapter
, rxq
->id
, posted
);
958 } else if (atomic_read(&rxq
->used
) == 0) {
959 /* Let be_worker replenish when memory is available */
960 adapter
->rx_post_starved
= true;
966 static struct be_eth_tx_compl
*be_tx_compl_get(struct be_queue_info
*tx_cq
)
968 struct be_eth_tx_compl
*txcp
= queue_tail_node(tx_cq
);
970 if (txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] == 0)
973 be_dws_le_to_cpu(txcp
, sizeof(*txcp
));
975 txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] = 0;
977 queue_tail_inc(tx_cq
);
981 static void be_tx_compl_process(struct be_adapter
*adapter
, u16 last_index
)
983 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
984 struct sk_buff
**sent_skbs
= adapter
->tx_obj
.sent_skb_list
;
985 struct sk_buff
*sent_skb
;
986 u16 cur_index
, num_wrbs
= 0;
988 cur_index
= txq
->tail
;
989 sent_skb
= sent_skbs
[cur_index
];
991 sent_skbs
[cur_index
] = NULL
;
994 cur_index
= txq
->tail
;
997 } while (cur_index
!= last_index
);
999 atomic_sub(num_wrbs
, &txq
->used
);
1000 skb_dma_unmap(&adapter
->pdev
->dev
, sent_skb
, DMA_TO_DEVICE
);
1001 kfree_skb(sent_skb
);
1004 static inline struct be_eq_entry
*event_get(struct be_eq_obj
*eq_obj
)
1006 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1011 eqe
->evt
= le32_to_cpu(eqe
->evt
);
1012 queue_tail_inc(&eq_obj
->q
);
1016 static int event_handle(struct be_adapter
*adapter
,
1017 struct be_eq_obj
*eq_obj
)
1019 struct be_eq_entry
*eqe
;
1022 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1027 /* Deal with any spurious interrupts that come
1030 be_eq_notify(adapter
, eq_obj
->q
.id
, true, true, num
);
1032 napi_schedule(&eq_obj
->napi
);
1037 /* Just read and notify events without processing them.
1038 * Used at the time of destroying event queues */
1039 static void be_eq_clean(struct be_adapter
*adapter
,
1040 struct be_eq_obj
*eq_obj
)
1042 struct be_eq_entry
*eqe
;
1045 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1051 be_eq_notify(adapter
, eq_obj
->q
.id
, false, true, num
);
1054 static void be_rx_q_clean(struct be_adapter
*adapter
)
1056 struct be_rx_page_info
*page_info
;
1057 struct be_queue_info
*rxq
= &adapter
->rx_obj
.q
;
1058 struct be_queue_info
*rx_cq
= &adapter
->rx_obj
.cq
;
1059 struct be_eth_rx_compl
*rxcp
;
1062 /* First cleanup pending rx completions */
1063 while ((rxcp
= be_rx_compl_get(adapter
)) != NULL
) {
1064 be_rx_compl_discard(adapter
, rxcp
);
1065 be_rx_compl_reset(rxcp
);
1066 be_cq_notify(adapter
, rx_cq
->id
, true, 1);
1069 /* Then free posted rx buffer that were not used */
1070 tail
= (rxq
->head
+ rxq
->len
- atomic_read(&rxq
->used
)) % rxq
->len
;
1071 for (; atomic_read(&rxq
->used
) > 0; index_inc(&tail
, rxq
->len
)) {
1072 page_info
= get_rx_page_info(adapter
, tail
);
1073 put_page(page_info
->page
);
1074 memset(page_info
, 0, sizeof(*page_info
));
1076 BUG_ON(atomic_read(&rxq
->used
));
1079 static void be_tx_compl_clean(struct be_adapter
*adapter
)
1081 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1082 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1083 struct be_eth_tx_compl
*txcp
;
1084 u16 end_idx
, cmpl
= 0, timeo
= 0;
1086 /* Wait for a max of 200ms for all the tx-completions to arrive. */
1088 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1089 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1091 be_tx_compl_process(adapter
, end_idx
);
1095 be_cq_notify(adapter
, tx_cq
->id
, false, cmpl
);
1099 if (atomic_read(&txq
->used
) == 0 || ++timeo
> 200)
1105 if (atomic_read(&txq
->used
))
1106 dev_err(&adapter
->pdev
->dev
, "%d pending tx-completions\n",
1107 atomic_read(&txq
->used
));
1110 static void be_mcc_queues_destroy(struct be_adapter
*adapter
)
1112 struct be_queue_info
*q
;
1114 q
= &adapter
->mcc_obj
.q
;
1116 be_cmd_q_destroy(adapter
, q
, QTYPE_MCCQ
);
1117 be_queue_free(adapter
, q
);
1119 q
= &adapter
->mcc_obj
.cq
;
1121 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1122 be_queue_free(adapter
, q
);
1125 /* Must be called only after TX qs are created as MCC shares TX EQ */
1126 static int be_mcc_queues_create(struct be_adapter
*adapter
)
1128 struct be_queue_info
*q
, *cq
;
1130 /* Alloc MCC compl queue */
1131 cq
= &adapter
->mcc_obj
.cq
;
1132 if (be_queue_alloc(adapter
, cq
, MCC_CQ_LEN
,
1133 sizeof(struct be_mcc_compl
)))
1136 /* Ask BE to create MCC compl queue; share TX's eq */
1137 if (be_cmd_cq_create(adapter
, cq
, &adapter
->tx_eq
.q
, false, true, 0))
1140 /* Alloc MCC queue */
1141 q
= &adapter
->mcc_obj
.q
;
1142 if (be_queue_alloc(adapter
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
1143 goto mcc_cq_destroy
;
1145 /* Ask BE to create MCC queue */
1146 if (be_cmd_mccq_create(adapter
, q
, cq
))
1152 be_queue_free(adapter
, q
);
1154 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1156 be_queue_free(adapter
, cq
);
1161 static void be_tx_queues_destroy(struct be_adapter
*adapter
)
1163 struct be_queue_info
*q
;
1165 q
= &adapter
->tx_obj
.q
;
1167 be_cmd_q_destroy(adapter
, q
, QTYPE_TXQ
);
1168 be_queue_free(adapter
, q
);
1170 q
= &adapter
->tx_obj
.cq
;
1172 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1173 be_queue_free(adapter
, q
);
1175 /* Clear any residual events */
1176 be_eq_clean(adapter
, &adapter
->tx_eq
);
1178 q
= &adapter
->tx_eq
.q
;
1180 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1181 be_queue_free(adapter
, q
);
1184 static int be_tx_queues_create(struct be_adapter
*adapter
)
1186 struct be_queue_info
*eq
, *q
, *cq
;
1188 adapter
->tx_eq
.max_eqd
= 0;
1189 adapter
->tx_eq
.min_eqd
= 0;
1190 adapter
->tx_eq
.cur_eqd
= 96;
1191 adapter
->tx_eq
.enable_aic
= false;
1192 /* Alloc Tx Event queue */
1193 eq
= &adapter
->tx_eq
.q
;
1194 if (be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
, sizeof(struct be_eq_entry
)))
1197 /* Ask BE to create Tx Event queue */
1198 if (be_cmd_eq_create(adapter
, eq
, adapter
->tx_eq
.cur_eqd
))
1200 /* Alloc TX eth compl queue */
1201 cq
= &adapter
->tx_obj
.cq
;
1202 if (be_queue_alloc(adapter
, cq
, TX_CQ_LEN
,
1203 sizeof(struct be_eth_tx_compl
)))
1206 /* Ask BE to create Tx eth compl queue */
1207 if (be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3))
1210 /* Alloc TX eth queue */
1211 q
= &adapter
->tx_obj
.q
;
1212 if (be_queue_alloc(adapter
, q
, TX_Q_LEN
, sizeof(struct be_eth_wrb
)))
1215 /* Ask BE to create Tx eth queue */
1216 if (be_cmd_txq_create(adapter
, q
, cq
))
1221 be_queue_free(adapter
, q
);
1223 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1225 be_queue_free(adapter
, cq
);
1227 be_cmd_q_destroy(adapter
, eq
, QTYPE_EQ
);
1229 be_queue_free(adapter
, eq
);
1233 static void be_rx_queues_destroy(struct be_adapter
*adapter
)
1235 struct be_queue_info
*q
;
1237 q
= &adapter
->rx_obj
.q
;
1239 be_cmd_q_destroy(adapter
, q
, QTYPE_RXQ
);
1240 be_rx_q_clean(adapter
);
1242 be_queue_free(adapter
, q
);
1244 q
= &adapter
->rx_obj
.cq
;
1246 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1247 be_queue_free(adapter
, q
);
1249 /* Clear any residual events */
1250 be_eq_clean(adapter
, &adapter
->rx_eq
);
1252 q
= &adapter
->rx_eq
.q
;
1254 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1255 be_queue_free(adapter
, q
);
1258 static int be_rx_queues_create(struct be_adapter
*adapter
)
1260 struct be_queue_info
*eq
, *q
, *cq
;
1263 adapter
->big_page_size
= (1 << get_order(rx_frag_size
)) * PAGE_SIZE
;
1264 adapter
->rx_eq
.max_eqd
= BE_MAX_EQD
;
1265 adapter
->rx_eq
.min_eqd
= 0;
1266 adapter
->rx_eq
.cur_eqd
= 0;
1267 adapter
->rx_eq
.enable_aic
= true;
1269 /* Alloc Rx Event queue */
1270 eq
= &adapter
->rx_eq
.q
;
1271 rc
= be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
,
1272 sizeof(struct be_eq_entry
));
1276 /* Ask BE to create Rx Event queue */
1277 rc
= be_cmd_eq_create(adapter
, eq
, adapter
->rx_eq
.cur_eqd
);
1281 /* Alloc RX eth compl queue */
1282 cq
= &adapter
->rx_obj
.cq
;
1283 rc
= be_queue_alloc(adapter
, cq
, RX_CQ_LEN
,
1284 sizeof(struct be_eth_rx_compl
));
1288 /* Ask BE to create Rx eth compl queue */
1289 rc
= be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3);
1293 /* Alloc RX eth queue */
1294 q
= &adapter
->rx_obj
.q
;
1295 rc
= be_queue_alloc(adapter
, q
, RX_Q_LEN
, sizeof(struct be_eth_rx_d
));
1299 /* Ask BE to create Rx eth queue */
1300 rc
= be_cmd_rxq_create(adapter
, q
, cq
->id
, rx_frag_size
,
1301 BE_MAX_JUMBO_FRAME_SIZE
, adapter
->if_handle
, false);
1307 be_queue_free(adapter
, q
);
1309 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1311 be_queue_free(adapter
, cq
);
1313 be_cmd_q_destroy(adapter
, eq
, QTYPE_EQ
);
1315 be_queue_free(adapter
, eq
);
1319 /* There are 8 evt ids per func. Retruns the evt id's bit number */
1320 static inline int be_evt_bit_get(struct be_adapter
*adapter
, u32 eq_id
)
1322 return eq_id
- 8 * be_pci_func(adapter
);
1325 static irqreturn_t
be_intx(int irq
, void *dev
)
1327 struct be_adapter
*adapter
= dev
;
1330 isr
= ioread32(adapter
->csr
+ CEV_ISR0_OFFSET
+
1331 be_pci_func(adapter
) * CEV_ISR_SIZE
);
1335 event_handle(adapter
, &adapter
->tx_eq
);
1336 event_handle(adapter
, &adapter
->rx_eq
);
1341 static irqreturn_t
be_msix_rx(int irq
, void *dev
)
1343 struct be_adapter
*adapter
= dev
;
1345 event_handle(adapter
, &adapter
->rx_eq
);
1350 static irqreturn_t
be_msix_tx_mcc(int irq
, void *dev
)
1352 struct be_adapter
*adapter
= dev
;
1354 event_handle(adapter
, &adapter
->tx_eq
);
1359 static inline bool do_gro(struct be_adapter
*adapter
,
1360 struct be_eth_rx_compl
*rxcp
)
1362 int err
= AMAP_GET_BITS(struct amap_eth_rx_compl
, err
, rxcp
);
1363 int tcp_frame
= AMAP_GET_BITS(struct amap_eth_rx_compl
, tcpf
, rxcp
);
1366 drvr_stats(adapter
)->be_rxcp_err
++;
1368 return (tcp_frame
&& !err
) ? true : false;
1371 int be_poll_rx(struct napi_struct
*napi
, int budget
)
1373 struct be_eq_obj
*rx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1374 struct be_adapter
*adapter
=
1375 container_of(rx_eq
, struct be_adapter
, rx_eq
);
1376 struct be_queue_info
*rx_cq
= &adapter
->rx_obj
.cq
;
1377 struct be_eth_rx_compl
*rxcp
;
1380 for (work_done
= 0; work_done
< budget
; work_done
++) {
1381 rxcp
= be_rx_compl_get(adapter
);
1385 if (do_gro(adapter
, rxcp
))
1386 be_rx_compl_process_gro(adapter
, rxcp
);
1388 be_rx_compl_process(adapter
, rxcp
);
1390 be_rx_compl_reset(rxcp
);
1393 /* Refill the queue */
1394 if (atomic_read(&adapter
->rx_obj
.q
.used
) < RX_FRAGS_REFILL_WM
)
1395 be_post_rx_frags(adapter
);
1398 if (work_done
< budget
) {
1399 napi_complete(napi
);
1400 be_cq_notify(adapter
, rx_cq
->id
, true, work_done
);
1402 /* More to be consumed; continue with interrupts disabled */
1403 be_cq_notify(adapter
, rx_cq
->id
, false, work_done
);
1408 void be_process_tx(struct be_adapter
*adapter
)
1410 struct be_queue_info
*txq
= &adapter
->tx_obj
.q
;
1411 struct be_queue_info
*tx_cq
= &adapter
->tx_obj
.cq
;
1412 struct be_eth_tx_compl
*txcp
;
1416 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1417 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1419 be_tx_compl_process(adapter
, end_idx
);
1424 be_cq_notify(adapter
, tx_cq
->id
, true, num_cmpl
);
1426 /* As Tx wrbs have been freed up, wake up netdev queue if
1427 * it was stopped due to lack of tx wrbs.
1429 if (netif_queue_stopped(adapter
->netdev
) &&
1430 atomic_read(&txq
->used
) < txq
->len
/ 2) {
1431 netif_wake_queue(adapter
->netdev
);
1434 drvr_stats(adapter
)->be_tx_events
++;
1435 drvr_stats(adapter
)->be_tx_compl
+= num_cmpl
;
1439 /* As TX and MCC share the same EQ check for both TX and MCC completions.
1440 * For TX/MCC we don't honour budget; consume everything
1442 static int be_poll_tx_mcc(struct napi_struct
*napi
, int budget
)
1444 struct be_eq_obj
*tx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1445 struct be_adapter
*adapter
=
1446 container_of(tx_eq
, struct be_adapter
, tx_eq
);
1448 napi_complete(napi
);
1450 be_process_tx(adapter
);
1452 be_process_mcc(adapter
);
1457 static void be_worker(struct work_struct
*work
)
1459 struct be_adapter
*adapter
=
1460 container_of(work
, struct be_adapter
, work
.work
);
1462 be_cmd_get_stats(adapter
, &adapter
->stats
.cmd
);
1465 be_rx_eqd_update(adapter
);
1467 be_tx_rate_update(adapter
);
1468 be_rx_rate_update(adapter
);
1470 if (adapter
->rx_post_starved
) {
1471 adapter
->rx_post_starved
= false;
1472 be_post_rx_frags(adapter
);
1475 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(1000));
1478 static void be_msix_enable(struct be_adapter
*adapter
)
1482 for (i
= 0; i
< BE_NUM_MSIX_VECTORS
; i
++)
1483 adapter
->msix_entries
[i
].entry
= i
;
1485 status
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1486 BE_NUM_MSIX_VECTORS
);
1488 adapter
->msix_enabled
= true;
1492 static inline int be_msix_vec_get(struct be_adapter
*adapter
, u32 eq_id
)
1494 return adapter
->msix_entries
[
1495 be_evt_bit_get(adapter
, eq_id
)].vector
;
1498 static int be_request_irq(struct be_adapter
*adapter
,
1499 struct be_eq_obj
*eq_obj
,
1500 void *handler
, char *desc
)
1502 struct net_device
*netdev
= adapter
->netdev
;
1505 sprintf(eq_obj
->desc
, "%s-%s", netdev
->name
, desc
);
1506 vec
= be_msix_vec_get(adapter
, eq_obj
->q
.id
);
1507 return request_irq(vec
, handler
, 0, eq_obj
->desc
, adapter
);
1510 static void be_free_irq(struct be_adapter
*adapter
, struct be_eq_obj
*eq_obj
)
1512 int vec
= be_msix_vec_get(adapter
, eq_obj
->q
.id
);
1513 free_irq(vec
, adapter
);
1516 static int be_msix_register(struct be_adapter
*adapter
)
1520 status
= be_request_irq(adapter
, &adapter
->tx_eq
, be_msix_tx_mcc
, "tx");
1524 status
= be_request_irq(adapter
, &adapter
->rx_eq
, be_msix_rx
, "rx");
1531 be_free_irq(adapter
, &adapter
->tx_eq
);
1533 dev_warn(&adapter
->pdev
->dev
,
1534 "MSIX Request IRQ failed - err %d\n", status
);
1535 pci_disable_msix(adapter
->pdev
);
1536 adapter
->msix_enabled
= false;
1540 static int be_irq_register(struct be_adapter
*adapter
)
1542 struct net_device
*netdev
= adapter
->netdev
;
1545 if (adapter
->msix_enabled
) {
1546 status
= be_msix_register(adapter
);
1552 netdev
->irq
= adapter
->pdev
->irq
;
1553 status
= request_irq(netdev
->irq
, be_intx
, IRQF_SHARED
, netdev
->name
,
1556 dev_err(&adapter
->pdev
->dev
,
1557 "INTx request IRQ failed - err %d\n", status
);
1561 adapter
->isr_registered
= true;
1565 static void be_irq_unregister(struct be_adapter
*adapter
)
1567 struct net_device
*netdev
= adapter
->netdev
;
1569 if (!adapter
->isr_registered
)
1573 if (!adapter
->msix_enabled
) {
1574 free_irq(netdev
->irq
, adapter
);
1579 be_free_irq(adapter
, &adapter
->tx_eq
);
1580 be_free_irq(adapter
, &adapter
->rx_eq
);
1582 adapter
->isr_registered
= false;
1586 static int be_open(struct net_device
*netdev
)
1588 struct be_adapter
*adapter
= netdev_priv(netdev
);
1589 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
1590 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
1594 /* First time posting */
1595 be_post_rx_frags(adapter
);
1597 napi_enable(&rx_eq
->napi
);
1598 napi_enable(&tx_eq
->napi
);
1600 be_irq_register(adapter
);
1602 be_intr_set(adapter
, true);
1604 /* The evt queues are created in unarmed state; arm them */
1605 be_eq_notify(adapter
, rx_eq
->q
.id
, true, false, 0);
1606 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
1608 /* Rx compl queue may be in unarmed state; rearm it */
1609 be_cq_notify(adapter
, adapter
->rx_obj
.cq
.id
, true, 0);
1611 status
= be_cmd_link_status_query(adapter
, &link_up
);
1614 be_link_status_update(adapter
, link_up
);
1616 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
1620 static int be_setup(struct be_adapter
*adapter
)
1622 struct net_device
*netdev
= adapter
->netdev
;
1623 u32 cap_flags
, en_flags
;
1626 cap_flags
= BE_IF_FLAGS_UNTAGGED
| BE_IF_FLAGS_BROADCAST
|
1627 BE_IF_FLAGS_MCAST_PROMISCUOUS
|
1628 BE_IF_FLAGS_PROMISCUOUS
|
1629 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
1630 en_flags
= BE_IF_FLAGS_UNTAGGED
| BE_IF_FLAGS_BROADCAST
|
1631 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
1633 status
= be_cmd_if_create(adapter
, cap_flags
, en_flags
,
1634 netdev
->dev_addr
, false/* pmac_invalid */,
1635 &adapter
->if_handle
, &adapter
->pmac_id
);
1639 status
= be_tx_queues_create(adapter
);
1643 status
= be_rx_queues_create(adapter
);
1647 status
= be_mcc_queues_create(adapter
);
1651 status
= be_vid_config(adapter
);
1655 status
= be_cmd_set_flow_control(adapter
, true, true);
1661 be_mcc_queues_destroy(adapter
);
1663 be_rx_queues_destroy(adapter
);
1665 be_tx_queues_destroy(adapter
);
1667 be_cmd_if_destroy(adapter
, adapter
->if_handle
);
1672 static int be_clear(struct be_adapter
*adapter
)
1674 be_mcc_queues_destroy(adapter
);
1675 be_rx_queues_destroy(adapter
);
1676 be_tx_queues_destroy(adapter
);
1678 be_cmd_if_destroy(adapter
, adapter
->if_handle
);
1683 static int be_close(struct net_device
*netdev
)
1685 struct be_adapter
*adapter
= netdev_priv(netdev
);
1686 struct be_eq_obj
*rx_eq
= &adapter
->rx_eq
;
1687 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
1690 cancel_delayed_work_sync(&adapter
->work
);
1692 netif_stop_queue(netdev
);
1693 netif_carrier_off(netdev
);
1694 adapter
->link_up
= false;
1696 be_intr_set(adapter
, false);
1698 if (adapter
->msix_enabled
) {
1699 vec
= be_msix_vec_get(adapter
, tx_eq
->q
.id
);
1700 synchronize_irq(vec
);
1701 vec
= be_msix_vec_get(adapter
, rx_eq
->q
.id
);
1702 synchronize_irq(vec
);
1704 synchronize_irq(netdev
->irq
);
1706 be_irq_unregister(adapter
);
1708 napi_disable(&rx_eq
->napi
);
1709 napi_disable(&tx_eq
->napi
);
1711 /* Wait for all pending tx completions to arrive so that
1712 * all tx skbs are freed.
1714 be_tx_compl_clean(adapter
);
1719 #define FW_FILE_HDR_SIGN "ServerEngines Corp. "
1720 char flash_cookie
[2][16] = {"*** SE FLAS",
1721 "H DIRECTORY *** "};
1722 static int be_flash_image(struct be_adapter
*adapter
,
1723 const struct firmware
*fw
,
1724 struct be_dma_mem
*flash_cmd
, u32 flash_type
)
1727 u32 flash_op
, image_offset
= 0, total_bytes
, image_size
= 0;
1729 const u8
*p
= fw
->data
;
1730 struct be_cmd_write_flashrom
*req
= flash_cmd
->va
;
1732 switch (flash_type
) {
1733 case FLASHROM_TYPE_ISCSI_ACTIVE
:
1734 image_offset
= FLASH_iSCSI_PRIMARY_IMAGE_START
;
1735 image_size
= FLASH_IMAGE_MAX_SIZE
;
1737 case FLASHROM_TYPE_ISCSI_BACKUP
:
1738 image_offset
= FLASH_iSCSI_BACKUP_IMAGE_START
;
1739 image_size
= FLASH_IMAGE_MAX_SIZE
;
1741 case FLASHROM_TYPE_FCOE_FW_ACTIVE
:
1742 image_offset
= FLASH_FCoE_PRIMARY_IMAGE_START
;
1743 image_size
= FLASH_IMAGE_MAX_SIZE
;
1745 case FLASHROM_TYPE_FCOE_FW_BACKUP
:
1746 image_offset
= FLASH_FCoE_BACKUP_IMAGE_START
;
1747 image_size
= FLASH_IMAGE_MAX_SIZE
;
1749 case FLASHROM_TYPE_BIOS
:
1750 image_offset
= FLASH_iSCSI_BIOS_START
;
1751 image_size
= FLASH_BIOS_IMAGE_MAX_SIZE
;
1753 case FLASHROM_TYPE_FCOE_BIOS
:
1754 image_offset
= FLASH_FCoE_BIOS_START
;
1755 image_size
= FLASH_BIOS_IMAGE_MAX_SIZE
;
1757 case FLASHROM_TYPE_PXE_BIOS
:
1758 image_offset
= FLASH_PXE_BIOS_START
;
1759 image_size
= FLASH_BIOS_IMAGE_MAX_SIZE
;
1765 p
+= sizeof(struct flash_file_hdr
) + image_offset
;
1766 if (p
+ image_size
> fw
->data
+ fw
->size
)
1769 total_bytes
= image_size
;
1771 while (total_bytes
) {
1772 if (total_bytes
> 32*1024)
1773 num_bytes
= 32*1024;
1775 num_bytes
= total_bytes
;
1776 total_bytes
-= num_bytes
;
1779 flash_op
= FLASHROM_OPER_FLASH
;
1781 flash_op
= FLASHROM_OPER_SAVE
;
1782 memcpy(req
->params
.data_buf
, p
, num_bytes
);
1784 status
= be_cmd_write_flashrom(adapter
, flash_cmd
,
1785 flash_type
, flash_op
, num_bytes
);
1787 dev_err(&adapter
->pdev
->dev
,
1788 "cmd to write to flash rom failed. type/op %d/%d\n",
1789 flash_type
, flash_op
);
1798 int be_load_fw(struct be_adapter
*adapter
, u8
*func
)
1800 char fw_file
[ETHTOOL_FLASH_MAX_FILENAME
];
1801 const struct firmware
*fw
;
1802 struct flash_file_hdr
*fhdr
;
1803 struct flash_section_info
*fsec
= NULL
;
1804 struct be_dma_mem flash_cmd
;
1807 bool entry_found
= false;
1809 char fw_ver
[FW_VER_LEN
];
1812 status
= be_cmd_get_fw_ver(adapter
, fw_ver
);
1816 fw_cfg
= *(fw_ver
+ 2);
1819 strcpy(fw_file
, func
);
1821 status
= request_firmware(&fw
, fw_file
, &adapter
->pdev
->dev
);
1826 fhdr
= (struct flash_file_hdr
*) p
;
1827 if (memcmp(fhdr
->sign
, FW_FILE_HDR_SIGN
, strlen(FW_FILE_HDR_SIGN
))) {
1828 dev_err(&adapter
->pdev
->dev
,
1829 "Firmware(%s) load error (signature did not match)\n",
1835 dev_info(&adapter
->pdev
->dev
, "Flashing firmware file %s\n", fw_file
);
1837 p
+= sizeof(struct flash_file_hdr
);
1838 while (p
< (fw
->data
+ fw
->size
)) {
1839 fsec
= (struct flash_section_info
*)p
;
1840 if (!memcmp(flash_cookie
, fsec
->cookie
, sizeof(flash_cookie
))) {
1849 dev_err(&adapter
->pdev
->dev
,
1850 "Flash cookie not found in firmware image\n");
1854 flash_cmd
.size
= sizeof(struct be_cmd_write_flashrom
) + 32*1024;
1855 flash_cmd
.va
= pci_alloc_consistent(adapter
->pdev
, flash_cmd
.size
,
1857 if (!flash_cmd
.va
) {
1859 dev_err(&adapter
->pdev
->dev
,
1860 "Memory allocation failure while flashing\n");
1864 for (flash_type
= FLASHROM_TYPE_ISCSI_ACTIVE
;
1865 flash_type
<= FLASHROM_TYPE_FCOE_FW_BACKUP
; flash_type
++) {
1866 status
= be_flash_image(adapter
, fw
, &flash_cmd
,
1872 pci_free_consistent(adapter
->pdev
, flash_cmd
.size
, flash_cmd
.va
,
1875 dev_err(&adapter
->pdev
->dev
, "Firmware load error\n");
1879 dev_info(&adapter
->pdev
->dev
, "Firmware flashed succesfully\n");
1882 release_firmware(fw
);
1886 static struct net_device_ops be_netdev_ops
= {
1887 .ndo_open
= be_open
,
1888 .ndo_stop
= be_close
,
1889 .ndo_start_xmit
= be_xmit
,
1890 .ndo_get_stats
= be_get_stats
,
1891 .ndo_set_rx_mode
= be_set_multicast_list
,
1892 .ndo_set_mac_address
= be_mac_addr_set
,
1893 .ndo_change_mtu
= be_change_mtu
,
1894 .ndo_validate_addr
= eth_validate_addr
,
1895 .ndo_vlan_rx_register
= be_vlan_register
,
1896 .ndo_vlan_rx_add_vid
= be_vlan_add_vid
,
1897 .ndo_vlan_rx_kill_vid
= be_vlan_rem_vid
,
1900 static void be_netdev_init(struct net_device
*netdev
)
1902 struct be_adapter
*adapter
= netdev_priv(netdev
);
1904 netdev
->features
|= NETIF_F_SG
| NETIF_F_HW_VLAN_RX
| NETIF_F_TSO
|
1905 NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_FILTER
| NETIF_F_HW_CSUM
|
1908 netdev
->flags
|= IFF_MULTICAST
;
1910 adapter
->rx_csum
= true;
1912 netif_set_gso_max_size(netdev
, 65535);
1914 BE_SET_NETDEV_OPS(netdev
, &be_netdev_ops
);
1916 SET_ETHTOOL_OPS(netdev
, &be_ethtool_ops
);
1918 netif_napi_add(netdev
, &adapter
->rx_eq
.napi
, be_poll_rx
,
1920 netif_napi_add(netdev
, &adapter
->tx_eq
.napi
, be_poll_tx_mcc
,
1923 netif_carrier_off(netdev
);
1924 netif_stop_queue(netdev
);
1927 static void be_unmap_pci_bars(struct be_adapter
*adapter
)
1930 iounmap(adapter
->csr
);
1932 iounmap(adapter
->db
);
1933 if (adapter
->pcicfg
)
1934 iounmap(adapter
->pcicfg
);
1937 static int be_map_pci_bars(struct be_adapter
*adapter
)
1941 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 2),
1942 pci_resource_len(adapter
->pdev
, 2));
1945 adapter
->csr
= addr
;
1947 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 4),
1953 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 1),
1954 pci_resource_len(adapter
->pdev
, 1));
1957 adapter
->pcicfg
= addr
;
1961 be_unmap_pci_bars(adapter
);
1966 static void be_ctrl_cleanup(struct be_adapter
*adapter
)
1968 struct be_dma_mem
*mem
= &adapter
->mbox_mem_alloced
;
1970 be_unmap_pci_bars(adapter
);
1973 pci_free_consistent(adapter
->pdev
, mem
->size
,
1977 static int be_ctrl_init(struct be_adapter
*adapter
)
1979 struct be_dma_mem
*mbox_mem_alloc
= &adapter
->mbox_mem_alloced
;
1980 struct be_dma_mem
*mbox_mem_align
= &adapter
->mbox_mem
;
1983 status
= be_map_pci_bars(adapter
);
1987 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
1988 mbox_mem_alloc
->va
= pci_alloc_consistent(adapter
->pdev
,
1989 mbox_mem_alloc
->size
, &mbox_mem_alloc
->dma
);
1990 if (!mbox_mem_alloc
->va
) {
1991 be_unmap_pci_bars(adapter
);
1994 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
1995 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
1996 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
1997 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
1998 spin_lock_init(&adapter
->mbox_lock
);
1999 spin_lock_init(&adapter
->mcc_lock
);
2000 spin_lock_init(&adapter
->mcc_cq_lock
);
2005 static void be_stats_cleanup(struct be_adapter
*adapter
)
2007 struct be_stats_obj
*stats
= &adapter
->stats
;
2008 struct be_dma_mem
*cmd
= &stats
->cmd
;
2011 pci_free_consistent(adapter
->pdev
, cmd
->size
,
2015 static int be_stats_init(struct be_adapter
*adapter
)
2017 struct be_stats_obj
*stats
= &adapter
->stats
;
2018 struct be_dma_mem
*cmd
= &stats
->cmd
;
2020 cmd
->size
= sizeof(struct be_cmd_req_get_stats
);
2021 cmd
->va
= pci_alloc_consistent(adapter
->pdev
, cmd
->size
, &cmd
->dma
);
2022 if (cmd
->va
== NULL
)
2027 static void __devexit
be_remove(struct pci_dev
*pdev
)
2029 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2033 unregister_netdev(adapter
->netdev
);
2037 be_stats_cleanup(adapter
);
2039 be_ctrl_cleanup(adapter
);
2041 if (adapter
->msix_enabled
) {
2042 pci_disable_msix(adapter
->pdev
);
2043 adapter
->msix_enabled
= false;
2046 pci_set_drvdata(pdev
, NULL
);
2047 pci_release_regions(pdev
);
2048 pci_disable_device(pdev
);
2050 free_netdev(adapter
->netdev
);
2053 static int be_hw_up(struct be_adapter
*adapter
)
2057 status
= be_cmd_POST(adapter
);
2061 status
= be_cmd_get_fw_ver(adapter
, adapter
->fw_ver
);
2065 status
= be_cmd_query_fw_cfg(adapter
,
2066 &adapter
->port_num
, &adapter
->cap
);
2070 static int __devinit
be_probe(struct pci_dev
*pdev
,
2071 const struct pci_device_id
*pdev_id
)
2074 struct be_adapter
*adapter
;
2075 struct net_device
*netdev
;
2078 status
= pci_enable_device(pdev
);
2082 status
= pci_request_regions(pdev
, DRV_NAME
);
2085 pci_set_master(pdev
);
2087 netdev
= alloc_etherdev(sizeof(struct be_adapter
));
2088 if (netdev
== NULL
) {
2092 adapter
= netdev_priv(netdev
);
2093 adapter
->pdev
= pdev
;
2094 pci_set_drvdata(pdev
, adapter
);
2095 adapter
->netdev
= netdev
;
2097 be_msix_enable(adapter
);
2099 status
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
2101 netdev
->features
|= NETIF_F_HIGHDMA
;
2103 status
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2105 dev_err(&pdev
->dev
, "Could not set PCI DMA Mask\n");
2110 status
= be_ctrl_init(adapter
);
2114 status
= be_cmd_reset_function(adapter
);
2118 status
= be_stats_init(adapter
);
2122 status
= be_hw_up(adapter
);
2126 status
= be_cmd_mac_addr_query(adapter
, mac
, MAC_ADDRESS_TYPE_NETWORK
,
2127 true /* permanent */, 0);
2130 memcpy(netdev
->dev_addr
, mac
, ETH_ALEN
);
2132 INIT_DELAYED_WORK(&adapter
->work
, be_worker
);
2133 be_netdev_init(netdev
);
2134 SET_NETDEV_DEV(netdev
, &adapter
->pdev
->dev
);
2136 status
= be_setup(adapter
);
2139 status
= register_netdev(netdev
);
2143 dev_info(&pdev
->dev
, "%s port %d\n", nic_name(pdev
), adapter
->port_num
);
2149 be_stats_cleanup(adapter
);
2151 be_ctrl_cleanup(adapter
);
2153 free_netdev(adapter
->netdev
);
2155 pci_release_regions(pdev
);
2157 pci_disable_device(pdev
);
2159 dev_err(&pdev
->dev
, "%s initialization failed\n", nic_name(pdev
));
2163 static int be_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2165 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2166 struct net_device
*netdev
= adapter
->netdev
;
2168 netif_device_detach(netdev
);
2169 if (netif_running(netdev
)) {
2176 pci_save_state(pdev
);
2177 pci_disable_device(pdev
);
2178 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2182 static int be_resume(struct pci_dev
*pdev
)
2185 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
2186 struct net_device
*netdev
= adapter
->netdev
;
2188 netif_device_detach(netdev
);
2190 status
= pci_enable_device(pdev
);
2194 pci_set_power_state(pdev
, 0);
2195 pci_restore_state(pdev
);
2198 if (netif_running(netdev
)) {
2203 netif_device_attach(netdev
);
2207 static struct pci_driver be_driver
= {
2209 .id_table
= be_dev_ids
,
2211 .remove
= be_remove
,
2212 .suspend
= be_suspend
,
2216 static int __init
be_init_module(void)
2218 if (rx_frag_size
!= 8192 && rx_frag_size
!= 4096
2219 && rx_frag_size
!= 2048) {
2220 printk(KERN_WARNING DRV_NAME
2221 " : Module param rx_frag_size must be 2048/4096/8192."
2223 rx_frag_size
= 2048;
2226 return pci_register_driver(&be_driver
);
2228 module_init(be_init_module
);
2230 static void __exit
be_exit_module(void)
2232 pci_unregister_driver(&be_driver
);
2234 module_exit(be_exit_module
);