b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * QLogic iSCSI Offload Driver |
| 4 | * Copyright (c) 2016 Cavium Inc. |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/pci.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/if_arp.h> |
| 11 | #include <scsi/iscsi_if.h> |
| 12 | #include <linux/inet.h> |
| 13 | #include <net/arp.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/kthread.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/if_vlan.h> |
| 18 | #include <linux/cpu.h> |
| 19 | #include <linux/iscsi_boot_sysfs.h> |
| 20 | |
| 21 | #include <scsi/scsi_cmnd.h> |
| 22 | #include <scsi/scsi_device.h> |
| 23 | #include <scsi/scsi_eh.h> |
| 24 | #include <scsi/scsi_host.h> |
| 25 | #include <scsi/scsi.h> |
| 26 | |
| 27 | #include "qedi.h" |
| 28 | #include "qedi_gbl.h" |
| 29 | #include "qedi_iscsi.h" |
| 30 | |
| 31 | static uint qedi_fw_debug; |
| 32 | module_param(qedi_fw_debug, uint, 0644); |
| 33 | MODULE_PARM_DESC(qedi_fw_debug, " Firmware debug level 0(default) to 3"); |
| 34 | |
| 35 | uint qedi_dbg_log = QEDI_LOG_WARN | QEDI_LOG_SCSI_TM; |
| 36 | module_param(qedi_dbg_log, uint, 0644); |
| 37 | MODULE_PARM_DESC(qedi_dbg_log, " Default debug level"); |
| 38 | |
| 39 | uint qedi_io_tracing; |
| 40 | module_param(qedi_io_tracing, uint, 0644); |
| 41 | MODULE_PARM_DESC(qedi_io_tracing, |
| 42 | " Enable logging of SCSI requests/completions into trace buffer. (default off)."); |
| 43 | |
| 44 | uint qedi_ll2_buf_size = 0x400; |
| 45 | module_param(qedi_ll2_buf_size, uint, 0644); |
| 46 | MODULE_PARM_DESC(qedi_ll2_buf_size, |
| 47 | "parameter to set ping packet size, default - 0x400, Jumbo packets - 0x2400."); |
| 48 | |
| 49 | const struct qed_iscsi_ops *qedi_ops; |
| 50 | static struct scsi_transport_template *qedi_scsi_transport; |
| 51 | static struct pci_driver qedi_pci_driver; |
| 52 | static DEFINE_PER_CPU(struct qedi_percpu_s, qedi_percpu); |
| 53 | static LIST_HEAD(qedi_udev_list); |
| 54 | /* Static function declaration */ |
| 55 | static int qedi_alloc_global_queues(struct qedi_ctx *qedi); |
| 56 | static void qedi_free_global_queues(struct qedi_ctx *qedi); |
| 57 | static struct qedi_cmd *qedi_get_cmd_from_tid(struct qedi_ctx *qedi, u32 tid); |
| 58 | static void qedi_reset_uio_rings(struct qedi_uio_dev *udev); |
| 59 | static void qedi_ll2_free_skbs(struct qedi_ctx *qedi); |
| 60 | static struct nvm_iscsi_block *qedi_get_nvram_block(struct qedi_ctx *qedi); |
| 61 | |
| 62 | static int qedi_iscsi_event_cb(void *context, u8 fw_event_code, void *fw_handle) |
| 63 | { |
| 64 | struct qedi_ctx *qedi; |
| 65 | struct qedi_endpoint *qedi_ep; |
| 66 | struct iscsi_eqe_data *data; |
| 67 | int rval = 0; |
| 68 | |
| 69 | if (!context || !fw_handle) { |
| 70 | QEDI_ERR(NULL, "Recv event with ctx NULL\n"); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
| 74 | qedi = (struct qedi_ctx *)context; |
| 75 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 76 | "Recv Event %d fw_handle %p\n", fw_event_code, fw_handle); |
| 77 | |
| 78 | data = (struct iscsi_eqe_data *)fw_handle; |
| 79 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 80 | "icid=0x%x conn_id=0x%x err-code=0x%x error-pdu-opcode-reserved=0x%x\n", |
| 81 | data->icid, data->conn_id, data->error_code, |
| 82 | data->error_pdu_opcode_reserved); |
| 83 | |
| 84 | qedi_ep = qedi->ep_tbl[data->icid]; |
| 85 | |
| 86 | if (!qedi_ep) { |
| 87 | QEDI_WARN(&qedi->dbg_ctx, |
| 88 | "Cannot process event, ep already disconnected, cid=0x%x\n", |
| 89 | data->icid); |
| 90 | WARN_ON(1); |
| 91 | return -ENODEV; |
| 92 | } |
| 93 | |
| 94 | switch (fw_event_code) { |
| 95 | case ISCSI_EVENT_TYPE_ASYN_CONNECT_COMPLETE: |
| 96 | if (qedi_ep->state == EP_STATE_OFLDCONN_START) |
| 97 | qedi_ep->state = EP_STATE_OFLDCONN_COMPL; |
| 98 | |
| 99 | wake_up_interruptible(&qedi_ep->tcp_ofld_wait); |
| 100 | break; |
| 101 | case ISCSI_EVENT_TYPE_ASYN_TERMINATE_DONE: |
| 102 | qedi_ep->state = EP_STATE_DISCONN_COMPL; |
| 103 | wake_up_interruptible(&qedi_ep->tcp_ofld_wait); |
| 104 | break; |
| 105 | case ISCSI_EVENT_TYPE_ISCSI_CONN_ERROR: |
| 106 | qedi_process_iscsi_error(qedi_ep, data); |
| 107 | break; |
| 108 | case ISCSI_EVENT_TYPE_ASYN_ABORT_RCVD: |
| 109 | case ISCSI_EVENT_TYPE_ASYN_SYN_RCVD: |
| 110 | case ISCSI_EVENT_TYPE_ASYN_MAX_RT_TIME: |
| 111 | case ISCSI_EVENT_TYPE_ASYN_MAX_RT_CNT: |
| 112 | case ISCSI_EVENT_TYPE_ASYN_MAX_KA_PROBES_CNT: |
| 113 | case ISCSI_EVENT_TYPE_ASYN_FIN_WAIT2: |
| 114 | case ISCSI_EVENT_TYPE_TCP_CONN_ERROR: |
| 115 | qedi_process_tcp_error(qedi_ep, data); |
| 116 | break; |
| 117 | default: |
| 118 | QEDI_ERR(&qedi->dbg_ctx, "Recv Unknown Event %u\n", |
| 119 | fw_event_code); |
| 120 | } |
| 121 | |
| 122 | return rval; |
| 123 | } |
| 124 | |
| 125 | static int qedi_uio_open(struct uio_info *uinfo, struct inode *inode) |
| 126 | { |
| 127 | struct qedi_uio_dev *udev = uinfo->priv; |
| 128 | struct qedi_ctx *qedi = udev->qedi; |
| 129 | |
| 130 | if (!capable(CAP_NET_ADMIN)) |
| 131 | return -EPERM; |
| 132 | |
| 133 | if (udev->uio_dev != -1) |
| 134 | return -EBUSY; |
| 135 | |
| 136 | rtnl_lock(); |
| 137 | udev->uio_dev = iminor(inode); |
| 138 | qedi_reset_uio_rings(udev); |
| 139 | set_bit(UIO_DEV_OPENED, &qedi->flags); |
| 140 | rtnl_unlock(); |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int qedi_uio_close(struct uio_info *uinfo, struct inode *inode) |
| 146 | { |
| 147 | struct qedi_uio_dev *udev = uinfo->priv; |
| 148 | struct qedi_ctx *qedi = udev->qedi; |
| 149 | |
| 150 | udev->uio_dev = -1; |
| 151 | clear_bit(UIO_DEV_OPENED, &qedi->flags); |
| 152 | qedi_ll2_free_skbs(qedi); |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static void __qedi_free_uio_rings(struct qedi_uio_dev *udev) |
| 157 | { |
| 158 | if (udev->uctrl) { |
| 159 | free_page((unsigned long)udev->uctrl); |
| 160 | udev->uctrl = NULL; |
| 161 | } |
| 162 | |
| 163 | if (udev->ll2_ring) { |
| 164 | free_page((unsigned long)udev->ll2_ring); |
| 165 | udev->ll2_ring = NULL; |
| 166 | } |
| 167 | |
| 168 | if (udev->ll2_buf) { |
| 169 | free_pages((unsigned long)udev->ll2_buf, 2); |
| 170 | udev->ll2_buf = NULL; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void __qedi_free_uio(struct qedi_uio_dev *udev) |
| 175 | { |
| 176 | uio_unregister_device(&udev->qedi_uinfo); |
| 177 | |
| 178 | __qedi_free_uio_rings(udev); |
| 179 | |
| 180 | pci_dev_put(udev->pdev); |
| 181 | kfree(udev); |
| 182 | } |
| 183 | |
| 184 | static void qedi_free_uio(struct qedi_uio_dev *udev) |
| 185 | { |
| 186 | if (!udev) |
| 187 | return; |
| 188 | |
| 189 | list_del_init(&udev->list); |
| 190 | __qedi_free_uio(udev); |
| 191 | } |
| 192 | |
| 193 | static void qedi_reset_uio_rings(struct qedi_uio_dev *udev) |
| 194 | { |
| 195 | struct qedi_ctx *qedi = NULL; |
| 196 | struct qedi_uio_ctrl *uctrl = NULL; |
| 197 | |
| 198 | qedi = udev->qedi; |
| 199 | uctrl = udev->uctrl; |
| 200 | |
| 201 | spin_lock_bh(&qedi->ll2_lock); |
| 202 | uctrl->host_rx_cons = 0; |
| 203 | uctrl->hw_rx_prod = 0; |
| 204 | uctrl->hw_rx_bd_prod = 0; |
| 205 | uctrl->host_rx_bd_cons = 0; |
| 206 | |
| 207 | memset(udev->ll2_ring, 0, udev->ll2_ring_size); |
| 208 | memset(udev->ll2_buf, 0, udev->ll2_buf_size); |
| 209 | spin_unlock_bh(&qedi->ll2_lock); |
| 210 | } |
| 211 | |
| 212 | static int __qedi_alloc_uio_rings(struct qedi_uio_dev *udev) |
| 213 | { |
| 214 | int rc = 0; |
| 215 | |
| 216 | if (udev->ll2_ring || udev->ll2_buf) |
| 217 | return rc; |
| 218 | |
| 219 | /* Memory for control area. */ |
| 220 | udev->uctrl = (void *)get_zeroed_page(GFP_KERNEL); |
| 221 | if (!udev->uctrl) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | /* Allocating memory for LL2 ring */ |
| 225 | udev->ll2_ring_size = QEDI_PAGE_SIZE; |
| 226 | udev->ll2_ring = (void *)get_zeroed_page(GFP_KERNEL | __GFP_COMP); |
| 227 | if (!udev->ll2_ring) { |
| 228 | rc = -ENOMEM; |
| 229 | goto exit_alloc_ring; |
| 230 | } |
| 231 | |
| 232 | /* Allocating memory for Tx/Rx pkt buffer */ |
| 233 | udev->ll2_buf_size = TX_RX_RING * qedi_ll2_buf_size; |
| 234 | udev->ll2_buf_size = QEDI_PAGE_ALIGN(udev->ll2_buf_size); |
| 235 | udev->ll2_buf = (void *)__get_free_pages(GFP_KERNEL | __GFP_COMP | |
| 236 | __GFP_ZERO, 2); |
| 237 | if (!udev->ll2_buf) { |
| 238 | rc = -ENOMEM; |
| 239 | goto exit_alloc_buf; |
| 240 | } |
| 241 | return rc; |
| 242 | |
| 243 | exit_alloc_buf: |
| 244 | free_page((unsigned long)udev->ll2_ring); |
| 245 | udev->ll2_ring = NULL; |
| 246 | exit_alloc_ring: |
| 247 | return rc; |
| 248 | } |
| 249 | |
| 250 | static int qedi_alloc_uio_rings(struct qedi_ctx *qedi) |
| 251 | { |
| 252 | struct qedi_uio_dev *udev = NULL; |
| 253 | int rc = 0; |
| 254 | |
| 255 | list_for_each_entry(udev, &qedi_udev_list, list) { |
| 256 | if (udev->pdev == qedi->pdev) { |
| 257 | udev->qedi = qedi; |
| 258 | if (__qedi_alloc_uio_rings(udev)) { |
| 259 | udev->qedi = NULL; |
| 260 | return -ENOMEM; |
| 261 | } |
| 262 | qedi->udev = udev; |
| 263 | return 0; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | udev = kzalloc(sizeof(*udev), GFP_KERNEL); |
| 268 | if (!udev) { |
| 269 | rc = -ENOMEM; |
| 270 | goto err_udev; |
| 271 | } |
| 272 | |
| 273 | udev->uio_dev = -1; |
| 274 | |
| 275 | udev->qedi = qedi; |
| 276 | udev->pdev = qedi->pdev; |
| 277 | |
| 278 | rc = __qedi_alloc_uio_rings(udev); |
| 279 | if (rc) |
| 280 | goto err_uctrl; |
| 281 | |
| 282 | list_add(&udev->list, &qedi_udev_list); |
| 283 | |
| 284 | pci_dev_get(udev->pdev); |
| 285 | qedi->udev = udev; |
| 286 | |
| 287 | udev->tx_pkt = udev->ll2_buf; |
| 288 | udev->rx_pkt = udev->ll2_buf + qedi_ll2_buf_size; |
| 289 | return 0; |
| 290 | |
| 291 | err_uctrl: |
| 292 | kfree(udev); |
| 293 | err_udev: |
| 294 | return -ENOMEM; |
| 295 | } |
| 296 | |
| 297 | static int qedi_init_uio(struct qedi_ctx *qedi) |
| 298 | { |
| 299 | struct qedi_uio_dev *udev = qedi->udev; |
| 300 | struct uio_info *uinfo; |
| 301 | int ret = 0; |
| 302 | |
| 303 | if (!udev) |
| 304 | return -ENOMEM; |
| 305 | |
| 306 | uinfo = &udev->qedi_uinfo; |
| 307 | |
| 308 | uinfo->mem[0].addr = (unsigned long)udev->uctrl; |
| 309 | uinfo->mem[0].size = sizeof(struct qedi_uio_ctrl); |
| 310 | uinfo->mem[0].memtype = UIO_MEM_LOGICAL; |
| 311 | |
| 312 | uinfo->mem[1].addr = (unsigned long)udev->ll2_ring; |
| 313 | uinfo->mem[1].size = udev->ll2_ring_size; |
| 314 | uinfo->mem[1].memtype = UIO_MEM_LOGICAL; |
| 315 | |
| 316 | uinfo->mem[2].addr = (unsigned long)udev->ll2_buf; |
| 317 | uinfo->mem[2].size = udev->ll2_buf_size; |
| 318 | uinfo->mem[2].memtype = UIO_MEM_LOGICAL; |
| 319 | |
| 320 | uinfo->name = "qedi_uio"; |
| 321 | uinfo->version = QEDI_MODULE_VERSION; |
| 322 | uinfo->irq = UIO_IRQ_CUSTOM; |
| 323 | |
| 324 | uinfo->open = qedi_uio_open; |
| 325 | uinfo->release = qedi_uio_close; |
| 326 | |
| 327 | if (udev->uio_dev == -1) { |
| 328 | if (!uinfo->priv) { |
| 329 | uinfo->priv = udev; |
| 330 | |
| 331 | ret = uio_register_device(&udev->pdev->dev, uinfo); |
| 332 | if (ret) { |
| 333 | QEDI_ERR(&qedi->dbg_ctx, |
| 334 | "UIO registration failed\n"); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | static int qedi_alloc_and_init_sb(struct qedi_ctx *qedi, |
| 343 | struct qed_sb_info *sb_info, u16 sb_id) |
| 344 | { |
| 345 | struct status_block_e4 *sb_virt; |
| 346 | dma_addr_t sb_phys; |
| 347 | int ret; |
| 348 | |
| 349 | sb_virt = dma_alloc_coherent(&qedi->pdev->dev, |
| 350 | sizeof(struct status_block_e4), &sb_phys, |
| 351 | GFP_KERNEL); |
| 352 | if (!sb_virt) { |
| 353 | QEDI_ERR(&qedi->dbg_ctx, |
| 354 | "Status block allocation failed for id = %d.\n", |
| 355 | sb_id); |
| 356 | return -ENOMEM; |
| 357 | } |
| 358 | |
| 359 | ret = qedi_ops->common->sb_init(qedi->cdev, sb_info, sb_virt, sb_phys, |
| 360 | sb_id, QED_SB_TYPE_STORAGE); |
| 361 | if (ret) { |
| 362 | dma_free_coherent(&qedi->pdev->dev, sizeof(*sb_virt), sb_virt, sb_phys); |
| 363 | QEDI_ERR(&qedi->dbg_ctx, |
| 364 | "Status block initialization failed for id = %d.\n", |
| 365 | sb_id); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static void qedi_free_sb(struct qedi_ctx *qedi) |
| 373 | { |
| 374 | struct qed_sb_info *sb_info; |
| 375 | int id; |
| 376 | |
| 377 | for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) { |
| 378 | sb_info = &qedi->sb_array[id]; |
| 379 | if (sb_info->sb_virt) |
| 380 | dma_free_coherent(&qedi->pdev->dev, |
| 381 | sizeof(*sb_info->sb_virt), |
| 382 | (void *)sb_info->sb_virt, |
| 383 | sb_info->sb_phys); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | static void qedi_free_fp(struct qedi_ctx *qedi) |
| 388 | { |
| 389 | kfree(qedi->fp_array); |
| 390 | kfree(qedi->sb_array); |
| 391 | } |
| 392 | |
| 393 | static void qedi_destroy_fp(struct qedi_ctx *qedi) |
| 394 | { |
| 395 | qedi_free_sb(qedi); |
| 396 | qedi_free_fp(qedi); |
| 397 | } |
| 398 | |
| 399 | static int qedi_alloc_fp(struct qedi_ctx *qedi) |
| 400 | { |
| 401 | int ret = 0; |
| 402 | |
| 403 | qedi->fp_array = kcalloc(MIN_NUM_CPUS_MSIX(qedi), |
| 404 | sizeof(struct qedi_fastpath), GFP_KERNEL); |
| 405 | if (!qedi->fp_array) { |
| 406 | QEDI_ERR(&qedi->dbg_ctx, |
| 407 | "fastpath fp array allocation failed.\n"); |
| 408 | return -ENOMEM; |
| 409 | } |
| 410 | |
| 411 | qedi->sb_array = kcalloc(MIN_NUM_CPUS_MSIX(qedi), |
| 412 | sizeof(struct qed_sb_info), GFP_KERNEL); |
| 413 | if (!qedi->sb_array) { |
| 414 | QEDI_ERR(&qedi->dbg_ctx, |
| 415 | "fastpath sb array allocation failed.\n"); |
| 416 | ret = -ENOMEM; |
| 417 | goto free_fp; |
| 418 | } |
| 419 | |
| 420 | return ret; |
| 421 | |
| 422 | free_fp: |
| 423 | qedi_free_fp(qedi); |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | static void qedi_int_fp(struct qedi_ctx *qedi) |
| 428 | { |
| 429 | struct qedi_fastpath *fp; |
| 430 | int id; |
| 431 | |
| 432 | memset(qedi->fp_array, 0, MIN_NUM_CPUS_MSIX(qedi) * |
| 433 | sizeof(*qedi->fp_array)); |
| 434 | memset(qedi->sb_array, 0, MIN_NUM_CPUS_MSIX(qedi) * |
| 435 | sizeof(*qedi->sb_array)); |
| 436 | |
| 437 | for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) { |
| 438 | fp = &qedi->fp_array[id]; |
| 439 | fp->sb_info = &qedi->sb_array[id]; |
| 440 | fp->sb_id = id; |
| 441 | fp->qedi = qedi; |
| 442 | snprintf(fp->name, sizeof(fp->name), "%s-fp-%d", |
| 443 | "qedi", id); |
| 444 | |
| 445 | /* fp_array[i] ---- irq cookie |
| 446 | * So init data which is needed in int ctx |
| 447 | */ |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | static int qedi_prepare_fp(struct qedi_ctx *qedi) |
| 452 | { |
| 453 | struct qedi_fastpath *fp; |
| 454 | int id, ret = 0; |
| 455 | |
| 456 | ret = qedi_alloc_fp(qedi); |
| 457 | if (ret) |
| 458 | goto err; |
| 459 | |
| 460 | qedi_int_fp(qedi); |
| 461 | |
| 462 | for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) { |
| 463 | fp = &qedi->fp_array[id]; |
| 464 | ret = qedi_alloc_and_init_sb(qedi, fp->sb_info, fp->sb_id); |
| 465 | if (ret) { |
| 466 | QEDI_ERR(&qedi->dbg_ctx, |
| 467 | "SB allocation and initialization failed.\n"); |
| 468 | ret = -EIO; |
| 469 | goto err_init; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return 0; |
| 474 | |
| 475 | err_init: |
| 476 | qedi_free_sb(qedi); |
| 477 | qedi_free_fp(qedi); |
| 478 | err: |
| 479 | return ret; |
| 480 | } |
| 481 | |
| 482 | static int qedi_setup_cid_que(struct qedi_ctx *qedi) |
| 483 | { |
| 484 | int i; |
| 485 | |
| 486 | qedi->cid_que.cid_que_base = kmalloc_array(qedi->max_active_conns, |
| 487 | sizeof(u32), GFP_KERNEL); |
| 488 | if (!qedi->cid_que.cid_que_base) |
| 489 | return -ENOMEM; |
| 490 | |
| 491 | qedi->cid_que.conn_cid_tbl = kmalloc_array(qedi->max_active_conns, |
| 492 | sizeof(struct qedi_conn *), |
| 493 | GFP_KERNEL); |
| 494 | if (!qedi->cid_que.conn_cid_tbl) { |
| 495 | kfree(qedi->cid_que.cid_que_base); |
| 496 | qedi->cid_que.cid_que_base = NULL; |
| 497 | return -ENOMEM; |
| 498 | } |
| 499 | |
| 500 | qedi->cid_que.cid_que = (u32 *)qedi->cid_que.cid_que_base; |
| 501 | qedi->cid_que.cid_q_prod_idx = 0; |
| 502 | qedi->cid_que.cid_q_cons_idx = 0; |
| 503 | qedi->cid_que.cid_q_max_idx = qedi->max_active_conns; |
| 504 | qedi->cid_que.cid_free_cnt = qedi->max_active_conns; |
| 505 | |
| 506 | for (i = 0; i < qedi->max_active_conns; i++) { |
| 507 | qedi->cid_que.cid_que[i] = i; |
| 508 | qedi->cid_que.conn_cid_tbl[i] = NULL; |
| 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static void qedi_release_cid_que(struct qedi_ctx *qedi) |
| 515 | { |
| 516 | kfree(qedi->cid_que.cid_que_base); |
| 517 | qedi->cid_que.cid_que_base = NULL; |
| 518 | |
| 519 | kfree(qedi->cid_que.conn_cid_tbl); |
| 520 | qedi->cid_que.conn_cid_tbl = NULL; |
| 521 | } |
| 522 | |
| 523 | static int qedi_init_id_tbl(struct qedi_portid_tbl *id_tbl, u16 size, |
| 524 | u16 start_id, u16 next) |
| 525 | { |
| 526 | id_tbl->start = start_id; |
| 527 | id_tbl->max = size; |
| 528 | id_tbl->next = next; |
| 529 | spin_lock_init(&id_tbl->lock); |
| 530 | id_tbl->table = kcalloc(BITS_TO_LONGS(size), sizeof(long), GFP_KERNEL); |
| 531 | if (!id_tbl->table) |
| 532 | return -ENOMEM; |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static void qedi_free_id_tbl(struct qedi_portid_tbl *id_tbl) |
| 538 | { |
| 539 | kfree(id_tbl->table); |
| 540 | id_tbl->table = NULL; |
| 541 | } |
| 542 | |
| 543 | int qedi_alloc_id(struct qedi_portid_tbl *id_tbl, u16 id) |
| 544 | { |
| 545 | int ret = -1; |
| 546 | |
| 547 | id -= id_tbl->start; |
| 548 | if (id >= id_tbl->max) |
| 549 | return ret; |
| 550 | |
| 551 | spin_lock(&id_tbl->lock); |
| 552 | if (!test_bit(id, id_tbl->table)) { |
| 553 | set_bit(id, id_tbl->table); |
| 554 | ret = 0; |
| 555 | } |
| 556 | spin_unlock(&id_tbl->lock); |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | u16 qedi_alloc_new_id(struct qedi_portid_tbl *id_tbl) |
| 561 | { |
| 562 | u16 id; |
| 563 | |
| 564 | spin_lock(&id_tbl->lock); |
| 565 | id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next); |
| 566 | if (id >= id_tbl->max) { |
| 567 | id = QEDI_LOCAL_PORT_INVALID; |
| 568 | if (id_tbl->next != 0) { |
| 569 | id = find_first_zero_bit(id_tbl->table, id_tbl->next); |
| 570 | if (id >= id_tbl->next) |
| 571 | id = QEDI_LOCAL_PORT_INVALID; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (id < id_tbl->max) { |
| 576 | set_bit(id, id_tbl->table); |
| 577 | id_tbl->next = (id + 1) & (id_tbl->max - 1); |
| 578 | id += id_tbl->start; |
| 579 | } |
| 580 | |
| 581 | spin_unlock(&id_tbl->lock); |
| 582 | |
| 583 | return id; |
| 584 | } |
| 585 | |
| 586 | void qedi_free_id(struct qedi_portid_tbl *id_tbl, u16 id) |
| 587 | { |
| 588 | if (id == QEDI_LOCAL_PORT_INVALID) |
| 589 | return; |
| 590 | |
| 591 | id -= id_tbl->start; |
| 592 | if (id >= id_tbl->max) |
| 593 | return; |
| 594 | |
| 595 | clear_bit(id, id_tbl->table); |
| 596 | } |
| 597 | |
| 598 | static void qedi_cm_free_mem(struct qedi_ctx *qedi) |
| 599 | { |
| 600 | kfree(qedi->ep_tbl); |
| 601 | qedi->ep_tbl = NULL; |
| 602 | qedi_free_id_tbl(&qedi->lcl_port_tbl); |
| 603 | } |
| 604 | |
| 605 | static int qedi_cm_alloc_mem(struct qedi_ctx *qedi) |
| 606 | { |
| 607 | u16 port_id; |
| 608 | |
| 609 | qedi->ep_tbl = kzalloc((qedi->max_active_conns * |
| 610 | sizeof(struct qedi_endpoint *)), GFP_KERNEL); |
| 611 | if (!qedi->ep_tbl) |
| 612 | return -ENOMEM; |
| 613 | port_id = prandom_u32() % QEDI_LOCAL_PORT_RANGE; |
| 614 | if (qedi_init_id_tbl(&qedi->lcl_port_tbl, QEDI_LOCAL_PORT_RANGE, |
| 615 | QEDI_LOCAL_PORT_MIN, port_id)) { |
| 616 | qedi_cm_free_mem(qedi); |
| 617 | return -ENOMEM; |
| 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static struct qedi_ctx *qedi_host_alloc(struct pci_dev *pdev) |
| 624 | { |
| 625 | struct Scsi_Host *shost; |
| 626 | struct qedi_ctx *qedi = NULL; |
| 627 | |
| 628 | shost = iscsi_host_alloc(&qedi_host_template, |
| 629 | sizeof(struct qedi_ctx), 0); |
| 630 | if (!shost) { |
| 631 | QEDI_ERR(NULL, "Could not allocate shost\n"); |
| 632 | goto exit_setup_shost; |
| 633 | } |
| 634 | |
| 635 | shost->max_id = QEDI_MAX_ISCSI_CONNS_PER_HBA - 1; |
| 636 | shost->max_channel = 0; |
| 637 | shost->max_lun = ~0; |
| 638 | shost->max_cmd_len = 16; |
| 639 | shost->transportt = qedi_scsi_transport; |
| 640 | |
| 641 | qedi = iscsi_host_priv(shost); |
| 642 | memset(qedi, 0, sizeof(*qedi)); |
| 643 | qedi->shost = shost; |
| 644 | qedi->dbg_ctx.host_no = shost->host_no; |
| 645 | qedi->pdev = pdev; |
| 646 | qedi->dbg_ctx.pdev = pdev; |
| 647 | qedi->max_active_conns = ISCSI_MAX_SESS_PER_HBA; |
| 648 | qedi->max_sqes = QEDI_SQ_SIZE; |
| 649 | |
| 650 | shost->nr_hw_queues = MIN_NUM_CPUS_MSIX(qedi); |
| 651 | |
| 652 | pci_set_drvdata(pdev, qedi); |
| 653 | |
| 654 | exit_setup_shost: |
| 655 | return qedi; |
| 656 | } |
| 657 | |
| 658 | static int qedi_ll2_rx(void *cookie, struct sk_buff *skb, u32 arg1, u32 arg2) |
| 659 | { |
| 660 | struct qedi_ctx *qedi = (struct qedi_ctx *)cookie; |
| 661 | struct qedi_uio_dev *udev; |
| 662 | struct qedi_uio_ctrl *uctrl; |
| 663 | struct skb_work_list *work; |
| 664 | struct ethhdr *eh; |
| 665 | |
| 666 | if (!qedi) { |
| 667 | QEDI_ERR(NULL, "qedi is NULL\n"); |
| 668 | return -1; |
| 669 | } |
| 670 | |
| 671 | if (!test_bit(UIO_DEV_OPENED, &qedi->flags)) { |
| 672 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_UIO, |
| 673 | "UIO DEV is not opened\n"); |
| 674 | kfree_skb(skb); |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | eh = (struct ethhdr *)skb->data; |
| 679 | /* Undo VLAN encapsulation */ |
| 680 | if (eh->h_proto == htons(ETH_P_8021Q)) { |
| 681 | memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2); |
| 682 | eh = (struct ethhdr *)skb_pull(skb, VLAN_HLEN); |
| 683 | skb_reset_mac_header(skb); |
| 684 | } |
| 685 | |
| 686 | /* Filter out non FIP/FCoE frames here to free them faster */ |
| 687 | if (eh->h_proto != htons(ETH_P_ARP) && |
| 688 | eh->h_proto != htons(ETH_P_IP) && |
| 689 | eh->h_proto != htons(ETH_P_IPV6)) { |
| 690 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_LL2, |
| 691 | "Dropping frame ethertype [0x%x] len [0x%x].\n", |
| 692 | eh->h_proto, skb->len); |
| 693 | kfree_skb(skb); |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_LL2, |
| 698 | "Allowed frame ethertype [0x%x] len [0x%x].\n", |
| 699 | eh->h_proto, skb->len); |
| 700 | |
| 701 | udev = qedi->udev; |
| 702 | uctrl = udev->uctrl; |
| 703 | |
| 704 | work = kzalloc(sizeof(*work), GFP_ATOMIC); |
| 705 | if (!work) { |
| 706 | QEDI_WARN(&qedi->dbg_ctx, |
| 707 | "Could not allocate work so dropping frame.\n"); |
| 708 | kfree_skb(skb); |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | INIT_LIST_HEAD(&work->list); |
| 713 | work->skb = skb; |
| 714 | |
| 715 | if (skb_vlan_tag_present(skb)) |
| 716 | work->vlan_id = skb_vlan_tag_get(skb); |
| 717 | |
| 718 | if (work->vlan_id) |
| 719 | __vlan_insert_tag(work->skb, htons(ETH_P_8021Q), work->vlan_id); |
| 720 | |
| 721 | spin_lock_bh(&qedi->ll2_lock); |
| 722 | list_add_tail(&work->list, &qedi->ll2_skb_list); |
| 723 | spin_unlock_bh(&qedi->ll2_lock); |
| 724 | |
| 725 | wake_up_process(qedi->ll2_recv_thread); |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | /* map this skb to iscsiuio mmaped region */ |
| 731 | static int qedi_ll2_process_skb(struct qedi_ctx *qedi, struct sk_buff *skb, |
| 732 | u16 vlan_id) |
| 733 | { |
| 734 | struct qedi_uio_dev *udev = NULL; |
| 735 | struct qedi_uio_ctrl *uctrl = NULL; |
| 736 | struct qedi_rx_bd rxbd; |
| 737 | struct qedi_rx_bd *p_rxbd; |
| 738 | u32 rx_bd_prod; |
| 739 | void *pkt; |
| 740 | int len = 0; |
| 741 | u32 prod; |
| 742 | |
| 743 | if (!qedi) { |
| 744 | QEDI_ERR(NULL, "qedi is NULL\n"); |
| 745 | return -1; |
| 746 | } |
| 747 | |
| 748 | udev = qedi->udev; |
| 749 | uctrl = udev->uctrl; |
| 750 | |
| 751 | ++uctrl->hw_rx_prod_cnt; |
| 752 | prod = (uctrl->hw_rx_prod + 1) % RX_RING; |
| 753 | |
| 754 | pkt = udev->rx_pkt + (prod * qedi_ll2_buf_size); |
| 755 | len = min_t(u32, skb->len, (u32)qedi_ll2_buf_size); |
| 756 | memcpy(pkt, skb->data, len); |
| 757 | |
| 758 | memset(&rxbd, 0, sizeof(rxbd)); |
| 759 | rxbd.rx_pkt_index = prod; |
| 760 | rxbd.rx_pkt_len = len; |
| 761 | rxbd.vlan_id = vlan_id; |
| 762 | |
| 763 | uctrl->hw_rx_bd_prod = (uctrl->hw_rx_bd_prod + 1) % QEDI_NUM_RX_BD; |
| 764 | rx_bd_prod = uctrl->hw_rx_bd_prod; |
| 765 | p_rxbd = (struct qedi_rx_bd *)udev->ll2_ring; |
| 766 | p_rxbd += rx_bd_prod; |
| 767 | |
| 768 | memcpy(p_rxbd, &rxbd, sizeof(rxbd)); |
| 769 | |
| 770 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_LL2, |
| 771 | "hw_rx_prod [%d] prod [%d] hw_rx_bd_prod [%d] rx_pkt_idx [%d] rx_len [%d].\n", |
| 772 | uctrl->hw_rx_prod, prod, uctrl->hw_rx_bd_prod, |
| 773 | rxbd.rx_pkt_index, rxbd.rx_pkt_len); |
| 774 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_LL2, |
| 775 | "host_rx_cons [%d] hw_rx_bd_cons [%d].\n", |
| 776 | uctrl->host_rx_cons, uctrl->host_rx_bd_cons); |
| 777 | |
| 778 | uctrl->hw_rx_prod = prod; |
| 779 | |
| 780 | /* notify the iscsiuio about new packet */ |
| 781 | uio_event_notify(&udev->qedi_uinfo); |
| 782 | |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static void qedi_ll2_free_skbs(struct qedi_ctx *qedi) |
| 787 | { |
| 788 | struct skb_work_list *work, *work_tmp; |
| 789 | |
| 790 | spin_lock_bh(&qedi->ll2_lock); |
| 791 | list_for_each_entry_safe(work, work_tmp, &qedi->ll2_skb_list, list) { |
| 792 | list_del(&work->list); |
| 793 | if (work->skb) |
| 794 | kfree_skb(work->skb); |
| 795 | kfree(work); |
| 796 | } |
| 797 | spin_unlock_bh(&qedi->ll2_lock); |
| 798 | } |
| 799 | |
| 800 | static int qedi_ll2_recv_thread(void *arg) |
| 801 | { |
| 802 | struct qedi_ctx *qedi = (struct qedi_ctx *)arg; |
| 803 | struct skb_work_list *work, *work_tmp; |
| 804 | |
| 805 | set_user_nice(current, -20); |
| 806 | |
| 807 | while (!kthread_should_stop()) { |
| 808 | spin_lock_bh(&qedi->ll2_lock); |
| 809 | list_for_each_entry_safe(work, work_tmp, &qedi->ll2_skb_list, |
| 810 | list) { |
| 811 | list_del(&work->list); |
| 812 | qedi_ll2_process_skb(qedi, work->skb, work->vlan_id); |
| 813 | kfree_skb(work->skb); |
| 814 | kfree(work); |
| 815 | } |
| 816 | set_current_state(TASK_INTERRUPTIBLE); |
| 817 | spin_unlock_bh(&qedi->ll2_lock); |
| 818 | schedule(); |
| 819 | } |
| 820 | |
| 821 | __set_current_state(TASK_RUNNING); |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | static int qedi_set_iscsi_pf_param(struct qedi_ctx *qedi) |
| 826 | { |
| 827 | u8 num_sq_pages; |
| 828 | u32 log_page_size; |
| 829 | int rval = 0; |
| 830 | |
| 831 | |
| 832 | num_sq_pages = (MAX_OUTSTANDING_TASKS_PER_CON * 8) / QEDI_PAGE_SIZE; |
| 833 | |
| 834 | qedi->num_queues = MIN_NUM_CPUS_MSIX(qedi); |
| 835 | |
| 836 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 837 | "Number of CQ count is %d\n", qedi->num_queues); |
| 838 | |
| 839 | memset(&qedi->pf_params.iscsi_pf_params, 0, |
| 840 | sizeof(qedi->pf_params.iscsi_pf_params)); |
| 841 | |
| 842 | qedi->p_cpuq = dma_alloc_coherent(&qedi->pdev->dev, |
| 843 | qedi->num_queues * sizeof(struct qedi_glbl_q_params), |
| 844 | &qedi->hw_p_cpuq, GFP_KERNEL); |
| 845 | if (!qedi->p_cpuq) { |
| 846 | QEDI_ERR(&qedi->dbg_ctx, "dma_alloc_coherent fail\n"); |
| 847 | rval = -1; |
| 848 | goto err_alloc_mem; |
| 849 | } |
| 850 | |
| 851 | rval = qedi_alloc_global_queues(qedi); |
| 852 | if (rval) { |
| 853 | QEDI_ERR(&qedi->dbg_ctx, "Global queue allocation failed.\n"); |
| 854 | rval = -1; |
| 855 | goto err_alloc_mem; |
| 856 | } |
| 857 | |
| 858 | qedi->pf_params.iscsi_pf_params.num_cons = QEDI_MAX_ISCSI_CONNS_PER_HBA; |
| 859 | qedi->pf_params.iscsi_pf_params.num_tasks = QEDI_MAX_ISCSI_TASK; |
| 860 | qedi->pf_params.iscsi_pf_params.half_way_close_timeout = 10; |
| 861 | qedi->pf_params.iscsi_pf_params.num_sq_pages_in_ring = num_sq_pages; |
| 862 | qedi->pf_params.iscsi_pf_params.num_r2tq_pages_in_ring = num_sq_pages; |
| 863 | qedi->pf_params.iscsi_pf_params.num_uhq_pages_in_ring = num_sq_pages; |
| 864 | qedi->pf_params.iscsi_pf_params.num_queues = qedi->num_queues; |
| 865 | qedi->pf_params.iscsi_pf_params.debug_mode = qedi_fw_debug; |
| 866 | qedi->pf_params.iscsi_pf_params.two_msl_timer = 4000; |
| 867 | qedi->pf_params.iscsi_pf_params.max_fin_rt = 2; |
| 868 | |
| 869 | for (log_page_size = 0 ; log_page_size < 32 ; log_page_size++) { |
| 870 | if ((1 << log_page_size) == QEDI_PAGE_SIZE) |
| 871 | break; |
| 872 | } |
| 873 | qedi->pf_params.iscsi_pf_params.log_page_size = log_page_size; |
| 874 | |
| 875 | qedi->pf_params.iscsi_pf_params.glbl_q_params_addr = |
| 876 | (u64)qedi->hw_p_cpuq; |
| 877 | |
| 878 | /* RQ BDQ initializations. |
| 879 | * rq_num_entries: suggested value for Initiator is 16 (4KB RQ) |
| 880 | * rqe_log_size: 8 for 256B RQE |
| 881 | */ |
| 882 | qedi->pf_params.iscsi_pf_params.rqe_log_size = 8; |
| 883 | /* BDQ address and size */ |
| 884 | qedi->pf_params.iscsi_pf_params.bdq_pbl_base_addr[BDQ_ID_RQ] = |
| 885 | qedi->bdq_pbl_list_dma; |
| 886 | qedi->pf_params.iscsi_pf_params.bdq_pbl_num_entries[BDQ_ID_RQ] = |
| 887 | qedi->bdq_pbl_list_num_entries; |
| 888 | qedi->pf_params.iscsi_pf_params.rq_buffer_size = QEDI_BDQ_BUF_SIZE; |
| 889 | |
| 890 | /* cq_num_entries: num_tasks + rq_num_entries */ |
| 891 | qedi->pf_params.iscsi_pf_params.cq_num_entries = 2048; |
| 892 | |
| 893 | qedi->pf_params.iscsi_pf_params.gl_rq_pi = QEDI_PROTO_CQ_PROD_IDX; |
| 894 | qedi->pf_params.iscsi_pf_params.gl_cmd_pi = 1; |
| 895 | |
| 896 | err_alloc_mem: |
| 897 | return rval; |
| 898 | } |
| 899 | |
| 900 | /* Free DMA coherent memory for array of queue pointers we pass to qed */ |
| 901 | static void qedi_free_iscsi_pf_param(struct qedi_ctx *qedi) |
| 902 | { |
| 903 | size_t size = 0; |
| 904 | |
| 905 | if (qedi->p_cpuq) { |
| 906 | size = qedi->num_queues * sizeof(struct qedi_glbl_q_params); |
| 907 | dma_free_coherent(&qedi->pdev->dev, size, qedi->p_cpuq, |
| 908 | qedi->hw_p_cpuq); |
| 909 | } |
| 910 | |
| 911 | qedi_free_global_queues(qedi); |
| 912 | |
| 913 | kfree(qedi->global_queues); |
| 914 | } |
| 915 | |
| 916 | static void qedi_get_boot_tgt_info(struct nvm_iscsi_block *block, |
| 917 | struct qedi_boot_target *tgt, u8 index) |
| 918 | { |
| 919 | u32 ipv6_en; |
| 920 | |
| 921 | ipv6_en = !!(block->generic.ctrl_flags & |
| 922 | NVM_ISCSI_CFG_GEN_IPV6_ENABLED); |
| 923 | |
| 924 | snprintf(tgt->iscsi_name, sizeof(tgt->iscsi_name), "%s\n", |
| 925 | block->target[index].target_name.byte); |
| 926 | |
| 927 | tgt->ipv6_en = ipv6_en; |
| 928 | |
| 929 | if (ipv6_en) |
| 930 | snprintf(tgt->ip_addr, IPV6_LEN, "%pI6\n", |
| 931 | block->target[index].ipv6_addr.byte); |
| 932 | else |
| 933 | snprintf(tgt->ip_addr, IPV4_LEN, "%pI4\n", |
| 934 | block->target[index].ipv4_addr.byte); |
| 935 | } |
| 936 | |
| 937 | static int qedi_find_boot_info(struct qedi_ctx *qedi, |
| 938 | struct qed_mfw_tlv_iscsi *iscsi, |
| 939 | struct nvm_iscsi_block *block) |
| 940 | { |
| 941 | struct qedi_boot_target *pri_tgt = NULL, *sec_tgt = NULL; |
| 942 | u32 pri_ctrl_flags = 0, sec_ctrl_flags = 0, found = 0; |
| 943 | struct iscsi_cls_session *cls_sess; |
| 944 | struct iscsi_cls_conn *cls_conn; |
| 945 | struct qedi_conn *qedi_conn; |
| 946 | struct iscsi_session *sess; |
| 947 | struct iscsi_conn *conn; |
| 948 | char ep_ip_addr[64]; |
| 949 | int i, ret = 0; |
| 950 | |
| 951 | pri_ctrl_flags = !!(block->target[0].ctrl_flags & |
| 952 | NVM_ISCSI_CFG_TARGET_ENABLED); |
| 953 | if (pri_ctrl_flags) { |
| 954 | pri_tgt = kzalloc(sizeof(*pri_tgt), GFP_KERNEL); |
| 955 | if (!pri_tgt) |
| 956 | return -1; |
| 957 | qedi_get_boot_tgt_info(block, pri_tgt, 0); |
| 958 | } |
| 959 | |
| 960 | sec_ctrl_flags = !!(block->target[1].ctrl_flags & |
| 961 | NVM_ISCSI_CFG_TARGET_ENABLED); |
| 962 | if (sec_ctrl_flags) { |
| 963 | sec_tgt = kzalloc(sizeof(*sec_tgt), GFP_KERNEL); |
| 964 | if (!sec_tgt) { |
| 965 | ret = -1; |
| 966 | goto free_tgt; |
| 967 | } |
| 968 | qedi_get_boot_tgt_info(block, sec_tgt, 1); |
| 969 | } |
| 970 | |
| 971 | for (i = 0; i < qedi->max_active_conns; i++) { |
| 972 | qedi_conn = qedi_get_conn_from_id(qedi, i); |
| 973 | if (!qedi_conn) |
| 974 | continue; |
| 975 | |
| 976 | if (qedi_conn->ep->ip_type == TCP_IPV4) |
| 977 | snprintf(ep_ip_addr, IPV4_LEN, "%pI4\n", |
| 978 | qedi_conn->ep->dst_addr); |
| 979 | else |
| 980 | snprintf(ep_ip_addr, IPV6_LEN, "%pI6\n", |
| 981 | qedi_conn->ep->dst_addr); |
| 982 | |
| 983 | cls_conn = qedi_conn->cls_conn; |
| 984 | conn = cls_conn->dd_data; |
| 985 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 986 | sess = cls_sess->dd_data; |
| 987 | |
| 988 | if (!iscsi_is_session_online(cls_sess)) |
| 989 | continue; |
| 990 | |
| 991 | if (!sess->targetname) |
| 992 | continue; |
| 993 | |
| 994 | if (pri_ctrl_flags) { |
| 995 | if (!strcmp(pri_tgt->iscsi_name, sess->targetname) && |
| 996 | !strcmp(pri_tgt->ip_addr, ep_ip_addr)) { |
| 997 | found = 1; |
| 998 | break; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | if (sec_ctrl_flags) { |
| 1003 | if (!strcmp(sec_tgt->iscsi_name, sess->targetname) && |
| 1004 | !strcmp(sec_tgt->ip_addr, ep_ip_addr)) { |
| 1005 | found = 1; |
| 1006 | break; |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | if (found) { |
| 1012 | if (conn->hdrdgst_en) { |
| 1013 | iscsi->header_digest_set = true; |
| 1014 | iscsi->header_digest = 1; |
| 1015 | } |
| 1016 | |
| 1017 | if (conn->datadgst_en) { |
| 1018 | iscsi->data_digest_set = true; |
| 1019 | iscsi->data_digest = 1; |
| 1020 | } |
| 1021 | iscsi->boot_taget_portal_set = true; |
| 1022 | iscsi->boot_taget_portal = sess->tpgt; |
| 1023 | |
| 1024 | } else { |
| 1025 | ret = -1; |
| 1026 | } |
| 1027 | |
| 1028 | if (sec_ctrl_flags) |
| 1029 | kfree(sec_tgt); |
| 1030 | free_tgt: |
| 1031 | if (pri_ctrl_flags) |
| 1032 | kfree(pri_tgt); |
| 1033 | |
| 1034 | return ret; |
| 1035 | } |
| 1036 | |
| 1037 | static void qedi_get_generic_tlv_data(void *dev, struct qed_generic_tlvs *data) |
| 1038 | { |
| 1039 | struct qedi_ctx *qedi; |
| 1040 | |
| 1041 | if (!dev) { |
| 1042 | QEDI_INFO(NULL, QEDI_LOG_EVT, |
| 1043 | "dev is NULL so ignoring get_generic_tlv_data request.\n"); |
| 1044 | return; |
| 1045 | } |
| 1046 | qedi = (struct qedi_ctx *)dev; |
| 1047 | |
| 1048 | memset(data, 0, sizeof(struct qed_generic_tlvs)); |
| 1049 | ether_addr_copy(data->mac[0], qedi->mac); |
| 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * Protocol TLV handler |
| 1054 | */ |
| 1055 | static void qedi_get_protocol_tlv_data(void *dev, void *data) |
| 1056 | { |
| 1057 | struct qed_mfw_tlv_iscsi *iscsi = data; |
| 1058 | struct qed_iscsi_stats *fw_iscsi_stats; |
| 1059 | struct nvm_iscsi_block *block = NULL; |
| 1060 | u32 chap_en = 0, mchap_en = 0; |
| 1061 | struct qedi_ctx *qedi = dev; |
| 1062 | int rval = 0; |
| 1063 | |
| 1064 | fw_iscsi_stats = kmalloc(sizeof(*fw_iscsi_stats), GFP_KERNEL); |
| 1065 | if (!fw_iscsi_stats) { |
| 1066 | QEDI_ERR(&qedi->dbg_ctx, |
| 1067 | "Could not allocate memory for fw_iscsi_stats.\n"); |
| 1068 | goto exit_get_data; |
| 1069 | } |
| 1070 | |
| 1071 | mutex_lock(&qedi->stats_lock); |
| 1072 | /* Query firmware for offload stats */ |
| 1073 | qedi_ops->get_stats(qedi->cdev, fw_iscsi_stats); |
| 1074 | mutex_unlock(&qedi->stats_lock); |
| 1075 | |
| 1076 | iscsi->rx_frames_set = true; |
| 1077 | iscsi->rx_frames = fw_iscsi_stats->iscsi_rx_packet_cnt; |
| 1078 | iscsi->rx_bytes_set = true; |
| 1079 | iscsi->rx_bytes = fw_iscsi_stats->iscsi_rx_bytes_cnt; |
| 1080 | iscsi->tx_frames_set = true; |
| 1081 | iscsi->tx_frames = fw_iscsi_stats->iscsi_tx_packet_cnt; |
| 1082 | iscsi->tx_bytes_set = true; |
| 1083 | iscsi->tx_bytes = fw_iscsi_stats->iscsi_tx_bytes_cnt; |
| 1084 | iscsi->frame_size_set = true; |
| 1085 | iscsi->frame_size = qedi->ll2_mtu; |
| 1086 | block = qedi_get_nvram_block(qedi); |
| 1087 | if (block) { |
| 1088 | chap_en = !!(block->generic.ctrl_flags & |
| 1089 | NVM_ISCSI_CFG_GEN_CHAP_ENABLED); |
| 1090 | mchap_en = !!(block->generic.ctrl_flags & |
| 1091 | NVM_ISCSI_CFG_GEN_CHAP_MUTUAL_ENABLED); |
| 1092 | |
| 1093 | iscsi->auth_method_set = (chap_en || mchap_en) ? true : false; |
| 1094 | iscsi->auth_method = 1; |
| 1095 | if (chap_en) |
| 1096 | iscsi->auth_method = 2; |
| 1097 | if (mchap_en) |
| 1098 | iscsi->auth_method = 3; |
| 1099 | |
| 1100 | iscsi->tx_desc_size_set = true; |
| 1101 | iscsi->tx_desc_size = QEDI_SQ_SIZE; |
| 1102 | iscsi->rx_desc_size_set = true; |
| 1103 | iscsi->rx_desc_size = QEDI_CQ_SIZE; |
| 1104 | |
| 1105 | /* tpgt, hdr digest, data digest */ |
| 1106 | rval = qedi_find_boot_info(qedi, iscsi, block); |
| 1107 | if (rval) |
| 1108 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 1109 | "Boot target not set"); |
| 1110 | } |
| 1111 | |
| 1112 | kfree(fw_iscsi_stats); |
| 1113 | exit_get_data: |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | static void qedi_link_update(void *dev, struct qed_link_output *link) |
| 1118 | { |
| 1119 | struct qedi_ctx *qedi = (struct qedi_ctx *)dev; |
| 1120 | |
| 1121 | if (link->link_up) { |
| 1122 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, "Link Up event.\n"); |
| 1123 | atomic_set(&qedi->link_state, QEDI_LINK_UP); |
| 1124 | } else { |
| 1125 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 1126 | "Link Down event.\n"); |
| 1127 | atomic_set(&qedi->link_state, QEDI_LINK_DOWN); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | static struct qed_iscsi_cb_ops qedi_cb_ops = { |
| 1132 | { |
| 1133 | .link_update = qedi_link_update, |
| 1134 | .get_protocol_tlv_data = qedi_get_protocol_tlv_data, |
| 1135 | .get_generic_tlv_data = qedi_get_generic_tlv_data, |
| 1136 | } |
| 1137 | }; |
| 1138 | |
| 1139 | static int qedi_queue_cqe(struct qedi_ctx *qedi, union iscsi_cqe *cqe, |
| 1140 | u16 que_idx, struct qedi_percpu_s *p) |
| 1141 | { |
| 1142 | struct qedi_work *qedi_work; |
| 1143 | struct qedi_conn *q_conn; |
| 1144 | struct iscsi_conn *conn; |
| 1145 | struct qedi_cmd *qedi_cmd; |
| 1146 | u32 iscsi_cid; |
| 1147 | int rc = 0; |
| 1148 | |
| 1149 | iscsi_cid = cqe->cqe_common.conn_id; |
| 1150 | q_conn = qedi->cid_que.conn_cid_tbl[iscsi_cid]; |
| 1151 | if (!q_conn) { |
| 1152 | QEDI_WARN(&qedi->dbg_ctx, |
| 1153 | "Session no longer exists for cid=0x%x!!\n", |
| 1154 | iscsi_cid); |
| 1155 | return -1; |
| 1156 | } |
| 1157 | conn = q_conn->cls_conn->dd_data; |
| 1158 | |
| 1159 | switch (cqe->cqe_common.cqe_type) { |
| 1160 | case ISCSI_CQE_TYPE_SOLICITED: |
| 1161 | case ISCSI_CQE_TYPE_SOLICITED_WITH_SENSE: |
| 1162 | qedi_cmd = qedi_get_cmd_from_tid(qedi, cqe->cqe_solicited.itid); |
| 1163 | if (!qedi_cmd) { |
| 1164 | rc = -1; |
| 1165 | break; |
| 1166 | } |
| 1167 | INIT_LIST_HEAD(&qedi_cmd->cqe_work.list); |
| 1168 | qedi_cmd->cqe_work.qedi = qedi; |
| 1169 | memcpy(&qedi_cmd->cqe_work.cqe, cqe, sizeof(union iscsi_cqe)); |
| 1170 | qedi_cmd->cqe_work.que_idx = que_idx; |
| 1171 | qedi_cmd->cqe_work.is_solicited = true; |
| 1172 | list_add_tail(&qedi_cmd->cqe_work.list, &p->work_list); |
| 1173 | break; |
| 1174 | case ISCSI_CQE_TYPE_UNSOLICITED: |
| 1175 | case ISCSI_CQE_TYPE_DUMMY: |
| 1176 | case ISCSI_CQE_TYPE_TASK_CLEANUP: |
| 1177 | qedi_work = kzalloc(sizeof(*qedi_work), GFP_ATOMIC); |
| 1178 | if (!qedi_work) { |
| 1179 | rc = -1; |
| 1180 | break; |
| 1181 | } |
| 1182 | INIT_LIST_HEAD(&qedi_work->list); |
| 1183 | qedi_work->qedi = qedi; |
| 1184 | memcpy(&qedi_work->cqe, cqe, sizeof(union iscsi_cqe)); |
| 1185 | qedi_work->que_idx = que_idx; |
| 1186 | qedi_work->is_solicited = false; |
| 1187 | list_add_tail(&qedi_work->list, &p->work_list); |
| 1188 | break; |
| 1189 | default: |
| 1190 | rc = -1; |
| 1191 | QEDI_ERR(&qedi->dbg_ctx, "FW Error cqe.\n"); |
| 1192 | } |
| 1193 | return rc; |
| 1194 | } |
| 1195 | |
| 1196 | static bool qedi_process_completions(struct qedi_fastpath *fp) |
| 1197 | { |
| 1198 | struct qedi_ctx *qedi = fp->qedi; |
| 1199 | struct qed_sb_info *sb_info = fp->sb_info; |
| 1200 | struct status_block_e4 *sb = sb_info->sb_virt; |
| 1201 | struct qedi_percpu_s *p = NULL; |
| 1202 | struct global_queue *que; |
| 1203 | u16 prod_idx; |
| 1204 | unsigned long flags; |
| 1205 | union iscsi_cqe *cqe; |
| 1206 | int cpu; |
| 1207 | int ret; |
| 1208 | |
| 1209 | /* Get the current firmware producer index */ |
| 1210 | prod_idx = sb->pi_array[QEDI_PROTO_CQ_PROD_IDX]; |
| 1211 | |
| 1212 | if (prod_idx >= QEDI_CQ_SIZE) |
| 1213 | prod_idx = prod_idx % QEDI_CQ_SIZE; |
| 1214 | |
| 1215 | que = qedi->global_queues[fp->sb_id]; |
| 1216 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_IO, |
| 1217 | "Before: global queue=%p prod_idx=%d cons_idx=%d, sb_id=%d\n", |
| 1218 | que, prod_idx, que->cq_cons_idx, fp->sb_id); |
| 1219 | |
| 1220 | qedi->intr_cpu = fp->sb_id; |
| 1221 | cpu = smp_processor_id(); |
| 1222 | p = &per_cpu(qedi_percpu, cpu); |
| 1223 | |
| 1224 | if (unlikely(!p->iothread)) |
| 1225 | WARN_ON(1); |
| 1226 | |
| 1227 | spin_lock_irqsave(&p->p_work_lock, flags); |
| 1228 | while (que->cq_cons_idx != prod_idx) { |
| 1229 | cqe = &que->cq[que->cq_cons_idx]; |
| 1230 | |
| 1231 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_IO, |
| 1232 | "cqe=%p prod_idx=%d cons_idx=%d.\n", |
| 1233 | cqe, prod_idx, que->cq_cons_idx); |
| 1234 | |
| 1235 | ret = qedi_queue_cqe(qedi, cqe, fp->sb_id, p); |
| 1236 | if (ret) |
| 1237 | QEDI_WARN(&qedi->dbg_ctx, |
| 1238 | "Dropping CQE 0x%x for cid=0x%x.\n", |
| 1239 | que->cq_cons_idx, cqe->cqe_common.conn_id); |
| 1240 | |
| 1241 | que->cq_cons_idx++; |
| 1242 | if (que->cq_cons_idx == QEDI_CQ_SIZE) |
| 1243 | que->cq_cons_idx = 0; |
| 1244 | } |
| 1245 | wake_up_process(p->iothread); |
| 1246 | spin_unlock_irqrestore(&p->p_work_lock, flags); |
| 1247 | |
| 1248 | return true; |
| 1249 | } |
| 1250 | |
| 1251 | static bool qedi_fp_has_work(struct qedi_fastpath *fp) |
| 1252 | { |
| 1253 | struct qedi_ctx *qedi = fp->qedi; |
| 1254 | struct global_queue *que; |
| 1255 | struct qed_sb_info *sb_info = fp->sb_info; |
| 1256 | struct status_block_e4 *sb = sb_info->sb_virt; |
| 1257 | u16 prod_idx; |
| 1258 | |
| 1259 | barrier(); |
| 1260 | |
| 1261 | /* Get the current firmware producer index */ |
| 1262 | prod_idx = sb->pi_array[QEDI_PROTO_CQ_PROD_IDX]; |
| 1263 | |
| 1264 | /* Get the pointer to the global CQ this completion is on */ |
| 1265 | que = qedi->global_queues[fp->sb_id]; |
| 1266 | |
| 1267 | /* prod idx wrap around uint16 */ |
| 1268 | if (prod_idx >= QEDI_CQ_SIZE) |
| 1269 | prod_idx = prod_idx % QEDI_CQ_SIZE; |
| 1270 | |
| 1271 | return (que->cq_cons_idx != prod_idx); |
| 1272 | } |
| 1273 | |
| 1274 | /* MSI-X fastpath handler code */ |
| 1275 | static irqreturn_t qedi_msix_handler(int irq, void *dev_id) |
| 1276 | { |
| 1277 | struct qedi_fastpath *fp = dev_id; |
| 1278 | struct qedi_ctx *qedi = fp->qedi; |
| 1279 | bool wake_io_thread = true; |
| 1280 | |
| 1281 | qed_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0); |
| 1282 | |
| 1283 | process_again: |
| 1284 | wake_io_thread = qedi_process_completions(fp); |
| 1285 | if (wake_io_thread) { |
| 1286 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 1287 | "process already running\n"); |
| 1288 | } |
| 1289 | |
| 1290 | if (qedi_fp_has_work(fp) == 0) |
| 1291 | qed_sb_update_sb_idx(fp->sb_info); |
| 1292 | |
| 1293 | /* Check for more work */ |
| 1294 | rmb(); |
| 1295 | |
| 1296 | if (qedi_fp_has_work(fp) == 0) |
| 1297 | qed_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1); |
| 1298 | else |
| 1299 | goto process_again; |
| 1300 | |
| 1301 | return IRQ_HANDLED; |
| 1302 | } |
| 1303 | |
| 1304 | /* simd handler for MSI/INTa */ |
| 1305 | static void qedi_simd_int_handler(void *cookie) |
| 1306 | { |
| 1307 | /* Cookie is qedi_ctx struct */ |
| 1308 | struct qedi_ctx *qedi = (struct qedi_ctx *)cookie; |
| 1309 | |
| 1310 | QEDI_WARN(&qedi->dbg_ctx, "qedi=%p.\n", qedi); |
| 1311 | } |
| 1312 | |
| 1313 | #define QEDI_SIMD_HANDLER_NUM 0 |
| 1314 | static void qedi_sync_free_irqs(struct qedi_ctx *qedi) |
| 1315 | { |
| 1316 | int i; |
| 1317 | u16 idx; |
| 1318 | |
| 1319 | if (qedi->int_info.msix_cnt) { |
| 1320 | for (i = 0; i < qedi->int_info.used_cnt; i++) { |
| 1321 | idx = i * qedi->dev_info.common.num_hwfns + |
| 1322 | qedi_ops->common->get_affin_hwfn_idx(qedi->cdev); |
| 1323 | |
| 1324 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 1325 | "Freeing IRQ #%d vector_idx=%d.\n", i, idx); |
| 1326 | |
| 1327 | synchronize_irq(qedi->int_info.msix[idx].vector); |
| 1328 | irq_set_affinity_hint(qedi->int_info.msix[idx].vector, |
| 1329 | NULL); |
| 1330 | free_irq(qedi->int_info.msix[idx].vector, |
| 1331 | &qedi->fp_array[i]); |
| 1332 | } |
| 1333 | } else { |
| 1334 | qedi_ops->common->simd_handler_clean(qedi->cdev, |
| 1335 | QEDI_SIMD_HANDLER_NUM); |
| 1336 | } |
| 1337 | |
| 1338 | qedi->int_info.used_cnt = 0; |
| 1339 | qedi_ops->common->set_fp_int(qedi->cdev, 0); |
| 1340 | } |
| 1341 | |
| 1342 | static int qedi_request_msix_irq(struct qedi_ctx *qedi) |
| 1343 | { |
| 1344 | int i, rc, cpu; |
| 1345 | u16 idx; |
| 1346 | |
| 1347 | cpu = cpumask_first(cpu_online_mask); |
| 1348 | for (i = 0; i < MIN_NUM_CPUS_MSIX(qedi); i++) { |
| 1349 | idx = i * qedi->dev_info.common.num_hwfns + |
| 1350 | qedi_ops->common->get_affin_hwfn_idx(qedi->cdev); |
| 1351 | |
| 1352 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 1353 | "dev_info: num_hwfns=%d affin_hwfn_idx=%d.\n", |
| 1354 | qedi->dev_info.common.num_hwfns, |
| 1355 | qedi_ops->common->get_affin_hwfn_idx(qedi->cdev)); |
| 1356 | |
| 1357 | rc = request_irq(qedi->int_info.msix[idx].vector, |
| 1358 | qedi_msix_handler, 0, "qedi", |
| 1359 | &qedi->fp_array[i]); |
| 1360 | if (rc) { |
| 1361 | QEDI_WARN(&qedi->dbg_ctx, "request_irq failed.\n"); |
| 1362 | qedi_sync_free_irqs(qedi); |
| 1363 | return rc; |
| 1364 | } |
| 1365 | qedi->int_info.used_cnt++; |
| 1366 | rc = irq_set_affinity_hint(qedi->int_info.msix[idx].vector, |
| 1367 | get_cpu_mask(cpu)); |
| 1368 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 1369 | } |
| 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | static int qedi_setup_int(struct qedi_ctx *qedi) |
| 1375 | { |
| 1376 | int rc = 0; |
| 1377 | |
| 1378 | rc = qedi_ops->common->set_fp_int(qedi->cdev, num_online_cpus()); |
| 1379 | rc = qedi_ops->common->get_fp_int(qedi->cdev, &qedi->int_info); |
| 1380 | if (rc) |
| 1381 | goto exit_setup_int; |
| 1382 | |
| 1383 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 1384 | "Number of msix_cnt = 0x%x num of cpus = 0x%x\n", |
| 1385 | qedi->int_info.msix_cnt, num_online_cpus()); |
| 1386 | |
| 1387 | if (qedi->int_info.msix_cnt) { |
| 1388 | rc = qedi_request_msix_irq(qedi); |
| 1389 | goto exit_setup_int; |
| 1390 | } else { |
| 1391 | qedi_ops->common->simd_handler_config(qedi->cdev, &qedi, |
| 1392 | QEDI_SIMD_HANDLER_NUM, |
| 1393 | qedi_simd_int_handler); |
| 1394 | qedi->int_info.used_cnt = 1; |
| 1395 | } |
| 1396 | |
| 1397 | exit_setup_int: |
| 1398 | return rc; |
| 1399 | } |
| 1400 | |
| 1401 | static void qedi_free_nvm_iscsi_cfg(struct qedi_ctx *qedi) |
| 1402 | { |
| 1403 | if (qedi->iscsi_image) |
| 1404 | dma_free_coherent(&qedi->pdev->dev, |
| 1405 | sizeof(struct qedi_nvm_iscsi_image), |
| 1406 | qedi->iscsi_image, qedi->nvm_buf_dma); |
| 1407 | } |
| 1408 | |
| 1409 | static int qedi_alloc_nvm_iscsi_cfg(struct qedi_ctx *qedi) |
| 1410 | { |
| 1411 | qedi->iscsi_image = dma_alloc_coherent(&qedi->pdev->dev, |
| 1412 | sizeof(struct qedi_nvm_iscsi_image), |
| 1413 | &qedi->nvm_buf_dma, GFP_KERNEL); |
| 1414 | if (!qedi->iscsi_image) { |
| 1415 | QEDI_ERR(&qedi->dbg_ctx, "Could not allocate NVM BUF.\n"); |
| 1416 | return -ENOMEM; |
| 1417 | } |
| 1418 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 1419 | "NVM BUF addr=0x%p dma=0x%llx.\n", qedi->iscsi_image, |
| 1420 | qedi->nvm_buf_dma); |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static void qedi_free_bdq(struct qedi_ctx *qedi) |
| 1426 | { |
| 1427 | int i; |
| 1428 | |
| 1429 | if (qedi->bdq_pbl_list) |
| 1430 | dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE, |
| 1431 | qedi->bdq_pbl_list, qedi->bdq_pbl_list_dma); |
| 1432 | |
| 1433 | if (qedi->bdq_pbl) |
| 1434 | dma_free_coherent(&qedi->pdev->dev, qedi->bdq_pbl_mem_size, |
| 1435 | qedi->bdq_pbl, qedi->bdq_pbl_dma); |
| 1436 | |
| 1437 | for (i = 0; i < QEDI_BDQ_NUM; i++) { |
| 1438 | if (qedi->bdq[i].buf_addr) { |
| 1439 | dma_free_coherent(&qedi->pdev->dev, QEDI_BDQ_BUF_SIZE, |
| 1440 | qedi->bdq[i].buf_addr, |
| 1441 | qedi->bdq[i].buf_dma); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | static void qedi_free_global_queues(struct qedi_ctx *qedi) |
| 1447 | { |
| 1448 | int i; |
| 1449 | struct global_queue **gl = qedi->global_queues; |
| 1450 | |
| 1451 | for (i = 0; i < qedi->num_queues; i++) { |
| 1452 | if (!gl[i]) |
| 1453 | continue; |
| 1454 | |
| 1455 | if (gl[i]->cq) |
| 1456 | dma_free_coherent(&qedi->pdev->dev, gl[i]->cq_mem_size, |
| 1457 | gl[i]->cq, gl[i]->cq_dma); |
| 1458 | if (gl[i]->cq_pbl) |
| 1459 | dma_free_coherent(&qedi->pdev->dev, gl[i]->cq_pbl_size, |
| 1460 | gl[i]->cq_pbl, gl[i]->cq_pbl_dma); |
| 1461 | |
| 1462 | kfree(gl[i]); |
| 1463 | } |
| 1464 | qedi_free_bdq(qedi); |
| 1465 | qedi_free_nvm_iscsi_cfg(qedi); |
| 1466 | } |
| 1467 | |
| 1468 | static int qedi_alloc_bdq(struct qedi_ctx *qedi) |
| 1469 | { |
| 1470 | int i; |
| 1471 | struct scsi_bd *pbl; |
| 1472 | u64 *list; |
| 1473 | dma_addr_t page; |
| 1474 | |
| 1475 | /* Alloc dma memory for BDQ buffers */ |
| 1476 | for (i = 0; i < QEDI_BDQ_NUM; i++) { |
| 1477 | qedi->bdq[i].buf_addr = |
| 1478 | dma_alloc_coherent(&qedi->pdev->dev, |
| 1479 | QEDI_BDQ_BUF_SIZE, |
| 1480 | &qedi->bdq[i].buf_dma, |
| 1481 | GFP_KERNEL); |
| 1482 | if (!qedi->bdq[i].buf_addr) { |
| 1483 | QEDI_ERR(&qedi->dbg_ctx, |
| 1484 | "Could not allocate BDQ buffer %d.\n", i); |
| 1485 | return -ENOMEM; |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | /* Alloc dma memory for BDQ page buffer list */ |
| 1490 | qedi->bdq_pbl_mem_size = QEDI_BDQ_NUM * sizeof(struct scsi_bd); |
| 1491 | qedi->bdq_pbl_mem_size = ALIGN(qedi->bdq_pbl_mem_size, QEDI_PAGE_SIZE); |
| 1492 | qedi->rq_num_entries = qedi->bdq_pbl_mem_size / sizeof(struct scsi_bd); |
| 1493 | |
| 1494 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, "rq_num_entries = %d.\n", |
| 1495 | qedi->rq_num_entries); |
| 1496 | |
| 1497 | qedi->bdq_pbl = dma_alloc_coherent(&qedi->pdev->dev, |
| 1498 | qedi->bdq_pbl_mem_size, |
| 1499 | &qedi->bdq_pbl_dma, GFP_KERNEL); |
| 1500 | if (!qedi->bdq_pbl) { |
| 1501 | QEDI_ERR(&qedi->dbg_ctx, "Could not allocate BDQ PBL.\n"); |
| 1502 | return -ENOMEM; |
| 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * Populate BDQ PBL with physical and virtual address of individual |
| 1507 | * BDQ buffers |
| 1508 | */ |
| 1509 | pbl = (struct scsi_bd *)qedi->bdq_pbl; |
| 1510 | for (i = 0; i < QEDI_BDQ_NUM; i++) { |
| 1511 | pbl->address.hi = |
| 1512 | cpu_to_le32(QEDI_U64_HI(qedi->bdq[i].buf_dma)); |
| 1513 | pbl->address.lo = |
| 1514 | cpu_to_le32(QEDI_U64_LO(qedi->bdq[i].buf_dma)); |
| 1515 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, |
| 1516 | "pbl [0x%p] pbl->address hi [0x%llx] lo [0x%llx], idx [%d]\n", |
| 1517 | pbl, pbl->address.hi, pbl->address.lo, i); |
| 1518 | pbl->opaque.iscsi_opaque.reserved_zero[0] = 0; |
| 1519 | pbl->opaque.iscsi_opaque.reserved_zero[1] = 0; |
| 1520 | pbl->opaque.iscsi_opaque.reserved_zero[2] = 0; |
| 1521 | pbl->opaque.iscsi_opaque.opaque = cpu_to_le16(i); |
| 1522 | pbl++; |
| 1523 | } |
| 1524 | |
| 1525 | /* Allocate list of PBL pages */ |
| 1526 | qedi->bdq_pbl_list = dma_alloc_coherent(&qedi->pdev->dev, |
| 1527 | QEDI_PAGE_SIZE, |
| 1528 | &qedi->bdq_pbl_list_dma, |
| 1529 | GFP_KERNEL); |
| 1530 | if (!qedi->bdq_pbl_list) { |
| 1531 | QEDI_ERR(&qedi->dbg_ctx, |
| 1532 | "Could not allocate list of PBL pages.\n"); |
| 1533 | return -ENOMEM; |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * Now populate PBL list with pages that contain pointers to the |
| 1538 | * individual buffers. |
| 1539 | */ |
| 1540 | qedi->bdq_pbl_list_num_entries = qedi->bdq_pbl_mem_size / |
| 1541 | QEDI_PAGE_SIZE; |
| 1542 | list = (u64 *)qedi->bdq_pbl_list; |
| 1543 | page = qedi->bdq_pbl_list_dma; |
| 1544 | for (i = 0; i < qedi->bdq_pbl_list_num_entries; i++) { |
| 1545 | *list = qedi->bdq_pbl_dma; |
| 1546 | list++; |
| 1547 | page += QEDI_PAGE_SIZE; |
| 1548 | } |
| 1549 | |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | static int qedi_alloc_global_queues(struct qedi_ctx *qedi) |
| 1554 | { |
| 1555 | u32 *list; |
| 1556 | int i; |
| 1557 | int status; |
| 1558 | u32 *pbl; |
| 1559 | dma_addr_t page; |
| 1560 | int num_pages; |
| 1561 | |
| 1562 | /* |
| 1563 | * Number of global queues (CQ / RQ). This should |
| 1564 | * be <= number of available MSIX vectors for the PF |
| 1565 | */ |
| 1566 | if (!qedi->num_queues) { |
| 1567 | QEDI_ERR(&qedi->dbg_ctx, "No MSI-X vectors available!\n"); |
| 1568 | return -ENOMEM; |
| 1569 | } |
| 1570 | |
| 1571 | /* Make sure we allocated the PBL that will contain the physical |
| 1572 | * addresses of our queues |
| 1573 | */ |
| 1574 | if (!qedi->p_cpuq) { |
| 1575 | status = -EINVAL; |
| 1576 | goto mem_alloc_failure; |
| 1577 | } |
| 1578 | |
| 1579 | qedi->global_queues = kzalloc((sizeof(struct global_queue *) * |
| 1580 | qedi->num_queues), GFP_KERNEL); |
| 1581 | if (!qedi->global_queues) { |
| 1582 | QEDI_ERR(&qedi->dbg_ctx, |
| 1583 | "Unable to allocate global queues array ptr memory\n"); |
| 1584 | return -ENOMEM; |
| 1585 | } |
| 1586 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 1587 | "qedi->global_queues=%p.\n", qedi->global_queues); |
| 1588 | |
| 1589 | /* Allocate DMA coherent buffers for BDQ */ |
| 1590 | status = qedi_alloc_bdq(qedi); |
| 1591 | if (status) |
| 1592 | goto mem_alloc_failure; |
| 1593 | |
| 1594 | /* Allocate DMA coherent buffers for NVM_ISCSI_CFG */ |
| 1595 | status = qedi_alloc_nvm_iscsi_cfg(qedi); |
| 1596 | if (status) |
| 1597 | goto mem_alloc_failure; |
| 1598 | |
| 1599 | /* Allocate a CQ and an associated PBL for each MSI-X |
| 1600 | * vector. |
| 1601 | */ |
| 1602 | for (i = 0; i < qedi->num_queues; i++) { |
| 1603 | qedi->global_queues[i] = |
| 1604 | kzalloc(sizeof(*qedi->global_queues[0]), |
| 1605 | GFP_KERNEL); |
| 1606 | if (!qedi->global_queues[i]) { |
| 1607 | QEDI_ERR(&qedi->dbg_ctx, |
| 1608 | "Unable to allocation global queue %d.\n", i); |
| 1609 | status = -ENOMEM; |
| 1610 | goto mem_alloc_failure; |
| 1611 | } |
| 1612 | |
| 1613 | qedi->global_queues[i]->cq_mem_size = |
| 1614 | (QEDI_CQ_SIZE + 8) * sizeof(union iscsi_cqe); |
| 1615 | qedi->global_queues[i]->cq_mem_size = |
| 1616 | (qedi->global_queues[i]->cq_mem_size + |
| 1617 | (QEDI_PAGE_SIZE - 1)); |
| 1618 | |
| 1619 | qedi->global_queues[i]->cq_pbl_size = |
| 1620 | (qedi->global_queues[i]->cq_mem_size / |
| 1621 | QEDI_PAGE_SIZE) * sizeof(void *); |
| 1622 | qedi->global_queues[i]->cq_pbl_size = |
| 1623 | (qedi->global_queues[i]->cq_pbl_size + |
| 1624 | (QEDI_PAGE_SIZE - 1)); |
| 1625 | |
| 1626 | qedi->global_queues[i]->cq = dma_alloc_coherent(&qedi->pdev->dev, |
| 1627 | qedi->global_queues[i]->cq_mem_size, |
| 1628 | &qedi->global_queues[i]->cq_dma, |
| 1629 | GFP_KERNEL); |
| 1630 | |
| 1631 | if (!qedi->global_queues[i]->cq) { |
| 1632 | QEDI_WARN(&qedi->dbg_ctx, |
| 1633 | "Could not allocate cq.\n"); |
| 1634 | status = -ENOMEM; |
| 1635 | goto mem_alloc_failure; |
| 1636 | } |
| 1637 | qedi->global_queues[i]->cq_pbl = dma_alloc_coherent(&qedi->pdev->dev, |
| 1638 | qedi->global_queues[i]->cq_pbl_size, |
| 1639 | &qedi->global_queues[i]->cq_pbl_dma, |
| 1640 | GFP_KERNEL); |
| 1641 | |
| 1642 | if (!qedi->global_queues[i]->cq_pbl) { |
| 1643 | QEDI_WARN(&qedi->dbg_ctx, |
| 1644 | "Could not allocate cq PBL.\n"); |
| 1645 | status = -ENOMEM; |
| 1646 | goto mem_alloc_failure; |
| 1647 | } |
| 1648 | |
| 1649 | /* Create PBL */ |
| 1650 | num_pages = qedi->global_queues[i]->cq_mem_size / |
| 1651 | QEDI_PAGE_SIZE; |
| 1652 | page = qedi->global_queues[i]->cq_dma; |
| 1653 | pbl = (u32 *)qedi->global_queues[i]->cq_pbl; |
| 1654 | |
| 1655 | while (num_pages--) { |
| 1656 | *pbl = (u32)page; |
| 1657 | pbl++; |
| 1658 | *pbl = (u32)((u64)page >> 32); |
| 1659 | pbl++; |
| 1660 | page += QEDI_PAGE_SIZE; |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | list = (u32 *)qedi->p_cpuq; |
| 1665 | |
| 1666 | /* |
| 1667 | * The list is built as follows: CQ#0 PBL pointer, RQ#0 PBL pointer, |
| 1668 | * CQ#1 PBL pointer, RQ#1 PBL pointer, etc. Each PBL pointer points |
| 1669 | * to the physical address which contains an array of pointers to the |
| 1670 | * physical addresses of the specific queue pages. |
| 1671 | */ |
| 1672 | for (i = 0; i < qedi->num_queues; i++) { |
| 1673 | *list = (u32)qedi->global_queues[i]->cq_pbl_dma; |
| 1674 | list++; |
| 1675 | *list = (u32)((u64)qedi->global_queues[i]->cq_pbl_dma >> 32); |
| 1676 | list++; |
| 1677 | |
| 1678 | *list = (u32)0; |
| 1679 | list++; |
| 1680 | *list = (u32)((u64)0 >> 32); |
| 1681 | list++; |
| 1682 | } |
| 1683 | |
| 1684 | return 0; |
| 1685 | |
| 1686 | mem_alloc_failure: |
| 1687 | qedi_free_global_queues(qedi); |
| 1688 | return status; |
| 1689 | } |
| 1690 | |
| 1691 | int qedi_alloc_sq(struct qedi_ctx *qedi, struct qedi_endpoint *ep) |
| 1692 | { |
| 1693 | int rval = 0; |
| 1694 | u32 *pbl; |
| 1695 | dma_addr_t page; |
| 1696 | int num_pages; |
| 1697 | |
| 1698 | if (!ep) |
| 1699 | return -EIO; |
| 1700 | |
| 1701 | /* Calculate appropriate queue and PBL sizes */ |
| 1702 | ep->sq_mem_size = QEDI_SQ_SIZE * sizeof(struct iscsi_wqe); |
| 1703 | ep->sq_mem_size += QEDI_PAGE_SIZE - 1; |
| 1704 | |
| 1705 | ep->sq_pbl_size = (ep->sq_mem_size / QEDI_PAGE_SIZE) * sizeof(void *); |
| 1706 | ep->sq_pbl_size = ep->sq_pbl_size + QEDI_PAGE_SIZE; |
| 1707 | |
| 1708 | ep->sq = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_mem_size, |
| 1709 | &ep->sq_dma, GFP_KERNEL); |
| 1710 | if (!ep->sq) { |
| 1711 | QEDI_WARN(&qedi->dbg_ctx, |
| 1712 | "Could not allocate send queue.\n"); |
| 1713 | rval = -ENOMEM; |
| 1714 | goto out; |
| 1715 | } |
| 1716 | ep->sq_pbl = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size, |
| 1717 | &ep->sq_pbl_dma, GFP_KERNEL); |
| 1718 | if (!ep->sq_pbl) { |
| 1719 | QEDI_WARN(&qedi->dbg_ctx, |
| 1720 | "Could not allocate send queue PBL.\n"); |
| 1721 | rval = -ENOMEM; |
| 1722 | goto out_free_sq; |
| 1723 | } |
| 1724 | |
| 1725 | /* Create PBL */ |
| 1726 | num_pages = ep->sq_mem_size / QEDI_PAGE_SIZE; |
| 1727 | page = ep->sq_dma; |
| 1728 | pbl = (u32 *)ep->sq_pbl; |
| 1729 | |
| 1730 | while (num_pages--) { |
| 1731 | *pbl = (u32)page; |
| 1732 | pbl++; |
| 1733 | *pbl = (u32)((u64)page >> 32); |
| 1734 | pbl++; |
| 1735 | page += QEDI_PAGE_SIZE; |
| 1736 | } |
| 1737 | |
| 1738 | return rval; |
| 1739 | |
| 1740 | out_free_sq: |
| 1741 | dma_free_coherent(&qedi->pdev->dev, ep->sq_mem_size, ep->sq, |
| 1742 | ep->sq_dma); |
| 1743 | out: |
| 1744 | return rval; |
| 1745 | } |
| 1746 | |
| 1747 | void qedi_free_sq(struct qedi_ctx *qedi, struct qedi_endpoint *ep) |
| 1748 | { |
| 1749 | if (ep->sq_pbl) |
| 1750 | dma_free_coherent(&qedi->pdev->dev, ep->sq_pbl_size, ep->sq_pbl, |
| 1751 | ep->sq_pbl_dma); |
| 1752 | if (ep->sq) |
| 1753 | dma_free_coherent(&qedi->pdev->dev, ep->sq_mem_size, ep->sq, |
| 1754 | ep->sq_dma); |
| 1755 | } |
| 1756 | |
| 1757 | int qedi_get_task_idx(struct qedi_ctx *qedi) |
| 1758 | { |
| 1759 | s16 tmp_idx; |
| 1760 | |
| 1761 | again: |
| 1762 | tmp_idx = find_first_zero_bit(qedi->task_idx_map, |
| 1763 | MAX_ISCSI_TASK_ENTRIES); |
| 1764 | |
| 1765 | if (tmp_idx >= MAX_ISCSI_TASK_ENTRIES) { |
| 1766 | QEDI_ERR(&qedi->dbg_ctx, "FW task context pool is full.\n"); |
| 1767 | tmp_idx = -1; |
| 1768 | goto err_idx; |
| 1769 | } |
| 1770 | |
| 1771 | if (test_and_set_bit(tmp_idx, qedi->task_idx_map)) |
| 1772 | goto again; |
| 1773 | |
| 1774 | err_idx: |
| 1775 | return tmp_idx; |
| 1776 | } |
| 1777 | |
| 1778 | void qedi_clear_task_idx(struct qedi_ctx *qedi, int idx) |
| 1779 | { |
| 1780 | if (!test_and_clear_bit(idx, qedi->task_idx_map)) |
| 1781 | QEDI_ERR(&qedi->dbg_ctx, |
| 1782 | "FW task context, already cleared, tid=0x%x\n", idx); |
| 1783 | } |
| 1784 | |
| 1785 | void qedi_update_itt_map(struct qedi_ctx *qedi, u32 tid, u32 proto_itt, |
| 1786 | struct qedi_cmd *cmd) |
| 1787 | { |
| 1788 | qedi->itt_map[tid].itt = proto_itt; |
| 1789 | qedi->itt_map[tid].p_cmd = cmd; |
| 1790 | |
| 1791 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, |
| 1792 | "update itt map tid=0x%x, with proto itt=0x%x\n", tid, |
| 1793 | qedi->itt_map[tid].itt); |
| 1794 | } |
| 1795 | |
| 1796 | void qedi_get_task_tid(struct qedi_ctx *qedi, u32 itt, s16 *tid) |
| 1797 | { |
| 1798 | u16 i; |
| 1799 | |
| 1800 | for (i = 0; i < MAX_ISCSI_TASK_ENTRIES; i++) { |
| 1801 | if (qedi->itt_map[i].itt == itt) { |
| 1802 | *tid = i; |
| 1803 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, |
| 1804 | "Ref itt=0x%x, found at tid=0x%x\n", |
| 1805 | itt, *tid); |
| 1806 | return; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | WARN_ON(1); |
| 1811 | } |
| 1812 | |
| 1813 | void qedi_get_proto_itt(struct qedi_ctx *qedi, u32 tid, u32 *proto_itt) |
| 1814 | { |
| 1815 | *proto_itt = qedi->itt_map[tid].itt; |
| 1816 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, |
| 1817 | "Get itt map tid [0x%x with proto itt[0x%x]", |
| 1818 | tid, *proto_itt); |
| 1819 | } |
| 1820 | |
| 1821 | struct qedi_cmd *qedi_get_cmd_from_tid(struct qedi_ctx *qedi, u32 tid) |
| 1822 | { |
| 1823 | struct qedi_cmd *cmd = NULL; |
| 1824 | |
| 1825 | if (tid >= MAX_ISCSI_TASK_ENTRIES) |
| 1826 | return NULL; |
| 1827 | |
| 1828 | cmd = qedi->itt_map[tid].p_cmd; |
| 1829 | if (cmd->task_id != tid) |
| 1830 | return NULL; |
| 1831 | |
| 1832 | qedi->itt_map[tid].p_cmd = NULL; |
| 1833 | |
| 1834 | return cmd; |
| 1835 | } |
| 1836 | |
| 1837 | static int qedi_alloc_itt(struct qedi_ctx *qedi) |
| 1838 | { |
| 1839 | qedi->itt_map = kcalloc(MAX_ISCSI_TASK_ENTRIES, |
| 1840 | sizeof(struct qedi_itt_map), GFP_KERNEL); |
| 1841 | if (!qedi->itt_map) { |
| 1842 | QEDI_ERR(&qedi->dbg_ctx, |
| 1843 | "Unable to allocate itt map array memory\n"); |
| 1844 | return -ENOMEM; |
| 1845 | } |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | static void qedi_free_itt(struct qedi_ctx *qedi) |
| 1850 | { |
| 1851 | kfree(qedi->itt_map); |
| 1852 | } |
| 1853 | |
| 1854 | static struct qed_ll2_cb_ops qedi_ll2_cb_ops = { |
| 1855 | .rx_cb = qedi_ll2_rx, |
| 1856 | .tx_cb = NULL, |
| 1857 | }; |
| 1858 | |
| 1859 | static int qedi_percpu_io_thread(void *arg) |
| 1860 | { |
| 1861 | struct qedi_percpu_s *p = arg; |
| 1862 | struct qedi_work *work, *tmp; |
| 1863 | unsigned long flags; |
| 1864 | LIST_HEAD(work_list); |
| 1865 | |
| 1866 | set_user_nice(current, -20); |
| 1867 | |
| 1868 | while (!kthread_should_stop()) { |
| 1869 | spin_lock_irqsave(&p->p_work_lock, flags); |
| 1870 | while (!list_empty(&p->work_list)) { |
| 1871 | list_splice_init(&p->work_list, &work_list); |
| 1872 | spin_unlock_irqrestore(&p->p_work_lock, flags); |
| 1873 | |
| 1874 | list_for_each_entry_safe(work, tmp, &work_list, list) { |
| 1875 | list_del_init(&work->list); |
| 1876 | qedi_fp_process_cqes(work); |
| 1877 | if (!work->is_solicited) |
| 1878 | kfree(work); |
| 1879 | } |
| 1880 | cond_resched(); |
| 1881 | spin_lock_irqsave(&p->p_work_lock, flags); |
| 1882 | } |
| 1883 | set_current_state(TASK_INTERRUPTIBLE); |
| 1884 | spin_unlock_irqrestore(&p->p_work_lock, flags); |
| 1885 | schedule(); |
| 1886 | } |
| 1887 | __set_current_state(TASK_RUNNING); |
| 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static int qedi_cpu_online(unsigned int cpu) |
| 1893 | { |
| 1894 | struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu); |
| 1895 | struct task_struct *thread; |
| 1896 | |
| 1897 | thread = kthread_create_on_node(qedi_percpu_io_thread, (void *)p, |
| 1898 | cpu_to_node(cpu), |
| 1899 | "qedi_thread/%d", cpu); |
| 1900 | if (IS_ERR(thread)) |
| 1901 | return PTR_ERR(thread); |
| 1902 | |
| 1903 | kthread_bind(thread, cpu); |
| 1904 | p->iothread = thread; |
| 1905 | wake_up_process(thread); |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | static int qedi_cpu_offline(unsigned int cpu) |
| 1910 | { |
| 1911 | struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu); |
| 1912 | struct qedi_work *work, *tmp; |
| 1913 | struct task_struct *thread; |
| 1914 | unsigned long flags; |
| 1915 | |
| 1916 | spin_lock_irqsave(&p->p_work_lock, flags); |
| 1917 | thread = p->iothread; |
| 1918 | p->iothread = NULL; |
| 1919 | |
| 1920 | list_for_each_entry_safe(work, tmp, &p->work_list, list) { |
| 1921 | list_del_init(&work->list); |
| 1922 | qedi_fp_process_cqes(work); |
| 1923 | if (!work->is_solicited) |
| 1924 | kfree(work); |
| 1925 | } |
| 1926 | |
| 1927 | spin_unlock_irqrestore(&p->p_work_lock, flags); |
| 1928 | if (thread) |
| 1929 | kthread_stop(thread); |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | void qedi_reset_host_mtu(struct qedi_ctx *qedi, u16 mtu) |
| 1934 | { |
| 1935 | struct qed_ll2_params params; |
| 1936 | |
| 1937 | qedi_recover_all_conns(qedi); |
| 1938 | |
| 1939 | qedi_ops->ll2->stop(qedi->cdev); |
| 1940 | qedi_ll2_free_skbs(qedi); |
| 1941 | |
| 1942 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, "old MTU %u, new MTU %u\n", |
| 1943 | qedi->ll2_mtu, mtu); |
| 1944 | memset(¶ms, 0, sizeof(params)); |
| 1945 | qedi->ll2_mtu = mtu; |
| 1946 | params.mtu = qedi->ll2_mtu + IPV6_HDR_LEN + TCP_HDR_LEN; |
| 1947 | params.drop_ttl0_packets = 0; |
| 1948 | params.rx_vlan_stripping = 1; |
| 1949 | ether_addr_copy(params.ll2_mac_address, qedi->dev_info.common.hw_mac); |
| 1950 | qedi_ops->ll2->start(qedi->cdev, ¶ms); |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * qedi_get_nvram_block: - Scan through the iSCSI NVRAM block (while accounting |
| 1955 | * for gaps) for the matching absolute-pf-id of the QEDI device. |
| 1956 | */ |
| 1957 | static struct nvm_iscsi_block * |
| 1958 | qedi_get_nvram_block(struct qedi_ctx *qedi) |
| 1959 | { |
| 1960 | int i; |
| 1961 | u8 pf; |
| 1962 | u32 flags; |
| 1963 | struct nvm_iscsi_block *block; |
| 1964 | |
| 1965 | pf = qedi->dev_info.common.abs_pf_id; |
| 1966 | block = &qedi->iscsi_image->iscsi_cfg.block[0]; |
| 1967 | for (i = 0; i < NUM_OF_ISCSI_PF_SUPPORTED; i++, block++) { |
| 1968 | flags = ((block->id) & NVM_ISCSI_CFG_BLK_CTRL_FLAG_MASK) >> |
| 1969 | NVM_ISCSI_CFG_BLK_CTRL_FLAG_OFFSET; |
| 1970 | if (flags & (NVM_ISCSI_CFG_BLK_CTRL_FLAG_IS_NOT_EMPTY | |
| 1971 | NVM_ISCSI_CFG_BLK_CTRL_FLAG_PF_MAPPED) && |
| 1972 | (pf == (block->id & NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_MASK) |
| 1973 | >> NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_OFFSET)) |
| 1974 | return block; |
| 1975 | } |
| 1976 | return NULL; |
| 1977 | } |
| 1978 | |
| 1979 | static ssize_t qedi_show_boot_eth_info(void *data, int type, char *buf) |
| 1980 | { |
| 1981 | struct qedi_ctx *qedi = data; |
| 1982 | struct nvm_iscsi_initiator *initiator; |
| 1983 | int rc = 1; |
| 1984 | u32 ipv6_en, dhcp_en, ip_len; |
| 1985 | struct nvm_iscsi_block *block; |
| 1986 | char *fmt, *ip, *sub, *gw; |
| 1987 | |
| 1988 | block = qedi_get_nvram_block(qedi); |
| 1989 | if (!block) |
| 1990 | return 0; |
| 1991 | |
| 1992 | initiator = &block->initiator; |
| 1993 | ipv6_en = block->generic.ctrl_flags & |
| 1994 | NVM_ISCSI_CFG_GEN_IPV6_ENABLED; |
| 1995 | dhcp_en = block->generic.ctrl_flags & |
| 1996 | NVM_ISCSI_CFG_GEN_DHCP_TCPIP_CONFIG_ENABLED; |
| 1997 | /* Static IP assignments. */ |
| 1998 | fmt = ipv6_en ? "%pI6\n" : "%pI4\n"; |
| 1999 | ip = ipv6_en ? initiator->ipv6.addr.byte : initiator->ipv4.addr.byte; |
| 2000 | ip_len = ipv6_en ? IPV6_LEN : IPV4_LEN; |
| 2001 | sub = ipv6_en ? initiator->ipv6.subnet_mask.byte : |
| 2002 | initiator->ipv4.subnet_mask.byte; |
| 2003 | gw = ipv6_en ? initiator->ipv6.gateway.byte : |
| 2004 | initiator->ipv4.gateway.byte; |
| 2005 | /* DHCP IP adjustments. */ |
| 2006 | fmt = dhcp_en ? "%s\n" : fmt; |
| 2007 | if (dhcp_en) { |
| 2008 | ip = ipv6_en ? "0::0" : "0.0.0.0"; |
| 2009 | sub = ip; |
| 2010 | gw = ip; |
| 2011 | ip_len = ipv6_en ? 5 : 8; |
| 2012 | } |
| 2013 | |
| 2014 | switch (type) { |
| 2015 | case ISCSI_BOOT_ETH_IP_ADDR: |
| 2016 | rc = snprintf(buf, ip_len, fmt, ip); |
| 2017 | break; |
| 2018 | case ISCSI_BOOT_ETH_SUBNET_MASK: |
| 2019 | rc = snprintf(buf, ip_len, fmt, sub); |
| 2020 | break; |
| 2021 | case ISCSI_BOOT_ETH_GATEWAY: |
| 2022 | rc = snprintf(buf, ip_len, fmt, gw); |
| 2023 | break; |
| 2024 | case ISCSI_BOOT_ETH_FLAGS: |
| 2025 | rc = snprintf(buf, 3, "%hhd\n", |
| 2026 | SYSFS_FLAG_FW_SEL_BOOT); |
| 2027 | break; |
| 2028 | case ISCSI_BOOT_ETH_INDEX: |
| 2029 | rc = snprintf(buf, 3, "0\n"); |
| 2030 | break; |
| 2031 | case ISCSI_BOOT_ETH_MAC: |
| 2032 | rc = sysfs_format_mac(buf, qedi->mac, ETH_ALEN); |
| 2033 | break; |
| 2034 | case ISCSI_BOOT_ETH_VLAN: |
| 2035 | rc = snprintf(buf, 12, "%d\n", |
| 2036 | GET_FIELD2(initiator->generic_cont0, |
| 2037 | NVM_ISCSI_CFG_INITIATOR_VLAN)); |
| 2038 | break; |
| 2039 | case ISCSI_BOOT_ETH_ORIGIN: |
| 2040 | if (dhcp_en) |
| 2041 | rc = snprintf(buf, 3, "3\n"); |
| 2042 | break; |
| 2043 | default: |
| 2044 | rc = 0; |
| 2045 | break; |
| 2046 | } |
| 2047 | |
| 2048 | return rc; |
| 2049 | } |
| 2050 | |
| 2051 | static umode_t qedi_eth_get_attr_visibility(void *data, int type) |
| 2052 | { |
| 2053 | int rc = 1; |
| 2054 | |
| 2055 | switch (type) { |
| 2056 | case ISCSI_BOOT_ETH_FLAGS: |
| 2057 | case ISCSI_BOOT_ETH_MAC: |
| 2058 | case ISCSI_BOOT_ETH_INDEX: |
| 2059 | case ISCSI_BOOT_ETH_IP_ADDR: |
| 2060 | case ISCSI_BOOT_ETH_SUBNET_MASK: |
| 2061 | case ISCSI_BOOT_ETH_GATEWAY: |
| 2062 | case ISCSI_BOOT_ETH_ORIGIN: |
| 2063 | case ISCSI_BOOT_ETH_VLAN: |
| 2064 | rc = 0444; |
| 2065 | break; |
| 2066 | default: |
| 2067 | rc = 0; |
| 2068 | break; |
| 2069 | } |
| 2070 | return rc; |
| 2071 | } |
| 2072 | |
| 2073 | static ssize_t qedi_show_boot_ini_info(void *data, int type, char *buf) |
| 2074 | { |
| 2075 | struct qedi_ctx *qedi = data; |
| 2076 | struct nvm_iscsi_initiator *initiator; |
| 2077 | int rc; |
| 2078 | struct nvm_iscsi_block *block; |
| 2079 | |
| 2080 | block = qedi_get_nvram_block(qedi); |
| 2081 | if (!block) |
| 2082 | return 0; |
| 2083 | |
| 2084 | initiator = &block->initiator; |
| 2085 | |
| 2086 | switch (type) { |
| 2087 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 2088 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, |
| 2089 | initiator->initiator_name.byte); |
| 2090 | break; |
| 2091 | default: |
| 2092 | rc = 0; |
| 2093 | break; |
| 2094 | } |
| 2095 | return rc; |
| 2096 | } |
| 2097 | |
| 2098 | static umode_t qedi_ini_get_attr_visibility(void *data, int type) |
| 2099 | { |
| 2100 | int rc; |
| 2101 | |
| 2102 | switch (type) { |
| 2103 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 2104 | rc = 0444; |
| 2105 | break; |
| 2106 | default: |
| 2107 | rc = 0; |
| 2108 | break; |
| 2109 | } |
| 2110 | return rc; |
| 2111 | } |
| 2112 | |
| 2113 | static ssize_t |
| 2114 | qedi_show_boot_tgt_info(struct qedi_ctx *qedi, int type, |
| 2115 | char *buf, enum qedi_nvm_tgts idx) |
| 2116 | { |
| 2117 | int rc = 1; |
| 2118 | u32 ctrl_flags, ipv6_en, chap_en, mchap_en, ip_len; |
| 2119 | struct nvm_iscsi_block *block; |
| 2120 | char *chap_name, *chap_secret; |
| 2121 | char *mchap_name, *mchap_secret; |
| 2122 | |
| 2123 | block = qedi_get_nvram_block(qedi); |
| 2124 | if (!block) |
| 2125 | goto exit_show_tgt_info; |
| 2126 | |
| 2127 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_EVT, |
| 2128 | "Port:%d, tgt_idx:%d\n", |
| 2129 | GET_FIELD2(block->id, NVM_ISCSI_CFG_BLK_MAPPED_PF_ID), idx); |
| 2130 | |
| 2131 | ctrl_flags = block->target[idx].ctrl_flags & |
| 2132 | NVM_ISCSI_CFG_TARGET_ENABLED; |
| 2133 | |
| 2134 | if (!ctrl_flags) { |
| 2135 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_EVT, |
| 2136 | "Target disabled\n"); |
| 2137 | goto exit_show_tgt_info; |
| 2138 | } |
| 2139 | |
| 2140 | ipv6_en = block->generic.ctrl_flags & |
| 2141 | NVM_ISCSI_CFG_GEN_IPV6_ENABLED; |
| 2142 | ip_len = ipv6_en ? IPV6_LEN : IPV4_LEN; |
| 2143 | chap_en = block->generic.ctrl_flags & |
| 2144 | NVM_ISCSI_CFG_GEN_CHAP_ENABLED; |
| 2145 | chap_name = chap_en ? block->initiator.chap_name.byte : NULL; |
| 2146 | chap_secret = chap_en ? block->initiator.chap_password.byte : NULL; |
| 2147 | |
| 2148 | mchap_en = block->generic.ctrl_flags & |
| 2149 | NVM_ISCSI_CFG_GEN_CHAP_MUTUAL_ENABLED; |
| 2150 | mchap_name = mchap_en ? block->target[idx].chap_name.byte : NULL; |
| 2151 | mchap_secret = mchap_en ? block->target[idx].chap_password.byte : NULL; |
| 2152 | |
| 2153 | switch (type) { |
| 2154 | case ISCSI_BOOT_TGT_NAME: |
| 2155 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, |
| 2156 | block->target[idx].target_name.byte); |
| 2157 | break; |
| 2158 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 2159 | if (ipv6_en) |
| 2160 | rc = snprintf(buf, ip_len, "%pI6\n", |
| 2161 | block->target[idx].ipv6_addr.byte); |
| 2162 | else |
| 2163 | rc = snprintf(buf, ip_len, "%pI4\n", |
| 2164 | block->target[idx].ipv4_addr.byte); |
| 2165 | break; |
| 2166 | case ISCSI_BOOT_TGT_PORT: |
| 2167 | rc = snprintf(buf, 12, "%d\n", |
| 2168 | GET_FIELD2(block->target[idx].generic_cont0, |
| 2169 | NVM_ISCSI_CFG_TARGET_TCP_PORT)); |
| 2170 | break; |
| 2171 | case ISCSI_BOOT_TGT_LUN: |
| 2172 | rc = snprintf(buf, 22, "%.*d\n", |
| 2173 | block->target[idx].lun.value[1], |
| 2174 | block->target[idx].lun.value[0]); |
| 2175 | break; |
| 2176 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 2177 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, |
| 2178 | chap_name); |
| 2179 | break; |
| 2180 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 2181 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, |
| 2182 | chap_secret); |
| 2183 | break; |
| 2184 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 2185 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, |
| 2186 | mchap_name); |
| 2187 | break; |
| 2188 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 2189 | rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, |
| 2190 | mchap_secret); |
| 2191 | break; |
| 2192 | case ISCSI_BOOT_TGT_FLAGS: |
| 2193 | rc = snprintf(buf, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 2194 | break; |
| 2195 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 2196 | rc = snprintf(buf, 3, "0\n"); |
| 2197 | break; |
| 2198 | default: |
| 2199 | rc = 0; |
| 2200 | break; |
| 2201 | } |
| 2202 | |
| 2203 | exit_show_tgt_info: |
| 2204 | return rc; |
| 2205 | } |
| 2206 | |
| 2207 | static ssize_t qedi_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 2208 | { |
| 2209 | struct qedi_ctx *qedi = data; |
| 2210 | |
| 2211 | return qedi_show_boot_tgt_info(qedi, type, buf, QEDI_NVM_TGT_PRI); |
| 2212 | } |
| 2213 | |
| 2214 | static ssize_t qedi_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 2215 | { |
| 2216 | struct qedi_ctx *qedi = data; |
| 2217 | |
| 2218 | return qedi_show_boot_tgt_info(qedi, type, buf, QEDI_NVM_TGT_SEC); |
| 2219 | } |
| 2220 | |
| 2221 | static umode_t qedi_tgt_get_attr_visibility(void *data, int type) |
| 2222 | { |
| 2223 | int rc; |
| 2224 | |
| 2225 | switch (type) { |
| 2226 | case ISCSI_BOOT_TGT_NAME: |
| 2227 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 2228 | case ISCSI_BOOT_TGT_PORT: |
| 2229 | case ISCSI_BOOT_TGT_LUN: |
| 2230 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 2231 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 2232 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 2233 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 2234 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 2235 | case ISCSI_BOOT_TGT_FLAGS: |
| 2236 | rc = 0444; |
| 2237 | break; |
| 2238 | default: |
| 2239 | rc = 0; |
| 2240 | break; |
| 2241 | } |
| 2242 | return rc; |
| 2243 | } |
| 2244 | |
| 2245 | static void qedi_boot_release(void *data) |
| 2246 | { |
| 2247 | struct qedi_ctx *qedi = data; |
| 2248 | |
| 2249 | scsi_host_put(qedi->shost); |
| 2250 | } |
| 2251 | |
| 2252 | static int qedi_get_boot_info(struct qedi_ctx *qedi) |
| 2253 | { |
| 2254 | int ret = 1; |
| 2255 | |
| 2256 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 2257 | "Get NVM iSCSI CFG image\n"); |
| 2258 | ret = qedi_ops->common->nvm_get_image(qedi->cdev, |
| 2259 | QED_NVM_IMAGE_ISCSI_CFG, |
| 2260 | (char *)qedi->iscsi_image, |
| 2261 | sizeof(struct qedi_nvm_iscsi_image)); |
| 2262 | if (ret) |
| 2263 | QEDI_ERR(&qedi->dbg_ctx, |
| 2264 | "Could not get NVM image. ret = %d\n", ret); |
| 2265 | |
| 2266 | return ret; |
| 2267 | } |
| 2268 | |
| 2269 | static int qedi_setup_boot_info(struct qedi_ctx *qedi) |
| 2270 | { |
| 2271 | struct iscsi_boot_kobj *boot_kobj; |
| 2272 | |
| 2273 | if (qedi_get_boot_info(qedi)) |
| 2274 | return -EPERM; |
| 2275 | |
| 2276 | qedi->boot_kset = iscsi_boot_create_host_kset(qedi->shost->host_no); |
| 2277 | if (!qedi->boot_kset) |
| 2278 | goto kset_free; |
| 2279 | |
| 2280 | if (!scsi_host_get(qedi->shost)) |
| 2281 | goto kset_free; |
| 2282 | |
| 2283 | boot_kobj = iscsi_boot_create_target(qedi->boot_kset, 0, qedi, |
| 2284 | qedi_show_boot_tgt_pri_info, |
| 2285 | qedi_tgt_get_attr_visibility, |
| 2286 | qedi_boot_release); |
| 2287 | if (!boot_kobj) |
| 2288 | goto put_host; |
| 2289 | |
| 2290 | if (!scsi_host_get(qedi->shost)) |
| 2291 | goto kset_free; |
| 2292 | |
| 2293 | boot_kobj = iscsi_boot_create_target(qedi->boot_kset, 1, qedi, |
| 2294 | qedi_show_boot_tgt_sec_info, |
| 2295 | qedi_tgt_get_attr_visibility, |
| 2296 | qedi_boot_release); |
| 2297 | if (!boot_kobj) |
| 2298 | goto put_host; |
| 2299 | |
| 2300 | if (!scsi_host_get(qedi->shost)) |
| 2301 | goto kset_free; |
| 2302 | |
| 2303 | boot_kobj = iscsi_boot_create_initiator(qedi->boot_kset, 0, qedi, |
| 2304 | qedi_show_boot_ini_info, |
| 2305 | qedi_ini_get_attr_visibility, |
| 2306 | qedi_boot_release); |
| 2307 | if (!boot_kobj) |
| 2308 | goto put_host; |
| 2309 | |
| 2310 | if (!scsi_host_get(qedi->shost)) |
| 2311 | goto kset_free; |
| 2312 | |
| 2313 | boot_kobj = iscsi_boot_create_ethernet(qedi->boot_kset, 0, qedi, |
| 2314 | qedi_show_boot_eth_info, |
| 2315 | qedi_eth_get_attr_visibility, |
| 2316 | qedi_boot_release); |
| 2317 | if (!boot_kobj) |
| 2318 | goto put_host; |
| 2319 | |
| 2320 | return 0; |
| 2321 | |
| 2322 | put_host: |
| 2323 | scsi_host_put(qedi->shost); |
| 2324 | kset_free: |
| 2325 | iscsi_boot_destroy_kset(qedi->boot_kset); |
| 2326 | return -ENOMEM; |
| 2327 | } |
| 2328 | |
| 2329 | static void __qedi_remove(struct pci_dev *pdev, int mode) |
| 2330 | { |
| 2331 | struct qedi_ctx *qedi = pci_get_drvdata(pdev); |
| 2332 | int rval; |
| 2333 | |
| 2334 | if (qedi->tmf_thread) { |
| 2335 | flush_workqueue(qedi->tmf_thread); |
| 2336 | destroy_workqueue(qedi->tmf_thread); |
| 2337 | qedi->tmf_thread = NULL; |
| 2338 | } |
| 2339 | |
| 2340 | if (qedi->offload_thread) { |
| 2341 | flush_workqueue(qedi->offload_thread); |
| 2342 | destroy_workqueue(qedi->offload_thread); |
| 2343 | qedi->offload_thread = NULL; |
| 2344 | } |
| 2345 | |
| 2346 | #ifdef CONFIG_DEBUG_FS |
| 2347 | qedi_dbg_host_exit(&qedi->dbg_ctx); |
| 2348 | #endif |
| 2349 | if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags)) |
| 2350 | qedi_ops->common->set_power_state(qedi->cdev, PCI_D0); |
| 2351 | |
| 2352 | qedi_sync_free_irqs(qedi); |
| 2353 | |
| 2354 | if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags)) { |
| 2355 | qedi_ops->stop(qedi->cdev); |
| 2356 | qedi_ops->ll2->stop(qedi->cdev); |
| 2357 | } |
| 2358 | |
| 2359 | if (mode == QEDI_MODE_NORMAL) |
| 2360 | qedi_free_iscsi_pf_param(qedi); |
| 2361 | |
| 2362 | rval = qedi_ops->common->update_drv_state(qedi->cdev, false); |
| 2363 | if (rval) |
| 2364 | QEDI_ERR(&qedi->dbg_ctx, "Failed to send drv state to MFW\n"); |
| 2365 | |
| 2366 | if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags)) { |
| 2367 | qedi_ops->common->slowpath_stop(qedi->cdev); |
| 2368 | qedi_ops->common->remove(qedi->cdev); |
| 2369 | } |
| 2370 | |
| 2371 | qedi_destroy_fp(qedi); |
| 2372 | |
| 2373 | if (mode == QEDI_MODE_NORMAL) { |
| 2374 | qedi_release_cid_que(qedi); |
| 2375 | qedi_cm_free_mem(qedi); |
| 2376 | qedi_free_uio(qedi->udev); |
| 2377 | qedi_free_itt(qedi); |
| 2378 | |
| 2379 | iscsi_host_remove(qedi->shost); |
| 2380 | iscsi_host_free(qedi->shost); |
| 2381 | |
| 2382 | if (qedi->ll2_recv_thread) { |
| 2383 | kthread_stop(qedi->ll2_recv_thread); |
| 2384 | qedi->ll2_recv_thread = NULL; |
| 2385 | } |
| 2386 | qedi_ll2_free_skbs(qedi); |
| 2387 | |
| 2388 | if (qedi->boot_kset) |
| 2389 | iscsi_boot_destroy_kset(qedi->boot_kset); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | static int __qedi_probe(struct pci_dev *pdev, int mode) |
| 2394 | { |
| 2395 | struct qedi_ctx *qedi; |
| 2396 | struct qed_ll2_params params; |
| 2397 | u32 dp_module = 0; |
| 2398 | u8 dp_level = 0; |
| 2399 | bool is_vf = false; |
| 2400 | char host_buf[16]; |
| 2401 | struct qed_link_params link_params; |
| 2402 | struct qed_slowpath_params sp_params; |
| 2403 | struct qed_probe_params qed_params; |
| 2404 | void *task_start, *task_end; |
| 2405 | int rc; |
| 2406 | u16 tmp; |
| 2407 | |
| 2408 | if (mode != QEDI_MODE_RECOVERY) { |
| 2409 | qedi = qedi_host_alloc(pdev); |
| 2410 | if (!qedi) { |
| 2411 | rc = -ENOMEM; |
| 2412 | goto exit_probe; |
| 2413 | } |
| 2414 | } else { |
| 2415 | qedi = pci_get_drvdata(pdev); |
| 2416 | } |
| 2417 | |
| 2418 | memset(&qed_params, 0, sizeof(qed_params)); |
| 2419 | qed_params.protocol = QED_PROTOCOL_ISCSI; |
| 2420 | qed_params.dp_module = dp_module; |
| 2421 | qed_params.dp_level = dp_level; |
| 2422 | qed_params.is_vf = is_vf; |
| 2423 | qedi->cdev = qedi_ops->common->probe(pdev, &qed_params); |
| 2424 | if (!qedi->cdev) { |
| 2425 | rc = -ENODEV; |
| 2426 | QEDI_ERR(&qedi->dbg_ctx, "Cannot initialize hardware\n"); |
| 2427 | goto free_host; |
| 2428 | } |
| 2429 | |
| 2430 | atomic_set(&qedi->link_state, QEDI_LINK_DOWN); |
| 2431 | |
| 2432 | rc = qedi_ops->fill_dev_info(qedi->cdev, &qedi->dev_info); |
| 2433 | if (rc) |
| 2434 | goto free_host; |
| 2435 | |
| 2436 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 2437 | "dev_info: num_hwfns=%d affin_hwfn_idx=%d.\n", |
| 2438 | qedi->dev_info.common.num_hwfns, |
| 2439 | qedi_ops->common->get_affin_hwfn_idx(qedi->cdev)); |
| 2440 | |
| 2441 | if (mode != QEDI_MODE_RECOVERY) { |
| 2442 | rc = qedi_set_iscsi_pf_param(qedi); |
| 2443 | if (rc) { |
| 2444 | rc = -ENOMEM; |
| 2445 | QEDI_ERR(&qedi->dbg_ctx, |
| 2446 | "Set iSCSI pf param fail\n"); |
| 2447 | goto free_host; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params); |
| 2452 | |
| 2453 | rc = qedi_prepare_fp(qedi); |
| 2454 | if (rc) { |
| 2455 | QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath.\n"); |
| 2456 | goto free_pf_params; |
| 2457 | } |
| 2458 | |
| 2459 | /* Start the Slowpath-process */ |
| 2460 | memset(&sp_params, 0, sizeof(struct qed_slowpath_params)); |
| 2461 | sp_params.int_mode = QED_INT_MODE_MSIX; |
| 2462 | sp_params.drv_major = QEDI_DRIVER_MAJOR_VER; |
| 2463 | sp_params.drv_minor = QEDI_DRIVER_MINOR_VER; |
| 2464 | sp_params.drv_rev = QEDI_DRIVER_REV_VER; |
| 2465 | sp_params.drv_eng = QEDI_DRIVER_ENG_VER; |
| 2466 | strlcpy(sp_params.name, "qedi iSCSI", QED_DRV_VER_STR_SIZE); |
| 2467 | rc = qedi_ops->common->slowpath_start(qedi->cdev, &sp_params); |
| 2468 | if (rc) { |
| 2469 | QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath\n"); |
| 2470 | goto stop_hw; |
| 2471 | } |
| 2472 | |
| 2473 | /* update_pf_params needs to be called before and after slowpath |
| 2474 | * start |
| 2475 | */ |
| 2476 | qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params); |
| 2477 | |
| 2478 | rc = qedi_setup_int(qedi); |
| 2479 | if (rc) |
| 2480 | goto stop_iscsi_func; |
| 2481 | |
| 2482 | qedi_ops->common->set_power_state(qedi->cdev, PCI_D0); |
| 2483 | |
| 2484 | /* Learn information crucial for qedi to progress */ |
| 2485 | rc = qedi_ops->fill_dev_info(qedi->cdev, &qedi->dev_info); |
| 2486 | if (rc) |
| 2487 | goto stop_iscsi_func; |
| 2488 | |
| 2489 | /* Record BDQ producer doorbell addresses */ |
| 2490 | qedi->bdq_primary_prod = qedi->dev_info.primary_dbq_rq_addr; |
| 2491 | qedi->bdq_secondary_prod = qedi->dev_info.secondary_bdq_rq_addr; |
| 2492 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 2493 | "BDQ primary_prod=%p secondary_prod=%p.\n", |
| 2494 | qedi->bdq_primary_prod, |
| 2495 | qedi->bdq_secondary_prod); |
| 2496 | |
| 2497 | /* |
| 2498 | * We need to write the number of BDs in the BDQ we've preallocated so |
| 2499 | * the f/w will do a prefetch and we'll get an unsolicited CQE when a |
| 2500 | * packet arrives. |
| 2501 | */ |
| 2502 | qedi->bdq_prod_idx = QEDI_BDQ_NUM; |
| 2503 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 2504 | "Writing %d to primary and secondary BDQ doorbell registers.\n", |
| 2505 | qedi->bdq_prod_idx); |
| 2506 | writew(qedi->bdq_prod_idx, qedi->bdq_primary_prod); |
| 2507 | tmp = readw(qedi->bdq_primary_prod); |
| 2508 | writew(qedi->bdq_prod_idx, qedi->bdq_secondary_prod); |
| 2509 | tmp = readw(qedi->bdq_secondary_prod); |
| 2510 | |
| 2511 | ether_addr_copy(qedi->mac, qedi->dev_info.common.hw_mac); |
| 2512 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, "MAC address is %pM.\n", |
| 2513 | qedi->mac); |
| 2514 | |
| 2515 | sprintf(host_buf, "host_%d", qedi->shost->host_no); |
| 2516 | qedi_ops->common->set_name(qedi->cdev, host_buf); |
| 2517 | |
| 2518 | qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi); |
| 2519 | |
| 2520 | memset(¶ms, 0, sizeof(params)); |
| 2521 | params.mtu = DEF_PATH_MTU + IPV6_HDR_LEN + TCP_HDR_LEN; |
| 2522 | qedi->ll2_mtu = DEF_PATH_MTU; |
| 2523 | params.drop_ttl0_packets = 0; |
| 2524 | params.rx_vlan_stripping = 1; |
| 2525 | ether_addr_copy(params.ll2_mac_address, qedi->dev_info.common.hw_mac); |
| 2526 | |
| 2527 | if (mode != QEDI_MODE_RECOVERY) { |
| 2528 | /* set up rx path */ |
| 2529 | INIT_LIST_HEAD(&qedi->ll2_skb_list); |
| 2530 | spin_lock_init(&qedi->ll2_lock); |
| 2531 | /* start qedi context */ |
| 2532 | spin_lock_init(&qedi->hba_lock); |
| 2533 | spin_lock_init(&qedi->task_idx_lock); |
| 2534 | mutex_init(&qedi->stats_lock); |
| 2535 | } |
| 2536 | qedi_ops->ll2->register_cb_ops(qedi->cdev, &qedi_ll2_cb_ops, qedi); |
| 2537 | qedi_ops->ll2->start(qedi->cdev, ¶ms); |
| 2538 | |
| 2539 | if (mode != QEDI_MODE_RECOVERY) { |
| 2540 | qedi->ll2_recv_thread = kthread_run(qedi_ll2_recv_thread, |
| 2541 | (void *)qedi, |
| 2542 | "qedi_ll2_thread"); |
| 2543 | } |
| 2544 | |
| 2545 | rc = qedi_ops->start(qedi->cdev, &qedi->tasks, |
| 2546 | qedi, qedi_iscsi_event_cb); |
| 2547 | if (rc) { |
| 2548 | rc = -ENODEV; |
| 2549 | QEDI_ERR(&qedi->dbg_ctx, "Cannot start iSCSI function\n"); |
| 2550 | goto stop_slowpath; |
| 2551 | } |
| 2552 | |
| 2553 | task_start = qedi_get_task_mem(&qedi->tasks, 0); |
| 2554 | task_end = qedi_get_task_mem(&qedi->tasks, MAX_TID_BLOCKS_ISCSI - 1); |
| 2555 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, |
| 2556 | "Task context start=%p, end=%p block_size=%u.\n", |
| 2557 | task_start, task_end, qedi->tasks.size); |
| 2558 | |
| 2559 | memset(&link_params, 0, sizeof(link_params)); |
| 2560 | link_params.link_up = true; |
| 2561 | rc = qedi_ops->common->set_link(qedi->cdev, &link_params); |
| 2562 | if (rc) { |
| 2563 | QEDI_WARN(&qedi->dbg_ctx, "Link set up failed.\n"); |
| 2564 | atomic_set(&qedi->link_state, QEDI_LINK_DOWN); |
| 2565 | } |
| 2566 | |
| 2567 | #ifdef CONFIG_DEBUG_FS |
| 2568 | qedi_dbg_host_init(&qedi->dbg_ctx, qedi_debugfs_ops, |
| 2569 | qedi_dbg_fops); |
| 2570 | #endif |
| 2571 | QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, |
| 2572 | "QLogic FastLinQ iSCSI Module qedi %s, FW %d.%d.%d.%d\n", |
| 2573 | QEDI_MODULE_VERSION, FW_MAJOR_VERSION, FW_MINOR_VERSION, |
| 2574 | FW_REVISION_VERSION, FW_ENGINEERING_VERSION); |
| 2575 | |
| 2576 | if (mode == QEDI_MODE_NORMAL) { |
| 2577 | if (iscsi_host_add(qedi->shost, &pdev->dev)) { |
| 2578 | QEDI_ERR(&qedi->dbg_ctx, |
| 2579 | "Could not add iscsi host\n"); |
| 2580 | rc = -ENOMEM; |
| 2581 | goto remove_host; |
| 2582 | } |
| 2583 | |
| 2584 | /* Allocate uio buffers */ |
| 2585 | rc = qedi_alloc_uio_rings(qedi); |
| 2586 | if (rc) { |
| 2587 | QEDI_ERR(&qedi->dbg_ctx, |
| 2588 | "UIO alloc ring failed err=%d\n", rc); |
| 2589 | goto remove_host; |
| 2590 | } |
| 2591 | |
| 2592 | rc = qedi_init_uio(qedi); |
| 2593 | if (rc) { |
| 2594 | QEDI_ERR(&qedi->dbg_ctx, |
| 2595 | "UIO init failed, err=%d\n", rc); |
| 2596 | goto free_uio; |
| 2597 | } |
| 2598 | |
| 2599 | /* host the array on iscsi_conn */ |
| 2600 | rc = qedi_setup_cid_que(qedi); |
| 2601 | if (rc) { |
| 2602 | QEDI_ERR(&qedi->dbg_ctx, |
| 2603 | "Could not setup cid que\n"); |
| 2604 | goto free_uio; |
| 2605 | } |
| 2606 | |
| 2607 | rc = qedi_cm_alloc_mem(qedi); |
| 2608 | if (rc) { |
| 2609 | QEDI_ERR(&qedi->dbg_ctx, |
| 2610 | "Could not alloc cm memory\n"); |
| 2611 | goto free_cid_que; |
| 2612 | } |
| 2613 | |
| 2614 | rc = qedi_alloc_itt(qedi); |
| 2615 | if (rc) { |
| 2616 | QEDI_ERR(&qedi->dbg_ctx, |
| 2617 | "Could not alloc itt memory\n"); |
| 2618 | goto free_cid_que; |
| 2619 | } |
| 2620 | |
| 2621 | sprintf(host_buf, "host_%d", qedi->shost->host_no); |
| 2622 | qedi->tmf_thread = create_singlethread_workqueue(host_buf); |
| 2623 | if (!qedi->tmf_thread) { |
| 2624 | QEDI_ERR(&qedi->dbg_ctx, |
| 2625 | "Unable to start tmf thread!\n"); |
| 2626 | rc = -ENODEV; |
| 2627 | goto free_cid_que; |
| 2628 | } |
| 2629 | |
| 2630 | sprintf(host_buf, "qedi_ofld%d", qedi->shost->host_no); |
| 2631 | qedi->offload_thread = create_workqueue(host_buf); |
| 2632 | if (!qedi->offload_thread) { |
| 2633 | QEDI_ERR(&qedi->dbg_ctx, |
| 2634 | "Unable to start offload thread!\n"); |
| 2635 | rc = -ENODEV; |
| 2636 | goto free_tmf_thread; |
| 2637 | } |
| 2638 | |
| 2639 | /* F/w needs 1st task context memory entry for performance */ |
| 2640 | set_bit(QEDI_RESERVE_TASK_ID, qedi->task_idx_map); |
| 2641 | atomic_set(&qedi->num_offloads, 0); |
| 2642 | |
| 2643 | if (qedi_setup_boot_info(qedi)) |
| 2644 | QEDI_ERR(&qedi->dbg_ctx, |
| 2645 | "No iSCSI boot target configured\n"); |
| 2646 | |
| 2647 | rc = qedi_ops->common->update_drv_state(qedi->cdev, true); |
| 2648 | if (rc) |
| 2649 | QEDI_ERR(&qedi->dbg_ctx, |
| 2650 | "Failed to send drv state to MFW\n"); |
| 2651 | |
| 2652 | } |
| 2653 | |
| 2654 | return 0; |
| 2655 | |
| 2656 | free_tmf_thread: |
| 2657 | destroy_workqueue(qedi->tmf_thread); |
| 2658 | free_cid_que: |
| 2659 | qedi_release_cid_que(qedi); |
| 2660 | free_uio: |
| 2661 | qedi_free_uio(qedi->udev); |
| 2662 | remove_host: |
| 2663 | #ifdef CONFIG_DEBUG_FS |
| 2664 | qedi_dbg_host_exit(&qedi->dbg_ctx); |
| 2665 | #endif |
| 2666 | iscsi_host_remove(qedi->shost); |
| 2667 | stop_iscsi_func: |
| 2668 | qedi_ops->stop(qedi->cdev); |
| 2669 | stop_slowpath: |
| 2670 | qedi_ops->common->slowpath_stop(qedi->cdev); |
| 2671 | stop_hw: |
| 2672 | qedi_ops->common->remove(qedi->cdev); |
| 2673 | free_pf_params: |
| 2674 | qedi_free_iscsi_pf_param(qedi); |
| 2675 | free_host: |
| 2676 | iscsi_host_free(qedi->shost); |
| 2677 | exit_probe: |
| 2678 | return rc; |
| 2679 | } |
| 2680 | |
| 2681 | static int qedi_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 2682 | { |
| 2683 | return __qedi_probe(pdev, QEDI_MODE_NORMAL); |
| 2684 | } |
| 2685 | |
| 2686 | static void qedi_remove(struct pci_dev *pdev) |
| 2687 | { |
| 2688 | __qedi_remove(pdev, QEDI_MODE_NORMAL); |
| 2689 | } |
| 2690 | |
| 2691 | static struct pci_device_id qedi_pci_tbl[] = { |
| 2692 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x165E) }, |
| 2693 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x8084) }, |
| 2694 | { 0 }, |
| 2695 | }; |
| 2696 | MODULE_DEVICE_TABLE(pci, qedi_pci_tbl); |
| 2697 | |
| 2698 | static enum cpuhp_state qedi_cpuhp_state; |
| 2699 | |
| 2700 | static struct pci_driver qedi_pci_driver = { |
| 2701 | .name = QEDI_MODULE_NAME, |
| 2702 | .id_table = qedi_pci_tbl, |
| 2703 | .probe = qedi_probe, |
| 2704 | .remove = qedi_remove, |
| 2705 | }; |
| 2706 | |
| 2707 | static int __init qedi_init(void) |
| 2708 | { |
| 2709 | struct qedi_percpu_s *p; |
| 2710 | int cpu, rc = 0; |
| 2711 | |
| 2712 | qedi_ops = qed_get_iscsi_ops(); |
| 2713 | if (!qedi_ops) { |
| 2714 | QEDI_ERR(NULL, "Failed to get qed iSCSI operations\n"); |
| 2715 | return -EINVAL; |
| 2716 | } |
| 2717 | |
| 2718 | #ifdef CONFIG_DEBUG_FS |
| 2719 | qedi_dbg_init("qedi"); |
| 2720 | #endif |
| 2721 | |
| 2722 | qedi_scsi_transport = iscsi_register_transport(&qedi_iscsi_transport); |
| 2723 | if (!qedi_scsi_transport) { |
| 2724 | QEDI_ERR(NULL, "Could not register qedi transport"); |
| 2725 | rc = -ENOMEM; |
| 2726 | goto exit_qedi_init_1; |
| 2727 | } |
| 2728 | |
| 2729 | for_each_possible_cpu(cpu) { |
| 2730 | p = &per_cpu(qedi_percpu, cpu); |
| 2731 | INIT_LIST_HEAD(&p->work_list); |
| 2732 | spin_lock_init(&p->p_work_lock); |
| 2733 | p->iothread = NULL; |
| 2734 | } |
| 2735 | |
| 2736 | rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/qedi:online", |
| 2737 | qedi_cpu_online, qedi_cpu_offline); |
| 2738 | if (rc < 0) |
| 2739 | goto exit_qedi_init_2; |
| 2740 | qedi_cpuhp_state = rc; |
| 2741 | |
| 2742 | rc = pci_register_driver(&qedi_pci_driver); |
| 2743 | if (rc) { |
| 2744 | QEDI_ERR(NULL, "Failed to register driver\n"); |
| 2745 | goto exit_qedi_hp; |
| 2746 | } |
| 2747 | |
| 2748 | return 0; |
| 2749 | |
| 2750 | exit_qedi_hp: |
| 2751 | cpuhp_remove_state(qedi_cpuhp_state); |
| 2752 | exit_qedi_init_2: |
| 2753 | iscsi_unregister_transport(&qedi_iscsi_transport); |
| 2754 | exit_qedi_init_1: |
| 2755 | #ifdef CONFIG_DEBUG_FS |
| 2756 | qedi_dbg_exit(); |
| 2757 | #endif |
| 2758 | qed_put_iscsi_ops(); |
| 2759 | return rc; |
| 2760 | } |
| 2761 | |
| 2762 | static void __exit qedi_cleanup(void) |
| 2763 | { |
| 2764 | pci_unregister_driver(&qedi_pci_driver); |
| 2765 | cpuhp_remove_state(qedi_cpuhp_state); |
| 2766 | iscsi_unregister_transport(&qedi_iscsi_transport); |
| 2767 | |
| 2768 | #ifdef CONFIG_DEBUG_FS |
| 2769 | qedi_dbg_exit(); |
| 2770 | #endif |
| 2771 | qed_put_iscsi_ops(); |
| 2772 | } |
| 2773 | |
| 2774 | MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx iSCSI Module"); |
| 2775 | MODULE_LICENSE("GPL"); |
| 2776 | MODULE_AUTHOR("QLogic Corporation"); |
| 2777 | MODULE_VERSION(QEDI_MODULE_VERSION); |
| 2778 | module_init(qedi_init); |
| 2779 | module_exit(qedi_cleanup); |