1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2013-2016 Qlogic Corporation 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* 31 * File: ql_hw.c 32 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656. 33 * Content: Contains Hardware dependent functions 34 */ 35 36 #include <sys/cdefs.h> 37 __FBSDID("$FreeBSD$"); 38 39 #include "ql_os.h" 40 #include "ql_hw.h" 41 #include "ql_def.h" 42 #include "ql_inline.h" 43 #include "ql_ver.h" 44 #include "ql_glbl.h" 45 #include "ql_dbg.h" 46 #include "ql_minidump.h" 47 48 /* 49 * Static Functions 50 */ 51 52 static void qla_del_rcv_cntxt(qla_host_t *ha); 53 static int qla_init_rcv_cntxt(qla_host_t *ha); 54 static int qla_del_xmt_cntxt(qla_host_t *ha); 55 static int qla_init_xmt_cntxt(qla_host_t *ha); 56 static int qla_mbx_cmd(qla_host_t *ha, uint32_t *h_mbox, uint32_t n_hmbox, 57 uint32_t *fw_mbox, uint32_t n_fwmbox, uint32_t no_pause); 58 static int qla_config_intr_cntxt(qla_host_t *ha, uint32_t start_idx, 59 uint32_t num_intrs, uint32_t create); 60 static int qla_config_rss(qla_host_t *ha, uint16_t cntxt_id); 61 static int qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id, 62 int tenable, int rcv); 63 static int qla_set_mac_rcv_mode(qla_host_t *ha, uint32_t mode); 64 static int qla_link_event_req(qla_host_t *ha, uint16_t cntxt_id); 65 66 static int qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd, 67 uint8_t *hdr); 68 static int qla_hw_add_all_mcast(qla_host_t *ha); 69 static int qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds); 70 71 static int qla_init_nic_func(qla_host_t *ha); 72 static int qla_stop_nic_func(qla_host_t *ha); 73 static int qla_query_fw_dcbx_caps(qla_host_t *ha); 74 static int qla_set_port_config(qla_host_t *ha, uint32_t cfg_bits); 75 static int qla_get_port_config(qla_host_t *ha, uint32_t *cfg_bits); 76 static int qla_set_cam_search_mode(qla_host_t *ha, uint32_t search_mode); 77 static int qla_get_cam_search_mode(qla_host_t *ha); 78 79 static void ql_minidump_free(qla_host_t *ha); 80 81 #ifdef QL_DBG 82 83 static void 84 qla_stop_pegs(qla_host_t *ha) 85 { 86 uint32_t val = 1; 87 88 ql_rdwr_indreg32(ha, Q8_CRB_PEG_0, &val, 0); 89 ql_rdwr_indreg32(ha, Q8_CRB_PEG_1, &val, 0); 90 ql_rdwr_indreg32(ha, Q8_CRB_PEG_2, &val, 0); 91 ql_rdwr_indreg32(ha, Q8_CRB_PEG_3, &val, 0); 92 ql_rdwr_indreg32(ha, Q8_CRB_PEG_4, &val, 0); 93 device_printf(ha->pci_dev, "%s PEGS HALTED!!!!!\n", __func__); 94 } 95 96 static int 97 qla_sysctl_stop_pegs(SYSCTL_HANDLER_ARGS) 98 { 99 int err, ret = 0; 100 qla_host_t *ha; 101 102 err = sysctl_handle_int(oidp, &ret, 0, req); 103 104 if (err || !req->newptr) 105 return (err); 106 107 if (ret == 1) { 108 ha = (qla_host_t *)arg1; 109 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) == 0) { 110 qla_stop_pegs(ha); 111 QLA_UNLOCK(ha, __func__); 112 } 113 } 114 115 return err; 116 } 117 #endif /* #ifdef QL_DBG */ 118 119 static int 120 qla_validate_set_port_cfg_bit(uint32_t bits) 121 { 122 if ((bits & 0xF) > 1) 123 return (-1); 124 125 if (((bits >> 4) & 0xF) > 2) 126 return (-1); 127 128 if (((bits >> 8) & 0xF) > 2) 129 return (-1); 130 131 return (0); 132 } 133 134 static int 135 qla_sysctl_port_cfg(SYSCTL_HANDLER_ARGS) 136 { 137 int err, ret = 0; 138 qla_host_t *ha; 139 uint32_t cfg_bits; 140 141 err = sysctl_handle_int(oidp, &ret, 0, req); 142 143 if (err || !req->newptr) 144 return (err); 145 146 ha = (qla_host_t *)arg1; 147 148 if ((qla_validate_set_port_cfg_bit((uint32_t)ret) == 0)) { 149 err = qla_get_port_config(ha, &cfg_bits); 150 151 if (err) 152 goto qla_sysctl_set_port_cfg_exit; 153 154 if (ret & 0x1) { 155 cfg_bits |= Q8_PORT_CFG_BITS_DCBX_ENABLE; 156 } else { 157 cfg_bits &= ~Q8_PORT_CFG_BITS_DCBX_ENABLE; 158 } 159 160 ret = ret >> 4; 161 cfg_bits &= ~Q8_PORT_CFG_BITS_PAUSE_CFG_MASK; 162 163 if ((ret & 0xF) == 0) { 164 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_DISABLED; 165 } else if ((ret & 0xF) == 1){ 166 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_STD; 167 } else { 168 cfg_bits |= Q8_PORT_CFG_BITS_PAUSE_PPM; 169 } 170 171 ret = ret >> 4; 172 cfg_bits &= ~Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK; 173 174 if (ret == 0) { 175 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_XMT_RCV; 176 } else if (ret == 1){ 177 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_XMT; 178 } else { 179 cfg_bits |= Q8_PORT_CFG_BITS_STDPAUSE_RCV; 180 } 181 182 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) == 0) { 183 err = qla_set_port_config(ha, cfg_bits); 184 QLA_UNLOCK(ha, __func__); 185 } else { 186 device_printf(ha->pci_dev, "%s: failed\n", __func__); 187 } 188 } else { 189 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) == 0) { 190 err = qla_get_port_config(ha, &cfg_bits); 191 QLA_UNLOCK(ha, __func__); 192 } else { 193 device_printf(ha->pci_dev, "%s: failed\n", __func__); 194 } 195 } 196 197 qla_sysctl_set_port_cfg_exit: 198 return err; 199 } 200 201 static int 202 qla_sysctl_set_cam_search_mode(SYSCTL_HANDLER_ARGS) 203 { 204 int err, ret = 0; 205 qla_host_t *ha; 206 207 err = sysctl_handle_int(oidp, &ret, 0, req); 208 209 if (err || !req->newptr) 210 return (err); 211 212 ha = (qla_host_t *)arg1; 213 214 if ((ret == Q8_HW_CONFIG_CAM_SEARCH_MODE_INTERNAL) || 215 (ret == Q8_HW_CONFIG_CAM_SEARCH_MODE_AUTO)) { 216 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) == 0) { 217 err = qla_set_cam_search_mode(ha, (uint32_t)ret); 218 QLA_UNLOCK(ha, __func__); 219 } else { 220 device_printf(ha->pci_dev, "%s: failed\n", __func__); 221 } 222 223 } else { 224 device_printf(ha->pci_dev, "%s: ret = %d\n", __func__, ret); 225 } 226 227 return (err); 228 } 229 230 static int 231 qla_sysctl_get_cam_search_mode(SYSCTL_HANDLER_ARGS) 232 { 233 int err, ret = 0; 234 qla_host_t *ha; 235 236 err = sysctl_handle_int(oidp, &ret, 0, req); 237 238 if (err || !req->newptr) 239 return (err); 240 241 ha = (qla_host_t *)arg1; 242 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) == 0) { 243 err = qla_get_cam_search_mode(ha); 244 QLA_UNLOCK(ha, __func__); 245 } else { 246 device_printf(ha->pci_dev, "%s: failed\n", __func__); 247 } 248 249 return (err); 250 } 251 252 static void 253 qlnx_add_hw_mac_stats_sysctls(qla_host_t *ha) 254 { 255 struct sysctl_ctx_list *ctx; 256 struct sysctl_oid_list *children; 257 struct sysctl_oid *ctx_oid; 258 259 ctx = device_get_sysctl_ctx(ha->pci_dev); 260 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 261 262 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_hw_mac", 263 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_hw_mac"); 264 children = SYSCTL_CHILDREN(ctx_oid); 265 266 SYSCTL_ADD_QUAD(ctx, children, 267 OID_AUTO, "xmt_frames", 268 CTLFLAG_RD, &ha->hw.mac.xmt_frames, 269 "xmt_frames"); 270 271 SYSCTL_ADD_QUAD(ctx, children, 272 OID_AUTO, "xmt_bytes", 273 CTLFLAG_RD, &ha->hw.mac.xmt_bytes, 274 "xmt_frames"); 275 276 SYSCTL_ADD_QUAD(ctx, children, 277 OID_AUTO, "xmt_mcast_pkts", 278 CTLFLAG_RD, &ha->hw.mac.xmt_mcast_pkts, 279 "xmt_mcast_pkts"); 280 281 SYSCTL_ADD_QUAD(ctx, children, 282 OID_AUTO, "xmt_bcast_pkts", 283 CTLFLAG_RD, &ha->hw.mac.xmt_bcast_pkts, 284 "xmt_bcast_pkts"); 285 286 SYSCTL_ADD_QUAD(ctx, children, 287 OID_AUTO, "xmt_pause_frames", 288 CTLFLAG_RD, &ha->hw.mac.xmt_pause_frames, 289 "xmt_pause_frames"); 290 291 SYSCTL_ADD_QUAD(ctx, children, 292 OID_AUTO, "xmt_cntrl_pkts", 293 CTLFLAG_RD, &ha->hw.mac.xmt_cntrl_pkts, 294 "xmt_cntrl_pkts"); 295 296 SYSCTL_ADD_QUAD(ctx, children, 297 OID_AUTO, "xmt_pkt_lt_64bytes", 298 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_64bytes, 299 "xmt_pkt_lt_64bytes"); 300 301 SYSCTL_ADD_QUAD(ctx, children, 302 OID_AUTO, "xmt_pkt_lt_127bytes", 303 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_127bytes, 304 "xmt_pkt_lt_127bytes"); 305 306 SYSCTL_ADD_QUAD(ctx, children, 307 OID_AUTO, "xmt_pkt_lt_255bytes", 308 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_255bytes, 309 "xmt_pkt_lt_255bytes"); 310 311 SYSCTL_ADD_QUAD(ctx, children, 312 OID_AUTO, "xmt_pkt_lt_511bytes", 313 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_511bytes, 314 "xmt_pkt_lt_511bytes"); 315 316 SYSCTL_ADD_QUAD(ctx, children, 317 OID_AUTO, "xmt_pkt_lt_1023bytes", 318 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_1023bytes, 319 "xmt_pkt_lt_1023bytes"); 320 321 SYSCTL_ADD_QUAD(ctx, children, 322 OID_AUTO, "xmt_pkt_lt_1518bytes", 323 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_lt_1518bytes, 324 "xmt_pkt_lt_1518bytes"); 325 326 SYSCTL_ADD_QUAD(ctx, children, 327 OID_AUTO, "xmt_pkt_gt_1518bytes", 328 CTLFLAG_RD, &ha->hw.mac.xmt_pkt_gt_1518bytes, 329 "xmt_pkt_gt_1518bytes"); 330 331 SYSCTL_ADD_QUAD(ctx, children, 332 OID_AUTO, "rcv_frames", 333 CTLFLAG_RD, &ha->hw.mac.rcv_frames, 334 "rcv_frames"); 335 336 SYSCTL_ADD_QUAD(ctx, children, 337 OID_AUTO, "rcv_bytes", 338 CTLFLAG_RD, &ha->hw.mac.rcv_bytes, 339 "rcv_bytes"); 340 341 SYSCTL_ADD_QUAD(ctx, children, 342 OID_AUTO, "rcv_mcast_pkts", 343 CTLFLAG_RD, &ha->hw.mac.rcv_mcast_pkts, 344 "rcv_mcast_pkts"); 345 346 SYSCTL_ADD_QUAD(ctx, children, 347 OID_AUTO, "rcv_bcast_pkts", 348 CTLFLAG_RD, &ha->hw.mac.rcv_bcast_pkts, 349 "rcv_bcast_pkts"); 350 351 SYSCTL_ADD_QUAD(ctx, children, 352 OID_AUTO, "rcv_pause_frames", 353 CTLFLAG_RD, &ha->hw.mac.rcv_pause_frames, 354 "rcv_pause_frames"); 355 356 SYSCTL_ADD_QUAD(ctx, children, 357 OID_AUTO, "rcv_cntrl_pkts", 358 CTLFLAG_RD, &ha->hw.mac.rcv_cntrl_pkts, 359 "rcv_cntrl_pkts"); 360 361 SYSCTL_ADD_QUAD(ctx, children, 362 OID_AUTO, "rcv_pkt_lt_64bytes", 363 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_64bytes, 364 "rcv_pkt_lt_64bytes"); 365 366 SYSCTL_ADD_QUAD(ctx, children, 367 OID_AUTO, "rcv_pkt_lt_127bytes", 368 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_127bytes, 369 "rcv_pkt_lt_127bytes"); 370 371 SYSCTL_ADD_QUAD(ctx, children, 372 OID_AUTO, "rcv_pkt_lt_255bytes", 373 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_255bytes, 374 "rcv_pkt_lt_255bytes"); 375 376 SYSCTL_ADD_QUAD(ctx, children, 377 OID_AUTO, "rcv_pkt_lt_511bytes", 378 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_511bytes, 379 "rcv_pkt_lt_511bytes"); 380 381 SYSCTL_ADD_QUAD(ctx, children, 382 OID_AUTO, "rcv_pkt_lt_1023bytes", 383 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_1023bytes, 384 "rcv_pkt_lt_1023bytes"); 385 386 SYSCTL_ADD_QUAD(ctx, children, 387 OID_AUTO, "rcv_pkt_lt_1518bytes", 388 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_lt_1518bytes, 389 "rcv_pkt_lt_1518bytes"); 390 391 SYSCTL_ADD_QUAD(ctx, children, 392 OID_AUTO, "rcv_pkt_gt_1518bytes", 393 CTLFLAG_RD, &ha->hw.mac.rcv_pkt_gt_1518bytes, 394 "rcv_pkt_gt_1518bytes"); 395 396 SYSCTL_ADD_QUAD(ctx, children, 397 OID_AUTO, "rcv_len_error", 398 CTLFLAG_RD, &ha->hw.mac.rcv_len_error, 399 "rcv_len_error"); 400 401 SYSCTL_ADD_QUAD(ctx, children, 402 OID_AUTO, "rcv_len_small", 403 CTLFLAG_RD, &ha->hw.mac.rcv_len_small, 404 "rcv_len_small"); 405 406 SYSCTL_ADD_QUAD(ctx, children, 407 OID_AUTO, "rcv_len_large", 408 CTLFLAG_RD, &ha->hw.mac.rcv_len_large, 409 "rcv_len_large"); 410 411 SYSCTL_ADD_QUAD(ctx, children, 412 OID_AUTO, "rcv_jabber", 413 CTLFLAG_RD, &ha->hw.mac.rcv_jabber, 414 "rcv_jabber"); 415 416 SYSCTL_ADD_QUAD(ctx, children, 417 OID_AUTO, "rcv_dropped", 418 CTLFLAG_RD, &ha->hw.mac.rcv_dropped, 419 "rcv_dropped"); 420 421 SYSCTL_ADD_QUAD(ctx, children, 422 OID_AUTO, "fcs_error", 423 CTLFLAG_RD, &ha->hw.mac.fcs_error, 424 "fcs_error"); 425 426 SYSCTL_ADD_QUAD(ctx, children, 427 OID_AUTO, "align_error", 428 CTLFLAG_RD, &ha->hw.mac.align_error, 429 "align_error"); 430 431 SYSCTL_ADD_QUAD(ctx, children, 432 OID_AUTO, "eswitched_frames", 433 CTLFLAG_RD, &ha->hw.mac.eswitched_frames, 434 "eswitched_frames"); 435 436 SYSCTL_ADD_QUAD(ctx, children, 437 OID_AUTO, "eswitched_bytes", 438 CTLFLAG_RD, &ha->hw.mac.eswitched_bytes, 439 "eswitched_bytes"); 440 441 SYSCTL_ADD_QUAD(ctx, children, 442 OID_AUTO, "eswitched_mcast_frames", 443 CTLFLAG_RD, &ha->hw.mac.eswitched_mcast_frames, 444 "eswitched_mcast_frames"); 445 446 SYSCTL_ADD_QUAD(ctx, children, 447 OID_AUTO, "eswitched_bcast_frames", 448 CTLFLAG_RD, &ha->hw.mac.eswitched_bcast_frames, 449 "eswitched_bcast_frames"); 450 451 SYSCTL_ADD_QUAD(ctx, children, 452 OID_AUTO, "eswitched_ucast_frames", 453 CTLFLAG_RD, &ha->hw.mac.eswitched_ucast_frames, 454 "eswitched_ucast_frames"); 455 456 SYSCTL_ADD_QUAD(ctx, children, 457 OID_AUTO, "eswitched_err_free_frames", 458 CTLFLAG_RD, &ha->hw.mac.eswitched_err_free_frames, 459 "eswitched_err_free_frames"); 460 461 SYSCTL_ADD_QUAD(ctx, children, 462 OID_AUTO, "eswitched_err_free_bytes", 463 CTLFLAG_RD, &ha->hw.mac.eswitched_err_free_bytes, 464 "eswitched_err_free_bytes"); 465 466 return; 467 } 468 469 static void 470 qlnx_add_hw_rcv_stats_sysctls(qla_host_t *ha) 471 { 472 struct sysctl_ctx_list *ctx; 473 struct sysctl_oid_list *children; 474 struct sysctl_oid *ctx_oid; 475 476 ctx = device_get_sysctl_ctx(ha->pci_dev); 477 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 478 479 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_hw_rcv", 480 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_hw_rcv"); 481 children = SYSCTL_CHILDREN(ctx_oid); 482 483 SYSCTL_ADD_QUAD(ctx, children, 484 OID_AUTO, "total_bytes", 485 CTLFLAG_RD, &ha->hw.rcv.total_bytes, 486 "total_bytes"); 487 488 SYSCTL_ADD_QUAD(ctx, children, 489 OID_AUTO, "total_pkts", 490 CTLFLAG_RD, &ha->hw.rcv.total_pkts, 491 "total_pkts"); 492 493 SYSCTL_ADD_QUAD(ctx, children, 494 OID_AUTO, "lro_pkt_count", 495 CTLFLAG_RD, &ha->hw.rcv.lro_pkt_count, 496 "lro_pkt_count"); 497 498 SYSCTL_ADD_QUAD(ctx, children, 499 OID_AUTO, "sw_pkt_count", 500 CTLFLAG_RD, &ha->hw.rcv.sw_pkt_count, 501 "sw_pkt_count"); 502 503 SYSCTL_ADD_QUAD(ctx, children, 504 OID_AUTO, "ip_chksum_err", 505 CTLFLAG_RD, &ha->hw.rcv.ip_chksum_err, 506 "ip_chksum_err"); 507 508 SYSCTL_ADD_QUAD(ctx, children, 509 OID_AUTO, "pkts_wo_acntxts", 510 CTLFLAG_RD, &ha->hw.rcv.pkts_wo_acntxts, 511 "pkts_wo_acntxts"); 512 513 SYSCTL_ADD_QUAD(ctx, children, 514 OID_AUTO, "pkts_dropped_no_sds_card", 515 CTLFLAG_RD, &ha->hw.rcv.pkts_dropped_no_sds_card, 516 "pkts_dropped_no_sds_card"); 517 518 SYSCTL_ADD_QUAD(ctx, children, 519 OID_AUTO, "pkts_dropped_no_sds_host", 520 CTLFLAG_RD, &ha->hw.rcv.pkts_dropped_no_sds_host, 521 "pkts_dropped_no_sds_host"); 522 523 SYSCTL_ADD_QUAD(ctx, children, 524 OID_AUTO, "oversized_pkts", 525 CTLFLAG_RD, &ha->hw.rcv.oversized_pkts, 526 "oversized_pkts"); 527 528 SYSCTL_ADD_QUAD(ctx, children, 529 OID_AUTO, "pkts_dropped_no_rds", 530 CTLFLAG_RD, &ha->hw.rcv.pkts_dropped_no_rds, 531 "pkts_dropped_no_rds"); 532 533 SYSCTL_ADD_QUAD(ctx, children, 534 OID_AUTO, "unxpctd_mcast_pkts", 535 CTLFLAG_RD, &ha->hw.rcv.unxpctd_mcast_pkts, 536 "unxpctd_mcast_pkts"); 537 538 SYSCTL_ADD_QUAD(ctx, children, 539 OID_AUTO, "re1_fbq_error", 540 CTLFLAG_RD, &ha->hw.rcv.re1_fbq_error, 541 "re1_fbq_error"); 542 543 SYSCTL_ADD_QUAD(ctx, children, 544 OID_AUTO, "invalid_mac_addr", 545 CTLFLAG_RD, &ha->hw.rcv.invalid_mac_addr, 546 "invalid_mac_addr"); 547 548 SYSCTL_ADD_QUAD(ctx, children, 549 OID_AUTO, "rds_prime_trys", 550 CTLFLAG_RD, &ha->hw.rcv.rds_prime_trys, 551 "rds_prime_trys"); 552 553 SYSCTL_ADD_QUAD(ctx, children, 554 OID_AUTO, "rds_prime_success", 555 CTLFLAG_RD, &ha->hw.rcv.rds_prime_success, 556 "rds_prime_success"); 557 558 SYSCTL_ADD_QUAD(ctx, children, 559 OID_AUTO, "lro_flows_added", 560 CTLFLAG_RD, &ha->hw.rcv.lro_flows_added, 561 "lro_flows_added"); 562 563 SYSCTL_ADD_QUAD(ctx, children, 564 OID_AUTO, "lro_flows_deleted", 565 CTLFLAG_RD, &ha->hw.rcv.lro_flows_deleted, 566 "lro_flows_deleted"); 567 568 SYSCTL_ADD_QUAD(ctx, children, 569 OID_AUTO, "lro_flows_active", 570 CTLFLAG_RD, &ha->hw.rcv.lro_flows_active, 571 "lro_flows_active"); 572 573 SYSCTL_ADD_QUAD(ctx, children, 574 OID_AUTO, "pkts_droped_unknown", 575 CTLFLAG_RD, &ha->hw.rcv.pkts_droped_unknown, 576 "pkts_droped_unknown"); 577 578 SYSCTL_ADD_QUAD(ctx, children, 579 OID_AUTO, "pkts_cnt_oversized", 580 CTLFLAG_RD, &ha->hw.rcv.pkts_cnt_oversized, 581 "pkts_cnt_oversized"); 582 583 return; 584 } 585 586 static void 587 qlnx_add_hw_xmt_stats_sysctls(qla_host_t *ha) 588 { 589 struct sysctl_ctx_list *ctx; 590 struct sysctl_oid_list *children; 591 struct sysctl_oid_list *node_children; 592 struct sysctl_oid *ctx_oid; 593 int i; 594 uint8_t name_str[16]; 595 596 ctx = device_get_sysctl_ctx(ha->pci_dev); 597 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 598 599 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_hw_xmt", 600 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_hw_xmt"); 601 children = SYSCTL_CHILDREN(ctx_oid); 602 603 for (i = 0; i < ha->hw.num_tx_rings; i++) { 604 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str))); 605 snprintf(name_str, sizeof(name_str), "%d", i); 606 607 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str, 608 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, name_str); 609 node_children = SYSCTL_CHILDREN(ctx_oid); 610 611 /* Tx Related */ 612 613 SYSCTL_ADD_QUAD(ctx, node_children, 614 OID_AUTO, "total_bytes", 615 CTLFLAG_RD, &ha->hw.xmt[i].total_bytes, 616 "total_bytes"); 617 618 SYSCTL_ADD_QUAD(ctx, node_children, 619 OID_AUTO, "total_pkts", 620 CTLFLAG_RD, &ha->hw.xmt[i].total_pkts, 621 "total_pkts"); 622 623 SYSCTL_ADD_QUAD(ctx, node_children, 624 OID_AUTO, "errors", 625 CTLFLAG_RD, &ha->hw.xmt[i].errors, 626 "errors"); 627 628 SYSCTL_ADD_QUAD(ctx, node_children, 629 OID_AUTO, "pkts_dropped", 630 CTLFLAG_RD, &ha->hw.xmt[i].pkts_dropped, 631 "pkts_dropped"); 632 633 SYSCTL_ADD_QUAD(ctx, node_children, 634 OID_AUTO, "switch_pkts", 635 CTLFLAG_RD, &ha->hw.xmt[i].switch_pkts, 636 "switch_pkts"); 637 638 SYSCTL_ADD_QUAD(ctx, node_children, 639 OID_AUTO, "num_buffers", 640 CTLFLAG_RD, &ha->hw.xmt[i].num_buffers, 641 "num_buffers"); 642 } 643 644 return; 645 } 646 647 static void 648 qlnx_add_hw_mbx_cmpl_stats_sysctls(qla_host_t *ha) 649 { 650 struct sysctl_ctx_list *ctx; 651 struct sysctl_oid_list *node_children; 652 653 ctx = device_get_sysctl_ctx(ha->pci_dev); 654 node_children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 655 656 SYSCTL_ADD_QUAD(ctx, node_children, 657 OID_AUTO, "mbx_completion_time_lt_200ms", 658 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[0], 659 "mbx_completion_time_lt_200ms"); 660 661 SYSCTL_ADD_QUAD(ctx, node_children, 662 OID_AUTO, "mbx_completion_time_200ms_400ms", 663 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[1], 664 "mbx_completion_time_200ms_400ms"); 665 666 SYSCTL_ADD_QUAD(ctx, node_children, 667 OID_AUTO, "mbx_completion_time_400ms_600ms", 668 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[2], 669 "mbx_completion_time_400ms_600ms"); 670 671 SYSCTL_ADD_QUAD(ctx, node_children, 672 OID_AUTO, "mbx_completion_time_600ms_800ms", 673 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[3], 674 "mbx_completion_time_600ms_800ms"); 675 676 SYSCTL_ADD_QUAD(ctx, node_children, 677 OID_AUTO, "mbx_completion_time_800ms_1000ms", 678 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[4], 679 "mbx_completion_time_800ms_1000ms"); 680 681 SYSCTL_ADD_QUAD(ctx, node_children, 682 OID_AUTO, "mbx_completion_time_1000ms_1200ms", 683 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[5], 684 "mbx_completion_time_1000ms_1200ms"); 685 686 SYSCTL_ADD_QUAD(ctx, node_children, 687 OID_AUTO, "mbx_completion_time_1200ms_1400ms", 688 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[6], 689 "mbx_completion_time_1200ms_1400ms"); 690 691 SYSCTL_ADD_QUAD(ctx, node_children, 692 OID_AUTO, "mbx_completion_time_1400ms_1600ms", 693 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[7], 694 "mbx_completion_time_1400ms_1600ms"); 695 696 SYSCTL_ADD_QUAD(ctx, node_children, 697 OID_AUTO, "mbx_completion_time_1600ms_1800ms", 698 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[8], 699 "mbx_completion_time_1600ms_1800ms"); 700 701 SYSCTL_ADD_QUAD(ctx, node_children, 702 OID_AUTO, "mbx_completion_time_1800ms_2000ms", 703 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[9], 704 "mbx_completion_time_1800ms_2000ms"); 705 706 SYSCTL_ADD_QUAD(ctx, node_children, 707 OID_AUTO, "mbx_completion_time_2000ms_2200ms", 708 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[10], 709 "mbx_completion_time_2000ms_2200ms"); 710 711 SYSCTL_ADD_QUAD(ctx, node_children, 712 OID_AUTO, "mbx_completion_time_2200ms_2400ms", 713 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[11], 714 "mbx_completion_time_2200ms_2400ms"); 715 716 SYSCTL_ADD_QUAD(ctx, node_children, 717 OID_AUTO, "mbx_completion_time_2400ms_2600ms", 718 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[12], 719 "mbx_completion_time_2400ms_2600ms"); 720 721 SYSCTL_ADD_QUAD(ctx, node_children, 722 OID_AUTO, "mbx_completion_time_2600ms_2800ms", 723 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[13], 724 "mbx_completion_time_2600ms_2800ms"); 725 726 SYSCTL_ADD_QUAD(ctx, node_children, 727 OID_AUTO, "mbx_completion_time_2800ms_3000ms", 728 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[14], 729 "mbx_completion_time_2800ms_3000ms"); 730 731 SYSCTL_ADD_QUAD(ctx, node_children, 732 OID_AUTO, "mbx_completion_time_3000ms_4000ms", 733 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[15], 734 "mbx_completion_time_3000ms_4000ms"); 735 736 SYSCTL_ADD_QUAD(ctx, node_children, 737 OID_AUTO, "mbx_completion_time_4000ms_5000ms", 738 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[16], 739 "mbx_completion_time_4000ms_5000ms"); 740 741 SYSCTL_ADD_QUAD(ctx, node_children, 742 OID_AUTO, "mbx_completion_host_mbx_cntrl_timeout", 743 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[17], 744 "mbx_completion_host_mbx_cntrl_timeout"); 745 746 SYSCTL_ADD_QUAD(ctx, node_children, 747 OID_AUTO, "mbx_completion_fw_mbx_cntrl_timeout", 748 CTLFLAG_RD, &ha->hw.mbx_comp_msecs[18], 749 "mbx_completion_fw_mbx_cntrl_timeout"); 750 return; 751 } 752 753 static void 754 qlnx_add_hw_stats_sysctls(qla_host_t *ha) 755 { 756 qlnx_add_hw_mac_stats_sysctls(ha); 757 qlnx_add_hw_rcv_stats_sysctls(ha); 758 qlnx_add_hw_xmt_stats_sysctls(ha); 759 qlnx_add_hw_mbx_cmpl_stats_sysctls(ha); 760 761 return; 762 } 763 764 static void 765 qlnx_add_drvr_sds_stats(qla_host_t *ha) 766 { 767 struct sysctl_ctx_list *ctx; 768 struct sysctl_oid_list *children; 769 struct sysctl_oid_list *node_children; 770 struct sysctl_oid *ctx_oid; 771 int i; 772 uint8_t name_str[16]; 773 774 ctx = device_get_sysctl_ctx(ha->pci_dev); 775 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 776 777 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_drvr_sds", 778 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_drvr_sds"); 779 children = SYSCTL_CHILDREN(ctx_oid); 780 781 for (i = 0; i < ha->hw.num_sds_rings; i++) { 782 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str))); 783 snprintf(name_str, sizeof(name_str), "%d", i); 784 785 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str, 786 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, name_str); 787 node_children = SYSCTL_CHILDREN(ctx_oid); 788 789 SYSCTL_ADD_QUAD(ctx, node_children, 790 OID_AUTO, "intr_count", 791 CTLFLAG_RD, &ha->hw.sds[i].intr_count, 792 "intr_count"); 793 794 SYSCTL_ADD_UINT(ctx, node_children, 795 OID_AUTO, "rx_free", 796 CTLFLAG_RD, &ha->hw.sds[i].rx_free, 797 ha->hw.sds[i].rx_free, "rx_free"); 798 } 799 800 return; 801 } 802 static void 803 qlnx_add_drvr_rds_stats(qla_host_t *ha) 804 { 805 struct sysctl_ctx_list *ctx; 806 struct sysctl_oid_list *children; 807 struct sysctl_oid_list *node_children; 808 struct sysctl_oid *ctx_oid; 809 int i; 810 uint8_t name_str[16]; 811 812 ctx = device_get_sysctl_ctx(ha->pci_dev); 813 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 814 815 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_drvr_rds", 816 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_drvr_rds"); 817 children = SYSCTL_CHILDREN(ctx_oid); 818 819 for (i = 0; i < ha->hw.num_rds_rings; i++) { 820 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str))); 821 snprintf(name_str, sizeof(name_str), "%d", i); 822 823 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str, 824 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, name_str); 825 node_children = SYSCTL_CHILDREN(ctx_oid); 826 827 SYSCTL_ADD_QUAD(ctx, node_children, 828 OID_AUTO, "count", 829 CTLFLAG_RD, &ha->hw.rds[i].count, 830 "count"); 831 832 SYSCTL_ADD_QUAD(ctx, node_children, 833 OID_AUTO, "lro_pkt_count", 834 CTLFLAG_RD, &ha->hw.rds[i].lro_pkt_count, 835 "lro_pkt_count"); 836 837 SYSCTL_ADD_QUAD(ctx, node_children, 838 OID_AUTO, "lro_bytes", 839 CTLFLAG_RD, &ha->hw.rds[i].lro_bytes, 840 "lro_bytes"); 841 } 842 843 return; 844 } 845 846 static void 847 qlnx_add_drvr_tx_stats(qla_host_t *ha) 848 { 849 struct sysctl_ctx_list *ctx; 850 struct sysctl_oid_list *children; 851 struct sysctl_oid_list *node_children; 852 struct sysctl_oid *ctx_oid; 853 int i; 854 uint8_t name_str[16]; 855 856 ctx = device_get_sysctl_ctx(ha->pci_dev); 857 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev)); 858 859 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats_drvr_xmt", 860 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "stats_drvr_xmt"); 861 children = SYSCTL_CHILDREN(ctx_oid); 862 863 for (i = 0; i < ha->hw.num_tx_rings; i++) { 864 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str))); 865 snprintf(name_str, sizeof(name_str), "%d", i); 866 867 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str, 868 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, name_str); 869 node_children = SYSCTL_CHILDREN(ctx_oid); 870 871 SYSCTL_ADD_QUAD(ctx, node_children, 872 OID_AUTO, "count", 873 CTLFLAG_RD, &ha->tx_ring[i].count, 874 "count"); 875 876 #ifdef QL_ENABLE_ISCSI_TLV 877 SYSCTL_ADD_QUAD(ctx, node_children, 878 OID_AUTO, "iscsi_pkt_count", 879 CTLFLAG_RD, &ha->tx_ring[i].iscsi_pkt_count, 880 "iscsi_pkt_count"); 881 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */ 882 } 883 884 return; 885 } 886 887 static void 888 qlnx_add_drvr_stats_sysctls(qla_host_t *ha) 889 { 890 qlnx_add_drvr_sds_stats(ha); 891 qlnx_add_drvr_rds_stats(ha); 892 qlnx_add_drvr_tx_stats(ha); 893 return; 894 } 895 896 /* 897 * Name: ql_hw_add_sysctls 898 * Function: Add P3Plus specific sysctls 899 */ 900 void 901 ql_hw_add_sysctls(qla_host_t *ha) 902 { 903 device_t dev; 904 905 dev = ha->pci_dev; 906 907 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 908 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 909 OID_AUTO, "num_rds_rings", CTLFLAG_RD, &ha->hw.num_rds_rings, 910 ha->hw.num_rds_rings, "Number of Rcv Descriptor Rings"); 911 912 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 913 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 914 OID_AUTO, "num_sds_rings", CTLFLAG_RD, &ha->hw.num_sds_rings, 915 ha->hw.num_sds_rings, "Number of Status Descriptor Rings"); 916 917 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 918 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 919 OID_AUTO, "num_tx_rings", CTLFLAG_RD, &ha->hw.num_tx_rings, 920 ha->hw.num_tx_rings, "Number of Transmit Rings"); 921 922 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 923 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 924 OID_AUTO, "tx_ring_index", CTLFLAG_RW, &ha->txr_idx, 925 ha->txr_idx, "Tx Ring Used"); 926 927 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 928 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 929 OID_AUTO, "max_tx_segs", CTLFLAG_RD, &ha->hw.max_tx_segs, 930 ha->hw.max_tx_segs, "Max # of Segments in a non-TSO pkt"); 931 932 ha->hw.sds_cidx_thres = 32; 933 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 934 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 935 OID_AUTO, "sds_cidx_thres", CTLFLAG_RW, &ha->hw.sds_cidx_thres, 936 ha->hw.sds_cidx_thres, 937 "Number of SDS entries to process before updating" 938 " SDS Ring Consumer Index"); 939 940 ha->hw.rds_pidx_thres = 32; 941 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 942 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 943 OID_AUTO, "rds_pidx_thres", CTLFLAG_RW, &ha->hw.rds_pidx_thres, 944 ha->hw.rds_pidx_thres, 945 "Number of Rcv Rings Entries to post before updating" 946 " RDS Ring Producer Index"); 947 948 ha->hw.rcv_intr_coalesce = (3 << 16) | 256; 949 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 950 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 951 OID_AUTO, "rcv_intr_coalesce", CTLFLAG_RW, 952 &ha->hw.rcv_intr_coalesce, 953 ha->hw.rcv_intr_coalesce, 954 "Rcv Intr Coalescing Parameters\n" 955 "\tbits 15:0 max packets\n" 956 "\tbits 31:16 max micro-seconds to wait\n" 957 "\tplease run\n" 958 "\tifconfig <if> down && ifconfig <if> up\n" 959 "\tto take effect \n"); 960 961 ha->hw.xmt_intr_coalesce = (64 << 16) | 64; 962 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 963 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 964 OID_AUTO, "xmt_intr_coalesce", CTLFLAG_RW, 965 &ha->hw.xmt_intr_coalesce, 966 ha->hw.xmt_intr_coalesce, 967 "Xmt Intr Coalescing Parameters\n" 968 "\tbits 15:0 max packets\n" 969 "\tbits 31:16 max micro-seconds to wait\n" 970 "\tplease run\n" 971 "\tifconfig <if> down && ifconfig <if> up\n" 972 "\tto take effect \n"); 973 974 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 975 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 976 "port_cfg", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 977 (void *)ha, 0, qla_sysctl_port_cfg, "I", 978 "Set Port Configuration if values below " 979 "otherwise Get Port Configuration\n" 980 "\tBits 0-3 ; 1 = DCBX Enable; 0 = DCBX Disable\n" 981 "\tBits 4-7 : 0 = no pause; 1 = std ; 2 = ppm \n" 982 "\tBits 8-11: std pause cfg; 0 = xmt and rcv;" 983 " 1 = xmt only; 2 = rcv only;\n"); 984 985 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 986 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 987 "set_cam_search_mode", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 988 (void *)ha, 0, qla_sysctl_set_cam_search_mode, "I", 989 "Set CAM Search Mode" 990 "\t 1 = search mode internal\n" 991 "\t 2 = search mode auto\n"); 992 993 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 994 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 995 "get_cam_search_mode", 996 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, (void *)ha, 0, 997 qla_sysctl_get_cam_search_mode, "I", 998 "Get CAM Search Mode" 999 "\t 1 = search mode internal\n" 1000 "\t 2 = search mode auto\n"); 1001 1002 ha->hw.enable_9kb = 1; 1003 1004 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1005 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1006 OID_AUTO, "enable_9kb", CTLFLAG_RW, &ha->hw.enable_9kb, 1007 ha->hw.enable_9kb, "Enable 9Kbyte Buffers when MTU = 9000"); 1008 1009 ha->hw.enable_hw_lro = 1; 1010 1011 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1012 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1013 OID_AUTO, "enable_hw_lro", CTLFLAG_RW, &ha->hw.enable_hw_lro, 1014 ha->hw.enable_hw_lro, "Enable Hardware LRO; Default is true \n" 1015 "\t 1 : Hardware LRO if LRO is enabled\n" 1016 "\t 0 : Software LRO if LRO is enabled\n" 1017 "\t Any change requires ifconfig down/up to take effect\n" 1018 "\t Note that LRO may be turned off/on via ifconfig\n"); 1019 1020 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1021 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1022 OID_AUTO, "sp_log_index", CTLFLAG_RW, &ha->hw.sp_log_index, 1023 ha->hw.sp_log_index, "sp_log_index"); 1024 1025 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1026 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1027 OID_AUTO, "sp_log_stop", CTLFLAG_RW, &ha->hw.sp_log_stop, 1028 ha->hw.sp_log_stop, "sp_log_stop"); 1029 1030 ha->hw.sp_log_stop_events = 0; 1031 1032 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1033 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1034 OID_AUTO, "sp_log_stop_events", CTLFLAG_RW, 1035 &ha->hw.sp_log_stop_events, 1036 ha->hw.sp_log_stop_events, "Slow path event log is stopped" 1037 " when OR of the following events occur \n" 1038 "\t 0x01 : Heart beat Failure\n" 1039 "\t 0x02 : Temperature Failure\n" 1040 "\t 0x04 : HW Initialization Failure\n" 1041 "\t 0x08 : Interface Initialization Failure\n" 1042 "\t 0x10 : Error Recovery Failure\n"); 1043 1044 ha->hw.mdump_active = 0; 1045 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1046 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1047 OID_AUTO, "minidump_active", CTLFLAG_RW, &ha->hw.mdump_active, 1048 ha->hw.mdump_active, 1049 "Minidump retrieval is Active"); 1050 1051 ha->hw.mdump_done = 0; 1052 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1053 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1054 OID_AUTO, "mdump_done", CTLFLAG_RW, 1055 &ha->hw.mdump_done, ha->hw.mdump_done, 1056 "Minidump has been done and available for retrieval"); 1057 1058 ha->hw.mdump_capture_mask = 0xF; 1059 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1060 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1061 OID_AUTO, "minidump_capture_mask", CTLFLAG_RW, 1062 &ha->hw.mdump_capture_mask, ha->hw.mdump_capture_mask, 1063 "Minidump capture mask"); 1064 #ifdef QL_DBG 1065 1066 ha->err_inject = 0; 1067 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1068 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1069 OID_AUTO, "err_inject", 1070 CTLFLAG_RW, &ha->err_inject, ha->err_inject, 1071 "Error to be injected\n" 1072 "\t\t\t 0: No Errors\n" 1073 "\t\t\t 1: rcv: rxb struct invalid\n" 1074 "\t\t\t 2: rcv: mp == NULL\n" 1075 "\t\t\t 3: lro: rxb struct invalid\n" 1076 "\t\t\t 4: lro: mp == NULL\n" 1077 "\t\t\t 5: rcv: num handles invalid\n" 1078 "\t\t\t 6: reg: indirect reg rd_wr failure\n" 1079 "\t\t\t 7: ocm: offchip memory rd_wr failure\n" 1080 "\t\t\t 8: mbx: mailbox command failure\n" 1081 "\t\t\t 9: heartbeat failure\n" 1082 "\t\t\t A: temperature failure\n" 1083 "\t\t\t 11: m_getcl or m_getjcl failure\n" 1084 "\t\t\t 13: Invalid Descriptor Count in SGL Receive\n" 1085 "\t\t\t 14: Invalid Descriptor Count in LRO Receive\n" 1086 "\t\t\t 15: peer port error recovery failure\n" 1087 "\t\t\t 16: tx_buf[next_prod_index].mbuf != NULL\n" ); 1088 1089 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 1090 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, 1091 "peg_stop", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 1092 (void *)ha, 0, qla_sysctl_stop_pegs, "I", "Peg Stop"); 1093 1094 #endif /* #ifdef QL_DBG */ 1095 1096 ha->hw.user_pri_nic = 0; 1097 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1098 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1099 OID_AUTO, "user_pri_nic", CTLFLAG_RW, &ha->hw.user_pri_nic, 1100 ha->hw.user_pri_nic, 1101 "VLAN Tag User Priority for Normal Ethernet Packets"); 1102 1103 ha->hw.user_pri_iscsi = 4; 1104 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev), 1105 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 1106 OID_AUTO, "user_pri_iscsi", CTLFLAG_RW, &ha->hw.user_pri_iscsi, 1107 ha->hw.user_pri_iscsi, 1108 "VLAN Tag User Priority for iSCSI Packets"); 1109 1110 qlnx_add_hw_stats_sysctls(ha); 1111 qlnx_add_drvr_stats_sysctls(ha); 1112 1113 return; 1114 } 1115 1116 void 1117 ql_hw_link_status(qla_host_t *ha) 1118 { 1119 device_printf(ha->pci_dev, "cable_oui\t\t 0x%08x\n", ha->hw.cable_oui); 1120 1121 if (ha->hw.link_up) { 1122 device_printf(ha->pci_dev, "link Up\n"); 1123 } else { 1124 device_printf(ha->pci_dev, "link Down\n"); 1125 } 1126 1127 if (ha->hw.fduplex) { 1128 device_printf(ha->pci_dev, "Full Duplex\n"); 1129 } else { 1130 device_printf(ha->pci_dev, "Half Duplex\n"); 1131 } 1132 1133 if (ha->hw.autoneg) { 1134 device_printf(ha->pci_dev, "Auto Negotiation Enabled\n"); 1135 } else { 1136 device_printf(ha->pci_dev, "Auto Negotiation Disabled\n"); 1137 } 1138 1139 switch (ha->hw.link_speed) { 1140 case 0x710: 1141 device_printf(ha->pci_dev, "link speed\t\t 10Gps\n"); 1142 break; 1143 1144 case 0x3E8: 1145 device_printf(ha->pci_dev, "link speed\t\t 1Gps\n"); 1146 break; 1147 1148 case 0x64: 1149 device_printf(ha->pci_dev, "link speed\t\t 100Mbps\n"); 1150 break; 1151 1152 default: 1153 device_printf(ha->pci_dev, "link speed\t\t Unknown\n"); 1154 break; 1155 } 1156 1157 switch (ha->hw.module_type) { 1158 case 0x01: 1159 device_printf(ha->pci_dev, "Module Type 10GBase-LRM\n"); 1160 break; 1161 1162 case 0x02: 1163 device_printf(ha->pci_dev, "Module Type 10GBase-LR\n"); 1164 break; 1165 1166 case 0x03: 1167 device_printf(ha->pci_dev, "Module Type 10GBase-SR\n"); 1168 break; 1169 1170 case 0x04: 1171 device_printf(ha->pci_dev, 1172 "Module Type 10GE Passive Copper(Compliant)[%d m]\n", 1173 ha->hw.cable_length); 1174 break; 1175 1176 case 0x05: 1177 device_printf(ha->pci_dev, "Module Type 10GE Active" 1178 " Limiting Copper(Compliant)[%d m]\n", 1179 ha->hw.cable_length); 1180 break; 1181 1182 case 0x06: 1183 device_printf(ha->pci_dev, 1184 "Module Type 10GE Passive Copper" 1185 " (Legacy, Best Effort)[%d m]\n", 1186 ha->hw.cable_length); 1187 break; 1188 1189 case 0x07: 1190 device_printf(ha->pci_dev, "Module Type 1000Base-SX\n"); 1191 break; 1192 1193 case 0x08: 1194 device_printf(ha->pci_dev, "Module Type 1000Base-LX\n"); 1195 break; 1196 1197 case 0x09: 1198 device_printf(ha->pci_dev, "Module Type 1000Base-CX\n"); 1199 break; 1200 1201 case 0x0A: 1202 device_printf(ha->pci_dev, "Module Type 1000Base-T\n"); 1203 break; 1204 1205 case 0x0B: 1206 device_printf(ha->pci_dev, "Module Type 1GE Passive Copper" 1207 "(Legacy, Best Effort)\n"); 1208 break; 1209 1210 default: 1211 device_printf(ha->pci_dev, "Unknown Module Type 0x%x\n", 1212 ha->hw.module_type); 1213 break; 1214 } 1215 1216 if (ha->hw.link_faults == 1) 1217 device_printf(ha->pci_dev, "SFP Power Fault\n"); 1218 } 1219 1220 /* 1221 * Name: ql_free_dma 1222 * Function: Frees the DMA'able memory allocated in ql_alloc_dma() 1223 */ 1224 void 1225 ql_free_dma(qla_host_t *ha) 1226 { 1227 uint32_t i; 1228 1229 if (ha->hw.dma_buf.flags.sds_ring) { 1230 for (i = 0; i < ha->hw.num_sds_rings; i++) { 1231 ql_free_dmabuf(ha, &ha->hw.dma_buf.sds_ring[i]); 1232 } 1233 ha->hw.dma_buf.flags.sds_ring = 0; 1234 } 1235 1236 if (ha->hw.dma_buf.flags.rds_ring) { 1237 for (i = 0; i < ha->hw.num_rds_rings; i++) { 1238 ql_free_dmabuf(ha, &ha->hw.dma_buf.rds_ring[i]); 1239 } 1240 ha->hw.dma_buf.flags.rds_ring = 0; 1241 } 1242 1243 if (ha->hw.dma_buf.flags.tx_ring) { 1244 ql_free_dmabuf(ha, &ha->hw.dma_buf.tx_ring); 1245 ha->hw.dma_buf.flags.tx_ring = 0; 1246 } 1247 ql_minidump_free(ha); 1248 } 1249 1250 /* 1251 * Name: ql_alloc_dma 1252 * Function: Allocates DMA'able memory for Tx/Rx Rings, Tx/Rx Contexts. 1253 */ 1254 int 1255 ql_alloc_dma(qla_host_t *ha) 1256 { 1257 device_t dev; 1258 uint32_t i, j, size, tx_ring_size; 1259 qla_hw_t *hw; 1260 qla_hw_tx_cntxt_t *tx_cntxt; 1261 uint8_t *vaddr; 1262 bus_addr_t paddr; 1263 1264 dev = ha->pci_dev; 1265 1266 QL_DPRINT2(ha, (dev, "%s: enter\n", __func__)); 1267 1268 hw = &ha->hw; 1269 /* 1270 * Allocate Transmit Ring 1271 */ 1272 tx_ring_size = (sizeof(q80_tx_cmd_t) * NUM_TX_DESCRIPTORS); 1273 size = (tx_ring_size * ha->hw.num_tx_rings); 1274 1275 hw->dma_buf.tx_ring.alignment = 8; 1276 hw->dma_buf.tx_ring.size = size + PAGE_SIZE; 1277 1278 if (ql_alloc_dmabuf(ha, &hw->dma_buf.tx_ring)) { 1279 device_printf(dev, "%s: tx ring alloc failed\n", __func__); 1280 goto ql_alloc_dma_exit; 1281 } 1282 1283 vaddr = (uint8_t *)hw->dma_buf.tx_ring.dma_b; 1284 paddr = hw->dma_buf.tx_ring.dma_addr; 1285 1286 for (i = 0; i < ha->hw.num_tx_rings; i++) { 1287 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i]; 1288 1289 tx_cntxt->tx_ring_base = (q80_tx_cmd_t *)vaddr; 1290 tx_cntxt->tx_ring_paddr = paddr; 1291 1292 vaddr += tx_ring_size; 1293 paddr += tx_ring_size; 1294 } 1295 1296 for (i = 0; i < ha->hw.num_tx_rings; i++) { 1297 tx_cntxt = (qla_hw_tx_cntxt_t *)&hw->tx_cntxt[i]; 1298 1299 tx_cntxt->tx_cons = (uint32_t *)vaddr; 1300 tx_cntxt->tx_cons_paddr = paddr; 1301 1302 vaddr += sizeof (uint32_t); 1303 paddr += sizeof (uint32_t); 1304 } 1305 1306 ha->hw.dma_buf.flags.tx_ring = 1; 1307 1308 QL_DPRINT2(ha, (dev, "%s: tx_ring phys %p virt %p\n", 1309 __func__, (void *)(hw->dma_buf.tx_ring.dma_addr), 1310 hw->dma_buf.tx_ring.dma_b)); 1311 /* 1312 * Allocate Receive Descriptor Rings 1313 */ 1314 1315 for (i = 0; i < hw->num_rds_rings; i++) { 1316 hw->dma_buf.rds_ring[i].alignment = 8; 1317 hw->dma_buf.rds_ring[i].size = 1318 (sizeof(q80_recv_desc_t)) * NUM_RX_DESCRIPTORS; 1319 1320 if (ql_alloc_dmabuf(ha, &hw->dma_buf.rds_ring[i])) { 1321 device_printf(dev, "%s: rds ring[%d] alloc failed\n", 1322 __func__, i); 1323 1324 for (j = 0; j < i; j++) 1325 ql_free_dmabuf(ha, &hw->dma_buf.rds_ring[j]); 1326 1327 goto ql_alloc_dma_exit; 1328 } 1329 QL_DPRINT4(ha, (dev, "%s: rx_ring[%d] phys %p virt %p\n", 1330 __func__, i, (void *)(hw->dma_buf.rds_ring[i].dma_addr), 1331 hw->dma_buf.rds_ring[i].dma_b)); 1332 } 1333 1334 hw->dma_buf.flags.rds_ring = 1; 1335 1336 /* 1337 * Allocate Status Descriptor Rings 1338 */ 1339 1340 for (i = 0; i < hw->num_sds_rings; i++) { 1341 hw->dma_buf.sds_ring[i].alignment = 8; 1342 hw->dma_buf.sds_ring[i].size = 1343 (sizeof(q80_stat_desc_t)) * NUM_STATUS_DESCRIPTORS; 1344 1345 if (ql_alloc_dmabuf(ha, &hw->dma_buf.sds_ring[i])) { 1346 device_printf(dev, "%s: sds ring alloc failed\n", 1347 __func__); 1348 1349 for (j = 0; j < i; j++) 1350 ql_free_dmabuf(ha, &hw->dma_buf.sds_ring[j]); 1351 1352 goto ql_alloc_dma_exit; 1353 } 1354 QL_DPRINT4(ha, (dev, "%s: sds_ring[%d] phys %p virt %p\n", 1355 __func__, i, 1356 (void *)(hw->dma_buf.sds_ring[i].dma_addr), 1357 hw->dma_buf.sds_ring[i].dma_b)); 1358 } 1359 for (i = 0; i < hw->num_sds_rings; i++) { 1360 hw->sds[i].sds_ring_base = 1361 (q80_stat_desc_t *)hw->dma_buf.sds_ring[i].dma_b; 1362 } 1363 1364 hw->dma_buf.flags.sds_ring = 1; 1365 1366 return 0; 1367 1368 ql_alloc_dma_exit: 1369 ql_free_dma(ha); 1370 return -1; 1371 } 1372 1373 #define Q8_MBX_MSEC_DELAY 5000 1374 1375 static int 1376 qla_mbx_cmd(qla_host_t *ha, uint32_t *h_mbox, uint32_t n_hmbox, 1377 uint32_t *fw_mbox, uint32_t n_fwmbox, uint32_t no_pause) 1378 { 1379 uint32_t i; 1380 uint32_t data; 1381 int ret = 0; 1382 uint64_t start_usecs; 1383 uint64_t end_usecs; 1384 uint64_t msecs_200; 1385 1386 ql_sp_log(ha, 0, 5, no_pause, h_mbox[0], h_mbox[1], h_mbox[2], h_mbox[3]); 1387 1388 if (ha->offline || ha->qla_initiate_recovery) { 1389 ql_sp_log(ha, 1, 2, ha->offline, ha->qla_initiate_recovery, 0, 0, 0); 1390 goto exit_qla_mbx_cmd; 1391 } 1392 1393 if (((ha->err_inject & 0xFFFF) == INJCT_MBX_CMD_FAILURE) && 1394 (((ha->err_inject & ~0xFFFF) == ((h_mbox[0] & 0xFFFF) << 16))|| 1395 !(ha->err_inject & ~0xFFFF))) { 1396 ret = -3; 1397 QL_INITIATE_RECOVERY(ha); 1398 goto exit_qla_mbx_cmd; 1399 } 1400 1401 start_usecs = qla_get_usec_timestamp(); 1402 1403 if (no_pause) 1404 i = 1000; 1405 else 1406 i = Q8_MBX_MSEC_DELAY; 1407 1408 while (i) { 1409 if (ha->qla_initiate_recovery) { 1410 ql_sp_log(ha, 2, 1, ha->qla_initiate_recovery, 0, 0, 0, 0); 1411 return (-1); 1412 } 1413 1414 data = READ_REG32(ha, Q8_HOST_MBOX_CNTRL); 1415 if (data == 0) 1416 break; 1417 if (no_pause) { 1418 DELAY(1000); 1419 } else { 1420 qla_mdelay(__func__, 1); 1421 } 1422 i--; 1423 } 1424 1425 if (i == 0) { 1426 device_printf(ha->pci_dev, "%s: host_mbx_cntrl 0x%08x\n", 1427 __func__, data); 1428 ql_sp_log(ha, 3, 1, data, 0, 0, 0, 0); 1429 ret = -1; 1430 ha->hw.mbx_comp_msecs[(Q8_MBX_COMP_MSECS - 2)]++; 1431 QL_INITIATE_RECOVERY(ha); 1432 goto exit_qla_mbx_cmd; 1433 } 1434 1435 for (i = 0; i < n_hmbox; i++) { 1436 WRITE_REG32(ha, (Q8_HOST_MBOX0 + (i << 2)), *h_mbox); 1437 h_mbox++; 1438 } 1439 1440 WRITE_REG32(ha, Q8_HOST_MBOX_CNTRL, 0x1); 1441 1442 i = Q8_MBX_MSEC_DELAY; 1443 while (i) { 1444 if (ha->qla_initiate_recovery) { 1445 ql_sp_log(ha, 4, 1, ha->qla_initiate_recovery, 0, 0, 0, 0); 1446 return (-1); 1447 } 1448 1449 data = READ_REG32(ha, Q8_FW_MBOX_CNTRL); 1450 1451 if ((data & 0x3) == 1) { 1452 data = READ_REG32(ha, Q8_FW_MBOX0); 1453 if ((data & 0xF000) != 0x8000) 1454 break; 1455 } 1456 if (no_pause) { 1457 DELAY(1000); 1458 } else { 1459 qla_mdelay(__func__, 1); 1460 } 1461 i--; 1462 } 1463 if (i == 0) { 1464 device_printf(ha->pci_dev, "%s: fw_mbx_cntrl 0x%08x\n", 1465 __func__, data); 1466 ql_sp_log(ha, 5, 1, data, 0, 0, 0, 0); 1467 ret = -2; 1468 ha->hw.mbx_comp_msecs[(Q8_MBX_COMP_MSECS - 1)]++; 1469 QL_INITIATE_RECOVERY(ha); 1470 goto exit_qla_mbx_cmd; 1471 } 1472 1473 for (i = 0; i < n_fwmbox; i++) { 1474 if (ha->qla_initiate_recovery) { 1475 ql_sp_log(ha, 6, 1, ha->qla_initiate_recovery, 0, 0, 0, 0); 1476 return (-1); 1477 } 1478 1479 *fw_mbox++ = READ_REG32(ha, (Q8_FW_MBOX0 + (i << 2))); 1480 } 1481 1482 WRITE_REG32(ha, Q8_FW_MBOX_CNTRL, 0x0); 1483 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0); 1484 1485 end_usecs = qla_get_usec_timestamp(); 1486 1487 if (end_usecs > start_usecs) { 1488 msecs_200 = (end_usecs - start_usecs)/(1000 * 200); 1489 1490 if (msecs_200 < 15) 1491 ha->hw.mbx_comp_msecs[msecs_200]++; 1492 else if (msecs_200 < 20) 1493 ha->hw.mbx_comp_msecs[15]++; 1494 else { 1495 device_printf(ha->pci_dev, "%s: [%ld, %ld] %ld\n", __func__, 1496 start_usecs, end_usecs, msecs_200); 1497 ha->hw.mbx_comp_msecs[16]++; 1498 } 1499 } 1500 ql_sp_log(ha, 7, 5, fw_mbox[0], fw_mbox[1], fw_mbox[2], fw_mbox[3], fw_mbox[4]); 1501 1502 exit_qla_mbx_cmd: 1503 return (ret); 1504 } 1505 1506 int 1507 qla_get_nic_partition(qla_host_t *ha, uint32_t *supports_9kb, 1508 uint32_t *num_rcvq) 1509 { 1510 uint32_t *mbox, err; 1511 device_t dev = ha->pci_dev; 1512 1513 bzero(ha->hw.mbox, (sizeof (uint32_t) * Q8_NUM_MBOX)); 1514 1515 mbox = ha->hw.mbox; 1516 1517 mbox[0] = Q8_MBX_GET_NIC_PARTITION | (0x2 << 16) | (0x2 << 29); 1518 1519 if (qla_mbx_cmd(ha, mbox, 2, mbox, 19, 0)) { 1520 device_printf(dev, "%s: failed0\n", __func__); 1521 return (-1); 1522 } 1523 err = mbox[0] >> 25; 1524 1525 if (supports_9kb != NULL) { 1526 if (mbox[16] & 0x80) /* bit 7 of mbox 16 */ 1527 *supports_9kb = 1; 1528 else 1529 *supports_9kb = 0; 1530 } 1531 1532 if (num_rcvq != NULL) 1533 *num_rcvq = ((mbox[6] >> 16) & 0xFFFF); 1534 1535 if ((err != 1) && (err != 0)) { 1536 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 1537 return (-1); 1538 } 1539 return 0; 1540 } 1541 1542 static int 1543 qla_config_intr_cntxt(qla_host_t *ha, uint32_t start_idx, uint32_t num_intrs, 1544 uint32_t create) 1545 { 1546 uint32_t i, err; 1547 device_t dev = ha->pci_dev; 1548 q80_config_intr_t *c_intr; 1549 q80_config_intr_rsp_t *c_intr_rsp; 1550 1551 c_intr = (q80_config_intr_t *)ha->hw.mbox; 1552 bzero(c_intr, (sizeof (q80_config_intr_t))); 1553 1554 c_intr->opcode = Q8_MBX_CONFIG_INTR; 1555 1556 c_intr->count_version = (sizeof (q80_config_intr_t) >> 2); 1557 c_intr->count_version |= Q8_MBX_CMD_VERSION; 1558 1559 c_intr->nentries = num_intrs; 1560 1561 for (i = 0; i < num_intrs; i++) { 1562 if (create) { 1563 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_CREATE; 1564 c_intr->intr[i].msix_index = start_idx + 1 + i; 1565 } else { 1566 c_intr->intr[i].cmd_type = Q8_MBX_CONFIG_INTR_DELETE; 1567 c_intr->intr[i].msix_index = 1568 ha->hw.intr_id[(start_idx + i)]; 1569 } 1570 1571 c_intr->intr[i].cmd_type |= Q8_MBX_CONFIG_INTR_TYPE_MSI_X; 1572 } 1573 1574 if (qla_mbx_cmd(ha, (uint32_t *)c_intr, 1575 (sizeof (q80_config_intr_t) >> 2), 1576 ha->hw.mbox, (sizeof (q80_config_intr_rsp_t) >> 2), 0)) { 1577 device_printf(dev, "%s: %s failed0\n", __func__, 1578 (create ? "create" : "delete")); 1579 return (-1); 1580 } 1581 1582 c_intr_rsp = (q80_config_intr_rsp_t *)ha->hw.mbox; 1583 1584 err = Q8_MBX_RSP_STATUS(c_intr_rsp->regcnt_status); 1585 1586 if (err) { 1587 device_printf(dev, "%s: %s failed1 [0x%08x, %d]\n", __func__, 1588 (create ? "create" : "delete"), err, c_intr_rsp->nentries); 1589 1590 for (i = 0; i < c_intr_rsp->nentries; i++) { 1591 device_printf(dev, "%s: [%d]:[0x%x 0x%x 0x%x]\n", 1592 __func__, i, 1593 c_intr_rsp->intr[i].status, 1594 c_intr_rsp->intr[i].intr_id, 1595 c_intr_rsp->intr[i].intr_src); 1596 } 1597 1598 return (-1); 1599 } 1600 1601 for (i = 0; ((i < num_intrs) && create); i++) { 1602 if (!c_intr_rsp->intr[i].status) { 1603 ha->hw.intr_id[(start_idx + i)] = 1604 c_intr_rsp->intr[i].intr_id; 1605 ha->hw.intr_src[(start_idx + i)] = 1606 c_intr_rsp->intr[i].intr_src; 1607 } 1608 } 1609 1610 return (0); 1611 } 1612 1613 /* 1614 * Name: qla_config_rss 1615 * Function: Configure RSS for the context/interface. 1616 */ 1617 static const uint64_t rss_key[] = { 0xbeac01fa6a42b73bULL, 1618 0x8030f20c77cb2da3ULL, 1619 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL, 1620 0x255b0ec26d5a56daULL }; 1621 1622 static int 1623 qla_config_rss(qla_host_t *ha, uint16_t cntxt_id) 1624 { 1625 q80_config_rss_t *c_rss; 1626 q80_config_rss_rsp_t *c_rss_rsp; 1627 uint32_t err, i; 1628 device_t dev = ha->pci_dev; 1629 1630 c_rss = (q80_config_rss_t *)ha->hw.mbox; 1631 bzero(c_rss, (sizeof (q80_config_rss_t))); 1632 1633 c_rss->opcode = Q8_MBX_CONFIG_RSS; 1634 1635 c_rss->count_version = (sizeof (q80_config_rss_t) >> 2); 1636 c_rss->count_version |= Q8_MBX_CMD_VERSION; 1637 1638 c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP_IP | 1639 Q8_MBX_RSS_HASH_TYPE_IPV6_TCP_IP); 1640 //c_rss->hash_type = (Q8_MBX_RSS_HASH_TYPE_IPV4_TCP | 1641 // Q8_MBX_RSS_HASH_TYPE_IPV6_TCP); 1642 1643 c_rss->flags = Q8_MBX_RSS_FLAGS_ENABLE_RSS; 1644 c_rss->flags |= Q8_MBX_RSS_FLAGS_USE_IND_TABLE; 1645 1646 c_rss->indtbl_mask = Q8_MBX_RSS_INDTBL_MASK; 1647 1648 c_rss->indtbl_mask |= Q8_MBX_RSS_FLAGS_MULTI_RSS_VALID; 1649 c_rss->flags |= Q8_MBX_RSS_FLAGS_TYPE_CRSS; 1650 1651 c_rss->cntxt_id = cntxt_id; 1652 1653 for (i = 0; i < 5; i++) { 1654 c_rss->rss_key[i] = rss_key[i]; 1655 } 1656 1657 if (qla_mbx_cmd(ha, (uint32_t *)c_rss, 1658 (sizeof (q80_config_rss_t) >> 2), 1659 ha->hw.mbox, (sizeof(q80_config_rss_rsp_t) >> 2), 0)) { 1660 device_printf(dev, "%s: failed0\n", __func__); 1661 return (-1); 1662 } 1663 c_rss_rsp = (q80_config_rss_rsp_t *)ha->hw.mbox; 1664 1665 err = Q8_MBX_RSP_STATUS(c_rss_rsp->regcnt_status); 1666 1667 if (err) { 1668 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 1669 return (-1); 1670 } 1671 return 0; 1672 } 1673 1674 static int 1675 qla_set_rss_ind_table(qla_host_t *ha, uint32_t start_idx, uint32_t count, 1676 uint16_t cntxt_id, uint8_t *ind_table) 1677 { 1678 q80_config_rss_ind_table_t *c_rss_ind; 1679 q80_config_rss_ind_table_rsp_t *c_rss_ind_rsp; 1680 uint32_t err; 1681 device_t dev = ha->pci_dev; 1682 1683 if ((count > Q8_RSS_IND_TBL_SIZE) || 1684 ((start_idx + count - 1) > Q8_RSS_IND_TBL_MAX_IDX)) { 1685 device_printf(dev, "%s: illegal count [%d, %d]\n", __func__, 1686 start_idx, count); 1687 return (-1); 1688 } 1689 1690 c_rss_ind = (q80_config_rss_ind_table_t *)ha->hw.mbox; 1691 bzero(c_rss_ind, sizeof (q80_config_rss_ind_table_t)); 1692 1693 c_rss_ind->opcode = Q8_MBX_CONFIG_RSS_TABLE; 1694 c_rss_ind->count_version = (sizeof (q80_config_rss_ind_table_t) >> 2); 1695 c_rss_ind->count_version |= Q8_MBX_CMD_VERSION; 1696 1697 c_rss_ind->start_idx = start_idx; 1698 c_rss_ind->end_idx = start_idx + count - 1; 1699 c_rss_ind->cntxt_id = cntxt_id; 1700 bcopy(ind_table, c_rss_ind->ind_table, count); 1701 1702 if (qla_mbx_cmd(ha, (uint32_t *)c_rss_ind, 1703 (sizeof (q80_config_rss_ind_table_t) >> 2), ha->hw.mbox, 1704 (sizeof(q80_config_rss_ind_table_rsp_t) >> 2), 0)) { 1705 device_printf(dev, "%s: failed0\n", __func__); 1706 return (-1); 1707 } 1708 1709 c_rss_ind_rsp = (q80_config_rss_ind_table_rsp_t *)ha->hw.mbox; 1710 err = Q8_MBX_RSP_STATUS(c_rss_ind_rsp->regcnt_status); 1711 1712 if (err) { 1713 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 1714 return (-1); 1715 } 1716 return 0; 1717 } 1718 1719 /* 1720 * Name: qla_config_intr_coalesce 1721 * Function: Configure Interrupt Coalescing. 1722 */ 1723 static int 1724 qla_config_intr_coalesce(qla_host_t *ha, uint16_t cntxt_id, int tenable, 1725 int rcv) 1726 { 1727 q80_config_intr_coalesc_t *intrc; 1728 q80_config_intr_coalesc_rsp_t *intrc_rsp; 1729 uint32_t err, i; 1730 device_t dev = ha->pci_dev; 1731 1732 intrc = (q80_config_intr_coalesc_t *)ha->hw.mbox; 1733 bzero(intrc, (sizeof (q80_config_intr_coalesc_t))); 1734 1735 intrc->opcode = Q8_MBX_CONFIG_INTR_COALESCE; 1736 intrc->count_version = (sizeof (q80_config_intr_coalesc_t) >> 2); 1737 intrc->count_version |= Q8_MBX_CMD_VERSION; 1738 1739 if (rcv) { 1740 intrc->flags = Q8_MBX_INTRC_FLAGS_RCV; 1741 intrc->max_pkts = ha->hw.rcv_intr_coalesce & 0xFFFF; 1742 intrc->max_mswait = (ha->hw.rcv_intr_coalesce >> 16) & 0xFFFF; 1743 } else { 1744 intrc->flags = Q8_MBX_INTRC_FLAGS_XMT; 1745 intrc->max_pkts = ha->hw.xmt_intr_coalesce & 0xFFFF; 1746 intrc->max_mswait = (ha->hw.xmt_intr_coalesce >> 16) & 0xFFFF; 1747 } 1748 1749 intrc->cntxt_id = cntxt_id; 1750 1751 if (tenable) { 1752 intrc->flags |= Q8_MBX_INTRC_FLAGS_PERIODIC; 1753 intrc->timer_type = Q8_MBX_INTRC_TIMER_PERIODIC; 1754 1755 for (i = 0; i < ha->hw.num_sds_rings; i++) { 1756 intrc->sds_ring_mask |= (1 << i); 1757 } 1758 intrc->ms_timeout = 1000; 1759 } 1760 1761 if (qla_mbx_cmd(ha, (uint32_t *)intrc, 1762 (sizeof (q80_config_intr_coalesc_t) >> 2), 1763 ha->hw.mbox, (sizeof(q80_config_intr_coalesc_rsp_t) >> 2), 0)) { 1764 device_printf(dev, "%s: failed0\n", __func__); 1765 return (-1); 1766 } 1767 intrc_rsp = (q80_config_intr_coalesc_rsp_t *)ha->hw.mbox; 1768 1769 err = Q8_MBX_RSP_STATUS(intrc_rsp->regcnt_status); 1770 1771 if (err) { 1772 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 1773 return (-1); 1774 } 1775 1776 return 0; 1777 } 1778 1779 /* 1780 * Name: qla_config_mac_addr 1781 * Function: binds a MAC address to the context/interface. 1782 * Can be unicast, multicast or broadcast. 1783 */ 1784 static int 1785 qla_config_mac_addr(qla_host_t *ha, uint8_t *mac_addr, uint32_t add_mac, 1786 uint32_t num_mac) 1787 { 1788 q80_config_mac_addr_t *cmac; 1789 q80_config_mac_addr_rsp_t *cmac_rsp; 1790 uint32_t err; 1791 device_t dev = ha->pci_dev; 1792 int i; 1793 uint8_t *mac_cpy = mac_addr; 1794 1795 if (num_mac > Q8_MAX_MAC_ADDRS) { 1796 device_printf(dev, "%s: %s num_mac [0x%x] > Q8_MAX_MAC_ADDRS\n", 1797 __func__, (add_mac ? "Add" : "Del"), num_mac); 1798 return (-1); 1799 } 1800 1801 cmac = (q80_config_mac_addr_t *)ha->hw.mbox; 1802 bzero(cmac, (sizeof (q80_config_mac_addr_t))); 1803 1804 cmac->opcode = Q8_MBX_CONFIG_MAC_ADDR; 1805 cmac->count_version = sizeof (q80_config_mac_addr_t) >> 2; 1806 cmac->count_version |= Q8_MBX_CMD_VERSION; 1807 1808 if (add_mac) 1809 cmac->cmd = Q8_MBX_CMAC_CMD_ADD_MAC_ADDR; 1810 else 1811 cmac->cmd = Q8_MBX_CMAC_CMD_DEL_MAC_ADDR; 1812 1813 cmac->cmd |= Q8_MBX_CMAC_CMD_CAM_INGRESS; 1814 1815 cmac->nmac_entries = num_mac; 1816 cmac->cntxt_id = ha->hw.rcv_cntxt_id; 1817 1818 for (i = 0; i < num_mac; i++) { 1819 bcopy(mac_addr, cmac->mac_addr[i].addr, Q8_ETHER_ADDR_LEN); 1820 mac_addr = mac_addr + ETHER_ADDR_LEN; 1821 } 1822 1823 if (qla_mbx_cmd(ha, (uint32_t *)cmac, 1824 (sizeof (q80_config_mac_addr_t) >> 2), 1825 ha->hw.mbox, (sizeof(q80_config_mac_addr_rsp_t) >> 2), 1)) { 1826 device_printf(dev, "%s: %s failed0\n", __func__, 1827 (add_mac ? "Add" : "Del")); 1828 return (-1); 1829 } 1830 cmac_rsp = (q80_config_mac_addr_rsp_t *)ha->hw.mbox; 1831 1832 err = Q8_MBX_RSP_STATUS(cmac_rsp->regcnt_status); 1833 1834 if (err) { 1835 device_printf(dev, "%s: %s failed1 [0x%08x]\n", __func__, 1836 (add_mac ? "Add" : "Del"), err); 1837 for (i = 0; i < num_mac; i++) { 1838 device_printf(dev, "%s: %02x:%02x:%02x:%02x:%02x:%02x\n", 1839 __func__, mac_cpy[0], mac_cpy[1], mac_cpy[2], 1840 mac_cpy[3], mac_cpy[4], mac_cpy[5]); 1841 mac_cpy += ETHER_ADDR_LEN; 1842 } 1843 return (-1); 1844 } 1845 1846 return 0; 1847 } 1848 1849 /* 1850 * Name: qla_set_mac_rcv_mode 1851 * Function: Enable/Disable AllMulticast and Promiscous Modes. 1852 */ 1853 static int 1854 qla_set_mac_rcv_mode(qla_host_t *ha, uint32_t mode) 1855 { 1856 q80_config_mac_rcv_mode_t *rcv_mode; 1857 uint32_t err; 1858 q80_config_mac_rcv_mode_rsp_t *rcv_mode_rsp; 1859 device_t dev = ha->pci_dev; 1860 1861 rcv_mode = (q80_config_mac_rcv_mode_t *)ha->hw.mbox; 1862 bzero(rcv_mode, (sizeof (q80_config_mac_rcv_mode_t))); 1863 1864 rcv_mode->opcode = Q8_MBX_CONFIG_MAC_RX_MODE; 1865 rcv_mode->count_version = sizeof (q80_config_mac_rcv_mode_t) >> 2; 1866 rcv_mode->count_version |= Q8_MBX_CMD_VERSION; 1867 1868 rcv_mode->mode = mode; 1869 1870 rcv_mode->cntxt_id = ha->hw.rcv_cntxt_id; 1871 1872 if (qla_mbx_cmd(ha, (uint32_t *)rcv_mode, 1873 (sizeof (q80_config_mac_rcv_mode_t) >> 2), 1874 ha->hw.mbox, (sizeof(q80_config_mac_rcv_mode_rsp_t) >> 2), 1)) { 1875 device_printf(dev, "%s: failed0\n", __func__); 1876 return (-1); 1877 } 1878 rcv_mode_rsp = (q80_config_mac_rcv_mode_rsp_t *)ha->hw.mbox; 1879 1880 err = Q8_MBX_RSP_STATUS(rcv_mode_rsp->regcnt_status); 1881 1882 if (err) { 1883 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 1884 return (-1); 1885 } 1886 1887 return 0; 1888 } 1889 1890 int 1891 ql_set_promisc(qla_host_t *ha) 1892 { 1893 int ret; 1894 1895 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_RCV_PROMISC_ENABLE; 1896 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode); 1897 return (ret); 1898 } 1899 1900 void 1901 qla_reset_promisc(qla_host_t *ha) 1902 { 1903 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_RCV_PROMISC_ENABLE; 1904 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode); 1905 } 1906 1907 int 1908 ql_set_allmulti(qla_host_t *ha) 1909 { 1910 int ret; 1911 1912 ha->hw.mac_rcv_mode |= Q8_MBX_MAC_ALL_MULTI_ENABLE; 1913 ret = qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode); 1914 return (ret); 1915 } 1916 1917 void 1918 qla_reset_allmulti(qla_host_t *ha) 1919 { 1920 ha->hw.mac_rcv_mode &= ~Q8_MBX_MAC_ALL_MULTI_ENABLE; 1921 (void)qla_set_mac_rcv_mode(ha, ha->hw.mac_rcv_mode); 1922 } 1923 1924 /* 1925 * Name: ql_set_max_mtu 1926 * Function: 1927 * Sets the maximum transfer unit size for the specified rcv context. 1928 */ 1929 int 1930 ql_set_max_mtu(qla_host_t *ha, uint32_t mtu, uint16_t cntxt_id) 1931 { 1932 device_t dev; 1933 q80_set_max_mtu_t *max_mtu; 1934 q80_set_max_mtu_rsp_t *max_mtu_rsp; 1935 uint32_t err; 1936 1937 dev = ha->pci_dev; 1938 1939 max_mtu = (q80_set_max_mtu_t *)ha->hw.mbox; 1940 bzero(max_mtu, (sizeof (q80_set_max_mtu_t))); 1941 1942 max_mtu->opcode = Q8_MBX_SET_MAX_MTU; 1943 max_mtu->count_version = (sizeof (q80_set_max_mtu_t) >> 2); 1944 max_mtu->count_version |= Q8_MBX_CMD_VERSION; 1945 1946 max_mtu->cntxt_id = cntxt_id; 1947 max_mtu->mtu = mtu; 1948 1949 if (qla_mbx_cmd(ha, (uint32_t *)max_mtu, 1950 (sizeof (q80_set_max_mtu_t) >> 2), 1951 ha->hw.mbox, (sizeof (q80_set_max_mtu_rsp_t) >> 2), 1)) { 1952 device_printf(dev, "%s: failed\n", __func__); 1953 return -1; 1954 } 1955 1956 max_mtu_rsp = (q80_set_max_mtu_rsp_t *)ha->hw.mbox; 1957 1958 err = Q8_MBX_RSP_STATUS(max_mtu_rsp->regcnt_status); 1959 1960 if (err) { 1961 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 1962 } 1963 1964 return 0; 1965 } 1966 1967 static int 1968 qla_link_event_req(qla_host_t *ha, uint16_t cntxt_id) 1969 { 1970 device_t dev; 1971 q80_link_event_t *lnk; 1972 q80_link_event_rsp_t *lnk_rsp; 1973 uint32_t err; 1974 1975 dev = ha->pci_dev; 1976 1977 lnk = (q80_link_event_t *)ha->hw.mbox; 1978 bzero(lnk, (sizeof (q80_link_event_t))); 1979 1980 lnk->opcode = Q8_MBX_LINK_EVENT_REQ; 1981 lnk->count_version = (sizeof (q80_link_event_t) >> 2); 1982 lnk->count_version |= Q8_MBX_CMD_VERSION; 1983 1984 lnk->cntxt_id = cntxt_id; 1985 lnk->cmd = Q8_LINK_EVENT_CMD_ENABLE_ASYNC; 1986 1987 if (qla_mbx_cmd(ha, (uint32_t *)lnk, (sizeof (q80_link_event_t) >> 2), 1988 ha->hw.mbox, (sizeof (q80_link_event_rsp_t) >> 2), 0)) { 1989 device_printf(dev, "%s: failed\n", __func__); 1990 return -1; 1991 } 1992 1993 lnk_rsp = (q80_link_event_rsp_t *)ha->hw.mbox; 1994 1995 err = Q8_MBX_RSP_STATUS(lnk_rsp->regcnt_status); 1996 1997 if (err) { 1998 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 1999 } 2000 2001 return 0; 2002 } 2003 2004 static int 2005 qla_config_fw_lro(qla_host_t *ha, uint16_t cntxt_id) 2006 { 2007 device_t dev; 2008 q80_config_fw_lro_t *fw_lro; 2009 q80_config_fw_lro_rsp_t *fw_lro_rsp; 2010 uint32_t err; 2011 2012 dev = ha->pci_dev; 2013 2014 fw_lro = (q80_config_fw_lro_t *)ha->hw.mbox; 2015 bzero(fw_lro, sizeof(q80_config_fw_lro_t)); 2016 2017 fw_lro->opcode = Q8_MBX_CONFIG_FW_LRO; 2018 fw_lro->count_version = (sizeof (q80_config_fw_lro_t) >> 2); 2019 fw_lro->count_version |= Q8_MBX_CMD_VERSION; 2020 2021 fw_lro->flags |= Q8_MBX_FW_LRO_IPV4 | Q8_MBX_FW_LRO_IPV4_WO_DST_IP_CHK; 2022 fw_lro->flags |= Q8_MBX_FW_LRO_IPV6 | Q8_MBX_FW_LRO_IPV6_WO_DST_IP_CHK; 2023 2024 fw_lro->cntxt_id = cntxt_id; 2025 2026 if (qla_mbx_cmd(ha, (uint32_t *)fw_lro, 2027 (sizeof (q80_config_fw_lro_t) >> 2), 2028 ha->hw.mbox, (sizeof (q80_config_fw_lro_rsp_t) >> 2), 0)) { 2029 device_printf(dev, "%s: failed\n", __func__); 2030 return -1; 2031 } 2032 2033 fw_lro_rsp = (q80_config_fw_lro_rsp_t *)ha->hw.mbox; 2034 2035 err = Q8_MBX_RSP_STATUS(fw_lro_rsp->regcnt_status); 2036 2037 if (err) { 2038 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 2039 } 2040 2041 return 0; 2042 } 2043 2044 static int 2045 qla_set_cam_search_mode(qla_host_t *ha, uint32_t search_mode) 2046 { 2047 device_t dev; 2048 q80_hw_config_t *hw_config; 2049 q80_hw_config_rsp_t *hw_config_rsp; 2050 uint32_t err; 2051 2052 dev = ha->pci_dev; 2053 2054 hw_config = (q80_hw_config_t *)ha->hw.mbox; 2055 bzero(hw_config, sizeof (q80_hw_config_t)); 2056 2057 hw_config->opcode = Q8_MBX_HW_CONFIG; 2058 hw_config->count_version = Q8_HW_CONFIG_SET_CAM_SEARCH_MODE_COUNT; 2059 hw_config->count_version |= Q8_MBX_CMD_VERSION; 2060 2061 hw_config->cmd = Q8_HW_CONFIG_SET_CAM_SEARCH_MODE; 2062 2063 hw_config->u.set_cam_search_mode.mode = search_mode; 2064 2065 if (qla_mbx_cmd(ha, (uint32_t *)hw_config, 2066 (sizeof (q80_hw_config_t) >> 2), 2067 ha->hw.mbox, (sizeof (q80_hw_config_rsp_t) >> 2), 0)) { 2068 device_printf(dev, "%s: failed\n", __func__); 2069 return -1; 2070 } 2071 hw_config_rsp = (q80_hw_config_rsp_t *)ha->hw.mbox; 2072 2073 err = Q8_MBX_RSP_STATUS(hw_config_rsp->regcnt_status); 2074 2075 if (err) { 2076 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 2077 } 2078 2079 return 0; 2080 } 2081 2082 static int 2083 qla_get_cam_search_mode(qla_host_t *ha) 2084 { 2085 device_t dev; 2086 q80_hw_config_t *hw_config; 2087 q80_hw_config_rsp_t *hw_config_rsp; 2088 uint32_t err; 2089 2090 dev = ha->pci_dev; 2091 2092 hw_config = (q80_hw_config_t *)ha->hw.mbox; 2093 bzero(hw_config, sizeof (q80_hw_config_t)); 2094 2095 hw_config->opcode = Q8_MBX_HW_CONFIG; 2096 hw_config->count_version = Q8_HW_CONFIG_GET_CAM_SEARCH_MODE_COUNT; 2097 hw_config->count_version |= Q8_MBX_CMD_VERSION; 2098 2099 hw_config->cmd = Q8_HW_CONFIG_GET_CAM_SEARCH_MODE; 2100 2101 if (qla_mbx_cmd(ha, (uint32_t *)hw_config, 2102 (sizeof (q80_hw_config_t) >> 2), 2103 ha->hw.mbox, (sizeof (q80_hw_config_rsp_t) >> 2), 0)) { 2104 device_printf(dev, "%s: failed\n", __func__); 2105 return -1; 2106 } 2107 hw_config_rsp = (q80_hw_config_rsp_t *)ha->hw.mbox; 2108 2109 err = Q8_MBX_RSP_STATUS(hw_config_rsp->regcnt_status); 2110 2111 if (err) { 2112 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 2113 } else { 2114 device_printf(dev, "%s: cam search mode [0x%08x]\n", __func__, 2115 hw_config_rsp->u.get_cam_search_mode.mode); 2116 } 2117 2118 return 0; 2119 } 2120 2121 static int 2122 qla_get_hw_stats(qla_host_t *ha, uint32_t cmd, uint32_t rsp_size) 2123 { 2124 device_t dev; 2125 q80_get_stats_t *stat; 2126 q80_get_stats_rsp_t *stat_rsp; 2127 uint32_t err; 2128 2129 dev = ha->pci_dev; 2130 2131 stat = (q80_get_stats_t *)ha->hw.mbox; 2132 bzero(stat, (sizeof (q80_get_stats_t))); 2133 2134 stat->opcode = Q8_MBX_GET_STATS; 2135 stat->count_version = 2; 2136 stat->count_version |= Q8_MBX_CMD_VERSION; 2137 2138 stat->cmd = cmd; 2139 2140 if (qla_mbx_cmd(ha, (uint32_t *)stat, 2, 2141 ha->hw.mbox, (rsp_size >> 2), 0)) { 2142 device_printf(dev, "%s: failed\n", __func__); 2143 return -1; 2144 } 2145 2146 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox; 2147 2148 err = Q8_MBX_RSP_STATUS(stat_rsp->regcnt_status); 2149 2150 if (err) { 2151 return -1; 2152 } 2153 2154 return 0; 2155 } 2156 2157 void 2158 ql_get_stats(qla_host_t *ha) 2159 { 2160 q80_get_stats_rsp_t *stat_rsp; 2161 q80_mac_stats_t *mstat; 2162 q80_xmt_stats_t *xstat; 2163 q80_rcv_stats_t *rstat; 2164 uint32_t cmd; 2165 int i; 2166 struct ifnet *ifp = ha->ifp; 2167 2168 if (ifp == NULL) 2169 return; 2170 2171 if (QLA_LOCK(ha, __func__, QLA_LOCK_DEFAULT_MS_TIMEOUT, 0) != 0) { 2172 device_printf(ha->pci_dev, "%s: failed\n", __func__); 2173 return; 2174 } 2175 2176 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 2177 QLA_UNLOCK(ha, __func__); 2178 return; 2179 } 2180 2181 stat_rsp = (q80_get_stats_rsp_t *)ha->hw.mbox; 2182 /* 2183 * Get MAC Statistics 2184 */ 2185 cmd = Q8_GET_STATS_CMD_TYPE_MAC; 2186 // cmd |= Q8_GET_STATS_CMD_CLEAR; 2187 2188 cmd |= ((ha->pci_func & 0x1) << 16); 2189 2190 if (ha->qla_watchdog_pause || (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) || 2191 ha->offline) 2192 goto ql_get_stats_exit; 2193 2194 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) { 2195 mstat = (q80_mac_stats_t *)&stat_rsp->u.mac; 2196 bcopy(mstat, &ha->hw.mac, sizeof(q80_mac_stats_t)); 2197 } else { 2198 device_printf(ha->pci_dev, "%s: mac failed [0x%08x]\n", 2199 __func__, ha->hw.mbox[0]); 2200 } 2201 /* 2202 * Get RCV Statistics 2203 */ 2204 cmd = Q8_GET_STATS_CMD_RCV | Q8_GET_STATS_CMD_TYPE_CNTXT; 2205 // cmd |= Q8_GET_STATS_CMD_CLEAR; 2206 cmd |= (ha->hw.rcv_cntxt_id << 16); 2207 2208 if (ha->qla_watchdog_pause || (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) || 2209 ha->offline) 2210 goto ql_get_stats_exit; 2211 2212 if (qla_get_hw_stats(ha, cmd, sizeof (q80_get_stats_rsp_t)) == 0) { 2213 rstat = (q80_rcv_stats_t *)&stat_rsp->u.rcv; 2214 bcopy(rstat, &ha->hw.rcv, sizeof(q80_rcv_stats_t)); 2215 } else { 2216 device_printf(ha->pci_dev, "%s: rcv failed [0x%08x]\n", 2217 __func__, ha->hw.mbox[0]); 2218 } 2219 2220 if (ha->qla_watchdog_pause || (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) || 2221 ha->offline) 2222 goto ql_get_stats_exit; 2223 /* 2224 * Get XMT Statistics 2225 */ 2226 for (i = 0 ; (i < ha->hw.num_tx_rings); i++) { 2227 if (ha->qla_watchdog_pause || 2228 (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) || 2229 ha->offline) 2230 goto ql_get_stats_exit; 2231 2232 cmd = Q8_GET_STATS_CMD_XMT | Q8_GET_STATS_CMD_TYPE_CNTXT; 2233 // cmd |= Q8_GET_STATS_CMD_CLEAR; 2234 cmd |= (ha->hw.tx_cntxt[i].tx_cntxt_id << 16); 2235 2236 if (qla_get_hw_stats(ha, cmd, sizeof(q80_get_stats_rsp_t)) 2237 == 0) { 2238 xstat = (q80_xmt_stats_t *)&stat_rsp->u.xmt; 2239 bcopy(xstat, &ha->hw.xmt[i], sizeof(q80_xmt_stats_t)); 2240 } else { 2241 device_printf(ha->pci_dev, "%s: xmt failed [0x%08x]\n", 2242 __func__, ha->hw.mbox[0]); 2243 } 2244 } 2245 2246 ql_get_stats_exit: 2247 QLA_UNLOCK(ha, __func__); 2248 2249 return; 2250 } 2251 2252 /* 2253 * Name: qla_tx_tso 2254 * Function: Checks if the packet to be transmitted is a candidate for 2255 * Large TCP Segment Offload. If yes, the appropriate fields in the Tx 2256 * Ring Structure are plugged in. 2257 */ 2258 static int 2259 qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd, uint8_t *hdr) 2260 { 2261 struct ether_vlan_header *eh; 2262 struct ip *ip = NULL; 2263 struct ip6_hdr *ip6 = NULL; 2264 struct tcphdr *th = NULL; 2265 uint32_t ehdrlen, hdrlen, ip_hlen, tcp_hlen, tcp_opt_off; 2266 uint16_t etype, opcode, offload = 1; 2267 2268 eh = mtod(mp, struct ether_vlan_header *); 2269 2270 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 2271 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; 2272 etype = ntohs(eh->evl_proto); 2273 } else { 2274 ehdrlen = ETHER_HDR_LEN; 2275 etype = ntohs(eh->evl_encap_proto); 2276 } 2277 2278 hdrlen = 0; 2279 2280 switch (etype) { 2281 case ETHERTYPE_IP: 2282 2283 tcp_opt_off = ehdrlen + sizeof(struct ip) + 2284 sizeof(struct tcphdr); 2285 2286 if (mp->m_len < tcp_opt_off) { 2287 m_copydata(mp, 0, tcp_opt_off, hdr); 2288 ip = (struct ip *)(hdr + ehdrlen); 2289 } else { 2290 ip = (struct ip *)(mp->m_data + ehdrlen); 2291 } 2292 2293 ip_hlen = ip->ip_hl << 2; 2294 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO; 2295 2296 2297 if ((ip->ip_p != IPPROTO_TCP) || 2298 (ip_hlen != sizeof (struct ip))){ 2299 /* IP Options are not supported */ 2300 2301 offload = 0; 2302 } else 2303 th = (struct tcphdr *)((caddr_t)ip + ip_hlen); 2304 2305 break; 2306 2307 case ETHERTYPE_IPV6: 2308 2309 tcp_opt_off = ehdrlen + sizeof(struct ip6_hdr) + 2310 sizeof (struct tcphdr); 2311 2312 if (mp->m_len < tcp_opt_off) { 2313 m_copydata(mp, 0, tcp_opt_off, hdr); 2314 ip6 = (struct ip6_hdr *)(hdr + ehdrlen); 2315 } else { 2316 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen); 2317 } 2318 2319 ip_hlen = sizeof(struct ip6_hdr); 2320 opcode = Q8_TX_CMD_OP_XMT_TCP_LSO_IPV6; 2321 2322 if (ip6->ip6_nxt != IPPROTO_TCP) { 2323 //device_printf(dev, "%s: ipv6\n", __func__); 2324 offload = 0; 2325 } else 2326 th = (struct tcphdr *)((caddr_t)ip6 + ip_hlen); 2327 break; 2328 2329 default: 2330 QL_DPRINT8(ha, (ha->pci_dev, "%s: type!=ip\n", __func__)); 2331 offload = 0; 2332 break; 2333 } 2334 2335 if (!offload) 2336 return (-1); 2337 2338 tcp_hlen = th->th_off << 2; 2339 hdrlen = ehdrlen + ip_hlen + tcp_hlen; 2340 2341 if (mp->m_len < hdrlen) { 2342 if (mp->m_len < tcp_opt_off) { 2343 if (tcp_hlen > sizeof(struct tcphdr)) { 2344 m_copydata(mp, tcp_opt_off, 2345 (tcp_hlen - sizeof(struct tcphdr)), 2346 &hdr[tcp_opt_off]); 2347 } 2348 } else { 2349 m_copydata(mp, 0, hdrlen, hdr); 2350 } 2351 } 2352 2353 tx_cmd->mss = mp->m_pkthdr.tso_segsz; 2354 2355 tx_cmd->flags_opcode = opcode ; 2356 tx_cmd->tcp_hdr_off = ip_hlen + ehdrlen; 2357 tx_cmd->total_hdr_len = hdrlen; 2358 2359 /* Check for Multicast least significant bit of MSB == 1 */ 2360 if (eh->evl_dhost[0] & 0x01) { 2361 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_MULTICAST; 2362 } 2363 2364 if (mp->m_len < hdrlen) { 2365 printf("%d\n", hdrlen); 2366 return (1); 2367 } 2368 2369 return (0); 2370 } 2371 2372 /* 2373 * Name: qla_tx_chksum 2374 * Function: Checks if the packet to be transmitted is a candidate for 2375 * TCP/UDP Checksum offload. If yes, the appropriate fields in the Tx 2376 * Ring Structure are plugged in. 2377 */ 2378 static int 2379 qla_tx_chksum(qla_host_t *ha, struct mbuf *mp, uint32_t *op_code, 2380 uint32_t *tcp_hdr_off) 2381 { 2382 struct ether_vlan_header *eh; 2383 struct ip *ip; 2384 struct ip6_hdr *ip6; 2385 uint32_t ehdrlen, ip_hlen; 2386 uint16_t etype, opcode, offload = 1; 2387 uint8_t buf[sizeof(struct ip6_hdr)]; 2388 2389 *op_code = 0; 2390 2391 if ((mp->m_pkthdr.csum_flags & 2392 (CSUM_TCP|CSUM_UDP|CSUM_TCP_IPV6 | CSUM_UDP_IPV6)) == 0) 2393 return (-1); 2394 2395 eh = mtod(mp, struct ether_vlan_header *); 2396 2397 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 2398 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; 2399 etype = ntohs(eh->evl_proto); 2400 } else { 2401 ehdrlen = ETHER_HDR_LEN; 2402 etype = ntohs(eh->evl_encap_proto); 2403 } 2404 2405 2406 switch (etype) { 2407 case ETHERTYPE_IP: 2408 ip = (struct ip *)(mp->m_data + ehdrlen); 2409 2410 ip_hlen = sizeof (struct ip); 2411 2412 if (mp->m_len < (ehdrlen + ip_hlen)) { 2413 m_copydata(mp, ehdrlen, sizeof(struct ip), buf); 2414 ip = (struct ip *)buf; 2415 } 2416 2417 if (ip->ip_p == IPPROTO_TCP) 2418 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM; 2419 else if (ip->ip_p == IPPROTO_UDP) 2420 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM; 2421 else { 2422 //device_printf(dev, "%s: ipv4\n", __func__); 2423 offload = 0; 2424 } 2425 break; 2426 2427 case ETHERTYPE_IPV6: 2428 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen); 2429 2430 ip_hlen = sizeof(struct ip6_hdr); 2431 2432 if (mp->m_len < (ehdrlen + ip_hlen)) { 2433 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr), 2434 buf); 2435 ip6 = (struct ip6_hdr *)buf; 2436 } 2437 2438 if (ip6->ip6_nxt == IPPROTO_TCP) 2439 opcode = Q8_TX_CMD_OP_XMT_TCP_CHKSUM_IPV6; 2440 else if (ip6->ip6_nxt == IPPROTO_UDP) 2441 opcode = Q8_TX_CMD_OP_XMT_UDP_CHKSUM_IPV6; 2442 else { 2443 //device_printf(dev, "%s: ipv6\n", __func__); 2444 offload = 0; 2445 } 2446 break; 2447 2448 default: 2449 offload = 0; 2450 break; 2451 } 2452 if (!offload) 2453 return (-1); 2454 2455 *op_code = opcode; 2456 *tcp_hdr_off = (ip_hlen + ehdrlen); 2457 2458 return (0); 2459 } 2460 2461 #define QLA_TX_MIN_FREE 2 2462 /* 2463 * Name: ql_hw_send 2464 * Function: Transmits a packet. It first checks if the packet is a 2465 * candidate for Large TCP Segment Offload and then for UDP/TCP checksum 2466 * offload. If either of these creteria are not met, it is transmitted 2467 * as a regular ethernet frame. 2468 */ 2469 int 2470 ql_hw_send(qla_host_t *ha, bus_dma_segment_t *segs, int nsegs, 2471 uint32_t tx_idx, struct mbuf *mp, uint32_t txr_idx, uint32_t iscsi_pdu) 2472 { 2473 struct ether_vlan_header *eh; 2474 qla_hw_t *hw = &ha->hw; 2475 q80_tx_cmd_t *tx_cmd, tso_cmd; 2476 bus_dma_segment_t *c_seg; 2477 uint32_t num_tx_cmds, hdr_len = 0; 2478 uint32_t total_length = 0, bytes, tx_cmd_count = 0, txr_next; 2479 device_t dev; 2480 int i, ret; 2481 uint8_t *src = NULL, *dst = NULL; 2482 uint8_t frame_hdr[QL_FRAME_HDR_SIZE]; 2483 uint32_t op_code = 0; 2484 uint32_t tcp_hdr_off = 0; 2485 2486 dev = ha->pci_dev; 2487 2488 /* 2489 * Always make sure there is atleast one empty slot in the tx_ring 2490 * tx_ring is considered full when there only one entry available 2491 */ 2492 num_tx_cmds = (nsegs + (Q8_TX_CMD_MAX_SEGMENTS - 1)) >> 2; 2493 2494 total_length = mp->m_pkthdr.len; 2495 if (total_length > QLA_MAX_TSO_FRAME_SIZE) { 2496 device_printf(dev, "%s: total length exceeds maxlen(%d)\n", 2497 __func__, total_length); 2498 return (EINVAL); 2499 } 2500 eh = mtod(mp, struct ether_vlan_header *); 2501 2502 if (mp->m_pkthdr.csum_flags & CSUM_TSO) { 2503 bzero((void *)&tso_cmd, sizeof(q80_tx_cmd_t)); 2504 2505 src = frame_hdr; 2506 ret = qla_tx_tso(ha, mp, &tso_cmd, src); 2507 2508 if (!(ret & ~1)) { 2509 /* find the additional tx_cmd descriptors required */ 2510 2511 if (mp->m_flags & M_VLANTAG) 2512 tso_cmd.total_hdr_len += ETHER_VLAN_ENCAP_LEN; 2513 2514 hdr_len = tso_cmd.total_hdr_len; 2515 2516 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN; 2517 bytes = QL_MIN(bytes, hdr_len); 2518 2519 num_tx_cmds++; 2520 hdr_len -= bytes; 2521 2522 while (hdr_len) { 2523 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len); 2524 hdr_len -= bytes; 2525 num_tx_cmds++; 2526 } 2527 hdr_len = tso_cmd.total_hdr_len; 2528 2529 if (ret == 0) 2530 src = (uint8_t *)eh; 2531 } else 2532 return (EINVAL); 2533 } else { 2534 (void)qla_tx_chksum(ha, mp, &op_code, &tcp_hdr_off); 2535 } 2536 2537 if (hw->tx_cntxt[txr_idx].txr_free <= (num_tx_cmds + QLA_TX_MIN_FREE)) { 2538 ql_hw_tx_done_locked(ha, txr_idx); 2539 if (hw->tx_cntxt[txr_idx].txr_free <= 2540 (num_tx_cmds + QLA_TX_MIN_FREE)) { 2541 QL_DPRINT8(ha, (dev, "%s: (hw->txr_free <= " 2542 "(num_tx_cmds + QLA_TX_MIN_FREE))\n", 2543 __func__)); 2544 return (-1); 2545 } 2546 } 2547 2548 for (i = 0; i < num_tx_cmds; i++) { 2549 int j; 2550 2551 j = (tx_idx+i) & (NUM_TX_DESCRIPTORS - 1); 2552 2553 if (NULL != ha->tx_ring[txr_idx].tx_buf[j].m_head) { 2554 QL_ASSERT(ha, 0, \ 2555 ("%s [%d]: txr_idx = %d tx_idx = %d mbuf = %p\n",\ 2556 __func__, __LINE__, txr_idx, j,\ 2557 ha->tx_ring[txr_idx].tx_buf[j].m_head)); 2558 return (EINVAL); 2559 } 2560 } 2561 2562 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[tx_idx]; 2563 2564 if (!(mp->m_pkthdr.csum_flags & CSUM_TSO)) { 2565 if (nsegs > ha->hw.max_tx_segs) 2566 ha->hw.max_tx_segs = nsegs; 2567 2568 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t)); 2569 2570 if (op_code) { 2571 tx_cmd->flags_opcode = op_code; 2572 tx_cmd->tcp_hdr_off = tcp_hdr_off; 2573 2574 } else { 2575 tx_cmd->flags_opcode = Q8_TX_CMD_OP_XMT_ETHER; 2576 } 2577 } else { 2578 bcopy(&tso_cmd, tx_cmd, sizeof(q80_tx_cmd_t)); 2579 ha->tx_tso_frames++; 2580 } 2581 2582 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 2583 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_VLAN_TAGGED; 2584 2585 if (iscsi_pdu) 2586 eh->evl_tag |= ha->hw.user_pri_iscsi << 13; 2587 2588 } else if (mp->m_flags & M_VLANTAG) { 2589 if (hdr_len) { /* TSO */ 2590 tx_cmd->flags_opcode |= (Q8_TX_CMD_FLAGS_VLAN_TAGGED | 2591 Q8_TX_CMD_FLAGS_HW_VLAN_ID); 2592 tx_cmd->tcp_hdr_off += ETHER_VLAN_ENCAP_LEN; 2593 } else 2594 tx_cmd->flags_opcode |= Q8_TX_CMD_FLAGS_HW_VLAN_ID; 2595 2596 ha->hw_vlan_tx_frames++; 2597 tx_cmd->vlan_tci = mp->m_pkthdr.ether_vtag; 2598 2599 if (iscsi_pdu) { 2600 tx_cmd->vlan_tci |= ha->hw.user_pri_iscsi << 13; 2601 mp->m_pkthdr.ether_vtag = tx_cmd->vlan_tci; 2602 } 2603 } 2604 2605 tx_cmd->n_bufs = (uint8_t)nsegs; 2606 tx_cmd->data_len_lo = (uint8_t)(total_length & 0xFF); 2607 tx_cmd->data_len_hi = qla_host_to_le16(((uint16_t)(total_length >> 8))); 2608 tx_cmd->cntxtid = Q8_TX_CMD_PORT_CNXTID(ha->pci_func); 2609 2610 c_seg = segs; 2611 2612 while (1) { 2613 for (i = 0; ((i < Q8_TX_CMD_MAX_SEGMENTS) && nsegs); i++) { 2614 switch (i) { 2615 case 0: 2616 tx_cmd->buf1_addr = c_seg->ds_addr; 2617 tx_cmd->buf1_len = c_seg->ds_len; 2618 break; 2619 2620 case 1: 2621 tx_cmd->buf2_addr = c_seg->ds_addr; 2622 tx_cmd->buf2_len = c_seg->ds_len; 2623 break; 2624 2625 case 2: 2626 tx_cmd->buf3_addr = c_seg->ds_addr; 2627 tx_cmd->buf3_len = c_seg->ds_len; 2628 break; 2629 2630 case 3: 2631 tx_cmd->buf4_addr = c_seg->ds_addr; 2632 tx_cmd->buf4_len = c_seg->ds_len; 2633 break; 2634 } 2635 2636 c_seg++; 2637 nsegs--; 2638 } 2639 2640 txr_next = hw->tx_cntxt[txr_idx].txr_next = 2641 (hw->tx_cntxt[txr_idx].txr_next + 1) & 2642 (NUM_TX_DESCRIPTORS - 1); 2643 tx_cmd_count++; 2644 2645 if (!nsegs) 2646 break; 2647 2648 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next]; 2649 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t)); 2650 } 2651 2652 if (mp->m_pkthdr.csum_flags & CSUM_TSO) { 2653 /* TSO : Copy the header in the following tx cmd descriptors */ 2654 2655 txr_next = hw->tx_cntxt[txr_idx].txr_next; 2656 2657 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next]; 2658 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t)); 2659 2660 bytes = sizeof(q80_tx_cmd_t) - Q8_TX_CMD_TSO_ALIGN; 2661 bytes = QL_MIN(bytes, hdr_len); 2662 2663 dst = (uint8_t *)tx_cmd + Q8_TX_CMD_TSO_ALIGN; 2664 2665 if (mp->m_flags & M_VLANTAG) { 2666 /* first copy the src/dst MAC addresses */ 2667 bcopy(src, dst, (ETHER_ADDR_LEN * 2)); 2668 dst += (ETHER_ADDR_LEN * 2); 2669 src += (ETHER_ADDR_LEN * 2); 2670 2671 *((uint16_t *)dst) = htons(ETHERTYPE_VLAN); 2672 dst += 2; 2673 *((uint16_t *)dst) = htons(mp->m_pkthdr.ether_vtag); 2674 dst += 2; 2675 2676 /* bytes left in src header */ 2677 hdr_len -= ((ETHER_ADDR_LEN * 2) + 2678 ETHER_VLAN_ENCAP_LEN); 2679 2680 /* bytes left in TxCmd Entry */ 2681 bytes -= ((ETHER_ADDR_LEN * 2) + ETHER_VLAN_ENCAP_LEN); 2682 2683 bcopy(src, dst, bytes); 2684 src += bytes; 2685 hdr_len -= bytes; 2686 } else { 2687 bcopy(src, dst, bytes); 2688 src += bytes; 2689 hdr_len -= bytes; 2690 } 2691 2692 txr_next = hw->tx_cntxt[txr_idx].txr_next = 2693 (hw->tx_cntxt[txr_idx].txr_next + 1) & 2694 (NUM_TX_DESCRIPTORS - 1); 2695 tx_cmd_count++; 2696 2697 while (hdr_len) { 2698 tx_cmd = &hw->tx_cntxt[txr_idx].tx_ring_base[txr_next]; 2699 bzero((void *)tx_cmd, sizeof(q80_tx_cmd_t)); 2700 2701 bytes = QL_MIN((sizeof(q80_tx_cmd_t)), hdr_len); 2702 2703 bcopy(src, tx_cmd, bytes); 2704 src += bytes; 2705 hdr_len -= bytes; 2706 2707 txr_next = hw->tx_cntxt[txr_idx].txr_next = 2708 (hw->tx_cntxt[txr_idx].txr_next + 1) & 2709 (NUM_TX_DESCRIPTORS - 1); 2710 tx_cmd_count++; 2711 } 2712 } 2713 2714 hw->tx_cntxt[txr_idx].txr_free = 2715 hw->tx_cntxt[txr_idx].txr_free - tx_cmd_count; 2716 2717 QL_UPDATE_TX_PRODUCER_INDEX(ha, hw->tx_cntxt[txr_idx].txr_next,\ 2718 txr_idx); 2719 QL_DPRINT8(ha, (dev, "%s: return\n", __func__)); 2720 2721 return (0); 2722 } 2723 2724 #define Q8_CONFIG_IND_TBL_SIZE 32 /* < Q8_RSS_IND_TBL_SIZE and power of 2 */ 2725 static int 2726 qla_config_rss_ind_table(qla_host_t *ha) 2727 { 2728 uint32_t i, count; 2729 uint8_t rss_ind_tbl[Q8_CONFIG_IND_TBL_SIZE]; 2730 2731 for (i = 0; i < Q8_CONFIG_IND_TBL_SIZE; i++) { 2732 rss_ind_tbl[i] = i % ha->hw.num_sds_rings; 2733 } 2734 2735 for (i = 0; i <= Q8_RSS_IND_TBL_MAX_IDX ; 2736 i = i + Q8_CONFIG_IND_TBL_SIZE) { 2737 if ((i + Q8_CONFIG_IND_TBL_SIZE) > Q8_RSS_IND_TBL_MAX_IDX) { 2738 count = Q8_RSS_IND_TBL_MAX_IDX - i + 1; 2739 } else { 2740 count = Q8_CONFIG_IND_TBL_SIZE; 2741 } 2742 2743 if (qla_set_rss_ind_table(ha, i, count, ha->hw.rcv_cntxt_id, 2744 rss_ind_tbl)) 2745 return (-1); 2746 } 2747 2748 return (0); 2749 } 2750 2751 static int 2752 qla_config_soft_lro(qla_host_t *ha) 2753 { 2754 int i; 2755 qla_hw_t *hw = &ha->hw; 2756 struct lro_ctrl *lro; 2757 2758 for (i = 0; i < hw->num_sds_rings; i++) { 2759 lro = &hw->sds[i].lro; 2760 2761 bzero(lro, sizeof(struct lro_ctrl)); 2762 2763 #if (__FreeBSD_version >= 1100101) 2764 if (tcp_lro_init_args(lro, ha->ifp, 0, NUM_RX_DESCRIPTORS)) { 2765 device_printf(ha->pci_dev, 2766 "%s: tcp_lro_init_args [%d] failed\n", 2767 __func__, i); 2768 return (-1); 2769 } 2770 #else 2771 if (tcp_lro_init(lro)) { 2772 device_printf(ha->pci_dev, 2773 "%s: tcp_lro_init [%d] failed\n", 2774 __func__, i); 2775 return (-1); 2776 } 2777 #endif /* #if (__FreeBSD_version >= 1100101) */ 2778 2779 lro->ifp = ha->ifp; 2780 } 2781 2782 QL_DPRINT2(ha, (ha->pci_dev, "%s: LRO initialized\n", __func__)); 2783 return (0); 2784 } 2785 2786 static void 2787 qla_drain_soft_lro(qla_host_t *ha) 2788 { 2789 int i; 2790 qla_hw_t *hw = &ha->hw; 2791 struct lro_ctrl *lro; 2792 2793 for (i = 0; i < hw->num_sds_rings; i++) { 2794 lro = &hw->sds[i].lro; 2795 2796 #if (__FreeBSD_version >= 1100101) 2797 tcp_lro_flush_all(lro); 2798 #else 2799 struct lro_entry *queued; 2800 2801 while ((!SLIST_EMPTY(&lro->lro_active))) { 2802 queued = SLIST_FIRST(&lro->lro_active); 2803 SLIST_REMOVE_HEAD(&lro->lro_active, next); 2804 tcp_lro_flush(lro, queued); 2805 } 2806 #endif /* #if (__FreeBSD_version >= 1100101) */ 2807 } 2808 2809 return; 2810 } 2811 2812 static void 2813 qla_free_soft_lro(qla_host_t *ha) 2814 { 2815 int i; 2816 qla_hw_t *hw = &ha->hw; 2817 struct lro_ctrl *lro; 2818 2819 for (i = 0; i < hw->num_sds_rings; i++) { 2820 lro = &hw->sds[i].lro; 2821 tcp_lro_free(lro); 2822 } 2823 2824 return; 2825 } 2826 2827 /* 2828 * Name: ql_del_hw_if 2829 * Function: Destroys the hardware specific entities corresponding to an 2830 * Ethernet Interface 2831 */ 2832 void 2833 ql_del_hw_if(qla_host_t *ha) 2834 { 2835 uint32_t i; 2836 uint32_t num_msix; 2837 2838 (void)qla_stop_nic_func(ha); 2839 2840 qla_del_rcv_cntxt(ha); 2841 2842 if(qla_del_xmt_cntxt(ha)) 2843 goto ql_del_hw_if_exit; 2844 2845 if (ha->hw.flags.init_intr_cnxt) { 2846 for (i = 0; i < ha->hw.num_sds_rings; ) { 2847 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings) 2848 num_msix = Q8_MAX_INTR_VECTORS; 2849 else 2850 num_msix = ha->hw.num_sds_rings - i; 2851 2852 if (qla_config_intr_cntxt(ha, i, num_msix, 0)) 2853 break; 2854 2855 i += num_msix; 2856 } 2857 2858 ha->hw.flags.init_intr_cnxt = 0; 2859 } 2860 2861 ql_del_hw_if_exit: 2862 if (ha->hw.enable_soft_lro) { 2863 qla_drain_soft_lro(ha); 2864 qla_free_soft_lro(ha); 2865 } 2866 2867 return; 2868 } 2869 2870 void 2871 qla_confirm_9kb_enable(qla_host_t *ha) 2872 { 2873 // uint32_t supports_9kb = 0; 2874 2875 ha->hw.mbx_intr_mask_offset = READ_REG32(ha, Q8_MBOX_INT_MASK_MSIX); 2876 2877 /* Use MSI-X vector 0; Enable Firmware Mailbox Interrupt */ 2878 WRITE_REG32(ha, Q8_MBOX_INT_ENABLE, BIT_2); 2879 WRITE_REG32(ha, ha->hw.mbx_intr_mask_offset, 0x0); 2880 2881 #if 0 2882 qla_get_nic_partition(ha, &supports_9kb, NULL); 2883 2884 if (!supports_9kb) 2885 #endif 2886 ha->hw.enable_9kb = 0; 2887 2888 return; 2889 } 2890 2891 /* 2892 * Name: ql_init_hw_if 2893 * Function: Creates the hardware specific entities corresponding to an 2894 * Ethernet Interface - Transmit and Receive Contexts. Sets the MAC Address 2895 * corresponding to the interface. Enables LRO if allowed. 2896 */ 2897 int 2898 ql_init_hw_if(qla_host_t *ha) 2899 { 2900 uint32_t i; 2901 uint8_t bcast_mac[6]; 2902 qla_rdesc_t *rdesc; 2903 uint32_t num_msix; 2904 2905 for (i = 0; i < ha->hw.num_sds_rings; i++) { 2906 bzero(ha->hw.dma_buf.sds_ring[i].dma_b, 2907 ha->hw.dma_buf.sds_ring[i].size); 2908 } 2909 2910 for (i = 0; i < ha->hw.num_sds_rings; ) { 2911 if ((i + Q8_MAX_INTR_VECTORS) < ha->hw.num_sds_rings) 2912 num_msix = Q8_MAX_INTR_VECTORS; 2913 else 2914 num_msix = ha->hw.num_sds_rings - i; 2915 2916 if (qla_config_intr_cntxt(ha, i, num_msix, 1)) { 2917 if (i > 0) { 2918 num_msix = i; 2919 2920 for (i = 0; i < num_msix; ) { 2921 qla_config_intr_cntxt(ha, i, 2922 Q8_MAX_INTR_VECTORS, 0); 2923 i += Q8_MAX_INTR_VECTORS; 2924 } 2925 } 2926 return (-1); 2927 } 2928 2929 i = i + num_msix; 2930 } 2931 2932 ha->hw.flags.init_intr_cnxt = 1; 2933 2934 /* 2935 * Create Receive Context 2936 */ 2937 if (qla_init_rcv_cntxt(ha)) { 2938 return (-1); 2939 } 2940 2941 for (i = 0; i < ha->hw.num_rds_rings; i++) { 2942 rdesc = &ha->hw.rds[i]; 2943 rdesc->rx_next = NUM_RX_DESCRIPTORS - 2; 2944 rdesc->rx_in = 0; 2945 /* Update the RDS Producer Indices */ 2946 QL_UPDATE_RDS_PRODUCER_INDEX(ha, rdesc->prod_std,\ 2947 rdesc->rx_next); 2948 } 2949 2950 /* 2951 * Create Transmit Context 2952 */ 2953 if (qla_init_xmt_cntxt(ha)) { 2954 qla_del_rcv_cntxt(ha); 2955 return (-1); 2956 } 2957 ha->hw.max_tx_segs = 0; 2958 2959 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 1, 1)) 2960 return(-1); 2961 2962 ha->hw.flags.unicast_mac = 1; 2963 2964 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF; 2965 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF; 2966 2967 if (qla_config_mac_addr(ha, bcast_mac, 1, 1)) 2968 return (-1); 2969 2970 ha->hw.flags.bcast_mac = 1; 2971 2972 /* 2973 * program any cached multicast addresses 2974 */ 2975 if (qla_hw_add_all_mcast(ha)) 2976 return (-1); 2977 2978 if (ql_set_max_mtu(ha, ha->max_frame_size, ha->hw.rcv_cntxt_id)) 2979 return (-1); 2980 2981 if (qla_config_rss(ha, ha->hw.rcv_cntxt_id)) 2982 return (-1); 2983 2984 if (qla_config_rss_ind_table(ha)) 2985 return (-1); 2986 2987 if (qla_config_intr_coalesce(ha, ha->hw.rcv_cntxt_id, 0, 1)) 2988 return (-1); 2989 2990 if (qla_link_event_req(ha, ha->hw.rcv_cntxt_id)) 2991 return (-1); 2992 2993 if (ha->ifp->if_capenable & IFCAP_LRO) { 2994 if (ha->hw.enable_hw_lro) { 2995 ha->hw.enable_soft_lro = 0; 2996 2997 if (qla_config_fw_lro(ha, ha->hw.rcv_cntxt_id)) 2998 return (-1); 2999 } else { 3000 ha->hw.enable_soft_lro = 1; 3001 3002 if (qla_config_soft_lro(ha)) 3003 return (-1); 3004 } 3005 } 3006 3007 if (qla_init_nic_func(ha)) 3008 return (-1); 3009 3010 if (qla_query_fw_dcbx_caps(ha)) 3011 return (-1); 3012 3013 for (i = 0; i < ha->hw.num_sds_rings; i++) 3014 QL_ENABLE_INTERRUPTS(ha, i); 3015 3016 return (0); 3017 } 3018 3019 static int 3020 qla_map_sds_to_rds(qla_host_t *ha, uint32_t start_idx, uint32_t num_idx) 3021 { 3022 device_t dev = ha->pci_dev; 3023 q80_rq_map_sds_to_rds_t *map_rings; 3024 q80_rsp_map_sds_to_rds_t *map_rings_rsp; 3025 uint32_t i, err; 3026 qla_hw_t *hw = &ha->hw; 3027 3028 map_rings = (q80_rq_map_sds_to_rds_t *)ha->hw.mbox; 3029 bzero(map_rings, sizeof(q80_rq_map_sds_to_rds_t)); 3030 3031 map_rings->opcode = Q8_MBX_MAP_SDS_TO_RDS; 3032 map_rings->count_version = (sizeof (q80_rq_map_sds_to_rds_t) >> 2); 3033 map_rings->count_version |= Q8_MBX_CMD_VERSION; 3034 3035 map_rings->cntxt_id = hw->rcv_cntxt_id; 3036 map_rings->num_rings = num_idx; 3037 3038 for (i = 0; i < num_idx; i++) { 3039 map_rings->sds_rds[i].sds_ring = i + start_idx; 3040 map_rings->sds_rds[i].rds_ring = i + start_idx; 3041 } 3042 3043 if (qla_mbx_cmd(ha, (uint32_t *)map_rings, 3044 (sizeof (q80_rq_map_sds_to_rds_t) >> 2), 3045 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) { 3046 device_printf(dev, "%s: failed0\n", __func__); 3047 return (-1); 3048 } 3049 3050 map_rings_rsp = (q80_rsp_map_sds_to_rds_t *)ha->hw.mbox; 3051 3052 err = Q8_MBX_RSP_STATUS(map_rings_rsp->regcnt_status); 3053 3054 if (err) { 3055 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3056 return (-1); 3057 } 3058 3059 return (0); 3060 } 3061 3062 /* 3063 * Name: qla_init_rcv_cntxt 3064 * Function: Creates the Receive Context. 3065 */ 3066 static int 3067 qla_init_rcv_cntxt(qla_host_t *ha) 3068 { 3069 q80_rq_rcv_cntxt_t *rcntxt; 3070 q80_rsp_rcv_cntxt_t *rcntxt_rsp; 3071 q80_stat_desc_t *sdesc; 3072 int i, j; 3073 qla_hw_t *hw = &ha->hw; 3074 device_t dev; 3075 uint32_t err; 3076 uint32_t rcntxt_sds_rings; 3077 uint32_t rcntxt_rds_rings; 3078 uint32_t max_idx; 3079 3080 dev = ha->pci_dev; 3081 3082 /* 3083 * Create Receive Context 3084 */ 3085 3086 for (i = 0; i < hw->num_sds_rings; i++) { 3087 sdesc = (q80_stat_desc_t *)&hw->sds[i].sds_ring_base[0]; 3088 3089 for (j = 0; j < NUM_STATUS_DESCRIPTORS; j++) { 3090 sdesc->data[0] = 1ULL; 3091 sdesc->data[1] = 1ULL; 3092 } 3093 } 3094 3095 rcntxt_sds_rings = hw->num_sds_rings; 3096 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS) 3097 rcntxt_sds_rings = MAX_RCNTXT_SDS_RINGS; 3098 3099 rcntxt_rds_rings = hw->num_rds_rings; 3100 3101 if (hw->num_rds_rings > MAX_RDS_RING_SETS) 3102 rcntxt_rds_rings = MAX_RDS_RING_SETS; 3103 3104 rcntxt = (q80_rq_rcv_cntxt_t *)ha->hw.mbox; 3105 bzero(rcntxt, (sizeof (q80_rq_rcv_cntxt_t))); 3106 3107 rcntxt->opcode = Q8_MBX_CREATE_RX_CNTXT; 3108 rcntxt->count_version = (sizeof (q80_rq_rcv_cntxt_t) >> 2); 3109 rcntxt->count_version |= Q8_MBX_CMD_VERSION; 3110 3111 rcntxt->cap0 = Q8_RCV_CNTXT_CAP0_BASEFW | 3112 Q8_RCV_CNTXT_CAP0_LRO | 3113 Q8_RCV_CNTXT_CAP0_HW_LRO | 3114 Q8_RCV_CNTXT_CAP0_RSS | 3115 Q8_RCV_CNTXT_CAP0_SGL_LRO; 3116 3117 if (ha->hw.enable_9kb) 3118 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SINGLE_JUMBO; 3119 else 3120 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_SGL_JUMBO; 3121 3122 if (ha->hw.num_rds_rings > 1) { 3123 rcntxt->nrds_sets_rings = rcntxt_rds_rings | (1 << 5); 3124 rcntxt->cap0 |= Q8_RCV_CNTXT_CAP0_MULTI_RDS; 3125 } else 3126 rcntxt->nrds_sets_rings = 0x1 | (1 << 5); 3127 3128 rcntxt->nsds_rings = rcntxt_sds_rings; 3129 3130 rcntxt->rds_producer_mode = Q8_RCV_CNTXT_RDS_PROD_MODE_UNIQUE; 3131 3132 rcntxt->rcv_vpid = 0; 3133 3134 for (i = 0; i < rcntxt_sds_rings; i++) { 3135 rcntxt->sds[i].paddr = 3136 qla_host_to_le64(hw->dma_buf.sds_ring[i].dma_addr); 3137 rcntxt->sds[i].size = 3138 qla_host_to_le32(NUM_STATUS_DESCRIPTORS); 3139 rcntxt->sds[i].intr_id = qla_host_to_le16(hw->intr_id[i]); 3140 rcntxt->sds[i].intr_src_bit = qla_host_to_le16(0); 3141 } 3142 3143 for (i = 0; i < rcntxt_rds_rings; i++) { 3144 rcntxt->rds[i].paddr_std = 3145 qla_host_to_le64(hw->dma_buf.rds_ring[i].dma_addr); 3146 3147 if (ha->hw.enable_9kb) 3148 rcntxt->rds[i].std_bsize = 3149 qla_host_to_le64(MJUM9BYTES); 3150 else 3151 rcntxt->rds[i].std_bsize = qla_host_to_le64(MCLBYTES); 3152 3153 rcntxt->rds[i].std_nentries = 3154 qla_host_to_le32(NUM_RX_DESCRIPTORS); 3155 } 3156 3157 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt, 3158 (sizeof (q80_rq_rcv_cntxt_t) >> 2), 3159 ha->hw.mbox, (sizeof(q80_rsp_rcv_cntxt_t) >> 2), 0)) { 3160 device_printf(dev, "%s: failed0\n", __func__); 3161 return (-1); 3162 } 3163 3164 rcntxt_rsp = (q80_rsp_rcv_cntxt_t *)ha->hw.mbox; 3165 3166 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status); 3167 3168 if (err) { 3169 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3170 return (-1); 3171 } 3172 3173 for (i = 0; i < rcntxt_sds_rings; i++) { 3174 hw->sds[i].sds_consumer = rcntxt_rsp->sds_cons[i]; 3175 } 3176 3177 for (i = 0; i < rcntxt_rds_rings; i++) { 3178 hw->rds[i].prod_std = rcntxt_rsp->rds[i].prod_std; 3179 } 3180 3181 hw->rcv_cntxt_id = rcntxt_rsp->cntxt_id; 3182 3183 ha->hw.flags.init_rx_cnxt = 1; 3184 3185 if (hw->num_sds_rings > MAX_RCNTXT_SDS_RINGS) { 3186 for (i = MAX_RCNTXT_SDS_RINGS; i < hw->num_sds_rings;) { 3187 if ((i + MAX_RCNTXT_SDS_RINGS) < hw->num_sds_rings) 3188 max_idx = MAX_RCNTXT_SDS_RINGS; 3189 else 3190 max_idx = hw->num_sds_rings - i; 3191 3192 err = qla_add_rcv_rings(ha, i, max_idx); 3193 if (err) 3194 return -1; 3195 3196 i += max_idx; 3197 } 3198 } 3199 3200 if (hw->num_rds_rings > 1) { 3201 for (i = 0; i < hw->num_rds_rings; ) { 3202 if ((i + MAX_SDS_TO_RDS_MAP) < hw->num_rds_rings) 3203 max_idx = MAX_SDS_TO_RDS_MAP; 3204 else 3205 max_idx = hw->num_rds_rings - i; 3206 3207 err = qla_map_sds_to_rds(ha, i, max_idx); 3208 if (err) 3209 return -1; 3210 3211 i += max_idx; 3212 } 3213 } 3214 3215 return (0); 3216 } 3217 3218 static int 3219 qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds) 3220 { 3221 device_t dev = ha->pci_dev; 3222 q80_rq_add_rcv_rings_t *add_rcv; 3223 q80_rsp_add_rcv_rings_t *add_rcv_rsp; 3224 uint32_t i,j, err; 3225 qla_hw_t *hw = &ha->hw; 3226 3227 add_rcv = (q80_rq_add_rcv_rings_t *)ha->hw.mbox; 3228 bzero(add_rcv, sizeof (q80_rq_add_rcv_rings_t)); 3229 3230 add_rcv->opcode = Q8_MBX_ADD_RX_RINGS; 3231 add_rcv->count_version = (sizeof (q80_rq_add_rcv_rings_t) >> 2); 3232 add_rcv->count_version |= Q8_MBX_CMD_VERSION; 3233 3234 add_rcv->nrds_sets_rings = nsds | (1 << 5); 3235 add_rcv->nsds_rings = nsds; 3236 add_rcv->cntxt_id = hw->rcv_cntxt_id; 3237 3238 for (i = 0; i < nsds; i++) { 3239 j = i + sds_idx; 3240 3241 add_rcv->sds[i].paddr = 3242 qla_host_to_le64(hw->dma_buf.sds_ring[j].dma_addr); 3243 3244 add_rcv->sds[i].size = 3245 qla_host_to_le32(NUM_STATUS_DESCRIPTORS); 3246 3247 add_rcv->sds[i].intr_id = qla_host_to_le16(hw->intr_id[j]); 3248 add_rcv->sds[i].intr_src_bit = qla_host_to_le16(0); 3249 } 3250 3251 for (i = 0; (i < nsds); i++) { 3252 j = i + sds_idx; 3253 3254 add_rcv->rds[i].paddr_std = 3255 qla_host_to_le64(hw->dma_buf.rds_ring[j].dma_addr); 3256 3257 if (ha->hw.enable_9kb) 3258 add_rcv->rds[i].std_bsize = 3259 qla_host_to_le64(MJUM9BYTES); 3260 else 3261 add_rcv->rds[i].std_bsize = qla_host_to_le64(MCLBYTES); 3262 3263 add_rcv->rds[i].std_nentries = 3264 qla_host_to_le32(NUM_RX_DESCRIPTORS); 3265 } 3266 3267 if (qla_mbx_cmd(ha, (uint32_t *)add_rcv, 3268 (sizeof (q80_rq_add_rcv_rings_t) >> 2), 3269 ha->hw.mbox, (sizeof(q80_rsp_add_rcv_rings_t) >> 2), 0)) { 3270 device_printf(dev, "%s: failed0\n", __func__); 3271 return (-1); 3272 } 3273 3274 add_rcv_rsp = (q80_rsp_add_rcv_rings_t *)ha->hw.mbox; 3275 3276 err = Q8_MBX_RSP_STATUS(add_rcv_rsp->regcnt_status); 3277 3278 if (err) { 3279 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3280 return (-1); 3281 } 3282 3283 for (i = 0; i < nsds; i++) { 3284 hw->sds[(i + sds_idx)].sds_consumer = add_rcv_rsp->sds_cons[i]; 3285 } 3286 3287 for (i = 0; i < nsds; i++) { 3288 hw->rds[(i + sds_idx)].prod_std = add_rcv_rsp->rds[i].prod_std; 3289 } 3290 3291 return (0); 3292 } 3293 3294 /* 3295 * Name: qla_del_rcv_cntxt 3296 * Function: Destroys the Receive Context. 3297 */ 3298 static void 3299 qla_del_rcv_cntxt(qla_host_t *ha) 3300 { 3301 device_t dev = ha->pci_dev; 3302 q80_rcv_cntxt_destroy_t *rcntxt; 3303 q80_rcv_cntxt_destroy_rsp_t *rcntxt_rsp; 3304 uint32_t err; 3305 uint8_t bcast_mac[6]; 3306 3307 if (!ha->hw.flags.init_rx_cnxt) 3308 return; 3309 3310 if (qla_hw_del_all_mcast(ha)) 3311 return; 3312 3313 if (ha->hw.flags.bcast_mac) { 3314 bcast_mac[0] = 0xFF; bcast_mac[1] = 0xFF; bcast_mac[2] = 0xFF; 3315 bcast_mac[3] = 0xFF; bcast_mac[4] = 0xFF; bcast_mac[5] = 0xFF; 3316 3317 if (qla_config_mac_addr(ha, bcast_mac, 0, 1)) 3318 return; 3319 ha->hw.flags.bcast_mac = 0; 3320 } 3321 3322 if (ha->hw.flags.unicast_mac) { 3323 if (qla_config_mac_addr(ha, ha->hw.mac_addr, 0, 1)) 3324 return; 3325 ha->hw.flags.unicast_mac = 0; 3326 } 3327 3328 rcntxt = (q80_rcv_cntxt_destroy_t *)ha->hw.mbox; 3329 bzero(rcntxt, (sizeof (q80_rcv_cntxt_destroy_t))); 3330 3331 rcntxt->opcode = Q8_MBX_DESTROY_RX_CNTXT; 3332 rcntxt->count_version = (sizeof (q80_rcv_cntxt_destroy_t) >> 2); 3333 rcntxt->count_version |= Q8_MBX_CMD_VERSION; 3334 3335 rcntxt->cntxt_id = ha->hw.rcv_cntxt_id; 3336 3337 if (qla_mbx_cmd(ha, (uint32_t *)rcntxt, 3338 (sizeof (q80_rcv_cntxt_destroy_t) >> 2), 3339 ha->hw.mbox, (sizeof(q80_rcv_cntxt_destroy_rsp_t) >> 2), 0)) { 3340 device_printf(dev, "%s: failed0\n", __func__); 3341 return; 3342 } 3343 rcntxt_rsp = (q80_rcv_cntxt_destroy_rsp_t *)ha->hw.mbox; 3344 3345 err = Q8_MBX_RSP_STATUS(rcntxt_rsp->regcnt_status); 3346 3347 if (err) { 3348 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3349 } 3350 3351 ha->hw.flags.init_rx_cnxt = 0; 3352 return; 3353 } 3354 3355 /* 3356 * Name: qla_init_xmt_cntxt 3357 * Function: Creates the Transmit Context. 3358 */ 3359 static int 3360 qla_init_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx) 3361 { 3362 device_t dev; 3363 qla_hw_t *hw = &ha->hw; 3364 q80_rq_tx_cntxt_t *tcntxt; 3365 q80_rsp_tx_cntxt_t *tcntxt_rsp; 3366 uint32_t err; 3367 qla_hw_tx_cntxt_t *hw_tx_cntxt; 3368 uint32_t intr_idx; 3369 3370 hw_tx_cntxt = &hw->tx_cntxt[txr_idx]; 3371 3372 dev = ha->pci_dev; 3373 3374 /* 3375 * Create Transmit Context 3376 */ 3377 tcntxt = (q80_rq_tx_cntxt_t *)ha->hw.mbox; 3378 bzero(tcntxt, (sizeof (q80_rq_tx_cntxt_t))); 3379 3380 tcntxt->opcode = Q8_MBX_CREATE_TX_CNTXT; 3381 tcntxt->count_version = (sizeof (q80_rq_tx_cntxt_t) >> 2); 3382 tcntxt->count_version |= Q8_MBX_CMD_VERSION; 3383 3384 intr_idx = txr_idx; 3385 3386 #ifdef QL_ENABLE_ISCSI_TLV 3387 3388 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO | 3389 Q8_TX_CNTXT_CAP0_TC; 3390 3391 if (txr_idx >= (ha->hw.num_tx_rings >> 1)) { 3392 tcntxt->traffic_class = 1; 3393 } 3394 3395 intr_idx = txr_idx % (ha->hw.num_tx_rings >> 1); 3396 3397 #else 3398 tcntxt->cap0 = Q8_TX_CNTXT_CAP0_BASEFW | Q8_TX_CNTXT_CAP0_LSO; 3399 3400 #endif /* #ifdef QL_ENABLE_ISCSI_TLV */ 3401 3402 tcntxt->ntx_rings = 1; 3403 3404 tcntxt->tx_ring[0].paddr = 3405 qla_host_to_le64(hw_tx_cntxt->tx_ring_paddr); 3406 tcntxt->tx_ring[0].tx_consumer = 3407 qla_host_to_le64(hw_tx_cntxt->tx_cons_paddr); 3408 tcntxt->tx_ring[0].nentries = qla_host_to_le16(NUM_TX_DESCRIPTORS); 3409 3410 tcntxt->tx_ring[0].intr_id = qla_host_to_le16(hw->intr_id[intr_idx]); 3411 tcntxt->tx_ring[0].intr_src_bit = qla_host_to_le16(0); 3412 3413 hw_tx_cntxt->txr_free = NUM_TX_DESCRIPTORS; 3414 hw_tx_cntxt->txr_next = hw_tx_cntxt->txr_comp = 0; 3415 *(hw_tx_cntxt->tx_cons) = 0; 3416 3417 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt, 3418 (sizeof (q80_rq_tx_cntxt_t) >> 2), 3419 ha->hw.mbox, 3420 (sizeof(q80_rsp_tx_cntxt_t) >> 2), 0)) { 3421 device_printf(dev, "%s: failed0\n", __func__); 3422 return (-1); 3423 } 3424 tcntxt_rsp = (q80_rsp_tx_cntxt_t *)ha->hw.mbox; 3425 3426 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status); 3427 3428 if (err) { 3429 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3430 return -1; 3431 } 3432 3433 hw_tx_cntxt->tx_prod_reg = tcntxt_rsp->tx_ring[0].prod_index; 3434 hw_tx_cntxt->tx_cntxt_id = tcntxt_rsp->tx_ring[0].cntxt_id; 3435 3436 if (qla_config_intr_coalesce(ha, hw_tx_cntxt->tx_cntxt_id, 0, 0)) 3437 return (-1); 3438 3439 return (0); 3440 } 3441 3442 /* 3443 * Name: qla_del_xmt_cntxt 3444 * Function: Destroys the Transmit Context. 3445 */ 3446 static int 3447 qla_del_xmt_cntxt_i(qla_host_t *ha, uint32_t txr_idx) 3448 { 3449 device_t dev = ha->pci_dev; 3450 q80_tx_cntxt_destroy_t *tcntxt; 3451 q80_tx_cntxt_destroy_rsp_t *tcntxt_rsp; 3452 uint32_t err; 3453 3454 tcntxt = (q80_tx_cntxt_destroy_t *)ha->hw.mbox; 3455 bzero(tcntxt, (sizeof (q80_tx_cntxt_destroy_t))); 3456 3457 tcntxt->opcode = Q8_MBX_DESTROY_TX_CNTXT; 3458 tcntxt->count_version = (sizeof (q80_tx_cntxt_destroy_t) >> 2); 3459 tcntxt->count_version |= Q8_MBX_CMD_VERSION; 3460 3461 tcntxt->cntxt_id = ha->hw.tx_cntxt[txr_idx].tx_cntxt_id; 3462 3463 if (qla_mbx_cmd(ha, (uint32_t *)tcntxt, 3464 (sizeof (q80_tx_cntxt_destroy_t) >> 2), 3465 ha->hw.mbox, (sizeof (q80_tx_cntxt_destroy_rsp_t) >> 2), 0)) { 3466 device_printf(dev, "%s: failed0\n", __func__); 3467 return (-1); 3468 } 3469 tcntxt_rsp = (q80_tx_cntxt_destroy_rsp_t *)ha->hw.mbox; 3470 3471 err = Q8_MBX_RSP_STATUS(tcntxt_rsp->regcnt_status); 3472 3473 if (err) { 3474 device_printf(dev, "%s: failed1 [0x%08x]\n", __func__, err); 3475 return (-1); 3476 } 3477 3478 return (0); 3479 } 3480 static int 3481 qla_del_xmt_cntxt(qla_host_t *ha) 3482 { 3483 uint32_t i; 3484 int ret = 0; 3485 3486 if (!ha->hw.flags.init_tx_cnxt) 3487 return (ret); 3488 3489 for (i = 0; i < ha->hw.num_tx_rings; i++) { 3490 if ((ret = qla_del_xmt_cntxt_i(ha, i)) != 0) 3491 break; 3492 } 3493 ha->hw.flags.init_tx_cnxt = 0; 3494 3495 return (ret); 3496 } 3497 3498 static int 3499 qla_init_xmt_cntxt(qla_host_t *ha) 3500 { 3501 uint32_t i, j; 3502 3503 for (i = 0; i < ha->hw.num_tx_rings; i++) { 3504 if (qla_init_xmt_cntxt_i(ha, i) != 0) { 3505 for (j = 0; j < i; j++) { 3506 if (qla_del_xmt_cntxt_i(ha, j)) 3507 break; 3508 } 3509 return (-1); 3510 } 3511 } 3512 ha->hw.flags.init_tx_cnxt = 1; 3513 return (0); 3514 } 3515 3516 static int 3517 qla_hw_all_mcast(qla_host_t *ha, uint32_t add_mcast) 3518 { 3519 int i, nmcast; 3520 uint32_t count = 0; 3521 uint8_t *mcast; 3522 3523 nmcast = ha->hw.nmcast; 3524 3525 QL_DPRINT2(ha, (ha->pci_dev, 3526 "%s:[0x%x] enter nmcast = %d \n", __func__, add_mcast, nmcast)); 3527 3528 mcast = ha->hw.mac_addr_arr; 3529 memset(mcast, 0, (Q8_MAX_MAC_ADDRS * ETHER_ADDR_LEN)); 3530 3531 for (i = 0 ; ((i < Q8_MAX_NUM_MULTICAST_ADDRS) && nmcast); i++) { 3532 if ((ha->hw.mcast[i].addr[0] != 0) || 3533 (ha->hw.mcast[i].addr[1] != 0) || 3534 (ha->hw.mcast[i].addr[2] != 0) || 3535 (ha->hw.mcast[i].addr[3] != 0) || 3536 (ha->hw.mcast[i].addr[4] != 0) || 3537 (ha->hw.mcast[i].addr[5] != 0)) { 3538 bcopy(ha->hw.mcast[i].addr, mcast, ETHER_ADDR_LEN); 3539 mcast = mcast + ETHER_ADDR_LEN; 3540 count++; 3541 3542 device_printf(ha->pci_dev, 3543 "%s: %x:%x:%x:%x:%x:%x \n", 3544 __func__, ha->hw.mcast[i].addr[0], 3545 ha->hw.mcast[i].addr[1], ha->hw.mcast[i].addr[2], 3546 ha->hw.mcast[i].addr[3], ha->hw.mcast[i].addr[4], 3547 ha->hw.mcast[i].addr[5]); 3548 3549 if (count == Q8_MAX_MAC_ADDRS) { 3550 if (qla_config_mac_addr(ha, ha->hw.mac_addr_arr, 3551 add_mcast, count)) { 3552 device_printf(ha->pci_dev, 3553 "%s: failed\n", __func__); 3554 return (-1); 3555 } 3556 3557 count = 0; 3558 mcast = ha->hw.mac_addr_arr; 3559 memset(mcast, 0, 3560 (Q8_MAX_MAC_ADDRS * ETHER_ADDR_LEN)); 3561 } 3562 3563 nmcast--; 3564 } 3565 } 3566 3567 if (count) { 3568 if (qla_config_mac_addr(ha, ha->hw.mac_addr_arr, add_mcast, 3569 count)) { 3570 device_printf(ha->pci_dev, "%s: failed\n", __func__); 3571 return (-1); 3572 } 3573 } 3574 QL_DPRINT2(ha, (ha->pci_dev, 3575 "%s:[0x%x] exit nmcast = %d \n", __func__, add_mcast, nmcast)); 3576 3577 return 0; 3578 } 3579 3580 static int 3581 qla_hw_add_all_mcast(qla_host_t *ha) 3582 { 3583 int ret; 3584 3585 ret = qla_hw_all_mcast(ha, 1); 3586 3587 return (ret); 3588 } 3589 3590 int 3591 qla_hw_del_all_mcast(qla_host_t *ha) 3592 { 3593 int ret; 3594 3595 ret = qla_hw_all_mcast(ha, 0); 3596 3597 bzero(ha->hw.mcast, (sizeof (qla_mcast_t) * Q8_MAX_NUM_MULTICAST_ADDRS)); 3598 ha->hw.nmcast = 0; 3599 3600 return (ret); 3601 } 3602 3603 static int 3604 qla_hw_mac_addr_present(qla_host_t *ha, uint8_t *mta) 3605 { 3606 int i; 3607 3608 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) { 3609 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0) 3610 return (0); /* its been already added */ 3611 } 3612 return (-1); 3613 } 3614 3615 static int 3616 qla_hw_add_mcast(qla_host_t *ha, uint8_t *mta, uint32_t nmcast) 3617 { 3618 int i; 3619 3620 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) { 3621 if ((ha->hw.mcast[i].addr[0] == 0) && 3622 (ha->hw.mcast[i].addr[1] == 0) && 3623 (ha->hw.mcast[i].addr[2] == 0) && 3624 (ha->hw.mcast[i].addr[3] == 0) && 3625 (ha->hw.mcast[i].addr[4] == 0) && 3626 (ha->hw.mcast[i].addr[5] == 0)) { 3627 bcopy(mta, ha->hw.mcast[i].addr, Q8_MAC_ADDR_LEN); 3628 ha->hw.nmcast++; 3629 3630 mta = mta + ETHER_ADDR_LEN; 3631 nmcast--; 3632 3633 if (nmcast == 0) 3634 break; 3635 } 3636 } 3637 return 0; 3638 } 3639 3640 static int 3641 qla_hw_del_mcast(qla_host_t *ha, uint8_t *mta, uint32_t nmcast) 3642 { 3643 int i; 3644 3645 for (i = 0; i < Q8_MAX_NUM_MULTICAST_ADDRS; i++) { 3646 if (QL_MAC_CMP(ha->hw.mcast[i].addr, mta) == 0) { 3647 ha->hw.mcast[i].addr[0] = 0; 3648 ha->hw.mcast[i].addr[1] = 0; 3649 ha->hw.mcast[i].addr[2] = 0; 3650 ha->hw.mcast[i].addr[3] = 0; 3651 ha->hw.mcast[i].addr[4] = 0; 3652 ha->hw.mcast[i].addr[5] = 0; 3653 3654 ha->hw.nmcast--; 3655 3656 mta = mta + ETHER_ADDR_LEN; 3657 nmcast--; 3658 3659 if (nmcast == 0) 3660 break; 3661 } 3662 } 3663 return 0; 3664 } 3665 3666 /* 3667 * Name: ql_hw_set_multi 3668 * Function: Sets the Multicast Addresses provided by the host O.S into the 3669 * hardware (for the given interface) 3670 */ 3671 int 3672 ql_hw_set_multi(qla_host_t *ha, uint8_t *mcast_addr, uint32_t mcnt, 3673 uint32_t add_mac) 3674 { 3675 uint8_t *mta = mcast_addr; 3676 int i; 3677 int ret = 0; 3678 uint32_t count = 0; 3679 uint8_t *mcast; 3680 3681 mcast = ha->hw.mac_addr_arr; 3682 memset(mcast, 0, (Q8_MAX_MAC_ADDRS * ETHER_ADDR_LEN)); 3683 3684 for (i = 0; i < mcnt; i++) { 3685 if (mta[0] || mta[1] || mta[2] || mta[3] || mta[4] || mta[5]) { 3686 if (add_mac) { 3687 if (qla_hw_mac_addr_present(ha, mta) != 0) { 3688 bcopy(mta, mcast, ETHER_ADDR_LEN); 3689 mcast = mcast + ETHER_ADDR_LEN; 3690 count++; 3691 } 3692 } else { 3693 if (qla_hw_mac_addr_present(ha, mta) == 0) { 3694 bcopy(mta, mcast, ETHER_ADDR_LEN); 3695 mcast = mcast + ETHER_ADDR_LEN; 3696 count++; 3697 } 3698 } 3699 } 3700 if (count == Q8_MAX_MAC_ADDRS) { 3701 if (qla_config_mac_addr(ha, ha->hw.mac_addr_arr, 3702 add_mac, count)) { 3703 device_printf(ha->pci_dev, "%s: failed\n", 3704 __func__); 3705 return (-1); 3706 } 3707 3708 if (add_mac) { 3709 qla_hw_add_mcast(ha, ha->hw.mac_addr_arr, 3710 count); 3711 } else { 3712 qla_hw_del_mcast(ha, ha->hw.mac_addr_arr, 3713 count); 3714 } 3715 3716 count = 0; 3717 mcast = ha->hw.mac_addr_arr; 3718 memset(mcast, 0, (Q8_MAX_MAC_ADDRS * ETHER_ADDR_LEN)); 3719 } 3720 3721 mta += Q8_MAC_ADDR_LEN; 3722 } 3723 3724 if (count) { 3725 if (qla_config_mac_addr(ha, ha->hw.mac_addr_arr, add_mac, 3726 count)) { 3727 device_printf(ha->pci_dev, "%s: failed\n", __func__); 3728 return (-1); 3729 } 3730 if (add_mac) { 3731 qla_hw_add_mcast(ha, ha->hw.mac_addr_arr, count); 3732 } else { 3733 qla_hw_del_mcast(ha, ha->hw.mac_addr_arr, count); 3734 } 3735 } 3736 3737 return (ret); 3738 } 3739 3740 /* 3741 * Name: ql_hw_tx_done_locked 3742 * Function: Handle Transmit Completions 3743 */ 3744 void 3745 ql_hw_tx_done_locked(qla_host_t *ha, uint32_t txr_idx) 3746 { 3747 qla_tx_buf_t *txb; 3748 qla_hw_t *hw = &ha->hw; 3749 uint32_t comp_idx, comp_count = 0; 3750 qla_hw_tx_cntxt_t *hw_tx_cntxt; 3751 3752 hw_tx_cntxt = &hw->tx_cntxt[txr_idx]; 3753 3754 /* retrieve index of last entry in tx ring completed */ 3755 comp_idx = qla_le32_to_host(*(hw_tx_cntxt->tx_cons)); 3756 3757 while (comp_idx != hw_tx_cntxt->txr_comp) { 3758 txb = &ha->tx_ring[txr_idx].tx_buf[hw_tx_cntxt->txr_comp]; 3759 3760 hw_tx_cntxt->txr_comp++; 3761 if (hw_tx_cntxt->txr_comp == NUM_TX_DESCRIPTORS) 3762 hw_tx_cntxt->txr_comp = 0; 3763 3764 comp_count++; 3765 3766 if (txb->m_head) { 3767 if_inc_counter(ha->ifp, IFCOUNTER_OPACKETS, 1); 3768 3769 bus_dmamap_sync(ha->tx_tag, txb->map, 3770 BUS_DMASYNC_POSTWRITE); 3771 bus_dmamap_unload(ha->tx_tag, txb->map); 3772 m_freem(txb->m_head); 3773 3774 txb->m_head = NULL; 3775 } 3776 } 3777 3778 hw_tx_cntxt->txr_free += comp_count; 3779 3780 if (hw_tx_cntxt->txr_free > NUM_TX_DESCRIPTORS) 3781 device_printf(ha->pci_dev, "%s [%d]: txr_idx = %d txr_free = %d" 3782 "txr_next = %d txr_comp = %d\n", __func__, __LINE__, 3783 txr_idx, hw_tx_cntxt->txr_free, 3784 hw_tx_cntxt->txr_next, hw_tx_cntxt->txr_comp); 3785 3786 QL_ASSERT(ha, (hw_tx_cntxt->txr_free <= NUM_TX_DESCRIPTORS), \ 3787 ("%s [%d]: txr_idx = %d txr_free = %d txr_next = %d txr_comp = %d\n",\ 3788 __func__, __LINE__, txr_idx, hw_tx_cntxt->txr_free, \ 3789 hw_tx_cntxt->txr_next, hw_tx_cntxt->txr_comp)); 3790 3791 return; 3792 } 3793 3794 void 3795 ql_update_link_state(qla_host_t *ha) 3796 { 3797 uint32_t link_state = 0; 3798 uint32_t prev_link_state; 3799 3800 prev_link_state = ha->hw.link_up; 3801 3802 if (ha->ifp->if_drv_flags & IFF_DRV_RUNNING) { 3803 link_state = READ_REG32(ha, Q8_LINK_STATE); 3804 3805 if (ha->pci_func == 0) { 3806 link_state = (((link_state & 0xF) == 1)? 1 : 0); 3807 } else { 3808 link_state = ((((link_state >> 4)& 0xF) == 1)? 1 : 0); 3809 } 3810 } 3811 3812 atomic_store_rel_8(&ha->hw.link_up, (uint8_t)link_state); 3813 3814 if (prev_link_state != ha->hw.link_up) { 3815 if (ha->hw.link_up) { 3816 if_link_state_change(ha->ifp, LINK_STATE_UP); 3817 } else { 3818 if_link_state_change(ha->ifp, LINK_STATE_DOWN); 3819 } 3820 } 3821 return; 3822 } 3823 3824 int 3825 ql_hw_check_health(qla_host_t *ha) 3826 { 3827 uint32_t val; 3828 3829 ha->hw.health_count++; 3830 3831 if (ha->hw.health_count < 500) 3832 return 0; 3833 3834 ha->hw.health_count = 0; 3835 3836 val = READ_REG32(ha, Q8_ASIC_TEMPERATURE); 3837 3838 if (((val & 0xFFFF) == 2) || ((val & 0xFFFF) == 3) || 3839 (QL_ERR_INJECT(ha, INJCT_TEMPERATURE_FAILURE))) { 3840 device_printf(ha->pci_dev, "%s: Temperature Alert" 3841 " at ts_usecs %ld ts_reg = 0x%08x\n", 3842 __func__, qla_get_usec_timestamp(), val); 3843 3844 if (ha->hw.sp_log_stop_events & Q8_SP_LOG_STOP_TEMP_FAILURE) 3845 ha->hw.sp_log_stop = -1; 3846 3847 QL_INITIATE_RECOVERY(ha); 3848 return -1; 3849 } 3850 3851 val = READ_REG32(ha, Q8_FIRMWARE_HEARTBEAT); 3852 3853 if ((val != ha->hw.hbeat_value) && 3854 (!(QL_ERR_INJECT(ha, INJCT_HEARTBEAT_FAILURE)))) { 3855 ha->hw.hbeat_value = val; 3856 ha->hw.hbeat_failure = 0; 3857 return 0; 3858 } 3859 3860 ha->hw.hbeat_failure++; 3861 3862 if ((ha->dbg_level & 0x8000) && (ha->hw.hbeat_failure == 1)) 3863 device_printf(ha->pci_dev, "%s: Heartbeat Failue 1[0x%08x]\n", 3864 __func__, val); 3865 if (ha->hw.hbeat_failure < 2) /* we ignore the first failure */ 3866 return 0; 3867 else { 3868 uint32_t peg_halt_status1; 3869 uint32_t peg_halt_status2; 3870 3871 peg_halt_status1 = READ_REG32(ha, Q8_PEG_HALT_STATUS1); 3872 peg_halt_status2 = READ_REG32(ha, Q8_PEG_HALT_STATUS2); 3873 3874 device_printf(ha->pci_dev, 3875 "%s: Heartbeat Failue at ts_usecs = %ld " 3876 "fw_heart_beat = 0x%08x " 3877 "peg_halt_status1 = 0x%08x " 3878 "peg_halt_status2 = 0x%08x\n", 3879 __func__, qla_get_usec_timestamp(), val, 3880 peg_halt_status1, peg_halt_status2); 3881 3882 if (ha->hw.sp_log_stop_events & Q8_SP_LOG_STOP_HBEAT_FAILURE) 3883 ha->hw.sp_log_stop = -1; 3884 } 3885 QL_INITIATE_RECOVERY(ha); 3886 3887 return -1; 3888 } 3889 3890 static int 3891 qla_init_nic_func(qla_host_t *ha) 3892 { 3893 device_t dev; 3894 q80_init_nic_func_t *init_nic; 3895 q80_init_nic_func_rsp_t *init_nic_rsp; 3896 uint32_t err; 3897 3898 dev = ha->pci_dev; 3899 3900 init_nic = (q80_init_nic_func_t *)ha->hw.mbox; 3901 bzero(init_nic, sizeof(q80_init_nic_func_t)); 3902 3903 init_nic->opcode = Q8_MBX_INIT_NIC_FUNC; 3904 init_nic->count_version = (sizeof (q80_init_nic_func_t) >> 2); 3905 init_nic->count_version |= Q8_MBX_CMD_VERSION; 3906 3907 init_nic->options = Q8_INIT_NIC_REG_DCBX_CHNG_AEN; 3908 init_nic->options |= Q8_INIT_NIC_REG_SFP_CHNG_AEN; 3909 init_nic->options |= Q8_INIT_NIC_REG_IDC_AEN; 3910 3911 //qla_dump_buf8(ha, __func__, init_nic, sizeof (q80_init_nic_func_t)); 3912 if (qla_mbx_cmd(ha, (uint32_t *)init_nic, 3913 (sizeof (q80_init_nic_func_t) >> 2), 3914 ha->hw.mbox, (sizeof (q80_init_nic_func_rsp_t) >> 2), 0)) { 3915 device_printf(dev, "%s: failed\n", __func__); 3916 return -1; 3917 } 3918 3919 init_nic_rsp = (q80_init_nic_func_rsp_t *)ha->hw.mbox; 3920 // qla_dump_buf8(ha, __func__, init_nic_rsp, sizeof (q80_init_nic_func_rsp_t)); 3921 3922 err = Q8_MBX_RSP_STATUS(init_nic_rsp->regcnt_status); 3923 3924 if (err) { 3925 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 3926 } else { 3927 device_printf(dev, "%s: successful\n", __func__); 3928 } 3929 3930 return 0; 3931 } 3932 3933 static int 3934 qla_stop_nic_func(qla_host_t *ha) 3935 { 3936 device_t dev; 3937 q80_stop_nic_func_t *stop_nic; 3938 q80_stop_nic_func_rsp_t *stop_nic_rsp; 3939 uint32_t err; 3940 3941 dev = ha->pci_dev; 3942 3943 stop_nic = (q80_stop_nic_func_t *)ha->hw.mbox; 3944 bzero(stop_nic, sizeof(q80_stop_nic_func_t)); 3945 3946 stop_nic->opcode = Q8_MBX_STOP_NIC_FUNC; 3947 stop_nic->count_version = (sizeof (q80_stop_nic_func_t) >> 2); 3948 stop_nic->count_version |= Q8_MBX_CMD_VERSION; 3949 3950 stop_nic->options = Q8_STOP_NIC_DEREG_DCBX_CHNG_AEN; 3951 stop_nic->options |= Q8_STOP_NIC_DEREG_SFP_CHNG_AEN; 3952 3953 //qla_dump_buf8(ha, __func__, stop_nic, sizeof (q80_stop_nic_func_t)); 3954 if (qla_mbx_cmd(ha, (uint32_t *)stop_nic, 3955 (sizeof (q80_stop_nic_func_t) >> 2), 3956 ha->hw.mbox, (sizeof (q80_stop_nic_func_rsp_t) >> 2), 0)) { 3957 device_printf(dev, "%s: failed\n", __func__); 3958 return -1; 3959 } 3960 3961 stop_nic_rsp = (q80_stop_nic_func_rsp_t *)ha->hw.mbox; 3962 //qla_dump_buf8(ha, __func__, stop_nic_rsp, sizeof (q80_stop_nic_func_rsp_ t)); 3963 3964 err = Q8_MBX_RSP_STATUS(stop_nic_rsp->regcnt_status); 3965 3966 if (err) { 3967 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 3968 } 3969 3970 return 0; 3971 } 3972 3973 static int 3974 qla_query_fw_dcbx_caps(qla_host_t *ha) 3975 { 3976 device_t dev; 3977 q80_query_fw_dcbx_caps_t *fw_dcbx; 3978 q80_query_fw_dcbx_caps_rsp_t *fw_dcbx_rsp; 3979 uint32_t err; 3980 3981 dev = ha->pci_dev; 3982 3983 fw_dcbx = (q80_query_fw_dcbx_caps_t *)ha->hw.mbox; 3984 bzero(fw_dcbx, sizeof(q80_query_fw_dcbx_caps_t)); 3985 3986 fw_dcbx->opcode = Q8_MBX_GET_FW_DCBX_CAPS; 3987 fw_dcbx->count_version = (sizeof (q80_query_fw_dcbx_caps_t) >> 2); 3988 fw_dcbx->count_version |= Q8_MBX_CMD_VERSION; 3989 3990 ql_dump_buf8(ha, __func__, fw_dcbx, sizeof (q80_query_fw_dcbx_caps_t)); 3991 if (qla_mbx_cmd(ha, (uint32_t *)fw_dcbx, 3992 (sizeof (q80_query_fw_dcbx_caps_t) >> 2), 3993 ha->hw.mbox, (sizeof (q80_query_fw_dcbx_caps_rsp_t) >> 2), 0)) { 3994 device_printf(dev, "%s: failed\n", __func__); 3995 return -1; 3996 } 3997 3998 fw_dcbx_rsp = (q80_query_fw_dcbx_caps_rsp_t *)ha->hw.mbox; 3999 ql_dump_buf8(ha, __func__, fw_dcbx_rsp, 4000 sizeof (q80_query_fw_dcbx_caps_rsp_t)); 4001 4002 err = Q8_MBX_RSP_STATUS(fw_dcbx_rsp->regcnt_status); 4003 4004 if (err) { 4005 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4006 } 4007 4008 return 0; 4009 } 4010 4011 static int 4012 qla_idc_ack(qla_host_t *ha, uint32_t aen_mb1, uint32_t aen_mb2, 4013 uint32_t aen_mb3, uint32_t aen_mb4) 4014 { 4015 device_t dev; 4016 q80_idc_ack_t *idc_ack; 4017 q80_idc_ack_rsp_t *idc_ack_rsp; 4018 uint32_t err; 4019 int count = 300; 4020 4021 dev = ha->pci_dev; 4022 4023 idc_ack = (q80_idc_ack_t *)ha->hw.mbox; 4024 bzero(idc_ack, sizeof(q80_idc_ack_t)); 4025 4026 idc_ack->opcode = Q8_MBX_IDC_ACK; 4027 idc_ack->count_version = (sizeof (q80_idc_ack_t) >> 2); 4028 idc_ack->count_version |= Q8_MBX_CMD_VERSION; 4029 4030 idc_ack->aen_mb1 = aen_mb1; 4031 idc_ack->aen_mb2 = aen_mb2; 4032 idc_ack->aen_mb3 = aen_mb3; 4033 idc_ack->aen_mb4 = aen_mb4; 4034 4035 ha->hw.imd_compl= 0; 4036 4037 if (qla_mbx_cmd(ha, (uint32_t *)idc_ack, 4038 (sizeof (q80_idc_ack_t) >> 2), 4039 ha->hw.mbox, (sizeof (q80_idc_ack_rsp_t) >> 2), 0)) { 4040 device_printf(dev, "%s: failed\n", __func__); 4041 return -1; 4042 } 4043 4044 idc_ack_rsp = (q80_idc_ack_rsp_t *)ha->hw.mbox; 4045 4046 err = Q8_MBX_RSP_STATUS(idc_ack_rsp->regcnt_status); 4047 4048 if (err) { 4049 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4050 return(-1); 4051 } 4052 4053 while (count && !ha->hw.imd_compl) { 4054 qla_mdelay(__func__, 100); 4055 count--; 4056 } 4057 4058 if (!count) 4059 return -1; 4060 else 4061 device_printf(dev, "%s: count %d\n", __func__, count); 4062 4063 return (0); 4064 } 4065 4066 static int 4067 qla_set_port_config(qla_host_t *ha, uint32_t cfg_bits) 4068 { 4069 device_t dev; 4070 q80_set_port_cfg_t *pcfg; 4071 q80_set_port_cfg_rsp_t *pfg_rsp; 4072 uint32_t err; 4073 int count = 300; 4074 4075 dev = ha->pci_dev; 4076 4077 pcfg = (q80_set_port_cfg_t *)ha->hw.mbox; 4078 bzero(pcfg, sizeof(q80_set_port_cfg_t)); 4079 4080 pcfg->opcode = Q8_MBX_SET_PORT_CONFIG; 4081 pcfg->count_version = (sizeof (q80_set_port_cfg_t) >> 2); 4082 pcfg->count_version |= Q8_MBX_CMD_VERSION; 4083 4084 pcfg->cfg_bits = cfg_bits; 4085 4086 device_printf(dev, "%s: cfg_bits" 4087 " [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]" 4088 " [0x%x, 0x%x, 0x%x]\n", __func__, 4089 ((cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20), 4090 ((cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5), 4091 ((cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0)); 4092 4093 ha->hw.imd_compl= 0; 4094 4095 if (qla_mbx_cmd(ha, (uint32_t *)pcfg, 4096 (sizeof (q80_set_port_cfg_t) >> 2), 4097 ha->hw.mbox, (sizeof (q80_set_port_cfg_rsp_t) >> 2), 0)) { 4098 device_printf(dev, "%s: failed\n", __func__); 4099 return -1; 4100 } 4101 4102 pfg_rsp = (q80_set_port_cfg_rsp_t *)ha->hw.mbox; 4103 4104 err = Q8_MBX_RSP_STATUS(pfg_rsp->regcnt_status); 4105 4106 if (err == Q8_MBX_RSP_IDC_INTRMD_RSP) { 4107 while (count && !ha->hw.imd_compl) { 4108 qla_mdelay(__func__, 100); 4109 count--; 4110 } 4111 if (count) { 4112 device_printf(dev, "%s: count %d\n", __func__, count); 4113 4114 err = 0; 4115 } 4116 } 4117 4118 if (err) { 4119 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4120 return(-1); 4121 } 4122 4123 return (0); 4124 } 4125 4126 static int 4127 qla_get_minidump_tmplt_size(qla_host_t *ha, uint32_t *size) 4128 { 4129 uint32_t err; 4130 device_t dev = ha->pci_dev; 4131 q80_config_md_templ_size_t *md_size; 4132 q80_config_md_templ_size_rsp_t *md_size_rsp; 4133 4134 #ifndef QL_LDFLASH_FW 4135 4136 ql_minidump_template_hdr_t *hdr; 4137 4138 hdr = (ql_minidump_template_hdr_t *)ql83xx_minidump; 4139 *size = hdr->size_of_template; 4140 return (0); 4141 4142 #endif /* #ifdef QL_LDFLASH_FW */ 4143 4144 md_size = (q80_config_md_templ_size_t *) ha->hw.mbox; 4145 bzero(md_size, sizeof(q80_config_md_templ_size_t)); 4146 4147 md_size->opcode = Q8_MBX_GET_MINIDUMP_TMPLT_SIZE; 4148 md_size->count_version = (sizeof (q80_config_md_templ_size_t) >> 2); 4149 md_size->count_version |= Q8_MBX_CMD_VERSION; 4150 4151 if (qla_mbx_cmd(ha, (uint32_t *) md_size, 4152 (sizeof(q80_config_md_templ_size_t) >> 2), ha->hw.mbox, 4153 (sizeof(q80_config_md_templ_size_rsp_t) >> 2), 0)) { 4154 device_printf(dev, "%s: failed\n", __func__); 4155 4156 return (-1); 4157 } 4158 4159 md_size_rsp = (q80_config_md_templ_size_rsp_t *) ha->hw.mbox; 4160 4161 err = Q8_MBX_RSP_STATUS(md_size_rsp->regcnt_status); 4162 4163 if (err) { 4164 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4165 return(-1); 4166 } 4167 4168 *size = md_size_rsp->templ_size; 4169 4170 return (0); 4171 } 4172 4173 static int 4174 qla_get_port_config(qla_host_t *ha, uint32_t *cfg_bits) 4175 { 4176 device_t dev; 4177 q80_get_port_cfg_t *pcfg; 4178 q80_get_port_cfg_rsp_t *pcfg_rsp; 4179 uint32_t err; 4180 4181 dev = ha->pci_dev; 4182 4183 pcfg = (q80_get_port_cfg_t *)ha->hw.mbox; 4184 bzero(pcfg, sizeof(q80_get_port_cfg_t)); 4185 4186 pcfg->opcode = Q8_MBX_GET_PORT_CONFIG; 4187 pcfg->count_version = (sizeof (q80_get_port_cfg_t) >> 2); 4188 pcfg->count_version |= Q8_MBX_CMD_VERSION; 4189 4190 if (qla_mbx_cmd(ha, (uint32_t *)pcfg, 4191 (sizeof (q80_get_port_cfg_t) >> 2), 4192 ha->hw.mbox, (sizeof (q80_get_port_cfg_rsp_t) >> 2), 0)) { 4193 device_printf(dev, "%s: failed\n", __func__); 4194 return -1; 4195 } 4196 4197 pcfg_rsp = (q80_get_port_cfg_rsp_t *)ha->hw.mbox; 4198 4199 err = Q8_MBX_RSP_STATUS(pcfg_rsp->regcnt_status); 4200 4201 if (err) { 4202 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4203 return(-1); 4204 } 4205 4206 device_printf(dev, "%s: [cfg_bits, port type]" 4207 " [0x%08x, 0x%02x] [STD_PAUSE_DIR, PAUSE_TYPE, DCBX]" 4208 " [0x%x, 0x%x, 0x%x]\n", __func__, 4209 pcfg_rsp->cfg_bits, pcfg_rsp->phys_port_type, 4210 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_STDPAUSE_DIR_MASK)>>20), 4211 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_PAUSE_CFG_MASK) >> 5), 4212 ((pcfg_rsp->cfg_bits & Q8_PORT_CFG_BITS_DCBX_ENABLE) ? 1: 0) 4213 ); 4214 4215 *cfg_bits = pcfg_rsp->cfg_bits; 4216 4217 return (0); 4218 } 4219 4220 int 4221 ql_iscsi_pdu(qla_host_t *ha, struct mbuf *mp) 4222 { 4223 struct ether_vlan_header *eh; 4224 uint16_t etype; 4225 struct ip *ip = NULL; 4226 struct ip6_hdr *ip6 = NULL; 4227 struct tcphdr *th = NULL; 4228 uint32_t hdrlen; 4229 uint32_t offset; 4230 uint8_t buf[sizeof(struct ip6_hdr)]; 4231 4232 eh = mtod(mp, struct ether_vlan_header *); 4233 4234 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 4235 hdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; 4236 etype = ntohs(eh->evl_proto); 4237 } else { 4238 hdrlen = ETHER_HDR_LEN; 4239 etype = ntohs(eh->evl_encap_proto); 4240 } 4241 4242 if (etype == ETHERTYPE_IP) { 4243 offset = (hdrlen + sizeof (struct ip)); 4244 4245 if (mp->m_len >= offset) { 4246 ip = (struct ip *)(mp->m_data + hdrlen); 4247 } else { 4248 m_copydata(mp, hdrlen, sizeof (struct ip), buf); 4249 ip = (struct ip *)buf; 4250 } 4251 4252 if (ip->ip_p == IPPROTO_TCP) { 4253 hdrlen += ip->ip_hl << 2; 4254 offset = hdrlen + 4; 4255 4256 if (mp->m_len >= offset) { 4257 th = (struct tcphdr *)(mp->m_data + hdrlen); 4258 } else { 4259 m_copydata(mp, hdrlen, 4, buf); 4260 th = (struct tcphdr *)buf; 4261 } 4262 } 4263 4264 } else if (etype == ETHERTYPE_IPV6) { 4265 offset = (hdrlen + sizeof (struct ip6_hdr)); 4266 4267 if (mp->m_len >= offset) { 4268 ip6 = (struct ip6_hdr *)(mp->m_data + hdrlen); 4269 } else { 4270 m_copydata(mp, hdrlen, sizeof (struct ip6_hdr), buf); 4271 ip6 = (struct ip6_hdr *)buf; 4272 } 4273 4274 if (ip6->ip6_nxt == IPPROTO_TCP) { 4275 hdrlen += sizeof(struct ip6_hdr); 4276 offset = hdrlen + 4; 4277 4278 if (mp->m_len >= offset) { 4279 th = (struct tcphdr *)(mp->m_data + hdrlen); 4280 } else { 4281 m_copydata(mp, hdrlen, 4, buf); 4282 th = (struct tcphdr *)buf; 4283 } 4284 } 4285 } 4286 4287 if (th != NULL) { 4288 if ((th->th_sport == htons(3260)) || 4289 (th->th_dport == htons(3260))) 4290 return 0; 4291 } 4292 return (-1); 4293 } 4294 4295 void 4296 qla_hw_async_event(qla_host_t *ha) 4297 { 4298 switch (ha->hw.aen_mb0) { 4299 case 0x8101: 4300 (void)qla_idc_ack(ha, ha->hw.aen_mb1, ha->hw.aen_mb2, 4301 ha->hw.aen_mb3, ha->hw.aen_mb4); 4302 4303 break; 4304 4305 default: 4306 break; 4307 } 4308 4309 return; 4310 } 4311 4312 #ifdef QL_LDFLASH_FW 4313 static int 4314 ql_get_minidump_template(qla_host_t *ha) 4315 { 4316 uint32_t err; 4317 device_t dev = ha->pci_dev; 4318 q80_config_md_templ_cmd_t *md_templ; 4319 q80_config_md_templ_cmd_rsp_t *md_templ_rsp; 4320 4321 md_templ = (q80_config_md_templ_cmd_t *) ha->hw.mbox; 4322 bzero(md_templ, (sizeof (q80_config_md_templ_cmd_t))); 4323 4324 md_templ->opcode = Q8_MBX_GET_MINIDUMP_TMPLT; 4325 md_templ->count_version = ( sizeof(q80_config_md_templ_cmd_t) >> 2); 4326 md_templ->count_version |= Q8_MBX_CMD_VERSION; 4327 4328 md_templ->buf_addr = ha->hw.dma_buf.minidump.dma_addr; 4329 md_templ->buff_size = ha->hw.dma_buf.minidump.size; 4330 4331 if (qla_mbx_cmd(ha, (uint32_t *) md_templ, 4332 (sizeof(q80_config_md_templ_cmd_t) >> 2), 4333 ha->hw.mbox, 4334 (sizeof(q80_config_md_templ_cmd_rsp_t) >> 2), 0)) { 4335 device_printf(dev, "%s: failed\n", __func__); 4336 4337 return (-1); 4338 } 4339 4340 md_templ_rsp = (q80_config_md_templ_cmd_rsp_t *) ha->hw.mbox; 4341 4342 err = Q8_MBX_RSP_STATUS(md_templ_rsp->regcnt_status); 4343 4344 if (err) { 4345 device_printf(dev, "%s: failed [0x%08x]\n", __func__, err); 4346 return (-1); 4347 } 4348 4349 return (0); 4350 4351 } 4352 #endif /* #ifdef QL_LDFLASH_FW */ 4353 4354 /* 4355 * Minidump related functionality 4356 */ 4357 4358 static int ql_parse_template(qla_host_t *ha); 4359 4360 static uint32_t ql_rdcrb(qla_host_t *ha, 4361 ql_minidump_entry_rdcrb_t *crb_entry, 4362 uint32_t * data_buff); 4363 4364 static uint32_t ql_pollrd(qla_host_t *ha, 4365 ql_minidump_entry_pollrd_t *entry, 4366 uint32_t * data_buff); 4367 4368 static uint32_t ql_pollrd_modify_write(qla_host_t *ha, 4369 ql_minidump_entry_rd_modify_wr_with_poll_t *entry, 4370 uint32_t *data_buff); 4371 4372 static uint32_t ql_L2Cache(qla_host_t *ha, 4373 ql_minidump_entry_cache_t *cacheEntry, 4374 uint32_t * data_buff); 4375 4376 static uint32_t ql_L1Cache(qla_host_t *ha, 4377 ql_minidump_entry_cache_t *cacheEntry, 4378 uint32_t *data_buff); 4379 4380 static uint32_t ql_rdocm(qla_host_t *ha, 4381 ql_minidump_entry_rdocm_t *ocmEntry, 4382 uint32_t *data_buff); 4383 4384 static uint32_t ql_rdmem(qla_host_t *ha, 4385 ql_minidump_entry_rdmem_t *mem_entry, 4386 uint32_t *data_buff); 4387 4388 static uint32_t ql_rdrom(qla_host_t *ha, 4389 ql_minidump_entry_rdrom_t *romEntry, 4390 uint32_t *data_buff); 4391 4392 static uint32_t ql_rdmux(qla_host_t *ha, 4393 ql_minidump_entry_mux_t *muxEntry, 4394 uint32_t *data_buff); 4395 4396 static uint32_t ql_rdmux2(qla_host_t *ha, 4397 ql_minidump_entry_mux2_t *muxEntry, 4398 uint32_t *data_buff); 4399 4400 static uint32_t ql_rdqueue(qla_host_t *ha, 4401 ql_minidump_entry_queue_t *queueEntry, 4402 uint32_t *data_buff); 4403 4404 static uint32_t ql_cntrl(qla_host_t *ha, 4405 ql_minidump_template_hdr_t *template_hdr, 4406 ql_minidump_entry_cntrl_t *crbEntry); 4407 4408 static uint32_t 4409 ql_minidump_size(qla_host_t *ha) 4410 { 4411 uint32_t i, k; 4412 uint32_t size = 0; 4413 ql_minidump_template_hdr_t *hdr; 4414 4415 hdr = (ql_minidump_template_hdr_t *)ha->hw.dma_buf.minidump.dma_b; 4416 4417 i = 0x2; 4418 4419 for (k = 1; k < QL_DBG_CAP_SIZE_ARRAY_LEN; k++) { 4420 if (i & ha->hw.mdump_capture_mask) 4421 size += hdr->capture_size_array[k]; 4422 i = i << 1; 4423 } 4424 return (size); 4425 } 4426 4427 static void 4428 ql_free_minidump_buffer(qla_host_t *ha) 4429 { 4430 if (ha->hw.mdump_buffer != NULL) { 4431 free(ha->hw.mdump_buffer, M_QLA83XXBUF); 4432 ha->hw.mdump_buffer = NULL; 4433 ha->hw.mdump_buffer_size = 0; 4434 } 4435 return; 4436 } 4437 4438 static int 4439 ql_alloc_minidump_buffer(qla_host_t *ha) 4440 { 4441 ha->hw.mdump_buffer_size = ql_minidump_size(ha); 4442 4443 if (!ha->hw.mdump_buffer_size) 4444 return (-1); 4445 4446 ha->hw.mdump_buffer = malloc(ha->hw.mdump_buffer_size, M_QLA83XXBUF, 4447 M_NOWAIT); 4448 4449 if (ha->hw.mdump_buffer == NULL) 4450 return (-1); 4451 4452 return (0); 4453 } 4454 4455 static void 4456 ql_free_minidump_template_buffer(qla_host_t *ha) 4457 { 4458 if (ha->hw.mdump_template != NULL) { 4459 free(ha->hw.mdump_template, M_QLA83XXBUF); 4460 ha->hw.mdump_template = NULL; 4461 ha->hw.mdump_template_size = 0; 4462 } 4463 return; 4464 } 4465 4466 static int 4467 ql_alloc_minidump_template_buffer(qla_host_t *ha) 4468 { 4469 ha->hw.mdump_template_size = ha->hw.dma_buf.minidump.size; 4470 4471 ha->hw.mdump_template = malloc(ha->hw.mdump_template_size, 4472 M_QLA83XXBUF, M_NOWAIT); 4473 4474 if (ha->hw.mdump_template == NULL) 4475 return (-1); 4476 4477 return (0); 4478 } 4479 4480 static int 4481 ql_alloc_minidump_buffers(qla_host_t *ha) 4482 { 4483 int ret; 4484 4485 ret = ql_alloc_minidump_template_buffer(ha); 4486 4487 if (ret) 4488 return (ret); 4489 4490 ret = ql_alloc_minidump_buffer(ha); 4491 4492 if (ret) 4493 ql_free_minidump_template_buffer(ha); 4494 4495 return (ret); 4496 } 4497 4498 static uint32_t 4499 ql_validate_minidump_checksum(qla_host_t *ha) 4500 { 4501 uint64_t sum = 0; 4502 int count; 4503 uint32_t *template_buff; 4504 4505 count = ha->hw.dma_buf.minidump.size / sizeof (uint32_t); 4506 template_buff = ha->hw.dma_buf.minidump.dma_b; 4507 4508 while (count-- > 0) { 4509 sum += *template_buff++; 4510 } 4511 4512 while (sum >> 32) { 4513 sum = (sum & 0xFFFFFFFF) + (sum >> 32); 4514 } 4515 4516 return (~sum); 4517 } 4518 4519 int 4520 ql_minidump_init(qla_host_t *ha) 4521 { 4522 int ret = 0; 4523 uint32_t template_size = 0; 4524 device_t dev = ha->pci_dev; 4525 4526 /* 4527 * Get Minidump Template Size 4528 */ 4529 ret = qla_get_minidump_tmplt_size(ha, &template_size); 4530 4531 if (ret || (template_size == 0)) { 4532 device_printf(dev, "%s: failed [%d, %d]\n", __func__, ret, 4533 template_size); 4534 return (-1); 4535 } 4536 4537 /* 4538 * Allocate Memory for Minidump Template 4539 */ 4540 4541 ha->hw.dma_buf.minidump.alignment = 8; 4542 ha->hw.dma_buf.minidump.size = template_size; 4543 4544 #ifdef QL_LDFLASH_FW 4545 if (ql_alloc_dmabuf(ha, &ha->hw.dma_buf.minidump)) { 4546 device_printf(dev, "%s: minidump dma alloc failed\n", __func__); 4547 4548 return (-1); 4549 } 4550 ha->hw.dma_buf.flags.minidump = 1; 4551 4552 /* 4553 * Retrieve Minidump Template 4554 */ 4555 ret = ql_get_minidump_template(ha); 4556 #else 4557 ha->hw.dma_buf.minidump.dma_b = ql83xx_minidump; 4558 4559 #endif /* #ifdef QL_LDFLASH_FW */ 4560 4561 if (ret == 0) { 4562 ret = ql_validate_minidump_checksum(ha); 4563 4564 if (ret == 0) { 4565 ret = ql_alloc_minidump_buffers(ha); 4566 4567 if (ret == 0) 4568 ha->hw.mdump_init = 1; 4569 else 4570 device_printf(dev, 4571 "%s: ql_alloc_minidump_buffers" 4572 " failed\n", __func__); 4573 } else { 4574 device_printf(dev, "%s: ql_validate_minidump_checksum" 4575 " failed\n", __func__); 4576 } 4577 } else { 4578 device_printf(dev, "%s: ql_get_minidump_template failed\n", 4579 __func__); 4580 } 4581 4582 if (ret) 4583 ql_minidump_free(ha); 4584 4585 return (ret); 4586 } 4587 4588 static void 4589 ql_minidump_free(qla_host_t *ha) 4590 { 4591 ha->hw.mdump_init = 0; 4592 if (ha->hw.dma_buf.flags.minidump) { 4593 ha->hw.dma_buf.flags.minidump = 0; 4594 ql_free_dmabuf(ha, &ha->hw.dma_buf.minidump); 4595 } 4596 4597 ql_free_minidump_template_buffer(ha); 4598 ql_free_minidump_buffer(ha); 4599 4600 return; 4601 } 4602 4603 void 4604 ql_minidump(qla_host_t *ha) 4605 { 4606 if (!ha->hw.mdump_init) 4607 return; 4608 4609 if (ha->hw.mdump_done) 4610 return; 4611 ha->hw.mdump_usec_ts = qla_get_usec_timestamp(); 4612 ha->hw.mdump_start_seq_index = ql_stop_sequence(ha); 4613 4614 bzero(ha->hw.mdump_buffer, ha->hw.mdump_buffer_size); 4615 bzero(ha->hw.mdump_template, ha->hw.mdump_template_size); 4616 4617 bcopy(ha->hw.dma_buf.minidump.dma_b, ha->hw.mdump_template, 4618 ha->hw.mdump_template_size); 4619 4620 ql_parse_template(ha); 4621 4622 ql_start_sequence(ha, ha->hw.mdump_start_seq_index); 4623 4624 ha->hw.mdump_done = 1; 4625 4626 return; 4627 } 4628 4629 /* 4630 * helper routines 4631 */ 4632 static void 4633 ql_entry_err_chk(ql_minidump_entry_t *entry, uint32_t esize) 4634 { 4635 if (esize != entry->hdr.entry_capture_size) { 4636 entry->hdr.entry_capture_size = esize; 4637 entry->hdr.driver_flags |= QL_DBG_SIZE_ERR_FLAG; 4638 } 4639 return; 4640 } 4641 4642 static int 4643 ql_parse_template(qla_host_t *ha) 4644 { 4645 uint32_t num_of_entries, buff_level, e_cnt, esize; 4646 uint32_t rv = 0; 4647 char *dump_buff, *dbuff; 4648 int sane_start = 0, sane_end = 0; 4649 ql_minidump_template_hdr_t *template_hdr; 4650 ql_minidump_entry_t *entry; 4651 uint32_t capture_mask; 4652 uint32_t dump_size; 4653 4654 /* Setup parameters */ 4655 template_hdr = (ql_minidump_template_hdr_t *)ha->hw.mdump_template; 4656 4657 if (template_hdr->entry_type == TLHDR) 4658 sane_start = 1; 4659 4660 dump_buff = (char *) ha->hw.mdump_buffer; 4661 4662 num_of_entries = template_hdr->num_of_entries; 4663 4664 entry = (ql_minidump_entry_t *) ((char *)template_hdr 4665 + template_hdr->first_entry_offset ); 4666 4667 template_hdr->saved_state_array[QL_OCM0_ADDR_INDX] = 4668 template_hdr->ocm_window_array[ha->pci_func]; 4669 template_hdr->saved_state_array[QL_PCIE_FUNC_INDX] = ha->pci_func; 4670 4671 capture_mask = ha->hw.mdump_capture_mask; 4672 dump_size = ha->hw.mdump_buffer_size; 4673 4674 template_hdr->driver_capture_mask = capture_mask; 4675 4676 QL_DPRINT80(ha, (ha->pci_dev, 4677 "%s: sane_start = %d num_of_entries = %d " 4678 "capture_mask = 0x%x dump_size = %d \n", 4679 __func__, sane_start, num_of_entries, capture_mask, dump_size)); 4680 4681 for (buff_level = 0, e_cnt = 0; e_cnt < num_of_entries; e_cnt++) { 4682 /* 4683 * If the capture_mask of the entry does not match capture mask 4684 * skip the entry after marking the driver_flags indicator. 4685 */ 4686 4687 if (!(entry->hdr.entry_capture_mask & capture_mask)) { 4688 entry->hdr.driver_flags |= QL_DBG_SKIPPED_FLAG; 4689 entry = (ql_minidump_entry_t *) ((char *) entry 4690 + entry->hdr.entry_size); 4691 continue; 4692 } 4693 4694 /* 4695 * This is ONLY needed in implementations where 4696 * the capture buffer allocated is too small to capture 4697 * all of the required entries for a given capture mask. 4698 * We need to empty the buffer contents to a file 4699 * if possible, before processing the next entry 4700 * If the buff_full_flag is set, no further capture will happen 4701 * and all remaining non-control entries will be skipped. 4702 */ 4703 if (entry->hdr.entry_capture_size != 0) { 4704 if ((buff_level + entry->hdr.entry_capture_size) > 4705 dump_size) { 4706 /* Try to recover by emptying buffer to file */ 4707 entry->hdr.driver_flags |= QL_DBG_SKIPPED_FLAG; 4708 entry = (ql_minidump_entry_t *) ((char *) entry 4709 + entry->hdr.entry_size); 4710 continue; 4711 } 4712 } 4713 4714 /* 4715 * Decode the entry type and process it accordingly 4716 */ 4717 4718 switch (entry->hdr.entry_type) { 4719 case RDNOP: 4720 break; 4721 4722 case RDEND: 4723 sane_end++; 4724 break; 4725 4726 case RDCRB: 4727 dbuff = dump_buff + buff_level; 4728 esize = ql_rdcrb(ha, (void *)entry, (void *)dbuff); 4729 ql_entry_err_chk(entry, esize); 4730 buff_level += esize; 4731 break; 4732 4733 case POLLRD: 4734 dbuff = dump_buff + buff_level; 4735 esize = ql_pollrd(ha, (void *)entry, (void *)dbuff); 4736 ql_entry_err_chk(entry, esize); 4737 buff_level += esize; 4738 break; 4739 4740 case POLLRDMWR: 4741 dbuff = dump_buff + buff_level; 4742 esize = ql_pollrd_modify_write(ha, (void *)entry, 4743 (void *)dbuff); 4744 ql_entry_err_chk(entry, esize); 4745 buff_level += esize; 4746 break; 4747 4748 case L2ITG: 4749 case L2DTG: 4750 case L2DAT: 4751 case L2INS: 4752 dbuff = dump_buff + buff_level; 4753 esize = ql_L2Cache(ha, (void *)entry, (void *)dbuff); 4754 if (esize == -1) { 4755 entry->hdr.driver_flags |= QL_DBG_SKIPPED_FLAG; 4756 } else { 4757 ql_entry_err_chk(entry, esize); 4758 buff_level += esize; 4759 } 4760 break; 4761 4762 case L1DAT: 4763 case L1INS: 4764 dbuff = dump_buff + buff_level; 4765 esize = ql_L1Cache(ha, (void *)entry, (void *)dbuff); 4766 ql_entry_err_chk(entry, esize); 4767 buff_level += esize; 4768 break; 4769 4770 case RDOCM: 4771 dbuff = dump_buff + buff_level; 4772 esize = ql_rdocm(ha, (void *)entry, (void *)dbuff); 4773 ql_entry_err_chk(entry, esize); 4774 buff_level += esize; 4775 break; 4776 4777 case RDMEM: 4778 dbuff = dump_buff + buff_level; 4779 esize = ql_rdmem(ha, (void *)entry, (void *)dbuff); 4780 ql_entry_err_chk(entry, esize); 4781 buff_level += esize; 4782 break; 4783 4784 case BOARD: 4785 case RDROM: 4786 dbuff = dump_buff + buff_level; 4787 esize = ql_rdrom(ha, (void *)entry, (void *)dbuff); 4788 ql_entry_err_chk(entry, esize); 4789 buff_level += esize; 4790 break; 4791 4792 case RDMUX: 4793 dbuff = dump_buff + buff_level; 4794 esize = ql_rdmux(ha, (void *)entry, (void *)dbuff); 4795 ql_entry_err_chk(entry, esize); 4796 buff_level += esize; 4797 break; 4798 4799 case RDMUX2: 4800 dbuff = dump_buff + buff_level; 4801 esize = ql_rdmux2(ha, (void *)entry, (void *)dbuff); 4802 ql_entry_err_chk(entry, esize); 4803 buff_level += esize; 4804 break; 4805 4806 case QUEUE: 4807 dbuff = dump_buff + buff_level; 4808 esize = ql_rdqueue(ha, (void *)entry, (void *)dbuff); 4809 ql_entry_err_chk(entry, esize); 4810 buff_level += esize; 4811 break; 4812 4813 case CNTRL: 4814 if ((rv = ql_cntrl(ha, template_hdr, (void *)entry))) { 4815 entry->hdr.driver_flags |= QL_DBG_SKIPPED_FLAG; 4816 } 4817 break; 4818 default: 4819 entry->hdr.driver_flags |= QL_DBG_SKIPPED_FLAG; 4820 break; 4821 } 4822 /* next entry in the template */ 4823 entry = (ql_minidump_entry_t *) ((char *) entry 4824 + entry->hdr.entry_size); 4825 } 4826 4827 if (!sane_start || (sane_end > 1)) { 4828 device_printf(ha->pci_dev, 4829 "\n%s: Template configuration error. Check Template\n", 4830 __func__); 4831 } 4832 4833 QL_DPRINT80(ha, (ha->pci_dev, "%s: Minidump num of entries = %d\n", 4834 __func__, template_hdr->num_of_entries)); 4835 4836 return 0; 4837 } 4838 4839 /* 4840 * Read CRB operation. 4841 */ 4842 static uint32_t 4843 ql_rdcrb(qla_host_t *ha, ql_minidump_entry_rdcrb_t * crb_entry, 4844 uint32_t * data_buff) 4845 { 4846 int loop_cnt; 4847 int ret; 4848 uint32_t op_count, addr, stride, value = 0; 4849 4850 addr = crb_entry->addr; 4851 op_count = crb_entry->op_count; 4852 stride = crb_entry->addr_stride; 4853 4854 for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) { 4855 ret = ql_rdwr_indreg32(ha, addr, &value, 1); 4856 4857 if (ret) 4858 return (0); 4859 4860 *data_buff++ = addr; 4861 *data_buff++ = value; 4862 addr = addr + stride; 4863 } 4864 4865 /* 4866 * for testing purpose we return amount of data written 4867 */ 4868 return (op_count * (2 * sizeof(uint32_t))); 4869 } 4870 4871 /* 4872 * Handle L2 Cache. 4873 */ 4874 4875 static uint32_t 4876 ql_L2Cache(qla_host_t *ha, ql_minidump_entry_cache_t *cacheEntry, 4877 uint32_t * data_buff) 4878 { 4879 int i, k; 4880 int loop_cnt; 4881 int ret; 4882 4883 uint32_t read_value; 4884 uint32_t addr, read_addr, cntrl_addr, tag_reg_addr, cntl_value_w; 4885 uint32_t tag_value, read_cnt; 4886 volatile uint8_t cntl_value_r; 4887 long timeout; 4888 uint32_t data; 4889 4890 loop_cnt = cacheEntry->op_count; 4891 4892 read_addr = cacheEntry->read_addr; 4893 cntrl_addr = cacheEntry->control_addr; 4894 cntl_value_w = (uint32_t) cacheEntry->write_value; 4895 4896 tag_reg_addr = cacheEntry->tag_reg_addr; 4897 4898 tag_value = cacheEntry->init_tag_value; 4899 read_cnt = cacheEntry->read_addr_cnt; 4900 4901 for (i = 0; i < loop_cnt; i++) { 4902 ret = ql_rdwr_indreg32(ha, tag_reg_addr, &tag_value, 0); 4903 if (ret) 4904 return (0); 4905 4906 if (cacheEntry->write_value != 0) { 4907 4908 ret = ql_rdwr_indreg32(ha, cntrl_addr, 4909 &cntl_value_w, 0); 4910 if (ret) 4911 return (0); 4912 } 4913 4914 if (cacheEntry->poll_mask != 0) { 4915 4916 timeout = cacheEntry->poll_wait; 4917 4918 ret = ql_rdwr_indreg32(ha, cntrl_addr, &data, 1); 4919 if (ret) 4920 return (0); 4921 4922 cntl_value_r = (uint8_t)data; 4923 4924 while ((cntl_value_r & cacheEntry->poll_mask) != 0) { 4925 if (timeout) { 4926 qla_mdelay(__func__, 1); 4927 timeout--; 4928 } else 4929 break; 4930 4931 ret = ql_rdwr_indreg32(ha, cntrl_addr, 4932 &data, 1); 4933 if (ret) 4934 return (0); 4935 4936 cntl_value_r = (uint8_t)data; 4937 } 4938 if (!timeout) { 4939 /* Report timeout error. 4940 * core dump capture failed 4941 * Skip remaining entries. 4942 * Write buffer out to file 4943 * Use driver specific fields in template header 4944 * to report this error. 4945 */ 4946 return (-1); 4947 } 4948 } 4949 4950 addr = read_addr; 4951 for (k = 0; k < read_cnt; k++) { 4952 ret = ql_rdwr_indreg32(ha, addr, &read_value, 1); 4953 if (ret) 4954 return (0); 4955 4956 *data_buff++ = read_value; 4957 addr += cacheEntry->read_addr_stride; 4958 } 4959 4960 tag_value += cacheEntry->tag_value_stride; 4961 } 4962 4963 return (read_cnt * loop_cnt * sizeof(uint32_t)); 4964 } 4965 4966 /* 4967 * Handle L1 Cache. 4968 */ 4969 4970 static uint32_t 4971 ql_L1Cache(qla_host_t *ha, 4972 ql_minidump_entry_cache_t *cacheEntry, 4973 uint32_t *data_buff) 4974 { 4975 int ret; 4976 int i, k; 4977 int loop_cnt; 4978 4979 uint32_t read_value; 4980 uint32_t addr, read_addr, cntrl_addr, tag_reg_addr; 4981 uint32_t tag_value, read_cnt; 4982 uint32_t cntl_value_w; 4983 4984 loop_cnt = cacheEntry->op_count; 4985 4986 read_addr = cacheEntry->read_addr; 4987 cntrl_addr = cacheEntry->control_addr; 4988 cntl_value_w = (uint32_t) cacheEntry->write_value; 4989 4990 tag_reg_addr = cacheEntry->tag_reg_addr; 4991 4992 tag_value = cacheEntry->init_tag_value; 4993 read_cnt = cacheEntry->read_addr_cnt; 4994 4995 for (i = 0; i < loop_cnt; i++) { 4996 ret = ql_rdwr_indreg32(ha, tag_reg_addr, &tag_value, 0); 4997 if (ret) 4998 return (0); 4999 5000 ret = ql_rdwr_indreg32(ha, cntrl_addr, &cntl_value_w, 0); 5001 if (ret) 5002 return (0); 5003 5004 addr = read_addr; 5005 for (k = 0; k < read_cnt; k++) { 5006 ret = ql_rdwr_indreg32(ha, addr, &read_value, 1); 5007 if (ret) 5008 return (0); 5009 5010 *data_buff++ = read_value; 5011 addr += cacheEntry->read_addr_stride; 5012 } 5013 5014 tag_value += cacheEntry->tag_value_stride; 5015 } 5016 5017 return (read_cnt * loop_cnt * sizeof(uint32_t)); 5018 } 5019 5020 /* 5021 * Reading OCM memory 5022 */ 5023 5024 static uint32_t 5025 ql_rdocm(qla_host_t *ha, 5026 ql_minidump_entry_rdocm_t *ocmEntry, 5027 uint32_t *data_buff) 5028 { 5029 int i, loop_cnt; 5030 volatile uint32_t addr; 5031 volatile uint32_t value; 5032 5033 addr = ocmEntry->read_addr; 5034 loop_cnt = ocmEntry->op_count; 5035 5036 for (i = 0; i < loop_cnt; i++) { 5037 value = READ_REG32(ha, addr); 5038 *data_buff++ = value; 5039 addr += ocmEntry->read_addr_stride; 5040 } 5041 return (loop_cnt * sizeof(value)); 5042 } 5043 5044 /* 5045 * Read memory 5046 */ 5047 5048 static uint32_t 5049 ql_rdmem(qla_host_t *ha, 5050 ql_minidump_entry_rdmem_t *mem_entry, 5051 uint32_t *data_buff) 5052 { 5053 int ret; 5054 int i, loop_cnt; 5055 volatile uint32_t addr; 5056 q80_offchip_mem_val_t val; 5057 5058 addr = mem_entry->read_addr; 5059 5060 /* size in bytes / 16 */ 5061 loop_cnt = mem_entry->read_data_size / (sizeof(uint32_t) * 4); 5062 5063 for (i = 0; i < loop_cnt; i++) { 5064 ret = ql_rdwr_offchip_mem(ha, (addr & 0x0ffffffff), &val, 1); 5065 if (ret) 5066 return (0); 5067 5068 *data_buff++ = val.data_lo; 5069 *data_buff++ = val.data_hi; 5070 *data_buff++ = val.data_ulo; 5071 *data_buff++ = val.data_uhi; 5072 5073 addr += (sizeof(uint32_t) * 4); 5074 } 5075 5076 return (loop_cnt * (sizeof(uint32_t) * 4)); 5077 } 5078 5079 /* 5080 * Read Rom 5081 */ 5082 5083 static uint32_t 5084 ql_rdrom(qla_host_t *ha, 5085 ql_minidump_entry_rdrom_t *romEntry, 5086 uint32_t *data_buff) 5087 { 5088 int ret; 5089 int i, loop_cnt; 5090 uint32_t addr; 5091 uint32_t value; 5092 5093 addr = romEntry->read_addr; 5094 loop_cnt = romEntry->read_data_size; /* This is size in bytes */ 5095 loop_cnt /= sizeof(value); 5096 5097 for (i = 0; i < loop_cnt; i++) { 5098 ret = ql_rd_flash32(ha, addr, &value); 5099 if (ret) 5100 return (0); 5101 5102 *data_buff++ = value; 5103 addr += sizeof(value); 5104 } 5105 5106 return (loop_cnt * sizeof(value)); 5107 } 5108 5109 /* 5110 * Read MUX data 5111 */ 5112 5113 static uint32_t 5114 ql_rdmux(qla_host_t *ha, 5115 ql_minidump_entry_mux_t *muxEntry, 5116 uint32_t *data_buff) 5117 { 5118 int ret; 5119 int loop_cnt; 5120 uint32_t read_value, sel_value; 5121 uint32_t read_addr, select_addr; 5122 5123 select_addr = muxEntry->select_addr; 5124 sel_value = muxEntry->select_value; 5125 read_addr = muxEntry->read_addr; 5126 5127 for (loop_cnt = 0; loop_cnt < muxEntry->op_count; loop_cnt++) { 5128 ret = ql_rdwr_indreg32(ha, select_addr, &sel_value, 0); 5129 if (ret) 5130 return (0); 5131 5132 ret = ql_rdwr_indreg32(ha, read_addr, &read_value, 1); 5133 if (ret) 5134 return (0); 5135 5136 *data_buff++ = sel_value; 5137 *data_buff++ = read_value; 5138 5139 sel_value += muxEntry->select_value_stride; 5140 } 5141 5142 return (loop_cnt * (2 * sizeof(uint32_t))); 5143 } 5144 5145 static uint32_t 5146 ql_rdmux2(qla_host_t *ha, 5147 ql_minidump_entry_mux2_t *muxEntry, 5148 uint32_t *data_buff) 5149 { 5150 int ret; 5151 int loop_cnt; 5152 5153 uint32_t select_addr_1, select_addr_2; 5154 uint32_t select_value_1, select_value_2; 5155 uint32_t select_value_count, select_value_mask; 5156 uint32_t read_addr, read_value; 5157 5158 select_addr_1 = muxEntry->select_addr_1; 5159 select_addr_2 = muxEntry->select_addr_2; 5160 select_value_1 = muxEntry->select_value_1; 5161 select_value_2 = muxEntry->select_value_2; 5162 select_value_count = muxEntry->select_value_count; 5163 select_value_mask = muxEntry->select_value_mask; 5164 5165 read_addr = muxEntry->read_addr; 5166 5167 for (loop_cnt = 0; loop_cnt < select_value_count; loop_cnt++) { 5168 uint32_t temp_sel_val; 5169 5170 ret = ql_rdwr_indreg32(ha, select_addr_1, &select_value_1, 0); 5171 if (ret) 5172 return (0); 5173 5174 temp_sel_val = select_value_1 & select_value_mask; 5175 5176 ret = ql_rdwr_indreg32(ha, select_addr_2, &temp_sel_val, 0); 5177 if (ret) 5178 return (0); 5179 5180 ret = ql_rdwr_indreg32(ha, read_addr, &read_value, 1); 5181 if (ret) 5182 return (0); 5183 5184 *data_buff++ = temp_sel_val; 5185 *data_buff++ = read_value; 5186 5187 ret = ql_rdwr_indreg32(ha, select_addr_1, &select_value_2, 0); 5188 if (ret) 5189 return (0); 5190 5191 temp_sel_val = select_value_2 & select_value_mask; 5192 5193 ret = ql_rdwr_indreg32(ha, select_addr_2, &temp_sel_val, 0); 5194 if (ret) 5195 return (0); 5196 5197 ret = ql_rdwr_indreg32(ha, read_addr, &read_value, 1); 5198 if (ret) 5199 return (0); 5200 5201 *data_buff++ = temp_sel_val; 5202 *data_buff++ = read_value; 5203 5204 select_value_1 += muxEntry->select_value_stride; 5205 select_value_2 += muxEntry->select_value_stride; 5206 } 5207 5208 return (loop_cnt * (4 * sizeof(uint32_t))); 5209 } 5210 5211 /* 5212 * Handling Queue State Reads. 5213 */ 5214 5215 static uint32_t 5216 ql_rdqueue(qla_host_t *ha, 5217 ql_minidump_entry_queue_t *queueEntry, 5218 uint32_t *data_buff) 5219 { 5220 int ret; 5221 int loop_cnt, k; 5222 uint32_t read_value; 5223 uint32_t read_addr, read_stride, select_addr; 5224 uint32_t queue_id, read_cnt; 5225 5226 read_cnt = queueEntry->read_addr_cnt; 5227 read_stride = queueEntry->read_addr_stride; 5228 select_addr = queueEntry->select_addr; 5229 5230 for (loop_cnt = 0, queue_id = 0; loop_cnt < queueEntry->op_count; 5231 loop_cnt++) { 5232 ret = ql_rdwr_indreg32(ha, select_addr, &queue_id, 0); 5233 if (ret) 5234 return (0); 5235 5236 read_addr = queueEntry->read_addr; 5237 5238 for (k = 0; k < read_cnt; k++) { 5239 ret = ql_rdwr_indreg32(ha, read_addr, &read_value, 1); 5240 if (ret) 5241 return (0); 5242 5243 *data_buff++ = read_value; 5244 read_addr += read_stride; 5245 } 5246 5247 queue_id += queueEntry->queue_id_stride; 5248 } 5249 5250 return (loop_cnt * (read_cnt * sizeof(uint32_t))); 5251 } 5252 5253 /* 5254 * Handling control entries. 5255 */ 5256 5257 static uint32_t 5258 ql_cntrl(qla_host_t *ha, 5259 ql_minidump_template_hdr_t *template_hdr, 5260 ql_minidump_entry_cntrl_t *crbEntry) 5261 { 5262 int ret; 5263 int count; 5264 uint32_t opcode, read_value, addr, entry_addr; 5265 long timeout; 5266 5267 entry_addr = crbEntry->addr; 5268 5269 for (count = 0; count < crbEntry->op_count; count++) { 5270 opcode = crbEntry->opcode; 5271 5272 if (opcode & QL_DBG_OPCODE_WR) { 5273 ret = ql_rdwr_indreg32(ha, entry_addr, 5274 &crbEntry->value_1, 0); 5275 if (ret) 5276 return (0); 5277 5278 opcode &= ~QL_DBG_OPCODE_WR; 5279 } 5280 5281 if (opcode & QL_DBG_OPCODE_RW) { 5282 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 1); 5283 if (ret) 5284 return (0); 5285 5286 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 0); 5287 if (ret) 5288 return (0); 5289 5290 opcode &= ~QL_DBG_OPCODE_RW; 5291 } 5292 5293 if (opcode & QL_DBG_OPCODE_AND) { 5294 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 1); 5295 if (ret) 5296 return (0); 5297 5298 read_value &= crbEntry->value_2; 5299 opcode &= ~QL_DBG_OPCODE_AND; 5300 5301 if (opcode & QL_DBG_OPCODE_OR) { 5302 read_value |= crbEntry->value_3; 5303 opcode &= ~QL_DBG_OPCODE_OR; 5304 } 5305 5306 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 0); 5307 if (ret) 5308 return (0); 5309 } 5310 5311 if (opcode & QL_DBG_OPCODE_OR) { 5312 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 1); 5313 if (ret) 5314 return (0); 5315 5316 read_value |= crbEntry->value_3; 5317 5318 ret = ql_rdwr_indreg32(ha, entry_addr, &read_value, 0); 5319 if (ret) 5320 return (0); 5321 5322 opcode &= ~QL_DBG_OPCODE_OR; 5323 } 5324 5325 if (opcode & QL_DBG_OPCODE_POLL) { 5326 opcode &= ~QL_DBG_OPCODE_POLL; 5327 timeout = crbEntry->poll_timeout; 5328 addr = entry_addr; 5329 5330 ret = ql_rdwr_indreg32(ha, addr, &read_value, 1); 5331 if (ret) 5332 return (0); 5333 5334 while ((read_value & crbEntry->value_2) 5335 != crbEntry->value_1) { 5336 if (timeout) { 5337 qla_mdelay(__func__, 1); 5338 timeout--; 5339 } else 5340 break; 5341 5342 ret = ql_rdwr_indreg32(ha, addr, 5343 &read_value, 1); 5344 if (ret) 5345 return (0); 5346 } 5347 5348 if (!timeout) { 5349 /* 5350 * Report timeout error. 5351 * core dump capture failed 5352 * Skip remaining entries. 5353 * Write buffer out to file 5354 * Use driver specific fields in template header 5355 * to report this error. 5356 */ 5357 return (-1); 5358 } 5359 } 5360 5361 if (opcode & QL_DBG_OPCODE_RDSTATE) { 5362 /* 5363 * decide which address to use. 5364 */ 5365 if (crbEntry->state_index_a) { 5366 addr = template_hdr->saved_state_array[ 5367 crbEntry-> state_index_a]; 5368 } else { 5369 addr = entry_addr; 5370 } 5371 5372 ret = ql_rdwr_indreg32(ha, addr, &read_value, 1); 5373 if (ret) 5374 return (0); 5375 5376 template_hdr->saved_state_array[crbEntry->state_index_v] 5377 = read_value; 5378 opcode &= ~QL_DBG_OPCODE_RDSTATE; 5379 } 5380 5381 if (opcode & QL_DBG_OPCODE_WRSTATE) { 5382 /* 5383 * decide which value to use. 5384 */ 5385 if (crbEntry->state_index_v) { 5386 read_value = template_hdr->saved_state_array[ 5387 crbEntry->state_index_v]; 5388 } else { 5389 read_value = crbEntry->value_1; 5390 } 5391 /* 5392 * decide which address to use. 5393 */ 5394 if (crbEntry->state_index_a) { 5395 addr = template_hdr->saved_state_array[ 5396 crbEntry-> state_index_a]; 5397 } else { 5398 addr = entry_addr; 5399 } 5400 5401 ret = ql_rdwr_indreg32(ha, addr, &read_value, 0); 5402 if (ret) 5403 return (0); 5404 5405 opcode &= ~QL_DBG_OPCODE_WRSTATE; 5406 } 5407 5408 if (opcode & QL_DBG_OPCODE_MDSTATE) { 5409 /* Read value from saved state using index */ 5410 read_value = template_hdr->saved_state_array[ 5411 crbEntry->state_index_v]; 5412 5413 read_value <<= crbEntry->shl; /*Shift left operation */ 5414 read_value >>= crbEntry->shr; /*Shift right operation */ 5415 5416 if (crbEntry->value_2) { 5417 /* check if AND mask is provided */ 5418 read_value &= crbEntry->value_2; 5419 } 5420 5421 read_value |= crbEntry->value_3; /* OR operation */ 5422 read_value += crbEntry->value_1; /* increment op */ 5423 5424 /* Write value back to state area. */ 5425 5426 template_hdr->saved_state_array[crbEntry->state_index_v] 5427 = read_value; 5428 opcode &= ~QL_DBG_OPCODE_MDSTATE; 5429 } 5430 5431 entry_addr += crbEntry->addr_stride; 5432 } 5433 5434 return (0); 5435 } 5436 5437 /* 5438 * Handling rd poll entry. 5439 */ 5440 5441 static uint32_t 5442 ql_pollrd(qla_host_t *ha, ql_minidump_entry_pollrd_t *entry, 5443 uint32_t *data_buff) 5444 { 5445 int ret; 5446 int loop_cnt; 5447 uint32_t op_count, select_addr, select_value_stride, select_value; 5448 uint32_t read_addr, poll, mask, data; 5449 uint32_t wait_count = 0; 5450 5451 select_addr = entry->select_addr; 5452 read_addr = entry->read_addr; 5453 select_value = entry->select_value; 5454 select_value_stride = entry->select_value_stride; 5455 op_count = entry->op_count; 5456 poll = entry->poll; 5457 mask = entry->mask; 5458 5459 for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) { 5460 ret = ql_rdwr_indreg32(ha, select_addr, &select_value, 0); 5461 if (ret) 5462 return (0); 5463 5464 wait_count = 0; 5465 5466 while (wait_count < poll) { 5467 uint32_t temp; 5468 5469 ret = ql_rdwr_indreg32(ha, select_addr, &temp, 1); 5470 if (ret) 5471 return (0); 5472 5473 if ( (temp & mask) != 0 ) { 5474 break; 5475 } 5476 wait_count++; 5477 } 5478 5479 if (wait_count == poll) { 5480 device_printf(ha->pci_dev, 5481 "%s: Error in processing entry\n", __func__); 5482 device_printf(ha->pci_dev, 5483 "%s: wait_count <0x%x> poll <0x%x>\n", 5484 __func__, wait_count, poll); 5485 return 0; 5486 } 5487 5488 ret = ql_rdwr_indreg32(ha, read_addr, &data, 1); 5489 if (ret) 5490 return (0); 5491 5492 *data_buff++ = select_value; 5493 *data_buff++ = data; 5494 select_value = select_value + select_value_stride; 5495 } 5496 5497 /* 5498 * for testing purpose we return amount of data written 5499 */ 5500 return (loop_cnt * (2 * sizeof(uint32_t))); 5501 } 5502 5503 /* 5504 * Handling rd modify write poll entry. 5505 */ 5506 5507 static uint32_t 5508 ql_pollrd_modify_write(qla_host_t *ha, 5509 ql_minidump_entry_rd_modify_wr_with_poll_t *entry, 5510 uint32_t *data_buff) 5511 { 5512 int ret; 5513 uint32_t addr_1, addr_2, value_1, value_2, data; 5514 uint32_t poll, mask, modify_mask; 5515 uint32_t wait_count = 0; 5516 5517 addr_1 = entry->addr_1; 5518 addr_2 = entry->addr_2; 5519 value_1 = entry->value_1; 5520 value_2 = entry->value_2; 5521 5522 poll = entry->poll; 5523 mask = entry->mask; 5524 modify_mask = entry->modify_mask; 5525 5526 ret = ql_rdwr_indreg32(ha, addr_1, &value_1, 0); 5527 if (ret) 5528 return (0); 5529 5530 wait_count = 0; 5531 while (wait_count < poll) { 5532 uint32_t temp; 5533 5534 ret = ql_rdwr_indreg32(ha, addr_1, &temp, 1); 5535 if (ret) 5536 return (0); 5537 5538 if ( (temp & mask) != 0 ) { 5539 break; 5540 } 5541 wait_count++; 5542 } 5543 5544 if (wait_count == poll) { 5545 device_printf(ha->pci_dev, "%s Error in processing entry\n", 5546 __func__); 5547 } else { 5548 ret = ql_rdwr_indreg32(ha, addr_2, &data, 1); 5549 if (ret) 5550 return (0); 5551 5552 data = (data & modify_mask); 5553 5554 ret = ql_rdwr_indreg32(ha, addr_2, &data, 0); 5555 if (ret) 5556 return (0); 5557 5558 ret = ql_rdwr_indreg32(ha, addr_1, &value_2, 0); 5559 if (ret) 5560 return (0); 5561 5562 /* Poll again */ 5563 wait_count = 0; 5564 while (wait_count < poll) { 5565 uint32_t temp; 5566 5567 ret = ql_rdwr_indreg32(ha, addr_1, &temp, 1); 5568 if (ret) 5569 return (0); 5570 5571 if ( (temp & mask) != 0 ) { 5572 break; 5573 } 5574 wait_count++; 5575 } 5576 *data_buff++ = addr_2; 5577 *data_buff++ = data; 5578 } 5579 5580 /* 5581 * for testing purpose we return amount of data written 5582 */ 5583 return (2 * sizeof(uint32_t)); 5584 } 5585