Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1 | /* bnx2x_cmn.h: Broadcom Everest network driver. |
| 2 | * |
Dmitry Kravkov | 5de9240 | 2011-05-04 23:51:13 +0000 | [diff] [blame] | 3 | * Copyright (c) 2007-2011 Broadcom Corporation |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 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 Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 26 | extern int num_queues; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 27 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 28 | /************************ Macros ********************************/ |
| 29 | #define BNX2X_PCI_FREE(x, y, size) \ |
| 30 | do { \ |
| 31 | if (x) { \ |
| 32 | dma_free_coherent(&bp->pdev->dev, size, (void *)x, y); \ |
| 33 | x = NULL; \ |
| 34 | y = 0; \ |
| 35 | } \ |
| 36 | } while (0) |
| 37 | |
| 38 | #define BNX2X_FREE(x) \ |
| 39 | do { \ |
| 40 | if (x) { \ |
| 41 | kfree((void *)x); \ |
| 42 | x = NULL; \ |
| 43 | } \ |
| 44 | } while (0) |
| 45 | |
| 46 | #define BNX2X_PCI_ALLOC(x, y, size) \ |
| 47 | do { \ |
| 48 | x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \ |
| 49 | if (x == NULL) \ |
| 50 | goto alloc_mem_err; \ |
| 51 | memset((void *)x, 0, size); \ |
| 52 | } while (0) |
| 53 | |
| 54 | #define BNX2X_ALLOC(x, size) \ |
| 55 | do { \ |
| 56 | x = kzalloc(size, GFP_KERNEL); \ |
| 57 | if (x == NULL) \ |
| 58 | goto alloc_mem_err; \ |
| 59 | } while (0) |
| 60 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 61 | /*********************** Interfaces **************************** |
| 62 | * Functions that need to be implemented by each driver version |
| 63 | */ |
| 64 | |
| 65 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 66 | * bnx2x_initial_phy_init - initialize link parameters structure variables. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 67 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 68 | * @bp: driver handle |
| 69 | * @load_mode: current mode |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 70 | */ |
| 71 | u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode); |
| 72 | |
| 73 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 74 | * bnx2x_link_set - configure hw according to link parameters structure. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 75 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 76 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 77 | */ |
| 78 | void bnx2x_link_set(struct bnx2x *bp); |
| 79 | |
| 80 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 81 | * bnx2x_link_test - query link status. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 82 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 83 | * @bp: driver handle |
| 84 | * @is_serdes: bool |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 85 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 86 | * Returns 0 if link is UP. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 87 | */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 88 | u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 89 | |
| 90 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 91 | * bnx2x__link_status_update - handles link status change. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 92 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 93 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 94 | */ |
| 95 | void bnx2x__link_status_update(struct bnx2x *bp); |
| 96 | |
| 97 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 98 | * bnx2x_link_report - report link status to upper layer. |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 99 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 100 | * @bp: driver handle |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 101 | */ |
| 102 | void bnx2x_link_report(struct bnx2x *bp); |
| 103 | |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 104 | /* None-atomic version of bnx2x_link_report() */ |
| 105 | void __bnx2x_link_report(struct bnx2x *bp); |
| 106 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 107 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 108 | * bnx2x_get_mf_speed - calculate MF speed. |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 109 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 110 | * @bp: driver handle |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 111 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 112 | * Takes into account current linespeed and MF configuration. |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 113 | */ |
| 114 | u16 bnx2x_get_mf_speed(struct bnx2x *bp); |
| 115 | |
| 116 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 117 | * bnx2x_msix_sp_int - MSI-X slowpath interrupt handler |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 118 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 119 | * @irq: irq number |
| 120 | * @dev_instance: private instance |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 121 | */ |
| 122 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance); |
| 123 | |
| 124 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 125 | * bnx2x_interrupt - non MSI-X interrupt handler |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 126 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 127 | * @irq: irq number |
| 128 | * @dev_instance: private instance |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 129 | */ |
| 130 | irqreturn_t bnx2x_interrupt(int irq, void *dev_instance); |
| 131 | #ifdef BCM_CNIC |
| 132 | |
| 133 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 134 | * bnx2x_cnic_notify - send command to cnic driver |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 135 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 136 | * @bp: driver handle |
| 137 | * @cmd: command |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 138 | */ |
| 139 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd); |
| 140 | |
| 141 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 142 | * bnx2x_setup_cnic_irq_info - provides cnic with IRQ information |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 143 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 144 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 145 | */ |
| 146 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp); |
| 147 | #endif |
| 148 | |
| 149 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 150 | * bnx2x_int_enable - enable HW interrupts. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 151 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 152 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 153 | */ |
| 154 | void bnx2x_int_enable(struct bnx2x *bp); |
| 155 | |
| 156 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 157 | * bnx2x_int_disable_sync - disable interrupts. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 158 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 159 | * @bp: driver handle |
| 160 | * @disable_hw: true, disable HW interrupts. |
| 161 | * |
| 162 | * This function ensures that there are no |
| 163 | * ISRs or SP DPCs (sp_task) are running after it returns. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 164 | */ |
| 165 | void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw); |
| 166 | |
| 167 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 168 | * bnx2x_init_firmware - loads device firmware |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 169 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 170 | * @bp: driver handle |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 171 | */ |
| 172 | int bnx2x_init_firmware(struct bnx2x *bp); |
| 173 | |
| 174 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 175 | * bnx2x_init_hw - init HW blocks according to current initialization stage. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 176 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 177 | * @bp: driver handle |
| 178 | * @load_code: COMMON, PORT or FUNCTION |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 179 | */ |
| 180 | int bnx2x_init_hw(struct bnx2x *bp, u32 load_code); |
| 181 | |
| 182 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 183 | * bnx2x_nic_init - init driver internals. |
| 184 | * |
| 185 | * @bp: driver handle |
| 186 | * @load_code: COMMON, PORT or FUNCTION |
| 187 | * |
| 188 | * Initializes: |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 189 | * - rings |
| 190 | * - status blocks |
| 191 | * - etc. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 192 | */ |
| 193 | void bnx2x_nic_init(struct bnx2x *bp, u32 load_code); |
| 194 | |
| 195 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 196 | * bnx2x_alloc_mem - allocate driver's memory. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 197 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 198 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 199 | */ |
| 200 | int bnx2x_alloc_mem(struct bnx2x *bp); |
| 201 | |
| 202 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 203 | * bnx2x_free_mem - release driver's memory. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 204 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 205 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 206 | */ |
| 207 | void bnx2x_free_mem(struct bnx2x *bp); |
| 208 | |
| 209 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 210 | * bnx2x_setup_client - setup eth client. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 211 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 212 | * @bp: driver handle |
| 213 | * @fp: pointer to fastpath structure |
| 214 | * @is_leading: boolean |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 215 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 216 | int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 217 | int is_leading); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 218 | |
| 219 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 220 | * bnx2x_set_num_queues - set number of queues according to mode. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 221 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 222 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 223 | */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 224 | void bnx2x_set_num_queues(struct bnx2x *bp); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 225 | |
| 226 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 227 | * bnx2x_chip_cleanup - cleanup chip internals. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 228 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 229 | * @bp: driver handle |
| 230 | * @unload_mode: COMMON, PORT, FUNCTION |
| 231 | * |
| 232 | * - Cleanup MAC configuration. |
| 233 | * - Closes clients. |
| 234 | * - etc. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 235 | */ |
| 236 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode); |
| 237 | |
| 238 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 239 | * bnx2x_acquire_hw_lock - acquire HW lock. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 240 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 241 | * @bp: driver handle |
| 242 | * @resource: resource bit which was locked |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 243 | */ |
| 244 | int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource); |
| 245 | |
| 246 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 247 | * bnx2x_release_hw_lock - release HW lock. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 248 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 249 | * @bp: driver handle |
| 250 | * @resource: resource bit which was locked |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 251 | */ |
| 252 | int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource); |
| 253 | |
| 254 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 255 | * bnx2x_set_eth_mac - configure eth MAC address in the HW |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 256 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 257 | * @bp: driver handle |
| 258 | * @set: set or clear |
| 259 | * |
| 260 | * Configures according to the value in netdev->dev_addr. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 261 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 262 | void bnx2x_set_eth_mac(struct bnx2x *bp, int set); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 263 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 264 | #ifdef BCM_CNIC |
| 265 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 266 | * bnx2x_set_fip_eth_mac_addr - Set/Clear FIP MAC(s) |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 267 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 268 | * @bp: driver handle |
| 269 | * @set: set or clear the CAM entry |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 270 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 271 | * Used next enties in the CAM after the ETH MAC(s). |
| 272 | * This function will wait until the ramdord completion returns. |
| 273 | * Return 0 if cussess, -ENODEV if ramrod doesn't return. |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 274 | */ |
| 275 | int bnx2x_set_fip_eth_mac_addr(struct bnx2x *bp, int set); |
| 276 | |
| 277 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 278 | * bnx2x_set_all_enode_macs - Set/Clear ALL_ENODE mcast MAC. |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 279 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 280 | * @bp: driver handle |
| 281 | * @set: set or clear |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 282 | */ |
| 283 | int bnx2x_set_all_enode_macs(struct bnx2x *bp, int set); |
| 284 | #endif |
| 285 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 286 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 287 | * bnx2x_set_rx_mode - set MAC filtering configurations. |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 288 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 289 | * @dev: netdevice |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 290 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 291 | * called with netif_tx_lock from dev_mcast.c |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 292 | */ |
| 293 | void bnx2x_set_rx_mode(struct net_device *dev); |
| 294 | |
| 295 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 296 | * bnx2x_set_storm_rx_mode - configure MAC filtering rules in a FW. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 297 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 298 | * @bp: driver handle |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 299 | */ |
| 300 | void bnx2x_set_storm_rx_mode(struct bnx2x *bp); |
| 301 | |
| 302 | /* Parity errors related */ |
| 303 | void bnx2x_inc_load_cnt(struct bnx2x *bp); |
| 304 | u32 bnx2x_dec_load_cnt(struct bnx2x *bp); |
| 305 | bool bnx2x_chk_parity_attn(struct bnx2x *bp); |
| 306 | bool bnx2x_reset_is_done(struct bnx2x *bp); |
| 307 | void bnx2x_disable_close_the_gate(struct bnx2x *bp); |
| 308 | |
| 309 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 310 | * bnx2x_stats_handle - perform statistics handling according to event. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 311 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 312 | * @bp: driver handle |
| 313 | * @event: bnx2x_stats_event |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 314 | */ |
| 315 | void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event); |
| 316 | |
| 317 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 318 | * bnx2x_sp_event - handle ramrods completion. |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 319 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 320 | * @fp: fastpath handle for the event |
| 321 | * @rr_cqe: eth_rx_cqe |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 322 | */ |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 323 | void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 324 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 325 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 326 | * bnx2x_func_start - init function |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 327 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 328 | * @bp: driver handle |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 329 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 330 | * Must be called before sending CLIENT_SETUP for the first client. |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 331 | */ |
| 332 | int bnx2x_func_start(struct bnx2x *bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 333 | |
| 334 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 335 | * bnx2x_ilt_set_info - prepare ILT configurations. |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 336 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 337 | * @bp: driver handle |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 338 | */ |
| 339 | void bnx2x_ilt_set_info(struct bnx2x *bp); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 340 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 341 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 342 | * bnx2x_dcbx_init - initialize dcbx protocol. |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 343 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 344 | * @bp: driver handle |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 345 | */ |
| 346 | void bnx2x_dcbx_init(struct bnx2x *bp); |
| 347 | |
| 348 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 349 | * bnx2x_set_power_state - set power state to the requested value. |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 350 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 351 | * @bp: driver handle |
| 352 | * @state: required state D0 or D3hot |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 353 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 354 | * Currently only D0 and D3hot are supported. |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 355 | */ |
| 356 | int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state); |
| 357 | |
Dmitry Kravkov | e3835b9 | 2011-03-06 10:50:44 +0000 | [diff] [blame] | 358 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 359 | * bnx2x_update_max_mf_config - update MAX part of MF configuration in HW. |
Dmitry Kravkov | e3835b9 | 2011-03-06 10:50:44 +0000 | [diff] [blame] | 360 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 361 | * @bp: driver handle |
| 362 | * @value: new value |
Dmitry Kravkov | e3835b9 | 2011-03-06 10:50:44 +0000 | [diff] [blame] | 363 | */ |
| 364 | void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value); |
| 365 | |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 366 | void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl); |
| 367 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 368 | /* dev_close main block */ |
| 369 | int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode); |
| 370 | |
| 371 | /* dev_open main block */ |
| 372 | int bnx2x_nic_load(struct bnx2x *bp, int load_mode); |
| 373 | |
| 374 | /* hard_xmit callback */ |
| 375 | netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev); |
| 376 | |
Vladislav Zolotarov | 8307fa3 | 2010-12-13 05:44:09 +0000 | [diff] [blame] | 377 | /* select_queue callback */ |
| 378 | u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb); |
| 379 | |
Dmitry Kravkov | a9fccec | 2011-06-14 01:33:30 +0000 | [diff] [blame^] | 380 | /* reload helper */ |
| 381 | int bnx2x_reload_if_running(struct net_device *dev); |
| 382 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 383 | int bnx2x_change_mac_addr(struct net_device *dev, void *p); |
| 384 | |
| 385 | /* NAPI poll Rx part */ |
| 386 | int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget); |
| 387 | |
| 388 | /* NAPI poll Tx part */ |
| 389 | int bnx2x_tx_int(struct bnx2x_fastpath *fp); |
| 390 | |
| 391 | /* suspend/resume callbacks */ |
| 392 | int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state); |
| 393 | int bnx2x_resume(struct pci_dev *pdev); |
| 394 | |
| 395 | /* Release IRQ vectors */ |
| 396 | void bnx2x_free_irq(struct bnx2x *bp); |
| 397 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 398 | void bnx2x_free_fp_mem(struct bnx2x *bp); |
| 399 | int bnx2x_alloc_fp_mem(struct bnx2x *bp); |
| 400 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 401 | void bnx2x_init_rx_rings(struct bnx2x *bp); |
| 402 | void bnx2x_free_skbs(struct bnx2x *bp); |
| 403 | void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw); |
| 404 | void bnx2x_netif_start(struct bnx2x *bp); |
| 405 | |
| 406 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 407 | * bnx2x_enable_msix - set msix configuration. |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 408 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 409 | * @bp: driver handle |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 410 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 411 | * fills msix_table, requests vectors, updates num_queues |
| 412 | * according to number of available vectors. |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 413 | */ |
| 414 | int bnx2x_enable_msix(struct bnx2x *bp); |
| 415 | |
| 416 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 417 | * bnx2x_enable_msi - request msi mode from OS, updated internals accordingly |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 418 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 419 | * @bp: driver handle |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 420 | */ |
| 421 | int bnx2x_enable_msi(struct bnx2x *bp); |
| 422 | |
| 423 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 424 | * bnx2x_poll - NAPI callback |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 425 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 426 | * @napi: napi structure |
| 427 | * @budget: |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 428 | * |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 429 | */ |
| 430 | int bnx2x_poll(struct napi_struct *napi, int budget); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 431 | |
| 432 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 433 | * bnx2x_alloc_mem_bp - allocate memories outsize main driver structure |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 434 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 435 | * @bp: driver handle |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 436 | */ |
| 437 | int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp); |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 438 | |
| 439 | /** |
| 440 | * bnx2x_free_mem_bp - release memories outsize main driver structure |
| 441 | * |
| 442 | * @bp: driver handle |
| 443 | */ |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 444 | void bnx2x_free_mem_bp(struct bnx2x *bp); |
| 445 | |
| 446 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 447 | * bnx2x_change_mtu - change mtu netdev callback |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 448 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 449 | * @dev: net device |
| 450 | * @new_mtu: requested mtu |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 451 | * |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 452 | */ |
| 453 | int bnx2x_change_mtu(struct net_device *dev, int new_mtu); |
| 454 | |
Michał Mirosław | 66371c4 | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 455 | u32 bnx2x_fix_features(struct net_device *dev, u32 features); |
| 456 | int bnx2x_set_features(struct net_device *dev, u32 features); |
| 457 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 458 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 459 | * bnx2x_tx_timeout - tx timeout netdev callback |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 460 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 461 | * @dev: net device |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 462 | */ |
| 463 | void bnx2x_tx_timeout(struct net_device *dev); |
| 464 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 465 | static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp) |
| 466 | { |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 467 | barrier(); /* status block is written to by the chip */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 468 | fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID]; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static inline void bnx2x_update_rx_prod(struct bnx2x *bp, |
| 472 | struct bnx2x_fastpath *fp, |
| 473 | u16 bd_prod, u16 rx_comp_prod, |
| 474 | u16 rx_sge_prod) |
| 475 | { |
| 476 | struct ustorm_eth_rx_producers rx_prods = {0}; |
| 477 | int i; |
| 478 | |
| 479 | /* Update producers */ |
| 480 | rx_prods.bd_prod = bd_prod; |
| 481 | rx_prods.cqe_prod = rx_comp_prod; |
| 482 | rx_prods.sge_prod = rx_sge_prod; |
| 483 | |
| 484 | /* |
| 485 | * Make sure that the BD and SGE data is updated before updating the |
| 486 | * producers since FW might read the BD/SGE right after the producer |
| 487 | * is updated. |
| 488 | * This is only applicable for weak-ordered memory model archs such |
| 489 | * as IA-64. The following barrier is also mandatory since FW will |
| 490 | * assumes BDs must have buffers. |
| 491 | */ |
| 492 | wmb(); |
| 493 | |
| 494 | for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 495 | REG_WR(bp, |
| 496 | BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset + i*4, |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 497 | ((u32 *)&rx_prods)[i]); |
| 498 | |
| 499 | mmiowb(); /* keep prod updates ordered */ |
| 500 | |
| 501 | DP(NETIF_MSG_RX_STATUS, |
| 502 | "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n", |
| 503 | fp->index, bd_prod, rx_comp_prod, rx_sge_prod); |
| 504 | } |
| 505 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 506 | static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id, |
| 507 | u8 segment, u16 index, u8 op, |
| 508 | u8 update, u32 igu_addr) |
| 509 | { |
| 510 | struct igu_regular cmd_data = {0}; |
| 511 | |
| 512 | cmd_data.sb_id_and_flags = |
| 513 | ((index << IGU_REGULAR_SB_INDEX_SHIFT) | |
| 514 | (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) | |
| 515 | (update << IGU_REGULAR_BUPDATE_SHIFT) | |
| 516 | (op << IGU_REGULAR_ENABLE_INT_SHIFT)); |
| 517 | |
| 518 | DP(NETIF_MSG_HW, "write 0x%08x to IGU addr 0x%x\n", |
| 519 | cmd_data.sb_id_and_flags, igu_addr); |
| 520 | REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags); |
| 521 | |
| 522 | /* Make sure that ACK is written */ |
| 523 | mmiowb(); |
| 524 | barrier(); |
| 525 | } |
| 526 | |
| 527 | static inline void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, |
| 528 | u8 idu_sb_id, bool is_Pf) |
| 529 | { |
| 530 | u32 data, ctl, cnt = 100; |
| 531 | u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA; |
| 532 | u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL; |
| 533 | u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4; |
| 534 | u32 sb_bit = 1 << (idu_sb_id%32); |
| 535 | u32 func_encode = BP_FUNC(bp) | |
| 536 | ((is_Pf == true ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT); |
| 537 | u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id; |
| 538 | |
| 539 | /* Not supported in BC mode */ |
| 540 | if (CHIP_INT_MODE_IS_BC(bp)) |
| 541 | return; |
| 542 | |
| 543 | data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup |
| 544 | << IGU_REGULAR_CLEANUP_TYPE_SHIFT) | |
| 545 | IGU_REGULAR_CLEANUP_SET | |
| 546 | IGU_REGULAR_BCLEANUP; |
| 547 | |
| 548 | ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT | |
| 549 | func_encode << IGU_CTRL_REG_FID_SHIFT | |
| 550 | IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT; |
| 551 | |
| 552 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", |
| 553 | data, igu_addr_data); |
| 554 | REG_WR(bp, igu_addr_data, data); |
| 555 | mmiowb(); |
| 556 | barrier(); |
| 557 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", |
| 558 | ctl, igu_addr_ctl); |
| 559 | REG_WR(bp, igu_addr_ctl, ctl); |
| 560 | mmiowb(); |
| 561 | barrier(); |
| 562 | |
| 563 | /* wait for clean up to finish */ |
| 564 | while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt) |
| 565 | msleep(20); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 566 | |
| 567 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 568 | if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) { |
| 569 | DP(NETIF_MSG_HW, "Unable to finish IGU cleanup: " |
| 570 | "idu_sb_id %d offset %d bit %d (cnt %d)\n", |
| 571 | idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id, |
| 576 | u8 storm, u16 index, u8 op, u8 update) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 577 | { |
| 578 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 579 | COMMAND_REG_INT_ACK); |
| 580 | struct igu_ack_register igu_ack; |
| 581 | |
| 582 | igu_ack.status_block_index = index; |
| 583 | igu_ack.sb_id_and_flags = |
| 584 | ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) | |
| 585 | (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) | |
| 586 | (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) | |
| 587 | (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT)); |
| 588 | |
| 589 | DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n", |
| 590 | (*(u32 *)&igu_ack), hc_addr); |
| 591 | REG_WR(bp, hc_addr, (*(u32 *)&igu_ack)); |
| 592 | |
| 593 | /* Make sure that ACK is written */ |
| 594 | mmiowb(); |
| 595 | barrier(); |
| 596 | } |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 597 | |
| 598 | static inline void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
| 599 | u16 index, u8 op, u8 update) |
| 600 | { |
| 601 | u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; |
| 602 | |
| 603 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, |
| 604 | igu_addr); |
| 605 | } |
| 606 | |
| 607 | static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm, |
| 608 | u16 index, u8 op, u8 update) |
| 609 | { |
| 610 | if (bp->common.int_block == INT_BLOCK_HC) |
| 611 | bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update); |
| 612 | else { |
| 613 | u8 segment; |
| 614 | |
| 615 | if (CHIP_INT_MODE_IS_BC(bp)) |
| 616 | segment = storm; |
| 617 | else if (igu_sb_id != bp->igu_dsb_id) |
| 618 | segment = IGU_SEG_ACCESS_DEF; |
| 619 | else if (storm == ATTENTION_ID) |
| 620 | segment = IGU_SEG_ACCESS_ATTN; |
| 621 | else |
| 622 | segment = IGU_SEG_ACCESS_DEF; |
| 623 | bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 628 | { |
| 629 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 630 | COMMAND_REG_SIMD_MASK); |
| 631 | u32 result = REG_RD(bp, hc_addr); |
| 632 | |
| 633 | DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n", |
| 634 | result, hc_addr); |
| 635 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 636 | barrier(); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 637 | return result; |
| 638 | } |
| 639 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 640 | static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp) |
| 641 | { |
| 642 | u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8); |
| 643 | u32 result = REG_RD(bp, igu_addr); |
| 644 | |
| 645 | DP(NETIF_MSG_HW, "read 0x%08x from IGU addr 0x%x\n", |
| 646 | result, igu_addr); |
| 647 | |
| 648 | barrier(); |
| 649 | return result; |
| 650 | } |
| 651 | |
| 652 | static inline u16 bnx2x_ack_int(struct bnx2x *bp) |
| 653 | { |
| 654 | barrier(); |
| 655 | if (bp->common.int_block == INT_BLOCK_HC) |
| 656 | return bnx2x_hc_ack_int(bp); |
| 657 | else |
| 658 | return bnx2x_igu_ack_int(bp); |
| 659 | } |
| 660 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 661 | static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp) |
| 662 | { |
| 663 | /* Tell compiler that consumer and producer can change */ |
| 664 | barrier(); |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 665 | return fp->tx_pkt_prod != fp->tx_pkt_cons; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp) |
| 669 | { |
| 670 | s16 used; |
| 671 | u16 prod; |
| 672 | u16 cons; |
| 673 | |
| 674 | prod = fp->tx_bd_prod; |
| 675 | cons = fp->tx_bd_cons; |
| 676 | |
| 677 | /* NUM_TX_RINGS = number of "next-page" entries |
| 678 | It will be used as a threshold */ |
| 679 | used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS; |
| 680 | |
| 681 | #ifdef BNX2X_STOP_ON_ERROR |
| 682 | WARN_ON(used < 0); |
| 683 | WARN_ON(used > fp->bp->tx_ring_size); |
| 684 | WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL); |
| 685 | #endif |
| 686 | |
| 687 | return (s16)(fp->bp->tx_ring_size) - used; |
| 688 | } |
| 689 | |
| 690 | static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp) |
| 691 | { |
| 692 | u16 hw_cons; |
| 693 | |
| 694 | /* Tell compiler that status block fields can change */ |
| 695 | barrier(); |
| 696 | hw_cons = le16_to_cpu(*fp->tx_cons_sb); |
| 697 | return hw_cons != fp->tx_pkt_cons; |
| 698 | } |
| 699 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 700 | static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp) |
| 701 | { |
| 702 | u16 rx_cons_sb; |
| 703 | |
| 704 | /* Tell compiler that status block fields can change */ |
| 705 | barrier(); |
| 706 | rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb); |
| 707 | if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 708 | rx_cons_sb++; |
| 709 | return (fp->rx_comp_cons != rx_cons_sb); |
| 710 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 711 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 712 | /** |
| 713 | * disables tx from stack point of view |
| 714 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 715 | * @bp: driver handle |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 716 | */ |
| 717 | static inline void bnx2x_tx_disable(struct bnx2x *bp) |
| 718 | { |
| 719 | netif_tx_disable(bp->dev); |
| 720 | netif_carrier_off(bp->dev); |
| 721 | } |
| 722 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 723 | static inline void bnx2x_free_rx_sge(struct bnx2x *bp, |
| 724 | struct bnx2x_fastpath *fp, u16 index) |
| 725 | { |
| 726 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 727 | struct page *page = sw_buf->page; |
| 728 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 729 | |
| 730 | /* Skip "next page" elements */ |
| 731 | if (!page) |
| 732 | return; |
| 733 | |
| 734 | dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping), |
Dmitry Kravkov | 4bca60f | 2010-10-06 03:30:27 +0000 | [diff] [blame] | 735 | SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 736 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 737 | |
| 738 | sw_buf->page = NULL; |
| 739 | sge->addr_hi = 0; |
| 740 | sge->addr_lo = 0; |
| 741 | } |
| 742 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 743 | static inline void bnx2x_add_all_napi(struct bnx2x *bp) |
| 744 | { |
| 745 | int i; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 746 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 747 | /* Add NAPI objects */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 748 | for_each_napi_queue(bp, i) |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 749 | netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi), |
| 750 | bnx2x_poll, BNX2X_NAPI_WEIGHT); |
| 751 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 752 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 753 | static inline void bnx2x_del_all_napi(struct bnx2x *bp) |
| 754 | { |
| 755 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 756 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 757 | for_each_napi_queue(bp, i) |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 758 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
| 759 | } |
| 760 | |
| 761 | static inline void bnx2x_disable_msi(struct bnx2x *bp) |
| 762 | { |
| 763 | if (bp->flags & USING_MSIX_FLAG) { |
| 764 | pci_disable_msix(bp->pdev); |
| 765 | bp->flags &= ~USING_MSIX_FLAG; |
| 766 | } else if (bp->flags & USING_MSI_FLAG) { |
| 767 | pci_disable_msi(bp->pdev); |
| 768 | bp->flags &= ~USING_MSI_FLAG; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | static inline int bnx2x_calc_num_queues(struct bnx2x *bp) |
| 773 | { |
| 774 | return num_queues ? |
| 775 | min_t(int, num_queues, BNX2X_MAX_QUEUES(bp)) : |
| 776 | min_t(int, num_online_cpus(), BNX2X_MAX_QUEUES(bp)); |
| 777 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 778 | |
| 779 | static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp) |
| 780 | { |
| 781 | int i, j; |
| 782 | |
| 783 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 784 | int idx = RX_SGE_CNT * i - 1; |
| 785 | |
| 786 | for (j = 0; j < 2; j++) { |
| 787 | SGE_MASK_CLEAR_BIT(fp, idx); |
| 788 | idx--; |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp) |
| 794 | { |
| 795 | /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */ |
| 796 | memset(fp->sge_mask, 0xff, |
| 797 | (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64)); |
| 798 | |
| 799 | /* Clear the two last indices in the page to 1: |
| 800 | these are the indices that correspond to the "next" element, |
| 801 | hence will never be indicated and should be removed from |
| 802 | the calculations. */ |
| 803 | bnx2x_clear_sge_mask_next_elems(fp); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp, |
| 807 | struct bnx2x_fastpath *fp, u16 index) |
| 808 | { |
| 809 | struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT); |
| 810 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 811 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 812 | dma_addr_t mapping; |
| 813 | |
| 814 | if (unlikely(page == NULL)) |
| 815 | return -ENOMEM; |
| 816 | |
| 817 | mapping = dma_map_page(&bp->pdev->dev, page, 0, |
| 818 | SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE); |
| 819 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
| 820 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 821 | return -ENOMEM; |
| 822 | } |
| 823 | |
| 824 | sw_buf->page = page; |
| 825 | dma_unmap_addr_set(sw_buf, mapping, mapping); |
| 826 | |
| 827 | sge->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 828 | sge->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 829 | |
| 830 | return 0; |
| 831 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 832 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 833 | static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp, |
| 834 | struct bnx2x_fastpath *fp, u16 index) |
| 835 | { |
| 836 | struct sk_buff *skb; |
| 837 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index]; |
| 838 | struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index]; |
| 839 | dma_addr_t mapping; |
| 840 | |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 841 | skb = netdev_alloc_skb(bp->dev, fp->rx_buf_size); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 842 | if (unlikely(skb == NULL)) |
| 843 | return -ENOMEM; |
| 844 | |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 845 | mapping = dma_map_single(&bp->pdev->dev, skb->data, fp->rx_buf_size, |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 846 | DMA_FROM_DEVICE); |
| 847 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Vladislav Zolotarov | 4095553 | 2011-05-22 10:06:58 +0000 | [diff] [blame] | 848 | dev_kfree_skb_any(skb); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 849 | return -ENOMEM; |
| 850 | } |
| 851 | |
| 852 | rx_buf->skb = skb; |
| 853 | dma_unmap_addr_set(rx_buf, mapping, mapping); |
| 854 | |
| 855 | rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 856 | rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | /* note that we are not allocating a new skb, |
| 862 | * we are just moving one from cons to prod |
| 863 | * we are not creating a new mapping, |
| 864 | * so there is no need to check for dma_mapping_error(). |
| 865 | */ |
| 866 | static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp, |
Dmitry Kravkov | 749a850 | 2010-10-06 03:29:05 +0000 | [diff] [blame] | 867 | u16 cons, u16 prod) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 868 | { |
| 869 | struct bnx2x *bp = fp->bp; |
| 870 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 871 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 872 | struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons]; |
| 873 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 874 | |
| 875 | dma_sync_single_for_device(&bp->pdev->dev, |
| 876 | dma_unmap_addr(cons_rx_buf, mapping), |
| 877 | RX_COPY_THRESH, DMA_FROM_DEVICE); |
| 878 | |
| 879 | prod_rx_buf->skb = cons_rx_buf->skb; |
| 880 | dma_unmap_addr_set(prod_rx_buf, mapping, |
| 881 | dma_unmap_addr(cons_rx_buf, mapping)); |
| 882 | *prod_bd = *cons_bd; |
| 883 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 884 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 885 | static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp, |
| 886 | struct bnx2x_fastpath *fp, int last) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 887 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 888 | int i; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 889 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 890 | if (fp->disable_tpa) |
| 891 | return; |
| 892 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 893 | for (i = 0; i < last; i++) |
| 894 | bnx2x_free_rx_sge(bp, fp, i); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 897 | static inline void bnx2x_free_tpa_pool(struct bnx2x *bp, |
| 898 | struct bnx2x_fastpath *fp, int last) |
| 899 | { |
| 900 | int i; |
| 901 | |
| 902 | for (i = 0; i < last; i++) { |
| 903 | struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]); |
| 904 | struct sk_buff *skb = rx_buf->skb; |
| 905 | |
| 906 | if (skb == NULL) { |
| 907 | DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i); |
| 908 | continue; |
| 909 | } |
| 910 | |
| 911 | if (fp->tpa_state[i] == BNX2X_TPA_START) |
| 912 | dma_unmap_single(&bp->pdev->dev, |
| 913 | dma_unmap_addr(rx_buf, mapping), |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 914 | fp->rx_buf_size, DMA_FROM_DEVICE); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 915 | |
| 916 | dev_kfree_skb(skb); |
| 917 | rx_buf->skb = NULL; |
| 918 | } |
| 919 | } |
| 920 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 921 | static inline void bnx2x_init_tx_ring_one(struct bnx2x_fastpath *fp) |
| 922 | { |
| 923 | int i; |
| 924 | |
| 925 | for (i = 1; i <= NUM_TX_RINGS; i++) { |
| 926 | struct eth_tx_next_bd *tx_next_bd = |
| 927 | &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd; |
| 928 | |
| 929 | tx_next_bd->addr_hi = |
| 930 | cpu_to_le32(U64_HI(fp->tx_desc_mapping + |
| 931 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
| 932 | tx_next_bd->addr_lo = |
| 933 | cpu_to_le32(U64_LO(fp->tx_desc_mapping + |
| 934 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
| 935 | } |
| 936 | |
| 937 | SET_FLAG(fp->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1); |
| 938 | fp->tx_db.data.zero_fill1 = 0; |
| 939 | fp->tx_db.data.prod = 0; |
| 940 | |
| 941 | fp->tx_pkt_prod = 0; |
| 942 | fp->tx_pkt_cons = 0; |
| 943 | fp->tx_bd_prod = 0; |
| 944 | fp->tx_bd_cons = 0; |
| 945 | fp->tx_pkt = 0; |
| 946 | } |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 947 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 948 | static inline void bnx2x_init_tx_rings(struct bnx2x *bp) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 949 | { |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 950 | int i; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 951 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 952 | for_each_tx_queue(bp, i) |
| 953 | bnx2x_init_tx_ring_one(&bp->fp[i]); |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 954 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 955 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 956 | static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp) |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 957 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 958 | int i; |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 959 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 960 | for (i = 1; i <= NUM_RX_RINGS; i++) { |
| 961 | struct eth_rx_bd *rx_bd; |
| 962 | |
| 963 | rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2]; |
| 964 | rx_bd->addr_hi = |
| 965 | cpu_to_le32(U64_HI(fp->rx_desc_mapping + |
| 966 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
| 967 | rx_bd->addr_lo = |
| 968 | cpu_to_le32(U64_LO(fp->rx_desc_mapping + |
| 969 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
| 970 | } |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 973 | static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath *fp) |
| 974 | { |
| 975 | int i; |
| 976 | |
| 977 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 978 | struct eth_rx_sge *sge; |
| 979 | |
| 980 | sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2]; |
| 981 | sge->addr_hi = |
| 982 | cpu_to_le32(U64_HI(fp->rx_sge_mapping + |
| 983 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 984 | |
| 985 | sge->addr_lo = |
| 986 | cpu_to_le32(U64_LO(fp->rx_sge_mapping + |
| 987 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath *fp) |
| 992 | { |
| 993 | int i; |
| 994 | for (i = 1; i <= NUM_RCQ_RINGS; i++) { |
| 995 | struct eth_rx_cqe_next_page *nextpg; |
| 996 | |
| 997 | nextpg = (struct eth_rx_cqe_next_page *) |
| 998 | &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1]; |
| 999 | nextpg->addr_hi = |
| 1000 | cpu_to_le32(U64_HI(fp->rx_comp_mapping + |
| 1001 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
| 1002 | nextpg->addr_lo = |
| 1003 | cpu_to_le32(U64_LO(fp->rx_comp_mapping + |
| 1004 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 1008 | /* Returns the number of actually allocated BDs */ |
| 1009 | static inline int bnx2x_alloc_rx_bds(struct bnx2x_fastpath *fp, |
| 1010 | int rx_ring_size) |
| 1011 | { |
| 1012 | struct bnx2x *bp = fp->bp; |
| 1013 | u16 ring_prod, cqe_ring_prod; |
| 1014 | int i; |
| 1015 | |
| 1016 | fp->rx_comp_cons = 0; |
| 1017 | cqe_ring_prod = ring_prod = 0; |
| 1018 | |
| 1019 | /* This routine is called only during fo init so |
| 1020 | * fp->eth_q_stats.rx_skb_alloc_failed = 0 |
| 1021 | */ |
| 1022 | for (i = 0; i < rx_ring_size; i++) { |
| 1023 | if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) { |
| 1024 | fp->eth_q_stats.rx_skb_alloc_failed++; |
| 1025 | continue; |
| 1026 | } |
| 1027 | ring_prod = NEXT_RX_IDX(ring_prod); |
| 1028 | cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod); |
| 1029 | WARN_ON(ring_prod <= (i - fp->eth_q_stats.rx_skb_alloc_failed)); |
| 1030 | } |
| 1031 | |
| 1032 | if (fp->eth_q_stats.rx_skb_alloc_failed) |
| 1033 | BNX2X_ERR("was only able to allocate " |
| 1034 | "%d rx skbs on queue[%d]\n", |
| 1035 | (i - fp->eth_q_stats.rx_skb_alloc_failed), fp->index); |
| 1036 | |
| 1037 | fp->rx_bd_prod = ring_prod; |
| 1038 | /* Limit the CQE producer by the CQE ring size */ |
| 1039 | fp->rx_comp_prod = min_t(u16, NUM_RCQ_RINGS*RCQ_DESC_CNT, |
| 1040 | cqe_ring_prod); |
| 1041 | fp->rx_pkt = fp->rx_calls = 0; |
| 1042 | |
| 1043 | return i - fp->eth_q_stats.rx_skb_alloc_failed; |
| 1044 | } |
| 1045 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 1046 | #ifdef BCM_CNIC |
| 1047 | static inline void bnx2x_init_fcoe_fp(struct bnx2x *bp) |
| 1048 | { |
| 1049 | bnx2x_fcoe(bp, cl_id) = BNX2X_FCOE_ETH_CL_ID + |
| 1050 | BP_E1HVN(bp) * NONE_ETH_CONTEXT_USE; |
| 1051 | bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID; |
| 1052 | bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID; |
| 1053 | bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id; |
| 1054 | bnx2x_fcoe(bp, bp) = bp; |
| 1055 | bnx2x_fcoe(bp, state) = BNX2X_FP_STATE_CLOSED; |
| 1056 | bnx2x_fcoe(bp, index) = FCOE_IDX; |
| 1057 | bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX; |
| 1058 | bnx2x_fcoe(bp, tx_cons_sb) = BNX2X_FCOE_L2_TX_INDEX; |
| 1059 | /* qZone id equals to FW (per path) client id */ |
| 1060 | bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fcoe(bp, cl_id) + |
| 1061 | BP_PORT(bp)*(CHIP_IS_E2(bp) ? ETH_MAX_RX_CLIENTS_E2 : |
| 1062 | ETH_MAX_RX_CLIENTS_E1H); |
| 1063 | /* init shortcut */ |
| 1064 | bnx2x_fcoe(bp, ustorm_rx_prods_offset) = CHIP_IS_E2(bp) ? |
| 1065 | USTORM_RX_PRODS_E2_OFFSET(bnx2x_fcoe(bp, cl_qzone_id)) : |
| 1066 | USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), bnx2x_fcoe_fp(bp)->cl_id); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1067 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 1068 | } |
| 1069 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1070 | |
Yaniv Rosner | 1ac9e42 | 2011-05-31 21:26:11 +0000 | [diff] [blame] | 1071 | int bnx2x_get_link_cfg_idx(struct bnx2x *bp); |
| 1072 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1073 | static inline void __storm_memset_struct(struct bnx2x *bp, |
| 1074 | u32 addr, size_t size, u32 *data) |
| 1075 | { |
| 1076 | int i; |
| 1077 | for (i = 0; i < size/4; i++) |
| 1078 | REG_WR(bp, addr + (i * 4), data[i]); |
| 1079 | } |
| 1080 | |
| 1081 | static inline void storm_memset_mac_filters(struct bnx2x *bp, |
| 1082 | struct tstorm_eth_mac_filter_config *mac_filters, |
| 1083 | u16 abs_fid) |
| 1084 | { |
| 1085 | size_t size = sizeof(struct tstorm_eth_mac_filter_config); |
| 1086 | |
| 1087 | u32 addr = BAR_TSTRORM_INTMEM + |
| 1088 | TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid); |
| 1089 | |
| 1090 | __storm_memset_struct(bp, addr, size, (u32 *)mac_filters); |
| 1091 | } |
| 1092 | |
| 1093 | static inline void storm_memset_cmng(struct bnx2x *bp, |
| 1094 | struct cmng_struct_per_port *cmng, |
| 1095 | u8 port) |
| 1096 | { |
Dmitry Kravkov | 3b7f817 | 2011-03-31 17:04:01 -0700 | [diff] [blame] | 1097 | size_t size = |
| 1098 | sizeof(struct rate_shaping_vars_per_port) + |
| 1099 | sizeof(struct fairness_vars_per_port) + |
| 1100 | sizeof(struct safc_struct_per_port) + |
| 1101 | sizeof(struct pfc_struct_per_port); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1102 | |
| 1103 | u32 addr = BAR_XSTRORM_INTMEM + |
| 1104 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port); |
| 1105 | |
| 1106 | __storm_memset_struct(bp, addr, size, (u32 *)cmng); |
Dmitry Kravkov | 3b7f817 | 2011-03-31 17:04:01 -0700 | [diff] [blame] | 1107 | |
| 1108 | addr += size + 4 /* SKIP DCB+LLFC */; |
| 1109 | size = sizeof(struct cmng_struct_per_port) - |
| 1110 | size /* written */ - 4 /*skipped*/; |
| 1111 | |
| 1112 | __storm_memset_struct(bp, addr, size, |
| 1113 | (u32 *)(cmng->traffic_type_to_priority_cos)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1114 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 1115 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1116 | /* HW Lock for shared dual port PHYs */ |
| 1117 | void bnx2x_acquire_phy_lock(struct bnx2x *bp); |
| 1118 | void bnx2x_release_phy_lock(struct bnx2x *bp); |
| 1119 | |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 1120 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 1121 | * bnx2x_extract_max_cfg - extract MAX BW part from MF configuration. |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 1122 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 1123 | * @bp: driver handle |
| 1124 | * @mf_cfg: MF configuration |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 1125 | * |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 1126 | */ |
| 1127 | static inline u16 bnx2x_extract_max_cfg(struct bnx2x *bp, u32 mf_cfg) |
| 1128 | { |
| 1129 | u16 max_cfg = (mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 1130 | FUNC_MF_CFG_MAX_BW_SHIFT; |
| 1131 | if (!max_cfg) { |
| 1132 | BNX2X_ERR("Illegal configuration detected for Max BW - " |
| 1133 | "using 100 instead\n"); |
| 1134 | max_cfg = 100; |
| 1135 | } |
| 1136 | return max_cfg; |
| 1137 | } |
| 1138 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1139 | #endif /* BNX2X_CMN_H */ |