1 /* bnx2x_cmn.h: Broadcom Everest network driver.
3 * Copyright (c) 2007-2010 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
20 #include <linux/types.h>
21 #include <linux/netdevice.h>
26 extern int num_queues
;
28 /*********************** Interfaces ****************************
29 * Functions that need to be implemented by each driver version
33 * Initialize link parameters structure variables.
40 u8
bnx2x_initial_phy_init(struct bnx2x
*bp
, int load_mode
);
43 * Configure hw according to link parameters structure.
47 void bnx2x_link_set(struct bnx2x
*bp
);
55 * @return 0 - link is UP
57 u8
bnx2x_link_test(struct bnx2x
*bp
, u8 is_serdes
);
60 * Handles link status change
64 void bnx2x__link_status_update(struct bnx2x
*bp
);
67 * Report link status to upper layer
73 void bnx2x_link_report(struct bnx2x
*bp
);
76 * calculates MF speed according to current linespeed and MF
83 u16
bnx2x_get_mf_speed(struct bnx2x
*bp
);
86 * MSI-X slowpath interrupt handler
93 irqreturn_t
bnx2x_msix_sp_int(int irq
, void *dev_instance
);
96 * non MSI-X interrupt handler
101 * @return irqreturn_t
103 irqreturn_t
bnx2x_interrupt(int irq
, void *dev_instance
);
107 * Send command to cnic driver
112 int bnx2x_cnic_notify(struct bnx2x
*bp
, int cmd
);
115 * Provides cnic information for proper interrupt handling
119 void bnx2x_setup_cnic_irq_info(struct bnx2x
*bp
);
123 * Enable HW interrupts.
127 void bnx2x_int_enable(struct bnx2x
*bp
);
130 * Disable interrupts. This function ensures that there are no
131 * ISRs or SP DPCs (sp_task) are running after it returns.
134 * @param disable_hw if true, disable HW interrupts.
136 void bnx2x_int_disable_sync(struct bnx2x
*bp
, int disable_hw
);
139 * Loads device firmware
145 int bnx2x_init_firmware(struct bnx2x
*bp
);
148 * Init HW blocks according to current initialization stage:
149 * COMMON, PORT or FUNCTION.
152 * @param load_code: COMMON, PORT or FUNCTION
156 int bnx2x_init_hw(struct bnx2x
*bp
, u32 load_code
);
159 * Init driver internals:
165 * @param load_code COMMON, PORT or FUNCTION
167 void bnx2x_nic_init(struct bnx2x
*bp
, u32 load_code
);
170 * Allocate driver's memory.
176 int bnx2x_alloc_mem(struct bnx2x
*bp
);
179 * Release driver's memory.
183 void bnx2x_free_mem(struct bnx2x
*bp
);
194 int bnx2x_setup_client(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
198 * Set number of queues according to mode
203 void bnx2x_set_num_queues(struct bnx2x
*bp
);
206 * Cleanup chip internals:
207 * - Cleanup MAC configuration.
214 void bnx2x_chip_cleanup(struct bnx2x
*bp
, int unload_mode
);
220 * @param resource Resource bit which was locked
224 int bnx2x_acquire_hw_lock(struct bnx2x
*bp
, u32 resource
);
229 * @param bp driver handle
230 * @param resource Resource bit which was locked
234 int bnx2x_release_hw_lock(struct bnx2x
*bp
, u32 resource
);
237 * Configure eth MAC address in the HW according to the value in
240 * @param bp driver handle
243 void bnx2x_set_eth_mac(struct bnx2x
*bp
, int set
);
247 * Set/Clear FIP MAC(s) at the next enties in the CAM after the ETH
248 * MAC(s). This function will wait until the ramdord completion
251 * @param bp driver handle
252 * @param set set or clear the CAM entry
254 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
256 int bnx2x_set_fip_eth_mac_addr(struct bnx2x
*bp
, int set
);
259 * Set/Clear ALL_ENODE mcast MAC.
266 int bnx2x_set_all_enode_macs(struct bnx2x
*bp
, int set
);
270 * Set MAC filtering configurations.
272 * @remarks called with netif_tx_lock from dev_mcast.c
274 * @param dev net_device
276 void bnx2x_set_rx_mode(struct net_device
*dev
);
279 * Configure MAC filtering rules in a FW.
281 * @param bp driver handle
283 void bnx2x_set_storm_rx_mode(struct bnx2x
*bp
);
285 /* Parity errors related */
286 void bnx2x_inc_load_cnt(struct bnx2x
*bp
);
287 u32
bnx2x_dec_load_cnt(struct bnx2x
*bp
);
288 bool bnx2x_chk_parity_attn(struct bnx2x
*bp
);
289 bool bnx2x_reset_is_done(struct bnx2x
*bp
);
290 void bnx2x_disable_close_the_gate(struct bnx2x
*bp
);
293 * Perform statistics handling according to event
295 * @param bp driver handle
296 * @param event bnx2x_stats_event
298 void bnx2x_stats_handle(struct bnx2x
*bp
, enum bnx2x_stats_event event
);
301 * Handle ramrods completion
303 * @param fp fastpath handle for the event
304 * @param rr_cqe eth_rx_cqe
306 void bnx2x_sp_event(struct bnx2x_fastpath
*fp
, union eth_rx_cqe
*rr_cqe
);
309 * Init/halt function before/after sending
310 * CLIENT_SETUP/CFC_DEL for the first/last client.
316 int bnx2x_func_start(struct bnx2x
*bp
);
319 * Prepare ILT configurations according to current driver
324 void bnx2x_ilt_set_info(struct bnx2x
*bp
);
327 * Inintialize dcbx protocol
331 void bnx2x_dcbx_init(struct bnx2x
*bp
);
334 * Set power state to the requested value. Currently only D0 and
335 * D3hot are supported.
338 * @param state D0 or D3hot
342 int bnx2x_set_power_state(struct bnx2x
*bp
, pci_power_t state
);
344 /* dev_close main block */
345 int bnx2x_nic_unload(struct bnx2x
*bp
, int unload_mode
);
347 /* dev_open main block */
348 int bnx2x_nic_load(struct bnx2x
*bp
, int load_mode
);
350 /* hard_xmit callback */
351 netdev_tx_t
bnx2x_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
353 /* select_queue callback */
354 u16
bnx2x_select_queue(struct net_device
*dev
, struct sk_buff
*skb
);
356 int bnx2x_change_mac_addr(struct net_device
*dev
, void *p
);
358 /* NAPI poll Rx part */
359 int bnx2x_rx_int(struct bnx2x_fastpath
*fp
, int budget
);
361 /* NAPI poll Tx part */
362 int bnx2x_tx_int(struct bnx2x_fastpath
*fp
);
364 /* suspend/resume callbacks */
365 int bnx2x_suspend(struct pci_dev
*pdev
, pm_message_t state
);
366 int bnx2x_resume(struct pci_dev
*pdev
);
368 /* Release IRQ vectors */
369 void bnx2x_free_irq(struct bnx2x
*bp
);
371 void bnx2x_init_rx_rings(struct bnx2x
*bp
);
372 void bnx2x_free_skbs(struct bnx2x
*bp
);
373 void bnx2x_netif_stop(struct bnx2x
*bp
, int disable_hw
);
374 void bnx2x_netif_start(struct bnx2x
*bp
);
377 * Fill msix_table, request vectors, update num_queues according
378 * to number of available vectors
384 int bnx2x_enable_msix(struct bnx2x
*bp
);
387 * Request msi mode from OS, updated internals accordingly
393 int bnx2x_enable_msi(struct bnx2x
*bp
);
403 int bnx2x_poll(struct napi_struct
*napi
, int budget
);
406 * Allocate/release memories outsize main driver structure
412 int __devinit
bnx2x_alloc_mem_bp(struct bnx2x
*bp
);
413 void bnx2x_free_mem_bp(struct bnx2x
*bp
);
416 * Change mtu netdev callback
423 int bnx2x_change_mtu(struct net_device
*dev
, int new_mtu
);
426 * tx timeout netdev callback
433 void bnx2x_tx_timeout(struct net_device
*dev
);
437 * vlan rx register netdev callback
444 void bnx2x_vlan_rx_register(struct net_device
*dev
,
445 struct vlan_group
*vlgrp
);
449 static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath
*fp
)
451 barrier(); /* status block is written to by the chip */
452 fp
->fp_hc_idx
= fp
->sb_running_index
[SM_RX_ID
];
455 static inline void bnx2x_update_rx_prod(struct bnx2x
*bp
,
456 struct bnx2x_fastpath
*fp
,
457 u16 bd_prod
, u16 rx_comp_prod
,
460 struct ustorm_eth_rx_producers rx_prods
= {0};
463 /* Update producers */
464 rx_prods
.bd_prod
= bd_prod
;
465 rx_prods
.cqe_prod
= rx_comp_prod
;
466 rx_prods
.sge_prod
= rx_sge_prod
;
469 * Make sure that the BD and SGE data is updated before updating the
470 * producers since FW might read the BD/SGE right after the producer
472 * This is only applicable for weak-ordered memory model archs such
473 * as IA-64. The following barrier is also mandatory since FW will
474 * assumes BDs must have buffers.
478 for (i
= 0; i
< sizeof(struct ustorm_eth_rx_producers
)/4; i
++)
480 BAR_USTRORM_INTMEM
+ fp
->ustorm_rx_prods_offset
+ i
*4,
481 ((u32
*)&rx_prods
)[i
]);
483 mmiowb(); /* keep prod updates ordered */
485 DP(NETIF_MSG_RX_STATUS
,
486 "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
487 fp
->index
, bd_prod
, rx_comp_prod
, rx_sge_prod
);
490 static inline void bnx2x_igu_ack_sb_gen(struct bnx2x
*bp
, u8 igu_sb_id
,
491 u8 segment
, u16 index
, u8 op
,
492 u8 update
, u32 igu_addr
)
494 struct igu_regular cmd_data
= {0};
496 cmd_data
.sb_id_and_flags
=
497 ((index
<< IGU_REGULAR_SB_INDEX_SHIFT
) |
498 (segment
<< IGU_REGULAR_SEGMENT_ACCESS_SHIFT
) |
499 (update
<< IGU_REGULAR_BUPDATE_SHIFT
) |
500 (op
<< IGU_REGULAR_ENABLE_INT_SHIFT
));
502 DP(NETIF_MSG_HW
, "write 0x%08x to IGU addr 0x%x\n",
503 cmd_data
.sb_id_and_flags
, igu_addr
);
504 REG_WR(bp
, igu_addr
, cmd_data
.sb_id_and_flags
);
506 /* Make sure that ACK is written */
511 static inline void bnx2x_igu_clear_sb_gen(struct bnx2x
*bp
,
512 u8 idu_sb_id
, bool is_Pf
)
514 u32 data
, ctl
, cnt
= 100;
515 u32 igu_addr_data
= IGU_REG_COMMAND_REG_32LSB_DATA
;
516 u32 igu_addr_ctl
= IGU_REG_COMMAND_REG_CTRL
;
517 u32 igu_addr_ack
= IGU_REG_CSTORM_TYPE_0_SB_CLEANUP
+ (idu_sb_id
/32)*4;
518 u32 sb_bit
= 1 << (idu_sb_id
%32);
519 u32 func_encode
= BP_FUNC(bp
) |
520 ((is_Pf
== true ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT
);
521 u32 addr_encode
= IGU_CMD_E2_PROD_UPD_BASE
+ idu_sb_id
;
523 /* Not supported in BC mode */
524 if (CHIP_INT_MODE_IS_BC(bp
))
527 data
= (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
528 << IGU_REGULAR_CLEANUP_TYPE_SHIFT
) |
529 IGU_REGULAR_CLEANUP_SET
|
530 IGU_REGULAR_BCLEANUP
;
532 ctl
= addr_encode
<< IGU_CTRL_REG_ADDRESS_SHIFT
|
533 func_encode
<< IGU_CTRL_REG_FID_SHIFT
|
534 IGU_CTRL_CMD_TYPE_WR
<< IGU_CTRL_REG_TYPE_SHIFT
;
536 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
537 data
, igu_addr_data
);
538 REG_WR(bp
, igu_addr_data
, data
);
541 DP(NETIF_MSG_HW
, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
543 REG_WR(bp
, igu_addr_ctl
, ctl
);
547 /* wait for clean up to finish */
548 while (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
) && --cnt
)
552 if (!(REG_RD(bp
, igu_addr_ack
) & sb_bit
)) {
553 DP(NETIF_MSG_HW
, "Unable to finish IGU cleanup: "
554 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
555 idu_sb_id
, idu_sb_id
/32, idu_sb_id
%32, cnt
);
559 static inline void bnx2x_hc_ack_sb(struct bnx2x
*bp
, u8 sb_id
,
560 u8 storm
, u16 index
, u8 op
, u8 update
)
562 u32 hc_addr
= (HC_REG_COMMAND_REG
+ BP_PORT(bp
)*32 +
563 COMMAND_REG_INT_ACK
);
564 struct igu_ack_register igu_ack
;
566 igu_ack
.status_block_index
= index
;
567 igu_ack
.sb_id_and_flags
=
568 ((sb_id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
569 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
570 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
571 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
573 DP(BNX2X_MSG_OFF
, "write 0x%08x to HC addr 0x%x\n",
574 (*(u32
*)&igu_ack
), hc_addr
);
575 REG_WR(bp
, hc_addr
, (*(u32
*)&igu_ack
));
577 /* Make sure that ACK is written */
582 static inline void bnx2x_igu_ack_sb(struct bnx2x
*bp
, u8 igu_sb_id
, u8 segment
,
583 u16 index
, u8 op
, u8 update
)
585 u32 igu_addr
= BAR_IGU_INTMEM
+ (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
)*8;
587 bnx2x_igu_ack_sb_gen(bp
, igu_sb_id
, segment
, index
, op
, update
,
591 static inline void bnx2x_ack_sb(struct bnx2x
*bp
, u8 igu_sb_id
, u8 storm
,
592 u16 index
, u8 op
, u8 update
)
594 if (bp
->common
.int_block
== INT_BLOCK_HC
)
595 bnx2x_hc_ack_sb(bp
, igu_sb_id
, storm
, index
, op
, update
);
599 if (CHIP_INT_MODE_IS_BC(bp
))
601 else if (igu_sb_id
!= bp
->igu_dsb_id
)
602 segment
= IGU_SEG_ACCESS_DEF
;
603 else if (storm
== ATTENTION_ID
)
604 segment
= IGU_SEG_ACCESS_ATTN
;
606 segment
= IGU_SEG_ACCESS_DEF
;
607 bnx2x_igu_ack_sb(bp
, igu_sb_id
, segment
, index
, op
, update
);
611 static inline u16
bnx2x_hc_ack_int(struct bnx2x
*bp
)
613 u32 hc_addr
= (HC_REG_COMMAND_REG
+ BP_PORT(bp
)*32 +
614 COMMAND_REG_SIMD_MASK
);
615 u32 result
= REG_RD(bp
, hc_addr
);
617 DP(BNX2X_MSG_OFF
, "read 0x%08x from HC addr 0x%x\n",
624 static inline u16
bnx2x_igu_ack_int(struct bnx2x
*bp
)
626 u32 igu_addr
= (BAR_IGU_INTMEM
+ IGU_REG_SISR_MDPC_WMASK_LSB_UPPER
*8);
627 u32 result
= REG_RD(bp
, igu_addr
);
629 DP(NETIF_MSG_HW
, "read 0x%08x from IGU addr 0x%x\n",
636 static inline u16
bnx2x_ack_int(struct bnx2x
*bp
)
639 if (bp
->common
.int_block
== INT_BLOCK_HC
)
640 return bnx2x_hc_ack_int(bp
);
642 return bnx2x_igu_ack_int(bp
);
645 static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath
*fp
)
647 /* Tell compiler that consumer and producer can change */
649 return fp
->tx_pkt_prod
!= fp
->tx_pkt_cons
;
652 static inline u16
bnx2x_tx_avail(struct bnx2x_fastpath
*fp
)
658 prod
= fp
->tx_bd_prod
;
659 cons
= fp
->tx_bd_cons
;
661 /* NUM_TX_RINGS = number of "next-page" entries
662 It will be used as a threshold */
663 used
= SUB_S16(prod
, cons
) + (s16
)NUM_TX_RINGS
;
665 #ifdef BNX2X_STOP_ON_ERROR
667 WARN_ON(used
> fp
->bp
->tx_ring_size
);
668 WARN_ON((fp
->bp
->tx_ring_size
- used
) > MAX_TX_AVAIL
);
671 return (s16
)(fp
->bp
->tx_ring_size
) - used
;
674 static inline int bnx2x_has_tx_work(struct bnx2x_fastpath
*fp
)
678 /* Tell compiler that status block fields can change */
680 hw_cons
= le16_to_cpu(*fp
->tx_cons_sb
);
681 return hw_cons
!= fp
->tx_pkt_cons
;
684 static inline int bnx2x_has_rx_work(struct bnx2x_fastpath
*fp
)
688 /* Tell compiler that status block fields can change */
690 rx_cons_sb
= le16_to_cpu(*fp
->rx_cons_sb
);
691 if ((rx_cons_sb
& MAX_RCQ_DESC_CNT
) == MAX_RCQ_DESC_CNT
)
693 return (fp
->rx_comp_cons
!= rx_cons_sb
);
697 * disables tx from stack point of view
701 static inline void bnx2x_tx_disable(struct bnx2x
*bp
)
703 netif_tx_disable(bp
->dev
);
704 netif_carrier_off(bp
->dev
);
707 static inline void bnx2x_free_rx_sge(struct bnx2x
*bp
,
708 struct bnx2x_fastpath
*fp
, u16 index
)
710 struct sw_rx_page
*sw_buf
= &fp
->rx_page_ring
[index
];
711 struct page
*page
= sw_buf
->page
;
712 struct eth_rx_sge
*sge
= &fp
->rx_sge_ring
[index
];
714 /* Skip "next page" elements */
718 dma_unmap_page(&bp
->pdev
->dev
, dma_unmap_addr(sw_buf
, mapping
),
719 SGE_PAGE_SIZE
*PAGES_PER_SGE
, DMA_FROM_DEVICE
);
720 __free_pages(page
, PAGES_PER_SGE_SHIFT
);
727 static inline void bnx2x_add_all_napi(struct bnx2x
*bp
)
731 /* Add NAPI objects */
732 for_each_napi_queue(bp
, i
)
733 netif_napi_add(bp
->dev
, &bnx2x_fp(bp
, i
, napi
),
734 bnx2x_poll
, BNX2X_NAPI_WEIGHT
);
737 static inline void bnx2x_del_all_napi(struct bnx2x
*bp
)
741 for_each_napi_queue(bp
, i
)
742 netif_napi_del(&bnx2x_fp(bp
, i
, napi
));
745 static inline void bnx2x_disable_msi(struct bnx2x
*bp
)
747 if (bp
->flags
& USING_MSIX_FLAG
) {
748 pci_disable_msix(bp
->pdev
);
749 bp
->flags
&= ~USING_MSIX_FLAG
;
750 } else if (bp
->flags
& USING_MSI_FLAG
) {
751 pci_disable_msi(bp
->pdev
);
752 bp
->flags
&= ~USING_MSI_FLAG
;
756 static inline int bnx2x_calc_num_queues(struct bnx2x
*bp
)
759 min_t(int, num_queues
, BNX2X_MAX_QUEUES(bp
)) :
760 min_t(int, num_online_cpus(), BNX2X_MAX_QUEUES(bp
));
763 static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath
*fp
)
767 for (i
= 1; i
<= NUM_RX_SGE_PAGES
; i
++) {
768 int idx
= RX_SGE_CNT
* i
- 1;
770 for (j
= 0; j
< 2; j
++) {
771 SGE_MASK_CLEAR_BIT(fp
, idx
);
777 static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath
*fp
)
779 /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
780 memset(fp
->sge_mask
, 0xff,
781 (NUM_RX_SGE
>> RX_SGE_MASK_ELEM_SHIFT
)*sizeof(u64
));
783 /* Clear the two last indices in the page to 1:
784 these are the indices that correspond to the "next" element,
785 hence will never be indicated and should be removed from
787 bnx2x_clear_sge_mask_next_elems(fp
);
790 static inline int bnx2x_alloc_rx_sge(struct bnx2x
*bp
,
791 struct bnx2x_fastpath
*fp
, u16 index
)
793 struct page
*page
= alloc_pages(GFP_ATOMIC
, PAGES_PER_SGE_SHIFT
);
794 struct sw_rx_page
*sw_buf
= &fp
->rx_page_ring
[index
];
795 struct eth_rx_sge
*sge
= &fp
->rx_sge_ring
[index
];
798 if (unlikely(page
== NULL
))
801 mapping
= dma_map_page(&bp
->pdev
->dev
, page
, 0,
802 SGE_PAGE_SIZE
*PAGES_PER_SGE
, DMA_FROM_DEVICE
);
803 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
804 __free_pages(page
, PAGES_PER_SGE_SHIFT
);
809 dma_unmap_addr_set(sw_buf
, mapping
, mapping
);
811 sge
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
812 sge
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
817 static inline int bnx2x_alloc_rx_skb(struct bnx2x
*bp
,
818 struct bnx2x_fastpath
*fp
, u16 index
)
821 struct sw_rx_bd
*rx_buf
= &fp
->rx_buf_ring
[index
];
822 struct eth_rx_bd
*rx_bd
= &fp
->rx_desc_ring
[index
];
825 skb
= netdev_alloc_skb(bp
->dev
, bp
->rx_buf_size
);
826 if (unlikely(skb
== NULL
))
829 mapping
= dma_map_single(&bp
->pdev
->dev
, skb
->data
, bp
->rx_buf_size
,
831 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
837 dma_unmap_addr_set(rx_buf
, mapping
, mapping
);
839 rx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
840 rx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
845 /* note that we are not allocating a new skb,
846 * we are just moving one from cons to prod
847 * we are not creating a new mapping,
848 * so there is no need to check for dma_mapping_error().
850 static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath
*fp
,
853 struct bnx2x
*bp
= fp
->bp
;
854 struct sw_rx_bd
*cons_rx_buf
= &fp
->rx_buf_ring
[cons
];
855 struct sw_rx_bd
*prod_rx_buf
= &fp
->rx_buf_ring
[prod
];
856 struct eth_rx_bd
*cons_bd
= &fp
->rx_desc_ring
[cons
];
857 struct eth_rx_bd
*prod_bd
= &fp
->rx_desc_ring
[prod
];
859 dma_sync_single_for_device(&bp
->pdev
->dev
,
860 dma_unmap_addr(cons_rx_buf
, mapping
),
861 RX_COPY_THRESH
, DMA_FROM_DEVICE
);
863 prod_rx_buf
->skb
= cons_rx_buf
->skb
;
864 dma_unmap_addr_set(prod_rx_buf
, mapping
,
865 dma_unmap_addr(cons_rx_buf
, mapping
));
869 static inline void bnx2x_free_rx_sge_range(struct bnx2x
*bp
,
870 struct bnx2x_fastpath
*fp
, int last
)
874 for (i
= 0; i
< last
; i
++)
875 bnx2x_free_rx_sge(bp
, fp
, i
);
878 static inline void bnx2x_free_tpa_pool(struct bnx2x
*bp
,
879 struct bnx2x_fastpath
*fp
, int last
)
883 for (i
= 0; i
< last
; i
++) {
884 struct sw_rx_bd
*rx_buf
= &(fp
->tpa_pool
[i
]);
885 struct sk_buff
*skb
= rx_buf
->skb
;
888 DP(NETIF_MSG_IFDOWN
, "tpa bin %d empty on free\n", i
);
892 if (fp
->tpa_state
[i
] == BNX2X_TPA_START
)
893 dma_unmap_single(&bp
->pdev
->dev
,
894 dma_unmap_addr(rx_buf
, mapping
),
895 bp
->rx_buf_size
, DMA_FROM_DEVICE
);
903 static inline void bnx2x_init_tx_rings(struct bnx2x
*bp
)
907 for_each_tx_queue(bp
, j
) {
908 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
910 for (i
= 1; i
<= NUM_TX_RINGS
; i
++) {
911 struct eth_tx_next_bd
*tx_next_bd
=
912 &fp
->tx_desc_ring
[TX_DESC_CNT
* i
- 1].next_bd
;
914 tx_next_bd
->addr_hi
=
915 cpu_to_le32(U64_HI(fp
->tx_desc_mapping
+
916 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
917 tx_next_bd
->addr_lo
=
918 cpu_to_le32(U64_LO(fp
->tx_desc_mapping
+
919 BCM_PAGE_SIZE
*(i
% NUM_TX_RINGS
)));
922 SET_FLAG(fp
->tx_db
.data
.header
.header
, DOORBELL_HDR_DB_TYPE
, 1);
923 fp
->tx_db
.data
.zero_fill1
= 0;
924 fp
->tx_db
.data
.prod
= 0;
934 static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath
*fp
)
938 for (i
= 1; i
<= NUM_RX_RINGS
; i
++) {
939 struct eth_rx_bd
*rx_bd
;
941 rx_bd
= &fp
->rx_desc_ring
[RX_DESC_CNT
* i
- 2];
943 cpu_to_le32(U64_HI(fp
->rx_desc_mapping
+
944 BCM_PAGE_SIZE
*(i
% NUM_RX_RINGS
)));
946 cpu_to_le32(U64_LO(fp
->rx_desc_mapping
+
947 BCM_PAGE_SIZE
*(i
% NUM_RX_RINGS
)));
951 static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath
*fp
)
955 for (i
= 1; i
<= NUM_RX_SGE_PAGES
; i
++) {
956 struct eth_rx_sge
*sge
;
958 sge
= &fp
->rx_sge_ring
[RX_SGE_CNT
* i
- 2];
960 cpu_to_le32(U64_HI(fp
->rx_sge_mapping
+
961 BCM_PAGE_SIZE
*(i
% NUM_RX_SGE_PAGES
)));
964 cpu_to_le32(U64_LO(fp
->rx_sge_mapping
+
965 BCM_PAGE_SIZE
*(i
% NUM_RX_SGE_PAGES
)));
969 static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath
*fp
)
972 for (i
= 1; i
<= NUM_RCQ_RINGS
; i
++) {
973 struct eth_rx_cqe_next_page
*nextpg
;
975 nextpg
= (struct eth_rx_cqe_next_page
*)
976 &fp
->rx_comp_ring
[RCQ_DESC_CNT
* i
- 1];
978 cpu_to_le32(U64_HI(fp
->rx_comp_mapping
+
979 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
981 cpu_to_le32(U64_LO(fp
->rx_comp_mapping
+
982 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
987 static inline void bnx2x_init_fcoe_fp(struct bnx2x
*bp
)
989 bnx2x_fcoe(bp
, cl_id
) = BNX2X_FCOE_ETH_CL_ID
+
990 BP_E1HVN(bp
) * NONE_ETH_CONTEXT_USE
;
991 bnx2x_fcoe(bp
, cid
) = BNX2X_FCOE_ETH_CID
;
992 bnx2x_fcoe(bp
, fw_sb_id
) = DEF_SB_ID
;
993 bnx2x_fcoe(bp
, igu_sb_id
) = bp
->igu_dsb_id
;
994 bnx2x_fcoe(bp
, bp
) = bp
;
995 bnx2x_fcoe(bp
, state
) = BNX2X_FP_STATE_CLOSED
;
996 bnx2x_fcoe(bp
, index
) = FCOE_IDX
;
997 bnx2x_fcoe(bp
, rx_cons_sb
) = BNX2X_FCOE_L2_RX_INDEX
;
998 bnx2x_fcoe(bp
, tx_cons_sb
) = BNX2X_FCOE_L2_TX_INDEX
;
999 /* qZone id equals to FW (per path) client id */
1000 bnx2x_fcoe(bp
, cl_qzone_id
) = bnx2x_fcoe(bp
, cl_id
) +
1001 BP_PORT(bp
)*(CHIP_IS_E2(bp
) ? ETH_MAX_RX_CLIENTS_E2
:
1002 ETH_MAX_RX_CLIENTS_E1H
);
1004 bnx2x_fcoe(bp
, ustorm_rx_prods_offset
) = CHIP_IS_E2(bp
) ?
1005 USTORM_RX_PRODS_E2_OFFSET(bnx2x_fcoe(bp
, cl_qzone_id
)) :
1006 USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp
), bnx2x_fcoe_fp(bp
)->cl_id
);
1011 static inline void __storm_memset_struct(struct bnx2x
*bp
,
1012 u32 addr
, size_t size
, u32
*data
)
1015 for (i
= 0; i
< size
/4; i
++)
1016 REG_WR(bp
, addr
+ (i
* 4), data
[i
]);
1019 static inline void storm_memset_mac_filters(struct bnx2x
*bp
,
1020 struct tstorm_eth_mac_filter_config
*mac_filters
,
1023 size_t size
= sizeof(struct tstorm_eth_mac_filter_config
);
1025 u32 addr
= BAR_TSTRORM_INTMEM
+
1026 TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid
);
1028 __storm_memset_struct(bp
, addr
, size
, (u32
*)mac_filters
);
1031 static inline void storm_memset_cmng(struct bnx2x
*bp
,
1032 struct cmng_struct_per_port
*cmng
,
1035 size_t size
= sizeof(struct cmng_struct_per_port
);
1037 u32 addr
= BAR_XSTRORM_INTMEM
+
1038 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port
);
1040 __storm_memset_struct(bp
, addr
, size
, (u32
*)cmng
);
1043 /* HW Lock for shared dual port PHYs */
1044 void bnx2x_acquire_phy_lock(struct bnx2x
*bp
);
1045 void bnx2x_release_phy_lock(struct bnx2x
*bp
);
1047 #endif /* BNX2X_CMN_H */