1 /* 2 * Copyright (c) 2007, 2014 Mellanox Technologies. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 */ 33 34 #include <sys/types.h> 35 #include <linux/if_vlan.h> 36 37 #include <dev/mlx4/device.h> 38 #include <dev/mlx4/cmd.h> 39 40 #include "en_port.h" 41 #include "en.h" 42 #define EN_IFQ_MIN_INTERVAL 3000 43 44 45 int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv) 46 { 47 struct mlx4_cmd_mailbox *mailbox; 48 struct mlx4_set_vlan_fltr_mbox *filter; 49 int i; 50 int j; 51 int index = 0; 52 u32 entry; 53 int err = 0; 54 55 mailbox = mlx4_alloc_cmd_mailbox(dev); 56 if (IS_ERR(mailbox)) 57 return PTR_ERR(mailbox); 58 59 filter = mailbox->buf; 60 memset(filter, 0, sizeof(*filter)); 61 for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) { 62 entry = 0; 63 for (j = 0; j < 32; j++) { 64 if (test_bit(index, priv->active_vlans)) 65 entry |= 1 << j; 66 index++; 67 } 68 filter->entry[i] = cpu_to_be32(entry); 69 } 70 err = mlx4_cmd(dev, mailbox->dma, priv->port, 0, MLX4_CMD_SET_VLAN_FLTR, 71 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED); 72 mlx4_free_cmd_mailbox(dev, mailbox); 73 return err; 74 } 75 76 int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port) 77 { 78 struct mlx4_en_query_port_context *qport_context; 79 struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]); 80 struct mlx4_en_port_state *state = &priv->port_state; 81 struct mlx4_cmd_mailbox *mailbox; 82 int err; 83 84 mailbox = mlx4_alloc_cmd_mailbox(mdev->dev); 85 if (IS_ERR(mailbox)) 86 return PTR_ERR(mailbox); 87 memset(mailbox->buf, 0, sizeof(*qport_context)); 88 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0, 89 MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B, 90 MLX4_CMD_WRAPPED); 91 if (err) 92 goto out; 93 qport_context = mailbox->buf; 94 95 /* This command is always accessed from Ethtool context 96 * already synchronized, no need in locking */ 97 state->link_state = !!(qport_context->link_up & MLX4_EN_LINK_UP_MASK); 98 switch (qport_context->link_speed & MLX4_EN_SPEED_MASK) { 99 case MLX4_EN_1G_SPEED: 100 state->link_speed = 1000; 101 break; 102 case MLX4_EN_10G_SPEED_XAUI: 103 case MLX4_EN_10G_SPEED_XFI: 104 state->link_speed = 10000; 105 break; 106 case MLX4_EN_20G_SPEED: 107 state->link_speed = 20000; 108 break; 109 case MLX4_EN_40G_SPEED: 110 state->link_speed = 40000; 111 break; 112 case MLX4_EN_56G_SPEED: 113 state->link_speed = 56000; 114 break; 115 default: 116 state->link_speed = -1; 117 break; 118 } 119 state->transciver = qport_context->transceiver; 120 state->autoneg = !!(qport_context->autoneg & MLX4_EN_AUTONEG_MASK); 121 122 out: 123 mlx4_free_cmd_mailbox(mdev->dev, mailbox); 124 return err; 125 } 126 127 static void mlx4_en_fold_software_stats(struct net_device *dev) 128 { 129 struct mlx4_en_priv *priv = netdev_priv(dev); 130 struct mlx4_en_dev *mdev = priv->mdev; 131 u64 packets, bytes; 132 int i; 133 134 if (!priv->port_up || mlx4_is_master(mdev->dev)) 135 return; 136 137 packets = 0; 138 bytes = 0; 139 for (i = 0; i < priv->rx_ring_num; i++) { 140 const struct mlx4_en_rx_ring *ring = priv->rx_ring[i]; 141 142 packets += READ_ONCE(ring->packets); 143 bytes += READ_ONCE(ring->bytes); 144 } 145 priv->pkstats.rx_packets = packets; 146 priv->pkstats.rx_bytes = bytes; 147 148 packets = 0; 149 bytes = 0; 150 for (i = 0; i < priv->tx_ring_num; i++) { 151 const struct mlx4_en_tx_ring *ring = priv->tx_ring[i]; 152 153 packets += READ_ONCE(ring->packets); 154 bytes += READ_ONCE(ring->bytes); 155 } 156 priv->pkstats.tx_packets = packets; 157 priv->pkstats.tx_bytes = bytes; 158 } 159 160 int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset) 161 { 162 struct mlx4_en_stat_out_mbox *mlx4_en_stats; 163 struct mlx4_en_stat_out_flow_control_mbox *flowstats; 164 struct net_device *dev = mdev->pndev[port]; 165 struct mlx4_en_priv *priv = netdev_priv(dev); 166 struct mlx4_en_vport_stats *vport_stats = &priv->vport_stats; 167 struct mlx4_cmd_mailbox *mailbox = NULL; 168 struct mlx4_cmd_mailbox *mailbox_flow = NULL; 169 u64 in_mod = reset << 8 | port; 170 int err; 171 int i; 172 int do_if_stat = 1; 173 unsigned long period = (unsigned long) (jiffies - priv->last_ifq_jiffies); 174 struct mlx4_en_vport_stats tmp_vport_stats; 175 176 if (jiffies_to_msecs(period) < EN_IFQ_MIN_INTERVAL || 177 priv->counter_index == 0xff) 178 do_if_stat = 0; 179 180 mailbox = mlx4_alloc_cmd_mailbox(mdev->dev); 181 if (IS_ERR(mailbox)) { 182 err = PTR_ERR(mailbox); 183 goto mailbox_out; 184 } 185 186 mailbox_flow = mlx4_alloc_cmd_mailbox(mdev->dev); 187 if (IS_ERR(mailbox_flow)) { 188 mlx4_free_cmd_mailbox(mdev->dev, mailbox); 189 err = PTR_ERR(mailbox_flow); 190 goto mailbox_out; 191 } 192 193 /* 0xffs indicates invalid value */ 194 memset(mailbox_flow->buf, 0xff, sizeof(*flowstats) * 195 MLX4_NUM_PRIORITIES); 196 197 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN) { 198 memset(mailbox_flow->buf, 0, sizeof(*flowstats)); 199 err = mlx4_cmd_box(mdev->dev, 0, mailbox_flow->dma, 200 in_mod | 1<<12, 0, MLX4_CMD_DUMP_ETH_STATS, 201 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 202 203 if (err) 204 goto out; 205 } 206 207 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0, 208 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B, 209 MLX4_CMD_NATIVE); 210 if (err) 211 goto out; 212 213 mlx4_en_stats = mailbox->buf; 214 215 spin_lock(&priv->stats_lock); 216 217 priv->port_stats.rx_chksum_good = 0; 218 priv->port_stats.rx_chksum_none = 0; 219 for (i = 0; i < priv->rx_ring_num; i++) { 220 priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok; 221 priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none; 222 } 223 224 priv->port_stats.tx_chksum_offload = 0; 225 priv->port_stats.queue_stopped = 0; 226 priv->port_stats.wake_queue = 0; 227 priv->port_stats.oversized_packets = 0; 228 priv->port_stats.tso_packets = 0; 229 priv->port_stats.defrag_attempts = 0; 230 for (i = 0; i < priv->tx_ring_num; i++) { 231 priv->port_stats.tx_chksum_offload += priv->tx_ring[i]->tx_csum; 232 priv->port_stats.queue_stopped += priv->tx_ring[i]->queue_stopped; 233 priv->port_stats.wake_queue += priv->tx_ring[i]->wake_queue; 234 priv->port_stats.oversized_packets += priv->tx_ring[i]->oversized_packets; 235 priv->port_stats.tso_packets += priv->tx_ring[i]->tso_packets; 236 priv->port_stats.defrag_attempts += priv->tx_ring[i]->defrag_attempts; 237 } 238 /* RX Statistics */ 239 priv->pkstats.rx_packets = be64_to_cpu(mlx4_en_stats->RTOT_prio_0) + 240 be64_to_cpu(mlx4_en_stats->RTOT_prio_1) + 241 be64_to_cpu(mlx4_en_stats->RTOT_prio_2) + 242 be64_to_cpu(mlx4_en_stats->RTOT_prio_3) + 243 be64_to_cpu(mlx4_en_stats->RTOT_prio_4) + 244 be64_to_cpu(mlx4_en_stats->RTOT_prio_5) + 245 be64_to_cpu(mlx4_en_stats->RTOT_prio_6) + 246 be64_to_cpu(mlx4_en_stats->RTOT_prio_7) + 247 be64_to_cpu(mlx4_en_stats->RTOT_novlan); 248 priv->pkstats.rx_bytes = be64_to_cpu(mlx4_en_stats->ROCT_prio_0) + 249 be64_to_cpu(mlx4_en_stats->ROCT_prio_1) + 250 be64_to_cpu(mlx4_en_stats->ROCT_prio_2) + 251 be64_to_cpu(mlx4_en_stats->ROCT_prio_3) + 252 be64_to_cpu(mlx4_en_stats->ROCT_prio_4) + 253 be64_to_cpu(mlx4_en_stats->ROCT_prio_5) + 254 be64_to_cpu(mlx4_en_stats->ROCT_prio_6) + 255 be64_to_cpu(mlx4_en_stats->ROCT_prio_7) + 256 be64_to_cpu(mlx4_en_stats->ROCT_novlan); 257 priv->pkstats.rx_multicast_packets = be64_to_cpu(mlx4_en_stats->MCAST_prio_0) + 258 be64_to_cpu(mlx4_en_stats->MCAST_prio_1) + 259 be64_to_cpu(mlx4_en_stats->MCAST_prio_2) + 260 be64_to_cpu(mlx4_en_stats->MCAST_prio_3) + 261 be64_to_cpu(mlx4_en_stats->MCAST_prio_4) + 262 be64_to_cpu(mlx4_en_stats->MCAST_prio_5) + 263 be64_to_cpu(mlx4_en_stats->MCAST_prio_6) + 264 be64_to_cpu(mlx4_en_stats->MCAST_prio_7) + 265 be64_to_cpu(mlx4_en_stats->MCAST_novlan); 266 priv->pkstats.rx_broadcast_packets = be64_to_cpu(mlx4_en_stats->RBCAST_prio_0) + 267 be64_to_cpu(mlx4_en_stats->RBCAST_prio_1) + 268 be64_to_cpu(mlx4_en_stats->RBCAST_prio_2) + 269 be64_to_cpu(mlx4_en_stats->RBCAST_prio_3) + 270 be64_to_cpu(mlx4_en_stats->RBCAST_prio_4) + 271 be64_to_cpu(mlx4_en_stats->RBCAST_prio_5) + 272 be64_to_cpu(mlx4_en_stats->RBCAST_prio_6) + 273 be64_to_cpu(mlx4_en_stats->RBCAST_prio_7) + 274 be64_to_cpu(mlx4_en_stats->RBCAST_novlan); 275 priv->pkstats.rx_errors = be64_to_cpu(mlx4_en_stats->PCS) + 276 be32_to_cpu(mlx4_en_stats->RJBBR) + 277 be32_to_cpu(mlx4_en_stats->RCRC) + 278 be32_to_cpu(mlx4_en_stats->RRUNT) + 279 be64_to_cpu(mlx4_en_stats->RInRangeLengthErr) + 280 be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr) + 281 be32_to_cpu(mlx4_en_stats->RSHORT) + 282 be64_to_cpu(mlx4_en_stats->RGIANT_prio_0) + 283 be64_to_cpu(mlx4_en_stats->RGIANT_prio_1) + 284 be64_to_cpu(mlx4_en_stats->RGIANT_prio_2) + 285 be64_to_cpu(mlx4_en_stats->RGIANT_prio_3) + 286 be64_to_cpu(mlx4_en_stats->RGIANT_prio_4) + 287 be64_to_cpu(mlx4_en_stats->RGIANT_prio_5) + 288 be64_to_cpu(mlx4_en_stats->RGIANT_prio_6) + 289 be64_to_cpu(mlx4_en_stats->RGIANT_prio_7) + 290 be64_to_cpu(mlx4_en_stats->RGIANT_novlan); 291 priv->pkstats.rx_dropped = be32_to_cpu(mlx4_en_stats->RdropOvflw); 292 priv->pkstats.rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength); 293 priv->pkstats.rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw); 294 priv->pkstats.rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC); 295 priv->pkstats.rx_jabbers = be32_to_cpu(mlx4_en_stats->RJBBR); 296 priv->pkstats.rx_in_range_length_error = be64_to_cpu(mlx4_en_stats->RInRangeLengthErr); 297 priv->pkstats.rx_out_range_length_error = be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr); 298 priv->pkstats.rx_lt_64_bytes_packets = be64_to_cpu(mlx4_en_stats->R64_prio_0) + 299 be64_to_cpu(mlx4_en_stats->R64_prio_1) + 300 be64_to_cpu(mlx4_en_stats->R64_prio_2) + 301 be64_to_cpu(mlx4_en_stats->R64_prio_3) + 302 be64_to_cpu(mlx4_en_stats->R64_prio_4) + 303 be64_to_cpu(mlx4_en_stats->R64_prio_5) + 304 be64_to_cpu(mlx4_en_stats->R64_prio_6) + 305 be64_to_cpu(mlx4_en_stats->R64_prio_7) + 306 be64_to_cpu(mlx4_en_stats->R64_novlan); 307 priv->pkstats.rx_127_bytes_packets = be64_to_cpu(mlx4_en_stats->R127_prio_0) + 308 be64_to_cpu(mlx4_en_stats->R127_prio_1) + 309 be64_to_cpu(mlx4_en_stats->R127_prio_2) + 310 be64_to_cpu(mlx4_en_stats->R127_prio_3) + 311 be64_to_cpu(mlx4_en_stats->R127_prio_4) + 312 be64_to_cpu(mlx4_en_stats->R127_prio_5) + 313 be64_to_cpu(mlx4_en_stats->R127_prio_6) + 314 be64_to_cpu(mlx4_en_stats->R127_prio_7) + 315 be64_to_cpu(mlx4_en_stats->R127_novlan); 316 priv->pkstats.rx_255_bytes_packets = be64_to_cpu(mlx4_en_stats->R255_prio_0) + 317 be64_to_cpu(mlx4_en_stats->R255_prio_1) + 318 be64_to_cpu(mlx4_en_stats->R255_prio_2) + 319 be64_to_cpu(mlx4_en_stats->R255_prio_3) + 320 be64_to_cpu(mlx4_en_stats->R255_prio_4) + 321 be64_to_cpu(mlx4_en_stats->R255_prio_5) + 322 be64_to_cpu(mlx4_en_stats->R255_prio_6) + 323 be64_to_cpu(mlx4_en_stats->R255_prio_7) + 324 be64_to_cpu(mlx4_en_stats->R255_novlan); 325 priv->pkstats.rx_511_bytes_packets = be64_to_cpu(mlx4_en_stats->R511_prio_0) + 326 be64_to_cpu(mlx4_en_stats->R511_prio_1) + 327 be64_to_cpu(mlx4_en_stats->R511_prio_2) + 328 be64_to_cpu(mlx4_en_stats->R511_prio_3) + 329 be64_to_cpu(mlx4_en_stats->R511_prio_4) + 330 be64_to_cpu(mlx4_en_stats->R511_prio_5) + 331 be64_to_cpu(mlx4_en_stats->R511_prio_6) + 332 be64_to_cpu(mlx4_en_stats->R511_prio_7) + 333 be64_to_cpu(mlx4_en_stats->R511_novlan); 334 priv->pkstats.rx_1023_bytes_packets = be64_to_cpu(mlx4_en_stats->R1023_prio_0) + 335 be64_to_cpu(mlx4_en_stats->R1023_prio_1) + 336 be64_to_cpu(mlx4_en_stats->R1023_prio_2) + 337 be64_to_cpu(mlx4_en_stats->R1023_prio_3) + 338 be64_to_cpu(mlx4_en_stats->R1023_prio_4) + 339 be64_to_cpu(mlx4_en_stats->R1023_prio_5) + 340 be64_to_cpu(mlx4_en_stats->R1023_prio_6) + 341 be64_to_cpu(mlx4_en_stats->R1023_prio_7) + 342 be64_to_cpu(mlx4_en_stats->R1023_novlan); 343 priv->pkstats.rx_1518_bytes_packets = be64_to_cpu(mlx4_en_stats->R1518_prio_0) + 344 be64_to_cpu(mlx4_en_stats->R1518_prio_1) + 345 be64_to_cpu(mlx4_en_stats->R1518_prio_2) + 346 be64_to_cpu(mlx4_en_stats->R1518_prio_3) + 347 be64_to_cpu(mlx4_en_stats->R1518_prio_4) + 348 be64_to_cpu(mlx4_en_stats->R1518_prio_5) + 349 be64_to_cpu(mlx4_en_stats->R1518_prio_6) + 350 be64_to_cpu(mlx4_en_stats->R1518_prio_7) + 351 be64_to_cpu(mlx4_en_stats->R1518_novlan); 352 priv->pkstats.rx_1522_bytes_packets = be64_to_cpu(mlx4_en_stats->R1522_prio_0) + 353 be64_to_cpu(mlx4_en_stats->R1522_prio_1) + 354 be64_to_cpu(mlx4_en_stats->R1522_prio_2) + 355 be64_to_cpu(mlx4_en_stats->R1522_prio_3) + 356 be64_to_cpu(mlx4_en_stats->R1522_prio_4) + 357 be64_to_cpu(mlx4_en_stats->R1522_prio_5) + 358 be64_to_cpu(mlx4_en_stats->R1522_prio_6) + 359 be64_to_cpu(mlx4_en_stats->R1522_prio_7) + 360 be64_to_cpu(mlx4_en_stats->R1522_novlan); 361 priv->pkstats.rx_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->R1548_prio_0) + 362 be64_to_cpu(mlx4_en_stats->R1548_prio_1) + 363 be64_to_cpu(mlx4_en_stats->R1548_prio_2) + 364 be64_to_cpu(mlx4_en_stats->R1548_prio_3) + 365 be64_to_cpu(mlx4_en_stats->R1548_prio_4) + 366 be64_to_cpu(mlx4_en_stats->R1548_prio_5) + 367 be64_to_cpu(mlx4_en_stats->R1548_prio_6) + 368 be64_to_cpu(mlx4_en_stats->R1548_prio_7) + 369 be64_to_cpu(mlx4_en_stats->R1548_novlan); 370 priv->pkstats.rx_gt_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->R2MTU_prio_0) + 371 be64_to_cpu(mlx4_en_stats->R2MTU_prio_1) + 372 be64_to_cpu(mlx4_en_stats->R2MTU_prio_2) + 373 be64_to_cpu(mlx4_en_stats->R2MTU_prio_3) + 374 be64_to_cpu(mlx4_en_stats->R2MTU_prio_4) + 375 be64_to_cpu(mlx4_en_stats->R2MTU_prio_5) + 376 be64_to_cpu(mlx4_en_stats->R2MTU_prio_6) + 377 be64_to_cpu(mlx4_en_stats->R2MTU_prio_7) + 378 be64_to_cpu(mlx4_en_stats->R2MTU_novlan); 379 380 /* Tx Stats */ 381 priv->pkstats.tx_packets = be64_to_cpu(mlx4_en_stats->TTOT_prio_0) + 382 be64_to_cpu(mlx4_en_stats->TTOT_prio_1) + 383 be64_to_cpu(mlx4_en_stats->TTOT_prio_2) + 384 be64_to_cpu(mlx4_en_stats->TTOT_prio_3) + 385 be64_to_cpu(mlx4_en_stats->TTOT_prio_4) + 386 be64_to_cpu(mlx4_en_stats->TTOT_prio_5) + 387 be64_to_cpu(mlx4_en_stats->TTOT_prio_6) + 388 be64_to_cpu(mlx4_en_stats->TTOT_prio_7) + 389 be64_to_cpu(mlx4_en_stats->TTOT_novlan); 390 priv->pkstats.tx_bytes = be64_to_cpu(mlx4_en_stats->TOCT_prio_0) + 391 be64_to_cpu(mlx4_en_stats->TOCT_prio_1) + 392 be64_to_cpu(mlx4_en_stats->TOCT_prio_2) + 393 be64_to_cpu(mlx4_en_stats->TOCT_prio_3) + 394 be64_to_cpu(mlx4_en_stats->TOCT_prio_4) + 395 be64_to_cpu(mlx4_en_stats->TOCT_prio_5) + 396 be64_to_cpu(mlx4_en_stats->TOCT_prio_6) + 397 be64_to_cpu(mlx4_en_stats->TOCT_prio_7) + 398 be64_to_cpu(mlx4_en_stats->TOCT_novlan); 399 priv->pkstats.tx_multicast_packets = be64_to_cpu(mlx4_en_stats->TMCAST_prio_0) + 400 be64_to_cpu(mlx4_en_stats->TMCAST_prio_1) + 401 be64_to_cpu(mlx4_en_stats->TMCAST_prio_2) + 402 be64_to_cpu(mlx4_en_stats->TMCAST_prio_3) + 403 be64_to_cpu(mlx4_en_stats->TMCAST_prio_4) + 404 be64_to_cpu(mlx4_en_stats->TMCAST_prio_5) + 405 be64_to_cpu(mlx4_en_stats->TMCAST_prio_6) + 406 be64_to_cpu(mlx4_en_stats->TMCAST_prio_7) + 407 be64_to_cpu(mlx4_en_stats->TMCAST_novlan); 408 priv->pkstats.tx_broadcast_packets = be64_to_cpu(mlx4_en_stats->TBCAST_prio_0) + 409 be64_to_cpu(mlx4_en_stats->TBCAST_prio_1) + 410 be64_to_cpu(mlx4_en_stats->TBCAST_prio_2) + 411 be64_to_cpu(mlx4_en_stats->TBCAST_prio_3) + 412 be64_to_cpu(mlx4_en_stats->TBCAST_prio_4) + 413 be64_to_cpu(mlx4_en_stats->TBCAST_prio_5) + 414 be64_to_cpu(mlx4_en_stats->TBCAST_prio_6) + 415 be64_to_cpu(mlx4_en_stats->TBCAST_prio_7) + 416 be64_to_cpu(mlx4_en_stats->TBCAST_novlan); 417 priv->pkstats.tx_errors = be64_to_cpu(mlx4_en_stats->TGIANT_prio_0) + 418 be64_to_cpu(mlx4_en_stats->TGIANT_prio_1) + 419 be64_to_cpu(mlx4_en_stats->TGIANT_prio_2) + 420 be64_to_cpu(mlx4_en_stats->TGIANT_prio_3) + 421 be64_to_cpu(mlx4_en_stats->TGIANT_prio_4) + 422 be64_to_cpu(mlx4_en_stats->TGIANT_prio_5) + 423 be64_to_cpu(mlx4_en_stats->TGIANT_prio_6) + 424 be64_to_cpu(mlx4_en_stats->TGIANT_prio_7) + 425 be64_to_cpu(mlx4_en_stats->TGIANT_novlan); 426 priv->pkstats.tx_dropped = be32_to_cpu(mlx4_en_stats->TDROP) - 427 priv->pkstats.tx_errors; 428 priv->pkstats.tx_lt_64_bytes_packets = be64_to_cpu(mlx4_en_stats->T64_prio_0) + 429 be64_to_cpu(mlx4_en_stats->T64_prio_1) + 430 be64_to_cpu(mlx4_en_stats->T64_prio_2) + 431 be64_to_cpu(mlx4_en_stats->T64_prio_3) + 432 be64_to_cpu(mlx4_en_stats->T64_prio_4) + 433 be64_to_cpu(mlx4_en_stats->T64_prio_5) + 434 be64_to_cpu(mlx4_en_stats->T64_prio_6) + 435 be64_to_cpu(mlx4_en_stats->T64_prio_7) + 436 be64_to_cpu(mlx4_en_stats->T64_novlan); 437 priv->pkstats.tx_127_bytes_packets = be64_to_cpu(mlx4_en_stats->T127_prio_0) + 438 be64_to_cpu(mlx4_en_stats->T127_prio_1) + 439 be64_to_cpu(mlx4_en_stats->T127_prio_2) + 440 be64_to_cpu(mlx4_en_stats->T127_prio_3) + 441 be64_to_cpu(mlx4_en_stats->T127_prio_4) + 442 be64_to_cpu(mlx4_en_stats->T127_prio_5) + 443 be64_to_cpu(mlx4_en_stats->T127_prio_6) + 444 be64_to_cpu(mlx4_en_stats->T127_prio_7) + 445 be64_to_cpu(mlx4_en_stats->T127_novlan); 446 priv->pkstats.tx_255_bytes_packets = be64_to_cpu(mlx4_en_stats->T255_prio_0) + 447 be64_to_cpu(mlx4_en_stats->T255_prio_1) + 448 be64_to_cpu(mlx4_en_stats->T255_prio_2) + 449 be64_to_cpu(mlx4_en_stats->T255_prio_3) + 450 be64_to_cpu(mlx4_en_stats->T255_prio_4) + 451 be64_to_cpu(mlx4_en_stats->T255_prio_5) + 452 be64_to_cpu(mlx4_en_stats->T255_prio_6) + 453 be64_to_cpu(mlx4_en_stats->T255_prio_7) + 454 be64_to_cpu(mlx4_en_stats->T255_novlan); 455 priv->pkstats.tx_511_bytes_packets = be64_to_cpu(mlx4_en_stats->T511_prio_0) + 456 be64_to_cpu(mlx4_en_stats->T511_prio_1) + 457 be64_to_cpu(mlx4_en_stats->T511_prio_2) + 458 be64_to_cpu(mlx4_en_stats->T511_prio_3) + 459 be64_to_cpu(mlx4_en_stats->T511_prio_4) + 460 be64_to_cpu(mlx4_en_stats->T511_prio_5) + 461 be64_to_cpu(mlx4_en_stats->T511_prio_6) + 462 be64_to_cpu(mlx4_en_stats->T511_prio_7) + 463 be64_to_cpu(mlx4_en_stats->T511_novlan); 464 priv->pkstats.tx_1023_bytes_packets = be64_to_cpu(mlx4_en_stats->T1023_prio_0) + 465 be64_to_cpu(mlx4_en_stats->T1023_prio_1) + 466 be64_to_cpu(mlx4_en_stats->T1023_prio_2) + 467 be64_to_cpu(mlx4_en_stats->T1023_prio_3) + 468 be64_to_cpu(mlx4_en_stats->T1023_prio_4) + 469 be64_to_cpu(mlx4_en_stats->T1023_prio_5) + 470 be64_to_cpu(mlx4_en_stats->T1023_prio_6) + 471 be64_to_cpu(mlx4_en_stats->T1023_prio_7) + 472 be64_to_cpu(mlx4_en_stats->T1023_novlan); 473 priv->pkstats.tx_1518_bytes_packets = be64_to_cpu(mlx4_en_stats->T1518_prio_0) + 474 be64_to_cpu(mlx4_en_stats->T1518_prio_1) + 475 be64_to_cpu(mlx4_en_stats->T1518_prio_2) + 476 be64_to_cpu(mlx4_en_stats->T1518_prio_3) + 477 be64_to_cpu(mlx4_en_stats->T1518_prio_4) + 478 be64_to_cpu(mlx4_en_stats->T1518_prio_5) + 479 be64_to_cpu(mlx4_en_stats->T1518_prio_6) + 480 be64_to_cpu(mlx4_en_stats->T1518_prio_7) + 481 be64_to_cpu(mlx4_en_stats->T1518_novlan); 482 priv->pkstats.tx_1522_bytes_packets = be64_to_cpu(mlx4_en_stats->T1522_prio_0) + 483 be64_to_cpu(mlx4_en_stats->T1522_prio_1) + 484 be64_to_cpu(mlx4_en_stats->T1522_prio_2) + 485 be64_to_cpu(mlx4_en_stats->T1522_prio_3) + 486 be64_to_cpu(mlx4_en_stats->T1522_prio_4) + 487 be64_to_cpu(mlx4_en_stats->T1522_prio_5) + 488 be64_to_cpu(mlx4_en_stats->T1522_prio_6) + 489 be64_to_cpu(mlx4_en_stats->T1522_prio_7) + 490 be64_to_cpu(mlx4_en_stats->T1522_novlan); 491 priv->pkstats.tx_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->T1548_prio_0) + 492 be64_to_cpu(mlx4_en_stats->T1548_prio_1) + 493 be64_to_cpu(mlx4_en_stats->T1548_prio_2) + 494 be64_to_cpu(mlx4_en_stats->T1548_prio_3) + 495 be64_to_cpu(mlx4_en_stats->T1548_prio_4) + 496 be64_to_cpu(mlx4_en_stats->T1548_prio_5) + 497 be64_to_cpu(mlx4_en_stats->T1548_prio_6) + 498 be64_to_cpu(mlx4_en_stats->T1548_prio_7) + 499 be64_to_cpu(mlx4_en_stats->T1548_novlan); 500 priv->pkstats.tx_gt_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->T2MTU_prio_0) + 501 be64_to_cpu(mlx4_en_stats->T2MTU_prio_1) + 502 be64_to_cpu(mlx4_en_stats->T2MTU_prio_2) + 503 be64_to_cpu(mlx4_en_stats->T2MTU_prio_3) + 504 be64_to_cpu(mlx4_en_stats->T2MTU_prio_4) + 505 be64_to_cpu(mlx4_en_stats->T2MTU_prio_5) + 506 be64_to_cpu(mlx4_en_stats->T2MTU_prio_6) + 507 be64_to_cpu(mlx4_en_stats->T2MTU_prio_7) + 508 be64_to_cpu(mlx4_en_stats->T2MTU_novlan); 509 510 priv->pkstats.rx_prio[0][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0); 511 priv->pkstats.rx_prio[0][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_0); 512 priv->pkstats.rx_prio[1][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1); 513 priv->pkstats.rx_prio[1][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_1); 514 priv->pkstats.rx_prio[2][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2); 515 priv->pkstats.rx_prio[2][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_2); 516 priv->pkstats.rx_prio[3][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3); 517 priv->pkstats.rx_prio[3][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_3); 518 priv->pkstats.rx_prio[4][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4); 519 priv->pkstats.rx_prio[4][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_4); 520 priv->pkstats.rx_prio[5][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5); 521 priv->pkstats.rx_prio[5][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_5); 522 priv->pkstats.rx_prio[6][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6); 523 priv->pkstats.rx_prio[6][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_6); 524 priv->pkstats.rx_prio[7][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7); 525 priv->pkstats.rx_prio[7][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_7); 526 priv->pkstats.rx_prio[8][0] = be64_to_cpu(mlx4_en_stats->RTOT_novlan); 527 priv->pkstats.rx_prio[8][1] = be64_to_cpu(mlx4_en_stats->ROCT_novlan); 528 priv->pkstats.tx_prio[0][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0); 529 priv->pkstats.tx_prio[0][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_0); 530 priv->pkstats.tx_prio[1][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1); 531 priv->pkstats.tx_prio[1][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_1); 532 priv->pkstats.tx_prio[2][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2); 533 priv->pkstats.tx_prio[2][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_2); 534 priv->pkstats.tx_prio[3][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3); 535 priv->pkstats.tx_prio[3][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_3); 536 priv->pkstats.tx_prio[4][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4); 537 priv->pkstats.tx_prio[4][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_4); 538 priv->pkstats.tx_prio[5][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5); 539 priv->pkstats.tx_prio[5][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_5); 540 priv->pkstats.tx_prio[6][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6); 541 priv->pkstats.tx_prio[6][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_6); 542 priv->pkstats.tx_prio[7][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7); 543 priv->pkstats.tx_prio[7][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_7); 544 priv->pkstats.tx_prio[8][0] = be64_to_cpu(mlx4_en_stats->TTOT_novlan); 545 priv->pkstats.tx_prio[8][1] = be64_to_cpu(mlx4_en_stats->TOCT_novlan); 546 547 flowstats = mailbox_flow->buf; 548 549 for (i = 0; i < MLX4_NUM_PRIORITIES; i++) { 550 priv->flowstats[i].rx_pause = 551 be64_to_cpu(flowstats[i].rx_pause); 552 priv->flowstats[i].rx_pause_duration = 553 be64_to_cpu(flowstats[i].rx_pause_duration); 554 priv->flowstats[i].rx_pause_transition = 555 be64_to_cpu(flowstats[i].rx_pause_transition); 556 priv->flowstats[i].tx_pause = 557 be64_to_cpu(flowstats[i].tx_pause); 558 priv->flowstats[i].tx_pause_duration = 559 be64_to_cpu(flowstats[i].tx_pause_duration); 560 priv->flowstats[i].tx_pause_transition = 561 be64_to_cpu(flowstats[i].tx_pause_transition); 562 } 563 564 mlx4_en_fold_software_stats(dev); 565 566 spin_unlock(&priv->stats_lock); 567 568 memset(&tmp_vport_stats, 0, sizeof(tmp_vport_stats)); 569 570 err = mlx4_get_vport_ethtool_stats(mdev->dev, port, 571 &tmp_vport_stats, reset); 572 spin_lock(&priv->stats_lock); 573 if (!err) { 574 /* ethtool stats format */ 575 vport_stats->rx_unicast_packets = tmp_vport_stats.rx_unicast_packets; 576 vport_stats->rx_unicast_bytes = tmp_vport_stats.rx_unicast_bytes; 577 vport_stats->rx_multicast_packets = tmp_vport_stats.rx_multicast_packets; 578 vport_stats->rx_multicast_bytes = tmp_vport_stats.rx_multicast_bytes; 579 vport_stats->rx_broadcast_packets = tmp_vport_stats.rx_broadcast_packets; 580 vport_stats->rx_broadcast_bytes = tmp_vport_stats.rx_broadcast_bytes; 581 vport_stats->rx_dropped = tmp_vport_stats.rx_dropped; 582 vport_stats->rx_errors = tmp_vport_stats.rx_errors; 583 vport_stats->tx_unicast_packets = tmp_vport_stats.tx_unicast_packets; 584 vport_stats->tx_unicast_bytes = tmp_vport_stats.tx_unicast_bytes; 585 vport_stats->tx_multicast_packets = tmp_vport_stats.tx_multicast_packets; 586 vport_stats->tx_multicast_bytes = tmp_vport_stats.tx_multicast_bytes; 587 vport_stats->tx_broadcast_packets = tmp_vport_stats.tx_broadcast_packets; 588 vport_stats->tx_broadcast_bytes = tmp_vport_stats.tx_broadcast_bytes; 589 vport_stats->tx_errors = tmp_vport_stats.tx_errors; 590 } 591 592 #if __FreeBSD_version >= 1100000 593 if (reset == 0) { 594 if_inc_counter(dev, IFCOUNTER_IPACKETS, 595 priv->pkstats.rx_packets - priv->pkstats_last.rx_packets); 596 if_inc_counter(dev, IFCOUNTER_OPACKETS, 597 priv->pkstats.tx_packets - priv->pkstats_last.tx_packets); 598 if_inc_counter(dev, IFCOUNTER_IBYTES, 599 priv->pkstats.rx_bytes - priv->pkstats_last.rx_bytes); 600 if_inc_counter(dev, IFCOUNTER_OBYTES, 601 priv->pkstats.tx_bytes - priv->pkstats_last.tx_bytes); 602 if_inc_counter(dev, IFCOUNTER_IERRORS, 603 priv->pkstats.rx_errors - priv->pkstats_last.rx_errors); 604 if_inc_counter(dev, IFCOUNTER_IQDROPS, 605 priv->pkstats.rx_dropped - priv->pkstats_last.rx_dropped); 606 if_inc_counter(dev, IFCOUNTER_IMCASTS, 607 priv->pkstats.rx_multicast_packets - priv->pkstats_last.rx_multicast_packets); 608 if_inc_counter(dev, IFCOUNTER_OMCASTS, 609 priv->pkstats.tx_multicast_packets - priv->pkstats_last.tx_multicast_packets); 610 } 611 priv->pkstats_last = priv->pkstats; 612 #else 613 dev->if_ipackets = priv->pkstats.rx_packets; 614 dev->if_opackets = priv->pkstats.tx_packets; 615 dev->if_ibytes = priv->pkstats.rx_bytes; 616 dev->if_obytes = priv->pkstats.tx_bytes; 617 dev->if_ierrors = priv->pkstats.rx_errors; 618 dev->if_iqdrops = priv->pkstats.rx_dropped; 619 dev->if_imcasts = priv->pkstats.rx_multicast_packets; 620 dev->if_omcasts = priv->pkstats.tx_multicast_packets; 621 dev->if_collisions = 0; 622 #endif 623 624 spin_unlock(&priv->stats_lock); 625 626 out: 627 mlx4_free_cmd_mailbox(mdev->dev, mailbox_flow); 628 mlx4_free_cmd_mailbox(mdev->dev, mailbox); 629 630 mailbox_out: 631 if (do_if_stat) 632 priv->last_ifq_jiffies = jiffies; 633 634 return err; 635 } 636