2 * Copyright (C) 2005 - 2011 Emulex
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@emulex.com
15 * Costa Mesa, CA 92626
18 #include <linux/prefetch.h>
21 #include <asm/div64.h>
23 MODULE_VERSION(DRV_VER
);
24 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
25 MODULE_DESCRIPTION(DRV_DESC
" " DRV_VER
);
26 MODULE_AUTHOR("ServerEngines Corporation");
27 MODULE_LICENSE("GPL");
29 static ushort rx_frag_size
= 2048;
30 static unsigned int num_vfs
;
31 module_param(rx_frag_size
, ushort
, S_IRUGO
);
32 module_param(num_vfs
, uint
, S_IRUGO
);
33 MODULE_PARM_DESC(rx_frag_size
, "Size of a fragment that holds rcvd data.");
34 MODULE_PARM_DESC(num_vfs
, "Number of PCI VFs to initialize");
36 static DEFINE_PCI_DEVICE_TABLE(be_dev_ids
) = {
37 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
38 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
39 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
40 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
41 { PCI_DEVICE(EMULEX_VENDOR_ID
, OC_DEVICE_ID3
)},
42 { PCI_DEVICE(EMULEX_VENDOR_ID
, OC_DEVICE_ID4
)},
45 MODULE_DEVICE_TABLE(pci
, be_dev_ids
);
46 /* UE Status Low CSR */
47 static const char * const ue_status_low_desc
[] = {
81 /* UE Status High CSR */
82 static const char * const ue_status_hi_desc
[] = {
117 static void be_queue_free(struct be_adapter
*adapter
, struct be_queue_info
*q
)
119 struct be_dma_mem
*mem
= &q
->dma_mem
;
121 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
125 static int be_queue_alloc(struct be_adapter
*adapter
, struct be_queue_info
*q
,
126 u16 len
, u16 entry_size
)
128 struct be_dma_mem
*mem
= &q
->dma_mem
;
130 memset(q
, 0, sizeof(*q
));
132 q
->entry_size
= entry_size
;
133 mem
->size
= len
* entry_size
;
134 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
, &mem
->dma
,
138 memset(mem
->va
, 0, mem
->size
);
142 static void be_intr_set(struct be_adapter
*adapter
, bool enable
)
144 u8 __iomem
*addr
= adapter
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
145 u32 reg
= ioread32(addr
);
146 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
148 if (adapter
->eeh_err
)
151 if (!enabled
&& enable
)
152 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
153 else if (enabled
&& !enable
)
154 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
158 iowrite32(reg
, addr
);
161 static void be_rxq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
164 val
|= qid
& DB_RQ_RING_ID_MASK
;
165 val
|= posted
<< DB_RQ_NUM_POSTED_SHIFT
;
168 iowrite32(val
, adapter
->db
+ DB_RQ_OFFSET
);
171 static void be_txq_notify(struct be_adapter
*adapter
, u16 qid
, u16 posted
)
174 val
|= qid
& DB_TXULP_RING_ID_MASK
;
175 val
|= (posted
& DB_TXULP_NUM_POSTED_MASK
) << DB_TXULP_NUM_POSTED_SHIFT
;
178 iowrite32(val
, adapter
->db
+ DB_TXULP1_OFFSET
);
181 static void be_eq_notify(struct be_adapter
*adapter
, u16 qid
,
182 bool arm
, bool clear_int
, u16 num_popped
)
185 val
|= qid
& DB_EQ_RING_ID_MASK
;
186 val
|= ((qid
& DB_EQ_RING_ID_EXT_MASK
) <<
187 DB_EQ_RING_ID_EXT_MASK_SHIFT
);
189 if (adapter
->eeh_err
)
193 val
|= 1 << DB_EQ_REARM_SHIFT
;
195 val
|= 1 << DB_EQ_CLR_SHIFT
;
196 val
|= 1 << DB_EQ_EVNT_SHIFT
;
197 val
|= num_popped
<< DB_EQ_NUM_POPPED_SHIFT
;
198 iowrite32(val
, adapter
->db
+ DB_EQ_OFFSET
);
201 void be_cq_notify(struct be_adapter
*adapter
, u16 qid
, bool arm
, u16 num_popped
)
204 val
|= qid
& DB_CQ_RING_ID_MASK
;
205 val
|= ((qid
& DB_CQ_RING_ID_EXT_MASK
) <<
206 DB_CQ_RING_ID_EXT_MASK_SHIFT
);
208 if (adapter
->eeh_err
)
212 val
|= 1 << DB_CQ_REARM_SHIFT
;
213 val
|= num_popped
<< DB_CQ_NUM_POPPED_SHIFT
;
214 iowrite32(val
, adapter
->db
+ DB_CQ_OFFSET
);
217 static int be_mac_addr_set(struct net_device
*netdev
, void *p
)
219 struct be_adapter
*adapter
= netdev_priv(netdev
);
220 struct sockaddr
*addr
= p
;
223 if (!is_valid_ether_addr(addr
->sa_data
))
224 return -EADDRNOTAVAIL
;
226 /* MAC addr configuration will be done in hardware for VFs
227 * by their corresponding PFs. Just copy to netdev addr here
229 if (!be_physfn(adapter
))
232 status
= be_cmd_pmac_del(adapter
, adapter
->if_handle
,
233 adapter
->pmac_id
, 0);
237 status
= be_cmd_pmac_add(adapter
, (u8
*)addr
->sa_data
,
238 adapter
->if_handle
, &adapter
->pmac_id
, 0);
241 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
246 static void populate_be2_stats(struct be_adapter
*adapter
)
249 struct be_drv_stats
*drvs
= &adapter
->drv_stats
;
250 struct be_pmem_stats
*pmem_sts
= be_pmem_stats_from_cmd(adapter
);
251 struct be_port_rxf_stats_v0
*port_stats
=
252 be_port_rxf_stats_from_cmd(adapter
);
253 struct be_rxf_stats_v0
*rxf_stats
=
254 be_rxf_stats_from_cmd(adapter
);
256 drvs
->rx_pause_frames
= port_stats
->rx_pause_frames
;
257 drvs
->rx_crc_errors
= port_stats
->rx_crc_errors
;
258 drvs
->rx_control_frames
= port_stats
->rx_control_frames
;
259 drvs
->rx_in_range_errors
= port_stats
->rx_in_range_errors
;
260 drvs
->rx_frame_too_long
= port_stats
->rx_frame_too_long
;
261 drvs
->rx_dropped_runt
= port_stats
->rx_dropped_runt
;
262 drvs
->rx_ip_checksum_errs
= port_stats
->rx_ip_checksum_errs
;
263 drvs
->rx_tcp_checksum_errs
= port_stats
->rx_tcp_checksum_errs
;
264 drvs
->rx_udp_checksum_errs
= port_stats
->rx_udp_checksum_errs
;
265 drvs
->rxpp_fifo_overflow_drop
= port_stats
->rx_fifo_overflow
;
266 drvs
->rx_dropped_tcp_length
= port_stats
->rx_dropped_tcp_length
;
267 drvs
->rx_dropped_too_small
= port_stats
->rx_dropped_too_small
;
268 drvs
->rx_dropped_too_short
= port_stats
->rx_dropped_too_short
;
269 drvs
->rx_out_range_errors
= port_stats
->rx_out_range_errors
;
270 drvs
->rx_input_fifo_overflow_drop
=
271 port_stats
->rx_input_fifo_overflow
;
272 drvs
->rx_dropped_header_too_small
=
273 port_stats
->rx_dropped_header_too_small
;
274 drvs
->rx_address_match_errors
=
275 port_stats
->rx_address_match_errors
;
276 drvs
->rx_alignment_symbol_errors
=
277 port_stats
->rx_alignment_symbol_errors
;
279 drvs
->tx_pauseframes
= port_stats
->tx_pauseframes
;
280 drvs
->tx_controlframes
= port_stats
->tx_controlframes
;
282 if (adapter
->port_num
)
283 drvs
->jabber_events
=
284 rxf_stats
->port1_jabber_events
;
286 drvs
->jabber_events
=
287 rxf_stats
->port0_jabber_events
;
288 drvs
->rx_drops_no_pbuf
= rxf_stats
->rx_drops_no_pbuf
;
289 drvs
->rx_drops_no_txpb
= rxf_stats
->rx_drops_no_txpb
;
290 drvs
->rx_drops_no_erx_descr
= rxf_stats
->rx_drops_no_erx_descr
;
291 drvs
->rx_drops_invalid_ring
= rxf_stats
->rx_drops_invalid_ring
;
292 drvs
->forwarded_packets
= rxf_stats
->forwarded_packets
;
293 drvs
->rx_drops_mtu
= rxf_stats
->rx_drops_mtu
;
294 drvs
->rx_drops_no_tpre_descr
=
295 rxf_stats
->rx_drops_no_tpre_descr
;
296 drvs
->rx_drops_too_many_frags
=
297 rxf_stats
->rx_drops_too_many_frags
;
298 adapter
->drv_stats
.eth_red_drops
= pmem_sts
->eth_red_drops
;
301 static void populate_be3_stats(struct be_adapter
*adapter
)
303 struct be_drv_stats
*drvs
= &adapter
->drv_stats
;
304 struct be_pmem_stats
*pmem_sts
= be_pmem_stats_from_cmd(adapter
);
306 struct be_rxf_stats_v1
*rxf_stats
=
307 be_rxf_stats_from_cmd(adapter
);
308 struct be_port_rxf_stats_v1
*port_stats
=
309 be_port_rxf_stats_from_cmd(adapter
);
311 drvs
->rx_priority_pause_frames
= 0;
312 drvs
->pmem_fifo_overflow_drop
= 0;
313 drvs
->rx_pause_frames
= port_stats
->rx_pause_frames
;
314 drvs
->rx_crc_errors
= port_stats
->rx_crc_errors
;
315 drvs
->rx_control_frames
= port_stats
->rx_control_frames
;
316 drvs
->rx_in_range_errors
= port_stats
->rx_in_range_errors
;
317 drvs
->rx_frame_too_long
= port_stats
->rx_frame_too_long
;
318 drvs
->rx_dropped_runt
= port_stats
->rx_dropped_runt
;
319 drvs
->rx_ip_checksum_errs
= port_stats
->rx_ip_checksum_errs
;
320 drvs
->rx_tcp_checksum_errs
= port_stats
->rx_tcp_checksum_errs
;
321 drvs
->rx_udp_checksum_errs
= port_stats
->rx_udp_checksum_errs
;
322 drvs
->rx_dropped_tcp_length
= port_stats
->rx_dropped_tcp_length
;
323 drvs
->rx_dropped_too_small
= port_stats
->rx_dropped_too_small
;
324 drvs
->rx_dropped_too_short
= port_stats
->rx_dropped_too_short
;
325 drvs
->rx_out_range_errors
= port_stats
->rx_out_range_errors
;
326 drvs
->rx_dropped_header_too_small
=
327 port_stats
->rx_dropped_header_too_small
;
328 drvs
->rx_input_fifo_overflow_drop
=
329 port_stats
->rx_input_fifo_overflow_drop
;
330 drvs
->rx_address_match_errors
=
331 port_stats
->rx_address_match_errors
;
332 drvs
->rx_alignment_symbol_errors
=
333 port_stats
->rx_alignment_symbol_errors
;
334 drvs
->rxpp_fifo_overflow_drop
=
335 port_stats
->rxpp_fifo_overflow_drop
;
336 drvs
->tx_pauseframes
= port_stats
->tx_pauseframes
;
337 drvs
->tx_controlframes
= port_stats
->tx_controlframes
;
338 drvs
->jabber_events
= port_stats
->jabber_events
;
339 drvs
->rx_drops_no_pbuf
= rxf_stats
->rx_drops_no_pbuf
;
340 drvs
->rx_drops_no_txpb
= rxf_stats
->rx_drops_no_txpb
;
341 drvs
->rx_drops_no_erx_descr
= rxf_stats
->rx_drops_no_erx_descr
;
342 drvs
->rx_drops_invalid_ring
= rxf_stats
->rx_drops_invalid_ring
;
343 drvs
->forwarded_packets
= rxf_stats
->forwarded_packets
;
344 drvs
->rx_drops_mtu
= rxf_stats
->rx_drops_mtu
;
345 drvs
->rx_drops_no_tpre_descr
=
346 rxf_stats
->rx_drops_no_tpre_descr
;
347 drvs
->rx_drops_too_many_frags
=
348 rxf_stats
->rx_drops_too_many_frags
;
349 adapter
->drv_stats
.eth_red_drops
= pmem_sts
->eth_red_drops
;
352 static void populate_lancer_stats(struct be_adapter
*adapter
)
355 struct be_drv_stats
*drvs
= &adapter
->drv_stats
;
356 struct lancer_cmd_pport_stats
*pport_stats
= pport_stats_from_cmd
358 drvs
->rx_priority_pause_frames
= 0;
359 drvs
->pmem_fifo_overflow_drop
= 0;
360 drvs
->rx_pause_frames
=
361 make_64bit_val(pport_stats
->rx_pause_frames_hi
,
362 pport_stats
->rx_pause_frames_lo
);
363 drvs
->rx_crc_errors
= make_64bit_val(pport_stats
->rx_crc_errors_hi
,
364 pport_stats
->rx_crc_errors_lo
);
365 drvs
->rx_control_frames
=
366 make_64bit_val(pport_stats
->rx_control_frames_hi
,
367 pport_stats
->rx_control_frames_lo
);
368 drvs
->rx_in_range_errors
= pport_stats
->rx_in_range_errors
;
369 drvs
->rx_frame_too_long
=
370 make_64bit_val(pport_stats
->rx_internal_mac_errors_hi
,
371 pport_stats
->rx_frames_too_long_lo
);
372 drvs
->rx_dropped_runt
= pport_stats
->rx_dropped_runt
;
373 drvs
->rx_ip_checksum_errs
= pport_stats
->rx_ip_checksum_errors
;
374 drvs
->rx_tcp_checksum_errs
= pport_stats
->rx_tcp_checksum_errors
;
375 drvs
->rx_udp_checksum_errs
= pport_stats
->rx_udp_checksum_errors
;
376 drvs
->rx_dropped_tcp_length
=
377 pport_stats
->rx_dropped_invalid_tcp_length
;
378 drvs
->rx_dropped_too_small
= pport_stats
->rx_dropped_too_small
;
379 drvs
->rx_dropped_too_short
= pport_stats
->rx_dropped_too_short
;
380 drvs
->rx_out_range_errors
= pport_stats
->rx_out_of_range_errors
;
381 drvs
->rx_dropped_header_too_small
=
382 pport_stats
->rx_dropped_header_too_small
;
383 drvs
->rx_input_fifo_overflow_drop
= pport_stats
->rx_fifo_overflow
;
384 drvs
->rx_address_match_errors
= pport_stats
->rx_address_match_errors
;
385 drvs
->rx_alignment_symbol_errors
=
386 make_64bit_val(pport_stats
->rx_symbol_errors_hi
,
387 pport_stats
->rx_symbol_errors_lo
);
388 drvs
->rxpp_fifo_overflow_drop
= pport_stats
->rx_fifo_overflow
;
389 drvs
->tx_pauseframes
= make_64bit_val(pport_stats
->tx_pause_frames_hi
,
390 pport_stats
->tx_pause_frames_lo
);
391 drvs
->tx_controlframes
=
392 make_64bit_val(pport_stats
->tx_control_frames_hi
,
393 pport_stats
->tx_control_frames_lo
);
394 drvs
->jabber_events
= pport_stats
->rx_jabbers
;
395 drvs
->rx_drops_no_pbuf
= 0;
396 drvs
->rx_drops_no_txpb
= 0;
397 drvs
->rx_drops_no_erx_descr
= 0;
398 drvs
->rx_drops_invalid_ring
= pport_stats
->rx_drops_invalid_queue
;
399 drvs
->forwarded_packets
= make_64bit_val(pport_stats
->num_forwards_hi
,
400 pport_stats
->num_forwards_lo
);
401 drvs
->rx_drops_mtu
= make_64bit_val(pport_stats
->rx_drops_mtu_hi
,
402 pport_stats
->rx_drops_mtu_lo
);
403 drvs
->rx_drops_no_tpre_descr
= 0;
404 drvs
->rx_drops_too_many_frags
=
405 make_64bit_val(pport_stats
->rx_drops_too_many_frags_hi
,
406 pport_stats
->rx_drops_too_many_frags_lo
);
409 void be_parse_stats(struct be_adapter
*adapter
)
411 if (adapter
->generation
== BE_GEN3
) {
412 if (lancer_chip(adapter
))
413 populate_lancer_stats(adapter
);
415 populate_be3_stats(adapter
);
417 populate_be2_stats(adapter
);
421 void netdev_stats_update(struct be_adapter
*adapter
)
423 struct be_drv_stats
*drvs
= &adapter
->drv_stats
;
424 struct net_device_stats
*dev_stats
= &adapter
->netdev
->stats
;
425 struct be_rx_obj
*rxo
;
426 struct be_tx_obj
*txo
;
427 unsigned long pkts
= 0, bytes
= 0, mcast
= 0, drops
= 0;
430 for_all_rx_queues(adapter
, rxo
, i
) {
431 pkts
+= rx_stats(rxo
)->rx_pkts
;
432 bytes
+= rx_stats(rxo
)->rx_bytes
;
433 mcast
+= rx_stats(rxo
)->rx_mcast_pkts
;
434 drops
+= rx_stats(rxo
)->rx_dropped
;
435 /* no space in linux buffers: best possible approximation */
436 if (adapter
->generation
== BE_GEN3
) {
437 if (!(lancer_chip(adapter
))) {
438 struct be_erx_stats_v1
*erx
=
439 be_erx_stats_from_cmd(adapter
);
440 drops
+= erx
->rx_drops_no_fragments
[rxo
->q
.id
];
443 struct be_erx_stats_v0
*erx
=
444 be_erx_stats_from_cmd(adapter
);
445 drops
+= erx
->rx_drops_no_fragments
[rxo
->q
.id
];
448 dev_stats
->rx_packets
= pkts
;
449 dev_stats
->rx_bytes
= bytes
;
450 dev_stats
->multicast
= mcast
;
451 dev_stats
->rx_dropped
= drops
;
454 for_all_tx_queues(adapter
, txo
, i
) {
455 pkts
+= tx_stats(txo
)->be_tx_pkts
;
456 bytes
+= tx_stats(txo
)->be_tx_bytes
;
458 dev_stats
->tx_packets
= pkts
;
459 dev_stats
->tx_bytes
= bytes
;
461 /* bad pkts received */
462 dev_stats
->rx_errors
= drvs
->rx_crc_errors
+
463 drvs
->rx_alignment_symbol_errors
+
464 drvs
->rx_in_range_errors
+
465 drvs
->rx_out_range_errors
+
466 drvs
->rx_frame_too_long
+
467 drvs
->rx_dropped_too_small
+
468 drvs
->rx_dropped_too_short
+
469 drvs
->rx_dropped_header_too_small
+
470 drvs
->rx_dropped_tcp_length
+
471 drvs
->rx_dropped_runt
+
472 drvs
->rx_tcp_checksum_errs
+
473 drvs
->rx_ip_checksum_errs
+
474 drvs
->rx_udp_checksum_errs
;
476 /* detailed rx errors */
477 dev_stats
->rx_length_errors
= drvs
->rx_in_range_errors
+
478 drvs
->rx_out_range_errors
+
479 drvs
->rx_frame_too_long
;
481 dev_stats
->rx_crc_errors
= drvs
->rx_crc_errors
;
483 /* frame alignment errors */
484 dev_stats
->rx_frame_errors
= drvs
->rx_alignment_symbol_errors
;
486 /* receiver fifo overrun */
487 /* drops_no_pbuf is no per i/f, it's per BE card */
488 dev_stats
->rx_fifo_errors
= drvs
->rxpp_fifo_overflow_drop
+
489 drvs
->rx_input_fifo_overflow_drop
+
490 drvs
->rx_drops_no_pbuf
;
493 void be_link_status_update(struct be_adapter
*adapter
, bool link_up
)
495 struct net_device
*netdev
= adapter
->netdev
;
497 /* If link came up or went down */
498 if (adapter
->link_up
!= link_up
) {
499 adapter
->link_speed
= -1;
501 netif_carrier_on(netdev
);
502 printk(KERN_INFO
"%s: Link up\n", netdev
->name
);
504 netif_carrier_off(netdev
);
505 printk(KERN_INFO
"%s: Link down\n", netdev
->name
);
507 adapter
->link_up
= link_up
;
511 /* Update the EQ delay n BE based on the RX frags consumed / sec */
512 static void be_rx_eqd_update(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
)
514 struct be_eq_obj
*rx_eq
= &rxo
->rx_eq
;
515 struct be_rx_stats
*stats
= &rxo
->stats
;
519 if (!rx_eq
->enable_aic
)
523 if (time_before(now
, stats
->rx_fps_jiffies
)) {
524 stats
->rx_fps_jiffies
= now
;
528 /* Update once a second */
529 if ((now
- stats
->rx_fps_jiffies
) < HZ
)
532 stats
->rx_fps
= (stats
->rx_frags
- stats
->prev_rx_frags
) /
533 ((now
- stats
->rx_fps_jiffies
) / HZ
);
535 stats
->rx_fps_jiffies
= now
;
536 stats
->prev_rx_frags
= stats
->rx_frags
;
537 eqd
= stats
->rx_fps
/ 110000;
539 if (eqd
> rx_eq
->max_eqd
)
540 eqd
= rx_eq
->max_eqd
;
541 if (eqd
< rx_eq
->min_eqd
)
542 eqd
= rx_eq
->min_eqd
;
545 if (eqd
!= rx_eq
->cur_eqd
)
546 be_cmd_modify_eqd(adapter
, rx_eq
->q
.id
, eqd
);
548 rx_eq
->cur_eqd
= eqd
;
551 static u32
be_calc_rate(u64 bytes
, unsigned long ticks
)
555 do_div(rate
, ticks
/ HZ
);
556 rate
<<= 3; /* bytes/sec -> bits/sec */
557 do_div(rate
, 1000000ul); /* MB/Sec */
562 static void be_tx_rate_update(struct be_tx_obj
*txo
)
564 struct be_tx_stats
*stats
= tx_stats(txo
);
567 /* Wrapped around? */
568 if (time_before(now
, stats
->be_tx_jiffies
)) {
569 stats
->be_tx_jiffies
= now
;
573 /* Update tx rate once in two seconds */
574 if ((now
- stats
->be_tx_jiffies
) > 2 * HZ
) {
575 stats
->be_tx_rate
= be_calc_rate(stats
->be_tx_bytes
576 - stats
->be_tx_bytes_prev
,
577 now
- stats
->be_tx_jiffies
);
578 stats
->be_tx_jiffies
= now
;
579 stats
->be_tx_bytes_prev
= stats
->be_tx_bytes
;
583 static void be_tx_stats_update(struct be_tx_obj
*txo
,
584 u32 wrb_cnt
, u32 copied
, u32 gso_segs
, bool stopped
)
586 struct be_tx_stats
*stats
= tx_stats(txo
);
589 stats
->be_tx_wrbs
+= wrb_cnt
;
590 stats
->be_tx_bytes
+= copied
;
591 stats
->be_tx_pkts
+= (gso_segs
? gso_segs
: 1);
593 stats
->be_tx_stops
++;
596 /* Determine number of WRB entries needed to xmit data in an skb */
597 static u32
wrb_cnt_for_skb(struct be_adapter
*adapter
, struct sk_buff
*skb
,
600 int cnt
= (skb
->len
> skb
->data_len
);
602 cnt
+= skb_shinfo(skb
)->nr_frags
;
604 /* to account for hdr wrb */
606 if (lancer_chip(adapter
) || !(cnt
& 1)) {
609 /* add a dummy to make it an even num */
613 BUG_ON(cnt
> BE_MAX_TX_FRAG_COUNT
);
617 static inline void wrb_fill(struct be_eth_wrb
*wrb
, u64 addr
, int len
)
619 wrb
->frag_pa_hi
= upper_32_bits(addr
);
620 wrb
->frag_pa_lo
= addr
& 0xFFFFFFFF;
621 wrb
->frag_len
= len
& ETH_WRB_FRAG_LEN_MASK
;
624 static void wrb_fill_hdr(struct be_adapter
*adapter
, struct be_eth_hdr_wrb
*hdr
,
625 struct sk_buff
*skb
, u32 wrb_cnt
, u32 len
)
630 memset(hdr
, 0, sizeof(*hdr
));
632 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, crc
, hdr
, 1);
634 if (skb_is_gso(skb
)) {
635 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso
, hdr
, 1);
636 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso_mss
,
637 hdr
, skb_shinfo(skb
)->gso_size
);
638 if (skb_is_gso_v6(skb
) && !lancer_chip(adapter
))
639 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, lso6
, hdr
, 1);
640 if (lancer_chip(adapter
) && adapter
->sli_family
==
641 LANCER_A0_SLI_FAMILY
) {
642 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, ipcs
, hdr
, 1);
644 AMAP_SET_BITS(struct amap_eth_hdr_wrb
,
646 else if (is_udp_pkt(skb
))
647 AMAP_SET_BITS(struct amap_eth_hdr_wrb
,
650 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
652 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, tcpcs
, hdr
, 1);
653 else if (is_udp_pkt(skb
))
654 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, udpcs
, hdr
, 1);
657 if (vlan_tx_tag_present(skb
)) {
658 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan
, hdr
, 1);
659 vlan_tag
= vlan_tx_tag_get(skb
);
660 vlan_prio
= (vlan_tag
& VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
661 /* If vlan priority provided by OS is NOT in available bmap */
662 if (!(adapter
->vlan_prio_bmap
& (1 << vlan_prio
)))
663 vlan_tag
= (vlan_tag
& ~VLAN_PRIO_MASK
) |
664 adapter
->recommended_prio
;
665 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, vlan_tag
, hdr
, vlan_tag
);
668 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, event
, hdr
, 1);
669 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, complete
, hdr
, 1);
670 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, num_wrb
, hdr
, wrb_cnt
);
671 AMAP_SET_BITS(struct amap_eth_hdr_wrb
, len
, hdr
, len
);
674 static void unmap_tx_frag(struct device
*dev
, struct be_eth_wrb
*wrb
,
679 be_dws_le_to_cpu(wrb
, sizeof(*wrb
));
681 dma
= (u64
)wrb
->frag_pa_hi
<< 32 | (u64
)wrb
->frag_pa_lo
;
684 dma_unmap_single(dev
, dma
, wrb
->frag_len
,
687 dma_unmap_page(dev
, dma
, wrb
->frag_len
, DMA_TO_DEVICE
);
691 static int make_tx_wrbs(struct be_adapter
*adapter
, struct be_queue_info
*txq
,
692 struct sk_buff
*skb
, u32 wrb_cnt
, bool dummy_wrb
)
696 struct device
*dev
= &adapter
->pdev
->dev
;
697 struct sk_buff
*first_skb
= skb
;
698 struct be_eth_wrb
*wrb
;
699 struct be_eth_hdr_wrb
*hdr
;
700 bool map_single
= false;
703 hdr
= queue_head_node(txq
);
705 map_head
= txq
->head
;
707 if (skb
->len
> skb
->data_len
) {
708 int len
= skb_headlen(skb
);
709 busaddr
= dma_map_single(dev
, skb
->data
, len
, DMA_TO_DEVICE
);
710 if (dma_mapping_error(dev
, busaddr
))
713 wrb
= queue_head_node(txq
);
714 wrb_fill(wrb
, busaddr
, len
);
715 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
720 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
721 struct skb_frag_struct
*frag
=
722 &skb_shinfo(skb
)->frags
[i
];
723 busaddr
= dma_map_page(dev
, frag
->page
, frag
->page_offset
,
724 frag
->size
, DMA_TO_DEVICE
);
725 if (dma_mapping_error(dev
, busaddr
))
727 wrb
= queue_head_node(txq
);
728 wrb_fill(wrb
, busaddr
, frag
->size
);
729 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
731 copied
+= frag
->size
;
735 wrb
= queue_head_node(txq
);
737 be_dws_cpu_to_le(wrb
, sizeof(*wrb
));
741 wrb_fill_hdr(adapter
, hdr
, first_skb
, wrb_cnt
, copied
);
742 be_dws_cpu_to_le(hdr
, sizeof(*hdr
));
746 txq
->head
= map_head
;
748 wrb
= queue_head_node(txq
);
749 unmap_tx_frag(dev
, wrb
, map_single
);
751 copied
-= wrb
->frag_len
;
757 static netdev_tx_t
be_xmit(struct sk_buff
*skb
,
758 struct net_device
*netdev
)
760 struct be_adapter
*adapter
= netdev_priv(netdev
);
761 struct be_tx_obj
*txo
= &adapter
->tx_obj
[skb_get_queue_mapping(skb
)];
762 struct be_queue_info
*txq
= &txo
->q
;
763 u32 wrb_cnt
= 0, copied
= 0;
764 u32 start
= txq
->head
;
765 bool dummy_wrb
, stopped
= false;
767 wrb_cnt
= wrb_cnt_for_skb(adapter
, skb
, &dummy_wrb
);
769 copied
= make_tx_wrbs(adapter
, txq
, skb
, wrb_cnt
, dummy_wrb
);
771 /* record the sent skb in the sent_skb table */
772 BUG_ON(txo
->sent_skb_list
[start
]);
773 txo
->sent_skb_list
[start
] = skb
;
775 /* Ensure txq has space for the next skb; Else stop the queue
776 * *BEFORE* ringing the tx doorbell, so that we serialze the
777 * tx compls of the current transmit which'll wake up the queue
779 atomic_add(wrb_cnt
, &txq
->used
);
780 if ((BE_MAX_TX_FRAG_COUNT
+ atomic_read(&txq
->used
)) >=
782 netif_stop_subqueue(netdev
, skb_get_queue_mapping(skb
));
786 be_txq_notify(adapter
, txq
->id
, wrb_cnt
);
788 be_tx_stats_update(txo
, wrb_cnt
, copied
,
789 skb_shinfo(skb
)->gso_segs
, stopped
);
792 dev_kfree_skb_any(skb
);
797 static int be_change_mtu(struct net_device
*netdev
, int new_mtu
)
799 struct be_adapter
*adapter
= netdev_priv(netdev
);
800 if (new_mtu
< BE_MIN_MTU
||
801 new_mtu
> (BE_MAX_JUMBO_FRAME_SIZE
-
802 (ETH_HLEN
+ ETH_FCS_LEN
))) {
803 dev_info(&adapter
->pdev
->dev
,
804 "MTU must be between %d and %d bytes\n",
806 (BE_MAX_JUMBO_FRAME_SIZE
- (ETH_HLEN
+ ETH_FCS_LEN
)));
809 dev_info(&adapter
->pdev
->dev
, "MTU changed from %d to %d bytes\n",
810 netdev
->mtu
, new_mtu
);
811 netdev
->mtu
= new_mtu
;
816 * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE.
817 * If the user configures more, place BE in vlan promiscuous mode.
819 static int be_vid_config(struct be_adapter
*adapter
, bool vf
, u32 vf_num
)
821 u16 vtag
[BE_NUM_VLANS_SUPPORTED
];
827 if_handle
= adapter
->vf_cfg
[vf_num
].vf_if_handle
;
828 vtag
[0] = cpu_to_le16(adapter
->vf_cfg
[vf_num
].vf_vlan_tag
);
829 status
= be_cmd_vlan_config(adapter
, if_handle
, vtag
, 1, 1, 0);
832 if (adapter
->vlans_added
<= adapter
->max_vlans
) {
833 /* Construct VLAN Table to give to HW */
834 for (i
= 0; i
< VLAN_N_VID
; i
++) {
835 if (adapter
->vlan_tag
[i
]) {
836 vtag
[ntags
] = cpu_to_le16(i
);
840 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
843 status
= be_cmd_vlan_config(adapter
, adapter
->if_handle
,
850 static void be_vlan_add_vid(struct net_device
*netdev
, u16 vid
)
852 struct be_adapter
*adapter
= netdev_priv(netdev
);
854 adapter
->vlans_added
++;
855 if (!be_physfn(adapter
))
858 adapter
->vlan_tag
[vid
] = 1;
859 if (adapter
->vlans_added
<= (adapter
->max_vlans
+ 1))
860 be_vid_config(adapter
, false, 0);
863 static void be_vlan_rem_vid(struct net_device
*netdev
, u16 vid
)
865 struct be_adapter
*adapter
= netdev_priv(netdev
);
867 adapter
->vlans_added
--;
869 if (!be_physfn(adapter
))
872 adapter
->vlan_tag
[vid
] = 0;
873 if (adapter
->vlans_added
<= adapter
->max_vlans
)
874 be_vid_config(adapter
, false, 0);
877 static void be_set_multicast_list(struct net_device
*netdev
)
879 struct be_adapter
*adapter
= netdev_priv(netdev
);
881 if (netdev
->flags
& IFF_PROMISC
) {
882 be_cmd_promiscuous_config(adapter
, true);
883 adapter
->promiscuous
= true;
887 /* BE was previously in promiscuous mode; disable it */
888 if (adapter
->promiscuous
) {
889 adapter
->promiscuous
= false;
890 be_cmd_promiscuous_config(adapter
, false);
893 /* Enable multicast promisc if num configured exceeds what we support */
894 if (netdev
->flags
& IFF_ALLMULTI
||
895 netdev_mc_count(netdev
) > BE_MAX_MC
) {
896 be_cmd_multicast_set(adapter
, adapter
->if_handle
, NULL
,
897 &adapter
->mc_cmd_mem
);
901 be_cmd_multicast_set(adapter
, adapter
->if_handle
, netdev
,
902 &adapter
->mc_cmd_mem
);
907 static int be_set_vf_mac(struct net_device
*netdev
, int vf
, u8
*mac
)
909 struct be_adapter
*adapter
= netdev_priv(netdev
);
912 if (!adapter
->sriov_enabled
)
915 if (!is_valid_ether_addr(mac
) || (vf
>= num_vfs
))
918 if (adapter
->vf_cfg
[vf
].vf_pmac_id
!= BE_INVALID_PMAC_ID
)
919 status
= be_cmd_pmac_del(adapter
,
920 adapter
->vf_cfg
[vf
].vf_if_handle
,
921 adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
923 status
= be_cmd_pmac_add(adapter
, mac
,
924 adapter
->vf_cfg
[vf
].vf_if_handle
,
925 &adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
928 dev_err(&adapter
->pdev
->dev
, "MAC %pM set on VF %d Failed\n",
931 memcpy(adapter
->vf_cfg
[vf
].vf_mac_addr
, mac
, ETH_ALEN
);
936 static int be_get_vf_config(struct net_device
*netdev
, int vf
,
937 struct ifla_vf_info
*vi
)
939 struct be_adapter
*adapter
= netdev_priv(netdev
);
941 if (!adapter
->sriov_enabled
)
948 vi
->tx_rate
= adapter
->vf_cfg
[vf
].vf_tx_rate
;
949 vi
->vlan
= adapter
->vf_cfg
[vf
].vf_vlan_tag
;
951 memcpy(&vi
->mac
, adapter
->vf_cfg
[vf
].vf_mac_addr
, ETH_ALEN
);
956 static int be_set_vf_vlan(struct net_device
*netdev
,
957 int vf
, u16 vlan
, u8 qos
)
959 struct be_adapter
*adapter
= netdev_priv(netdev
);
962 if (!adapter
->sriov_enabled
)
965 if ((vf
>= num_vfs
) || (vlan
> 4095))
969 adapter
->vf_cfg
[vf
].vf_vlan_tag
= vlan
;
970 adapter
->vlans_added
++;
972 adapter
->vf_cfg
[vf
].vf_vlan_tag
= 0;
973 adapter
->vlans_added
--;
976 status
= be_vid_config(adapter
, true, vf
);
979 dev_info(&adapter
->pdev
->dev
,
980 "VLAN %d config on VF %d failed\n", vlan
, vf
);
984 static int be_set_vf_tx_rate(struct net_device
*netdev
,
987 struct be_adapter
*adapter
= netdev_priv(netdev
);
990 if (!adapter
->sriov_enabled
)
993 if ((vf
>= num_vfs
) || (rate
< 0))
999 adapter
->vf_cfg
[vf
].vf_tx_rate
= rate
;
1000 status
= be_cmd_set_qos(adapter
, rate
/ 10, vf
+ 1);
1003 dev_info(&adapter
->pdev
->dev
,
1004 "tx rate %d on VF %d failed\n", rate
, vf
);
1008 static void be_rx_rate_update(struct be_rx_obj
*rxo
)
1010 struct be_rx_stats
*stats
= &rxo
->stats
;
1011 ulong now
= jiffies
;
1013 /* Wrapped around */
1014 if (time_before(now
, stats
->rx_jiffies
)) {
1015 stats
->rx_jiffies
= now
;
1019 /* Update the rate once in two seconds */
1020 if ((now
- stats
->rx_jiffies
) < 2 * HZ
)
1023 stats
->rx_rate
= be_calc_rate(stats
->rx_bytes
- stats
->rx_bytes_prev
,
1024 now
- stats
->rx_jiffies
);
1025 stats
->rx_jiffies
= now
;
1026 stats
->rx_bytes_prev
= stats
->rx_bytes
;
1029 static void be_rx_stats_update(struct be_rx_obj
*rxo
,
1030 struct be_rx_compl_info
*rxcp
)
1032 struct be_rx_stats
*stats
= &rxo
->stats
;
1035 stats
->rx_frags
+= rxcp
->num_rcvd
;
1036 stats
->rx_bytes
+= rxcp
->pkt_size
;
1038 if (rxcp
->pkt_type
== BE_MULTICAST_PACKET
)
1039 stats
->rx_mcast_pkts
++;
1044 static inline bool csum_passed(struct be_rx_compl_info
*rxcp
)
1046 /* L4 checksum is not reliable for non TCP/UDP packets.
1047 * Also ignore ipcksm for ipv6 pkts */
1048 return (rxcp
->tcpf
|| rxcp
->udpf
) && rxcp
->l4_csum
&&
1049 (rxcp
->ip_csum
|| rxcp
->ipv6
);
1052 static struct be_rx_page_info
*
1053 get_rx_page_info(struct be_adapter
*adapter
,
1054 struct be_rx_obj
*rxo
,
1057 struct be_rx_page_info
*rx_page_info
;
1058 struct be_queue_info
*rxq
= &rxo
->q
;
1060 rx_page_info
= &rxo
->page_info_tbl
[frag_idx
];
1061 BUG_ON(!rx_page_info
->page
);
1063 if (rx_page_info
->last_page_user
) {
1064 dma_unmap_page(&adapter
->pdev
->dev
,
1065 dma_unmap_addr(rx_page_info
, bus
),
1066 adapter
->big_page_size
, DMA_FROM_DEVICE
);
1067 rx_page_info
->last_page_user
= false;
1070 atomic_dec(&rxq
->used
);
1071 return rx_page_info
;
1074 /* Throwaway the data in the Rx completion */
1075 static void be_rx_compl_discard(struct be_adapter
*adapter
,
1076 struct be_rx_obj
*rxo
,
1077 struct be_rx_compl_info
*rxcp
)
1079 struct be_queue_info
*rxq
= &rxo
->q
;
1080 struct be_rx_page_info
*page_info
;
1081 u16 i
, num_rcvd
= rxcp
->num_rcvd
;
1083 for (i
= 0; i
< num_rcvd
; i
++) {
1084 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
1085 put_page(page_info
->page
);
1086 memset(page_info
, 0, sizeof(*page_info
));
1087 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
1092 * skb_fill_rx_data forms a complete skb for an ether frame
1093 * indicated by rxcp.
1095 static void skb_fill_rx_data(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
,
1096 struct sk_buff
*skb
, struct be_rx_compl_info
*rxcp
)
1098 struct be_queue_info
*rxq
= &rxo
->q
;
1099 struct be_rx_page_info
*page_info
;
1101 u16 hdr_len
, curr_frag_len
, remaining
;
1104 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
1105 start
= page_address(page_info
->page
) + page_info
->page_offset
;
1108 /* Copy data in the first descriptor of this completion */
1109 curr_frag_len
= min(rxcp
->pkt_size
, rx_frag_size
);
1111 /* Copy the header portion into skb_data */
1112 hdr_len
= min(BE_HDR_LEN
, curr_frag_len
);
1113 memcpy(skb
->data
, start
, hdr_len
);
1114 skb
->len
= curr_frag_len
;
1115 if (curr_frag_len
<= BE_HDR_LEN
) { /* tiny packet */
1116 /* Complete packet has now been moved to data */
1117 put_page(page_info
->page
);
1119 skb
->tail
+= curr_frag_len
;
1121 skb_shinfo(skb
)->nr_frags
= 1;
1122 skb_shinfo(skb
)->frags
[0].page
= page_info
->page
;
1123 skb_shinfo(skb
)->frags
[0].page_offset
=
1124 page_info
->page_offset
+ hdr_len
;
1125 skb_shinfo(skb
)->frags
[0].size
= curr_frag_len
- hdr_len
;
1126 skb
->data_len
= curr_frag_len
- hdr_len
;
1127 skb
->tail
+= hdr_len
;
1129 page_info
->page
= NULL
;
1131 if (rxcp
->pkt_size
<= rx_frag_size
) {
1132 BUG_ON(rxcp
->num_rcvd
!= 1);
1136 /* More frags present for this completion */
1137 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
1138 remaining
= rxcp
->pkt_size
- curr_frag_len
;
1139 for (i
= 1, j
= 0; i
< rxcp
->num_rcvd
; i
++) {
1140 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
1141 curr_frag_len
= min(remaining
, rx_frag_size
);
1143 /* Coalesce all frags from the same physical page in one slot */
1144 if (page_info
->page_offset
== 0) {
1147 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
1148 skb_shinfo(skb
)->frags
[j
].page_offset
=
1149 page_info
->page_offset
;
1150 skb_shinfo(skb
)->frags
[j
].size
= 0;
1151 skb_shinfo(skb
)->nr_frags
++;
1153 put_page(page_info
->page
);
1156 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
1157 skb
->len
+= curr_frag_len
;
1158 skb
->data_len
+= curr_frag_len
;
1160 remaining
-= curr_frag_len
;
1161 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
1162 page_info
->page
= NULL
;
1164 BUG_ON(j
> MAX_SKB_FRAGS
);
1167 /* Process the RX completion indicated by rxcp when GRO is disabled */
1168 static void be_rx_compl_process(struct be_adapter
*adapter
,
1169 struct be_rx_obj
*rxo
,
1170 struct be_rx_compl_info
*rxcp
)
1172 struct net_device
*netdev
= adapter
->netdev
;
1173 struct sk_buff
*skb
;
1175 skb
= netdev_alloc_skb_ip_align(netdev
, BE_HDR_LEN
);
1176 if (unlikely(!skb
)) {
1177 rxo
->stats
.rx_dropped
++;
1178 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1182 skb_fill_rx_data(adapter
, rxo
, skb
, rxcp
);
1184 if (likely((netdev
->features
& NETIF_F_RXCSUM
) && csum_passed(rxcp
)))
1185 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1187 skb_checksum_none_assert(skb
);
1189 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1190 skb
->protocol
= eth_type_trans(skb
, netdev
);
1191 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1192 skb
->rxhash
= rxcp
->rss_hash
;
1195 if (unlikely(rxcp
->vlanf
))
1196 __vlan_hwaccel_put_tag(skb
, rxcp
->vlan_tag
);
1198 netif_receive_skb(skb
);
1201 /* Process the RX completion indicated by rxcp when GRO is enabled */
1202 static void be_rx_compl_process_gro(struct be_adapter
*adapter
,
1203 struct be_rx_obj
*rxo
,
1204 struct be_rx_compl_info
*rxcp
)
1206 struct be_rx_page_info
*page_info
;
1207 struct sk_buff
*skb
= NULL
;
1208 struct be_queue_info
*rxq
= &rxo
->q
;
1209 struct be_eq_obj
*eq_obj
= &rxo
->rx_eq
;
1210 u16 remaining
, curr_frag_len
;
1213 skb
= napi_get_frags(&eq_obj
->napi
);
1215 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1219 remaining
= rxcp
->pkt_size
;
1220 for (i
= 0, j
= -1; i
< rxcp
->num_rcvd
; i
++) {
1221 page_info
= get_rx_page_info(adapter
, rxo
, rxcp
->rxq_idx
);
1223 curr_frag_len
= min(remaining
, rx_frag_size
);
1225 /* Coalesce all frags from the same physical page in one slot */
1226 if (i
== 0 || page_info
->page_offset
== 0) {
1227 /* First frag or Fresh page */
1229 skb_shinfo(skb
)->frags
[j
].page
= page_info
->page
;
1230 skb_shinfo(skb
)->frags
[j
].page_offset
=
1231 page_info
->page_offset
;
1232 skb_shinfo(skb
)->frags
[j
].size
= 0;
1234 put_page(page_info
->page
);
1236 skb_shinfo(skb
)->frags
[j
].size
+= curr_frag_len
;
1238 remaining
-= curr_frag_len
;
1239 index_inc(&rxcp
->rxq_idx
, rxq
->len
);
1240 memset(page_info
, 0, sizeof(*page_info
));
1242 BUG_ON(j
> MAX_SKB_FRAGS
);
1244 skb_shinfo(skb
)->nr_frags
= j
+ 1;
1245 skb
->len
= rxcp
->pkt_size
;
1246 skb
->data_len
= rxcp
->pkt_size
;
1247 skb
->truesize
+= rxcp
->pkt_size
;
1248 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1249 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1250 skb
->rxhash
= rxcp
->rss_hash
;
1252 if (unlikely(rxcp
->vlanf
))
1253 __vlan_hwaccel_put_tag(skb
, rxcp
->vlan_tag
);
1255 napi_gro_frags(&eq_obj
->napi
);
1258 static void be_parse_rx_compl_v1(struct be_adapter
*adapter
,
1259 struct be_eth_rx_compl
*compl,
1260 struct be_rx_compl_info
*rxcp
)
1263 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, pktsize
, compl);
1264 rxcp
->vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vtp
, compl);
1265 rxcp
->err
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, err
, compl);
1266 rxcp
->tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, tcpf
, compl);
1267 rxcp
->udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, udpf
, compl);
1269 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, ipcksm
, compl);
1271 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, l4_cksm
, compl);
1273 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, ip_version
, compl);
1275 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, fragndx
, compl);
1277 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, numfrags
, compl);
1279 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, cast_enc
, compl);
1281 AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, rsshash
, rxcp
);
1283 rxcp
->vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vtm
,
1285 rxcp
->vlan_tag
= AMAP_GET_BITS(struct amap_eth_rx_compl_v1
, vlan_tag
,
1290 static void be_parse_rx_compl_v0(struct be_adapter
*adapter
,
1291 struct be_eth_rx_compl
*compl,
1292 struct be_rx_compl_info
*rxcp
)
1295 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, pktsize
, compl);
1296 rxcp
->vlanf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vtp
, compl);
1297 rxcp
->err
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, err
, compl);
1298 rxcp
->tcpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, tcpf
, compl);
1299 rxcp
->udpf
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, udpf
, compl);
1301 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, ipcksm
, compl);
1303 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, l4_cksm
, compl);
1305 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, ip_version
, compl);
1307 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, fragndx
, compl);
1309 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, numfrags
, compl);
1311 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, cast_enc
, compl);
1313 AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, rsshash
, rxcp
);
1315 rxcp
->vtm
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vtm
,
1317 rxcp
->vlan_tag
= AMAP_GET_BITS(struct amap_eth_rx_compl_v0
, vlan_tag
,
1322 static struct be_rx_compl_info
*be_rx_compl_get(struct be_rx_obj
*rxo
)
1324 struct be_eth_rx_compl
*compl = queue_tail_node(&rxo
->cq
);
1325 struct be_rx_compl_info
*rxcp
= &rxo
->rxcp
;
1326 struct be_adapter
*adapter
= rxo
->adapter
;
1328 /* For checking the valid bit it is Ok to use either definition as the
1329 * valid bit is at the same position in both v0 and v1 Rx compl */
1330 if (compl->dw
[offsetof(struct amap_eth_rx_compl_v1
, valid
) / 32] == 0)
1334 be_dws_le_to_cpu(compl, sizeof(*compl));
1336 if (adapter
->be3_native
)
1337 be_parse_rx_compl_v1(adapter
, compl, rxcp
);
1339 be_parse_rx_compl_v0(adapter
, compl, rxcp
);
1342 /* vlanf could be wrongly set in some cards.
1343 * ignore if vtm is not set */
1344 if ((adapter
->function_mode
& 0x400) && !rxcp
->vtm
)
1347 if (!lancer_chip(adapter
))
1348 rxcp
->vlan_tag
= swab16(rxcp
->vlan_tag
);
1350 if (((adapter
->pvid
& VLAN_VID_MASK
) ==
1351 (rxcp
->vlan_tag
& VLAN_VID_MASK
)) &&
1352 !adapter
->vlan_tag
[rxcp
->vlan_tag
])
1356 /* As the compl has been parsed, reset it; we wont touch it again */
1357 compl->dw
[offsetof(struct amap_eth_rx_compl_v1
, valid
) / 32] = 0;
1359 queue_tail_inc(&rxo
->cq
);
1363 static inline struct page
*be_alloc_pages(u32 size
, gfp_t gfp
)
1365 u32 order
= get_order(size
);
1369 return alloc_pages(gfp
, order
);
1373 * Allocate a page, split it to fragments of size rx_frag_size and post as
1374 * receive buffers to BE
1376 static void be_post_rx_frags(struct be_rx_obj
*rxo
, gfp_t gfp
)
1378 struct be_adapter
*adapter
= rxo
->adapter
;
1379 struct be_rx_page_info
*page_info_tbl
= rxo
->page_info_tbl
;
1380 struct be_rx_page_info
*page_info
= NULL
, *prev_page_info
= NULL
;
1381 struct be_queue_info
*rxq
= &rxo
->q
;
1382 struct page
*pagep
= NULL
;
1383 struct be_eth_rx_d
*rxd
;
1384 u64 page_dmaaddr
= 0, frag_dmaaddr
;
1385 u32 posted
, page_offset
= 0;
1387 page_info
= &rxo
->page_info_tbl
[rxq
->head
];
1388 for (posted
= 0; posted
< MAX_RX_POST
&& !page_info
->page
; posted
++) {
1390 pagep
= be_alloc_pages(adapter
->big_page_size
, gfp
);
1391 if (unlikely(!pagep
)) {
1392 rxo
->stats
.rx_post_fail
++;
1395 page_dmaaddr
= dma_map_page(&adapter
->pdev
->dev
, pagep
,
1396 0, adapter
->big_page_size
,
1398 page_info
->page_offset
= 0;
1401 page_info
->page_offset
= page_offset
+ rx_frag_size
;
1403 page_offset
= page_info
->page_offset
;
1404 page_info
->page
= pagep
;
1405 dma_unmap_addr_set(page_info
, bus
, page_dmaaddr
);
1406 frag_dmaaddr
= page_dmaaddr
+ page_info
->page_offset
;
1408 rxd
= queue_head_node(rxq
);
1409 rxd
->fragpa_lo
= cpu_to_le32(frag_dmaaddr
& 0xFFFFFFFF);
1410 rxd
->fragpa_hi
= cpu_to_le32(upper_32_bits(frag_dmaaddr
));
1412 /* Any space left in the current big page for another frag? */
1413 if ((page_offset
+ rx_frag_size
+ rx_frag_size
) >
1414 adapter
->big_page_size
) {
1416 page_info
->last_page_user
= true;
1419 prev_page_info
= page_info
;
1420 queue_head_inc(rxq
);
1421 page_info
= &page_info_tbl
[rxq
->head
];
1424 prev_page_info
->last_page_user
= true;
1427 atomic_add(posted
, &rxq
->used
);
1428 be_rxq_notify(adapter
, rxq
->id
, posted
);
1429 } else if (atomic_read(&rxq
->used
) == 0) {
1430 /* Let be_worker replenish when memory is available */
1431 rxo
->rx_post_starved
= true;
1435 static struct be_eth_tx_compl
*be_tx_compl_get(struct be_queue_info
*tx_cq
)
1437 struct be_eth_tx_compl
*txcp
= queue_tail_node(tx_cq
);
1439 if (txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] == 0)
1443 be_dws_le_to_cpu(txcp
, sizeof(*txcp
));
1445 txcp
->dw
[offsetof(struct amap_eth_tx_compl
, valid
) / 32] = 0;
1447 queue_tail_inc(tx_cq
);
1451 static u16
be_tx_compl_process(struct be_adapter
*adapter
,
1452 struct be_tx_obj
*txo
, u16 last_index
)
1454 struct be_queue_info
*txq
= &txo
->q
;
1455 struct be_eth_wrb
*wrb
;
1456 struct sk_buff
**sent_skbs
= txo
->sent_skb_list
;
1457 struct sk_buff
*sent_skb
;
1458 u16 cur_index
, num_wrbs
= 1; /* account for hdr wrb */
1459 bool unmap_skb_hdr
= true;
1461 sent_skb
= sent_skbs
[txq
->tail
];
1463 sent_skbs
[txq
->tail
] = NULL
;
1465 /* skip header wrb */
1466 queue_tail_inc(txq
);
1469 cur_index
= txq
->tail
;
1470 wrb
= queue_tail_node(txq
);
1471 unmap_tx_frag(&adapter
->pdev
->dev
, wrb
,
1472 (unmap_skb_hdr
&& skb_headlen(sent_skb
)));
1473 unmap_skb_hdr
= false;
1476 queue_tail_inc(txq
);
1477 } while (cur_index
!= last_index
);
1479 kfree_skb(sent_skb
);
1483 static inline struct be_eq_entry
*event_get(struct be_eq_obj
*eq_obj
)
1485 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1491 eqe
->evt
= le32_to_cpu(eqe
->evt
);
1492 queue_tail_inc(&eq_obj
->q
);
1496 static int event_handle(struct be_adapter
*adapter
,
1497 struct be_eq_obj
*eq_obj
,
1500 struct be_eq_entry
*eqe
;
1503 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1508 /* Deal with any spurious interrupts that come
1514 be_eq_notify(adapter
, eq_obj
->q
.id
, rearm
, true, num
);
1516 napi_schedule(&eq_obj
->napi
);
1521 /* Just read and notify events without processing them.
1522 * Used at the time of destroying event queues */
1523 static void be_eq_clean(struct be_adapter
*adapter
,
1524 struct be_eq_obj
*eq_obj
)
1526 struct be_eq_entry
*eqe
;
1529 while ((eqe
= event_get(eq_obj
)) != NULL
) {
1535 be_eq_notify(adapter
, eq_obj
->q
.id
, false, true, num
);
1538 static void be_rx_q_clean(struct be_adapter
*adapter
, struct be_rx_obj
*rxo
)
1540 struct be_rx_page_info
*page_info
;
1541 struct be_queue_info
*rxq
= &rxo
->q
;
1542 struct be_queue_info
*rx_cq
= &rxo
->cq
;
1543 struct be_rx_compl_info
*rxcp
;
1546 /* First cleanup pending rx completions */
1547 while ((rxcp
= be_rx_compl_get(rxo
)) != NULL
) {
1548 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1549 be_cq_notify(adapter
, rx_cq
->id
, false, 1);
1552 /* Then free posted rx buffer that were not used */
1553 tail
= (rxq
->head
+ rxq
->len
- atomic_read(&rxq
->used
)) % rxq
->len
;
1554 for (; atomic_read(&rxq
->used
) > 0; index_inc(&tail
, rxq
->len
)) {
1555 page_info
= get_rx_page_info(adapter
, rxo
, tail
);
1556 put_page(page_info
->page
);
1557 memset(page_info
, 0, sizeof(*page_info
));
1559 BUG_ON(atomic_read(&rxq
->used
));
1560 rxq
->tail
= rxq
->head
= 0;
1563 static void be_tx_compl_clean(struct be_adapter
*adapter
,
1564 struct be_tx_obj
*txo
)
1566 struct be_queue_info
*tx_cq
= &txo
->cq
;
1567 struct be_queue_info
*txq
= &txo
->q
;
1568 struct be_eth_tx_compl
*txcp
;
1569 u16 end_idx
, cmpl
= 0, timeo
= 0, num_wrbs
= 0;
1570 struct sk_buff
**sent_skbs
= txo
->sent_skb_list
;
1571 struct sk_buff
*sent_skb
;
1574 /* Wait for a max of 200ms for all the tx-completions to arrive. */
1576 while ((txcp
= be_tx_compl_get(tx_cq
))) {
1577 end_idx
= AMAP_GET_BITS(struct amap_eth_tx_compl
,
1579 num_wrbs
+= be_tx_compl_process(adapter
, txo
, end_idx
);
1583 be_cq_notify(adapter
, tx_cq
->id
, false, cmpl
);
1584 atomic_sub(num_wrbs
, &txq
->used
);
1589 if (atomic_read(&txq
->used
) == 0 || ++timeo
> 200)
1595 if (atomic_read(&txq
->used
))
1596 dev_err(&adapter
->pdev
->dev
, "%d pending tx-completions\n",
1597 atomic_read(&txq
->used
));
1599 /* free posted tx for which compls will never arrive */
1600 while (atomic_read(&txq
->used
)) {
1601 sent_skb
= sent_skbs
[txq
->tail
];
1602 end_idx
= txq
->tail
;
1604 wrb_cnt_for_skb(adapter
, sent_skb
, &dummy_wrb
) - 1,
1606 num_wrbs
= be_tx_compl_process(adapter
, txo
, end_idx
);
1607 atomic_sub(num_wrbs
, &txq
->used
);
1611 static void be_mcc_queues_destroy(struct be_adapter
*adapter
)
1613 struct be_queue_info
*q
;
1615 q
= &adapter
->mcc_obj
.q
;
1617 be_cmd_q_destroy(adapter
, q
, QTYPE_MCCQ
);
1618 be_queue_free(adapter
, q
);
1620 q
= &adapter
->mcc_obj
.cq
;
1622 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1623 be_queue_free(adapter
, q
);
1626 /* Must be called only after TX qs are created as MCC shares TX EQ */
1627 static int be_mcc_queues_create(struct be_adapter
*adapter
)
1629 struct be_queue_info
*q
, *cq
;
1631 /* Alloc MCC compl queue */
1632 cq
= &adapter
->mcc_obj
.cq
;
1633 if (be_queue_alloc(adapter
, cq
, MCC_CQ_LEN
,
1634 sizeof(struct be_mcc_compl
)))
1637 /* Ask BE to create MCC compl queue; share TX's eq */
1638 if (be_cmd_cq_create(adapter
, cq
, &adapter
->tx_eq
.q
, false, true, 0))
1641 /* Alloc MCC queue */
1642 q
= &adapter
->mcc_obj
.q
;
1643 if (be_queue_alloc(adapter
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
1644 goto mcc_cq_destroy
;
1646 /* Ask BE to create MCC queue */
1647 if (be_cmd_mccq_create(adapter
, q
, cq
))
1653 be_queue_free(adapter
, q
);
1655 be_cmd_q_destroy(adapter
, cq
, QTYPE_CQ
);
1657 be_queue_free(adapter
, cq
);
1662 static void be_tx_queues_destroy(struct be_adapter
*adapter
)
1664 struct be_queue_info
*q
;
1665 struct be_tx_obj
*txo
;
1668 for_all_tx_queues(adapter
, txo
, i
) {
1671 be_cmd_q_destroy(adapter
, q
, QTYPE_TXQ
);
1672 be_queue_free(adapter
, q
);
1676 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1677 be_queue_free(adapter
, q
);
1680 /* Clear any residual events */
1681 be_eq_clean(adapter
, &adapter
->tx_eq
);
1683 q
= &adapter
->tx_eq
.q
;
1685 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1686 be_queue_free(adapter
, q
);
1689 /* One TX event queue is shared by all TX compl qs */
1690 static int be_tx_queues_create(struct be_adapter
*adapter
)
1692 struct be_queue_info
*eq
, *q
, *cq
;
1693 struct be_tx_obj
*txo
;
1696 adapter
->tx_eq
.max_eqd
= 0;
1697 adapter
->tx_eq
.min_eqd
= 0;
1698 adapter
->tx_eq
.cur_eqd
= 96;
1699 adapter
->tx_eq
.enable_aic
= false;
1701 eq
= &adapter
->tx_eq
.q
;
1702 if (be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
,
1703 sizeof(struct be_eq_entry
)))
1706 if (be_cmd_eq_create(adapter
, eq
, adapter
->tx_eq
.cur_eqd
))
1708 adapter
->tx_eq
.eq_idx
= adapter
->eq_next_idx
++;
1710 for_all_tx_queues(adapter
, txo
, i
) {
1712 if (be_queue_alloc(adapter
, cq
, TX_CQ_LEN
,
1713 sizeof(struct be_eth_tx_compl
)))
1716 if (be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3))
1720 if (be_queue_alloc(adapter
, q
, TX_Q_LEN
,
1721 sizeof(struct be_eth_wrb
)))
1724 if (be_cmd_txq_create(adapter
, q
, cq
))
1730 be_tx_queues_destroy(adapter
);
1734 static void be_rx_queues_destroy(struct be_adapter
*adapter
)
1736 struct be_queue_info
*q
;
1737 struct be_rx_obj
*rxo
;
1740 for_all_rx_queues(adapter
, rxo
, i
) {
1741 be_queue_free(adapter
, &rxo
->q
);
1745 be_cmd_q_destroy(adapter
, q
, QTYPE_CQ
);
1746 be_queue_free(adapter
, q
);
1750 be_cmd_q_destroy(adapter
, q
, QTYPE_EQ
);
1751 be_queue_free(adapter
, q
);
1755 static u32
be_num_rxqs_want(struct be_adapter
*adapter
)
1757 if ((adapter
->function_caps
& BE_FUNCTION_CAPS_RSS
) &&
1758 !adapter
->sriov_enabled
&& !(adapter
->function_mode
& 0x400)) {
1759 return 1 + MAX_RSS_QS
; /* one default non-RSS queue */
1761 dev_warn(&adapter
->pdev
->dev
,
1762 "No support for multiple RX queues\n");
1767 static int be_rx_queues_create(struct be_adapter
*adapter
)
1769 struct be_queue_info
*eq
, *q
, *cq
;
1770 struct be_rx_obj
*rxo
;
1773 adapter
->num_rx_qs
= min(be_num_rxqs_want(adapter
),
1774 msix_enabled(adapter
) ?
1775 adapter
->num_msix_vec
- 1 : 1);
1776 if (adapter
->num_rx_qs
!= MAX_RX_QS
)
1777 dev_warn(&adapter
->pdev
->dev
,
1778 "Can create only %d RX queues", adapter
->num_rx_qs
);
1780 adapter
->big_page_size
= (1 << get_order(rx_frag_size
)) * PAGE_SIZE
;
1781 for_all_rx_queues(adapter
, rxo
, i
) {
1782 rxo
->adapter
= adapter
;
1783 rxo
->rx_eq
.max_eqd
= BE_MAX_EQD
;
1784 rxo
->rx_eq
.enable_aic
= true;
1788 rc
= be_queue_alloc(adapter
, eq
, EVNT_Q_LEN
,
1789 sizeof(struct be_eq_entry
));
1793 rc
= be_cmd_eq_create(adapter
, eq
, rxo
->rx_eq
.cur_eqd
);
1797 rxo
->rx_eq
.eq_idx
= adapter
->eq_next_idx
++;
1801 rc
= be_queue_alloc(adapter
, cq
, RX_CQ_LEN
,
1802 sizeof(struct be_eth_rx_compl
));
1806 rc
= be_cmd_cq_create(adapter
, cq
, eq
, false, false, 3);
1810 /* Rx Q - will be created in be_open() */
1812 rc
= be_queue_alloc(adapter
, q
, RX_Q_LEN
,
1813 sizeof(struct be_eth_rx_d
));
1821 be_rx_queues_destroy(adapter
);
1825 static bool event_peek(struct be_eq_obj
*eq_obj
)
1827 struct be_eq_entry
*eqe
= queue_tail_node(&eq_obj
->q
);
1834 static irqreturn_t
be_intx(int irq
, void *dev
)
1836 struct be_adapter
*adapter
= dev
;
1837 struct be_rx_obj
*rxo
;
1838 int isr
, i
, tx
= 0 , rx
= 0;
1840 if (lancer_chip(adapter
)) {
1841 if (event_peek(&adapter
->tx_eq
))
1842 tx
= event_handle(adapter
, &adapter
->tx_eq
, false);
1843 for_all_rx_queues(adapter
, rxo
, i
) {
1844 if (event_peek(&rxo
->rx_eq
))
1845 rx
|= event_handle(adapter
, &rxo
->rx_eq
, true);
1852 isr
= ioread32(adapter
->csr
+ CEV_ISR0_OFFSET
+
1853 (adapter
->tx_eq
.q
.id
/ 8) * CEV_ISR_SIZE
);
1857 if ((1 << adapter
->tx_eq
.eq_idx
& isr
))
1858 event_handle(adapter
, &adapter
->tx_eq
, false);
1860 for_all_rx_queues(adapter
, rxo
, i
) {
1861 if ((1 << rxo
->rx_eq
.eq_idx
& isr
))
1862 event_handle(adapter
, &rxo
->rx_eq
, true);
1869 static irqreturn_t
be_msix_rx(int irq
, void *dev
)
1871 struct be_rx_obj
*rxo
= dev
;
1872 struct be_adapter
*adapter
= rxo
->adapter
;
1874 event_handle(adapter
, &rxo
->rx_eq
, true);
1879 static irqreturn_t
be_msix_tx_mcc(int irq
, void *dev
)
1881 struct be_adapter
*adapter
= dev
;
1883 event_handle(adapter
, &adapter
->tx_eq
, false);
1888 static inline bool do_gro(struct be_rx_compl_info
*rxcp
)
1890 return (rxcp
->tcpf
&& !rxcp
->err
) ? true : false;
1893 static int be_poll_rx(struct napi_struct
*napi
, int budget
)
1895 struct be_eq_obj
*rx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1896 struct be_rx_obj
*rxo
= container_of(rx_eq
, struct be_rx_obj
, rx_eq
);
1897 struct be_adapter
*adapter
= rxo
->adapter
;
1898 struct be_queue_info
*rx_cq
= &rxo
->cq
;
1899 struct be_rx_compl_info
*rxcp
;
1902 rxo
->stats
.rx_polls
++;
1903 for (work_done
= 0; work_done
< budget
; work_done
++) {
1904 rxcp
= be_rx_compl_get(rxo
);
1908 /* Ignore flush completions */
1909 if (rxcp
->num_rcvd
&& rxcp
->pkt_size
) {
1911 be_rx_compl_process_gro(adapter
, rxo
, rxcp
);
1913 be_rx_compl_process(adapter
, rxo
, rxcp
);
1914 } else if (rxcp
->pkt_size
== 0) {
1915 be_rx_compl_discard(adapter
, rxo
, rxcp
);
1918 be_rx_stats_update(rxo
, rxcp
);
1921 /* Refill the queue */
1922 if (atomic_read(&rxo
->q
.used
) < RX_FRAGS_REFILL_WM
)
1923 be_post_rx_frags(rxo
, GFP_ATOMIC
);
1926 if (work_done
< budget
) {
1927 napi_complete(napi
);
1928 be_cq_notify(adapter
, rx_cq
->id
, true, work_done
);
1930 /* More to be consumed; continue with interrupts disabled */
1931 be_cq_notify(adapter
, rx_cq
->id
, false, work_done
);
1936 /* As TX and MCC share the same EQ check for both TX and MCC completions.
1937 * For TX/MCC we don't honour budget; consume everything
1939 static int be_poll_tx_mcc(struct napi_struct
*napi
, int budget
)
1941 struct be_eq_obj
*tx_eq
= container_of(napi
, struct be_eq_obj
, napi
);
1942 struct be_adapter
*adapter
=
1943 container_of(tx_eq
, struct be_adapter
, tx_eq
);
1944 struct be_tx_obj
*txo
;
1945 struct be_eth_tx_compl
*txcp
;
1946 int tx_compl
, mcc_compl
, status
= 0;
1950 for_all_tx_queues(adapter
, txo
, i
) {
1953 while ((txcp
= be_tx_compl_get(&txo
->cq
))) {
1954 num_wrbs
+= be_tx_compl_process(adapter
, txo
,
1955 AMAP_GET_BITS(struct amap_eth_tx_compl
,
1960 be_cq_notify(adapter
, txo
->cq
.id
, true, tx_compl
);
1962 atomic_sub(num_wrbs
, &txo
->q
.used
);
1964 /* As Tx wrbs have been freed up, wake up netdev queue
1965 * if it was stopped due to lack of tx wrbs. */
1966 if (__netif_subqueue_stopped(adapter
->netdev
, i
) &&
1967 atomic_read(&txo
->q
.used
) < txo
->q
.len
/ 2) {
1968 netif_wake_subqueue(adapter
->netdev
, i
);
1971 adapter
->drv_stats
.be_tx_events
++;
1972 txo
->stats
.be_tx_compl
+= tx_compl
;
1976 mcc_compl
= be_process_mcc(adapter
, &status
);
1979 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
1980 be_cq_notify(adapter
, mcc_obj
->cq
.id
, true, mcc_compl
);
1983 napi_complete(napi
);
1985 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
1989 void be_detect_dump_ue(struct be_adapter
*adapter
)
1991 u32 ue_status_lo
, ue_status_hi
, ue_status_lo_mask
, ue_status_hi_mask
;
1994 pci_read_config_dword(adapter
->pdev
,
1995 PCICFG_UE_STATUS_LOW
, &ue_status_lo
);
1996 pci_read_config_dword(adapter
->pdev
,
1997 PCICFG_UE_STATUS_HIGH
, &ue_status_hi
);
1998 pci_read_config_dword(adapter
->pdev
,
1999 PCICFG_UE_STATUS_LOW_MASK
, &ue_status_lo_mask
);
2000 pci_read_config_dword(adapter
->pdev
,
2001 PCICFG_UE_STATUS_HI_MASK
, &ue_status_hi_mask
);
2003 ue_status_lo
= (ue_status_lo
& (~ue_status_lo_mask
));
2004 ue_status_hi
= (ue_status_hi
& (~ue_status_hi_mask
));
2006 if (ue_status_lo
|| ue_status_hi
) {
2007 adapter
->ue_detected
= true;
2008 adapter
->eeh_err
= true;
2009 dev_err(&adapter
->pdev
->dev
, "UE Detected!!\n");
2013 for (i
= 0; ue_status_lo
; ue_status_lo
>>= 1, i
++) {
2014 if (ue_status_lo
& 1)
2015 dev_err(&adapter
->pdev
->dev
,
2016 "UE: %s bit set\n", ue_status_low_desc
[i
]);
2020 for (i
= 0; ue_status_hi
; ue_status_hi
>>= 1, i
++) {
2021 if (ue_status_hi
& 1)
2022 dev_err(&adapter
->pdev
->dev
,
2023 "UE: %s bit set\n", ue_status_hi_desc
[i
]);
2029 static void be_worker(struct work_struct
*work
)
2031 struct be_adapter
*adapter
=
2032 container_of(work
, struct be_adapter
, work
.work
);
2033 struct be_rx_obj
*rxo
;
2034 struct be_tx_obj
*txo
;
2037 if (!adapter
->ue_detected
&& !lancer_chip(adapter
))
2038 be_detect_dump_ue(adapter
);
2040 /* when interrupts are not yet enabled, just reap any pending
2041 * mcc completions */
2042 if (!netif_running(adapter
->netdev
)) {
2043 int mcc_compl
, status
= 0;
2045 mcc_compl
= be_process_mcc(adapter
, &status
);
2048 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
2049 be_cq_notify(adapter
, mcc_obj
->cq
.id
, false, mcc_compl
);
2055 if (!adapter
->stats_cmd_sent
) {
2056 if (lancer_chip(adapter
))
2057 lancer_cmd_get_pport_stats(adapter
,
2058 &adapter
->stats_cmd
);
2060 be_cmd_get_stats(adapter
, &adapter
->stats_cmd
);
2063 for_all_tx_queues(adapter
, txo
, i
)
2064 be_tx_rate_update(txo
);
2066 for_all_rx_queues(adapter
, rxo
, i
) {
2067 be_rx_rate_update(rxo
);
2068 be_rx_eqd_update(adapter
, rxo
);
2070 if (rxo
->rx_post_starved
) {
2071 rxo
->rx_post_starved
= false;
2072 be_post_rx_frags(rxo
, GFP_KERNEL
);
2077 adapter
->work_counter
++;
2078 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(1000));
2081 static void be_msix_disable(struct be_adapter
*adapter
)
2083 if (msix_enabled(adapter
)) {
2084 pci_disable_msix(adapter
->pdev
);
2085 adapter
->num_msix_vec
= 0;
2089 static void be_msix_enable(struct be_adapter
*adapter
)
2091 #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */
2092 int i
, status
, num_vec
;
2094 num_vec
= be_num_rxqs_want(adapter
) + 1;
2096 for (i
= 0; i
< num_vec
; i
++)
2097 adapter
->msix_entries
[i
].entry
= i
;
2099 status
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
, num_vec
);
2102 } else if (status
>= BE_MIN_MSIX_VECTORS
) {
2104 if (pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
2110 adapter
->num_msix_vec
= num_vec
;
2114 static void be_sriov_enable(struct be_adapter
*adapter
)
2116 be_check_sriov_fn_type(adapter
);
2117 #ifdef CONFIG_PCI_IOV
2118 if (be_physfn(adapter
) && num_vfs
) {
2122 pos
= pci_find_ext_capability(adapter
->pdev
,
2123 PCI_EXT_CAP_ID_SRIOV
);
2124 pci_read_config_word(adapter
->pdev
,
2125 pos
+ PCI_SRIOV_TOTAL_VF
, &nvfs
);
2127 if (num_vfs
> nvfs
) {
2128 dev_info(&adapter
->pdev
->dev
,
2129 "Device supports %d VFs and not %d\n",
2134 status
= pci_enable_sriov(adapter
->pdev
, num_vfs
);
2135 adapter
->sriov_enabled
= status
? false : true;
2140 static void be_sriov_disable(struct be_adapter
*adapter
)
2142 #ifdef CONFIG_PCI_IOV
2143 if (adapter
->sriov_enabled
) {
2144 pci_disable_sriov(adapter
->pdev
);
2145 adapter
->sriov_enabled
= false;
2150 static inline int be_msix_vec_get(struct be_adapter
*adapter
,
2151 struct be_eq_obj
*eq_obj
)
2153 return adapter
->msix_entries
[eq_obj
->eq_idx
].vector
;
2156 static int be_request_irq(struct be_adapter
*adapter
,
2157 struct be_eq_obj
*eq_obj
,
2158 void *handler
, char *desc
, void *context
)
2160 struct net_device
*netdev
= adapter
->netdev
;
2163 sprintf(eq_obj
->desc
, "%s-%s", netdev
->name
, desc
);
2164 vec
= be_msix_vec_get(adapter
, eq_obj
);
2165 return request_irq(vec
, handler
, 0, eq_obj
->desc
, context
);
2168 static void be_free_irq(struct be_adapter
*adapter
, struct be_eq_obj
*eq_obj
,
2171 int vec
= be_msix_vec_get(adapter
, eq_obj
);
2172 free_irq(vec
, context
);
2175 static int be_msix_register(struct be_adapter
*adapter
)
2177 struct be_rx_obj
*rxo
;
2181 status
= be_request_irq(adapter
, &adapter
->tx_eq
, be_msix_tx_mcc
, "tx",
2186 for_all_rx_queues(adapter
, rxo
, i
) {
2187 sprintf(qname
, "rxq%d", i
);
2188 status
= be_request_irq(adapter
, &rxo
->rx_eq
, be_msix_rx
,
2197 be_free_irq(adapter
, &adapter
->tx_eq
, adapter
);
2199 for (i
--, rxo
= &adapter
->rx_obj
[i
]; i
>= 0; i
--, rxo
--)
2200 be_free_irq(adapter
, &rxo
->rx_eq
, rxo
);
2203 dev_warn(&adapter
->pdev
->dev
,
2204 "MSIX Request IRQ failed - err %d\n", status
);
2205 be_msix_disable(adapter
);
2209 static int be_irq_register(struct be_adapter
*adapter
)
2211 struct net_device
*netdev
= adapter
->netdev
;
2214 if (msix_enabled(adapter
)) {
2215 status
= be_msix_register(adapter
);
2218 /* INTx is not supported for VF */
2219 if (!be_physfn(adapter
))
2224 netdev
->irq
= adapter
->pdev
->irq
;
2225 status
= request_irq(netdev
->irq
, be_intx
, IRQF_SHARED
, netdev
->name
,
2228 dev_err(&adapter
->pdev
->dev
,
2229 "INTx request IRQ failed - err %d\n", status
);
2233 adapter
->isr_registered
= true;
2237 static void be_irq_unregister(struct be_adapter
*adapter
)
2239 struct net_device
*netdev
= adapter
->netdev
;
2240 struct be_rx_obj
*rxo
;
2243 if (!adapter
->isr_registered
)
2247 if (!msix_enabled(adapter
)) {
2248 free_irq(netdev
->irq
, adapter
);
2253 be_free_irq(adapter
, &adapter
->tx_eq
, adapter
);
2255 for_all_rx_queues(adapter
, rxo
, i
)
2256 be_free_irq(adapter
, &rxo
->rx_eq
, rxo
);
2259 adapter
->isr_registered
= false;
2262 static void be_rx_queues_clear(struct be_adapter
*adapter
)
2264 struct be_queue_info
*q
;
2265 struct be_rx_obj
*rxo
;
2268 for_all_rx_queues(adapter
, rxo
, i
) {
2271 be_cmd_rxq_destroy(adapter
, q
);
2272 /* After the rxq is invalidated, wait for a grace time
2273 * of 1ms for all dma to end and the flush compl to
2277 be_rx_q_clean(adapter
, rxo
);
2280 /* Clear any residual events */
2283 be_eq_clean(adapter
, &rxo
->rx_eq
);
2287 static int be_close(struct net_device
*netdev
)
2289 struct be_adapter
*adapter
= netdev_priv(netdev
);
2290 struct be_rx_obj
*rxo
;
2291 struct be_tx_obj
*txo
;
2292 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
2295 be_async_mcc_disable(adapter
);
2297 netif_carrier_off(netdev
);
2298 adapter
->link_up
= false;
2300 if (!lancer_chip(adapter
))
2301 be_intr_set(adapter
, false);
2303 for_all_rx_queues(adapter
, rxo
, i
)
2304 napi_disable(&rxo
->rx_eq
.napi
);
2306 napi_disable(&tx_eq
->napi
);
2308 if (lancer_chip(adapter
)) {
2309 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, false, 0);
2310 for_all_rx_queues(adapter
, rxo
, i
)
2311 be_cq_notify(adapter
, rxo
->cq
.id
, false, 0);
2312 for_all_tx_queues(adapter
, txo
, i
)
2313 be_cq_notify(adapter
, txo
->cq
.id
, false, 0);
2316 if (msix_enabled(adapter
)) {
2317 vec
= be_msix_vec_get(adapter
, tx_eq
);
2318 synchronize_irq(vec
);
2320 for_all_rx_queues(adapter
, rxo
, i
) {
2321 vec
= be_msix_vec_get(adapter
, &rxo
->rx_eq
);
2322 synchronize_irq(vec
);
2325 synchronize_irq(netdev
->irq
);
2327 be_irq_unregister(adapter
);
2329 /* Wait for all pending tx completions to arrive so that
2330 * all tx skbs are freed.
2332 for_all_tx_queues(adapter
, txo
, i
)
2333 be_tx_compl_clean(adapter
, txo
);
2335 be_rx_queues_clear(adapter
);
2339 static int be_rx_queues_setup(struct be_adapter
*adapter
)
2341 struct be_rx_obj
*rxo
;
2343 u8 rsstable
[MAX_RSS_QS
];
2345 for_all_rx_queues(adapter
, rxo
, i
) {
2346 rc
= be_cmd_rxq_create(adapter
, &rxo
->q
, rxo
->cq
.id
,
2347 rx_frag_size
, BE_MAX_JUMBO_FRAME_SIZE
,
2349 (i
> 0) ? 1 : 0/* rss enable */, &rxo
->rss_id
);
2354 if (be_multi_rxq(adapter
)) {
2355 for_all_rss_queues(adapter
, rxo
, i
)
2356 rsstable
[i
] = rxo
->rss_id
;
2358 rc
= be_cmd_rss_config(adapter
, rsstable
,
2359 adapter
->num_rx_qs
- 1);
2364 /* First time posting */
2365 for_all_rx_queues(adapter
, rxo
, i
) {
2366 be_post_rx_frags(rxo
, GFP_KERNEL
);
2367 napi_enable(&rxo
->rx_eq
.napi
);
2372 static int be_open(struct net_device
*netdev
)
2374 struct be_adapter
*adapter
= netdev_priv(netdev
);
2375 struct be_eq_obj
*tx_eq
= &adapter
->tx_eq
;
2376 struct be_rx_obj
*rxo
;
2382 status
= be_rx_queues_setup(adapter
);
2386 napi_enable(&tx_eq
->napi
);
2388 be_irq_register(adapter
);
2390 if (!lancer_chip(adapter
))
2391 be_intr_set(adapter
, true);
2393 /* The evt queues are created in unarmed state; arm them */
2394 for_all_rx_queues(adapter
, rxo
, i
) {
2395 be_eq_notify(adapter
, rxo
->rx_eq
.q
.id
, true, false, 0);
2396 be_cq_notify(adapter
, rxo
->cq
.id
, true, 0);
2398 be_eq_notify(adapter
, tx_eq
->q
.id
, true, false, 0);
2400 /* Now that interrupts are on we can process async mcc */
2401 be_async_mcc_enable(adapter
);
2403 status
= be_cmd_link_status_query(adapter
, &link_up
, &mac_speed
,
2407 be_link_status_update(adapter
, link_up
);
2409 if (be_physfn(adapter
)) {
2410 status
= be_vid_config(adapter
, false, 0);
2414 status
= be_cmd_set_flow_control(adapter
,
2415 adapter
->tx_fc
, adapter
->rx_fc
);
2422 be_close(adapter
->netdev
);
2426 static int be_setup_wol(struct be_adapter
*adapter
, bool enable
)
2428 struct be_dma_mem cmd
;
2432 memset(mac
, 0, ETH_ALEN
);
2434 cmd
.size
= sizeof(struct be_cmd_req_acpi_wol_magic_config
);
2435 cmd
.va
= dma_alloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
2439 memset(cmd
.va
, 0, cmd
.size
);
2442 status
= pci_write_config_dword(adapter
->pdev
,
2443 PCICFG_PM_CONTROL_OFFSET
, PCICFG_PM_CONTROL_MASK
);
2445 dev_err(&adapter
->pdev
->dev
,
2446 "Could not enable Wake-on-lan\n");
2447 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
2451 status
= be_cmd_enable_magic_wol(adapter
,
2452 adapter
->netdev
->dev_addr
, &cmd
);
2453 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 1);
2454 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 1);
2456 status
= be_cmd_enable_magic_wol(adapter
, mac
, &cmd
);
2457 pci_enable_wake(adapter
->pdev
, PCI_D3hot
, 0);
2458 pci_enable_wake(adapter
->pdev
, PCI_D3cold
, 0);
2461 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
, cmd
.dma
);
2466 * Generate a seed MAC address from the PF MAC Address using jhash.
2467 * MAC Address for VFs are assigned incrementally starting from the seed.
2468 * These addresses are programmed in the ASIC by the PF and the VF driver
2469 * queries for the MAC address during its probe.
2471 static inline int be_vf_eth_addr_config(struct be_adapter
*adapter
)
2477 be_vf_eth_addr_generate(adapter
, mac
);
2479 for (vf
= 0; vf
< num_vfs
; vf
++) {
2480 status
= be_cmd_pmac_add(adapter
, mac
,
2481 adapter
->vf_cfg
[vf
].vf_if_handle
,
2482 &adapter
->vf_cfg
[vf
].vf_pmac_id
,
2485 dev_err(&adapter
->pdev
->dev
,
2486 "Mac address add failed for VF %d\n", vf
);
2488 memcpy(adapter
->vf_cfg
[vf
].vf_mac_addr
, mac
, ETH_ALEN
);
2495 static inline void be_vf_eth_addr_rem(struct be_adapter
*adapter
)
2499 for (vf
= 0; vf
< num_vfs
; vf
++) {
2500 if (adapter
->vf_cfg
[vf
].vf_pmac_id
!= BE_INVALID_PMAC_ID
)
2501 be_cmd_pmac_del(adapter
,
2502 adapter
->vf_cfg
[vf
].vf_if_handle
,
2503 adapter
->vf_cfg
[vf
].vf_pmac_id
, vf
+ 1);
2507 static int be_setup(struct be_adapter
*adapter
)
2509 struct net_device
*netdev
= adapter
->netdev
;
2510 u32 cap_flags
, en_flags
, vf
= 0;
2514 cap_flags
= en_flags
= BE_IF_FLAGS_UNTAGGED
|
2515 BE_IF_FLAGS_BROADCAST
|
2516 BE_IF_FLAGS_MULTICAST
;
2518 if (be_physfn(adapter
)) {
2519 cap_flags
|= BE_IF_FLAGS_MCAST_PROMISCUOUS
|
2520 BE_IF_FLAGS_PROMISCUOUS
|
2521 BE_IF_FLAGS_PASS_L3L4_ERRORS
;
2522 en_flags
|= BE_IF_FLAGS_PASS_L3L4_ERRORS
;
2524 if (adapter
->function_caps
& BE_FUNCTION_CAPS_RSS
) {
2525 cap_flags
|= BE_IF_FLAGS_RSS
;
2526 en_flags
|= BE_IF_FLAGS_RSS
;
2530 status
= be_cmd_if_create(adapter
, cap_flags
, en_flags
,
2531 netdev
->dev_addr
, false/* pmac_invalid */,
2532 &adapter
->if_handle
, &adapter
->pmac_id
, 0);
2536 if (be_physfn(adapter
)) {
2537 if (adapter
->sriov_enabled
) {
2538 while (vf
< num_vfs
) {
2539 cap_flags
= en_flags
= BE_IF_FLAGS_UNTAGGED
|
2540 BE_IF_FLAGS_BROADCAST
;
2541 status
= be_cmd_if_create(adapter
, cap_flags
,
2542 en_flags
, mac
, true,
2543 &adapter
->vf_cfg
[vf
].vf_if_handle
,
2546 dev_err(&adapter
->pdev
->dev
,
2547 "Interface Create failed for VF %d\n",
2551 adapter
->vf_cfg
[vf
].vf_pmac_id
=
2557 status
= be_cmd_mac_addr_query(adapter
, mac
,
2558 MAC_ADDRESS_TYPE_NETWORK
, false, adapter
->if_handle
);
2560 memcpy(adapter
->netdev
->dev_addr
, mac
, ETH_ALEN
);
2561 memcpy(adapter
->netdev
->perm_addr
, mac
, ETH_ALEN
);
2565 status
= be_tx_queues_create(adapter
);
2569 status
= be_rx_queues_create(adapter
);
2573 /* Allow all priorities by default. A GRP5 evt may modify this */
2574 adapter
->vlan_prio_bmap
= 0xff;
2576 status
= be_mcc_queues_create(adapter
);
2580 adapter
->link_speed
= -1;
2585 be_rx_queues_destroy(adapter
);
2587 be_tx_queues_destroy(adapter
);
2589 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2590 for (vf
= 0; vf
< num_vfs
; vf
++)
2591 if (adapter
->vf_cfg
[vf
].vf_if_handle
)
2592 be_cmd_if_destroy(adapter
,
2593 adapter
->vf_cfg
[vf
].vf_if_handle
,
2595 be_cmd_if_destroy(adapter
, adapter
->if_handle
, 0);
2600 static int be_clear(struct be_adapter
*adapter
)
2604 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2605 be_vf_eth_addr_rem(adapter
);
2607 be_mcc_queues_destroy(adapter
);
2608 be_rx_queues_destroy(adapter
);
2609 be_tx_queues_destroy(adapter
);
2610 adapter
->eq_next_idx
= 0;
2612 if (be_physfn(adapter
) && adapter
->sriov_enabled
)
2613 for (vf
= 0; vf
< num_vfs
; vf
++)
2614 if (adapter
->vf_cfg
[vf
].vf_if_handle
)
2615 be_cmd_if_destroy(adapter
,
2616 adapter
->vf_cfg
[vf
].vf_if_handle
,
2619 be_cmd_if_destroy(adapter
, adapter
->if_handle
, 0);
2621 /* tell fw we're done with firing cmds */
2622 be_cmd_fw_clean(adapter
);
2627 #define FW_FILE_HDR_SIGN "ServerEngines Corp. "
2628 static bool be_flash_redboot(struct be_adapter
*adapter
,
2629 const u8
*p
, u32 img_start
, int image_size
,
2636 crc_offset
= hdr_size
+ img_start
+ image_size
- 4;
2640 status
= be_cmd_get_flash_crc(adapter
, flashed_crc
,
2643 dev_err(&adapter
->pdev
->dev
,
2644 "could not get crc from flash, not flashing redboot\n");
2648 /*update redboot only if crc does not match*/
2649 if (!memcmp(flashed_crc
, p
, 4))
2655 static int be_flash_data(struct be_adapter
*adapter
,
2656 const struct firmware
*fw
,
2657 struct be_dma_mem
*flash_cmd
, int num_of_images
)
2660 int status
= 0, i
, filehdr_size
= 0;
2661 u32 total_bytes
= 0, flash_op
;
2663 const u8
*p
= fw
->data
;
2664 struct be_cmd_write_flashrom
*req
= flash_cmd
->va
;
2665 const struct flash_comp
*pflashcomp
;
2668 static const struct flash_comp gen3_flash_types
[9] = {
2669 { FLASH_iSCSI_PRIMARY_IMAGE_START_g3
, IMG_TYPE_ISCSI_ACTIVE
,
2670 FLASH_IMAGE_MAX_SIZE_g3
},
2671 { FLASH_REDBOOT_START_g3
, IMG_TYPE_REDBOOT
,
2672 FLASH_REDBOOT_IMAGE_MAX_SIZE_g3
},
2673 { FLASH_iSCSI_BIOS_START_g3
, IMG_TYPE_BIOS
,
2674 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2675 { FLASH_PXE_BIOS_START_g3
, IMG_TYPE_PXE_BIOS
,
2676 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2677 { FLASH_FCoE_BIOS_START_g3
, IMG_TYPE_FCOE_BIOS
,
2678 FLASH_BIOS_IMAGE_MAX_SIZE_g3
},
2679 { FLASH_iSCSI_BACKUP_IMAGE_START_g3
, IMG_TYPE_ISCSI_BACKUP
,
2680 FLASH_IMAGE_MAX_SIZE_g3
},
2681 { FLASH_FCoE_PRIMARY_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_ACTIVE
,
2682 FLASH_IMAGE_MAX_SIZE_g3
},
2683 { FLASH_FCoE_BACKUP_IMAGE_START_g3
, IMG_TYPE_FCOE_FW_BACKUP
,
2684 FLASH_IMAGE_MAX_SIZE_g3
},
2685 { FLASH_NCSI_START_g3
, IMG_TYPE_NCSI_FW
,
2686 FLASH_NCSI_IMAGE_MAX_SIZE_g3
}
2688 static const struct flash_comp gen2_flash_types
[8] = {
2689 { FLASH_iSCSI_PRIMARY_IMAGE_START_g2
, IMG_TYPE_ISCSI_ACTIVE
,
2690 FLASH_IMAGE_MAX_SIZE_g2
},
2691 { FLASH_REDBOOT_START_g2
, IMG_TYPE_REDBOOT
,
2692 FLASH_REDBOOT_IMAGE_MAX_SIZE_g2
},
2693 { FLASH_iSCSI_BIOS_START_g2
, IMG_TYPE_BIOS
,
2694 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2695 { FLASH_PXE_BIOS_START_g2
, IMG_TYPE_PXE_BIOS
,
2696 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2697 { FLASH_FCoE_BIOS_START_g2
, IMG_TYPE_FCOE_BIOS
,
2698 FLASH_BIOS_IMAGE_MAX_SIZE_g2
},
2699 { FLASH_iSCSI_BACKUP_IMAGE_START_g2
, IMG_TYPE_ISCSI_BACKUP
,
2700 FLASH_IMAGE_MAX_SIZE_g2
},
2701 { FLASH_FCoE_PRIMARY_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_ACTIVE
,
2702 FLASH_IMAGE_MAX_SIZE_g2
},
2703 { FLASH_FCoE_BACKUP_IMAGE_START_g2
, IMG_TYPE_FCOE_FW_BACKUP
,
2704 FLASH_IMAGE_MAX_SIZE_g2
}
2707 if (adapter
->generation
== BE_GEN3
) {
2708 pflashcomp
= gen3_flash_types
;
2709 filehdr_size
= sizeof(struct flash_file_hdr_g3
);
2710 num_comp
= ARRAY_SIZE(gen3_flash_types
);
2712 pflashcomp
= gen2_flash_types
;
2713 filehdr_size
= sizeof(struct flash_file_hdr_g2
);
2714 num_comp
= ARRAY_SIZE(gen2_flash_types
);
2716 for (i
= 0; i
< num_comp
; i
++) {
2717 if ((pflashcomp
[i
].optype
== IMG_TYPE_NCSI_FW
) &&
2718 memcmp(adapter
->fw_ver
, "3.102.148.0", 11) < 0)
2720 if ((pflashcomp
[i
].optype
== IMG_TYPE_REDBOOT
) &&
2721 (!be_flash_redboot(adapter
, fw
->data
,
2722 pflashcomp
[i
].offset
, pflashcomp
[i
].size
, filehdr_size
+
2723 (num_of_images
* sizeof(struct image_hdr
)))))
2726 p
+= filehdr_size
+ pflashcomp
[i
].offset
2727 + (num_of_images
* sizeof(struct image_hdr
));
2728 if (p
+ pflashcomp
[i
].size
> fw
->data
+ fw
->size
)
2730 total_bytes
= pflashcomp
[i
].size
;
2731 while (total_bytes
) {
2732 if (total_bytes
> 32*1024)
2733 num_bytes
= 32*1024;
2735 num_bytes
= total_bytes
;
2736 total_bytes
-= num_bytes
;
2739 flash_op
= FLASHROM_OPER_FLASH
;
2741 flash_op
= FLASHROM_OPER_SAVE
;
2742 memcpy(req
->params
.data_buf
, p
, num_bytes
);
2744 status
= be_cmd_write_flashrom(adapter
, flash_cmd
,
2745 pflashcomp
[i
].optype
, flash_op
, num_bytes
);
2747 dev_err(&adapter
->pdev
->dev
,
2748 "cmd to write to flash rom failed.\n");
2756 static int get_ufigen_type(struct flash_file_hdr_g2
*fhdr
)
2760 if (fhdr
->build
[0] == '3')
2762 else if (fhdr
->build
[0] == '2')
2768 static int lancer_fw_download(struct be_adapter
*adapter
,
2769 const struct firmware
*fw
)
2771 #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024)
2772 #define LANCER_FW_DOWNLOAD_LOCATION "/prg"
2773 struct be_dma_mem flash_cmd
;
2774 const u8
*data_ptr
= NULL
;
2775 u8
*dest_image_ptr
= NULL
;
2776 size_t image_size
= 0;
2778 u32 data_written
= 0;
2783 if (!IS_ALIGNED(fw
->size
, sizeof(u32
))) {
2784 dev_err(&adapter
->pdev
->dev
,
2785 "FW Image not properly aligned. "
2786 "Length must be 4 byte aligned.\n");
2788 goto lancer_fw_exit
;
2791 flash_cmd
.size
= sizeof(struct lancer_cmd_req_write_object
)
2792 + LANCER_FW_DOWNLOAD_CHUNK
;
2793 flash_cmd
.va
= dma_alloc_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
,
2794 &flash_cmd
.dma
, GFP_KERNEL
);
2795 if (!flash_cmd
.va
) {
2797 dev_err(&adapter
->pdev
->dev
,
2798 "Memory allocation failure while flashing\n");
2799 goto lancer_fw_exit
;
2802 dest_image_ptr
= flash_cmd
.va
+
2803 sizeof(struct lancer_cmd_req_write_object
);
2804 image_size
= fw
->size
;
2805 data_ptr
= fw
->data
;
2807 while (image_size
) {
2808 chunk_size
= min_t(u32
, image_size
, LANCER_FW_DOWNLOAD_CHUNK
);
2810 /* Copy the image chunk content. */
2811 memcpy(dest_image_ptr
, data_ptr
, chunk_size
);
2813 status
= lancer_cmd_write_object(adapter
, &flash_cmd
,
2814 chunk_size
, offset
, LANCER_FW_DOWNLOAD_LOCATION
,
2815 &data_written
, &add_status
);
2820 offset
+= data_written
;
2821 data_ptr
+= data_written
;
2822 image_size
-= data_written
;
2826 /* Commit the FW written */
2827 status
= lancer_cmd_write_object(adapter
, &flash_cmd
,
2828 0, offset
, LANCER_FW_DOWNLOAD_LOCATION
,
2829 &data_written
, &add_status
);
2832 dma_free_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
, flash_cmd
.va
,
2835 dev_err(&adapter
->pdev
->dev
,
2836 "Firmware load error. "
2837 "Status code: 0x%x Additional Status: 0x%x\n",
2838 status
, add_status
);
2839 goto lancer_fw_exit
;
2842 dev_info(&adapter
->pdev
->dev
, "Firmware flashed successfully\n");
2847 static int be_fw_download(struct be_adapter
*adapter
, const struct firmware
* fw
)
2849 struct flash_file_hdr_g2
*fhdr
;
2850 struct flash_file_hdr_g3
*fhdr3
;
2851 struct image_hdr
*img_hdr_ptr
= NULL
;
2852 struct be_dma_mem flash_cmd
;
2854 int status
= 0, i
= 0, num_imgs
= 0;
2857 fhdr
= (struct flash_file_hdr_g2
*) p
;
2859 flash_cmd
.size
= sizeof(struct be_cmd_write_flashrom
) + 32*1024;
2860 flash_cmd
.va
= dma_alloc_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
,
2861 &flash_cmd
.dma
, GFP_KERNEL
);
2862 if (!flash_cmd
.va
) {
2864 dev_err(&adapter
->pdev
->dev
,
2865 "Memory allocation failure while flashing\n");
2869 if ((adapter
->generation
== BE_GEN3
) &&
2870 (get_ufigen_type(fhdr
) == BE_GEN3
)) {
2871 fhdr3
= (struct flash_file_hdr_g3
*) fw
->data
;
2872 num_imgs
= le32_to_cpu(fhdr3
->num_imgs
);
2873 for (i
= 0; i
< num_imgs
; i
++) {
2874 img_hdr_ptr
= (struct image_hdr
*) (fw
->data
+
2875 (sizeof(struct flash_file_hdr_g3
) +
2876 i
* sizeof(struct image_hdr
)));
2877 if (le32_to_cpu(img_hdr_ptr
->imageid
) == 1)
2878 status
= be_flash_data(adapter
, fw
, &flash_cmd
,
2881 } else if ((adapter
->generation
== BE_GEN2
) &&
2882 (get_ufigen_type(fhdr
) == BE_GEN2
)) {
2883 status
= be_flash_data(adapter
, fw
, &flash_cmd
, 0);
2885 dev_err(&adapter
->pdev
->dev
,
2886 "UFI and Interface are not compatible for flashing\n");
2890 dma_free_coherent(&adapter
->pdev
->dev
, flash_cmd
.size
, flash_cmd
.va
,
2893 dev_err(&adapter
->pdev
->dev
, "Firmware load error\n");
2897 dev_info(&adapter
->pdev
->dev
, "Firmware flashed successfully\n");
2903 int be_load_fw(struct be_adapter
*adapter
, u8
*fw_file
)
2905 const struct firmware
*fw
;
2908 if (!netif_running(adapter
->netdev
)) {
2909 dev_err(&adapter
->pdev
->dev
,
2910 "Firmware load not allowed (interface is down)\n");
2914 status
= request_firmware(&fw
, fw_file
, &adapter
->pdev
->dev
);
2918 dev_info(&adapter
->pdev
->dev
, "Flashing firmware file %s\n", fw_file
);
2920 if (lancer_chip(adapter
))
2921 status
= lancer_fw_download(adapter
, fw
);
2923 status
= be_fw_download(adapter
, fw
);
2926 release_firmware(fw
);
2930 static struct net_device_ops be_netdev_ops
= {
2931 .ndo_open
= be_open
,
2932 .ndo_stop
= be_close
,
2933 .ndo_start_xmit
= be_xmit
,
2934 .ndo_set_rx_mode
= be_set_multicast_list
,
2935 .ndo_set_mac_address
= be_mac_addr_set
,
2936 .ndo_change_mtu
= be_change_mtu
,
2937 .ndo_validate_addr
= eth_validate_addr
,
2938 .ndo_vlan_rx_add_vid
= be_vlan_add_vid
,
2939 .ndo_vlan_rx_kill_vid
= be_vlan_rem_vid
,
2940 .ndo_set_vf_mac
= be_set_vf_mac
,
2941 .ndo_set_vf_vlan
= be_set_vf_vlan
,
2942 .ndo_set_vf_tx_rate
= be_set_vf_tx_rate
,
2943 .ndo_get_vf_config
= be_get_vf_config
2946 static void be_netdev_init(struct net_device
*netdev
)
2948 struct be_adapter
*adapter
= netdev_priv(netdev
);
2949 struct be_rx_obj
*rxo
;
2952 netdev
->hw_features
|= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_TSO6
|
2953 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
|
2955 if (be_multi_rxq(adapter
))
2956 netdev
->hw_features
|= NETIF_F_RXHASH
;
2958 netdev
->features
|= netdev
->hw_features
|
2959 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
2961 netdev
->vlan_features
|= NETIF_F_SG
| NETIF_F_TSO
| NETIF_F_TSO6
|
2962 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
2964 netdev
->flags
|= IFF_MULTICAST
;
2966 /* Default settings for Rx and Tx flow control */
2967 adapter
->rx_fc
= true;
2968 adapter
->tx_fc
= true;
2970 netif_set_gso_max_size(netdev
, 65535);
2972 BE_SET_NETDEV_OPS(netdev
, &be_netdev_ops
);
2974 SET_ETHTOOL_OPS(netdev
, &be_ethtool_ops
);
2976 for_all_rx_queues(adapter
, rxo
, i
)
2977 netif_napi_add(netdev
, &rxo
->rx_eq
.napi
, be_poll_rx
,
2980 netif_napi_add(netdev
, &adapter
->tx_eq
.napi
, be_poll_tx_mcc
,
2984 static void be_unmap_pci_bars(struct be_adapter
*adapter
)
2987 iounmap(adapter
->csr
);
2989 iounmap(adapter
->db
);
2990 if (adapter
->pcicfg
&& be_physfn(adapter
))
2991 iounmap(adapter
->pcicfg
);
2994 static int be_map_pci_bars(struct be_adapter
*adapter
)
2997 int pcicfg_reg
, db_reg
;
2999 if (lancer_chip(adapter
)) {
3000 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 0),
3001 pci_resource_len(adapter
->pdev
, 0));
3008 if (be_physfn(adapter
)) {
3009 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, 2),
3010 pci_resource_len(adapter
->pdev
, 2));
3013 adapter
->csr
= addr
;
3016 if (adapter
->generation
== BE_GEN2
) {
3021 if (be_physfn(adapter
))
3026 addr
= ioremap_nocache(pci_resource_start(adapter
->pdev
, db_reg
),
3027 pci_resource_len(adapter
->pdev
, db_reg
));
3032 if (be_physfn(adapter
)) {
3033 addr
= ioremap_nocache(
3034 pci_resource_start(adapter
->pdev
, pcicfg_reg
),
3035 pci_resource_len(adapter
->pdev
, pcicfg_reg
));
3038 adapter
->pcicfg
= addr
;
3040 adapter
->pcicfg
= adapter
->db
+ SRIOV_VF_PCICFG_OFFSET
;
3044 be_unmap_pci_bars(adapter
);
3049 static void be_ctrl_cleanup(struct be_adapter
*adapter
)
3051 struct be_dma_mem
*mem
= &adapter
->mbox_mem_alloced
;
3053 be_unmap_pci_bars(adapter
);
3056 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
3059 mem
= &adapter
->mc_cmd_mem
;
3061 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
, mem
->va
,
3065 static int be_ctrl_init(struct be_adapter
*adapter
)
3067 struct be_dma_mem
*mbox_mem_alloc
= &adapter
->mbox_mem_alloced
;
3068 struct be_dma_mem
*mbox_mem_align
= &adapter
->mbox_mem
;
3069 struct be_dma_mem
*mc_cmd_mem
= &adapter
->mc_cmd_mem
;
3072 status
= be_map_pci_bars(adapter
);
3076 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
3077 mbox_mem_alloc
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
,
3078 mbox_mem_alloc
->size
,
3079 &mbox_mem_alloc
->dma
,
3081 if (!mbox_mem_alloc
->va
) {
3083 goto unmap_pci_bars
;
3086 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
3087 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
3088 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
3089 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
3091 mc_cmd_mem
->size
= sizeof(struct be_cmd_req_mcast_mac_config
);
3092 mc_cmd_mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
,
3093 mc_cmd_mem
->size
, &mc_cmd_mem
->dma
,
3095 if (mc_cmd_mem
->va
== NULL
) {
3099 memset(mc_cmd_mem
->va
, 0, mc_cmd_mem
->size
);
3101 mutex_init(&adapter
->mbox_lock
);
3102 spin_lock_init(&adapter
->mcc_lock
);
3103 spin_lock_init(&adapter
->mcc_cq_lock
);
3105 init_completion(&adapter
->flash_compl
);
3106 pci_save_state(adapter
->pdev
);
3110 dma_free_coherent(&adapter
->pdev
->dev
, mbox_mem_alloc
->size
,
3111 mbox_mem_alloc
->va
, mbox_mem_alloc
->dma
);
3114 be_unmap_pci_bars(adapter
);
3120 static void be_stats_cleanup(struct be_adapter
*adapter
)
3122 struct be_dma_mem
*cmd
= &adapter
->stats_cmd
;
3125 dma_free_coherent(&adapter
->pdev
->dev
, cmd
->size
,
3129 static int be_stats_init(struct be_adapter
*adapter
)
3131 struct be_dma_mem
*cmd
= &adapter
->stats_cmd
;
3133 if (adapter
->generation
== BE_GEN2
) {
3134 cmd
->size
= sizeof(struct be_cmd_req_get_stats_v0
);
3136 if (lancer_chip(adapter
))
3137 cmd
->size
= sizeof(struct lancer_cmd_req_pport_stats
);
3139 cmd
->size
= sizeof(struct be_cmd_req_get_stats_v1
);
3141 cmd
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, cmd
->size
, &cmd
->dma
,
3143 if (cmd
->va
== NULL
)
3145 memset(cmd
->va
, 0, cmd
->size
);
3149 static void __devexit
be_remove(struct pci_dev
*pdev
)
3151 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3156 cancel_delayed_work_sync(&adapter
->work
);
3158 unregister_netdev(adapter
->netdev
);
3162 be_stats_cleanup(adapter
);
3164 be_ctrl_cleanup(adapter
);
3166 kfree(adapter
->vf_cfg
);
3167 be_sriov_disable(adapter
);
3169 be_msix_disable(adapter
);
3171 pci_set_drvdata(pdev
, NULL
);
3172 pci_release_regions(pdev
);
3173 pci_disable_device(pdev
);
3175 free_netdev(adapter
->netdev
);
3178 static int be_get_config(struct be_adapter
*adapter
)
3183 status
= be_cmd_get_fw_ver(adapter
, adapter
->fw_ver
);
3187 status
= be_cmd_query_fw_cfg(adapter
, &adapter
->port_num
,
3188 &adapter
->function_mode
, &adapter
->function_caps
);
3192 memset(mac
, 0, ETH_ALEN
);
3194 /* A default permanent address is given to each VF for Lancer*/
3195 if (be_physfn(adapter
) || lancer_chip(adapter
)) {
3196 status
= be_cmd_mac_addr_query(adapter
, mac
,
3197 MAC_ADDRESS_TYPE_NETWORK
, true /*permanent */, 0);
3202 if (!is_valid_ether_addr(mac
))
3203 return -EADDRNOTAVAIL
;
3205 memcpy(adapter
->netdev
->dev_addr
, mac
, ETH_ALEN
);
3206 memcpy(adapter
->netdev
->perm_addr
, mac
, ETH_ALEN
);
3209 if (adapter
->function_mode
& 0x400)
3210 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
/4;
3212 adapter
->max_vlans
= BE_NUM_VLANS_SUPPORTED
;
3214 status
= be_cmd_get_cntl_attributes(adapter
);
3218 be_cmd_check_native_mode(adapter
);
3220 if ((num_vfs
&& adapter
->sriov_enabled
) ||
3221 (adapter
->function_mode
& 0x400) ||
3222 lancer_chip(adapter
) || !be_physfn(adapter
)) {
3223 adapter
->num_tx_qs
= 1;
3224 netif_set_real_num_tx_queues(adapter
->netdev
,
3225 adapter
->num_tx_qs
);
3227 adapter
->num_tx_qs
= MAX_TX_QS
;
3233 static int be_dev_family_check(struct be_adapter
*adapter
)
3235 struct pci_dev
*pdev
= adapter
->pdev
;
3236 u32 sli_intf
= 0, if_type
;
3238 switch (pdev
->device
) {
3241 adapter
->generation
= BE_GEN2
;
3245 adapter
->generation
= BE_GEN3
;
3249 pci_read_config_dword(pdev
, SLI_INTF_REG_OFFSET
, &sli_intf
);
3250 if_type
= (sli_intf
& SLI_INTF_IF_TYPE_MASK
) >>
3251 SLI_INTF_IF_TYPE_SHIFT
;
3253 if (((sli_intf
& SLI_INTF_VALID_MASK
) != SLI_INTF_VALID
) ||
3255 dev_err(&pdev
->dev
, "SLI_INTF reg val is not valid\n");
3258 adapter
->sli_family
= ((sli_intf
& SLI_INTF_FAMILY_MASK
) >>
3259 SLI_INTF_FAMILY_SHIFT
);
3260 adapter
->generation
= BE_GEN3
;
3263 adapter
->generation
= 0;
3268 static int lancer_wait_ready(struct be_adapter
*adapter
)
3270 #define SLIPORT_READY_TIMEOUT 500
3274 for (i
= 0; i
< SLIPORT_READY_TIMEOUT
; i
++) {
3275 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
3276 if (sliport_status
& SLIPORT_STATUS_RDY_MASK
)
3282 if (i
== SLIPORT_READY_TIMEOUT
)
3288 static int lancer_test_and_set_rdy_state(struct be_adapter
*adapter
)
3291 u32 sliport_status
, err
, reset_needed
;
3292 status
= lancer_wait_ready(adapter
);
3294 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
3295 err
= sliport_status
& SLIPORT_STATUS_ERR_MASK
;
3296 reset_needed
= sliport_status
& SLIPORT_STATUS_RN_MASK
;
3297 if (err
&& reset_needed
) {
3298 iowrite32(SLI_PORT_CONTROL_IP_MASK
,
3299 adapter
->db
+ SLIPORT_CONTROL_OFFSET
);
3301 /* check adapter has corrected the error */
3302 status
= lancer_wait_ready(adapter
);
3303 sliport_status
= ioread32(adapter
->db
+
3304 SLIPORT_STATUS_OFFSET
);
3305 sliport_status
&= (SLIPORT_STATUS_ERR_MASK
|
3306 SLIPORT_STATUS_RN_MASK
);
3307 if (status
|| sliport_status
)
3309 } else if (err
|| reset_needed
) {
3316 static int __devinit
be_probe(struct pci_dev
*pdev
,
3317 const struct pci_device_id
*pdev_id
)
3320 struct be_adapter
*adapter
;
3321 struct net_device
*netdev
;
3323 status
= pci_enable_device(pdev
);
3327 status
= pci_request_regions(pdev
, DRV_NAME
);
3330 pci_set_master(pdev
);
3332 netdev
= alloc_etherdev_mq(sizeof(struct be_adapter
), MAX_TX_QS
);
3333 if (netdev
== NULL
) {
3337 adapter
= netdev_priv(netdev
);
3338 adapter
->pdev
= pdev
;
3339 pci_set_drvdata(pdev
, adapter
);
3341 status
= be_dev_family_check(adapter
);
3345 adapter
->netdev
= netdev
;
3346 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3348 status
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64));
3350 netdev
->features
|= NETIF_F_HIGHDMA
;
3352 status
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3354 dev_err(&pdev
->dev
, "Could not set PCI DMA Mask\n");
3359 be_sriov_enable(adapter
);
3360 if (adapter
->sriov_enabled
) {
3361 adapter
->vf_cfg
= kcalloc(num_vfs
,
3362 sizeof(struct be_vf_cfg
), GFP_KERNEL
);
3364 if (!adapter
->vf_cfg
)
3368 status
= be_ctrl_init(adapter
);
3372 if (lancer_chip(adapter
)) {
3373 status
= lancer_test_and_set_rdy_state(adapter
);
3375 dev_err(&pdev
->dev
, "Adapter in non recoverable error\n");
3380 /* sync up with fw's ready state */
3381 if (be_physfn(adapter
)) {
3382 status
= be_cmd_POST(adapter
);
3387 /* tell fw we're ready to fire cmds */
3388 status
= be_cmd_fw_init(adapter
);
3392 status
= be_cmd_reset_function(adapter
);
3396 status
= be_stats_init(adapter
);
3400 status
= be_get_config(adapter
);
3404 /* The INTR bit may be set in the card when probed by a kdump kernel
3407 if (!lancer_chip(adapter
))
3408 be_intr_set(adapter
, false);
3410 be_msix_enable(adapter
);
3412 INIT_DELAYED_WORK(&adapter
->work
, be_worker
);
3414 status
= be_setup(adapter
);
3418 be_netdev_init(netdev
);
3419 status
= register_netdev(netdev
);
3422 netif_carrier_off(netdev
);
3424 if (be_physfn(adapter
) && adapter
->sriov_enabled
) {
3429 if (!lancer_chip(adapter
)) {
3430 status
= be_vf_eth_addr_config(adapter
);
3435 for (vf
= 0; vf
< num_vfs
; vf
++) {
3436 status
= be_cmd_link_status_query(adapter
, &link_up
,
3437 &mac_speed
, &lnk_speed
, vf
+ 1);
3439 adapter
->vf_cfg
[vf
].vf_tx_rate
= lnk_speed
* 10;
3445 dev_info(&pdev
->dev
, "%s port %d\n", nic_name(pdev
), adapter
->port_num
);
3447 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
3451 unregister_netdev(netdev
);
3455 be_msix_disable(adapter
);
3457 be_stats_cleanup(adapter
);
3459 be_ctrl_cleanup(adapter
);
3461 kfree(adapter
->vf_cfg
);
3463 be_sriov_disable(adapter
);
3464 free_netdev(netdev
);
3465 pci_set_drvdata(pdev
, NULL
);
3467 pci_release_regions(pdev
);
3469 pci_disable_device(pdev
);
3471 dev_err(&pdev
->dev
, "%s initialization failed\n", nic_name(pdev
));
3475 static int be_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3477 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3478 struct net_device
*netdev
= adapter
->netdev
;
3480 cancel_delayed_work_sync(&adapter
->work
);
3482 be_setup_wol(adapter
, true);
3484 netif_device_detach(netdev
);
3485 if (netif_running(netdev
)) {
3490 be_cmd_get_flow_control(adapter
, &adapter
->tx_fc
, &adapter
->rx_fc
);
3493 be_msix_disable(adapter
);
3494 pci_save_state(pdev
);
3495 pci_disable_device(pdev
);
3496 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
3500 static int be_resume(struct pci_dev
*pdev
)
3503 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3504 struct net_device
*netdev
= adapter
->netdev
;
3506 netif_device_detach(netdev
);
3508 status
= pci_enable_device(pdev
);
3512 pci_set_power_state(pdev
, 0);
3513 pci_restore_state(pdev
);
3515 be_msix_enable(adapter
);
3516 /* tell fw we're ready to fire cmds */
3517 status
= be_cmd_fw_init(adapter
);
3522 if (netif_running(netdev
)) {
3527 netif_device_attach(netdev
);
3530 be_setup_wol(adapter
, false);
3532 schedule_delayed_work(&adapter
->work
, msecs_to_jiffies(100));
3537 * An FLR will stop BE from DMAing any data.
3539 static void be_shutdown(struct pci_dev
*pdev
)
3541 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3546 cancel_delayed_work_sync(&adapter
->work
);
3548 netif_device_detach(adapter
->netdev
);
3551 be_setup_wol(adapter
, true);
3553 be_cmd_reset_function(adapter
);
3555 pci_disable_device(pdev
);
3558 static pci_ers_result_t
be_eeh_err_detected(struct pci_dev
*pdev
,
3559 pci_channel_state_t state
)
3561 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3562 struct net_device
*netdev
= adapter
->netdev
;
3564 dev_err(&adapter
->pdev
->dev
, "EEH error detected\n");
3566 adapter
->eeh_err
= true;
3568 netif_device_detach(netdev
);
3570 if (netif_running(netdev
)) {
3577 if (state
== pci_channel_io_perm_failure
)
3578 return PCI_ERS_RESULT_DISCONNECT
;
3580 pci_disable_device(pdev
);
3582 return PCI_ERS_RESULT_NEED_RESET
;
3585 static pci_ers_result_t
be_eeh_reset(struct pci_dev
*pdev
)
3587 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3590 dev_info(&adapter
->pdev
->dev
, "EEH reset\n");
3591 adapter
->eeh_err
= false;
3593 status
= pci_enable_device(pdev
);
3595 return PCI_ERS_RESULT_DISCONNECT
;
3597 pci_set_master(pdev
);
3598 pci_set_power_state(pdev
, 0);
3599 pci_restore_state(pdev
);
3601 /* Check if card is ok and fw is ready */
3602 status
= be_cmd_POST(adapter
);
3604 return PCI_ERS_RESULT_DISCONNECT
;
3606 return PCI_ERS_RESULT_RECOVERED
;
3609 static void be_eeh_resume(struct pci_dev
*pdev
)
3612 struct be_adapter
*adapter
= pci_get_drvdata(pdev
);
3613 struct net_device
*netdev
= adapter
->netdev
;
3615 dev_info(&adapter
->pdev
->dev
, "EEH resume\n");
3617 pci_save_state(pdev
);
3619 /* tell fw we're ready to fire cmds */
3620 status
= be_cmd_fw_init(adapter
);
3624 status
= be_setup(adapter
);
3628 if (netif_running(netdev
)) {
3629 status
= be_open(netdev
);
3633 netif_device_attach(netdev
);
3636 dev_err(&adapter
->pdev
->dev
, "EEH resume failed\n");
3639 static struct pci_error_handlers be_eeh_handlers
= {
3640 .error_detected
= be_eeh_err_detected
,
3641 .slot_reset
= be_eeh_reset
,
3642 .resume
= be_eeh_resume
,
3645 static struct pci_driver be_driver
= {
3647 .id_table
= be_dev_ids
,
3649 .remove
= be_remove
,
3650 .suspend
= be_suspend
,
3651 .resume
= be_resume
,
3652 .shutdown
= be_shutdown
,
3653 .err_handler
= &be_eeh_handlers
3656 static int __init
be_init_module(void)
3658 if (rx_frag_size
!= 8192 && rx_frag_size
!= 4096 &&
3659 rx_frag_size
!= 2048) {
3660 printk(KERN_WARNING DRV_NAME
3661 " : Module param rx_frag_size must be 2048/4096/8192."
3663 rx_frag_size
= 2048;
3666 return pci_register_driver(&be_driver
);
3668 module_init(be_init_module
);
3670 static void __exit
be_exit_module(void)
3672 pci_unregister_driver(&be_driver
);
3674 module_exit(be_exit_module
);