blob: 4bb011358ed9a4a41605dd156dab0cee7fd65aab [file] [log] [blame]
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001/* bnx2x_cmn.h: Broadcom Everest network driver.
2 *
3 * Copyright (c) 2007-2010 Broadcom Corporation
4 *
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.
8 *
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
15 *
16 */
17#ifndef BNX2X_CMN_H
18#define BNX2X_CMN_H
19
20#include <linux/types.h>
21#include <linux/netdevice.h>
22
23
24#include "bnx2x.h"
25
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000026extern int num_queues;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000027
28/*********************** Interfaces ****************************
29 * Functions that need to be implemented by each driver version
30 */
31
32/**
33 * Initialize link parameters structure variables.
34 *
35 * @param bp
36 * @param load_mode
37 *
38 * @return u8
39 */
40u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode);
41
42/**
43 * Configure hw according to link parameters structure.
44 *
45 * @param bp
46 */
47void bnx2x_link_set(struct bnx2x *bp);
48
49/**
50 * Query link status
51 *
52 * @param bp
Yaniv Rosnera22f0782010-09-07 11:41:20 +000053 * @param is_serdes
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000054 *
55 * @return 0 - link is UP
56 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000057u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000058
59/**
60 * Handles link status change
61 *
62 * @param bp
63 */
64void bnx2x__link_status_update(struct bnx2x *bp);
65
66/**
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000067 * Report link status to upper layer
68 *
69 * @param bp
70 *
71 * @return int
72 */
73void bnx2x_link_report(struct bnx2x *bp);
74
75/**
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080076 * calculates MF speed according to current linespeed and MF
77 * configuration
78 *
79 * @param bp
80 *
81 * @return u16
82 */
83u16 bnx2x_get_mf_speed(struct bnx2x *bp);
84
85/**
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000086 * MSI-X slowpath interrupt handler
87 *
88 * @param irq
89 * @param dev_instance
90 *
91 * @return irqreturn_t
92 */
93irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance);
94
95/**
96 * non MSI-X interrupt handler
97 *
98 * @param irq
99 * @param dev_instance
100 *
101 * @return irqreturn_t
102 */
103irqreturn_t bnx2x_interrupt(int irq, void *dev_instance);
104#ifdef BCM_CNIC
105
106/**
107 * Send command to cnic driver
108 *
109 * @param bp
110 * @param cmd
111 */
112int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
113
114/**
115 * Provides cnic information for proper interrupt handling
116 *
117 * @param bp
118 */
119void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
120#endif
121
122/**
123 * Enable HW interrupts.
124 *
125 * @param bp
126 */
127void bnx2x_int_enable(struct bnx2x *bp);
128
129/**
130 * Disable interrupts. This function ensures that there are no
131 * ISRs or SP DPCs (sp_task) are running after it returns.
132 *
133 * @param bp
134 * @param disable_hw if true, disable HW interrupts.
135 */
136void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw);
137
138/**
Dmitry Kravkov6891dd22010-08-03 21:49:40 +0000139 * Loads device firmware
140 *
141 * @param bp
142 *
143 * @return int
144 */
145int bnx2x_init_firmware(struct bnx2x *bp);
146
147/**
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000148 * Init HW blocks according to current initialization stage:
149 * COMMON, PORT or FUNCTION.
150 *
151 * @param bp
152 * @param load_code: COMMON, PORT or FUNCTION
153 *
154 * @return int
155 */
156int bnx2x_init_hw(struct bnx2x *bp, u32 load_code);
157
158/**
159 * Init driver internals:
160 * - rings
161 * - status blocks
162 * - etc.
163 *
164 * @param bp
165 * @param load_code COMMON, PORT or FUNCTION
166 */
167void bnx2x_nic_init(struct bnx2x *bp, u32 load_code);
168
169/**
170 * Allocate driver's memory.
171 *
172 * @param bp
173 *
174 * @return int
175 */
176int bnx2x_alloc_mem(struct bnx2x *bp);
177
178/**
179 * Release driver's memory.
180 *
181 * @param bp
182 */
183void bnx2x_free_mem(struct bnx2x *bp);
184
185/**
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000186 * Setup eth Client.
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000187 *
188 * @param bp
189 * @param fp
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000190 * @param is_leading
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000191 *
192 * @return int
193 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000194int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp,
195 int is_leading);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000196
197/**
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000198 * Set number of queues according to mode
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000199 *
200 * @param bp
201 *
202 */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000203void bnx2x_set_num_queues(struct bnx2x *bp);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000204
205/**
206 * Cleanup chip internals:
207 * - Cleanup MAC configuration.
208 * - Close clients.
209 * - etc.
210 *
211 * @param bp
212 * @param unload_mode
213 */
214void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode);
215
216/**
217 * Acquire HW lock.
218 *
219 * @param bp
220 * @param resource Resource bit which was locked
221 *
222 * @return int
223 */
224int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource);
225
226/**
227 * Release HW lock.
228 *
229 * @param bp driver handle
230 * @param resource Resource bit which was locked
231 *
232 * @return int
233 */
234int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
235
236/**
237 * Configure eth MAC address in the HW according to the value in
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000238 * netdev->dev_addr.
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000239 *
240 * @param bp driver handle
241 * @param set
242 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000243void bnx2x_set_eth_mac(struct bnx2x *bp, int set);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000244
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000245#ifdef BCM_CNIC
246/**
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
249 * returns.
250 *
251 * @param bp driver handle
252 * @param set set or clear the CAM entry
253 *
254 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
255 */
256int bnx2x_set_fip_eth_mac_addr(struct bnx2x *bp, int set);
257
258/**
259 * Set/Clear ALL_ENODE mcast MAC.
260 *
261 * @param bp
262 * @param set
263 *
264 * @return int
265 */
266int bnx2x_set_all_enode_macs(struct bnx2x *bp, int set);
267#endif
268
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000269/**
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000270 * Set MAC filtering configurations.
271 *
272 * @remarks called with netif_tx_lock from dev_mcast.c
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000273 *
274 * @param dev net_device
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000275 */
276void bnx2x_set_rx_mode(struct net_device *dev);
277
278/**
279 * Configure MAC filtering rules in a FW.
280 *
281 * @param bp driver handle
282 */
283void bnx2x_set_storm_rx_mode(struct bnx2x *bp);
284
285/* Parity errors related */
286void bnx2x_inc_load_cnt(struct bnx2x *bp);
287u32 bnx2x_dec_load_cnt(struct bnx2x *bp);
288bool bnx2x_chk_parity_attn(struct bnx2x *bp);
289bool bnx2x_reset_is_done(struct bnx2x *bp);
290void bnx2x_disable_close_the_gate(struct bnx2x *bp);
291
292/**
293 * Perform statistics handling according to event
294 *
295 * @param bp driver handle
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000296 * @param event bnx2x_stats_event
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000297 */
298void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
299
300/**
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000301 * Handle ramrods completion
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000302 *
303 * @param fp fastpath handle for the event
304 * @param rr_cqe eth_rx_cqe
305 */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000306void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000307
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000308/**
309 * Init/halt function before/after sending
310 * CLIENT_SETUP/CFC_DEL for the first/last client.
311 *
312 * @param bp
313 *
314 * @return int
315 */
316int bnx2x_func_start(struct bnx2x *bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000317
318/**
319 * Prepare ILT configurations according to current driver
320 * parameters.
321 *
322 * @param bp
323 */
324void bnx2x_ilt_set_info(struct bnx2x *bp);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000325
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000326/**
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000327 * Set power state to the requested value. Currently only D0 and
328 * D3hot are supported.
329 *
330 * @param bp
331 * @param state D0 or D3hot
332 *
333 * @return int
334 */
335int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
336
337/* dev_close main block */
338int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode);
339
340/* dev_open main block */
341int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
342
343/* hard_xmit callback */
344netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
345
346int bnx2x_change_mac_addr(struct net_device *dev, void *p);
347
348/* NAPI poll Rx part */
349int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget);
350
351/* NAPI poll Tx part */
352int bnx2x_tx_int(struct bnx2x_fastpath *fp);
353
354/* suspend/resume callbacks */
355int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
356int bnx2x_resume(struct pci_dev *pdev);
357
358/* Release IRQ vectors */
359void bnx2x_free_irq(struct bnx2x *bp);
360
361void bnx2x_init_rx_rings(struct bnx2x *bp);
362void bnx2x_free_skbs(struct bnx2x *bp);
363void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
364void bnx2x_netif_start(struct bnx2x *bp);
365
366/**
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000367 * Fill msix_table, request vectors, update num_queues according
368 * to number of available vectors
369 *
370 * @param bp
371 *
372 * @return int
373 */
374int bnx2x_enable_msix(struct bnx2x *bp);
375
376/**
377 * Request msi mode from OS, updated internals accordingly
378 *
379 * @param bp
380 *
381 * @return int
382 */
383int bnx2x_enable_msi(struct bnx2x *bp);
384
385/**
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000386 * NAPI callback
387 *
388 * @param napi
389 * @param budget
390 *
391 * @return int
392 */
393int bnx2x_poll(struct napi_struct *napi, int budget);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000394
395/**
396 * Allocate/release memories outsize main driver structure
397 *
398 * @param bp
399 *
400 * @return int
401 */
402int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp);
403void bnx2x_free_mem_bp(struct bnx2x *bp);
404
405/**
406 * Change mtu netdev callback
407 *
408 * @param dev
409 * @param new_mtu
410 *
411 * @return int
412 */
413int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
414
415/**
416 * tx timeout netdev callback
417 *
418 * @param dev
419 * @param new_mtu
420 *
421 * @return int
422 */
423void bnx2x_tx_timeout(struct net_device *dev);
424
425#ifdef BCM_VLAN
426/**
427 * vlan rx register netdev callback
428 *
429 * @param dev
430 * @param new_mtu
431 *
432 * @return int
433 */
434void bnx2x_vlan_rx_register(struct net_device *dev,
435 struct vlan_group *vlgrp);
436
437#endif
438
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000439static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
440{
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000441 barrier(); /* status block is written to by the chip */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000442 fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID];
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000443}
444
445static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
446 struct bnx2x_fastpath *fp,
447 u16 bd_prod, u16 rx_comp_prod,
448 u16 rx_sge_prod)
449{
450 struct ustorm_eth_rx_producers rx_prods = {0};
451 int i;
452
453 /* Update producers */
454 rx_prods.bd_prod = bd_prod;
455 rx_prods.cqe_prod = rx_comp_prod;
456 rx_prods.sge_prod = rx_sge_prod;
457
458 /*
459 * Make sure that the BD and SGE data is updated before updating the
460 * producers since FW might read the BD/SGE right after the producer
461 * is updated.
462 * This is only applicable for weak-ordered memory model archs such
463 * as IA-64. The following barrier is also mandatory since FW will
464 * assumes BDs must have buffers.
465 */
466 wmb();
467
468 for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000469 REG_WR(bp,
470 BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset + i*4,
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000471 ((u32 *)&rx_prods)[i]);
472
473 mmiowb(); /* keep prod updates ordered */
474
475 DP(NETIF_MSG_RX_STATUS,
476 "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
477 fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
478}
479
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000480static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id,
481 u8 segment, u16 index, u8 op,
482 u8 update, u32 igu_addr)
483{
484 struct igu_regular cmd_data = {0};
485
486 cmd_data.sb_id_and_flags =
487 ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
488 (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
489 (update << IGU_REGULAR_BUPDATE_SHIFT) |
490 (op << IGU_REGULAR_ENABLE_INT_SHIFT));
491
492 DP(NETIF_MSG_HW, "write 0x%08x to IGU addr 0x%x\n",
493 cmd_data.sb_id_and_flags, igu_addr);
494 REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags);
495
496 /* Make sure that ACK is written */
497 mmiowb();
498 barrier();
499}
500
501static inline void bnx2x_igu_clear_sb_gen(struct bnx2x *bp,
502 u8 idu_sb_id, bool is_Pf)
503{
504 u32 data, ctl, cnt = 100;
505 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
506 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
507 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
508 u32 sb_bit = 1 << (idu_sb_id%32);
509 u32 func_encode = BP_FUNC(bp) |
510 ((is_Pf == true ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT);
511 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
512
513 /* Not supported in BC mode */
514 if (CHIP_INT_MODE_IS_BC(bp))
515 return;
516
517 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
518 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
519 IGU_REGULAR_CLEANUP_SET |
520 IGU_REGULAR_BCLEANUP;
521
522 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
523 func_encode << IGU_CTRL_REG_FID_SHIFT |
524 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
525
526 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
527 data, igu_addr_data);
528 REG_WR(bp, igu_addr_data, data);
529 mmiowb();
530 barrier();
531 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
532 ctl, igu_addr_ctl);
533 REG_WR(bp, igu_addr_ctl, ctl);
534 mmiowb();
535 barrier();
536
537 /* wait for clean up to finish */
538 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
539 msleep(20);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000540
541
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000542 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
543 DP(NETIF_MSG_HW, "Unable to finish IGU cleanup: "
544 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
545 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
546 }
547}
548
549static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id,
550 u8 storm, u16 index, u8 op, u8 update)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000551{
552 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
553 COMMAND_REG_INT_ACK);
554 struct igu_ack_register igu_ack;
555
556 igu_ack.status_block_index = index;
557 igu_ack.sb_id_and_flags =
558 ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
559 (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
560 (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
561 (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
562
563 DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
564 (*(u32 *)&igu_ack), hc_addr);
565 REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
566
567 /* Make sure that ACK is written */
568 mmiowb();
569 barrier();
570}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000571
572static inline void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
573 u16 index, u8 op, u8 update)
574{
575 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
576
577 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
578 igu_addr);
579}
580
581static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm,
582 u16 index, u8 op, u8 update)
583{
584 if (bp->common.int_block == INT_BLOCK_HC)
585 bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update);
586 else {
587 u8 segment;
588
589 if (CHIP_INT_MODE_IS_BC(bp))
590 segment = storm;
591 else if (igu_sb_id != bp->igu_dsb_id)
592 segment = IGU_SEG_ACCESS_DEF;
593 else if (storm == ATTENTION_ID)
594 segment = IGU_SEG_ACCESS_ATTN;
595 else
596 segment = IGU_SEG_ACCESS_DEF;
597 bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update);
598 }
599}
600
601static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000602{
603 u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
604 COMMAND_REG_SIMD_MASK);
605 u32 result = REG_RD(bp, hc_addr);
606
607 DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
608 result, hc_addr);
609
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000610 barrier();
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000611 return result;
612}
613
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000614static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp)
615{
616 u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8);
617 u32 result = REG_RD(bp, igu_addr);
618
619 DP(NETIF_MSG_HW, "read 0x%08x from IGU addr 0x%x\n",
620 result, igu_addr);
621
622 barrier();
623 return result;
624}
625
626static inline u16 bnx2x_ack_int(struct bnx2x *bp)
627{
628 barrier();
629 if (bp->common.int_block == INT_BLOCK_HC)
630 return bnx2x_hc_ack_int(bp);
631 else
632 return bnx2x_igu_ack_int(bp);
633}
634
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000635static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
636{
637 /* Tell compiler that consumer and producer can change */
638 barrier();
Eric Dumazet807540b2010-09-23 05:40:09 +0000639 return fp->tx_pkt_prod != fp->tx_pkt_cons;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000640}
641
642static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
643{
644 s16 used;
645 u16 prod;
646 u16 cons;
647
648 prod = fp->tx_bd_prod;
649 cons = fp->tx_bd_cons;
650
651 /* NUM_TX_RINGS = number of "next-page" entries
652 It will be used as a threshold */
653 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
654
655#ifdef BNX2X_STOP_ON_ERROR
656 WARN_ON(used < 0);
657 WARN_ON(used > fp->bp->tx_ring_size);
658 WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
659#endif
660
661 return (s16)(fp->bp->tx_ring_size) - used;
662}
663
664static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
665{
666 u16 hw_cons;
667
668 /* Tell compiler that status block fields can change */
669 barrier();
670 hw_cons = le16_to_cpu(*fp->tx_cons_sb);
671 return hw_cons != fp->tx_pkt_cons;
672}
673
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000674static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
675{
676 u16 rx_cons_sb;
677
678 /* Tell compiler that status block fields can change */
679 barrier();
680 rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
681 if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
682 rx_cons_sb++;
683 return (fp->rx_comp_cons != rx_cons_sb);
684}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000685
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000686/**
687 * disables tx from stack point of view
688 *
689 * @param bp
690 */
691static inline void bnx2x_tx_disable(struct bnx2x *bp)
692{
693 netif_tx_disable(bp->dev);
694 netif_carrier_off(bp->dev);
695}
696
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000697static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
698 struct bnx2x_fastpath *fp, u16 index)
699{
700 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
701 struct page *page = sw_buf->page;
702 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
703
704 /* Skip "next page" elements */
705 if (!page)
706 return;
707
708 dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
Dmitry Kravkov4bca60f2010-10-06 03:30:27 +0000709 SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000710 __free_pages(page, PAGES_PER_SGE_SHIFT);
711
712 sw_buf->page = NULL;
713 sge->addr_hi = 0;
714 sge->addr_lo = 0;
715}
716
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000717static inline void bnx2x_add_all_napi(struct bnx2x *bp)
718{
719 int i;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000720
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000721 /* Add NAPI objects */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000722 for_each_napi_queue(bp, i)
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000723 netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
724 bnx2x_poll, BNX2X_NAPI_WEIGHT);
725}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000726
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000727static inline void bnx2x_del_all_napi(struct bnx2x *bp)
728{
729 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000730
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000731 for_each_napi_queue(bp, i)
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000732 netif_napi_del(&bnx2x_fp(bp, i, napi));
733}
734
735static inline void bnx2x_disable_msi(struct bnx2x *bp)
736{
737 if (bp->flags & USING_MSIX_FLAG) {
738 pci_disable_msix(bp->pdev);
739 bp->flags &= ~USING_MSIX_FLAG;
740 } else if (bp->flags & USING_MSI_FLAG) {
741 pci_disable_msi(bp->pdev);
742 bp->flags &= ~USING_MSI_FLAG;
743 }
744}
745
746static inline int bnx2x_calc_num_queues(struct bnx2x *bp)
747{
748 return num_queues ?
749 min_t(int, num_queues, BNX2X_MAX_QUEUES(bp)) :
750 min_t(int, num_online_cpus(), BNX2X_MAX_QUEUES(bp));
751}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000752
753static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
754{
755 int i, j;
756
757 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
758 int idx = RX_SGE_CNT * i - 1;
759
760 for (j = 0; j < 2; j++) {
761 SGE_MASK_CLEAR_BIT(fp, idx);
762 idx--;
763 }
764 }
765}
766
767static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
768{
769 /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
770 memset(fp->sge_mask, 0xff,
771 (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
772
773 /* Clear the two last indices in the page to 1:
774 these are the indices that correspond to the "next" element,
775 hence will never be indicated and should be removed from
776 the calculations. */
777 bnx2x_clear_sge_mask_next_elems(fp);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000778}
779
780static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
781 struct bnx2x_fastpath *fp, u16 index)
782{
783 struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
784 struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
785 struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
786 dma_addr_t mapping;
787
788 if (unlikely(page == NULL))
789 return -ENOMEM;
790
791 mapping = dma_map_page(&bp->pdev->dev, page, 0,
792 SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
793 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
794 __free_pages(page, PAGES_PER_SGE_SHIFT);
795 return -ENOMEM;
796 }
797
798 sw_buf->page = page;
799 dma_unmap_addr_set(sw_buf, mapping, mapping);
800
801 sge->addr_hi = cpu_to_le32(U64_HI(mapping));
802 sge->addr_lo = cpu_to_le32(U64_LO(mapping));
803
804 return 0;
805}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000806
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000807static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
808 struct bnx2x_fastpath *fp, u16 index)
809{
810 struct sk_buff *skb;
811 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
812 struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
813 dma_addr_t mapping;
814
815 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
816 if (unlikely(skb == NULL))
817 return -ENOMEM;
818
819 mapping = dma_map_single(&bp->pdev->dev, skb->data, bp->rx_buf_size,
820 DMA_FROM_DEVICE);
821 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
822 dev_kfree_skb(skb);
823 return -ENOMEM;
824 }
825
826 rx_buf->skb = skb;
827 dma_unmap_addr_set(rx_buf, mapping, mapping);
828
829 rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
830 rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
831
832 return 0;
833}
834
835/* note that we are not allocating a new skb,
836 * we are just moving one from cons to prod
837 * we are not creating a new mapping,
838 * so there is no need to check for dma_mapping_error().
839 */
840static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
Dmitry Kravkov749a8502010-10-06 03:29:05 +0000841 u16 cons, u16 prod)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000842{
843 struct bnx2x *bp = fp->bp;
844 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
845 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
846 struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
847 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
848
849 dma_sync_single_for_device(&bp->pdev->dev,
850 dma_unmap_addr(cons_rx_buf, mapping),
851 RX_COPY_THRESH, DMA_FROM_DEVICE);
852
853 prod_rx_buf->skb = cons_rx_buf->skb;
854 dma_unmap_addr_set(prod_rx_buf, mapping,
855 dma_unmap_addr(cons_rx_buf, mapping));
856 *prod_bd = *cons_bd;
857}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000858
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000859static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
860 struct bnx2x_fastpath *fp, int last)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000861{
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000862 int i;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000863
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000864 for (i = 0; i < last; i++)
865 bnx2x_free_rx_sge(bp, fp, i);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000866}
867
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000868static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
869 struct bnx2x_fastpath *fp, int last)
870{
871 int i;
872
873 for (i = 0; i < last; i++) {
874 struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
875 struct sk_buff *skb = rx_buf->skb;
876
877 if (skb == NULL) {
878 DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
879 continue;
880 }
881
882 if (fp->tpa_state[i] == BNX2X_TPA_START)
883 dma_unmap_single(&bp->pdev->dev,
884 dma_unmap_addr(rx_buf, mapping),
885 bp->rx_buf_size, DMA_FROM_DEVICE);
886
887 dev_kfree_skb(skb);
888 rx_buf->skb = NULL;
889 }
890}
891
892
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000893static inline void bnx2x_init_tx_rings(struct bnx2x *bp)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000894{
895 int i, j;
896
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000897 for_each_tx_queue(bp, j) {
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000898 struct bnx2x_fastpath *fp = &bp->fp[j];
899
900 for (i = 1; i <= NUM_TX_RINGS; i++) {
901 struct eth_tx_next_bd *tx_next_bd =
902 &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
903
904 tx_next_bd->addr_hi =
905 cpu_to_le32(U64_HI(fp->tx_desc_mapping +
906 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
907 tx_next_bd->addr_lo =
908 cpu_to_le32(U64_LO(fp->tx_desc_mapping +
909 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
910 }
911
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000912 SET_FLAG(fp->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000913 fp->tx_db.data.zero_fill1 = 0;
914 fp->tx_db.data.prod = 0;
915
916 fp->tx_pkt_prod = 0;
917 fp->tx_pkt_cons = 0;
918 fp->tx_bd_prod = 0;
919 fp->tx_bd_cons = 0;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000920 fp->tx_pkt = 0;
921 }
922}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000923
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000924static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000925{
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000926 int i;
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000927
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000928 for (i = 1; i <= NUM_RX_RINGS; i++) {
929 struct eth_rx_bd *rx_bd;
930
931 rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
932 rx_bd->addr_hi =
933 cpu_to_le32(U64_HI(fp->rx_desc_mapping +
934 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
935 rx_bd->addr_lo =
936 cpu_to_le32(U64_LO(fp->rx_desc_mapping +
937 BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
938 }
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +0000939}
940
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000941static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath *fp)
942{
943 int i;
944
945 for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
946 struct eth_rx_sge *sge;
947
948 sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
949 sge->addr_hi =
950 cpu_to_le32(U64_HI(fp->rx_sge_mapping +
951 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
952
953 sge->addr_lo =
954 cpu_to_le32(U64_LO(fp->rx_sge_mapping +
955 BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
956 }
957}
958
959static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath *fp)
960{
961 int i;
962 for (i = 1; i <= NUM_RCQ_RINGS; i++) {
963 struct eth_rx_cqe_next_page *nextpg;
964
965 nextpg = (struct eth_rx_cqe_next_page *)
966 &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
967 nextpg->addr_hi =
968 cpu_to_le32(U64_HI(fp->rx_comp_mapping +
969 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
970 nextpg->addr_lo =
971 cpu_to_le32(U64_LO(fp->rx_comp_mapping +
972 BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
973 }
974}
975
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000976#ifdef BCM_CNIC
977static inline void bnx2x_init_fcoe_fp(struct bnx2x *bp)
978{
979 bnx2x_fcoe(bp, cl_id) = BNX2X_FCOE_ETH_CL_ID +
980 BP_E1HVN(bp) * NONE_ETH_CONTEXT_USE;
981 bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID;
982 bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
983 bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
984 bnx2x_fcoe(bp, bp) = bp;
985 bnx2x_fcoe(bp, state) = BNX2X_FP_STATE_CLOSED;
986 bnx2x_fcoe(bp, index) = FCOE_IDX;
987 bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
988 bnx2x_fcoe(bp, tx_cons_sb) = BNX2X_FCOE_L2_TX_INDEX;
989 /* qZone id equals to FW (per path) client id */
990 bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fcoe(bp, cl_id) +
991 BP_PORT(bp)*(CHIP_IS_E2(bp) ? ETH_MAX_RX_CLIENTS_E2 :
992 ETH_MAX_RX_CLIENTS_E1H);
993 /* init shortcut */
994 bnx2x_fcoe(bp, ustorm_rx_prods_offset) = CHIP_IS_E2(bp) ?
995 USTORM_RX_PRODS_E2_OFFSET(bnx2x_fcoe(bp, cl_qzone_id)) :
996 USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), bnx2x_fcoe_fp(bp)->cl_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000997
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000998}
999#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001000
1001static inline void __storm_memset_struct(struct bnx2x *bp,
1002 u32 addr, size_t size, u32 *data)
1003{
1004 int i;
1005 for (i = 0; i < size/4; i++)
1006 REG_WR(bp, addr + (i * 4), data[i]);
1007}
1008
1009static inline void storm_memset_mac_filters(struct bnx2x *bp,
1010 struct tstorm_eth_mac_filter_config *mac_filters,
1011 u16 abs_fid)
1012{
1013 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
1014
1015 u32 addr = BAR_TSTRORM_INTMEM +
1016 TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid);
1017
1018 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
1019}
1020
1021static inline void storm_memset_cmng(struct bnx2x *bp,
1022 struct cmng_struct_per_port *cmng,
1023 u8 port)
1024{
1025 size_t size = sizeof(struct cmng_struct_per_port);
1026
1027 u32 addr = BAR_XSTRORM_INTMEM +
1028 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
1029
1030 __storm_memset_struct(bp, addr, size, (u32 *)cmng);
1031}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001032
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001033/* HW Lock for shared dual port PHYs */
1034void bnx2x_acquire_phy_lock(struct bnx2x *bp);
1035void bnx2x_release_phy_lock(struct bnx2x *bp);
1036
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001037#endif /* BNX2X_CMN_H */