1 /*- 2 * Copyright 2007-2009 Solarflare Communications Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26 #include <sys/cdefs.h> 27 __FBSDID("$FreeBSD$"); 28 29 #include "efsys.h" 30 #include "efx.h" 31 #include "efx_types.h" 32 #include "efx_regs.h" 33 #include "efx_impl.h" 34 35 #if EFSYS_OPT_QSTATS 36 #define EFX_EV_QSTAT_INCR(_eep, _stat) \ 37 do { \ 38 (_eep)->ee_stat[_stat]++; \ 39 _NOTE(CONSTANTCONDITION) \ 40 } while (B_FALSE) 41 #else 42 #define EFX_EV_QSTAT_INCR(_eep, _stat) 43 #endif 44 45 __checkReturn int 46 efx_ev_init( 47 __in efx_nic_t *enp) 48 { 49 efx_oword_t oword; 50 int rc; 51 52 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 53 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR); 54 55 if (enp->en_mod_flags & EFX_MOD_EV) { 56 rc = EINVAL; 57 goto fail1; 58 } 59 60 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0); 61 62 /* 63 * Program the event queue for receive and transmit queue 64 * flush events. 65 */ 66 EFX_BAR_READO(enp, FR_AZ_DP_CTRL_REG, &oword); 67 EFX_SET_OWORD_FIELD(oword, FRF_AZ_FLS_EVQ_ID, 0); 68 EFX_BAR_WRITEO(enp, FR_AZ_DP_CTRL_REG, &oword); 69 70 enp->en_mod_flags |= EFX_MOD_EV; 71 return (0); 72 73 fail1: 74 EFSYS_PROBE1(fail1, int, rc); 75 76 return (rc); 77 } 78 79 static __checkReturn boolean_t 80 efx_ev_rx_not_ok( 81 __in efx_evq_t *eep, 82 __in efx_qword_t *eqp, 83 __in uint32_t label, 84 __in uint32_t id, 85 __inout uint16_t *flagsp) 86 { 87 boolean_t ignore = B_FALSE; 88 89 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TOBE_DISC) != 0) { 90 EFX_EV_QSTAT_INCR(eep, EV_RX_TOBE_DISC); 91 EFSYS_PROBE(tobe_disc); 92 /* 93 * Assume this is a unicast address mismatch, unless below 94 * we find either FSF_AZ_RX_EV_ETH_CRC_ERR or 95 * EV_RX_PAUSE_FRM_ERR is set. 96 */ 97 (*flagsp) |= EFX_ADDR_MISMATCH; 98 } 99 100 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_FRM_TRUNC) != 0) { 101 EFSYS_PROBE2(frm_trunc, uint32_t, label, uint32_t, id); 102 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC); 103 (*flagsp) |= EFX_DISCARD; 104 105 #if (EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER) 106 /* 107 * Lookout for payload queue ran dry errors and ignore them. 108 * 109 * Sadly for the header/data split cases, the descriptor 110 * pointer in this event refers to the header queue and 111 * therefore cannot be easily detected as duplicate. 112 * So we drop these and rely on the receive processing seeing 113 * a subsequent packet with FSF_AZ_RX_EV_SOP set to discard 114 * the partially received packet. 115 */ 116 if ((EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) == 0) && 117 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) == 0) && 118 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT) == 0)) 119 ignore = B_TRUE; 120 #endif /* EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER */ 121 } 122 123 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_ETH_CRC_ERR) != 0) { 124 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR); 125 EFSYS_PROBE(crc_err); 126 (*flagsp) &= ~EFX_ADDR_MISMATCH; 127 (*flagsp) |= EFX_DISCARD; 128 } 129 130 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PAUSE_FRM_ERR) != 0) { 131 EFX_EV_QSTAT_INCR(eep, EV_RX_PAUSE_FRM_ERR); 132 EFSYS_PROBE(pause_frm_err); 133 (*flagsp) &= ~EFX_ADDR_MISMATCH; 134 (*flagsp) |= EFX_DISCARD; 135 } 136 137 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BUF_OWNER_ID_ERR) != 0) { 138 EFX_EV_QSTAT_INCR(eep, EV_RX_BUF_OWNER_ID_ERR); 139 EFSYS_PROBE(owner_id_err); 140 (*flagsp) |= EFX_DISCARD; 141 } 142 143 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR) != 0) { 144 EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR); 145 EFSYS_PROBE(ipv4_err); 146 (*flagsp) &= ~EFX_CKSUM_IPV4; 147 } 148 149 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR) != 0) { 150 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR); 151 EFSYS_PROBE(udp_chk_err); 152 (*flagsp) &= ~EFX_CKSUM_TCPUDP; 153 } 154 155 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_FRAG_ERR) != 0) { 156 EFX_EV_QSTAT_INCR(eep, EV_RX_IP_FRAG_ERR); 157 158 /* 159 * If IP is fragmented FSF_AZ_RX_EV_IP_FRAG_ERR is set. This 160 * causes FSF_AZ_RX_EV_PKT_OK to be clear. This is not an error 161 * condition. 162 */ 163 (*flagsp) &= ~(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP); 164 } 165 166 return (ignore); 167 } 168 169 static __checkReturn boolean_t 170 efx_ev_rx( 171 __in efx_evq_t *eep, 172 __in efx_qword_t *eqp, 173 __in const efx_ev_callbacks_t *eecp, 174 __in_opt void *arg) 175 { 176 efx_nic_t *enp = eep->ee_enp; 177 uint32_t id; 178 uint32_t size; 179 uint32_t label; 180 boolean_t ok; 181 #if (EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER) 182 boolean_t sop; 183 boolean_t jumbo_cont; 184 #endif /* EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER */ 185 uint32_t hdr_type; 186 boolean_t is_v6; 187 uint16_t flags; 188 boolean_t ignore; 189 boolean_t should_abort; 190 191 EFX_EV_QSTAT_INCR(eep, EV_RX); 192 193 /* Basic packet information */ 194 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_DESC_PTR); 195 size = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT); 196 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_Q_LABEL); 197 ok = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_OK) != 0); 198 199 #if (EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER) 200 sop = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) != 0); 201 jumbo_cont = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) != 0); 202 #endif /* EFSYS_OPT_RX_HDR_SPLIT || EFSYS_OPT_RX_SCATTER */ 203 204 hdr_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_HDR_TYPE); 205 206 is_v6 = (enp->en_family != EFX_FAMILY_FALCON && 207 EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_IPV6_PKT) != 0); 208 209 /* 210 * If packet is marked as OK and packet type is TCP/IP or 211 * UDP/IP or other IP, then we can rely on the hardware checksums. 212 */ 213 switch (hdr_type) { 214 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_TCP: 215 flags = EFX_PKT_TCP | EFX_CKSUM_TCPUDP; 216 if (is_v6) { 217 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6); 218 flags |= EFX_PKT_IPV6; 219 } else { 220 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4); 221 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4; 222 } 223 break; 224 225 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_UDP: 226 flags = EFX_PKT_UDP | EFX_CKSUM_TCPUDP; 227 if (is_v6) { 228 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6); 229 flags |= EFX_PKT_IPV6; 230 } else { 231 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4); 232 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4; 233 } 234 break; 235 236 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_OTHER: 237 if (is_v6) { 238 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6); 239 flags = EFX_PKT_IPV6; 240 } else { 241 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4); 242 flags = EFX_PKT_IPV4 | EFX_CKSUM_IPV4; 243 } 244 break; 245 246 case FSE_AZ_RX_EV_HDR_TYPE_OTHER: 247 EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP); 248 flags = 0; 249 break; 250 251 default: 252 EFSYS_ASSERT(B_FALSE); 253 flags = 0; 254 break; 255 } 256 257 #if EFSYS_OPT_RX_SCATTER || EFSYS_OPT_RX_HDR_SPLIT 258 /* Report scatter and header/lookahead split buffer flags */ 259 if (sop) 260 flags |= EFX_PKT_START; 261 if (jumbo_cont) 262 flags |= EFX_PKT_CONT; 263 #endif /* EFSYS_OPT_RX_SCATTER || EFSYS_OPT_RX_HDR_SPLIT */ 264 265 /* Detect errors included in the FSF_AZ_RX_EV_PKT_OK indication */ 266 if (!ok) { 267 ignore = efx_ev_rx_not_ok(eep, eqp, label, id, &flags); 268 if (ignore) { 269 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id, 270 uint32_t, size, uint16_t, flags); 271 272 return (B_FALSE); 273 } 274 } 275 276 /* If we're not discarding the packet then it is ok */ 277 if (~flags & EFX_DISCARD) 278 EFX_EV_QSTAT_INCR(eep, EV_RX_OK); 279 280 /* Detect multicast packets that didn't match the filter */ 281 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_PKT) != 0) { 282 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_PKT); 283 284 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_HASH_MATCH) != 0) { 285 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_HASH_MATCH); 286 } else { 287 EFSYS_PROBE(mcast_mismatch); 288 flags |= EFX_ADDR_MISMATCH; 289 } 290 } else { 291 flags |= EFX_PKT_UNICAST; 292 } 293 294 /* 295 * The packet parser in Siena can abort parsing packets under 296 * certain error conditions, setting the PKT_NOT_PARSED bit 297 * (which clears PKT_OK). If this is set, then don't trust 298 * the PKT_TYPE field. 299 */ 300 if (enp->en_family != EFX_FAMILY_FALCON && !ok) { 301 uint32_t parse_err; 302 303 parse_err = EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_PKT_NOT_PARSED); 304 if (parse_err != 0) 305 flags |= EFX_CHECK_VLAN; 306 } 307 308 if (~flags & EFX_CHECK_VLAN) { 309 uint32_t pkt_type; 310 311 pkt_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_TYPE); 312 if (pkt_type >= FSE_AZ_RX_EV_PKT_TYPE_VLAN) 313 flags |= EFX_PKT_VLAN_TAGGED; 314 } 315 316 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id, 317 uint32_t, size, uint16_t, flags); 318 319 EFSYS_ASSERT(eecp->eec_rx != NULL); 320 should_abort = eecp->eec_rx(arg, label, id, size, flags); 321 322 return (should_abort); 323 } 324 325 static __checkReturn boolean_t 326 efx_ev_tx( 327 __in efx_evq_t *eep, 328 __in efx_qword_t *eqp, 329 __in const efx_ev_callbacks_t *eecp, 330 __in_opt void *arg) 331 { 332 uint32_t id; 333 uint32_t label; 334 boolean_t should_abort; 335 336 EFX_EV_QSTAT_INCR(eep, EV_TX); 337 338 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0 && 339 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) == 0 && 340 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) == 0 && 341 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) == 0) { 342 343 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_DESC_PTR); 344 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_Q_LABEL); 345 346 EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id); 347 348 EFSYS_ASSERT(eecp->eec_tx != NULL); 349 should_abort = eecp->eec_tx(arg, label, id); 350 351 return (should_abort); 352 } 353 354 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0) 355 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index, 356 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1), 357 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0)); 358 359 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) != 0) 360 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_ERR); 361 362 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) != 0) 363 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_TOO_BIG); 364 365 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) != 0) 366 EFX_EV_QSTAT_INCR(eep, EV_TX_WQ_FF_FULL); 367 368 EFX_EV_QSTAT_INCR(eep, EV_TX_UNEXPECTED); 369 return (B_FALSE); 370 } 371 372 static __checkReturn boolean_t 373 efx_ev_global( 374 __in efx_evq_t *eep, 375 __in efx_qword_t *eqp, 376 __in const efx_ev_callbacks_t *eecp, 377 __in_opt void *arg) 378 { 379 efx_nic_t *enp = eep->ee_enp; 380 efx_port_t *epp = &(enp->en_port); 381 boolean_t should_abort; 382 383 EFX_EV_QSTAT_INCR(eep, EV_GLOBAL); 384 should_abort = B_FALSE; 385 386 /* Check for a link management event */ 387 if (EFX_QWORD_FIELD(*eqp, FSF_BZ_GLB_EV_XG_MNT_INTR) != 0) { 388 EFX_EV_QSTAT_INCR(eep, EV_GLOBAL_MNT); 389 390 EFSYS_PROBE(xg_mgt); 391 392 epp->ep_mac_poll_needed = B_TRUE; 393 } 394 395 return (should_abort); 396 } 397 398 static __checkReturn boolean_t 399 efx_ev_driver( 400 __in efx_evq_t *eep, 401 __in efx_qword_t *eqp, 402 __in const efx_ev_callbacks_t *eecp, 403 __in_opt void *arg) 404 { 405 boolean_t should_abort; 406 407 EFX_EV_QSTAT_INCR(eep, EV_DRIVER); 408 should_abort = B_FALSE; 409 410 switch (EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBCODE)) { 411 case FSE_AZ_TX_DESCQ_FLS_DONE_EV: { 412 uint32_t txq_index; 413 414 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE); 415 416 txq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA); 417 418 EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index); 419 420 EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL); 421 should_abort = eecp->eec_txq_flush_done(arg, txq_index); 422 423 break; 424 } 425 case FSE_AZ_RX_DESCQ_FLS_DONE_EV: { 426 uint32_t rxq_index; 427 uint32_t failed; 428 429 rxq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_DESCQ_ID); 430 failed = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL); 431 432 EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL); 433 EFSYS_ASSERT(eecp->eec_rxq_flush_failed != NULL); 434 435 if (failed) { 436 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_FAILED); 437 438 EFSYS_PROBE1(rx_descq_fls_failed, uint32_t, rxq_index); 439 440 should_abort = eecp->eec_rxq_flush_failed(arg, rxq_index); 441 } else { 442 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE); 443 444 EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index); 445 446 should_abort = eecp->eec_rxq_flush_done(arg, rxq_index); 447 } 448 449 break; 450 } 451 case FSE_AZ_EVQ_INIT_DONE_EV: 452 EFSYS_ASSERT(eecp->eec_initialized != NULL); 453 should_abort = eecp->eec_initialized(arg); 454 455 break; 456 457 case FSE_AZ_EVQ_NOT_EN_EV: 458 EFSYS_PROBE(evq_not_en); 459 break; 460 461 case FSE_AZ_SRM_UPD_DONE_EV: { 462 uint32_t code; 463 464 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_SRM_UPD_DONE); 465 466 code = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA); 467 468 EFSYS_ASSERT(eecp->eec_sram != NULL); 469 should_abort = eecp->eec_sram(arg, code); 470 471 break; 472 } 473 case FSE_AZ_WAKE_UP_EV: { 474 uint32_t id; 475 476 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA); 477 478 EFSYS_ASSERT(eecp->eec_wake_up != NULL); 479 should_abort = eecp->eec_wake_up(arg, id); 480 481 break; 482 } 483 case FSE_AZ_TX_PKT_NON_TCP_UDP: 484 EFSYS_PROBE(tx_pkt_non_tcp_udp); 485 break; 486 487 case FSE_AZ_TIMER_EV: { 488 uint32_t id; 489 490 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA); 491 492 EFSYS_ASSERT(eecp->eec_timer != NULL); 493 should_abort = eecp->eec_timer(arg, id); 494 495 break; 496 } 497 case FSE_AZ_RX_DSC_ERROR_EV: 498 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DSC_ERROR); 499 500 EFSYS_PROBE(rx_dsc_error); 501 502 EFSYS_ASSERT(eecp->eec_exception != NULL); 503 should_abort = eecp->eec_exception(arg, 504 EFX_EXCEPTION_RX_DSC_ERROR, 0); 505 506 break; 507 508 case FSE_AZ_TX_DSC_ERROR_EV: 509 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DSC_ERROR); 510 511 EFSYS_PROBE(tx_dsc_error); 512 513 EFSYS_ASSERT(eecp->eec_exception != NULL); 514 should_abort = eecp->eec_exception(arg, 515 EFX_EXCEPTION_TX_DSC_ERROR, 0); 516 517 break; 518 519 default: 520 break; 521 } 522 523 return (should_abort); 524 } 525 526 static __checkReturn boolean_t 527 efx_ev_drv_gen( 528 __in efx_evq_t *eep, 529 __in efx_qword_t *eqp, 530 __in const efx_ev_callbacks_t *eecp, 531 __in_opt void *arg) 532 { 533 uint32_t data; 534 boolean_t should_abort; 535 536 EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN); 537 538 data = EFX_QWORD_FIELD(*eqp, FSF_AZ_EV_DATA_DW0); 539 if (data >= ((uint32_t)1 << 16)) { 540 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index, 541 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1), 542 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0)); 543 return (B_TRUE); 544 } 545 546 EFSYS_ASSERT(eecp->eec_software != NULL); 547 should_abort = eecp->eec_software(arg, (uint16_t)data); 548 549 return (should_abort); 550 } 551 552 #if EFSYS_OPT_MCDI 553 554 static __checkReturn boolean_t 555 efx_ev_mcdi( 556 __in efx_evq_t *eep, 557 __in efx_qword_t *eqp, 558 __in const efx_ev_callbacks_t *eecp, 559 __in_opt void *arg) 560 { 561 efx_nic_t *enp = eep->ee_enp; 562 unsigned code; 563 boolean_t should_abort = B_FALSE; 564 565 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA); 566 567 if (enp->en_family != EFX_FAMILY_SIENA) 568 goto out; 569 570 EFSYS_ASSERT(eecp->eec_link_change != NULL); 571 EFSYS_ASSERT(eecp->eec_exception != NULL); 572 #if EFSYS_OPT_MON_STATS 573 EFSYS_ASSERT(eecp->eec_monitor != NULL); 574 #endif 575 576 EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE); 577 578 code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE); 579 switch (code) { 580 case MCDI_EVENT_CODE_BADSSERT: 581 efx_mcdi_ev_death(enp, EINTR); 582 break; 583 584 case MCDI_EVENT_CODE_CMDDONE: 585 efx_mcdi_ev_cpl(enp, 586 MCDI_EV_FIELD(eqp, CMDDONE_SEQ), 587 MCDI_EV_FIELD(eqp, CMDDONE_DATALEN), 588 MCDI_EV_FIELD(eqp, CMDDONE_ERRNO)); 589 break; 590 591 case MCDI_EVENT_CODE_LINKCHANGE: { 592 efx_link_mode_t link_mode; 593 594 siena_phy_link_ev(enp, eqp, &link_mode); 595 should_abort = eecp->eec_link_change(arg, link_mode); 596 break; 597 } 598 case MCDI_EVENT_CODE_SENSOREVT: { 599 #if EFSYS_OPT_MON_STATS 600 efx_mon_stat_t id; 601 efx_mon_stat_value_t value; 602 int rc; 603 604 if ((rc = siena_mon_ev(enp, eqp, &id, &value)) == 0) 605 should_abort = eecp->eec_monitor(arg, id, value); 606 else if (rc == ENOTSUP) { 607 should_abort = eecp->eec_exception(arg, 608 EFX_EXCEPTION_UNKNOWN_SENSOREVT, 609 MCDI_EV_FIELD(eqp, DATA)); 610 } else 611 EFSYS_ASSERT(rc == ENODEV); /* Wrong port */ 612 #else 613 should_abort = B_FALSE; 614 #endif 615 break; 616 } 617 case MCDI_EVENT_CODE_SCHEDERR: 618 /* Informational only */ 619 break; 620 621 case MCDI_EVENT_CODE_REBOOT: 622 efx_mcdi_ev_death(enp, EIO); 623 break; 624 625 case MCDI_EVENT_CODE_MAC_STATS_DMA: 626 #if EFSYS_OPT_MAC_STATS 627 if (eecp->eec_mac_stats != NULL) { 628 eecp->eec_mac_stats(arg, 629 MCDI_EV_FIELD(eqp, MAC_STATS_DMA_GENERATION)); 630 } 631 #endif 632 break; 633 634 case MCDI_EVENT_CODE_FWALERT: { 635 uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON); 636 637 if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS) 638 should_abort = eecp->eec_exception(arg, 639 EFX_EXCEPTION_FWALERT_SRAM, 640 MCDI_EV_FIELD(eqp, FWALERT_DATA)); 641 else 642 should_abort = eecp->eec_exception(arg, 643 EFX_EXCEPTION_UNKNOWN_FWALERT, 644 MCDI_EV_FIELD(eqp, DATA)); 645 break; 646 } 647 648 default: 649 EFSYS_PROBE1(mc_pcol_error, int, code); 650 break; 651 } 652 653 out: 654 return (should_abort); 655 } 656 657 #endif /* EFSYS_OPT_MCDI */ 658 659 __checkReturn int 660 efx_ev_qprime( 661 __in efx_evq_t *eep, 662 __in unsigned int count) 663 { 664 efx_nic_t *enp = eep->ee_enp; 665 uint32_t rptr; 666 efx_dword_t dword; 667 int rc; 668 669 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 670 671 if (!(enp->en_mod_flags & EFX_MOD_INTR)) { 672 rc = EINVAL; 673 goto fail1; 674 } 675 676 rptr = count & eep->ee_mask; 677 678 EFX_POPULATE_DWORD_1(dword, FRF_AZ_EVQ_RPTR, rptr); 679 680 EFX_BAR_TBL_WRITED(enp, FR_AZ_EVQ_RPTR_REG, eep->ee_index, 681 &dword, B_FALSE); 682 683 return (0); 684 685 fail1: 686 EFSYS_PROBE1(fail1, int, rc); 687 688 return (rc); 689 } 690 691 __checkReturn boolean_t 692 efx_ev_qpending( 693 __in efx_evq_t *eep, 694 __in unsigned int count) 695 { 696 size_t offset; 697 efx_qword_t qword; 698 699 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 700 701 offset = (count & eep->ee_mask) * sizeof (efx_qword_t); 702 EFSYS_MEM_READQ(eep->ee_esmp, offset, &qword); 703 704 return (EFX_QWORD_FIELD(qword, EFX_DWORD_0) != 0xffffffff && 705 EFX_QWORD_FIELD(qword, EFX_DWORD_1) != 0xffffffff); 706 } 707 708 #if EFSYS_OPT_EV_PREFETCH 709 710 void 711 efx_ev_qprefetch( 712 __in efx_evq_t *eep, 713 __in unsigned int count) 714 { 715 unsigned int offset; 716 717 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 718 719 offset = (count & eep->ee_mask) * sizeof (efx_qword_t); 720 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset); 721 } 722 723 #endif /* EFSYS_OPT_EV_PREFETCH */ 724 725 #define EFX_EV_BATCH 8 726 727 #define EFX_EV_PRESENT(_qword) \ 728 (EFX_QWORD_FIELD((_qword), EFX_DWORD_0) != 0xffffffff && \ 729 EFX_QWORD_FIELD((_qword), EFX_DWORD_1) != 0xffffffff) 730 731 void 732 efx_ev_qpoll( 733 __in efx_evq_t *eep, 734 __inout unsigned int *countp, 735 __in const efx_ev_callbacks_t *eecp, 736 __in_opt void *arg) 737 { 738 efx_qword_t ev[EFX_EV_BATCH]; 739 unsigned int batch; 740 unsigned int total; 741 unsigned int count; 742 unsigned int index; 743 size_t offset; 744 745 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 746 EFSYS_ASSERT(countp != NULL); 747 EFSYS_ASSERT(eecp != NULL); 748 749 count = *countp; 750 do { 751 /* Read up until the end of the batch period */ 752 batch = EFX_EV_BATCH - (count & (EFX_EV_BATCH - 1)); 753 offset = (count & eep->ee_mask) * sizeof (efx_qword_t); 754 for (total = 0; total < batch; ++total) { 755 EFSYS_MEM_READQ(eep->ee_esmp, offset, &(ev[total])); 756 757 if (!EFX_EV_PRESENT(ev[total])) 758 break; 759 760 EFSYS_PROBE3(event, unsigned int, eep->ee_index, 761 uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_1), 762 uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_0)); 763 764 offset += sizeof (efx_qword_t); 765 } 766 767 #if EFSYS_OPT_EV_PREFETCH && (EFSYS_OPT_EV_PREFETCH_PERIOD > 1) 768 /* 769 * Prefetch the next batch when we get within PREFETCH_PERIOD 770 * of a completed batch. If the batch is smaller, then prefetch 771 * immediately. 772 */ 773 if (total == batch && total < EFSYS_OPT_EV_PREFETCH_PERIOD) 774 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset); 775 #endif /* EFSYS_OPT_EV_PREFETCH */ 776 777 /* Process the batch of events */ 778 for (index = 0; index < total; ++index) { 779 boolean_t should_abort; 780 uint32_t code; 781 efx_ev_handler_t handler; 782 783 #if EFSYS_OPT_EV_PREFETCH 784 /* Prefetch if we've now reached the batch period */ 785 if (total == batch && 786 index + EFSYS_OPT_EV_PREFETCH_PERIOD == total) { 787 offset = (count + batch) & eep->ee_mask; 788 offset *= sizeof (efx_qword_t); 789 790 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset); 791 } 792 #endif /* EFSYS_OPT_EV_PREFETCH */ 793 794 EFX_EV_QSTAT_INCR(eep, EV_ALL); 795 796 code = EFX_QWORD_FIELD(ev[index], FSF_AZ_EV_CODE); 797 handler = eep->ee_handler[code]; 798 EFSYS_ASSERT(handler != NULL); 799 should_abort = handler(eep, &(ev[index]), eecp, arg); 800 if (should_abort) { 801 /* Ignore subsequent events */ 802 total = index + 1; 803 break; 804 } 805 } 806 807 /* 808 * Now that the hardware has most likely moved onto dma'ing 809 * into the next cache line, clear the processed events. Take 810 * care to only clear out events that we've processed 811 */ 812 EFX_SET_QWORD(ev[0]); 813 offset = (count & eep->ee_mask) * sizeof (efx_qword_t); 814 for (index = 0; index < total; ++index) { 815 EFSYS_MEM_WRITEQ(eep->ee_esmp, offset, &(ev[0])); 816 offset += sizeof (efx_qword_t); 817 } 818 819 count += total; 820 821 } while (total == batch); 822 823 *countp = count; 824 } 825 826 void 827 efx_ev_qpost( 828 __in efx_evq_t *eep, 829 __in uint16_t data) 830 { 831 efx_nic_t *enp = eep->ee_enp; 832 efx_qword_t ev; 833 efx_oword_t oword; 834 835 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 836 837 EFX_POPULATE_QWORD_2(ev, FSF_AZ_EV_CODE, FSE_AZ_EV_CODE_DRV_GEN_EV, 838 FSF_AZ_EV_DATA_DW0, (uint32_t)data); 839 840 EFX_POPULATE_OWORD_3(oword, FRF_AZ_DRV_EV_QID, eep->ee_index, 841 EFX_DWORD_0, EFX_QWORD_FIELD(ev, EFX_DWORD_0), 842 EFX_DWORD_1, EFX_QWORD_FIELD(ev, EFX_DWORD_1)); 843 844 EFX_BAR_WRITEO(enp, FR_AZ_DRV_EV_REG, &oword); 845 } 846 847 __checkReturn int 848 efx_ev_qmoderate( 849 __in efx_evq_t *eep, 850 __in unsigned int us) 851 { 852 efx_nic_t *enp = eep->ee_enp; 853 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 854 unsigned int locked; 855 efx_dword_t dword; 856 int rc; 857 858 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 859 860 if (us > encp->enc_evq_timer_max_us) { 861 rc = EINVAL; 862 goto fail1; 863 } 864 865 /* If the value is zero then disable the timer */ 866 if (us == 0) { 867 if (enp->en_family == EFX_FAMILY_FALCON) 868 EFX_POPULATE_DWORD_2(dword, 869 FRF_AB_TC_TIMER_MODE, FFE_AB_TIMER_MODE_DIS, 870 FRF_AB_TC_TIMER_VAL, 0); 871 else 872 EFX_POPULATE_DWORD_2(dword, 873 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS, 874 FRF_CZ_TC_TIMER_VAL, 0); 875 } else { 876 uint32_t timer_val; 877 878 /* Calculate the timer value in quanta */ 879 timer_val = us * 1000 / encp->enc_evq_timer_quantum_ns; 880 881 /* Moderation value is base 0 so we need to deduct 1 */ 882 if (timer_val > 0) 883 timer_val--; 884 885 if (enp->en_family == EFX_FAMILY_FALCON) 886 EFX_POPULATE_DWORD_2(dword, 887 FRF_AB_TC_TIMER_MODE, FFE_AB_TIMER_MODE_INT_HLDOFF, 888 FRF_AB_TIMER_VAL, timer_val); 889 else 890 EFX_POPULATE_DWORD_2(dword, 891 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_INT_HLDOFF, 892 FRF_CZ_TC_TIMER_VAL, timer_val); 893 } 894 895 locked = (eep->ee_index == 0) ? 1 : 0; 896 897 EFX_BAR_TBL_WRITED(enp, FR_BZ_TIMER_COMMAND_REGP0, 898 eep->ee_index, &dword, locked); 899 900 return (0); 901 902 fail1: 903 EFSYS_PROBE1(fail1, int, rc); 904 905 return (rc); 906 } 907 908 __checkReturn int 909 efx_ev_qcreate( 910 __in efx_nic_t *enp, 911 __in unsigned int index, 912 __in efsys_mem_t *esmp, 913 __in size_t n, 914 __in uint32_t id, 915 __deref_out efx_evq_t **eepp) 916 { 917 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 918 uint32_t size; 919 efx_evq_t *eep; 920 efx_oword_t oword; 921 int rc; 922 923 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 924 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV); 925 926 EFSYS_ASSERT3U(enp->en_ev_qcount + 1, <, encp->enc_evq_limit); 927 928 if (!ISP2(n) || !(n & EFX_EVQ_NEVS_MASK)) { 929 rc = EINVAL; 930 goto fail1; 931 } 932 if (index >= encp->enc_evq_limit) { 933 rc = EINVAL; 934 goto fail2; 935 } 936 #if EFSYS_OPT_RX_SCALE 937 if (enp->en_intr.ei_type == EFX_INTR_LINE && 938 index >= EFX_MAXRSS_LEGACY) { 939 rc = EINVAL; 940 goto fail3; 941 } 942 #endif 943 for (size = 0; (1 << size) <= (EFX_EVQ_MAXNEVS / EFX_EVQ_MINNEVS); 944 size++) 945 if ((1 << size) == (int)(n / EFX_EVQ_MINNEVS)) 946 break; 947 if (id + (1 << size) >= encp->enc_buftbl_limit) { 948 rc = EINVAL; 949 goto fail4; 950 } 951 952 /* Allocate an EVQ object */ 953 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep); 954 if (eep == NULL) { 955 rc = ENOMEM; 956 goto fail5; 957 } 958 959 eep->ee_magic = EFX_EVQ_MAGIC; 960 eep->ee_enp = enp; 961 eep->ee_index = index; 962 eep->ee_mask = n - 1; 963 eep->ee_esmp = esmp; 964 965 /* Set up the handler table */ 966 eep->ee_handler[FSE_AZ_EV_CODE_RX_EV] = efx_ev_rx; 967 eep->ee_handler[FSE_AZ_EV_CODE_TX_EV] = efx_ev_tx; 968 eep->ee_handler[FSE_AZ_EV_CODE_DRIVER_EV] = efx_ev_driver; 969 eep->ee_handler[FSE_AZ_EV_CODE_GLOBAL_EV] = efx_ev_global; 970 eep->ee_handler[FSE_AZ_EV_CODE_DRV_GEN_EV] = efx_ev_drv_gen; 971 #if EFSYS_OPT_MCDI 972 eep->ee_handler[FSE_AZ_EV_CODE_MCDI_EVRESPONSE] = efx_ev_mcdi; 973 #endif /* EFSYS_OPT_MCDI */ 974 975 /* Set up the new event queue */ 976 if (enp->en_family != EFX_FAMILY_FALCON) { 977 EFX_POPULATE_OWORD_1(oword, FRF_CZ_TIMER_Q_EN, 1); 978 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, index, &oword); 979 } 980 981 EFX_POPULATE_OWORD_3(oword, FRF_AZ_EVQ_EN, 1, FRF_AZ_EVQ_SIZE, size, 982 FRF_AZ_EVQ_BUF_BASE_ID, id); 983 984 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword); 985 986 enp->en_ev_qcount++; 987 *eepp = eep; 988 return (0); 989 990 fail5: 991 EFSYS_PROBE(fail5); 992 fail4: 993 EFSYS_PROBE(fail4); 994 #if EFSYS_OPT_RX_SCALE 995 fail3: 996 EFSYS_PROBE(fail3); 997 #endif 998 fail2: 999 EFSYS_PROBE(fail2); 1000 fail1: 1001 EFSYS_PROBE1(fail1, int, rc); 1002 1003 return (rc); 1004 } 1005 1006 #if EFSYS_OPT_QSTATS 1007 #if EFSYS_OPT_NAMES 1008 /* START MKCONFIG GENERATED EfxEventQueueStatNamesBlock 67e9bdcd920059bd */ 1009 static const char __cs * __cs __efx_ev_qstat_name[] = { 1010 "all", 1011 "rx", 1012 "rx_ok", 1013 "rx_recovery", 1014 "rx_frm_trunc", 1015 "rx_tobe_disc", 1016 "rx_pause_frm_err", 1017 "rx_buf_owner_id_err", 1018 "rx_ipv4_hdr_chksum_err", 1019 "rx_tcp_udp_chksum_err", 1020 "rx_eth_crc_err", 1021 "rx_ip_frag_err", 1022 "rx_mcast_pkt", 1023 "rx_mcast_hash_match", 1024 "rx_tcp_ipv4", 1025 "rx_tcp_ipv6", 1026 "rx_udp_ipv4", 1027 "rx_udp_ipv6", 1028 "rx_other_ipv4", 1029 "rx_other_ipv6", 1030 "rx_non_ip", 1031 "rx_overrun", 1032 "tx", 1033 "tx_wq_ff_full", 1034 "tx_pkt_err", 1035 "tx_pkt_too_big", 1036 "tx_unexpected", 1037 "global", 1038 "global_phy", 1039 "global_mnt", 1040 "global_rx_recovery", 1041 "driver", 1042 "driver_srm_upd_done", 1043 "driver_tx_descq_fls_done", 1044 "driver_rx_descq_fls_done", 1045 "driver_rx_descq_fls_failed", 1046 "driver_rx_dsc_error", 1047 "driver_tx_dsc_error", 1048 "drv_gen", 1049 "mcdi_response", 1050 }; 1051 /* END MKCONFIG GENERATED EfxEventQueueStatNamesBlock */ 1052 1053 const char __cs * 1054 efx_ev_qstat_name( 1055 __in efx_nic_t *enp, 1056 __in unsigned int id) 1057 { 1058 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 1059 EFSYS_ASSERT3U(id, <, EV_NQSTATS); 1060 1061 return (__efx_ev_qstat_name[id]); 1062 } 1063 #endif /* EFSYS_OPT_NAMES */ 1064 #endif /* EFSYS_OPT_QSTATS */ 1065 1066 #if EFSYS_OPT_QSTATS 1067 void 1068 efx_ev_qstats_update( 1069 __in efx_evq_t *eep, 1070 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat) 1071 { 1072 unsigned int id; 1073 1074 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 1075 1076 for (id = 0; id < EV_NQSTATS; id++) { 1077 efsys_stat_t *essp = &stat[id]; 1078 1079 EFSYS_STAT_INCR(essp, eep->ee_stat[id]); 1080 eep->ee_stat[id] = 0; 1081 } 1082 } 1083 #endif /* EFSYS_OPT_QSTATS */ 1084 1085 void 1086 efx_ev_qdestroy( 1087 __in efx_evq_t *eep) 1088 { 1089 efx_nic_t *enp = eep->ee_enp; 1090 efx_oword_t oword; 1091 1092 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC); 1093 1094 EFSYS_ASSERT(enp->en_ev_qcount != 0); 1095 --enp->en_ev_qcount; 1096 1097 /* Purge event queue */ 1098 EFX_ZERO_OWORD(oword); 1099 1100 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, 1101 eep->ee_index, &oword); 1102 1103 if (enp->en_family != EFX_FAMILY_FALCON) { 1104 EFX_ZERO_OWORD(oword); 1105 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, 1106 eep->ee_index, &oword); 1107 } 1108 1109 /* Free the EVQ object */ 1110 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep); 1111 } 1112 1113 void 1114 efx_ev_fini( 1115 __in efx_nic_t *enp) 1116 { 1117 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 1118 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR); 1119 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV); 1120 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX)); 1121 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX)); 1122 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0); 1123 1124 enp->en_mod_flags &= ~EFX_MOD_EV; 1125 } 1126