]> Git Repo - linux.git/blob - drivers/net/bnx2x/bnx2x_cmn.h
net: bnx2x: convert to hw_features
[linux.git] / drivers / net / bnx2x / bnx2x_cmn.h
1 /* 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 <[email protected]>
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
26 extern int num_queues;
27
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  */
40 u8 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  */
47 void bnx2x_link_set(struct bnx2x *bp);
48
49 /**
50  * Query link status
51  *
52  * @param bp
53  * @param is_serdes
54  *
55  * @return 0 - link is UP
56  */
57 u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes);
58
59 /**
60  * Handles link status change
61  *
62  * @param bp
63  */
64 void bnx2x__link_status_update(struct bnx2x *bp);
65
66 /**
67  * Report link status to upper layer
68  *
69  * @param bp
70  *
71  * @return int
72  */
73 void bnx2x_link_report(struct bnx2x *bp);
74
75 /**
76  * calculates MF speed according to current linespeed and MF
77  * configuration
78  *
79  * @param bp
80  *
81  * @return u16
82  */
83 u16 bnx2x_get_mf_speed(struct bnx2x *bp);
84
85 /**
86  * MSI-X slowpath interrupt handler
87  *
88  * @param irq
89  * @param dev_instance
90  *
91  * @return irqreturn_t
92  */
93 irqreturn_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  */
103 irqreturn_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  */
112 int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
113
114 /**
115  * Provides cnic information for proper interrupt handling
116  *
117  * @param bp
118  */
119 void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
120 #endif
121
122 /**
123  * Enable HW interrupts.
124  *
125  * @param bp
126  */
127 void 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  */
136 void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw);
137
138 /**
139  * Loads device firmware
140  *
141  * @param bp
142  *
143  * @return int
144  */
145 int bnx2x_init_firmware(struct bnx2x *bp);
146
147 /**
148  * 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  */
156 int 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  */
167 void 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  */
176 int bnx2x_alloc_mem(struct bnx2x *bp);
177
178 /**
179  * Release driver's memory.
180  *
181  * @param bp
182  */
183 void bnx2x_free_mem(struct bnx2x *bp);
184
185 /**
186  * Setup eth Client.
187  *
188  * @param bp
189  * @param fp
190  * @param is_leading
191  *
192  * @return int
193  */
194 int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp,
195                        int is_leading);
196
197 /**
198  * Set number of queues according to mode
199  *
200  * @param bp
201  *
202  */
203 void bnx2x_set_num_queues(struct bnx2x *bp);
204
205 /**
206  * Cleanup chip internals:
207  * - Cleanup MAC configuration.
208  * - Close clients.
209  * - etc.
210  *
211  * @param bp
212  * @param unload_mode
213  */
214 void 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  */
224 int 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  */
234 int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
235
236 /**
237  * Configure eth MAC address in the HW according to the value in
238  * netdev->dev_addr.
239  *
240  * @param bp driver handle
241  * @param set
242  */
243 void bnx2x_set_eth_mac(struct bnx2x *bp, int set);
244
245 #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  */
256 int 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  */
266 int bnx2x_set_all_enode_macs(struct bnx2x *bp, int set);
267 #endif
268
269 /**
270  * Set MAC filtering configurations.
271  *
272  * @remarks called with netif_tx_lock from dev_mcast.c
273  *
274  * @param dev net_device
275  */
276 void 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  */
283 void bnx2x_set_storm_rx_mode(struct bnx2x *bp);
284
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);
291
292 /**
293  * Perform statistics handling according to event
294  *
295  * @param bp driver handle
296  * @param event bnx2x_stats_event
297  */
298 void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
299
300 /**
301  * Handle ramrods completion
302  *
303  * @param fp fastpath handle for the event
304  * @param rr_cqe eth_rx_cqe
305  */
306 void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
307
308 /**
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  */
316 int bnx2x_func_start(struct bnx2x *bp);
317
318 /**
319  * Prepare ILT configurations according to current driver
320  * parameters.
321  *
322  * @param bp
323  */
324 void bnx2x_ilt_set_info(struct bnx2x *bp);
325
326 /**
327  * Inintialize dcbx protocol
328  *
329  * @param bp
330  */
331 void bnx2x_dcbx_init(struct bnx2x *bp);
332
333 /**
334  * Set power state to the requested value. Currently only D0 and
335  * D3hot are supported.
336  *
337  * @param bp
338  * @param state D0 or D3hot
339  *
340  * @return int
341  */
342 int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
343
344 /**
345  * Updates MAX part of MF configuration in HW
346  * (if required)
347  *
348  * @param bp
349  * @param value
350  */
351 void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value);
352
353 /* dev_close main block */
354 int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode);
355
356 /* dev_open main block */
357 int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
358
359 /* hard_xmit callback */
360 netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
361
362 /* select_queue callback */
363 u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb);
364
365 int bnx2x_change_mac_addr(struct net_device *dev, void *p);
366
367 /* NAPI poll Rx part */
368 int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget);
369
370 /* NAPI poll Tx part */
371 int bnx2x_tx_int(struct bnx2x_fastpath *fp);
372
373 /* suspend/resume callbacks */
374 int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
375 int bnx2x_resume(struct pci_dev *pdev);
376
377 /* Release IRQ vectors */
378 void bnx2x_free_irq(struct bnx2x *bp);
379
380 void bnx2x_init_rx_rings(struct bnx2x *bp);
381 void bnx2x_free_skbs(struct bnx2x *bp);
382 void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
383 void bnx2x_netif_start(struct bnx2x *bp);
384
385 /**
386  * Fill msix_table, request vectors, update num_queues according
387  * to number of available vectors
388  *
389  * @param bp
390  *
391  * @return int
392  */
393 int bnx2x_enable_msix(struct bnx2x *bp);
394
395 /**
396  * Request msi mode from OS, updated internals accordingly
397  *
398  * @param bp
399  *
400  * @return int
401  */
402 int bnx2x_enable_msi(struct bnx2x *bp);
403
404 /**
405  * NAPI callback
406  *
407  * @param napi
408  * @param budget
409  *
410  * @return int
411  */
412 int bnx2x_poll(struct napi_struct *napi, int budget);
413
414 /**
415  * Allocate/release memories outsize main driver structure
416  *
417  * @param bp
418  *
419  * @return int
420  */
421 int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp);
422 void bnx2x_free_mem_bp(struct bnx2x *bp);
423
424 /**
425  * Change mtu netdev callback
426  *
427  * @param dev
428  * @param new_mtu
429  *
430  * @return int
431  */
432 int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
433
434 u32 bnx2x_fix_features(struct net_device *dev, u32 features);
435 int bnx2x_set_features(struct net_device *dev, u32 features);
436
437 /**
438  * tx timeout netdev callback
439  *
440  * @param dev
441  * @param new_mtu
442  *
443  * @return int
444  */
445 void bnx2x_tx_timeout(struct net_device *dev);
446
447 #ifdef BCM_VLAN
448 /**
449  * vlan rx register netdev callback
450  *
451  * @param dev
452  * @param new_mtu
453  *
454  * @return int
455  */
456 void bnx2x_vlan_rx_register(struct net_device *dev,
457                                    struct vlan_group *vlgrp);
458
459 #endif
460
461 static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
462 {
463         barrier(); /* status block is written to by the chip */
464         fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID];
465 }
466
467 static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
468                                         struct bnx2x_fastpath *fp,
469                                         u16 bd_prod, u16 rx_comp_prod,
470                                         u16 rx_sge_prod)
471 {
472         struct ustorm_eth_rx_producers rx_prods = {0};
473         int i;
474
475         /* Update producers */
476         rx_prods.bd_prod = bd_prod;
477         rx_prods.cqe_prod = rx_comp_prod;
478         rx_prods.sge_prod = rx_sge_prod;
479
480         /*
481          * Make sure that the BD and SGE data is updated before updating the
482          * producers since FW might read the BD/SGE right after the producer
483          * is updated.
484          * This is only applicable for weak-ordered memory model archs such
485          * as IA-64. The following barrier is also mandatory since FW will
486          * assumes BDs must have buffers.
487          */
488         wmb();
489
490         for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
491                 REG_WR(bp,
492                        BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset + i*4,
493                        ((u32 *)&rx_prods)[i]);
494
495         mmiowb(); /* keep prod updates ordered */
496
497         DP(NETIF_MSG_RX_STATUS,
498            "queue[%d]:  wrote  bd_prod %u  cqe_prod %u  sge_prod %u\n",
499            fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
500 }
501
502 static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id,
503                                         u8 segment, u16 index, u8 op,
504                                         u8 update, u32 igu_addr)
505 {
506         struct igu_regular cmd_data = {0};
507
508         cmd_data.sb_id_and_flags =
509                         ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
510                          (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
511                          (update << IGU_REGULAR_BUPDATE_SHIFT) |
512                          (op << IGU_REGULAR_ENABLE_INT_SHIFT));
513
514         DP(NETIF_MSG_HW, "write 0x%08x to IGU addr 0x%x\n",
515            cmd_data.sb_id_and_flags, igu_addr);
516         REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags);
517
518         /* Make sure that ACK is written */
519         mmiowb();
520         barrier();
521 }
522
523 static inline void bnx2x_igu_clear_sb_gen(struct bnx2x *bp,
524                                           u8 idu_sb_id, bool is_Pf)
525 {
526         u32 data, ctl, cnt = 100;
527         u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
528         u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
529         u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
530         u32 sb_bit =  1 << (idu_sb_id%32);
531         u32 func_encode = BP_FUNC(bp) |
532                         ((is_Pf == true ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT);
533         u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
534
535         /* Not supported in BC mode */
536         if (CHIP_INT_MODE_IS_BC(bp))
537                 return;
538
539         data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
540                         << IGU_REGULAR_CLEANUP_TYPE_SHIFT)      |
541                 IGU_REGULAR_CLEANUP_SET                         |
542                 IGU_REGULAR_BCLEANUP;
543
544         ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT         |
545               func_encode << IGU_CTRL_REG_FID_SHIFT             |
546               IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
547
548         DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
549                          data, igu_addr_data);
550         REG_WR(bp, igu_addr_data, data);
551         mmiowb();
552         barrier();
553         DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
554                           ctl, igu_addr_ctl);
555         REG_WR(bp, igu_addr_ctl, ctl);
556         mmiowb();
557         barrier();
558
559         /* wait for clean up to finish */
560         while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
561                 msleep(20);
562
563
564         if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
565                 DP(NETIF_MSG_HW, "Unable to finish IGU cleanup: "
566                           "idu_sb_id %d offset %d bit %d (cnt %d)\n",
567                           idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
568         }
569 }
570
571 static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id,
572                                    u8 storm, u16 index, u8 op, u8 update)
573 {
574         u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
575                        COMMAND_REG_INT_ACK);
576         struct igu_ack_register igu_ack;
577
578         igu_ack.status_block_index = index;
579         igu_ack.sb_id_and_flags =
580                         ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
581                          (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
582                          (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
583                          (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
584
585         DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
586            (*(u32 *)&igu_ack), hc_addr);
587         REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
588
589         /* Make sure that ACK is written */
590         mmiowb();
591         barrier();
592 }
593
594 static inline void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
595                       u16 index, u8 op, u8 update)
596 {
597         u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
598
599         bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
600                              igu_addr);
601 }
602
603 static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm,
604                                 u16 index, u8 op, u8 update)
605 {
606         if (bp->common.int_block == INT_BLOCK_HC)
607                 bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update);
608         else {
609                 u8 segment;
610
611                 if (CHIP_INT_MODE_IS_BC(bp))
612                         segment = storm;
613                 else if (igu_sb_id != bp->igu_dsb_id)
614                         segment = IGU_SEG_ACCESS_DEF;
615                 else if (storm == ATTENTION_ID)
616                         segment = IGU_SEG_ACCESS_ATTN;
617                 else
618                         segment = IGU_SEG_ACCESS_DEF;
619                 bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update);
620         }
621 }
622
623 static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp)
624 {
625         u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
626                        COMMAND_REG_SIMD_MASK);
627         u32 result = REG_RD(bp, hc_addr);
628
629         DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
630            result, hc_addr);
631
632         barrier();
633         return result;
634 }
635
636 static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp)
637 {
638         u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8);
639         u32 result = REG_RD(bp, igu_addr);
640
641         DP(NETIF_MSG_HW, "read 0x%08x from IGU addr 0x%x\n",
642            result, igu_addr);
643
644         barrier();
645         return result;
646 }
647
648 static inline u16 bnx2x_ack_int(struct bnx2x *bp)
649 {
650         barrier();
651         if (bp->common.int_block == INT_BLOCK_HC)
652                 return bnx2x_hc_ack_int(bp);
653         else
654                 return bnx2x_igu_ack_int(bp);
655 }
656
657 static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
658 {
659         /* Tell compiler that consumer and producer can change */
660         barrier();
661         return fp->tx_pkt_prod != fp->tx_pkt_cons;
662 }
663
664 static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
665 {
666         s16 used;
667         u16 prod;
668         u16 cons;
669
670         prod = fp->tx_bd_prod;
671         cons = fp->tx_bd_cons;
672
673         /* NUM_TX_RINGS = number of "next-page" entries
674            It will be used as a threshold */
675         used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
676
677 #ifdef BNX2X_STOP_ON_ERROR
678         WARN_ON(used < 0);
679         WARN_ON(used > fp->bp->tx_ring_size);
680         WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
681 #endif
682
683         return (s16)(fp->bp->tx_ring_size) - used;
684 }
685
686 static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
687 {
688         u16 hw_cons;
689
690         /* Tell compiler that status block fields can change */
691         barrier();
692         hw_cons = le16_to_cpu(*fp->tx_cons_sb);
693         return hw_cons != fp->tx_pkt_cons;
694 }
695
696 static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
697 {
698         u16 rx_cons_sb;
699
700         /* Tell compiler that status block fields can change */
701         barrier();
702         rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
703         if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
704                 rx_cons_sb++;
705         return (fp->rx_comp_cons != rx_cons_sb);
706 }
707
708 /**
709  * disables tx from stack point of view
710  *
711  * @param bp
712  */
713 static inline void bnx2x_tx_disable(struct bnx2x *bp)
714 {
715         netif_tx_disable(bp->dev);
716         netif_carrier_off(bp->dev);
717 }
718
719 static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
720                                      struct bnx2x_fastpath *fp, u16 index)
721 {
722         struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
723         struct page *page = sw_buf->page;
724         struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
725
726         /* Skip "next page" elements */
727         if (!page)
728                 return;
729
730         dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
731                        SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
732         __free_pages(page, PAGES_PER_SGE_SHIFT);
733
734         sw_buf->page = NULL;
735         sge->addr_hi = 0;
736         sge->addr_lo = 0;
737 }
738
739 static inline void bnx2x_add_all_napi(struct bnx2x *bp)
740 {
741         int i;
742
743         /* Add NAPI objects */
744         for_each_napi_queue(bp, i)
745                 netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
746                                bnx2x_poll, BNX2X_NAPI_WEIGHT);
747 }
748
749 static inline void bnx2x_del_all_napi(struct bnx2x *bp)
750 {
751         int i;
752
753         for_each_napi_queue(bp, i)
754                 netif_napi_del(&bnx2x_fp(bp, i, napi));
755 }
756
757 static inline void bnx2x_disable_msi(struct bnx2x *bp)
758 {
759         if (bp->flags & USING_MSIX_FLAG) {
760                 pci_disable_msix(bp->pdev);
761                 bp->flags &= ~USING_MSIX_FLAG;
762         } else if (bp->flags & USING_MSI_FLAG) {
763                 pci_disable_msi(bp->pdev);
764                 bp->flags &= ~USING_MSI_FLAG;
765         }
766 }
767
768 static inline int bnx2x_calc_num_queues(struct bnx2x *bp)
769 {
770         return  num_queues ?
771                  min_t(int, num_queues, BNX2X_MAX_QUEUES(bp)) :
772                  min_t(int, num_online_cpus(), BNX2X_MAX_QUEUES(bp));
773 }
774
775 static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
776 {
777         int i, j;
778
779         for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
780                 int idx = RX_SGE_CNT * i - 1;
781
782                 for (j = 0; j < 2; j++) {
783                         SGE_MASK_CLEAR_BIT(fp, idx);
784                         idx--;
785                 }
786         }
787 }
788
789 static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
790 {
791         /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
792         memset(fp->sge_mask, 0xff,
793                (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
794
795         /* Clear the two last indices in the page to 1:
796            these are the indices that correspond to the "next" element,
797            hence will never be indicated and should be removed from
798            the calculations. */
799         bnx2x_clear_sge_mask_next_elems(fp);
800 }
801
802 static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
803                                      struct bnx2x_fastpath *fp, u16 index)
804 {
805         struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
806         struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
807         struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
808         dma_addr_t mapping;
809
810         if (unlikely(page == NULL))
811                 return -ENOMEM;
812
813         mapping = dma_map_page(&bp->pdev->dev, page, 0,
814                                SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
815         if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
816                 __free_pages(page, PAGES_PER_SGE_SHIFT);
817                 return -ENOMEM;
818         }
819
820         sw_buf->page = page;
821         dma_unmap_addr_set(sw_buf, mapping, mapping);
822
823         sge->addr_hi = cpu_to_le32(U64_HI(mapping));
824         sge->addr_lo = cpu_to_le32(U64_LO(mapping));
825
826         return 0;
827 }
828
829 static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
830                                      struct bnx2x_fastpath *fp, u16 index)
831 {
832         struct sk_buff *skb;
833         struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
834         struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
835         dma_addr_t mapping;
836
837         skb = netdev_alloc_skb(bp->dev, fp->rx_buf_size);
838         if (unlikely(skb == NULL))
839                 return -ENOMEM;
840
841         mapping = dma_map_single(&bp->pdev->dev, skb->data, fp->rx_buf_size,
842                                  DMA_FROM_DEVICE);
843         if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
844                 dev_kfree_skb(skb);
845                 return -ENOMEM;
846         }
847
848         rx_buf->skb = skb;
849         dma_unmap_addr_set(rx_buf, mapping, mapping);
850
851         rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
852         rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
853
854         return 0;
855 }
856
857 /* note that we are not allocating a new skb,
858  * we are just moving one from cons to prod
859  * we are not creating a new mapping,
860  * so there is no need to check for dma_mapping_error().
861  */
862 static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
863                                       u16 cons, u16 prod)
864 {
865         struct bnx2x *bp = fp->bp;
866         struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
867         struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
868         struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
869         struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
870
871         dma_sync_single_for_device(&bp->pdev->dev,
872                                    dma_unmap_addr(cons_rx_buf, mapping),
873                                    RX_COPY_THRESH, DMA_FROM_DEVICE);
874
875         prod_rx_buf->skb = cons_rx_buf->skb;
876         dma_unmap_addr_set(prod_rx_buf, mapping,
877                            dma_unmap_addr(cons_rx_buf, mapping));
878         *prod_bd = *cons_bd;
879 }
880
881 static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
882                                            struct bnx2x_fastpath *fp, int last)
883 {
884         int i;
885
886         for (i = 0; i < last; i++)
887                 bnx2x_free_rx_sge(bp, fp, i);
888 }
889
890 static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
891                                        struct bnx2x_fastpath *fp, int last)
892 {
893         int i;
894
895         for (i = 0; i < last; i++) {
896                 struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
897                 struct sk_buff *skb = rx_buf->skb;
898
899                 if (skb == NULL) {
900                         DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
901                         continue;
902                 }
903
904                 if (fp->tpa_state[i] == BNX2X_TPA_START)
905                         dma_unmap_single(&bp->pdev->dev,
906                                          dma_unmap_addr(rx_buf, mapping),
907                                          fp->rx_buf_size, DMA_FROM_DEVICE);
908
909                 dev_kfree_skb(skb);
910                 rx_buf->skb = NULL;
911         }
912 }
913
914
915 static inline void bnx2x_init_tx_rings(struct bnx2x *bp)
916 {
917         int i, j;
918
919         for_each_tx_queue(bp, j) {
920                 struct bnx2x_fastpath *fp = &bp->fp[j];
921
922                 for (i = 1; i <= NUM_TX_RINGS; i++) {
923                         struct eth_tx_next_bd *tx_next_bd =
924                                 &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
925
926                         tx_next_bd->addr_hi =
927                                 cpu_to_le32(U64_HI(fp->tx_desc_mapping +
928                                             BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
929                         tx_next_bd->addr_lo =
930                                 cpu_to_le32(U64_LO(fp->tx_desc_mapping +
931                                             BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
932                 }
933
934                 SET_FLAG(fp->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
935                 fp->tx_db.data.zero_fill1 = 0;
936                 fp->tx_db.data.prod = 0;
937
938                 fp->tx_pkt_prod = 0;
939                 fp->tx_pkt_cons = 0;
940                 fp->tx_bd_prod = 0;
941                 fp->tx_bd_cons = 0;
942                 fp->tx_pkt = 0;
943         }
944 }
945
946 static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
947 {
948         int i;
949
950         for (i = 1; i <= NUM_RX_RINGS; i++) {
951                 struct eth_rx_bd *rx_bd;
952
953                 rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
954                 rx_bd->addr_hi =
955                         cpu_to_le32(U64_HI(fp->rx_desc_mapping +
956                                     BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
957                 rx_bd->addr_lo =
958                         cpu_to_le32(U64_LO(fp->rx_desc_mapping +
959                                     BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
960         }
961 }
962
963 static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath *fp)
964 {
965         int i;
966
967         for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
968                 struct eth_rx_sge *sge;
969
970                 sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
971                 sge->addr_hi =
972                         cpu_to_le32(U64_HI(fp->rx_sge_mapping +
973                         BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
974
975                 sge->addr_lo =
976                         cpu_to_le32(U64_LO(fp->rx_sge_mapping +
977                         BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
978         }
979 }
980
981 static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath *fp)
982 {
983         int i;
984         for (i = 1; i <= NUM_RCQ_RINGS; i++) {
985                 struct eth_rx_cqe_next_page *nextpg;
986
987                 nextpg = (struct eth_rx_cqe_next_page *)
988                         &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
989                 nextpg->addr_hi =
990                         cpu_to_le32(U64_HI(fp->rx_comp_mapping +
991                                    BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
992                 nextpg->addr_lo =
993                         cpu_to_le32(U64_LO(fp->rx_comp_mapping +
994                                    BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
995         }
996 }
997
998 #ifdef BCM_CNIC
999 static inline void bnx2x_init_fcoe_fp(struct bnx2x *bp)
1000 {
1001         bnx2x_fcoe(bp, cl_id) = BNX2X_FCOE_ETH_CL_ID +
1002                 BP_E1HVN(bp) * NONE_ETH_CONTEXT_USE;
1003         bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID;
1004         bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
1005         bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
1006         bnx2x_fcoe(bp, bp) = bp;
1007         bnx2x_fcoe(bp, state) = BNX2X_FP_STATE_CLOSED;
1008         bnx2x_fcoe(bp, index) = FCOE_IDX;
1009         bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
1010         bnx2x_fcoe(bp, tx_cons_sb) = BNX2X_FCOE_L2_TX_INDEX;
1011         /* qZone id equals to FW (per path) client id */
1012         bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fcoe(bp, cl_id) +
1013                 BP_PORT(bp)*(CHIP_IS_E2(bp) ? ETH_MAX_RX_CLIENTS_E2 :
1014                                 ETH_MAX_RX_CLIENTS_E1H);
1015         /* init shortcut */
1016         bnx2x_fcoe(bp, ustorm_rx_prods_offset) = CHIP_IS_E2(bp) ?
1017             USTORM_RX_PRODS_E2_OFFSET(bnx2x_fcoe(bp, cl_qzone_id)) :
1018             USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), bnx2x_fcoe_fp(bp)->cl_id);
1019
1020 }
1021 #endif
1022
1023 static inline void __storm_memset_struct(struct bnx2x *bp,
1024                                          u32 addr, size_t size, u32 *data)
1025 {
1026         int i;
1027         for (i = 0; i < size/4; i++)
1028                 REG_WR(bp, addr + (i * 4), data[i]);
1029 }
1030
1031 static inline void storm_memset_mac_filters(struct bnx2x *bp,
1032                         struct tstorm_eth_mac_filter_config *mac_filters,
1033                         u16 abs_fid)
1034 {
1035         size_t size = sizeof(struct tstorm_eth_mac_filter_config);
1036
1037         u32 addr = BAR_TSTRORM_INTMEM +
1038                         TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid);
1039
1040         __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
1041 }
1042
1043 static inline void storm_memset_cmng(struct bnx2x *bp,
1044                                 struct cmng_struct_per_port *cmng,
1045                                 u8 port)
1046 {
1047         size_t size =
1048                 sizeof(struct rate_shaping_vars_per_port) +
1049                 sizeof(struct fairness_vars_per_port) +
1050                 sizeof(struct safc_struct_per_port) +
1051                 sizeof(struct pfc_struct_per_port);
1052
1053         u32 addr = BAR_XSTRORM_INTMEM +
1054                         XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
1055
1056         __storm_memset_struct(bp, addr, size, (u32 *)cmng);
1057
1058         addr += size + 4 /* SKIP DCB+LLFC */;
1059         size = sizeof(struct cmng_struct_per_port) -
1060                 size /* written */ - 4 /*skipped*/;
1061
1062         __storm_memset_struct(bp, addr, size,
1063                               (u32 *)(cmng->traffic_type_to_priority_cos));
1064 }
1065
1066 /* HW Lock for shared dual port PHYs */
1067 void bnx2x_acquire_phy_lock(struct bnx2x *bp);
1068 void bnx2x_release_phy_lock(struct bnx2x *bp);
1069
1070 /**
1071  * Extracts MAX BW part from MF configuration.
1072  *
1073  * @param bp
1074  * @param mf_cfg
1075  *
1076  * @return u16
1077  */
1078 static inline u16 bnx2x_extract_max_cfg(struct bnx2x *bp, u32 mf_cfg)
1079 {
1080         u16 max_cfg = (mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
1081                               FUNC_MF_CFG_MAX_BW_SHIFT;
1082         if (!max_cfg) {
1083                 BNX2X_ERR("Illegal configuration detected for Max BW - "
1084                           "using 100 instead\n");
1085                 max_cfg = 100;
1086         }
1087         return max_cfg;
1088 }
1089
1090 #endif /* BNX2X_CMN_H */
This page took 0.093985 seconds and 4 git commands to generate.