Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * QLogic FCoE Offload Driver |
Chad Dupuis | 12d0b12 | 2017-05-31 06:33:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2016-2017 Cavium Inc. |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 4 | * |
| 5 | * This software is available under the terms of the GNU General Public License |
| 6 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 7 | * this source tree. |
| 8 | */ |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/pci.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/highmem.h> |
| 15 | #include <linux/crc32.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/kthread.h> |
| 19 | #include <scsi/libfc.h> |
| 20 | #include <scsi/scsi_host.h> |
| 21 | #include <linux/if_ether.h> |
| 22 | #include <linux/if_vlan.h> |
| 23 | #include <linux/cpu.h> |
| 24 | #include "qedf.h" |
Chad Dupuis | 5185b32 | 2017-05-31 06:33:48 -0700 | [diff] [blame] | 25 | #include <uapi/linux/pci_regs.h> |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 26 | |
| 27 | const struct qed_fcoe_ops *qed_ops; |
| 28 | |
| 29 | static int qedf_probe(struct pci_dev *pdev, const struct pci_device_id *id); |
| 30 | static void qedf_remove(struct pci_dev *pdev); |
| 31 | |
| 32 | extern struct qedf_debugfs_ops qedf_debugfs_ops; |
| 33 | extern struct file_operations qedf_dbg_fops; |
| 34 | |
| 35 | /* |
| 36 | * Driver module parameters. |
| 37 | */ |
| 38 | static unsigned int qedf_dev_loss_tmo = 60; |
| 39 | module_param_named(dev_loss_tmo, qedf_dev_loss_tmo, int, S_IRUGO); |
| 40 | MODULE_PARM_DESC(dev_loss_tmo, " dev_loss_tmo setting for attached " |
| 41 | "remote ports (default 60)"); |
| 42 | |
| 43 | uint qedf_debug = QEDF_LOG_INFO; |
| 44 | module_param_named(debug, qedf_debug, uint, S_IRUGO); |
| 45 | MODULE_PARM_DESC(qedf_debug, " Debug mask. Pass '1' to enable default debugging" |
| 46 | " mask"); |
| 47 | |
| 48 | static uint qedf_fipvlan_retries = 30; |
| 49 | module_param_named(fipvlan_retries, qedf_fipvlan_retries, int, S_IRUGO); |
| 50 | MODULE_PARM_DESC(fipvlan_retries, " Number of FIP VLAN requests to attempt " |
| 51 | "before giving up (default 30)"); |
| 52 | |
| 53 | static uint qedf_fallback_vlan = QEDF_FALLBACK_VLAN; |
| 54 | module_param_named(fallback_vlan, qedf_fallback_vlan, int, S_IRUGO); |
| 55 | MODULE_PARM_DESC(fallback_vlan, " VLAN ID to try if fip vlan request fails " |
| 56 | "(default 1002)."); |
| 57 | |
| 58 | static uint qedf_default_prio = QEDF_DEFAULT_PRIO; |
| 59 | module_param_named(default_prio, qedf_default_prio, int, S_IRUGO); |
| 60 | MODULE_PARM_DESC(default_prio, " Default 802.1q priority for FIP and FCoE" |
| 61 | " traffic (default 3)."); |
| 62 | |
| 63 | uint qedf_dump_frames; |
| 64 | module_param_named(dump_frames, qedf_dump_frames, int, S_IRUGO | S_IWUSR); |
| 65 | MODULE_PARM_DESC(dump_frames, " Print the skb data of FIP and FCoE frames " |
| 66 | "(default off)"); |
| 67 | |
| 68 | static uint qedf_queue_depth; |
| 69 | module_param_named(queue_depth, qedf_queue_depth, int, S_IRUGO); |
| 70 | MODULE_PARM_DESC(queue_depth, " Sets the queue depth for all LUNs discovered " |
| 71 | "by the qedf driver. Default is 0 (use OS default)."); |
| 72 | |
| 73 | uint qedf_io_tracing; |
| 74 | module_param_named(io_tracing, qedf_io_tracing, int, S_IRUGO | S_IWUSR); |
| 75 | MODULE_PARM_DESC(io_tracing, " Enable logging of SCSI requests/completions " |
| 76 | "into trace buffer. (default off)."); |
| 77 | |
| 78 | static uint qedf_max_lun = MAX_FIBRE_LUNS; |
| 79 | module_param_named(max_lun, qedf_max_lun, int, S_IRUGO); |
| 80 | MODULE_PARM_DESC(max_lun, " Sets the maximum luns per target that the driver " |
| 81 | "supports. (default 0xffffffff)"); |
| 82 | |
| 83 | uint qedf_link_down_tmo; |
| 84 | module_param_named(link_down_tmo, qedf_link_down_tmo, int, S_IRUGO); |
| 85 | MODULE_PARM_DESC(link_down_tmo, " Delays informing the fcoe transport that the " |
| 86 | "link is down by N seconds."); |
| 87 | |
| 88 | bool qedf_retry_delay; |
| 89 | module_param_named(retry_delay, qedf_retry_delay, bool, S_IRUGO | S_IWUSR); |
| 90 | MODULE_PARM_DESC(retry_delay, " Enable/disable handling of FCP_RSP IU retry " |
| 91 | "delay handling (default off)."); |
| 92 | |
| 93 | static uint qedf_dp_module; |
| 94 | module_param_named(dp_module, qedf_dp_module, uint, S_IRUGO); |
| 95 | MODULE_PARM_DESC(dp_module, " bit flags control for verbose printk passed " |
| 96 | "qed module during probe."); |
| 97 | |
Chad Dupuis | 2b82a62 | 2017-05-31 06:33:54 -0700 | [diff] [blame] | 98 | static uint qedf_dp_level = QED_LEVEL_NOTICE; |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 99 | module_param_named(dp_level, qedf_dp_level, uint, S_IRUGO); |
| 100 | MODULE_PARM_DESC(dp_level, " printk verbosity control passed to qed module " |
| 101 | "during probe (0-3: 0 more verbose)."); |
| 102 | |
| 103 | struct workqueue_struct *qedf_io_wq; |
| 104 | |
| 105 | static struct fcoe_percpu_s qedf_global; |
| 106 | static DEFINE_SPINLOCK(qedf_global_lock); |
| 107 | |
| 108 | static struct kmem_cache *qedf_io_work_cache; |
| 109 | |
| 110 | void qedf_set_vlan_id(struct qedf_ctx *qedf, int vlan_id) |
| 111 | { |
| 112 | qedf->vlan_id = vlan_id; |
| 113 | qedf->vlan_id |= qedf_default_prio << VLAN_PRIO_SHIFT; |
| 114 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Setting vlan_id=%04x " |
| 115 | "prio=%d.\n", vlan_id, qedf_default_prio); |
| 116 | } |
| 117 | |
| 118 | /* Returns true if we have a valid vlan, false otherwise */ |
| 119 | static bool qedf_initiate_fipvlan_req(struct qedf_ctx *qedf) |
| 120 | { |
| 121 | int rc; |
| 122 | |
| 123 | if (atomic_read(&qedf->link_state) != QEDF_LINK_UP) { |
| 124 | QEDF_ERR(&(qedf->dbg_ctx), "Link not up.\n"); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | while (qedf->fipvlan_retries--) { |
| 129 | if (qedf->vlan_id > 0) |
| 130 | return true; |
| 131 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 132 | "Retry %d.\n", qedf->fipvlan_retries); |
| 133 | init_completion(&qedf->fipvlan_compl); |
| 134 | qedf_fcoe_send_vlan_req(qedf); |
| 135 | rc = wait_for_completion_timeout(&qedf->fipvlan_compl, |
| 136 | 1 * HZ); |
| 137 | if (rc > 0) { |
| 138 | fcoe_ctlr_link_up(&qedf->ctlr); |
| 139 | return true; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | static void qedf_handle_link_update(struct work_struct *work) |
| 147 | { |
| 148 | struct qedf_ctx *qedf = |
| 149 | container_of(work, struct qedf_ctx, link_update.work); |
| 150 | int rc; |
| 151 | |
| 152 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Entered.\n"); |
| 153 | |
| 154 | if (atomic_read(&qedf->link_state) == QEDF_LINK_UP) { |
| 155 | rc = qedf_initiate_fipvlan_req(qedf); |
| 156 | if (rc) |
| 157 | return; |
| 158 | /* |
| 159 | * If we get here then we never received a repsonse to our |
| 160 | * fip vlan request so set the vlan_id to the default and |
| 161 | * tell FCoE that the link is up |
| 162 | */ |
| 163 | QEDF_WARN(&(qedf->dbg_ctx), "Did not receive FIP VLAN " |
| 164 | "response, falling back to default VLAN %d.\n", |
| 165 | qedf_fallback_vlan); |
| 166 | qedf_set_vlan_id(qedf, QEDF_FALLBACK_VLAN); |
| 167 | |
| 168 | /* |
| 169 | * Zero out data_src_addr so we'll update it with the new |
| 170 | * lport port_id |
| 171 | */ |
| 172 | eth_zero_addr(qedf->data_src_addr); |
| 173 | fcoe_ctlr_link_up(&qedf->ctlr); |
| 174 | } else if (atomic_read(&qedf->link_state) == QEDF_LINK_DOWN) { |
| 175 | /* |
| 176 | * If we hit here and link_down_tmo_valid is still 1 it means |
| 177 | * that link_down_tmo timed out so set it to 0 to make sure any |
| 178 | * other readers have accurate state. |
| 179 | */ |
| 180 | atomic_set(&qedf->link_down_tmo_valid, 0); |
| 181 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 182 | "Calling fcoe_ctlr_link_down().\n"); |
| 183 | fcoe_ctlr_link_down(&qedf->ctlr); |
| 184 | qedf_wait_for_upload(qedf); |
| 185 | /* Reset the number of FIP VLAN retries */ |
| 186 | qedf->fipvlan_retries = qedf_fipvlan_retries; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | static void qedf_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, |
| 191 | void *arg) |
| 192 | { |
| 193 | struct fc_exch *exch = fc_seq_exch(seq); |
| 194 | struct fc_lport *lport = exch->lp; |
| 195 | struct qedf_ctx *qedf = lport_priv(lport); |
| 196 | |
| 197 | if (!qedf) { |
| 198 | QEDF_ERR(NULL, "qedf is NULL.\n"); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * If ERR_PTR is set then don't try to stat anything as it will cause |
| 204 | * a crash when we access fp. |
| 205 | */ |
| 206 | if (IS_ERR(fp)) { |
| 207 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, |
| 208 | "fp has IS_ERR() set.\n"); |
| 209 | goto skip_stat; |
| 210 | } |
| 211 | |
| 212 | /* Log stats for FLOGI reject */ |
| 213 | if (fc_frame_payload_op(fp) == ELS_LS_RJT) |
| 214 | qedf->flogi_failed++; |
| 215 | |
| 216 | /* Complete flogi_compl so we can proceed to sending ADISCs */ |
| 217 | complete(&qedf->flogi_compl); |
| 218 | |
| 219 | skip_stat: |
| 220 | /* Report response to libfc */ |
| 221 | fc_lport_flogi_resp(seq, fp, lport); |
| 222 | } |
| 223 | |
| 224 | static struct fc_seq *qedf_elsct_send(struct fc_lport *lport, u32 did, |
| 225 | struct fc_frame *fp, unsigned int op, |
| 226 | void (*resp)(struct fc_seq *, |
| 227 | struct fc_frame *, |
| 228 | void *), |
| 229 | void *arg, u32 timeout) |
| 230 | { |
| 231 | struct qedf_ctx *qedf = lport_priv(lport); |
| 232 | |
| 233 | /* |
| 234 | * Intercept FLOGI for statistic purposes. Note we use the resp |
| 235 | * callback to tell if this is really a flogi. |
| 236 | */ |
| 237 | if (resp == fc_lport_flogi_resp) { |
| 238 | qedf->flogi_cnt++; |
| 239 | return fc_elsct_send(lport, did, fp, op, qedf_flogi_resp, |
| 240 | arg, timeout); |
| 241 | } |
| 242 | |
| 243 | return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); |
| 244 | } |
| 245 | |
| 246 | int qedf_send_flogi(struct qedf_ctx *qedf) |
| 247 | { |
| 248 | struct fc_lport *lport; |
| 249 | struct fc_frame *fp; |
| 250 | |
| 251 | lport = qedf->lport; |
| 252 | |
| 253 | if (!lport->tt.elsct_send) |
| 254 | return -EINVAL; |
| 255 | |
| 256 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 257 | if (!fp) { |
| 258 | QEDF_ERR(&(qedf->dbg_ctx), "fc_frame_alloc failed.\n"); |
| 259 | return -ENOMEM; |
| 260 | } |
| 261 | |
| 262 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, |
| 263 | "Sending FLOGI to reestablish session with switch.\n"); |
| 264 | lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, |
| 265 | ELS_FLOGI, qedf_flogi_resp, lport, lport->r_a_tov); |
| 266 | |
| 267 | init_completion(&qedf->flogi_compl); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | struct qedf_tmp_rdata_item { |
| 273 | struct fc_rport_priv *rdata; |
| 274 | struct list_head list; |
| 275 | }; |
| 276 | |
| 277 | /* |
| 278 | * This function is called if link_down_tmo is in use. If we get a link up and |
| 279 | * link_down_tmo has not expired then use just FLOGI/ADISC to recover our |
| 280 | * sessions with targets. Otherwise, just call fcoe_ctlr_link_up(). |
| 281 | */ |
| 282 | static void qedf_link_recovery(struct work_struct *work) |
| 283 | { |
| 284 | struct qedf_ctx *qedf = |
| 285 | container_of(work, struct qedf_ctx, link_recovery.work); |
| 286 | struct qedf_rport *fcport; |
| 287 | struct fc_rport_priv *rdata; |
| 288 | struct qedf_tmp_rdata_item *rdata_item, *tmp_rdata_item; |
| 289 | bool rc; |
| 290 | int retries = 30; |
| 291 | int rval, i; |
| 292 | struct list_head rdata_login_list; |
| 293 | |
| 294 | INIT_LIST_HEAD(&rdata_login_list); |
| 295 | |
| 296 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 297 | "Link down tmo did not expire.\n"); |
| 298 | |
| 299 | /* |
| 300 | * Essentially reset the fcoe_ctlr here without affecting the state |
| 301 | * of the libfc structs. |
| 302 | */ |
| 303 | qedf->ctlr.state = FIP_ST_LINK_WAIT; |
| 304 | fcoe_ctlr_link_down(&qedf->ctlr); |
| 305 | |
| 306 | /* |
| 307 | * Bring the link up before we send the fipvlan request so libfcoe |
| 308 | * can select a new fcf in parallel |
| 309 | */ |
| 310 | fcoe_ctlr_link_up(&qedf->ctlr); |
| 311 | |
| 312 | /* Since the link when down and up to verify which vlan we're on */ |
| 313 | qedf->fipvlan_retries = qedf_fipvlan_retries; |
| 314 | rc = qedf_initiate_fipvlan_req(qedf); |
| 315 | if (!rc) |
| 316 | return; |
| 317 | |
| 318 | /* |
| 319 | * We need to wait for an FCF to be selected due to the |
| 320 | * fcoe_ctlr_link_up other the FLOGI will be rejected. |
| 321 | */ |
| 322 | while (retries > 0) { |
| 323 | if (qedf->ctlr.sel_fcf) { |
| 324 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 325 | "FCF reselected, proceeding with FLOGI.\n"); |
| 326 | break; |
| 327 | } |
| 328 | msleep(500); |
| 329 | retries--; |
| 330 | } |
| 331 | |
| 332 | if (retries < 1) { |
| 333 | QEDF_ERR(&(qedf->dbg_ctx), "Exhausted retries waiting for " |
| 334 | "FCF selection.\n"); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | rval = qedf_send_flogi(qedf); |
| 339 | if (rval) |
| 340 | return; |
| 341 | |
| 342 | /* Wait for FLOGI completion before proceeding with sending ADISCs */ |
| 343 | i = wait_for_completion_timeout(&qedf->flogi_compl, |
| 344 | qedf->lport->r_a_tov); |
| 345 | if (i == 0) { |
| 346 | QEDF_ERR(&(qedf->dbg_ctx), "FLOGI timed out.\n"); |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Call lport->tt.rport_login which will cause libfc to send an |
| 352 | * ADISC since the rport is in state ready. |
| 353 | */ |
| 354 | rcu_read_lock(); |
| 355 | list_for_each_entry_rcu(fcport, &qedf->fcports, peers) { |
| 356 | rdata = fcport->rdata; |
| 357 | if (rdata == NULL) |
| 358 | continue; |
| 359 | rdata_item = kzalloc(sizeof(struct qedf_tmp_rdata_item), |
| 360 | GFP_ATOMIC); |
| 361 | if (!rdata_item) |
| 362 | continue; |
| 363 | if (kref_get_unless_zero(&rdata->kref)) { |
| 364 | rdata_item->rdata = rdata; |
| 365 | list_add(&rdata_item->list, &rdata_login_list); |
| 366 | } else |
| 367 | kfree(rdata_item); |
| 368 | } |
| 369 | rcu_read_unlock(); |
| 370 | /* |
| 371 | * Do the fc_rport_login outside of the rcu lock so we don't take a |
| 372 | * mutex in an atomic context. |
| 373 | */ |
| 374 | list_for_each_entry_safe(rdata_item, tmp_rdata_item, &rdata_login_list, |
| 375 | list) { |
| 376 | list_del(&rdata_item->list); |
| 377 | fc_rport_login(rdata_item->rdata); |
| 378 | kref_put(&rdata_item->rdata->kref, fc_rport_destroy); |
| 379 | kfree(rdata_item); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void qedf_update_link_speed(struct qedf_ctx *qedf, |
| 384 | struct qed_link_output *link) |
| 385 | { |
| 386 | struct fc_lport *lport = qedf->lport; |
| 387 | |
| 388 | lport->link_speed = FC_PORTSPEED_UNKNOWN; |
| 389 | lport->link_supported_speeds = FC_PORTSPEED_UNKNOWN; |
| 390 | |
| 391 | /* Set fc_host link speed */ |
| 392 | switch (link->speed) { |
| 393 | case 10000: |
| 394 | lport->link_speed = FC_PORTSPEED_10GBIT; |
| 395 | break; |
| 396 | case 25000: |
| 397 | lport->link_speed = FC_PORTSPEED_25GBIT; |
| 398 | break; |
| 399 | case 40000: |
| 400 | lport->link_speed = FC_PORTSPEED_40GBIT; |
| 401 | break; |
| 402 | case 50000: |
| 403 | lport->link_speed = FC_PORTSPEED_50GBIT; |
| 404 | break; |
| 405 | case 100000: |
| 406 | lport->link_speed = FC_PORTSPEED_100GBIT; |
| 407 | break; |
| 408 | default: |
| 409 | lport->link_speed = FC_PORTSPEED_UNKNOWN; |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Set supported link speed by querying the supported |
| 415 | * capabilities of the link. |
| 416 | */ |
| 417 | if (link->supported_caps & SUPPORTED_10000baseKR_Full) |
| 418 | lport->link_supported_speeds |= FC_PORTSPEED_10GBIT; |
| 419 | if (link->supported_caps & SUPPORTED_25000baseKR_Full) |
| 420 | lport->link_supported_speeds |= FC_PORTSPEED_25GBIT; |
| 421 | if (link->supported_caps & SUPPORTED_40000baseLR4_Full) |
| 422 | lport->link_supported_speeds |= FC_PORTSPEED_40GBIT; |
| 423 | if (link->supported_caps & SUPPORTED_50000baseKR2_Full) |
| 424 | lport->link_supported_speeds |= FC_PORTSPEED_50GBIT; |
| 425 | if (link->supported_caps & SUPPORTED_100000baseKR4_Full) |
| 426 | lport->link_supported_speeds |= FC_PORTSPEED_100GBIT; |
| 427 | fc_host_supported_speeds(lport->host) = lport->link_supported_speeds; |
| 428 | } |
| 429 | |
| 430 | static void qedf_link_update(void *dev, struct qed_link_output *link) |
| 431 | { |
| 432 | struct qedf_ctx *qedf = (struct qedf_ctx *)dev; |
| 433 | |
| 434 | if (link->link_up) { |
| 435 | QEDF_ERR(&(qedf->dbg_ctx), "LINK UP (%d GB/s).\n", |
| 436 | link->speed / 1000); |
| 437 | |
| 438 | /* Cancel any pending link down work */ |
| 439 | cancel_delayed_work(&qedf->link_update); |
| 440 | |
| 441 | atomic_set(&qedf->link_state, QEDF_LINK_UP); |
| 442 | qedf_update_link_speed(qedf, link); |
| 443 | |
| 444 | if (atomic_read(&qedf->dcbx) == QEDF_DCBX_DONE) { |
| 445 | QEDF_ERR(&(qedf->dbg_ctx), "DCBx done.\n"); |
| 446 | if (atomic_read(&qedf->link_down_tmo_valid) > 0) |
| 447 | queue_delayed_work(qedf->link_update_wq, |
| 448 | &qedf->link_recovery, 0); |
| 449 | else |
| 450 | queue_delayed_work(qedf->link_update_wq, |
| 451 | &qedf->link_update, 0); |
| 452 | atomic_set(&qedf->link_down_tmo_valid, 0); |
| 453 | } |
| 454 | |
| 455 | } else { |
| 456 | QEDF_ERR(&(qedf->dbg_ctx), "LINK DOWN.\n"); |
| 457 | |
| 458 | atomic_set(&qedf->link_state, QEDF_LINK_DOWN); |
| 459 | atomic_set(&qedf->dcbx, QEDF_DCBX_PENDING); |
| 460 | /* |
| 461 | * Flag that we're waiting for the link to come back up before |
| 462 | * informing the fcoe layer of the event. |
| 463 | */ |
| 464 | if (qedf_link_down_tmo > 0) { |
| 465 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 466 | "Starting link down tmo.\n"); |
| 467 | atomic_set(&qedf->link_down_tmo_valid, 1); |
| 468 | } |
| 469 | qedf->vlan_id = 0; |
| 470 | qedf_update_link_speed(qedf, link); |
| 471 | queue_delayed_work(qedf->link_update_wq, &qedf->link_update, |
| 472 | qedf_link_down_tmo * HZ); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | |
| 477 | static void qedf_dcbx_handler(void *dev, struct qed_dcbx_get *get, u32 mib_type) |
| 478 | { |
| 479 | struct qedf_ctx *qedf = (struct qedf_ctx *)dev; |
| 480 | |
| 481 | QEDF_ERR(&(qedf->dbg_ctx), "DCBx event valid=%d enabled=%d fcoe " |
| 482 | "prio=%d.\n", get->operational.valid, get->operational.enabled, |
| 483 | get->operational.app_prio.fcoe); |
| 484 | |
| 485 | if (get->operational.enabled && get->operational.valid) { |
| 486 | /* If DCBX was already negotiated on link up then just exit */ |
| 487 | if (atomic_read(&qedf->dcbx) == QEDF_DCBX_DONE) { |
| 488 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 489 | "DCBX already set on link up.\n"); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | atomic_set(&qedf->dcbx, QEDF_DCBX_DONE); |
| 494 | |
| 495 | if (atomic_read(&qedf->link_state) == QEDF_LINK_UP) { |
| 496 | if (atomic_read(&qedf->link_down_tmo_valid) > 0) |
| 497 | queue_delayed_work(qedf->link_update_wq, |
| 498 | &qedf->link_recovery, 0); |
| 499 | else |
| 500 | queue_delayed_work(qedf->link_update_wq, |
| 501 | &qedf->link_update, 0); |
| 502 | atomic_set(&qedf->link_down_tmo_valid, 0); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | } |
| 507 | |
| 508 | static u32 qedf_get_login_failures(void *cookie) |
| 509 | { |
| 510 | struct qedf_ctx *qedf; |
| 511 | |
| 512 | qedf = (struct qedf_ctx *)cookie; |
| 513 | return qedf->flogi_failed; |
| 514 | } |
| 515 | |
| 516 | static struct qed_fcoe_cb_ops qedf_cb_ops = { |
| 517 | { |
| 518 | .link_update = qedf_link_update, |
| 519 | .dcbx_aen = qedf_dcbx_handler, |
| 520 | } |
| 521 | }; |
| 522 | |
| 523 | /* |
| 524 | * Various transport templates. |
| 525 | */ |
| 526 | |
| 527 | static struct scsi_transport_template *qedf_fc_transport_template; |
| 528 | static struct scsi_transport_template *qedf_fc_vport_transport_template; |
| 529 | |
| 530 | /* |
| 531 | * SCSI EH handlers |
| 532 | */ |
| 533 | static int qedf_eh_abort(struct scsi_cmnd *sc_cmd) |
| 534 | { |
| 535 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); |
| 536 | struct fc_rport_libfc_priv *rp = rport->dd_data; |
| 537 | struct qedf_rport *fcport; |
| 538 | struct fc_lport *lport; |
| 539 | struct qedf_ctx *qedf; |
| 540 | struct qedf_ioreq *io_req; |
| 541 | int rc = FAILED; |
| 542 | int rval; |
| 543 | |
| 544 | if (fc_remote_port_chkready(rport)) { |
| 545 | QEDF_ERR(NULL, "rport not ready\n"); |
| 546 | goto out; |
| 547 | } |
| 548 | |
| 549 | lport = shost_priv(sc_cmd->device->host); |
| 550 | qedf = (struct qedf_ctx *)lport_priv(lport); |
| 551 | |
| 552 | if ((lport->state != LPORT_ST_READY) || !(lport->link_up)) { |
| 553 | QEDF_ERR(&(qedf->dbg_ctx), "link not ready.\n"); |
| 554 | goto out; |
| 555 | } |
| 556 | |
| 557 | fcport = (struct qedf_rport *)&rp[1]; |
| 558 | |
| 559 | io_req = (struct qedf_ioreq *)sc_cmd->SCp.ptr; |
| 560 | if (!io_req) { |
| 561 | QEDF_ERR(&(qedf->dbg_ctx), "io_req is NULL.\n"); |
| 562 | rc = SUCCESS; |
| 563 | goto out; |
| 564 | } |
| 565 | |
| 566 | if (!test_bit(QEDF_CMD_OUTSTANDING, &io_req->flags) || |
| 567 | test_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags) || |
| 568 | test_bit(QEDF_CMD_IN_ABORT, &io_req->flags)) { |
| 569 | QEDF_ERR(&(qedf->dbg_ctx), "io_req xid=0x%x already in " |
| 570 | "cleanup or abort processing or already " |
| 571 | "completed.\n", io_req->xid); |
| 572 | rc = SUCCESS; |
| 573 | goto out; |
| 574 | } |
| 575 | |
| 576 | QEDF_ERR(&(qedf->dbg_ctx), "Aborting io_req sc_cmd=%p xid=0x%x " |
| 577 | "fp_idx=%d.\n", sc_cmd, io_req->xid, io_req->fp_idx); |
| 578 | |
| 579 | if (qedf->stop_io_on_error) { |
| 580 | qedf_stop_all_io(qedf); |
| 581 | rc = SUCCESS; |
| 582 | goto out; |
| 583 | } |
| 584 | |
| 585 | init_completion(&io_req->abts_done); |
| 586 | rval = qedf_initiate_abts(io_req, true); |
| 587 | if (rval) { |
| 588 | QEDF_ERR(&(qedf->dbg_ctx), "Failed to queue ABTS.\n"); |
| 589 | goto out; |
| 590 | } |
| 591 | |
| 592 | wait_for_completion(&io_req->abts_done); |
| 593 | |
| 594 | if (io_req->event == QEDF_IOREQ_EV_ABORT_SUCCESS || |
| 595 | io_req->event == QEDF_IOREQ_EV_ABORT_FAILED || |
| 596 | io_req->event == QEDF_IOREQ_EV_CLEANUP_SUCCESS) { |
| 597 | /* |
| 598 | * If we get a reponse to the abort this is success from |
| 599 | * the perspective that all references to the command have |
| 600 | * been removed from the driver and firmware |
| 601 | */ |
| 602 | rc = SUCCESS; |
| 603 | } else { |
| 604 | /* If the abort and cleanup failed then return a failure */ |
| 605 | rc = FAILED; |
| 606 | } |
| 607 | |
| 608 | if (rc == SUCCESS) |
| 609 | QEDF_ERR(&(qedf->dbg_ctx), "ABTS succeeded, xid=0x%x.\n", |
| 610 | io_req->xid); |
| 611 | else |
| 612 | QEDF_ERR(&(qedf->dbg_ctx), "ABTS failed, xid=0x%x.\n", |
| 613 | io_req->xid); |
| 614 | |
| 615 | out: |
| 616 | return rc; |
| 617 | } |
| 618 | |
| 619 | static int qedf_eh_target_reset(struct scsi_cmnd *sc_cmd) |
| 620 | { |
| 621 | QEDF_ERR(NULL, "TARGET RESET Issued..."); |
| 622 | return qedf_initiate_tmf(sc_cmd, FCP_TMF_TGT_RESET); |
| 623 | } |
| 624 | |
| 625 | static int qedf_eh_device_reset(struct scsi_cmnd *sc_cmd) |
| 626 | { |
| 627 | QEDF_ERR(NULL, "LUN RESET Issued...\n"); |
| 628 | return qedf_initiate_tmf(sc_cmd, FCP_TMF_LUN_RESET); |
| 629 | } |
| 630 | |
Chad Dupuis | b09fdc3 | 2017-05-31 06:33:56 -0700 | [diff] [blame^] | 631 | static int qedf_eh_bus_reset(struct scsi_cmnd *sc_cmd) |
| 632 | { |
| 633 | QEDF_ERR(NULL, "BUS RESET Issued...\n"); |
| 634 | /* |
| 635 | * Essentially a no-op but return SUCCESS to prevent |
| 636 | * unnecessary escalation to the host reset handler. |
| 637 | */ |
| 638 | return SUCCESS; |
| 639 | } |
| 640 | |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 641 | void qedf_wait_for_upload(struct qedf_ctx *qedf) |
| 642 | { |
| 643 | while (1) { |
| 644 | if (atomic_read(&qedf->num_offloads)) |
| 645 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 646 | "Waiting for all uploads to complete.\n"); |
| 647 | else |
| 648 | break; |
| 649 | msleep(500); |
| 650 | } |
| 651 | } |
| 652 | |
Chad Dupuis | 5cf446d | 2017-05-31 06:33:55 -0700 | [diff] [blame] | 653 | /* Performs soft reset of qedf_ctx by simulating a link down/up */ |
| 654 | static void qedf_ctx_soft_reset(struct fc_lport *lport) |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 655 | { |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 656 | struct qedf_ctx *qedf; |
| 657 | |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 658 | if (lport->vport) { |
| 659 | QEDF_ERR(NULL, "Cannot issue host reset on NPIV port.\n"); |
Chad Dupuis | 5cf446d | 2017-05-31 06:33:55 -0700 | [diff] [blame] | 660 | return; |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Chad Dupuis | 5cf446d | 2017-05-31 06:33:55 -0700 | [diff] [blame] | 663 | qedf = lport_priv(lport); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 664 | |
| 665 | /* For host reset, essentially do a soft link up/down */ |
| 666 | atomic_set(&qedf->link_state, QEDF_LINK_DOWN); |
| 667 | atomic_set(&qedf->dcbx, QEDF_DCBX_PENDING); |
| 668 | queue_delayed_work(qedf->link_update_wq, &qedf->link_update, |
| 669 | 0); |
| 670 | qedf_wait_for_upload(qedf); |
| 671 | atomic_set(&qedf->link_state, QEDF_LINK_UP); |
| 672 | qedf->vlan_id = 0; |
| 673 | queue_delayed_work(qedf->link_update_wq, &qedf->link_update, |
| 674 | 0); |
Chad Dupuis | 5cf446d | 2017-05-31 06:33:55 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /* Reset the host by gracefully logging out and then logging back in */ |
| 678 | static int qedf_eh_host_reset(struct scsi_cmnd *sc_cmd) |
| 679 | { |
| 680 | struct fc_lport *lport; |
| 681 | struct qedf_ctx *qedf; |
| 682 | |
| 683 | lport = shost_priv(sc_cmd->device->host); |
| 684 | qedf = lport_priv(lport); |
| 685 | |
| 686 | if (atomic_read(&qedf->link_state) == QEDF_LINK_DOWN || |
| 687 | test_bit(QEDF_UNLOADING, &qedf->flags)) |
| 688 | return FAILED; |
| 689 | |
| 690 | QEDF_ERR(&(qedf->dbg_ctx), "HOST RESET Issued..."); |
| 691 | |
| 692 | qedf_ctx_soft_reset(lport); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 693 | |
| 694 | return SUCCESS; |
| 695 | } |
| 696 | |
| 697 | static int qedf_slave_configure(struct scsi_device *sdev) |
| 698 | { |
| 699 | if (qedf_queue_depth) { |
| 700 | scsi_change_queue_depth(sdev, qedf_queue_depth); |
| 701 | } |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static struct scsi_host_template qedf_host_template = { |
| 707 | .module = THIS_MODULE, |
| 708 | .name = QEDF_MODULE_NAME, |
| 709 | .this_id = -1, |
| 710 | .cmd_per_lun = 3, |
| 711 | .use_clustering = ENABLE_CLUSTERING, |
| 712 | .max_sectors = 0xffff, |
| 713 | .queuecommand = qedf_queuecommand, |
| 714 | .shost_attrs = qedf_host_attrs, |
| 715 | .eh_abort_handler = qedf_eh_abort, |
| 716 | .eh_device_reset_handler = qedf_eh_device_reset, /* lun reset */ |
| 717 | .eh_target_reset_handler = qedf_eh_target_reset, /* target reset */ |
Chad Dupuis | b09fdc3 | 2017-05-31 06:33:56 -0700 | [diff] [blame^] | 718 | .eh_bus_reset_handler = qedf_eh_bus_reset, |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 719 | .eh_host_reset_handler = qedf_eh_host_reset, |
| 720 | .slave_configure = qedf_slave_configure, |
| 721 | .dma_boundary = QED_HW_DMA_BOUNDARY, |
| 722 | .sg_tablesize = QEDF_MAX_BDS_PER_CMD, |
| 723 | .can_queue = FCOE_PARAMS_NUM_TASKS, |
| 724 | }; |
| 725 | |
| 726 | static int qedf_get_paged_crc_eof(struct sk_buff *skb, int tlen) |
| 727 | { |
| 728 | int rc; |
| 729 | |
| 730 | spin_lock(&qedf_global_lock); |
| 731 | rc = fcoe_get_paged_crc_eof(skb, tlen, &qedf_global); |
| 732 | spin_unlock(&qedf_global_lock); |
| 733 | |
| 734 | return rc; |
| 735 | } |
| 736 | |
| 737 | static struct qedf_rport *qedf_fcport_lookup(struct qedf_ctx *qedf, u32 port_id) |
| 738 | { |
| 739 | struct qedf_rport *fcport; |
| 740 | struct fc_rport_priv *rdata; |
| 741 | |
| 742 | rcu_read_lock(); |
| 743 | list_for_each_entry_rcu(fcport, &qedf->fcports, peers) { |
| 744 | rdata = fcport->rdata; |
| 745 | if (rdata == NULL) |
| 746 | continue; |
| 747 | if (rdata->ids.port_id == port_id) { |
| 748 | rcu_read_unlock(); |
| 749 | return fcport; |
| 750 | } |
| 751 | } |
| 752 | rcu_read_unlock(); |
| 753 | |
| 754 | /* Return NULL to caller to let them know fcport was not found */ |
| 755 | return NULL; |
| 756 | } |
| 757 | |
| 758 | /* Transmits an ELS frame over an offloaded session */ |
| 759 | static int qedf_xmit_l2_frame(struct qedf_rport *fcport, struct fc_frame *fp) |
| 760 | { |
| 761 | struct fc_frame_header *fh; |
| 762 | int rc = 0; |
| 763 | |
| 764 | fh = fc_frame_header_get(fp); |
| 765 | if ((fh->fh_type == FC_TYPE_ELS) && |
| 766 | (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { |
| 767 | switch (fc_frame_payload_op(fp)) { |
| 768 | case ELS_ADISC: |
| 769 | qedf_send_adisc(fcport, fp); |
| 770 | rc = 1; |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | return rc; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * qedf_xmit - qedf FCoE frame transmit function |
| 780 | * |
| 781 | */ |
| 782 | static int qedf_xmit(struct fc_lport *lport, struct fc_frame *fp) |
| 783 | { |
| 784 | struct fc_lport *base_lport; |
| 785 | struct qedf_ctx *qedf; |
| 786 | struct ethhdr *eh; |
| 787 | struct fcoe_crc_eof *cp; |
| 788 | struct sk_buff *skb; |
| 789 | struct fc_frame_header *fh; |
| 790 | struct fcoe_hdr *hp; |
| 791 | u8 sof, eof; |
| 792 | u32 crc; |
| 793 | unsigned int hlen, tlen, elen; |
| 794 | int wlen; |
| 795 | struct fc_stats *stats; |
| 796 | struct fc_lport *tmp_lport; |
| 797 | struct fc_lport *vn_port = NULL; |
| 798 | struct qedf_rport *fcport; |
| 799 | int rc; |
| 800 | u16 vlan_tci = 0; |
| 801 | |
| 802 | qedf = (struct qedf_ctx *)lport_priv(lport); |
| 803 | |
| 804 | fh = fc_frame_header_get(fp); |
| 805 | skb = fp_skb(fp); |
| 806 | |
| 807 | /* Filter out traffic to other NPIV ports on the same host */ |
| 808 | if (lport->vport) |
| 809 | base_lport = shost_priv(vport_to_shost(lport->vport)); |
| 810 | else |
| 811 | base_lport = lport; |
| 812 | |
| 813 | /* Flag if the destination is the base port */ |
| 814 | if (base_lport->port_id == ntoh24(fh->fh_d_id)) { |
| 815 | vn_port = base_lport; |
| 816 | } else { |
| 817 | /* Got through the list of vports attached to the base_lport |
| 818 | * and see if we have a match with the destination address. |
| 819 | */ |
| 820 | list_for_each_entry(tmp_lport, &base_lport->vports, list) { |
| 821 | if (tmp_lport->port_id == ntoh24(fh->fh_d_id)) { |
| 822 | vn_port = tmp_lport; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | if (vn_port && ntoh24(fh->fh_d_id) != FC_FID_FLOGI) { |
| 828 | struct fc_rport_priv *rdata = NULL; |
| 829 | |
| 830 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, |
| 831 | "Dropping FCoE frame to %06x.\n", ntoh24(fh->fh_d_id)); |
| 832 | kfree_skb(skb); |
| 833 | rdata = fc_rport_lookup(lport, ntoh24(fh->fh_d_id)); |
| 834 | if (rdata) |
| 835 | rdata->retries = lport->max_rport_retry_count; |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | /* End NPIV filtering */ |
| 839 | |
| 840 | if (!qedf->ctlr.sel_fcf) { |
| 841 | kfree_skb(skb); |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | if (!test_bit(QEDF_LL2_STARTED, &qedf->flags)) { |
| 846 | QEDF_WARN(&(qedf->dbg_ctx), "LL2 not started\n"); |
| 847 | kfree_skb(skb); |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | if (atomic_read(&qedf->link_state) != QEDF_LINK_UP) { |
| 852 | QEDF_WARN(&(qedf->dbg_ctx), "qedf link down\n"); |
| 853 | kfree_skb(skb); |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { |
| 858 | if (fcoe_ctlr_els_send(&qedf->ctlr, lport, skb)) |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /* Check to see if this needs to be sent on an offloaded session */ |
| 863 | fcport = qedf_fcport_lookup(qedf, ntoh24(fh->fh_d_id)); |
| 864 | |
| 865 | if (fcport && test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { |
| 866 | rc = qedf_xmit_l2_frame(fcport, fp); |
| 867 | /* |
| 868 | * If the frame was successfully sent over the middle path |
| 869 | * then do not try to also send it over the LL2 path |
| 870 | */ |
| 871 | if (rc) |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | sof = fr_sof(fp); |
| 876 | eof = fr_eof(fp); |
| 877 | |
| 878 | elen = sizeof(struct ethhdr); |
| 879 | hlen = sizeof(struct fcoe_hdr); |
| 880 | tlen = sizeof(struct fcoe_crc_eof); |
| 881 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; |
| 882 | |
| 883 | skb->ip_summed = CHECKSUM_NONE; |
| 884 | crc = fcoe_fc_crc(fp); |
| 885 | |
| 886 | /* copy port crc and eof to the skb buff */ |
| 887 | if (skb_is_nonlinear(skb)) { |
| 888 | skb_frag_t *frag; |
| 889 | |
| 890 | if (qedf_get_paged_crc_eof(skb, tlen)) { |
| 891 | kfree_skb(skb); |
| 892 | return -ENOMEM; |
| 893 | } |
| 894 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; |
| 895 | cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset; |
| 896 | } else { |
| 897 | cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); |
| 898 | } |
| 899 | |
| 900 | memset(cp, 0, sizeof(*cp)); |
| 901 | cp->fcoe_eof = eof; |
| 902 | cp->fcoe_crc32 = cpu_to_le32(~crc); |
| 903 | if (skb_is_nonlinear(skb)) { |
| 904 | kunmap_atomic(cp); |
| 905 | cp = NULL; |
| 906 | } |
| 907 | |
| 908 | |
| 909 | /* adjust skb network/transport offsets to match mac/fcoe/port */ |
| 910 | skb_push(skb, elen + hlen); |
| 911 | skb_reset_mac_header(skb); |
| 912 | skb_reset_network_header(skb); |
| 913 | skb->mac_len = elen; |
| 914 | skb->protocol = htons(ETH_P_FCOE); |
| 915 | |
| 916 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), qedf->vlan_id); |
| 917 | |
| 918 | /* fill up mac and fcoe headers */ |
| 919 | eh = eth_hdr(skb); |
| 920 | eh->h_proto = htons(ETH_P_FCOE); |
| 921 | if (qedf->ctlr.map_dest) |
| 922 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); |
| 923 | else |
| 924 | /* insert GW address */ |
| 925 | ether_addr_copy(eh->h_dest, qedf->ctlr.dest_addr); |
| 926 | |
| 927 | /* Set the source MAC address */ |
| 928 | fc_fcoe_set_mac(eh->h_source, fh->fh_s_id); |
| 929 | |
| 930 | hp = (struct fcoe_hdr *)(eh + 1); |
| 931 | memset(hp, 0, sizeof(*hp)); |
| 932 | if (FC_FCOE_VER) |
| 933 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); |
| 934 | hp->fcoe_sof = sof; |
| 935 | |
| 936 | /*update tx stats */ |
| 937 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
| 938 | stats->TxFrames++; |
| 939 | stats->TxWords += wlen; |
| 940 | put_cpu(); |
| 941 | |
| 942 | /* Get VLAN ID from skb for printing purposes */ |
| 943 | __vlan_hwaccel_get_tag(skb, &vlan_tci); |
| 944 | |
| 945 | /* send down to lld */ |
| 946 | fr_dev(fp) = lport; |
| 947 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FCoE frame send: " |
| 948 | "src=%06x dest=%06x r_ctl=%x type=%x vlan=%04x.\n", |
| 949 | ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id), fh->fh_r_ctl, fh->fh_type, |
| 950 | vlan_tci); |
| 951 | if (qedf_dump_frames) |
| 952 | print_hex_dump(KERN_WARNING, "fcoe: ", DUMP_PREFIX_OFFSET, 16, |
| 953 | 1, skb->data, skb->len, false); |
| 954 | qed_ops->ll2->start_xmit(qedf->cdev, skb); |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | static int qedf_alloc_sq(struct qedf_ctx *qedf, struct qedf_rport *fcport) |
| 960 | { |
| 961 | int rval = 0; |
| 962 | u32 *pbl; |
| 963 | dma_addr_t page; |
| 964 | int num_pages; |
| 965 | |
| 966 | /* Calculate appropriate queue and PBL sizes */ |
| 967 | fcport->sq_mem_size = SQ_NUM_ENTRIES * sizeof(struct fcoe_wqe); |
| 968 | fcport->sq_mem_size = ALIGN(fcport->sq_mem_size, QEDF_PAGE_SIZE); |
| 969 | fcport->sq_pbl_size = (fcport->sq_mem_size / QEDF_PAGE_SIZE) * |
| 970 | sizeof(void *); |
| 971 | fcport->sq_pbl_size = fcport->sq_pbl_size + QEDF_PAGE_SIZE; |
| 972 | |
| 973 | fcport->sq = dma_alloc_coherent(&qedf->pdev->dev, fcport->sq_mem_size, |
| 974 | &fcport->sq_dma, GFP_KERNEL); |
| 975 | if (!fcport->sq) { |
| 976 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate send " |
| 977 | "queue.\n"); |
| 978 | rval = 1; |
| 979 | goto out; |
| 980 | } |
| 981 | memset(fcport->sq, 0, fcport->sq_mem_size); |
| 982 | |
| 983 | fcport->sq_pbl = dma_alloc_coherent(&qedf->pdev->dev, |
| 984 | fcport->sq_pbl_size, &fcport->sq_pbl_dma, GFP_KERNEL); |
| 985 | if (!fcport->sq_pbl) { |
| 986 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate send " |
| 987 | "queue PBL.\n"); |
| 988 | rval = 1; |
| 989 | goto out_free_sq; |
| 990 | } |
| 991 | memset(fcport->sq_pbl, 0, fcport->sq_pbl_size); |
| 992 | |
| 993 | /* Create PBL */ |
| 994 | num_pages = fcport->sq_mem_size / QEDF_PAGE_SIZE; |
| 995 | page = fcport->sq_dma; |
| 996 | pbl = (u32 *)fcport->sq_pbl; |
| 997 | |
| 998 | while (num_pages--) { |
| 999 | *pbl = U64_LO(page); |
| 1000 | pbl++; |
| 1001 | *pbl = U64_HI(page); |
| 1002 | pbl++; |
| 1003 | page += QEDF_PAGE_SIZE; |
| 1004 | } |
| 1005 | |
| 1006 | return rval; |
| 1007 | |
| 1008 | out_free_sq: |
| 1009 | dma_free_coherent(&qedf->pdev->dev, fcport->sq_mem_size, fcport->sq, |
| 1010 | fcport->sq_dma); |
| 1011 | out: |
| 1012 | return rval; |
| 1013 | } |
| 1014 | |
| 1015 | static void qedf_free_sq(struct qedf_ctx *qedf, struct qedf_rport *fcport) |
| 1016 | { |
| 1017 | if (fcport->sq_pbl) |
| 1018 | dma_free_coherent(&qedf->pdev->dev, fcport->sq_pbl_size, |
| 1019 | fcport->sq_pbl, fcport->sq_pbl_dma); |
| 1020 | if (fcport->sq) |
| 1021 | dma_free_coherent(&qedf->pdev->dev, fcport->sq_mem_size, |
| 1022 | fcport->sq, fcport->sq_dma); |
| 1023 | } |
| 1024 | |
| 1025 | static int qedf_offload_connection(struct qedf_ctx *qedf, |
| 1026 | struct qedf_rport *fcport) |
| 1027 | { |
| 1028 | struct qed_fcoe_params_offload conn_info; |
| 1029 | u32 port_id; |
| 1030 | u8 lport_src_id[3]; |
| 1031 | int rval; |
| 1032 | uint16_t total_sqe = (fcport->sq_mem_size / sizeof(struct fcoe_wqe)); |
| 1033 | |
| 1034 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, "Offloading connection " |
| 1035 | "portid=%06x.\n", fcport->rdata->ids.port_id); |
| 1036 | rval = qed_ops->acquire_conn(qedf->cdev, &fcport->handle, |
| 1037 | &fcport->fw_cid, &fcport->p_doorbell); |
| 1038 | if (rval) { |
| 1039 | QEDF_WARN(&(qedf->dbg_ctx), "Could not acquire connection " |
| 1040 | "for portid=%06x.\n", fcport->rdata->ids.port_id); |
| 1041 | rval = 1; /* For some reason qed returns 0 on failure here */ |
| 1042 | goto out; |
| 1043 | } |
| 1044 | |
| 1045 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, "portid=%06x " |
| 1046 | "fw_cid=%08x handle=%d.\n", fcport->rdata->ids.port_id, |
| 1047 | fcport->fw_cid, fcport->handle); |
| 1048 | |
| 1049 | memset(&conn_info, 0, sizeof(struct qed_fcoe_params_offload)); |
| 1050 | |
| 1051 | /* Fill in the offload connection info */ |
| 1052 | conn_info.sq_pbl_addr = fcport->sq_pbl_dma; |
| 1053 | |
| 1054 | conn_info.sq_curr_page_addr = (dma_addr_t)(*(u64 *)fcport->sq_pbl); |
| 1055 | conn_info.sq_next_page_addr = |
| 1056 | (dma_addr_t)(*(u64 *)(fcport->sq_pbl + 8)); |
| 1057 | |
| 1058 | /* Need to use our FCoE MAC for the offload session */ |
| 1059 | port_id = fc_host_port_id(qedf->lport->host); |
| 1060 | lport_src_id[2] = (port_id & 0x000000FF); |
| 1061 | lport_src_id[1] = (port_id & 0x0000FF00) >> 8; |
| 1062 | lport_src_id[0] = (port_id & 0x00FF0000) >> 16; |
| 1063 | fc_fcoe_set_mac(conn_info.src_mac, lport_src_id); |
| 1064 | |
| 1065 | ether_addr_copy(conn_info.dst_mac, qedf->ctlr.dest_addr); |
| 1066 | |
| 1067 | conn_info.tx_max_fc_pay_len = fcport->rdata->maxframe_size; |
| 1068 | conn_info.e_d_tov_timer_val = qedf->lport->e_d_tov / 20; |
| 1069 | conn_info.rec_tov_timer_val = 3; /* I think this is what E3 was */ |
| 1070 | conn_info.rx_max_fc_pay_len = fcport->rdata->maxframe_size; |
| 1071 | |
| 1072 | /* Set VLAN data */ |
| 1073 | conn_info.vlan_tag = qedf->vlan_id << |
| 1074 | FCOE_CONN_OFFLOAD_RAMROD_DATA_VLAN_ID_SHIFT; |
| 1075 | conn_info.vlan_tag |= |
| 1076 | qedf_default_prio << FCOE_CONN_OFFLOAD_RAMROD_DATA_PRIORITY_SHIFT; |
| 1077 | conn_info.flags |= (FCOE_CONN_OFFLOAD_RAMROD_DATA_B_VLAN_FLAG_MASK << |
| 1078 | FCOE_CONN_OFFLOAD_RAMROD_DATA_B_VLAN_FLAG_SHIFT); |
| 1079 | |
| 1080 | /* Set host port source id */ |
| 1081 | port_id = fc_host_port_id(qedf->lport->host); |
| 1082 | fcport->sid = port_id; |
| 1083 | conn_info.s_id.addr_hi = (port_id & 0x000000FF); |
| 1084 | conn_info.s_id.addr_mid = (port_id & 0x0000FF00) >> 8; |
| 1085 | conn_info.s_id.addr_lo = (port_id & 0x00FF0000) >> 16; |
| 1086 | |
| 1087 | conn_info.max_conc_seqs_c3 = fcport->rdata->max_seq; |
| 1088 | |
| 1089 | /* Set remote port destination id */ |
| 1090 | port_id = fcport->rdata->rport->port_id; |
| 1091 | conn_info.d_id.addr_hi = (port_id & 0x000000FF); |
| 1092 | conn_info.d_id.addr_mid = (port_id & 0x0000FF00) >> 8; |
| 1093 | conn_info.d_id.addr_lo = (port_id & 0x00FF0000) >> 16; |
| 1094 | |
| 1095 | conn_info.def_q_idx = 0; /* Default index for send queue? */ |
| 1096 | |
| 1097 | /* Set FC-TAPE specific flags if needed */ |
| 1098 | if (fcport->dev_type == QEDF_RPORT_TYPE_TAPE) { |
| 1099 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, |
| 1100 | "Enable CONF, REC for portid=%06x.\n", |
| 1101 | fcport->rdata->ids.port_id); |
| 1102 | conn_info.flags |= 1 << |
| 1103 | FCOE_CONN_OFFLOAD_RAMROD_DATA_B_CONF_REQ_SHIFT; |
| 1104 | conn_info.flags |= |
| 1105 | ((fcport->rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) << |
| 1106 | FCOE_CONN_OFFLOAD_RAMROD_DATA_B_REC_VALID_SHIFT; |
| 1107 | } |
| 1108 | |
| 1109 | rval = qed_ops->offload_conn(qedf->cdev, fcport->handle, &conn_info); |
| 1110 | if (rval) { |
| 1111 | QEDF_WARN(&(qedf->dbg_ctx), "Could not offload connection " |
| 1112 | "for portid=%06x.\n", fcport->rdata->ids.port_id); |
| 1113 | goto out_free_conn; |
| 1114 | } else |
| 1115 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, "Offload " |
| 1116 | "succeeded portid=%06x total_sqe=%d.\n", |
| 1117 | fcport->rdata->ids.port_id, total_sqe); |
| 1118 | |
| 1119 | spin_lock_init(&fcport->rport_lock); |
| 1120 | atomic_set(&fcport->free_sqes, total_sqe); |
| 1121 | return 0; |
| 1122 | out_free_conn: |
| 1123 | qed_ops->release_conn(qedf->cdev, fcport->handle); |
| 1124 | out: |
| 1125 | return rval; |
| 1126 | } |
| 1127 | |
| 1128 | #define QEDF_TERM_BUFF_SIZE 10 |
| 1129 | static void qedf_upload_connection(struct qedf_ctx *qedf, |
| 1130 | struct qedf_rport *fcport) |
| 1131 | { |
| 1132 | void *term_params; |
| 1133 | dma_addr_t term_params_dma; |
| 1134 | |
| 1135 | /* Term params needs to be a DMA coherent buffer as qed shared the |
| 1136 | * physical DMA address with the firmware. The buffer may be used in |
| 1137 | * the receive path so we may eventually have to move this. |
| 1138 | */ |
| 1139 | term_params = dma_alloc_coherent(&qedf->pdev->dev, QEDF_TERM_BUFF_SIZE, |
| 1140 | &term_params_dma, GFP_KERNEL); |
| 1141 | |
| 1142 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, "Uploading connection " |
| 1143 | "port_id=%06x.\n", fcport->rdata->ids.port_id); |
| 1144 | |
| 1145 | qed_ops->destroy_conn(qedf->cdev, fcport->handle, term_params_dma); |
| 1146 | qed_ops->release_conn(qedf->cdev, fcport->handle); |
| 1147 | |
| 1148 | dma_free_coherent(&qedf->pdev->dev, QEDF_TERM_BUFF_SIZE, term_params, |
| 1149 | term_params_dma); |
| 1150 | } |
| 1151 | |
| 1152 | static void qedf_cleanup_fcport(struct qedf_ctx *qedf, |
| 1153 | struct qedf_rport *fcport) |
| 1154 | { |
| 1155 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_CONN, "Cleaning up portid=%06x.\n", |
| 1156 | fcport->rdata->ids.port_id); |
| 1157 | |
| 1158 | /* Flush any remaining i/o's before we upload the connection */ |
| 1159 | qedf_flush_active_ios(fcport, -1); |
| 1160 | |
| 1161 | if (test_and_clear_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) |
| 1162 | qedf_upload_connection(qedf, fcport); |
| 1163 | qedf_free_sq(qedf, fcport); |
| 1164 | fcport->rdata = NULL; |
| 1165 | fcport->qedf = NULL; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * This event_callback is called after successful completion of libfc |
| 1170 | * initiated target login. qedf can proceed with initiating the session |
| 1171 | * establishment. |
| 1172 | */ |
| 1173 | static void qedf_rport_event_handler(struct fc_lport *lport, |
| 1174 | struct fc_rport_priv *rdata, |
| 1175 | enum fc_rport_event event) |
| 1176 | { |
| 1177 | struct qedf_ctx *qedf = lport_priv(lport); |
| 1178 | struct fc_rport *rport = rdata->rport; |
| 1179 | struct fc_rport_libfc_priv *rp; |
| 1180 | struct qedf_rport *fcport; |
| 1181 | u32 port_id; |
| 1182 | int rval; |
| 1183 | unsigned long flags; |
| 1184 | |
| 1185 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "event = %d, " |
| 1186 | "port_id = 0x%x\n", event, rdata->ids.port_id); |
| 1187 | |
| 1188 | switch (event) { |
| 1189 | case RPORT_EV_READY: |
| 1190 | if (!rport) { |
| 1191 | QEDF_WARN(&(qedf->dbg_ctx), "rport is NULL.\n"); |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | rp = rport->dd_data; |
| 1196 | fcport = (struct qedf_rport *)&rp[1]; |
| 1197 | fcport->qedf = qedf; |
| 1198 | |
| 1199 | if (atomic_read(&qedf->num_offloads) >= QEDF_MAX_SESSIONS) { |
| 1200 | QEDF_ERR(&(qedf->dbg_ctx), "Not offloading " |
| 1201 | "portid=0x%x as max number of offloaded sessions " |
| 1202 | "reached.\n", rdata->ids.port_id); |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | /* |
| 1207 | * Don't try to offload the session again. Can happen when we |
| 1208 | * get an ADISC |
| 1209 | */ |
| 1210 | if (test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { |
| 1211 | QEDF_WARN(&(qedf->dbg_ctx), "Session already " |
| 1212 | "offloaded, portid=0x%x.\n", |
| 1213 | rdata->ids.port_id); |
| 1214 | return; |
| 1215 | } |
| 1216 | |
| 1217 | if (rport->port_id == FC_FID_DIR_SERV) { |
| 1218 | /* |
| 1219 | * qedf_rport structure doesn't exist for |
| 1220 | * directory server. |
| 1221 | * We should not come here, as lport will |
| 1222 | * take care of fabric login |
| 1223 | */ |
| 1224 | QEDF_WARN(&(qedf->dbg_ctx), "rport struct does not " |
| 1225 | "exist for dir server port_id=%x\n", |
| 1226 | rdata->ids.port_id); |
| 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | if (rdata->spp_type != FC_TYPE_FCP) { |
| 1231 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 1232 | "Not offlading since since spp type isn't FCP\n"); |
| 1233 | break; |
| 1234 | } |
| 1235 | if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 1236 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 1237 | "Not FCP target so not offloading\n"); |
| 1238 | break; |
| 1239 | } |
| 1240 | |
| 1241 | fcport->rdata = rdata; |
| 1242 | fcport->rport = rport; |
| 1243 | |
| 1244 | rval = qedf_alloc_sq(qedf, fcport); |
| 1245 | if (rval) { |
| 1246 | qedf_cleanup_fcport(qedf, fcport); |
| 1247 | break; |
| 1248 | } |
| 1249 | |
| 1250 | /* Set device type */ |
| 1251 | if (rdata->flags & FC_RP_FLAGS_RETRY && |
| 1252 | rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET && |
| 1253 | !(rdata->ids.roles & FC_RPORT_ROLE_FCP_INITIATOR)) { |
| 1254 | fcport->dev_type = QEDF_RPORT_TYPE_TAPE; |
| 1255 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 1256 | "portid=%06x is a TAPE device.\n", |
| 1257 | rdata->ids.port_id); |
| 1258 | } else { |
| 1259 | fcport->dev_type = QEDF_RPORT_TYPE_DISK; |
| 1260 | } |
| 1261 | |
| 1262 | rval = qedf_offload_connection(qedf, fcport); |
| 1263 | if (rval) { |
| 1264 | qedf_cleanup_fcport(qedf, fcport); |
| 1265 | break; |
| 1266 | } |
| 1267 | |
| 1268 | /* Add fcport to list of qedf_ctx list of offloaded ports */ |
| 1269 | spin_lock_irqsave(&qedf->hba_lock, flags); |
| 1270 | list_add_rcu(&fcport->peers, &qedf->fcports); |
| 1271 | spin_unlock_irqrestore(&qedf->hba_lock, flags); |
| 1272 | |
| 1273 | /* |
| 1274 | * Set the session ready bit to let everyone know that this |
| 1275 | * connection is ready for I/O |
| 1276 | */ |
| 1277 | set_bit(QEDF_RPORT_SESSION_READY, &fcport->flags); |
| 1278 | atomic_inc(&qedf->num_offloads); |
| 1279 | |
| 1280 | break; |
| 1281 | case RPORT_EV_LOGO: |
| 1282 | case RPORT_EV_FAILED: |
| 1283 | case RPORT_EV_STOP: |
| 1284 | port_id = rdata->ids.port_id; |
| 1285 | if (port_id == FC_FID_DIR_SERV) |
| 1286 | break; |
| 1287 | |
| 1288 | if (!rport) { |
| 1289 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 1290 | "port_id=%x - rport notcreated Yet!!\n", port_id); |
| 1291 | break; |
| 1292 | } |
| 1293 | rp = rport->dd_data; |
| 1294 | /* |
| 1295 | * Perform session upload. Note that rdata->peers is already |
| 1296 | * removed from disc->rports list before we get this event. |
| 1297 | */ |
| 1298 | fcport = (struct qedf_rport *)&rp[1]; |
| 1299 | |
| 1300 | /* Only free this fcport if it is offloaded already */ |
| 1301 | if (test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { |
| 1302 | set_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags); |
| 1303 | qedf_cleanup_fcport(qedf, fcport); |
| 1304 | |
| 1305 | /* |
| 1306 | * Remove fcport to list of qedf_ctx list of offloaded |
| 1307 | * ports |
| 1308 | */ |
| 1309 | spin_lock_irqsave(&qedf->hba_lock, flags); |
| 1310 | list_del_rcu(&fcport->peers); |
| 1311 | spin_unlock_irqrestore(&qedf->hba_lock, flags); |
| 1312 | |
| 1313 | clear_bit(QEDF_RPORT_UPLOADING_CONNECTION, |
| 1314 | &fcport->flags); |
| 1315 | atomic_dec(&qedf->num_offloads); |
| 1316 | } |
| 1317 | |
| 1318 | break; |
| 1319 | |
| 1320 | case RPORT_EV_NONE: |
| 1321 | break; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | static void qedf_abort_io(struct fc_lport *lport) |
| 1326 | { |
| 1327 | /* NO-OP but need to fill in the template */ |
| 1328 | } |
| 1329 | |
| 1330 | static void qedf_fcp_cleanup(struct fc_lport *lport) |
| 1331 | { |
| 1332 | /* |
| 1333 | * NO-OP but need to fill in template to prevent a NULL |
| 1334 | * function pointer dereference during link down. I/Os |
| 1335 | * will be flushed when port is uploaded. |
| 1336 | */ |
| 1337 | } |
| 1338 | |
| 1339 | static struct libfc_function_template qedf_lport_template = { |
| 1340 | .frame_send = qedf_xmit, |
| 1341 | .fcp_abort_io = qedf_abort_io, |
| 1342 | .fcp_cleanup = qedf_fcp_cleanup, |
| 1343 | .rport_event_callback = qedf_rport_event_handler, |
| 1344 | .elsct_send = qedf_elsct_send, |
| 1345 | }; |
| 1346 | |
| 1347 | static void qedf_fcoe_ctlr_setup(struct qedf_ctx *qedf) |
| 1348 | { |
| 1349 | fcoe_ctlr_init(&qedf->ctlr, FIP_ST_AUTO); |
| 1350 | |
| 1351 | qedf->ctlr.send = qedf_fip_send; |
| 1352 | qedf->ctlr.update_mac = qedf_update_src_mac; |
| 1353 | qedf->ctlr.get_src_addr = qedf_get_src_mac; |
| 1354 | ether_addr_copy(qedf->ctlr.ctl_src_addr, qedf->mac); |
| 1355 | } |
| 1356 | |
Chad Dupuis | 5185b32 | 2017-05-31 06:33:48 -0700 | [diff] [blame] | 1357 | static void qedf_setup_fdmi(struct qedf_ctx *qedf) |
| 1358 | { |
| 1359 | struct fc_lport *lport = qedf->lport; |
| 1360 | struct fc_host_attrs *fc_host = shost_to_fc_host(lport->host); |
| 1361 | u8 buf[8]; |
| 1362 | int i, pos; |
| 1363 | |
| 1364 | /* |
| 1365 | * fdmi_enabled needs to be set for libfc to execute FDMI registration. |
| 1366 | */ |
| 1367 | lport->fdmi_enabled = 1; |
| 1368 | |
| 1369 | /* |
| 1370 | * Setup the necessary fc_host attributes to that will be used to fill |
| 1371 | * in the FDMI information. |
| 1372 | */ |
| 1373 | |
| 1374 | /* Get the PCI-e Device Serial Number Capability */ |
| 1375 | pos = pci_find_ext_capability(qedf->pdev, PCI_EXT_CAP_ID_DSN); |
| 1376 | if (pos) { |
| 1377 | pos += 4; |
| 1378 | for (i = 0; i < 8; i++) |
| 1379 | pci_read_config_byte(qedf->pdev, pos + i, &buf[i]); |
| 1380 | |
| 1381 | snprintf(fc_host->serial_number, |
| 1382 | sizeof(fc_host->serial_number), |
| 1383 | "%02X%02X%02X%02X%02X%02X%02X%02X", |
| 1384 | buf[7], buf[6], buf[5], buf[4], |
| 1385 | buf[3], buf[2], buf[1], buf[0]); |
| 1386 | } else |
| 1387 | snprintf(fc_host->serial_number, |
| 1388 | sizeof(fc_host->serial_number), "Unknown"); |
| 1389 | |
| 1390 | snprintf(fc_host->manufacturer, |
| 1391 | sizeof(fc_host->manufacturer), "%s", "Cavium Inc."); |
| 1392 | |
| 1393 | snprintf(fc_host->model, sizeof(fc_host->model), "%s", "QL41000"); |
| 1394 | |
| 1395 | snprintf(fc_host->model_description, sizeof(fc_host->model_description), |
| 1396 | "%s", "QLogic FastLinQ QL41000 Series 10/25/40/50GGbE Controller" |
| 1397 | "(FCoE)"); |
| 1398 | |
| 1399 | snprintf(fc_host->hardware_version, sizeof(fc_host->hardware_version), |
| 1400 | "Rev %d", qedf->pdev->revision); |
| 1401 | |
| 1402 | snprintf(fc_host->driver_version, sizeof(fc_host->driver_version), |
| 1403 | "%s", QEDF_VERSION); |
| 1404 | |
| 1405 | snprintf(fc_host->firmware_version, sizeof(fc_host->firmware_version), |
| 1406 | "%d.%d.%d.%d", FW_MAJOR_VERSION, FW_MINOR_VERSION, |
| 1407 | FW_REVISION_VERSION, FW_ENGINEERING_VERSION); |
| 1408 | } |
| 1409 | |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 1410 | static int qedf_lport_setup(struct qedf_ctx *qedf) |
| 1411 | { |
| 1412 | struct fc_lport *lport = qedf->lport; |
| 1413 | |
| 1414 | lport->link_up = 0; |
| 1415 | lport->max_retry_count = QEDF_FLOGI_RETRY_CNT; |
| 1416 | lport->max_rport_retry_count = QEDF_RPORT_RETRY_CNT; |
| 1417 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
| 1418 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); |
| 1419 | lport->boot_time = jiffies; |
| 1420 | lport->e_d_tov = 2 * 1000; |
| 1421 | lport->r_a_tov = 10 * 1000; |
| 1422 | |
| 1423 | /* Set NPIV support */ |
| 1424 | lport->does_npiv = 1; |
| 1425 | fc_host_max_npiv_vports(lport->host) = QEDF_MAX_NPIV; |
| 1426 | |
| 1427 | fc_set_wwnn(lport, qedf->wwnn); |
| 1428 | fc_set_wwpn(lport, qedf->wwpn); |
| 1429 | |
| 1430 | fcoe_libfc_config(lport, &qedf->ctlr, &qedf_lport_template, 0); |
| 1431 | |
| 1432 | /* Allocate the exchange manager */ |
| 1433 | fc_exch_mgr_alloc(lport, FC_CLASS_3, qedf->max_scsi_xid + 1, |
| 1434 | qedf->max_els_xid, NULL); |
| 1435 | |
| 1436 | if (fc_lport_init_stats(lport)) |
| 1437 | return -ENOMEM; |
| 1438 | |
| 1439 | /* Finish lport config */ |
| 1440 | fc_lport_config(lport); |
| 1441 | |
| 1442 | /* Set max frame size */ |
| 1443 | fc_set_mfs(lport, QEDF_MFS); |
| 1444 | fc_host_maxframe_size(lport->host) = lport->mfs; |
| 1445 | |
| 1446 | /* Set default dev_loss_tmo based on module parameter */ |
| 1447 | fc_host_dev_loss_tmo(lport->host) = qedf_dev_loss_tmo; |
| 1448 | |
| 1449 | /* Set symbolic node name */ |
| 1450 | snprintf(fc_host_symbolic_name(lport->host), 256, |
| 1451 | "QLogic %s v%s", QEDF_MODULE_NAME, QEDF_VERSION); |
| 1452 | |
Chad Dupuis | 5185b32 | 2017-05-31 06:33:48 -0700 | [diff] [blame] | 1453 | qedf_setup_fdmi(qedf); |
| 1454 | |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * NPIV functions |
| 1460 | */ |
| 1461 | |
| 1462 | static int qedf_vport_libfc_config(struct fc_vport *vport, |
| 1463 | struct fc_lport *lport) |
| 1464 | { |
| 1465 | lport->link_up = 0; |
| 1466 | lport->qfull = 0; |
| 1467 | lport->max_retry_count = QEDF_FLOGI_RETRY_CNT; |
| 1468 | lport->max_rport_retry_count = QEDF_RPORT_RETRY_CNT; |
| 1469 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
| 1470 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); |
| 1471 | lport->boot_time = jiffies; |
| 1472 | lport->e_d_tov = 2 * 1000; |
| 1473 | lport->r_a_tov = 10 * 1000; |
| 1474 | lport->does_npiv = 1; /* Temporary until we add NPIV support */ |
| 1475 | |
| 1476 | /* Allocate stats for vport */ |
| 1477 | if (fc_lport_init_stats(lport)) |
| 1478 | return -ENOMEM; |
| 1479 | |
| 1480 | /* Finish lport config */ |
| 1481 | fc_lport_config(lport); |
| 1482 | |
| 1483 | /* offload related configuration */ |
| 1484 | lport->crc_offload = 0; |
| 1485 | lport->seq_offload = 0; |
| 1486 | lport->lro_enabled = 0; |
| 1487 | lport->lro_xid = 0; |
| 1488 | lport->lso_max = 0; |
| 1489 | |
| 1490 | return 0; |
| 1491 | } |
| 1492 | |
| 1493 | static int qedf_vport_create(struct fc_vport *vport, bool disabled) |
| 1494 | { |
| 1495 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 1496 | struct fc_lport *n_port = shost_priv(shost); |
| 1497 | struct fc_lport *vn_port; |
| 1498 | struct qedf_ctx *base_qedf = lport_priv(n_port); |
| 1499 | struct qedf_ctx *vport_qedf; |
| 1500 | |
| 1501 | char buf[32]; |
| 1502 | int rc = 0; |
| 1503 | |
| 1504 | rc = fcoe_validate_vport_create(vport); |
| 1505 | if (rc) { |
| 1506 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); |
| 1507 | QEDF_WARN(&(base_qedf->dbg_ctx), "Failed to create vport, " |
| 1508 | "WWPN (0x%s) already exists.\n", buf); |
| 1509 | goto err1; |
| 1510 | } |
| 1511 | |
| 1512 | if (atomic_read(&base_qedf->link_state) != QEDF_LINK_UP) { |
| 1513 | QEDF_WARN(&(base_qedf->dbg_ctx), "Cannot create vport " |
| 1514 | "because link is not up.\n"); |
| 1515 | rc = -EIO; |
| 1516 | goto err1; |
| 1517 | } |
| 1518 | |
| 1519 | vn_port = libfc_vport_create(vport, sizeof(struct qedf_ctx)); |
| 1520 | if (!vn_port) { |
| 1521 | QEDF_WARN(&(base_qedf->dbg_ctx), "Could not create lport " |
| 1522 | "for vport.\n"); |
| 1523 | rc = -ENOMEM; |
| 1524 | goto err1; |
| 1525 | } |
| 1526 | |
| 1527 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); |
| 1528 | QEDF_ERR(&(base_qedf->dbg_ctx), "Creating NPIV port, WWPN=%s.\n", |
| 1529 | buf); |
| 1530 | |
| 1531 | /* Copy some fields from base_qedf */ |
| 1532 | vport_qedf = lport_priv(vn_port); |
| 1533 | memcpy(vport_qedf, base_qedf, sizeof(struct qedf_ctx)); |
| 1534 | |
| 1535 | /* Set qedf data specific to this vport */ |
| 1536 | vport_qedf->lport = vn_port; |
| 1537 | /* Use same hba_lock as base_qedf */ |
| 1538 | vport_qedf->hba_lock = base_qedf->hba_lock; |
| 1539 | vport_qedf->pdev = base_qedf->pdev; |
| 1540 | vport_qedf->cmd_mgr = base_qedf->cmd_mgr; |
| 1541 | init_completion(&vport_qedf->flogi_compl); |
| 1542 | INIT_LIST_HEAD(&vport_qedf->fcports); |
| 1543 | |
| 1544 | rc = qedf_vport_libfc_config(vport, vn_port); |
| 1545 | if (rc) { |
| 1546 | QEDF_ERR(&(base_qedf->dbg_ctx), "Could not allocate memory " |
| 1547 | "for lport stats.\n"); |
| 1548 | goto err2; |
| 1549 | } |
| 1550 | |
| 1551 | fc_set_wwnn(vn_port, vport->node_name); |
| 1552 | fc_set_wwpn(vn_port, vport->port_name); |
| 1553 | vport_qedf->wwnn = vn_port->wwnn; |
| 1554 | vport_qedf->wwpn = vn_port->wwpn; |
| 1555 | |
| 1556 | vn_port->host->transportt = qedf_fc_vport_transport_template; |
| 1557 | vn_port->host->can_queue = QEDF_MAX_ELS_XID; |
| 1558 | vn_port->host->max_lun = qedf_max_lun; |
| 1559 | vn_port->host->sg_tablesize = QEDF_MAX_BDS_PER_CMD; |
| 1560 | vn_port->host->max_cmd_len = QEDF_MAX_CDB_LEN; |
| 1561 | |
| 1562 | rc = scsi_add_host(vn_port->host, &vport->dev); |
| 1563 | if (rc) { |
| 1564 | QEDF_WARN(&(base_qedf->dbg_ctx), "Error adding Scsi_Host.\n"); |
| 1565 | goto err2; |
| 1566 | } |
| 1567 | |
| 1568 | /* Set default dev_loss_tmo based on module parameter */ |
| 1569 | fc_host_dev_loss_tmo(vn_port->host) = qedf_dev_loss_tmo; |
| 1570 | |
| 1571 | /* Init libfc stuffs */ |
| 1572 | memcpy(&vn_port->tt, &qedf_lport_template, |
| 1573 | sizeof(qedf_lport_template)); |
| 1574 | fc_exch_init(vn_port); |
| 1575 | fc_elsct_init(vn_port); |
| 1576 | fc_lport_init(vn_port); |
| 1577 | fc_disc_init(vn_port); |
| 1578 | fc_disc_config(vn_port, vn_port); |
| 1579 | |
| 1580 | |
| 1581 | /* Allocate the exchange manager */ |
| 1582 | shost = vport_to_shost(vport); |
| 1583 | n_port = shost_priv(shost); |
| 1584 | fc_exch_mgr_list_clone(n_port, vn_port); |
| 1585 | |
| 1586 | /* Set max frame size */ |
| 1587 | fc_set_mfs(vn_port, QEDF_MFS); |
| 1588 | |
| 1589 | fc_host_port_type(vn_port->host) = FC_PORTTYPE_UNKNOWN; |
| 1590 | |
| 1591 | if (disabled) { |
| 1592 | fc_vport_set_state(vport, FC_VPORT_DISABLED); |
| 1593 | } else { |
| 1594 | vn_port->boot_time = jiffies; |
| 1595 | fc_fabric_login(vn_port); |
| 1596 | fc_vport_setlink(vn_port); |
| 1597 | } |
| 1598 | |
| 1599 | QEDF_INFO(&(base_qedf->dbg_ctx), QEDF_LOG_NPIV, "vn_port=%p.\n", |
| 1600 | vn_port); |
| 1601 | |
| 1602 | /* Set up debug context for vport */ |
| 1603 | vport_qedf->dbg_ctx.host_no = vn_port->host->host_no; |
| 1604 | vport_qedf->dbg_ctx.pdev = base_qedf->pdev; |
| 1605 | |
| 1606 | err2: |
| 1607 | scsi_host_put(vn_port->host); |
| 1608 | err1: |
| 1609 | return rc; |
| 1610 | } |
| 1611 | |
| 1612 | static int qedf_vport_destroy(struct fc_vport *vport) |
| 1613 | { |
| 1614 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 1615 | struct fc_lport *n_port = shost_priv(shost); |
| 1616 | struct fc_lport *vn_port = vport->dd_data; |
| 1617 | |
| 1618 | mutex_lock(&n_port->lp_mutex); |
| 1619 | list_del(&vn_port->list); |
| 1620 | mutex_unlock(&n_port->lp_mutex); |
| 1621 | |
| 1622 | fc_fabric_logoff(vn_port); |
| 1623 | fc_lport_destroy(vn_port); |
| 1624 | |
| 1625 | /* Detach from scsi-ml */ |
| 1626 | fc_remove_host(vn_port->host); |
| 1627 | scsi_remove_host(vn_port->host); |
| 1628 | |
| 1629 | /* |
| 1630 | * Only try to release the exchange manager if the vn_port |
| 1631 | * configuration is complete. |
| 1632 | */ |
| 1633 | if (vn_port->state == LPORT_ST_READY) |
| 1634 | fc_exch_mgr_free(vn_port); |
| 1635 | |
| 1636 | /* Free memory used by statistical counters */ |
| 1637 | fc_lport_free_stats(vn_port); |
| 1638 | |
| 1639 | /* Release Scsi_Host */ |
| 1640 | if (vn_port->host) |
| 1641 | scsi_host_put(vn_port->host); |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static int qedf_vport_disable(struct fc_vport *vport, bool disable) |
| 1647 | { |
| 1648 | struct fc_lport *lport = vport->dd_data; |
| 1649 | |
| 1650 | if (disable) { |
| 1651 | fc_vport_set_state(vport, FC_VPORT_DISABLED); |
| 1652 | fc_fabric_logoff(lport); |
| 1653 | } else { |
| 1654 | lport->boot_time = jiffies; |
| 1655 | fc_fabric_login(lport); |
| 1656 | fc_vport_setlink(lport); |
| 1657 | } |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | /* |
| 1662 | * During removal we need to wait for all the vports associated with a port |
| 1663 | * to be destroyed so we avoid a race condition where libfc is still trying |
| 1664 | * to reap vports while the driver remove function has already reaped the |
| 1665 | * driver contexts associated with the physical port. |
| 1666 | */ |
| 1667 | static void qedf_wait_for_vport_destroy(struct qedf_ctx *qedf) |
| 1668 | { |
| 1669 | struct fc_host_attrs *fc_host = shost_to_fc_host(qedf->lport->host); |
| 1670 | |
| 1671 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_NPIV, |
| 1672 | "Entered.\n"); |
| 1673 | while (fc_host->npiv_vports_inuse > 0) { |
| 1674 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_NPIV, |
| 1675 | "Waiting for all vports to be reaped.\n"); |
| 1676 | msleep(1000); |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * qedf_fcoe_reset - Resets the fcoe |
| 1682 | * |
| 1683 | * @shost: shost the reset is from |
| 1684 | * |
| 1685 | * Returns: always 0 |
| 1686 | */ |
| 1687 | static int qedf_fcoe_reset(struct Scsi_Host *shost) |
| 1688 | { |
| 1689 | struct fc_lport *lport = shost_priv(shost); |
| 1690 | |
Chad Dupuis | 5cf446d | 2017-05-31 06:33:55 -0700 | [diff] [blame] | 1691 | qedf_ctx_soft_reset(lport); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 1692 | return 0; |
| 1693 | } |
| 1694 | |
| 1695 | static struct fc_host_statistics *qedf_fc_get_host_stats(struct Scsi_Host |
| 1696 | *shost) |
| 1697 | { |
| 1698 | struct fc_host_statistics *qedf_stats; |
| 1699 | struct fc_lport *lport = shost_priv(shost); |
| 1700 | struct qedf_ctx *qedf = lport_priv(lport); |
| 1701 | struct qed_fcoe_stats *fw_fcoe_stats; |
| 1702 | |
| 1703 | qedf_stats = fc_get_host_stats(shost); |
| 1704 | |
| 1705 | /* We don't collect offload stats for specific NPIV ports */ |
| 1706 | if (lport->vport) |
| 1707 | goto out; |
| 1708 | |
| 1709 | fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL); |
| 1710 | if (!fw_fcoe_stats) { |
| 1711 | QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for " |
| 1712 | "fw_fcoe_stats.\n"); |
| 1713 | goto out; |
| 1714 | } |
| 1715 | |
| 1716 | /* Query firmware for offload stats */ |
| 1717 | qed_ops->get_stats(qedf->cdev, fw_fcoe_stats); |
| 1718 | |
| 1719 | /* |
| 1720 | * The expectation is that we add our offload stats to the stats |
| 1721 | * being maintained by libfc each time the fc_get_host_status callback |
| 1722 | * is invoked. The additions are not carried over for each call to |
| 1723 | * the fc_get_host_stats callback. |
| 1724 | */ |
| 1725 | qedf_stats->tx_frames += fw_fcoe_stats->fcoe_tx_data_pkt_cnt + |
| 1726 | fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt + |
| 1727 | fw_fcoe_stats->fcoe_tx_other_pkt_cnt; |
| 1728 | qedf_stats->rx_frames += fw_fcoe_stats->fcoe_rx_data_pkt_cnt + |
| 1729 | fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt + |
| 1730 | fw_fcoe_stats->fcoe_rx_other_pkt_cnt; |
| 1731 | qedf_stats->fcp_input_megabytes += |
| 1732 | do_div(fw_fcoe_stats->fcoe_rx_byte_cnt, 1000000); |
| 1733 | qedf_stats->fcp_output_megabytes += |
| 1734 | do_div(fw_fcoe_stats->fcoe_tx_byte_cnt, 1000000); |
| 1735 | qedf_stats->rx_words += fw_fcoe_stats->fcoe_rx_byte_cnt / 4; |
| 1736 | qedf_stats->tx_words += fw_fcoe_stats->fcoe_tx_byte_cnt / 4; |
| 1737 | qedf_stats->invalid_crc_count += |
| 1738 | fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt; |
| 1739 | qedf_stats->dumped_frames = |
| 1740 | fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt; |
| 1741 | qedf_stats->error_frames += |
| 1742 | fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt; |
| 1743 | qedf_stats->fcp_input_requests += qedf->input_requests; |
| 1744 | qedf_stats->fcp_output_requests += qedf->output_requests; |
| 1745 | qedf_stats->fcp_control_requests += qedf->control_requests; |
| 1746 | qedf_stats->fcp_packet_aborts += qedf->packet_aborts; |
| 1747 | qedf_stats->fcp_frame_alloc_failures += qedf->alloc_failures; |
| 1748 | |
| 1749 | kfree(fw_fcoe_stats); |
| 1750 | out: |
| 1751 | return qedf_stats; |
| 1752 | } |
| 1753 | |
| 1754 | static struct fc_function_template qedf_fc_transport_fn = { |
| 1755 | .show_host_node_name = 1, |
| 1756 | .show_host_port_name = 1, |
| 1757 | .show_host_supported_classes = 1, |
| 1758 | .show_host_supported_fc4s = 1, |
| 1759 | .show_host_active_fc4s = 1, |
| 1760 | .show_host_maxframe_size = 1, |
| 1761 | |
| 1762 | .show_host_port_id = 1, |
| 1763 | .show_host_supported_speeds = 1, |
| 1764 | .get_host_speed = fc_get_host_speed, |
| 1765 | .show_host_speed = 1, |
| 1766 | .show_host_port_type = 1, |
| 1767 | .get_host_port_state = fc_get_host_port_state, |
| 1768 | .show_host_port_state = 1, |
| 1769 | .show_host_symbolic_name = 1, |
| 1770 | |
| 1771 | /* |
| 1772 | * Tell FC transport to allocate enough space to store the backpointer |
| 1773 | * for the associate qedf_rport struct. |
| 1774 | */ |
| 1775 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + |
| 1776 | sizeof(struct qedf_rport)), |
| 1777 | .show_rport_maxframe_size = 1, |
| 1778 | .show_rport_supported_classes = 1, |
| 1779 | .show_host_fabric_name = 1, |
| 1780 | .show_starget_node_name = 1, |
| 1781 | .show_starget_port_name = 1, |
| 1782 | .show_starget_port_id = 1, |
| 1783 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, |
| 1784 | .show_rport_dev_loss_tmo = 1, |
| 1785 | .get_fc_host_stats = qedf_fc_get_host_stats, |
| 1786 | .issue_fc_host_lip = qedf_fcoe_reset, |
| 1787 | .vport_create = qedf_vport_create, |
| 1788 | .vport_delete = qedf_vport_destroy, |
| 1789 | .vport_disable = qedf_vport_disable, |
| 1790 | .bsg_request = fc_lport_bsg_request, |
| 1791 | }; |
| 1792 | |
| 1793 | static struct fc_function_template qedf_fc_vport_transport_fn = { |
| 1794 | .show_host_node_name = 1, |
| 1795 | .show_host_port_name = 1, |
| 1796 | .show_host_supported_classes = 1, |
| 1797 | .show_host_supported_fc4s = 1, |
| 1798 | .show_host_active_fc4s = 1, |
| 1799 | .show_host_maxframe_size = 1, |
| 1800 | .show_host_port_id = 1, |
| 1801 | .show_host_supported_speeds = 1, |
| 1802 | .get_host_speed = fc_get_host_speed, |
| 1803 | .show_host_speed = 1, |
| 1804 | .show_host_port_type = 1, |
| 1805 | .get_host_port_state = fc_get_host_port_state, |
| 1806 | .show_host_port_state = 1, |
| 1807 | .show_host_symbolic_name = 1, |
| 1808 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + |
| 1809 | sizeof(struct qedf_rport)), |
| 1810 | .show_rport_maxframe_size = 1, |
| 1811 | .show_rport_supported_classes = 1, |
| 1812 | .show_host_fabric_name = 1, |
| 1813 | .show_starget_node_name = 1, |
| 1814 | .show_starget_port_name = 1, |
| 1815 | .show_starget_port_id = 1, |
| 1816 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, |
| 1817 | .show_rport_dev_loss_tmo = 1, |
| 1818 | .get_fc_host_stats = fc_get_host_stats, |
| 1819 | .issue_fc_host_lip = qedf_fcoe_reset, |
| 1820 | .bsg_request = fc_lport_bsg_request, |
| 1821 | }; |
| 1822 | |
| 1823 | static bool qedf_fp_has_work(struct qedf_fastpath *fp) |
| 1824 | { |
| 1825 | struct qedf_ctx *qedf = fp->qedf; |
| 1826 | struct global_queue *que; |
| 1827 | struct qed_sb_info *sb_info = fp->sb_info; |
| 1828 | struct status_block *sb = sb_info->sb_virt; |
| 1829 | u16 prod_idx; |
| 1830 | |
| 1831 | /* Get the pointer to the global CQ this completion is on */ |
| 1832 | que = qedf->global_queues[fp->sb_id]; |
| 1833 | |
| 1834 | /* Be sure all responses have been written to PI */ |
| 1835 | rmb(); |
| 1836 | |
| 1837 | /* Get the current firmware producer index */ |
| 1838 | prod_idx = sb->pi_array[QEDF_FCOE_PARAMS_GL_RQ_PI]; |
| 1839 | |
| 1840 | return (que->cq_prod_idx != prod_idx); |
| 1841 | } |
| 1842 | |
| 1843 | /* |
| 1844 | * Interrupt handler code. |
| 1845 | */ |
| 1846 | |
| 1847 | /* Process completion queue and copy CQE contents for deferred processesing |
| 1848 | * |
| 1849 | * Return true if we should wake the I/O thread, false if not. |
| 1850 | */ |
| 1851 | static bool qedf_process_completions(struct qedf_fastpath *fp) |
| 1852 | { |
| 1853 | struct qedf_ctx *qedf = fp->qedf; |
| 1854 | struct qed_sb_info *sb_info = fp->sb_info; |
| 1855 | struct status_block *sb = sb_info->sb_virt; |
| 1856 | struct global_queue *que; |
| 1857 | u16 prod_idx; |
| 1858 | struct fcoe_cqe *cqe; |
| 1859 | struct qedf_io_work *io_work; |
| 1860 | int num_handled = 0; |
| 1861 | unsigned int cpu; |
| 1862 | struct qedf_ioreq *io_req = NULL; |
| 1863 | u16 xid; |
| 1864 | u16 new_cqes; |
| 1865 | u32 comp_type; |
| 1866 | |
| 1867 | /* Get the current firmware producer index */ |
| 1868 | prod_idx = sb->pi_array[QEDF_FCOE_PARAMS_GL_RQ_PI]; |
| 1869 | |
| 1870 | /* Get the pointer to the global CQ this completion is on */ |
| 1871 | que = qedf->global_queues[fp->sb_id]; |
| 1872 | |
| 1873 | /* Calculate the amount of new elements since last processing */ |
| 1874 | new_cqes = (prod_idx >= que->cq_prod_idx) ? |
| 1875 | (prod_idx - que->cq_prod_idx) : |
| 1876 | 0x10000 - que->cq_prod_idx + prod_idx; |
| 1877 | |
| 1878 | /* Save producer index */ |
| 1879 | que->cq_prod_idx = prod_idx; |
| 1880 | |
| 1881 | while (new_cqes) { |
| 1882 | fp->completions++; |
| 1883 | num_handled++; |
| 1884 | cqe = &que->cq[que->cq_cons_idx]; |
| 1885 | |
| 1886 | comp_type = (cqe->cqe_data >> FCOE_CQE_CQE_TYPE_SHIFT) & |
| 1887 | FCOE_CQE_CQE_TYPE_MASK; |
| 1888 | |
| 1889 | /* |
| 1890 | * Process unsolicited CQEs directly in the interrupt handler |
| 1891 | * sine we need the fastpath ID |
| 1892 | */ |
| 1893 | if (comp_type == FCOE_UNSOLIC_CQE_TYPE) { |
| 1894 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_UNSOL, |
| 1895 | "Unsolicated CQE.\n"); |
| 1896 | qedf_process_unsol_compl(qedf, fp->sb_id, cqe); |
| 1897 | /* |
| 1898 | * Don't add a work list item. Increment consumer |
| 1899 | * consumer index and move on. |
| 1900 | */ |
| 1901 | goto inc_idx; |
| 1902 | } |
| 1903 | |
| 1904 | xid = cqe->cqe_data & FCOE_CQE_TASK_ID_MASK; |
| 1905 | io_req = &qedf->cmd_mgr->cmds[xid]; |
| 1906 | |
| 1907 | /* |
| 1908 | * Figure out which percpu thread we should queue this I/O |
| 1909 | * on. |
| 1910 | */ |
| 1911 | if (!io_req) |
| 1912 | /* If there is not io_req assocated with this CQE |
| 1913 | * just queue it on CPU 0 |
| 1914 | */ |
| 1915 | cpu = 0; |
| 1916 | else { |
| 1917 | cpu = io_req->cpu; |
| 1918 | io_req->int_cpu = smp_processor_id(); |
| 1919 | } |
| 1920 | |
| 1921 | io_work = mempool_alloc(qedf->io_mempool, GFP_ATOMIC); |
| 1922 | if (!io_work) { |
| 1923 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate " |
| 1924 | "work for I/O completion.\n"); |
| 1925 | continue; |
| 1926 | } |
| 1927 | memset(io_work, 0, sizeof(struct qedf_io_work)); |
| 1928 | |
| 1929 | INIT_WORK(&io_work->work, qedf_fp_io_handler); |
| 1930 | |
| 1931 | /* Copy contents of CQE for deferred processing */ |
| 1932 | memcpy(&io_work->cqe, cqe, sizeof(struct fcoe_cqe)); |
| 1933 | |
| 1934 | io_work->qedf = fp->qedf; |
| 1935 | io_work->fp = NULL; /* Only used for unsolicited frames */ |
| 1936 | |
| 1937 | queue_work_on(cpu, qedf_io_wq, &io_work->work); |
| 1938 | |
| 1939 | inc_idx: |
| 1940 | que->cq_cons_idx++; |
| 1941 | if (que->cq_cons_idx == fp->cq_num_entries) |
| 1942 | que->cq_cons_idx = 0; |
| 1943 | new_cqes--; |
| 1944 | } |
| 1945 | |
| 1946 | return true; |
| 1947 | } |
| 1948 | |
| 1949 | |
| 1950 | /* MSI-X fastpath handler code */ |
| 1951 | static irqreturn_t qedf_msix_handler(int irq, void *dev_id) |
| 1952 | { |
| 1953 | struct qedf_fastpath *fp = dev_id; |
| 1954 | |
| 1955 | if (!fp) { |
| 1956 | QEDF_ERR(NULL, "fp is null.\n"); |
| 1957 | return IRQ_HANDLED; |
| 1958 | } |
| 1959 | if (!fp->sb_info) { |
| 1960 | QEDF_ERR(NULL, "fp->sb_info in null."); |
| 1961 | return IRQ_HANDLED; |
| 1962 | } |
| 1963 | |
| 1964 | /* |
| 1965 | * Disable interrupts for this status block while we process new |
| 1966 | * completions |
| 1967 | */ |
| 1968 | qed_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0 /*do not update*/); |
| 1969 | |
| 1970 | while (1) { |
| 1971 | qedf_process_completions(fp); |
| 1972 | |
| 1973 | if (qedf_fp_has_work(fp) == 0) { |
| 1974 | /* Update the sb information */ |
| 1975 | qed_sb_update_sb_idx(fp->sb_info); |
| 1976 | |
| 1977 | /* Check for more work */ |
| 1978 | rmb(); |
| 1979 | |
| 1980 | if (qedf_fp_has_work(fp) == 0) { |
| 1981 | /* Re-enable interrupts */ |
| 1982 | qed_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1); |
| 1983 | return IRQ_HANDLED; |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | /* Do we ever want to break out of above loop? */ |
| 1989 | return IRQ_HANDLED; |
| 1990 | } |
| 1991 | |
| 1992 | /* simd handler for MSI/INTa */ |
| 1993 | static void qedf_simd_int_handler(void *cookie) |
| 1994 | { |
| 1995 | /* Cookie is qedf_ctx struct */ |
| 1996 | struct qedf_ctx *qedf = (struct qedf_ctx *)cookie; |
| 1997 | |
| 1998 | QEDF_WARN(&(qedf->dbg_ctx), "qedf=%p.\n", qedf); |
| 1999 | } |
| 2000 | |
| 2001 | #define QEDF_SIMD_HANDLER_NUM 0 |
| 2002 | static void qedf_sync_free_irqs(struct qedf_ctx *qedf) |
| 2003 | { |
| 2004 | int i; |
| 2005 | |
| 2006 | if (qedf->int_info.msix_cnt) { |
| 2007 | for (i = 0; i < qedf->int_info.used_cnt; i++) { |
| 2008 | synchronize_irq(qedf->int_info.msix[i].vector); |
| 2009 | irq_set_affinity_hint(qedf->int_info.msix[i].vector, |
| 2010 | NULL); |
| 2011 | irq_set_affinity_notifier(qedf->int_info.msix[i].vector, |
| 2012 | NULL); |
| 2013 | free_irq(qedf->int_info.msix[i].vector, |
| 2014 | &qedf->fp_array[i]); |
| 2015 | } |
| 2016 | } else |
| 2017 | qed_ops->common->simd_handler_clean(qedf->cdev, |
| 2018 | QEDF_SIMD_HANDLER_NUM); |
| 2019 | |
| 2020 | qedf->int_info.used_cnt = 0; |
| 2021 | qed_ops->common->set_fp_int(qedf->cdev, 0); |
| 2022 | } |
| 2023 | |
| 2024 | static int qedf_request_msix_irq(struct qedf_ctx *qedf) |
| 2025 | { |
| 2026 | int i, rc, cpu; |
| 2027 | |
| 2028 | cpu = cpumask_first(cpu_online_mask); |
| 2029 | for (i = 0; i < qedf->num_queues; i++) { |
| 2030 | rc = request_irq(qedf->int_info.msix[i].vector, |
| 2031 | qedf_msix_handler, 0, "qedf", &qedf->fp_array[i]); |
| 2032 | |
| 2033 | if (rc) { |
| 2034 | QEDF_WARN(&(qedf->dbg_ctx), "request_irq failed.\n"); |
| 2035 | qedf_sync_free_irqs(qedf); |
| 2036 | return rc; |
| 2037 | } |
| 2038 | |
| 2039 | qedf->int_info.used_cnt++; |
| 2040 | rc = irq_set_affinity_hint(qedf->int_info.msix[i].vector, |
| 2041 | get_cpu_mask(cpu)); |
| 2042 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 2043 | } |
| 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | static int qedf_setup_int(struct qedf_ctx *qedf) |
| 2049 | { |
| 2050 | int rc = 0; |
| 2051 | |
| 2052 | /* |
| 2053 | * Learn interrupt configuration |
| 2054 | */ |
| 2055 | rc = qed_ops->common->set_fp_int(qedf->cdev, num_online_cpus()); |
Chad Dupuis | 914fff1 | 2017-05-31 06:33:50 -0700 | [diff] [blame] | 2056 | if (rc <= 0) |
| 2057 | return 0; |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 2058 | |
| 2059 | rc = qed_ops->common->get_fp_int(qedf->cdev, &qedf->int_info); |
| 2060 | if (rc) |
| 2061 | return 0; |
| 2062 | |
| 2063 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Number of msix_cnt = " |
| 2064 | "0x%x num of cpus = 0x%x\n", qedf->int_info.msix_cnt, |
| 2065 | num_online_cpus()); |
| 2066 | |
| 2067 | if (qedf->int_info.msix_cnt) |
| 2068 | return qedf_request_msix_irq(qedf); |
| 2069 | |
| 2070 | qed_ops->common->simd_handler_config(qedf->cdev, &qedf, |
| 2071 | QEDF_SIMD_HANDLER_NUM, qedf_simd_int_handler); |
| 2072 | qedf->int_info.used_cnt = 1; |
| 2073 | |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
| 2077 | /* Main function for libfc frame reception */ |
| 2078 | static void qedf_recv_frame(struct qedf_ctx *qedf, |
| 2079 | struct sk_buff *skb) |
| 2080 | { |
| 2081 | u32 fr_len; |
| 2082 | struct fc_lport *lport; |
| 2083 | struct fc_frame_header *fh; |
| 2084 | struct fcoe_crc_eof crc_eof; |
| 2085 | struct fc_frame *fp; |
| 2086 | u8 *mac = NULL; |
| 2087 | u8 *dest_mac = NULL; |
| 2088 | struct fcoe_hdr *hp; |
| 2089 | struct qedf_rport *fcport; |
| 2090 | |
| 2091 | lport = qedf->lport; |
| 2092 | if (lport == NULL || lport->state == LPORT_ST_DISABLED) { |
| 2093 | QEDF_WARN(NULL, "Invalid lport struct or lport disabled.\n"); |
| 2094 | kfree_skb(skb); |
| 2095 | return; |
| 2096 | } |
| 2097 | |
| 2098 | if (skb_is_nonlinear(skb)) |
| 2099 | skb_linearize(skb); |
| 2100 | mac = eth_hdr(skb)->h_source; |
| 2101 | dest_mac = eth_hdr(skb)->h_dest; |
| 2102 | |
| 2103 | /* Pull the header */ |
| 2104 | hp = (struct fcoe_hdr *)skb->data; |
| 2105 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 2106 | skb_pull(skb, sizeof(struct fcoe_hdr)); |
| 2107 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); |
| 2108 | |
| 2109 | fp = (struct fc_frame *)skb; |
| 2110 | fc_frame_init(fp); |
| 2111 | fr_dev(fp) = lport; |
| 2112 | fr_sof(fp) = hp->fcoe_sof; |
| 2113 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { |
| 2114 | kfree_skb(skb); |
| 2115 | return; |
| 2116 | } |
| 2117 | fr_eof(fp) = crc_eof.fcoe_eof; |
| 2118 | fr_crc(fp) = crc_eof.fcoe_crc32; |
| 2119 | if (pskb_trim(skb, fr_len)) { |
| 2120 | kfree_skb(skb); |
| 2121 | return; |
| 2122 | } |
| 2123 | |
| 2124 | fh = fc_frame_header_get(fp); |
| 2125 | |
| 2126 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && |
| 2127 | fh->fh_type == FC_TYPE_FCP) { |
| 2128 | /* Drop FCP data. We dont this in L2 path */ |
| 2129 | kfree_skb(skb); |
| 2130 | return; |
| 2131 | } |
| 2132 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && |
| 2133 | fh->fh_type == FC_TYPE_ELS) { |
| 2134 | switch (fc_frame_payload_op(fp)) { |
| 2135 | case ELS_LOGO: |
| 2136 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { |
| 2137 | /* drop non-FIP LOGO */ |
| 2138 | kfree_skb(skb); |
| 2139 | return; |
| 2140 | } |
| 2141 | break; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 2146 | /* Drop incoming ABTS */ |
| 2147 | kfree_skb(skb); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | /* |
| 2152 | * If a connection is uploading, drop incoming FCoE frames as there |
| 2153 | * is a small window where we could try to return a frame while libfc |
| 2154 | * is trying to clean things up. |
| 2155 | */ |
| 2156 | |
| 2157 | /* Get fcport associated with d_id if it exists */ |
| 2158 | fcport = qedf_fcport_lookup(qedf, ntoh24(fh->fh_d_id)); |
| 2159 | |
| 2160 | if (fcport && test_bit(QEDF_RPORT_UPLOADING_CONNECTION, |
| 2161 | &fcport->flags)) { |
| 2162 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, |
| 2163 | "Connection uploading, dropping fp=%p.\n", fp); |
| 2164 | kfree_skb(skb); |
| 2165 | return; |
| 2166 | } |
| 2167 | |
| 2168 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FCoE frame receive: " |
| 2169 | "skb=%p fp=%p src=%06x dest=%06x r_ctl=%x fh_type=%x.\n", skb, fp, |
| 2170 | ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id), fh->fh_r_ctl, |
| 2171 | fh->fh_type); |
| 2172 | if (qedf_dump_frames) |
| 2173 | print_hex_dump(KERN_WARNING, "fcoe: ", DUMP_PREFIX_OFFSET, 16, |
| 2174 | 1, skb->data, skb->len, false); |
| 2175 | fc_exch_recv(lport, fp); |
| 2176 | } |
| 2177 | |
| 2178 | static void qedf_ll2_process_skb(struct work_struct *work) |
| 2179 | { |
| 2180 | struct qedf_skb_work *skb_work = |
| 2181 | container_of(work, struct qedf_skb_work, work); |
| 2182 | struct qedf_ctx *qedf = skb_work->qedf; |
| 2183 | struct sk_buff *skb = skb_work->skb; |
| 2184 | struct ethhdr *eh; |
| 2185 | |
| 2186 | if (!qedf) { |
| 2187 | QEDF_ERR(NULL, "qedf is NULL\n"); |
| 2188 | goto err_out; |
| 2189 | } |
| 2190 | |
| 2191 | eh = (struct ethhdr *)skb->data; |
| 2192 | |
| 2193 | /* Undo VLAN encapsulation */ |
| 2194 | if (eh->h_proto == htons(ETH_P_8021Q)) { |
| 2195 | memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2); |
| 2196 | eh = (struct ethhdr *)skb_pull(skb, VLAN_HLEN); |
| 2197 | skb_reset_mac_header(skb); |
| 2198 | } |
| 2199 | |
| 2200 | /* |
| 2201 | * Process either a FIP frame or FCoE frame based on the |
| 2202 | * protocol value. If it's not either just drop the |
| 2203 | * frame. |
| 2204 | */ |
| 2205 | if (eh->h_proto == htons(ETH_P_FIP)) { |
| 2206 | qedf_fip_recv(qedf, skb); |
| 2207 | goto out; |
| 2208 | } else if (eh->h_proto == htons(ETH_P_FCOE)) { |
| 2209 | __skb_pull(skb, ETH_HLEN); |
| 2210 | qedf_recv_frame(qedf, skb); |
| 2211 | goto out; |
| 2212 | } else |
| 2213 | goto err_out; |
| 2214 | |
| 2215 | err_out: |
| 2216 | kfree_skb(skb); |
| 2217 | out: |
| 2218 | kfree(skb_work); |
| 2219 | return; |
| 2220 | } |
| 2221 | |
| 2222 | static int qedf_ll2_rx(void *cookie, struct sk_buff *skb, |
| 2223 | u32 arg1, u32 arg2) |
| 2224 | { |
| 2225 | struct qedf_ctx *qedf = (struct qedf_ctx *)cookie; |
| 2226 | struct qedf_skb_work *skb_work; |
| 2227 | |
| 2228 | skb_work = kzalloc(sizeof(struct qedf_skb_work), GFP_ATOMIC); |
| 2229 | if (!skb_work) { |
| 2230 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate skb_work so " |
| 2231 | "dropping frame.\n"); |
| 2232 | kfree_skb(skb); |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
| 2236 | INIT_WORK(&skb_work->work, qedf_ll2_process_skb); |
| 2237 | skb_work->skb = skb; |
| 2238 | skb_work->qedf = qedf; |
| 2239 | queue_work(qedf->ll2_recv_wq, &skb_work->work); |
| 2240 | |
| 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | static struct qed_ll2_cb_ops qedf_ll2_cb_ops = { |
| 2245 | .rx_cb = qedf_ll2_rx, |
| 2246 | .tx_cb = NULL, |
| 2247 | }; |
| 2248 | |
| 2249 | /* Main thread to process I/O completions */ |
| 2250 | void qedf_fp_io_handler(struct work_struct *work) |
| 2251 | { |
| 2252 | struct qedf_io_work *io_work = |
| 2253 | container_of(work, struct qedf_io_work, work); |
| 2254 | u32 comp_type; |
| 2255 | |
| 2256 | /* |
| 2257 | * Deferred part of unsolicited CQE sends |
| 2258 | * frame to libfc. |
| 2259 | */ |
| 2260 | comp_type = (io_work->cqe.cqe_data >> |
| 2261 | FCOE_CQE_CQE_TYPE_SHIFT) & |
| 2262 | FCOE_CQE_CQE_TYPE_MASK; |
| 2263 | if (comp_type == FCOE_UNSOLIC_CQE_TYPE && |
| 2264 | io_work->fp) |
| 2265 | fc_exch_recv(io_work->qedf->lport, io_work->fp); |
| 2266 | else |
| 2267 | qedf_process_cqe(io_work->qedf, &io_work->cqe); |
| 2268 | |
| 2269 | kfree(io_work); |
| 2270 | } |
| 2271 | |
| 2272 | static int qedf_alloc_and_init_sb(struct qedf_ctx *qedf, |
| 2273 | struct qed_sb_info *sb_info, u16 sb_id) |
| 2274 | { |
| 2275 | struct status_block *sb_virt; |
| 2276 | dma_addr_t sb_phys; |
| 2277 | int ret; |
| 2278 | |
| 2279 | sb_virt = dma_alloc_coherent(&qedf->pdev->dev, |
| 2280 | sizeof(struct status_block), &sb_phys, GFP_KERNEL); |
| 2281 | |
| 2282 | if (!sb_virt) { |
| 2283 | QEDF_ERR(&(qedf->dbg_ctx), "Status block allocation failed " |
| 2284 | "for id = %d.\n", sb_id); |
| 2285 | return -ENOMEM; |
| 2286 | } |
| 2287 | |
| 2288 | ret = qed_ops->common->sb_init(qedf->cdev, sb_info, sb_virt, sb_phys, |
| 2289 | sb_id, QED_SB_TYPE_STORAGE); |
| 2290 | |
| 2291 | if (ret) { |
| 2292 | QEDF_ERR(&(qedf->dbg_ctx), "Status block initialization " |
| 2293 | "failed for id = %d.\n", sb_id); |
| 2294 | return ret; |
| 2295 | } |
| 2296 | |
| 2297 | return 0; |
| 2298 | } |
| 2299 | |
| 2300 | static void qedf_free_sb(struct qedf_ctx *qedf, struct qed_sb_info *sb_info) |
| 2301 | { |
| 2302 | if (sb_info->sb_virt) |
| 2303 | dma_free_coherent(&qedf->pdev->dev, sizeof(*sb_info->sb_virt), |
| 2304 | (void *)sb_info->sb_virt, sb_info->sb_phys); |
| 2305 | } |
| 2306 | |
| 2307 | static void qedf_destroy_sb(struct qedf_ctx *qedf) |
| 2308 | { |
| 2309 | int id; |
| 2310 | struct qedf_fastpath *fp = NULL; |
| 2311 | |
| 2312 | for (id = 0; id < qedf->num_queues; id++) { |
| 2313 | fp = &(qedf->fp_array[id]); |
| 2314 | if (fp->sb_id == QEDF_SB_ID_NULL) |
| 2315 | break; |
| 2316 | qedf_free_sb(qedf, fp->sb_info); |
| 2317 | kfree(fp->sb_info); |
| 2318 | } |
| 2319 | kfree(qedf->fp_array); |
| 2320 | } |
| 2321 | |
| 2322 | static int qedf_prepare_sb(struct qedf_ctx *qedf) |
| 2323 | { |
| 2324 | int id; |
| 2325 | struct qedf_fastpath *fp; |
| 2326 | int ret; |
| 2327 | |
| 2328 | qedf->fp_array = |
| 2329 | kcalloc(qedf->num_queues, sizeof(struct qedf_fastpath), |
| 2330 | GFP_KERNEL); |
| 2331 | |
| 2332 | if (!qedf->fp_array) { |
| 2333 | QEDF_ERR(&(qedf->dbg_ctx), "fastpath array allocation " |
| 2334 | "failed.\n"); |
| 2335 | return -ENOMEM; |
| 2336 | } |
| 2337 | |
| 2338 | for (id = 0; id < qedf->num_queues; id++) { |
| 2339 | fp = &(qedf->fp_array[id]); |
| 2340 | fp->sb_id = QEDF_SB_ID_NULL; |
| 2341 | fp->sb_info = kcalloc(1, sizeof(*fp->sb_info), GFP_KERNEL); |
| 2342 | if (!fp->sb_info) { |
| 2343 | QEDF_ERR(&(qedf->dbg_ctx), "SB info struct " |
| 2344 | "allocation failed.\n"); |
| 2345 | goto err; |
| 2346 | } |
| 2347 | ret = qedf_alloc_and_init_sb(qedf, fp->sb_info, id); |
| 2348 | if (ret) { |
| 2349 | QEDF_ERR(&(qedf->dbg_ctx), "SB allocation and " |
| 2350 | "initialization failed.\n"); |
| 2351 | goto err; |
| 2352 | } |
| 2353 | fp->sb_id = id; |
| 2354 | fp->qedf = qedf; |
| 2355 | fp->cq_num_entries = |
| 2356 | qedf->global_queues[id]->cq_mem_size / |
| 2357 | sizeof(struct fcoe_cqe); |
| 2358 | } |
| 2359 | err: |
| 2360 | return 0; |
| 2361 | } |
| 2362 | |
| 2363 | void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe) |
| 2364 | { |
| 2365 | u16 xid; |
| 2366 | struct qedf_ioreq *io_req; |
| 2367 | struct qedf_rport *fcport; |
| 2368 | u32 comp_type; |
| 2369 | |
| 2370 | comp_type = (cqe->cqe_data >> FCOE_CQE_CQE_TYPE_SHIFT) & |
| 2371 | FCOE_CQE_CQE_TYPE_MASK; |
| 2372 | |
| 2373 | xid = cqe->cqe_data & FCOE_CQE_TASK_ID_MASK; |
| 2374 | io_req = &qedf->cmd_mgr->cmds[xid]; |
| 2375 | |
| 2376 | /* Completion not for a valid I/O anymore so just return */ |
| 2377 | if (!io_req) |
| 2378 | return; |
| 2379 | |
| 2380 | fcport = io_req->fcport; |
| 2381 | |
| 2382 | if (fcport == NULL) { |
| 2383 | QEDF_ERR(&(qedf->dbg_ctx), "fcport is NULL.\n"); |
| 2384 | return; |
| 2385 | } |
| 2386 | |
| 2387 | /* |
| 2388 | * Check that fcport is offloaded. If it isn't then the spinlock |
| 2389 | * isn't valid and shouldn't be taken. We should just return. |
| 2390 | */ |
| 2391 | if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { |
| 2392 | QEDF_ERR(&(qedf->dbg_ctx), "Session not offloaded yet.\n"); |
| 2393 | return; |
| 2394 | } |
| 2395 | |
| 2396 | |
| 2397 | switch (comp_type) { |
| 2398 | case FCOE_GOOD_COMPLETION_CQE_TYPE: |
| 2399 | atomic_inc(&fcport->free_sqes); |
| 2400 | switch (io_req->cmd_type) { |
| 2401 | case QEDF_SCSI_CMD: |
| 2402 | qedf_scsi_completion(qedf, cqe, io_req); |
| 2403 | break; |
| 2404 | case QEDF_ELS: |
| 2405 | qedf_process_els_compl(qedf, cqe, io_req); |
| 2406 | break; |
| 2407 | case QEDF_TASK_MGMT_CMD: |
| 2408 | qedf_process_tmf_compl(qedf, cqe, io_req); |
| 2409 | break; |
| 2410 | case QEDF_SEQ_CLEANUP: |
| 2411 | qedf_process_seq_cleanup_compl(qedf, cqe, io_req); |
| 2412 | break; |
| 2413 | } |
| 2414 | break; |
| 2415 | case FCOE_ERROR_DETECTION_CQE_TYPE: |
| 2416 | atomic_inc(&fcport->free_sqes); |
| 2417 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2418 | "Error detect CQE.\n"); |
| 2419 | qedf_process_error_detect(qedf, cqe, io_req); |
| 2420 | break; |
| 2421 | case FCOE_EXCH_CLEANUP_CQE_TYPE: |
| 2422 | atomic_inc(&fcport->free_sqes); |
| 2423 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2424 | "Cleanup CQE.\n"); |
| 2425 | qedf_process_cleanup_compl(qedf, cqe, io_req); |
| 2426 | break; |
| 2427 | case FCOE_ABTS_CQE_TYPE: |
| 2428 | atomic_inc(&fcport->free_sqes); |
| 2429 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2430 | "Abort CQE.\n"); |
| 2431 | qedf_process_abts_compl(qedf, cqe, io_req); |
| 2432 | break; |
| 2433 | case FCOE_DUMMY_CQE_TYPE: |
| 2434 | atomic_inc(&fcport->free_sqes); |
| 2435 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2436 | "Dummy CQE.\n"); |
| 2437 | break; |
| 2438 | case FCOE_LOCAL_COMP_CQE_TYPE: |
| 2439 | atomic_inc(&fcport->free_sqes); |
| 2440 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2441 | "Local completion CQE.\n"); |
| 2442 | break; |
| 2443 | case FCOE_WARNING_CQE_TYPE: |
| 2444 | atomic_inc(&fcport->free_sqes); |
| 2445 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2446 | "Warning CQE.\n"); |
| 2447 | qedf_process_warning_compl(qedf, cqe, io_req); |
| 2448 | break; |
| 2449 | case MAX_FCOE_CQE_TYPE: |
| 2450 | atomic_inc(&fcport->free_sqes); |
| 2451 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2452 | "Max FCoE CQE.\n"); |
| 2453 | break; |
| 2454 | default: |
| 2455 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, |
| 2456 | "Default CQE.\n"); |
| 2457 | break; |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | static void qedf_free_bdq(struct qedf_ctx *qedf) |
| 2462 | { |
| 2463 | int i; |
| 2464 | |
| 2465 | if (qedf->bdq_pbl_list) |
| 2466 | dma_free_coherent(&qedf->pdev->dev, QEDF_PAGE_SIZE, |
| 2467 | qedf->bdq_pbl_list, qedf->bdq_pbl_list_dma); |
| 2468 | |
| 2469 | if (qedf->bdq_pbl) |
| 2470 | dma_free_coherent(&qedf->pdev->dev, qedf->bdq_pbl_mem_size, |
| 2471 | qedf->bdq_pbl, qedf->bdq_pbl_dma); |
| 2472 | |
| 2473 | for (i = 0; i < QEDF_BDQ_SIZE; i++) { |
| 2474 | if (qedf->bdq[i].buf_addr) { |
| 2475 | dma_free_coherent(&qedf->pdev->dev, QEDF_BDQ_BUF_SIZE, |
| 2476 | qedf->bdq[i].buf_addr, qedf->bdq[i].buf_dma); |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | static void qedf_free_global_queues(struct qedf_ctx *qedf) |
| 2482 | { |
| 2483 | int i; |
| 2484 | struct global_queue **gl = qedf->global_queues; |
| 2485 | |
| 2486 | for (i = 0; i < qedf->num_queues; i++) { |
| 2487 | if (!gl[i]) |
| 2488 | continue; |
| 2489 | |
| 2490 | if (gl[i]->cq) |
| 2491 | dma_free_coherent(&qedf->pdev->dev, |
| 2492 | gl[i]->cq_mem_size, gl[i]->cq, gl[i]->cq_dma); |
| 2493 | if (gl[i]->cq_pbl) |
| 2494 | dma_free_coherent(&qedf->pdev->dev, gl[i]->cq_pbl_size, |
| 2495 | gl[i]->cq_pbl, gl[i]->cq_pbl_dma); |
| 2496 | |
| 2497 | kfree(gl[i]); |
| 2498 | } |
| 2499 | |
| 2500 | qedf_free_bdq(qedf); |
| 2501 | } |
| 2502 | |
| 2503 | static int qedf_alloc_bdq(struct qedf_ctx *qedf) |
| 2504 | { |
| 2505 | int i; |
| 2506 | struct scsi_bd *pbl; |
| 2507 | u64 *list; |
| 2508 | dma_addr_t page; |
| 2509 | |
| 2510 | /* Alloc dma memory for BDQ buffers */ |
| 2511 | for (i = 0; i < QEDF_BDQ_SIZE; i++) { |
| 2512 | qedf->bdq[i].buf_addr = dma_alloc_coherent(&qedf->pdev->dev, |
| 2513 | QEDF_BDQ_BUF_SIZE, &qedf->bdq[i].buf_dma, GFP_KERNEL); |
| 2514 | if (!qedf->bdq[i].buf_addr) { |
| 2515 | QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate BDQ " |
| 2516 | "buffer %d.\n", i); |
| 2517 | return -ENOMEM; |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | /* Alloc dma memory for BDQ page buffer list */ |
| 2522 | qedf->bdq_pbl_mem_size = |
| 2523 | QEDF_BDQ_SIZE * sizeof(struct scsi_bd); |
| 2524 | qedf->bdq_pbl_mem_size = |
| 2525 | ALIGN(qedf->bdq_pbl_mem_size, QEDF_PAGE_SIZE); |
| 2526 | |
| 2527 | qedf->bdq_pbl = dma_alloc_coherent(&qedf->pdev->dev, |
| 2528 | qedf->bdq_pbl_mem_size, &qedf->bdq_pbl_dma, GFP_KERNEL); |
| 2529 | if (!qedf->bdq_pbl) { |
| 2530 | QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate BDQ PBL.\n"); |
| 2531 | return -ENOMEM; |
| 2532 | } |
| 2533 | |
| 2534 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
Joe Perches | fd2b18b | 2017-03-06 10:32:27 -0800 | [diff] [blame] | 2535 | "BDQ PBL addr=0x%p dma=%pad\n", |
| 2536 | qedf->bdq_pbl, &qedf->bdq_pbl_dma); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 2537 | |
| 2538 | /* |
| 2539 | * Populate BDQ PBL with physical and virtual address of individual |
| 2540 | * BDQ buffers |
| 2541 | */ |
| 2542 | pbl = (struct scsi_bd *)qedf->bdq_pbl; |
| 2543 | for (i = 0; i < QEDF_BDQ_SIZE; i++) { |
| 2544 | pbl->address.hi = cpu_to_le32(U64_HI(qedf->bdq[i].buf_dma)); |
| 2545 | pbl->address.lo = cpu_to_le32(U64_LO(qedf->bdq[i].buf_dma)); |
| 2546 | pbl->opaque.hi = 0; |
| 2547 | /* Opaque lo data is an index into the BDQ array */ |
| 2548 | pbl->opaque.lo = cpu_to_le32(i); |
| 2549 | pbl++; |
| 2550 | } |
| 2551 | |
| 2552 | /* Allocate list of PBL pages */ |
| 2553 | qedf->bdq_pbl_list = dma_alloc_coherent(&qedf->pdev->dev, |
| 2554 | QEDF_PAGE_SIZE, &qedf->bdq_pbl_list_dma, GFP_KERNEL); |
| 2555 | if (!qedf->bdq_pbl_list) { |
| 2556 | QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate list of PBL " |
| 2557 | "pages.\n"); |
| 2558 | return -ENOMEM; |
| 2559 | } |
| 2560 | memset(qedf->bdq_pbl_list, 0, QEDF_PAGE_SIZE); |
| 2561 | |
| 2562 | /* |
| 2563 | * Now populate PBL list with pages that contain pointers to the |
| 2564 | * individual buffers. |
| 2565 | */ |
| 2566 | qedf->bdq_pbl_list_num_entries = qedf->bdq_pbl_mem_size / |
| 2567 | QEDF_PAGE_SIZE; |
| 2568 | list = (u64 *)qedf->bdq_pbl_list; |
| 2569 | page = qedf->bdq_pbl_list_dma; |
| 2570 | for (i = 0; i < qedf->bdq_pbl_list_num_entries; i++) { |
| 2571 | *list = qedf->bdq_pbl_dma; |
| 2572 | list++; |
| 2573 | page += QEDF_PAGE_SIZE; |
| 2574 | } |
| 2575 | |
| 2576 | return 0; |
| 2577 | } |
| 2578 | |
| 2579 | static int qedf_alloc_global_queues(struct qedf_ctx *qedf) |
| 2580 | { |
| 2581 | u32 *list; |
| 2582 | int i; |
| 2583 | int status = 0, rc; |
| 2584 | u32 *pbl; |
| 2585 | dma_addr_t page; |
| 2586 | int num_pages; |
| 2587 | |
| 2588 | /* Allocate and map CQs, RQs */ |
| 2589 | /* |
| 2590 | * Number of global queues (CQ / RQ). This should |
| 2591 | * be <= number of available MSIX vectors for the PF |
| 2592 | */ |
| 2593 | if (!qedf->num_queues) { |
| 2594 | QEDF_ERR(&(qedf->dbg_ctx), "No MSI-X vectors available!\n"); |
| 2595 | return 1; |
| 2596 | } |
| 2597 | |
| 2598 | /* |
| 2599 | * Make sure we allocated the PBL that will contain the physical |
| 2600 | * addresses of our queues |
| 2601 | */ |
| 2602 | if (!qedf->p_cpuq) { |
| 2603 | status = 1; |
| 2604 | goto mem_alloc_failure; |
| 2605 | } |
| 2606 | |
| 2607 | qedf->global_queues = kzalloc((sizeof(struct global_queue *) |
| 2608 | * qedf->num_queues), GFP_KERNEL); |
| 2609 | if (!qedf->global_queues) { |
| 2610 | QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate global " |
| 2611 | "queues array ptr memory\n"); |
| 2612 | return -ENOMEM; |
| 2613 | } |
| 2614 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 2615 | "qedf->global_queues=%p.\n", qedf->global_queues); |
| 2616 | |
| 2617 | /* Allocate DMA coherent buffers for BDQ */ |
| 2618 | rc = qedf_alloc_bdq(qedf); |
| 2619 | if (rc) |
| 2620 | goto mem_alloc_failure; |
| 2621 | |
| 2622 | /* Allocate a CQ and an associated PBL for each MSI-X vector */ |
| 2623 | for (i = 0; i < qedf->num_queues; i++) { |
| 2624 | qedf->global_queues[i] = kzalloc(sizeof(struct global_queue), |
| 2625 | GFP_KERNEL); |
| 2626 | if (!qedf->global_queues[i]) { |
| 2627 | QEDF_WARN(&(qedf->dbg_ctx), "Unable to allocation " |
| 2628 | "global queue %d.\n", i); |
| 2629 | goto mem_alloc_failure; |
| 2630 | } |
| 2631 | |
| 2632 | qedf->global_queues[i]->cq_mem_size = |
| 2633 | FCOE_PARAMS_CQ_NUM_ENTRIES * sizeof(struct fcoe_cqe); |
| 2634 | qedf->global_queues[i]->cq_mem_size = |
| 2635 | ALIGN(qedf->global_queues[i]->cq_mem_size, QEDF_PAGE_SIZE); |
| 2636 | |
| 2637 | qedf->global_queues[i]->cq_pbl_size = |
| 2638 | (qedf->global_queues[i]->cq_mem_size / |
| 2639 | PAGE_SIZE) * sizeof(void *); |
| 2640 | qedf->global_queues[i]->cq_pbl_size = |
| 2641 | ALIGN(qedf->global_queues[i]->cq_pbl_size, QEDF_PAGE_SIZE); |
| 2642 | |
| 2643 | qedf->global_queues[i]->cq = |
| 2644 | dma_alloc_coherent(&qedf->pdev->dev, |
| 2645 | qedf->global_queues[i]->cq_mem_size, |
| 2646 | &qedf->global_queues[i]->cq_dma, GFP_KERNEL); |
| 2647 | |
| 2648 | if (!qedf->global_queues[i]->cq) { |
| 2649 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate " |
| 2650 | "cq.\n"); |
| 2651 | status = -ENOMEM; |
| 2652 | goto mem_alloc_failure; |
| 2653 | } |
| 2654 | memset(qedf->global_queues[i]->cq, 0, |
| 2655 | qedf->global_queues[i]->cq_mem_size); |
| 2656 | |
| 2657 | qedf->global_queues[i]->cq_pbl = |
| 2658 | dma_alloc_coherent(&qedf->pdev->dev, |
| 2659 | qedf->global_queues[i]->cq_pbl_size, |
| 2660 | &qedf->global_queues[i]->cq_pbl_dma, GFP_KERNEL); |
| 2661 | |
| 2662 | if (!qedf->global_queues[i]->cq_pbl) { |
| 2663 | QEDF_WARN(&(qedf->dbg_ctx), "Could not allocate " |
| 2664 | "cq PBL.\n"); |
| 2665 | status = -ENOMEM; |
| 2666 | goto mem_alloc_failure; |
| 2667 | } |
| 2668 | memset(qedf->global_queues[i]->cq_pbl, 0, |
| 2669 | qedf->global_queues[i]->cq_pbl_size); |
| 2670 | |
| 2671 | /* Create PBL */ |
| 2672 | num_pages = qedf->global_queues[i]->cq_mem_size / |
| 2673 | QEDF_PAGE_SIZE; |
| 2674 | page = qedf->global_queues[i]->cq_dma; |
| 2675 | pbl = (u32 *)qedf->global_queues[i]->cq_pbl; |
| 2676 | |
| 2677 | while (num_pages--) { |
| 2678 | *pbl = U64_LO(page); |
| 2679 | pbl++; |
| 2680 | *pbl = U64_HI(page); |
| 2681 | pbl++; |
| 2682 | page += QEDF_PAGE_SIZE; |
| 2683 | } |
| 2684 | /* Set the initial consumer index for cq */ |
| 2685 | qedf->global_queues[i]->cq_cons_idx = 0; |
| 2686 | } |
| 2687 | |
| 2688 | list = (u32 *)qedf->p_cpuq; |
| 2689 | |
| 2690 | /* |
| 2691 | * The list is built as follows: CQ#0 PBL pointer, RQ#0 PBL pointer, |
| 2692 | * CQ#1 PBL pointer, RQ#1 PBL pointer, etc. Each PBL pointer points |
| 2693 | * to the physical address which contains an array of pointers to |
| 2694 | * the physical addresses of the specific queue pages. |
| 2695 | */ |
| 2696 | for (i = 0; i < qedf->num_queues; i++) { |
| 2697 | *list = U64_LO(qedf->global_queues[i]->cq_pbl_dma); |
| 2698 | list++; |
| 2699 | *list = U64_HI(qedf->global_queues[i]->cq_pbl_dma); |
| 2700 | list++; |
| 2701 | *list = U64_LO(0); |
| 2702 | list++; |
| 2703 | *list = U64_HI(0); |
| 2704 | list++; |
| 2705 | } |
| 2706 | |
| 2707 | return 0; |
| 2708 | |
| 2709 | mem_alloc_failure: |
| 2710 | qedf_free_global_queues(qedf); |
| 2711 | return status; |
| 2712 | } |
| 2713 | |
| 2714 | static int qedf_set_fcoe_pf_param(struct qedf_ctx *qedf) |
| 2715 | { |
| 2716 | u8 sq_num_pbl_pages; |
| 2717 | u32 sq_mem_size; |
| 2718 | u32 cq_mem_size; |
| 2719 | u32 cq_num_entries; |
| 2720 | int rval; |
| 2721 | |
| 2722 | /* |
| 2723 | * The number of completion queues/fastpath interrupts/status blocks |
| 2724 | * we allocation is the minimum off: |
| 2725 | * |
| 2726 | * Number of CPUs |
| 2727 | * Number of MSI-X vectors |
| 2728 | * Max number allocated in hardware (QEDF_MAX_NUM_CQS) |
| 2729 | */ |
| 2730 | qedf->num_queues = min((unsigned int)QEDF_MAX_NUM_CQS, |
| 2731 | num_online_cpus()); |
| 2732 | |
| 2733 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Number of CQs is %d.\n", |
| 2734 | qedf->num_queues); |
| 2735 | |
| 2736 | qedf->p_cpuq = pci_alloc_consistent(qedf->pdev, |
| 2737 | qedf->num_queues * sizeof(struct qedf_glbl_q_params), |
| 2738 | &qedf->hw_p_cpuq); |
| 2739 | |
| 2740 | if (!qedf->p_cpuq) { |
| 2741 | QEDF_ERR(&(qedf->dbg_ctx), "pci_alloc_consistent failed.\n"); |
| 2742 | return 1; |
| 2743 | } |
| 2744 | |
| 2745 | rval = qedf_alloc_global_queues(qedf); |
| 2746 | if (rval) { |
| 2747 | QEDF_ERR(&(qedf->dbg_ctx), "Global queue allocation " |
| 2748 | "failed.\n"); |
| 2749 | return 1; |
| 2750 | } |
| 2751 | |
| 2752 | /* Calculate SQ PBL size in the same manner as in qedf_sq_alloc() */ |
| 2753 | sq_mem_size = SQ_NUM_ENTRIES * sizeof(struct fcoe_wqe); |
| 2754 | sq_mem_size = ALIGN(sq_mem_size, QEDF_PAGE_SIZE); |
| 2755 | sq_num_pbl_pages = (sq_mem_size / QEDF_PAGE_SIZE); |
| 2756 | |
| 2757 | /* Calculate CQ num entries */ |
| 2758 | cq_mem_size = FCOE_PARAMS_CQ_NUM_ENTRIES * sizeof(struct fcoe_cqe); |
| 2759 | cq_mem_size = ALIGN(cq_mem_size, QEDF_PAGE_SIZE); |
| 2760 | cq_num_entries = cq_mem_size / sizeof(struct fcoe_cqe); |
| 2761 | |
| 2762 | memset(&(qedf->pf_params), 0, |
| 2763 | sizeof(qedf->pf_params)); |
| 2764 | |
| 2765 | /* Setup the value for fcoe PF */ |
| 2766 | qedf->pf_params.fcoe_pf_params.num_cons = QEDF_MAX_SESSIONS; |
| 2767 | qedf->pf_params.fcoe_pf_params.num_tasks = FCOE_PARAMS_NUM_TASKS; |
| 2768 | qedf->pf_params.fcoe_pf_params.glbl_q_params_addr = |
| 2769 | (u64)qedf->hw_p_cpuq; |
| 2770 | qedf->pf_params.fcoe_pf_params.sq_num_pbl_pages = sq_num_pbl_pages; |
| 2771 | |
| 2772 | qedf->pf_params.fcoe_pf_params.rq_buffer_log_size = 0; |
| 2773 | |
| 2774 | qedf->pf_params.fcoe_pf_params.cq_num_entries = cq_num_entries; |
| 2775 | qedf->pf_params.fcoe_pf_params.num_cqs = qedf->num_queues; |
| 2776 | |
| 2777 | /* log_page_size: 12 for 4KB pages */ |
| 2778 | qedf->pf_params.fcoe_pf_params.log_page_size = ilog2(QEDF_PAGE_SIZE); |
| 2779 | |
| 2780 | qedf->pf_params.fcoe_pf_params.mtu = 9000; |
| 2781 | qedf->pf_params.fcoe_pf_params.gl_rq_pi = QEDF_FCOE_PARAMS_GL_RQ_PI; |
| 2782 | qedf->pf_params.fcoe_pf_params.gl_cmd_pi = QEDF_FCOE_PARAMS_GL_CMD_PI; |
| 2783 | |
| 2784 | /* BDQ address and size */ |
| 2785 | qedf->pf_params.fcoe_pf_params.bdq_pbl_base_addr[0] = |
| 2786 | qedf->bdq_pbl_list_dma; |
| 2787 | qedf->pf_params.fcoe_pf_params.bdq_pbl_num_entries[0] = |
| 2788 | qedf->bdq_pbl_list_num_entries; |
| 2789 | qedf->pf_params.fcoe_pf_params.rq_buffer_size = QEDF_BDQ_BUF_SIZE; |
| 2790 | |
| 2791 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 2792 | "bdq_list=%p bdq_pbl_list_dma=%llx bdq_pbl_list_entries=%d.\n", |
| 2793 | qedf->bdq_pbl_list, |
| 2794 | qedf->pf_params.fcoe_pf_params.bdq_pbl_base_addr[0], |
| 2795 | qedf->pf_params.fcoe_pf_params.bdq_pbl_num_entries[0]); |
| 2796 | |
| 2797 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 2798 | "cq_num_entries=%d.\n", |
| 2799 | qedf->pf_params.fcoe_pf_params.cq_num_entries); |
| 2800 | |
| 2801 | return 0; |
| 2802 | } |
| 2803 | |
| 2804 | /* Free DMA coherent memory for array of queue pointers we pass to qed */ |
| 2805 | static void qedf_free_fcoe_pf_param(struct qedf_ctx *qedf) |
| 2806 | { |
| 2807 | size_t size = 0; |
| 2808 | |
| 2809 | if (qedf->p_cpuq) { |
| 2810 | size = qedf->num_queues * sizeof(struct qedf_glbl_q_params); |
| 2811 | pci_free_consistent(qedf->pdev, size, qedf->p_cpuq, |
| 2812 | qedf->hw_p_cpuq); |
| 2813 | } |
| 2814 | |
| 2815 | qedf_free_global_queues(qedf); |
| 2816 | |
| 2817 | if (qedf->global_queues) |
| 2818 | kfree(qedf->global_queues); |
| 2819 | } |
| 2820 | |
| 2821 | /* |
| 2822 | * PCI driver functions |
| 2823 | */ |
| 2824 | |
| 2825 | static const struct pci_device_id qedf_pci_tbl[] = { |
| 2826 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x165c) }, |
| 2827 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x8080) }, |
| 2828 | {0} |
| 2829 | }; |
| 2830 | MODULE_DEVICE_TABLE(pci, qedf_pci_tbl); |
| 2831 | |
| 2832 | static struct pci_driver qedf_pci_driver = { |
| 2833 | .name = QEDF_MODULE_NAME, |
| 2834 | .id_table = qedf_pci_tbl, |
| 2835 | .probe = qedf_probe, |
| 2836 | .remove = qedf_remove, |
| 2837 | }; |
| 2838 | |
| 2839 | static int __qedf_probe(struct pci_dev *pdev, int mode) |
| 2840 | { |
| 2841 | int rc = -EINVAL; |
| 2842 | struct fc_lport *lport; |
| 2843 | struct qedf_ctx *qedf; |
| 2844 | struct Scsi_Host *host; |
| 2845 | bool is_vf = false; |
| 2846 | struct qed_ll2_params params; |
| 2847 | char host_buf[20]; |
| 2848 | struct qed_link_params link_params; |
| 2849 | int status; |
| 2850 | void *task_start, *task_end; |
| 2851 | struct qed_slowpath_params slowpath_params; |
| 2852 | struct qed_probe_params qed_params; |
| 2853 | u16 tmp; |
| 2854 | |
| 2855 | /* |
| 2856 | * When doing error recovery we didn't reap the lport so don't try |
| 2857 | * to reallocate it. |
| 2858 | */ |
| 2859 | if (mode != QEDF_MODE_RECOVERY) { |
| 2860 | lport = libfc_host_alloc(&qedf_host_template, |
| 2861 | sizeof(struct qedf_ctx)); |
| 2862 | |
| 2863 | if (!lport) { |
| 2864 | QEDF_ERR(NULL, "Could not allocate lport.\n"); |
| 2865 | rc = -ENOMEM; |
| 2866 | goto err0; |
| 2867 | } |
| 2868 | |
| 2869 | /* Initialize qedf_ctx */ |
| 2870 | qedf = lport_priv(lport); |
| 2871 | qedf->lport = lport; |
| 2872 | qedf->ctlr.lp = lport; |
| 2873 | qedf->pdev = pdev; |
| 2874 | qedf->dbg_ctx.pdev = pdev; |
| 2875 | qedf->dbg_ctx.host_no = lport->host->host_no; |
| 2876 | spin_lock_init(&qedf->hba_lock); |
| 2877 | INIT_LIST_HEAD(&qedf->fcports); |
| 2878 | qedf->curr_conn_id = QEDF_MAX_SESSIONS - 1; |
| 2879 | atomic_set(&qedf->num_offloads, 0); |
| 2880 | qedf->stop_io_on_error = false; |
| 2881 | pci_set_drvdata(pdev, qedf); |
Chad Dupuis | 8eaf7df | 2017-03-23 06:58:47 -0700 | [diff] [blame] | 2882 | init_completion(&qedf->fipvlan_compl); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 2883 | |
| 2884 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_INFO, |
| 2885 | "QLogic FastLinQ FCoE Module qedf %s, " |
| 2886 | "FW %d.%d.%d.%d\n", QEDF_VERSION, |
| 2887 | FW_MAJOR_VERSION, FW_MINOR_VERSION, FW_REVISION_VERSION, |
| 2888 | FW_ENGINEERING_VERSION); |
| 2889 | } else { |
| 2890 | /* Init pointers during recovery */ |
| 2891 | qedf = pci_get_drvdata(pdev); |
| 2892 | lport = qedf->lport; |
| 2893 | } |
| 2894 | |
| 2895 | host = lport->host; |
| 2896 | |
| 2897 | /* Allocate mempool for qedf_io_work structs */ |
| 2898 | qedf->io_mempool = mempool_create_slab_pool(QEDF_IO_WORK_MIN, |
| 2899 | qedf_io_work_cache); |
| 2900 | if (qedf->io_mempool == NULL) { |
| 2901 | QEDF_ERR(&(qedf->dbg_ctx), "qedf->io_mempool is NULL.\n"); |
| 2902 | goto err1; |
| 2903 | } |
| 2904 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_INFO, "qedf->io_mempool=%p.\n", |
| 2905 | qedf->io_mempool); |
| 2906 | |
| 2907 | sprintf(host_buf, "qedf_%u_link", |
| 2908 | qedf->lport->host->host_no); |
| 2909 | qedf->link_update_wq = create_singlethread_workqueue(host_buf); |
| 2910 | INIT_DELAYED_WORK(&qedf->link_update, qedf_handle_link_update); |
| 2911 | INIT_DELAYED_WORK(&qedf->link_recovery, qedf_link_recovery); |
| 2912 | |
| 2913 | qedf->fipvlan_retries = qedf_fipvlan_retries; |
| 2914 | |
| 2915 | /* |
| 2916 | * Common probe. Takes care of basic hardware init and pci_* |
| 2917 | * functions. |
| 2918 | */ |
| 2919 | memset(&qed_params, 0, sizeof(qed_params)); |
| 2920 | qed_params.protocol = QED_PROTOCOL_FCOE; |
| 2921 | qed_params.dp_module = qedf_dp_module; |
| 2922 | qed_params.dp_level = qedf_dp_level; |
| 2923 | qed_params.is_vf = is_vf; |
| 2924 | qedf->cdev = qed_ops->common->probe(pdev, &qed_params); |
| 2925 | if (!qedf->cdev) { |
| 2926 | rc = -ENODEV; |
| 2927 | goto err1; |
| 2928 | } |
| 2929 | |
| 2930 | /* queue allocation code should come here |
| 2931 | * order should be |
| 2932 | * slowpath_start |
| 2933 | * status block allocation |
| 2934 | * interrupt registration (to get min number of queues) |
| 2935 | * set_fcoe_pf_param |
| 2936 | * qed_sp_fcoe_func_start |
| 2937 | */ |
| 2938 | rc = qedf_set_fcoe_pf_param(qedf); |
| 2939 | if (rc) { |
| 2940 | QEDF_ERR(&(qedf->dbg_ctx), "Cannot set fcoe pf param.\n"); |
| 2941 | goto err2; |
| 2942 | } |
| 2943 | qed_ops->common->update_pf_params(qedf->cdev, &qedf->pf_params); |
| 2944 | |
| 2945 | /* Learn information crucial for qedf to progress */ |
| 2946 | rc = qed_ops->fill_dev_info(qedf->cdev, &qedf->dev_info); |
| 2947 | if (rc) { |
| 2948 | QEDF_ERR(&(qedf->dbg_ctx), "Failed to dev info.\n"); |
| 2949 | goto err1; |
| 2950 | } |
| 2951 | |
| 2952 | /* Record BDQ producer doorbell addresses */ |
| 2953 | qedf->bdq_primary_prod = qedf->dev_info.primary_dbq_rq_addr; |
| 2954 | qedf->bdq_secondary_prod = qedf->dev_info.secondary_bdq_rq_addr; |
| 2955 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 2956 | "BDQ primary_prod=%p secondary_prod=%p.\n", qedf->bdq_primary_prod, |
| 2957 | qedf->bdq_secondary_prod); |
| 2958 | |
| 2959 | qed_ops->register_ops(qedf->cdev, &qedf_cb_ops, qedf); |
| 2960 | |
| 2961 | rc = qedf_prepare_sb(qedf); |
| 2962 | if (rc) { |
| 2963 | |
| 2964 | QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n"); |
| 2965 | goto err2; |
| 2966 | } |
| 2967 | |
| 2968 | /* Start the Slowpath-process */ |
| 2969 | slowpath_params.int_mode = QED_INT_MODE_MSIX; |
| 2970 | slowpath_params.drv_major = QEDF_DRIVER_MAJOR_VER; |
| 2971 | slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER; |
| 2972 | slowpath_params.drv_rev = QEDF_DRIVER_REV_VER; |
| 2973 | slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER; |
Kees Cook | cd22874 | 2017-05-05 15:42:55 -0700 | [diff] [blame] | 2974 | strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE); |
Dupuis, Chad | 61d8658 | 2017-02-15 06:28:23 -0800 | [diff] [blame] | 2975 | rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params); |
| 2976 | if (rc) { |
| 2977 | QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n"); |
| 2978 | goto err2; |
| 2979 | } |
| 2980 | |
| 2981 | /* |
| 2982 | * update_pf_params needs to be called before and after slowpath |
| 2983 | * start |
| 2984 | */ |
| 2985 | qed_ops->common->update_pf_params(qedf->cdev, &qedf->pf_params); |
| 2986 | |
| 2987 | /* Setup interrupts */ |
| 2988 | rc = qedf_setup_int(qedf); |
| 2989 | if (rc) |
| 2990 | goto err3; |
| 2991 | |
| 2992 | rc = qed_ops->start(qedf->cdev, &qedf->tasks); |
| 2993 | if (rc) { |
| 2994 | QEDF_ERR(&(qedf->dbg_ctx), "Cannot start FCoE function.\n"); |
| 2995 | goto err4; |
| 2996 | } |
| 2997 | task_start = qedf_get_task_mem(&qedf->tasks, 0); |
| 2998 | task_end = qedf_get_task_mem(&qedf->tasks, MAX_TID_BLOCKS_FCOE - 1); |
| 2999 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Task context start=%p, " |
| 3000 | "end=%p block_size=%u.\n", task_start, task_end, |
| 3001 | qedf->tasks.size); |
| 3002 | |
| 3003 | /* |
| 3004 | * We need to write the number of BDs in the BDQ we've preallocated so |
| 3005 | * the f/w will do a prefetch and we'll get an unsolicited CQE when a |
| 3006 | * packet arrives. |
| 3007 | */ |
| 3008 | qedf->bdq_prod_idx = QEDF_BDQ_SIZE; |
| 3009 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 3010 | "Writing %d to primary and secondary BDQ doorbell registers.\n", |
| 3011 | qedf->bdq_prod_idx); |
| 3012 | writew(qedf->bdq_prod_idx, qedf->bdq_primary_prod); |
| 3013 | tmp = readw(qedf->bdq_primary_prod); |
| 3014 | writew(qedf->bdq_prod_idx, qedf->bdq_secondary_prod); |
| 3015 | tmp = readw(qedf->bdq_secondary_prod); |
| 3016 | |
| 3017 | qed_ops->common->set_power_state(qedf->cdev, PCI_D0); |
| 3018 | |
| 3019 | /* Now that the dev_info struct has been filled in set the MAC |
| 3020 | * address |
| 3021 | */ |
| 3022 | ether_addr_copy(qedf->mac, qedf->dev_info.common.hw_mac); |
| 3023 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "MAC address is %pM.\n", |
| 3024 | qedf->mac); |
| 3025 | |
| 3026 | /* Set the WWNN and WWPN based on the MAC address */ |
| 3027 | qedf->wwnn = fcoe_wwn_from_mac(qedf->mac, 1, 0); |
| 3028 | qedf->wwpn = fcoe_wwn_from_mac(qedf->mac, 2, 0); |
| 3029 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "WWNN=%016llx " |
| 3030 | "WWPN=%016llx.\n", qedf->wwnn, qedf->wwpn); |
| 3031 | |
| 3032 | sprintf(host_buf, "host_%d", host->host_no); |
| 3033 | qed_ops->common->set_id(qedf->cdev, host_buf, QEDF_VERSION); |
| 3034 | |
| 3035 | |
| 3036 | /* Set xid max values */ |
| 3037 | qedf->max_scsi_xid = QEDF_MAX_SCSI_XID; |
| 3038 | qedf->max_els_xid = QEDF_MAX_ELS_XID; |
| 3039 | |
| 3040 | /* Allocate cmd mgr */ |
| 3041 | qedf->cmd_mgr = qedf_cmd_mgr_alloc(qedf); |
| 3042 | if (!qedf->cmd_mgr) { |
| 3043 | QEDF_ERR(&(qedf->dbg_ctx), "Failed to allocate cmd mgr.\n"); |
| 3044 | goto err5; |
| 3045 | } |
| 3046 | |
| 3047 | if (mode != QEDF_MODE_RECOVERY) { |
| 3048 | host->transportt = qedf_fc_transport_template; |
| 3049 | host->can_queue = QEDF_MAX_ELS_XID; |
| 3050 | host->max_lun = qedf_max_lun; |
| 3051 | host->max_cmd_len = QEDF_MAX_CDB_LEN; |
| 3052 | rc = scsi_add_host(host, &pdev->dev); |
| 3053 | if (rc) |
| 3054 | goto err6; |
| 3055 | } |
| 3056 | |
| 3057 | memset(¶ms, 0, sizeof(params)); |
| 3058 | params.mtu = 9000; |
| 3059 | ether_addr_copy(params.ll2_mac_address, qedf->mac); |
| 3060 | |
| 3061 | /* Start LL2 processing thread */ |
| 3062 | snprintf(host_buf, 20, "qedf_%d_ll2", host->host_no); |
| 3063 | qedf->ll2_recv_wq = |
| 3064 | create_singlethread_workqueue(host_buf); |
| 3065 | if (!qedf->ll2_recv_wq) { |
| 3066 | QEDF_ERR(&(qedf->dbg_ctx), "Failed to LL2 workqueue.\n"); |
| 3067 | goto err7; |
| 3068 | } |
| 3069 | |
| 3070 | #ifdef CONFIG_DEBUG_FS |
| 3071 | qedf_dbg_host_init(&(qedf->dbg_ctx), &qedf_debugfs_ops, |
| 3072 | &qedf_dbg_fops); |
| 3073 | #endif |
| 3074 | |
| 3075 | /* Start LL2 */ |
| 3076 | qed_ops->ll2->register_cb_ops(qedf->cdev, &qedf_ll2_cb_ops, qedf); |
| 3077 | rc = qed_ops->ll2->start(qedf->cdev, ¶ms); |
| 3078 | if (rc) { |
| 3079 | QEDF_ERR(&(qedf->dbg_ctx), "Could not start Light L2.\n"); |
| 3080 | goto err7; |
| 3081 | } |
| 3082 | set_bit(QEDF_LL2_STARTED, &qedf->flags); |
| 3083 | |
| 3084 | /* hw will be insterting vlan tag*/ |
| 3085 | qedf->vlan_hw_insert = 1; |
| 3086 | qedf->vlan_id = 0; |
| 3087 | |
| 3088 | /* |
| 3089 | * No need to setup fcoe_ctlr or fc_lport objects during recovery since |
| 3090 | * they were not reaped during the unload process. |
| 3091 | */ |
| 3092 | if (mode != QEDF_MODE_RECOVERY) { |
| 3093 | /* Setup imbedded fcoe controller */ |
| 3094 | qedf_fcoe_ctlr_setup(qedf); |
| 3095 | |
| 3096 | /* Setup lport */ |
| 3097 | rc = qedf_lport_setup(qedf); |
| 3098 | if (rc) { |
| 3099 | QEDF_ERR(&(qedf->dbg_ctx), |
| 3100 | "qedf_lport_setup failed.\n"); |
| 3101 | goto err7; |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | sprintf(host_buf, "qedf_%u_timer", qedf->lport->host->host_no); |
| 3106 | qedf->timer_work_queue = |
| 3107 | create_singlethread_workqueue(host_buf); |
| 3108 | if (!qedf->timer_work_queue) { |
| 3109 | QEDF_ERR(&(qedf->dbg_ctx), "Failed to start timer " |
| 3110 | "workqueue.\n"); |
| 3111 | goto err7; |
| 3112 | } |
| 3113 | |
| 3114 | /* DPC workqueue is not reaped during recovery unload */ |
| 3115 | if (mode != QEDF_MODE_RECOVERY) { |
| 3116 | sprintf(host_buf, "qedf_%u_dpc", |
| 3117 | qedf->lport->host->host_no); |
| 3118 | qedf->dpc_wq = create_singlethread_workqueue(host_buf); |
| 3119 | } |
| 3120 | |
| 3121 | /* |
| 3122 | * GRC dump and sysfs parameters are not reaped during the recovery |
| 3123 | * unload process. |
| 3124 | */ |
| 3125 | if (mode != QEDF_MODE_RECOVERY) { |
| 3126 | qedf->grcdump_size = qed_ops->common->dbg_grc_size(qedf->cdev); |
| 3127 | if (qedf->grcdump_size) { |
| 3128 | rc = qedf_alloc_grc_dump_buf(&qedf->grcdump, |
| 3129 | qedf->grcdump_size); |
| 3130 | if (rc) { |
| 3131 | QEDF_ERR(&(qedf->dbg_ctx), |
| 3132 | "GRC Dump buffer alloc failed.\n"); |
| 3133 | qedf->grcdump = NULL; |
| 3134 | } |
| 3135 | |
| 3136 | QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, |
| 3137 | "grcdump: addr=%p, size=%u.\n", |
| 3138 | qedf->grcdump, qedf->grcdump_size); |
| 3139 | } |
| 3140 | qedf_create_sysfs_ctx_attr(qedf); |
| 3141 | |
| 3142 | /* Initialize I/O tracing for this adapter */ |
| 3143 | spin_lock_init(&qedf->io_trace_lock); |
| 3144 | qedf->io_trace_idx = 0; |
| 3145 | } |
| 3146 | |
| 3147 | init_completion(&qedf->flogi_compl); |
| 3148 | |
| 3149 | memset(&link_params, 0, sizeof(struct qed_link_params)); |
| 3150 | link_params.link_up = true; |
| 3151 | status = qed_ops->common->set_link(qedf->cdev, &link_params); |
| 3152 | if (status) |
| 3153 | QEDF_WARN(&(qedf->dbg_ctx), "set_link failed.\n"); |
| 3154 | |
| 3155 | /* Start/restart discovery */ |
| 3156 | if (mode == QEDF_MODE_RECOVERY) |
| 3157 | fcoe_ctlr_link_up(&qedf->ctlr); |
| 3158 | else |
| 3159 | fc_fabric_login(lport); |
| 3160 | |
| 3161 | /* All good */ |
| 3162 | return 0; |
| 3163 | |
| 3164 | err7: |
| 3165 | if (qedf->ll2_recv_wq) |
| 3166 | destroy_workqueue(qedf->ll2_recv_wq); |
| 3167 | fc_remove_host(qedf->lport->host); |
| 3168 | scsi_remove_host(qedf->lport->host); |
| 3169 | #ifdef CONFIG_DEBUG_FS |
| 3170 | qedf_dbg_host_exit(&(qedf->dbg_ctx)); |
| 3171 | #endif |
| 3172 | err6: |
| 3173 | qedf_cmd_mgr_free(qedf->cmd_mgr); |
| 3174 | err5: |
| 3175 | qed_ops->stop(qedf->cdev); |
| 3176 | err4: |
| 3177 | qedf_free_fcoe_pf_param(qedf); |
| 3178 | qedf_sync_free_irqs(qedf); |
| 3179 | err3: |
| 3180 | qed_ops->common->slowpath_stop(qedf->cdev); |
| 3181 | err2: |
| 3182 | qed_ops->common->remove(qedf->cdev); |
| 3183 | err1: |
| 3184 | scsi_host_put(lport->host); |
| 3185 | err0: |
| 3186 | return rc; |
| 3187 | } |
| 3188 | |
| 3189 | static int qedf_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 3190 | { |
| 3191 | return __qedf_probe(pdev, QEDF_MODE_NORMAL); |
| 3192 | } |
| 3193 | |
| 3194 | static void __qedf_remove(struct pci_dev *pdev, int mode) |
| 3195 | { |
| 3196 | struct qedf_ctx *qedf; |
| 3197 | |
| 3198 | if (!pdev) { |
| 3199 | QEDF_ERR(NULL, "pdev is NULL.\n"); |
| 3200 | return; |
| 3201 | } |
| 3202 | |
| 3203 | qedf = pci_get_drvdata(pdev); |
| 3204 | |
| 3205 | /* |
| 3206 | * Prevent race where we're in board disable work and then try to |
| 3207 | * rmmod the module. |
| 3208 | */ |
| 3209 | if (test_bit(QEDF_UNLOADING, &qedf->flags)) { |
| 3210 | QEDF_ERR(&qedf->dbg_ctx, "Already removing PCI function.\n"); |
| 3211 | return; |
| 3212 | } |
| 3213 | |
| 3214 | if (mode != QEDF_MODE_RECOVERY) |
| 3215 | set_bit(QEDF_UNLOADING, &qedf->flags); |
| 3216 | |
| 3217 | /* Logoff the fabric to upload all connections */ |
| 3218 | if (mode == QEDF_MODE_RECOVERY) |
| 3219 | fcoe_ctlr_link_down(&qedf->ctlr); |
| 3220 | else |
| 3221 | fc_fabric_logoff(qedf->lport); |
| 3222 | qedf_wait_for_upload(qedf); |
| 3223 | |
| 3224 | #ifdef CONFIG_DEBUG_FS |
| 3225 | qedf_dbg_host_exit(&(qedf->dbg_ctx)); |
| 3226 | #endif |
| 3227 | |
| 3228 | /* Stop any link update handling */ |
| 3229 | cancel_delayed_work_sync(&qedf->link_update); |
| 3230 | destroy_workqueue(qedf->link_update_wq); |
| 3231 | qedf->link_update_wq = NULL; |
| 3232 | |
| 3233 | if (qedf->timer_work_queue) |
| 3234 | destroy_workqueue(qedf->timer_work_queue); |
| 3235 | |
| 3236 | /* Stop Light L2 */ |
| 3237 | clear_bit(QEDF_LL2_STARTED, &qedf->flags); |
| 3238 | qed_ops->ll2->stop(qedf->cdev); |
| 3239 | if (qedf->ll2_recv_wq) |
| 3240 | destroy_workqueue(qedf->ll2_recv_wq); |
| 3241 | |
| 3242 | /* Stop fastpath */ |
| 3243 | qedf_sync_free_irqs(qedf); |
| 3244 | qedf_destroy_sb(qedf); |
| 3245 | |
| 3246 | /* |
| 3247 | * During recovery don't destroy OS constructs that represent the |
| 3248 | * physical port. |
| 3249 | */ |
| 3250 | if (mode != QEDF_MODE_RECOVERY) { |
| 3251 | qedf_free_grc_dump_buf(&qedf->grcdump); |
| 3252 | qedf_remove_sysfs_ctx_attr(qedf); |
| 3253 | |
| 3254 | /* Remove all SCSI/libfc/libfcoe structures */ |
| 3255 | fcoe_ctlr_destroy(&qedf->ctlr); |
| 3256 | fc_lport_destroy(qedf->lport); |
| 3257 | fc_remove_host(qedf->lport->host); |
| 3258 | scsi_remove_host(qedf->lport->host); |
| 3259 | } |
| 3260 | |
| 3261 | qedf_cmd_mgr_free(qedf->cmd_mgr); |
| 3262 | |
| 3263 | if (mode != QEDF_MODE_RECOVERY) { |
| 3264 | fc_exch_mgr_free(qedf->lport); |
| 3265 | fc_lport_free_stats(qedf->lport); |
| 3266 | |
| 3267 | /* Wait for all vports to be reaped */ |
| 3268 | qedf_wait_for_vport_destroy(qedf); |
| 3269 | } |
| 3270 | |
| 3271 | /* |
| 3272 | * Now that all connections have been uploaded we can stop the |
| 3273 | * rest of the qed operations |
| 3274 | */ |
| 3275 | qed_ops->stop(qedf->cdev); |
| 3276 | |
| 3277 | if (mode != QEDF_MODE_RECOVERY) { |
| 3278 | if (qedf->dpc_wq) { |
| 3279 | /* Stop general DPC handling */ |
| 3280 | destroy_workqueue(qedf->dpc_wq); |
| 3281 | qedf->dpc_wq = NULL; |
| 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | /* Final shutdown for the board */ |
| 3286 | qedf_free_fcoe_pf_param(qedf); |
| 3287 | if (mode != QEDF_MODE_RECOVERY) { |
| 3288 | qed_ops->common->set_power_state(qedf->cdev, PCI_D0); |
| 3289 | pci_set_drvdata(pdev, NULL); |
| 3290 | } |
| 3291 | qed_ops->common->slowpath_stop(qedf->cdev); |
| 3292 | qed_ops->common->remove(qedf->cdev); |
| 3293 | |
| 3294 | mempool_destroy(qedf->io_mempool); |
| 3295 | |
| 3296 | /* Only reap the Scsi_host on a real removal */ |
| 3297 | if (mode != QEDF_MODE_RECOVERY) |
| 3298 | scsi_host_put(qedf->lport->host); |
| 3299 | } |
| 3300 | |
| 3301 | static void qedf_remove(struct pci_dev *pdev) |
| 3302 | { |
| 3303 | /* Check to make sure this function wasn't already disabled */ |
| 3304 | if (!atomic_read(&pdev->enable_cnt)) |
| 3305 | return; |
| 3306 | |
| 3307 | __qedf_remove(pdev, QEDF_MODE_NORMAL); |
| 3308 | } |
| 3309 | |
| 3310 | /* |
| 3311 | * Module Init/Remove |
| 3312 | */ |
| 3313 | |
| 3314 | static int __init qedf_init(void) |
| 3315 | { |
| 3316 | int ret; |
| 3317 | |
| 3318 | /* If debug=1 passed, set the default log mask */ |
| 3319 | if (qedf_debug == QEDF_LOG_DEFAULT) |
| 3320 | qedf_debug = QEDF_DEFAULT_LOG_MASK; |
| 3321 | |
| 3322 | /* Print driver banner */ |
| 3323 | QEDF_INFO(NULL, QEDF_LOG_INFO, "%s v%s.\n", QEDF_DESCR, |
| 3324 | QEDF_VERSION); |
| 3325 | |
| 3326 | /* Create kmem_cache for qedf_io_work structs */ |
| 3327 | qedf_io_work_cache = kmem_cache_create("qedf_io_work_cache", |
| 3328 | sizeof(struct qedf_io_work), 0, SLAB_HWCACHE_ALIGN, NULL); |
| 3329 | if (qedf_io_work_cache == NULL) { |
| 3330 | QEDF_ERR(NULL, "qedf_io_work_cache is NULL.\n"); |
| 3331 | goto err1; |
| 3332 | } |
| 3333 | QEDF_INFO(NULL, QEDF_LOG_DISC, "qedf_io_work_cache=%p.\n", |
| 3334 | qedf_io_work_cache); |
| 3335 | |
| 3336 | qed_ops = qed_get_fcoe_ops(); |
| 3337 | if (!qed_ops) { |
| 3338 | QEDF_ERR(NULL, "Failed to get qed fcoe operations\n"); |
| 3339 | goto err1; |
| 3340 | } |
| 3341 | |
| 3342 | #ifdef CONFIG_DEBUG_FS |
| 3343 | qedf_dbg_init("qedf"); |
| 3344 | #endif |
| 3345 | |
| 3346 | qedf_fc_transport_template = |
| 3347 | fc_attach_transport(&qedf_fc_transport_fn); |
| 3348 | if (!qedf_fc_transport_template) { |
| 3349 | QEDF_ERR(NULL, "Could not register with FC transport\n"); |
| 3350 | goto err2; |
| 3351 | } |
| 3352 | |
| 3353 | qedf_fc_vport_transport_template = |
| 3354 | fc_attach_transport(&qedf_fc_vport_transport_fn); |
| 3355 | if (!qedf_fc_vport_transport_template) { |
| 3356 | QEDF_ERR(NULL, "Could not register vport template with FC " |
| 3357 | "transport\n"); |
| 3358 | goto err3; |
| 3359 | } |
| 3360 | |
| 3361 | qedf_io_wq = create_workqueue("qedf_io_wq"); |
| 3362 | if (!qedf_io_wq) { |
| 3363 | QEDF_ERR(NULL, "Could not create qedf_io_wq.\n"); |
| 3364 | goto err4; |
| 3365 | } |
| 3366 | |
| 3367 | qedf_cb_ops.get_login_failures = qedf_get_login_failures; |
| 3368 | |
| 3369 | ret = pci_register_driver(&qedf_pci_driver); |
| 3370 | if (ret) { |
| 3371 | QEDF_ERR(NULL, "Failed to register driver\n"); |
| 3372 | goto err5; |
| 3373 | } |
| 3374 | |
| 3375 | return 0; |
| 3376 | |
| 3377 | err5: |
| 3378 | destroy_workqueue(qedf_io_wq); |
| 3379 | err4: |
| 3380 | fc_release_transport(qedf_fc_vport_transport_template); |
| 3381 | err3: |
| 3382 | fc_release_transport(qedf_fc_transport_template); |
| 3383 | err2: |
| 3384 | #ifdef CONFIG_DEBUG_FS |
| 3385 | qedf_dbg_exit(); |
| 3386 | #endif |
| 3387 | qed_put_fcoe_ops(); |
| 3388 | err1: |
| 3389 | return -EINVAL; |
| 3390 | } |
| 3391 | |
| 3392 | static void __exit qedf_cleanup(void) |
| 3393 | { |
| 3394 | pci_unregister_driver(&qedf_pci_driver); |
| 3395 | |
| 3396 | destroy_workqueue(qedf_io_wq); |
| 3397 | |
| 3398 | fc_release_transport(qedf_fc_vport_transport_template); |
| 3399 | fc_release_transport(qedf_fc_transport_template); |
| 3400 | #ifdef CONFIG_DEBUG_FS |
| 3401 | qedf_dbg_exit(); |
| 3402 | #endif |
| 3403 | qed_put_fcoe_ops(); |
| 3404 | |
| 3405 | kmem_cache_destroy(qedf_io_work_cache); |
| 3406 | } |
| 3407 | |
| 3408 | MODULE_LICENSE("GPL"); |
| 3409 | MODULE_DESCRIPTION("QLogic QEDF 25/40/50/100Gb FCoE Driver"); |
| 3410 | MODULE_AUTHOR("QLogic Corporation"); |
| 3411 | MODULE_VERSION(QEDF_VERSION); |
| 3412 | module_init(qedf_init); |
| 3413 | module_exit(qedf_cleanup); |