2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016 Cavium Inc.
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
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>
26 const struct qed_fcoe_ops
*qed_ops
;
28 static int qedf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
);
29 static void qedf_remove(struct pci_dev
*pdev
);
31 extern struct qedf_debugfs_ops qedf_debugfs_ops
;
32 extern struct file_operations qedf_dbg_fops
;
35 * Driver module parameters.
37 static unsigned int qedf_dev_loss_tmo
= 60;
38 module_param_named(dev_loss_tmo
, qedf_dev_loss_tmo
, int, S_IRUGO
);
39 MODULE_PARM_DESC(dev_loss_tmo
, " dev_loss_tmo setting for attached "
40 "remote ports (default 60)");
42 uint qedf_debug
= QEDF_LOG_INFO
;
43 module_param_named(debug
, qedf_debug
, uint
, S_IRUGO
);
44 MODULE_PARM_DESC(qedf_debug
, " Debug mask. Pass '1' to enable default debugging"
47 static uint qedf_fipvlan_retries
= 30;
48 module_param_named(fipvlan_retries
, qedf_fipvlan_retries
, int, S_IRUGO
);
49 MODULE_PARM_DESC(fipvlan_retries
, " Number of FIP VLAN requests to attempt "
50 "before giving up (default 30)");
52 static uint qedf_fallback_vlan
= QEDF_FALLBACK_VLAN
;
53 module_param_named(fallback_vlan
, qedf_fallback_vlan
, int, S_IRUGO
);
54 MODULE_PARM_DESC(fallback_vlan
, " VLAN ID to try if fip vlan request fails "
57 static uint qedf_default_prio
= QEDF_DEFAULT_PRIO
;
58 module_param_named(default_prio
, qedf_default_prio
, int, S_IRUGO
);
59 MODULE_PARM_DESC(default_prio
, " Default 802.1q priority for FIP and FCoE"
60 " traffic (default 3).");
62 uint qedf_dump_frames
;
63 module_param_named(dump_frames
, qedf_dump_frames
, int, S_IRUGO
| S_IWUSR
);
64 MODULE_PARM_DESC(dump_frames
, " Print the skb data of FIP and FCoE frames "
67 static uint qedf_queue_depth
;
68 module_param_named(queue_depth
, qedf_queue_depth
, int, S_IRUGO
);
69 MODULE_PARM_DESC(queue_depth
, " Sets the queue depth for all LUNs discovered "
70 "by the qedf driver. Default is 0 (use OS default).");
73 module_param_named(io_tracing
, qedf_io_tracing
, int, S_IRUGO
| S_IWUSR
);
74 MODULE_PARM_DESC(io_tracing
, " Enable logging of SCSI requests/completions "
75 "into trace buffer. (default off).");
77 static uint qedf_max_lun
= MAX_FIBRE_LUNS
;
78 module_param_named(max_lun
, qedf_max_lun
, int, S_IRUGO
);
79 MODULE_PARM_DESC(max_lun
, " Sets the maximum luns per target that the driver "
80 "supports. (default 0xffffffff)");
82 uint qedf_link_down_tmo
;
83 module_param_named(link_down_tmo
, qedf_link_down_tmo
, int, S_IRUGO
);
84 MODULE_PARM_DESC(link_down_tmo
, " Delays informing the fcoe transport that the "
85 "link is down by N seconds.");
87 bool qedf_retry_delay
;
88 module_param_named(retry_delay
, qedf_retry_delay
, bool, S_IRUGO
| S_IWUSR
);
89 MODULE_PARM_DESC(retry_delay
, " Enable/disable handling of FCP_RSP IU retry "
90 "delay handling (default off).");
92 static uint qedf_dp_module
;
93 module_param_named(dp_module
, qedf_dp_module
, uint
, S_IRUGO
);
94 MODULE_PARM_DESC(dp_module
, " bit flags control for verbose printk passed "
95 "qed module during probe.");
97 static uint qedf_dp_level
;
98 module_param_named(dp_level
, qedf_dp_level
, uint
, S_IRUGO
);
99 MODULE_PARM_DESC(dp_level
, " printk verbosity control passed to qed module "
100 "during probe (0-3: 0 more verbose).");
102 struct workqueue_struct
*qedf_io_wq
;
104 static struct fcoe_percpu_s qedf_global
;
105 static DEFINE_SPINLOCK(qedf_global_lock
);
107 static struct kmem_cache
*qedf_io_work_cache
;
109 void qedf_set_vlan_id(struct qedf_ctx
*qedf
, int vlan_id
)
111 qedf
->vlan_id
= vlan_id
;
112 qedf
->vlan_id
|= qedf_default_prio
<< VLAN_PRIO_SHIFT
;
113 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Setting vlan_id=%04x "
114 "prio=%d.\n", vlan_id
, qedf_default_prio
);
117 /* Returns true if we have a valid vlan, false otherwise */
118 static bool qedf_initiate_fipvlan_req(struct qedf_ctx
*qedf
)
122 if (atomic_read(&qedf
->link_state
) != QEDF_LINK_UP
) {
123 QEDF_ERR(&(qedf
->dbg_ctx
), "Link not up.\n");
127 while (qedf
->fipvlan_retries
--) {
128 if (qedf
->vlan_id
> 0)
130 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
131 "Retry %d.\n", qedf
->fipvlan_retries
);
132 init_completion(&qedf
->fipvlan_compl
);
133 qedf_fcoe_send_vlan_req(qedf
);
134 rc
= wait_for_completion_timeout(&qedf
->fipvlan_compl
,
137 fcoe_ctlr_link_up(&qedf
->ctlr
);
145 static void qedf_handle_link_update(struct work_struct
*work
)
147 struct qedf_ctx
*qedf
=
148 container_of(work
, struct qedf_ctx
, link_update
.work
);
151 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Entered.\n");
153 if (atomic_read(&qedf
->link_state
) == QEDF_LINK_UP
) {
154 rc
= qedf_initiate_fipvlan_req(qedf
);
158 * If we get here then we never received a repsonse to our
159 * fip vlan request so set the vlan_id to the default and
160 * tell FCoE that the link is up
162 QEDF_WARN(&(qedf
->dbg_ctx
), "Did not receive FIP VLAN "
163 "response, falling back to default VLAN %d.\n",
165 qedf_set_vlan_id(qedf
, QEDF_FALLBACK_VLAN
);
168 * Zero out data_src_addr so we'll update it with the new
171 eth_zero_addr(qedf
->data_src_addr
);
172 fcoe_ctlr_link_up(&qedf
->ctlr
);
173 } else if (atomic_read(&qedf
->link_state
) == QEDF_LINK_DOWN
) {
175 * If we hit here and link_down_tmo_valid is still 1 it means
176 * that link_down_tmo timed out so set it to 0 to make sure any
177 * other readers have accurate state.
179 atomic_set(&qedf
->link_down_tmo_valid
, 0);
180 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
181 "Calling fcoe_ctlr_link_down().\n");
182 fcoe_ctlr_link_down(&qedf
->ctlr
);
183 qedf_wait_for_upload(qedf
);
184 /* Reset the number of FIP VLAN retries */
185 qedf
->fipvlan_retries
= qedf_fipvlan_retries
;
189 static void qedf_flogi_resp(struct fc_seq
*seq
, struct fc_frame
*fp
,
192 struct fc_exch
*exch
= fc_seq_exch(seq
);
193 struct fc_lport
*lport
= exch
->lp
;
194 struct qedf_ctx
*qedf
= lport_priv(lport
);
197 QEDF_ERR(NULL
, "qedf is NULL.\n");
202 * If ERR_PTR is set then don't try to stat anything as it will cause
203 * a crash when we access fp.
206 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_ELS
,
207 "fp has IS_ERR() set.\n");
211 /* Log stats for FLOGI reject */
212 if (fc_frame_payload_op(fp
) == ELS_LS_RJT
)
213 qedf
->flogi_failed
++;
215 /* Complete flogi_compl so we can proceed to sending ADISCs */
216 complete(&qedf
->flogi_compl
);
219 /* Report response to libfc */
220 fc_lport_flogi_resp(seq
, fp
, lport
);
223 static struct fc_seq
*qedf_elsct_send(struct fc_lport
*lport
, u32 did
,
224 struct fc_frame
*fp
, unsigned int op
,
225 void (*resp
)(struct fc_seq
*,
228 void *arg
, u32 timeout
)
230 struct qedf_ctx
*qedf
= lport_priv(lport
);
233 * Intercept FLOGI for statistic purposes. Note we use the resp
234 * callback to tell if this is really a flogi.
236 if (resp
== fc_lport_flogi_resp
) {
238 return fc_elsct_send(lport
, did
, fp
, op
, qedf_flogi_resp
,
242 return fc_elsct_send(lport
, did
, fp
, op
, resp
, arg
, timeout
);
245 int qedf_send_flogi(struct qedf_ctx
*qedf
)
247 struct fc_lport
*lport
;
252 if (!lport
->tt
.elsct_send
)
255 fp
= fc_frame_alloc(lport
, sizeof(struct fc_els_flogi
));
257 QEDF_ERR(&(qedf
->dbg_ctx
), "fc_frame_alloc failed.\n");
261 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_ELS
,
262 "Sending FLOGI to reestablish session with switch.\n");
263 lport
->tt
.elsct_send(lport
, FC_FID_FLOGI
, fp
,
264 ELS_FLOGI
, qedf_flogi_resp
, lport
, lport
->r_a_tov
);
266 init_completion(&qedf
->flogi_compl
);
271 struct qedf_tmp_rdata_item
{
272 struct fc_rport_priv
*rdata
;
273 struct list_head list
;
277 * This function is called if link_down_tmo is in use. If we get a link up and
278 * link_down_tmo has not expired then use just FLOGI/ADISC to recover our
279 * sessions with targets. Otherwise, just call fcoe_ctlr_link_up().
281 static void qedf_link_recovery(struct work_struct
*work
)
283 struct qedf_ctx
*qedf
=
284 container_of(work
, struct qedf_ctx
, link_recovery
.work
);
285 struct qedf_rport
*fcport
;
286 struct fc_rport_priv
*rdata
;
287 struct qedf_tmp_rdata_item
*rdata_item
, *tmp_rdata_item
;
291 struct list_head rdata_login_list
;
293 INIT_LIST_HEAD(&rdata_login_list
);
295 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
296 "Link down tmo did not expire.\n");
299 * Essentially reset the fcoe_ctlr here without affecting the state
300 * of the libfc structs.
302 qedf
->ctlr
.state
= FIP_ST_LINK_WAIT
;
303 fcoe_ctlr_link_down(&qedf
->ctlr
);
306 * Bring the link up before we send the fipvlan request so libfcoe
307 * can select a new fcf in parallel
309 fcoe_ctlr_link_up(&qedf
->ctlr
);
311 /* Since the link when down and up to verify which vlan we're on */
312 qedf
->fipvlan_retries
= qedf_fipvlan_retries
;
313 rc
= qedf_initiate_fipvlan_req(qedf
);
318 * We need to wait for an FCF to be selected due to the
319 * fcoe_ctlr_link_up other the FLOGI will be rejected.
321 while (retries
> 0) {
322 if (qedf
->ctlr
.sel_fcf
) {
323 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
324 "FCF reselected, proceeding with FLOGI.\n");
332 QEDF_ERR(&(qedf
->dbg_ctx
), "Exhausted retries waiting for "
337 rval
= qedf_send_flogi(qedf
);
341 /* Wait for FLOGI completion before proceeding with sending ADISCs */
342 i
= wait_for_completion_timeout(&qedf
->flogi_compl
,
343 qedf
->lport
->r_a_tov
);
345 QEDF_ERR(&(qedf
->dbg_ctx
), "FLOGI timed out.\n");
350 * Call lport->tt.rport_login which will cause libfc to send an
351 * ADISC since the rport is in state ready.
354 list_for_each_entry_rcu(fcport
, &qedf
->fcports
, peers
) {
355 rdata
= fcport
->rdata
;
358 rdata_item
= kzalloc(sizeof(struct qedf_tmp_rdata_item
),
362 if (kref_get_unless_zero(&rdata
->kref
)) {
363 rdata_item
->rdata
= rdata
;
364 list_add(&rdata_item
->list
, &rdata_login_list
);
370 * Do the fc_rport_login outside of the rcu lock so we don't take a
371 * mutex in an atomic context.
373 list_for_each_entry_safe(rdata_item
, tmp_rdata_item
, &rdata_login_list
,
375 list_del(&rdata_item
->list
);
376 fc_rport_login(rdata_item
->rdata
);
377 kref_put(&rdata_item
->rdata
->kref
, fc_rport_destroy
);
382 static void qedf_update_link_speed(struct qedf_ctx
*qedf
,
383 struct qed_link_output
*link
)
385 struct fc_lport
*lport
= qedf
->lport
;
387 lport
->link_speed
= FC_PORTSPEED_UNKNOWN
;
388 lport
->link_supported_speeds
= FC_PORTSPEED_UNKNOWN
;
390 /* Set fc_host link speed */
391 switch (link
->speed
) {
393 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
396 lport
->link_speed
= FC_PORTSPEED_25GBIT
;
399 lport
->link_speed
= FC_PORTSPEED_40GBIT
;
402 lport
->link_speed
= FC_PORTSPEED_50GBIT
;
405 lport
->link_speed
= FC_PORTSPEED_100GBIT
;
408 lport
->link_speed
= FC_PORTSPEED_UNKNOWN
;
413 * Set supported link speed by querying the supported
414 * capabilities of the link.
416 if (link
->supported_caps
& SUPPORTED_10000baseKR_Full
)
417 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
418 if (link
->supported_caps
& SUPPORTED_25000baseKR_Full
)
419 lport
->link_supported_speeds
|= FC_PORTSPEED_25GBIT
;
420 if (link
->supported_caps
& SUPPORTED_40000baseLR4_Full
)
421 lport
->link_supported_speeds
|= FC_PORTSPEED_40GBIT
;
422 if (link
->supported_caps
& SUPPORTED_50000baseKR2_Full
)
423 lport
->link_supported_speeds
|= FC_PORTSPEED_50GBIT
;
424 if (link
->supported_caps
& SUPPORTED_100000baseKR4_Full
)
425 lport
->link_supported_speeds
|= FC_PORTSPEED_100GBIT
;
426 fc_host_supported_speeds(lport
->host
) = lport
->link_supported_speeds
;
429 static void qedf_link_update(void *dev
, struct qed_link_output
*link
)
431 struct qedf_ctx
*qedf
= (struct qedf_ctx
*)dev
;
434 QEDF_ERR(&(qedf
->dbg_ctx
), "LINK UP (%d GB/s).\n",
437 /* Cancel any pending link down work */
438 cancel_delayed_work(&qedf
->link_update
);
440 atomic_set(&qedf
->link_state
, QEDF_LINK_UP
);
441 qedf_update_link_speed(qedf
, link
);
443 if (atomic_read(&qedf
->dcbx
) == QEDF_DCBX_DONE
) {
444 QEDF_ERR(&(qedf
->dbg_ctx
), "DCBx done.\n");
445 if (atomic_read(&qedf
->link_down_tmo_valid
) > 0)
446 queue_delayed_work(qedf
->link_update_wq
,
447 &qedf
->link_recovery
, 0);
449 queue_delayed_work(qedf
->link_update_wq
,
450 &qedf
->link_update
, 0);
451 atomic_set(&qedf
->link_down_tmo_valid
, 0);
455 QEDF_ERR(&(qedf
->dbg_ctx
), "LINK DOWN.\n");
457 atomic_set(&qedf
->link_state
, QEDF_LINK_DOWN
);
458 atomic_set(&qedf
->dcbx
, QEDF_DCBX_PENDING
);
460 * Flag that we're waiting for the link to come back up before
461 * informing the fcoe layer of the event.
463 if (qedf_link_down_tmo
> 0) {
464 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
465 "Starting link down tmo.\n");
466 atomic_set(&qedf
->link_down_tmo_valid
, 1);
469 qedf_update_link_speed(qedf
, link
);
470 queue_delayed_work(qedf
->link_update_wq
, &qedf
->link_update
,
471 qedf_link_down_tmo
* HZ
);
476 static void qedf_dcbx_handler(void *dev
, struct qed_dcbx_get
*get
, u32 mib_type
)
478 struct qedf_ctx
*qedf
= (struct qedf_ctx
*)dev
;
480 QEDF_ERR(&(qedf
->dbg_ctx
), "DCBx event valid=%d enabled=%d fcoe "
481 "prio=%d.\n", get
->operational
.valid
, get
->operational
.enabled
,
482 get
->operational
.app_prio
.fcoe
);
484 if (get
->operational
.enabled
&& get
->operational
.valid
) {
485 /* If DCBX was already negotiated on link up then just exit */
486 if (atomic_read(&qedf
->dcbx
) == QEDF_DCBX_DONE
) {
487 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
488 "DCBX already set on link up.\n");
492 atomic_set(&qedf
->dcbx
, QEDF_DCBX_DONE
);
494 if (atomic_read(&qedf
->link_state
) == QEDF_LINK_UP
) {
495 if (atomic_read(&qedf
->link_down_tmo_valid
) > 0)
496 queue_delayed_work(qedf
->link_update_wq
,
497 &qedf
->link_recovery
, 0);
499 queue_delayed_work(qedf
->link_update_wq
,
500 &qedf
->link_update
, 0);
501 atomic_set(&qedf
->link_down_tmo_valid
, 0);
507 static u32
qedf_get_login_failures(void *cookie
)
509 struct qedf_ctx
*qedf
;
511 qedf
= (struct qedf_ctx
*)cookie
;
512 return qedf
->flogi_failed
;
515 static struct qed_fcoe_cb_ops qedf_cb_ops
= {
517 .link_update
= qedf_link_update
,
518 .dcbx_aen
= qedf_dcbx_handler
,
523 * Various transport templates.
526 static struct scsi_transport_template
*qedf_fc_transport_template
;
527 static struct scsi_transport_template
*qedf_fc_vport_transport_template
;
532 static int qedf_eh_abort(struct scsi_cmnd
*sc_cmd
)
534 struct fc_rport
*rport
= starget_to_rport(scsi_target(sc_cmd
->device
));
535 struct fc_rport_libfc_priv
*rp
= rport
->dd_data
;
536 struct qedf_rport
*fcport
;
537 struct fc_lport
*lport
;
538 struct qedf_ctx
*qedf
;
539 struct qedf_ioreq
*io_req
;
543 if (fc_remote_port_chkready(rport
)) {
544 QEDF_ERR(NULL
, "rport not ready\n");
548 lport
= shost_priv(sc_cmd
->device
->host
);
549 qedf
= (struct qedf_ctx
*)lport_priv(lport
);
551 if ((lport
->state
!= LPORT_ST_READY
) || !(lport
->link_up
)) {
552 QEDF_ERR(&(qedf
->dbg_ctx
), "link not ready.\n");
556 fcport
= (struct qedf_rport
*)&rp
[1];
558 io_req
= (struct qedf_ioreq
*)sc_cmd
->SCp
.ptr
;
560 QEDF_ERR(&(qedf
->dbg_ctx
), "io_req is NULL.\n");
565 if (!test_bit(QEDF_CMD_OUTSTANDING
, &io_req
->flags
) ||
566 test_bit(QEDF_CMD_IN_CLEANUP
, &io_req
->flags
) ||
567 test_bit(QEDF_CMD_IN_ABORT
, &io_req
->flags
)) {
568 QEDF_ERR(&(qedf
->dbg_ctx
), "io_req xid=0x%x already in "
569 "cleanup or abort processing or already "
570 "completed.\n", io_req
->xid
);
575 QEDF_ERR(&(qedf
->dbg_ctx
), "Aborting io_req sc_cmd=%p xid=0x%x "
576 "fp_idx=%d.\n", sc_cmd
, io_req
->xid
, io_req
->fp_idx
);
578 if (qedf
->stop_io_on_error
) {
579 qedf_stop_all_io(qedf
);
584 init_completion(&io_req
->abts_done
);
585 rval
= qedf_initiate_abts(io_req
, true);
587 QEDF_ERR(&(qedf
->dbg_ctx
), "Failed to queue ABTS.\n");
591 wait_for_completion(&io_req
->abts_done
);
593 if (io_req
->event
== QEDF_IOREQ_EV_ABORT_SUCCESS
||
594 io_req
->event
== QEDF_IOREQ_EV_ABORT_FAILED
||
595 io_req
->event
== QEDF_IOREQ_EV_CLEANUP_SUCCESS
) {
597 * If we get a reponse to the abort this is success from
598 * the perspective that all references to the command have
599 * been removed from the driver and firmware
603 /* If the abort and cleanup failed then return a failure */
608 QEDF_ERR(&(qedf
->dbg_ctx
), "ABTS succeeded, xid=0x%x.\n",
611 QEDF_ERR(&(qedf
->dbg_ctx
), "ABTS failed, xid=0x%x.\n",
618 static int qedf_eh_target_reset(struct scsi_cmnd
*sc_cmd
)
620 QEDF_ERR(NULL
, "TARGET RESET Issued...");
621 return qedf_initiate_tmf(sc_cmd
, FCP_TMF_TGT_RESET
);
624 static int qedf_eh_device_reset(struct scsi_cmnd
*sc_cmd
)
626 QEDF_ERR(NULL
, "LUN RESET Issued...\n");
627 return qedf_initiate_tmf(sc_cmd
, FCP_TMF_LUN_RESET
);
630 void qedf_wait_for_upload(struct qedf_ctx
*qedf
)
633 if (atomic_read(&qedf
->num_offloads
))
634 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
635 "Waiting for all uploads to complete.\n");
642 /* Reset the host by gracefully logging out and then logging back in */
643 static int qedf_eh_host_reset(struct scsi_cmnd
*sc_cmd
)
645 struct fc_lport
*lport
;
646 struct qedf_ctx
*qedf
;
648 lport
= shost_priv(sc_cmd
->device
->host
);
651 QEDF_ERR(NULL
, "Cannot issue host reset on NPIV port.\n");
655 qedf
= (struct qedf_ctx
*)lport_priv(lport
);
657 if (atomic_read(&qedf
->link_state
) == QEDF_LINK_DOWN
||
658 test_bit(QEDF_UNLOADING
, &qedf
->flags
) ||
659 test_bit(QEDF_DBG_STOP_IO
, &qedf
->flags
))
662 QEDF_ERR(&(qedf
->dbg_ctx
), "HOST RESET Issued...");
664 /* For host reset, essentially do a soft link up/down */
665 atomic_set(&qedf
->link_state
, QEDF_LINK_DOWN
);
666 atomic_set(&qedf
->dcbx
, QEDF_DCBX_PENDING
);
667 queue_delayed_work(qedf
->link_update_wq
, &qedf
->link_update
,
669 qedf_wait_for_upload(qedf
);
670 atomic_set(&qedf
->link_state
, QEDF_LINK_UP
);
672 queue_delayed_work(qedf
->link_update_wq
, &qedf
->link_update
,
678 static int qedf_slave_configure(struct scsi_device
*sdev
)
680 if (qedf_queue_depth
) {
681 scsi_change_queue_depth(sdev
, qedf_queue_depth
);
687 static struct scsi_host_template qedf_host_template
= {
688 .module
= THIS_MODULE
,
689 .name
= QEDF_MODULE_NAME
,
692 .use_clustering
= ENABLE_CLUSTERING
,
693 .max_sectors
= 0xffff,
694 .queuecommand
= qedf_queuecommand
,
695 .shost_attrs
= qedf_host_attrs
,
696 .eh_abort_handler
= qedf_eh_abort
,
697 .eh_device_reset_handler
= qedf_eh_device_reset
, /* lun reset */
698 .eh_target_reset_handler
= qedf_eh_target_reset
, /* target reset */
699 .eh_host_reset_handler
= qedf_eh_host_reset
,
700 .slave_configure
= qedf_slave_configure
,
701 .dma_boundary
= QED_HW_DMA_BOUNDARY
,
702 .sg_tablesize
= QEDF_MAX_BDS_PER_CMD
,
703 .can_queue
= FCOE_PARAMS_NUM_TASKS
,
706 static int qedf_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
710 spin_lock(&qedf_global_lock
);
711 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &qedf_global
);
712 spin_unlock(&qedf_global_lock
);
717 static struct qedf_rport
*qedf_fcport_lookup(struct qedf_ctx
*qedf
, u32 port_id
)
719 struct qedf_rport
*fcport
;
720 struct fc_rport_priv
*rdata
;
723 list_for_each_entry_rcu(fcport
, &qedf
->fcports
, peers
) {
724 rdata
= fcport
->rdata
;
727 if (rdata
->ids
.port_id
== port_id
) {
734 /* Return NULL to caller to let them know fcport was not found */
738 /* Transmits an ELS frame over an offloaded session */
739 static int qedf_xmit_l2_frame(struct qedf_rport
*fcport
, struct fc_frame
*fp
)
741 struct fc_frame_header
*fh
;
744 fh
= fc_frame_header_get(fp
);
745 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
746 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
747 switch (fc_frame_payload_op(fp
)) {
749 qedf_send_adisc(fcport
, fp
);
759 * qedf_xmit - qedf FCoE frame transmit function
762 static int qedf_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
764 struct fc_lport
*base_lport
;
765 struct qedf_ctx
*qedf
;
767 struct fcoe_crc_eof
*cp
;
769 struct fc_frame_header
*fh
;
773 unsigned int hlen
, tlen
, elen
;
775 struct fc_stats
*stats
;
776 struct fc_lport
*tmp_lport
;
777 struct fc_lport
*vn_port
= NULL
;
778 struct qedf_rport
*fcport
;
782 qedf
= (struct qedf_ctx
*)lport_priv(lport
);
784 fh
= fc_frame_header_get(fp
);
787 /* Filter out traffic to other NPIV ports on the same host */
789 base_lport
= shost_priv(vport_to_shost(lport
->vport
));
793 /* Flag if the destination is the base port */
794 if (base_lport
->port_id
== ntoh24(fh
->fh_d_id
)) {
795 vn_port
= base_lport
;
797 /* Got through the list of vports attached to the base_lport
798 * and see if we have a match with the destination address.
800 list_for_each_entry(tmp_lport
, &base_lport
->vports
, list
) {
801 if (tmp_lport
->port_id
== ntoh24(fh
->fh_d_id
)) {
807 if (vn_port
&& ntoh24(fh
->fh_d_id
) != FC_FID_FLOGI
) {
808 struct fc_rport_priv
*rdata
= NULL
;
810 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
811 "Dropping FCoE frame to %06x.\n", ntoh24(fh
->fh_d_id
));
813 rdata
= fc_rport_lookup(lport
, ntoh24(fh
->fh_d_id
));
815 rdata
->retries
= lport
->max_rport_retry_count
;
818 /* End NPIV filtering */
820 if (!qedf
->ctlr
.sel_fcf
) {
825 if (!test_bit(QEDF_LL2_STARTED
, &qedf
->flags
)) {
826 QEDF_WARN(&(qedf
->dbg_ctx
), "LL2 not started\n");
831 if (atomic_read(&qedf
->link_state
) != QEDF_LINK_UP
) {
832 QEDF_WARN(&(qedf
->dbg_ctx
), "qedf link down\n");
837 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
838 if (fcoe_ctlr_els_send(&qedf
->ctlr
, lport
, skb
))
842 /* Check to see if this needs to be sent on an offloaded session */
843 fcport
= qedf_fcport_lookup(qedf
, ntoh24(fh
->fh_d_id
));
845 if (fcport
&& test_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
)) {
846 rc
= qedf_xmit_l2_frame(fcport
, fp
);
848 * If the frame was successfully sent over the middle path
849 * then do not try to also send it over the LL2 path
858 elen
= sizeof(struct ethhdr
);
859 hlen
= sizeof(struct fcoe_hdr
);
860 tlen
= sizeof(struct fcoe_crc_eof
);
861 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
863 skb
->ip_summed
= CHECKSUM_NONE
;
864 crc
= fcoe_fc_crc(fp
);
866 /* copy port crc and eof to the skb buff */
867 if (skb_is_nonlinear(skb
)) {
870 if (qedf_get_paged_crc_eof(skb
, tlen
)) {
874 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
875 cp
= kmap_atomic(skb_frag_page(frag
)) + frag
->page_offset
;
877 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
880 memset(cp
, 0, sizeof(*cp
));
882 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
883 if (skb_is_nonlinear(skb
)) {
889 /* adjust skb network/transport offsets to match mac/fcoe/port */
890 skb_push(skb
, elen
+ hlen
);
891 skb_reset_mac_header(skb
);
892 skb_reset_network_header(skb
);
894 skb
->protocol
= htons(ETH_P_FCOE
);
896 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), qedf
->vlan_id
);
898 /* fill up mac and fcoe headers */
900 eh
->h_proto
= htons(ETH_P_FCOE
);
901 if (qedf
->ctlr
.map_dest
)
902 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
904 /* insert GW address */
905 ether_addr_copy(eh
->h_dest
, qedf
->ctlr
.dest_addr
);
907 /* Set the source MAC address */
908 fc_fcoe_set_mac(eh
->h_source
, fh
->fh_s_id
);
910 hp
= (struct fcoe_hdr
*)(eh
+ 1);
911 memset(hp
, 0, sizeof(*hp
));
913 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
917 stats
= per_cpu_ptr(lport
->stats
, get_cpu());
919 stats
->TxWords
+= wlen
;
922 /* Get VLAN ID from skb for printing purposes */
923 __vlan_hwaccel_get_tag(skb
, &vlan_tci
);
925 /* send down to lld */
927 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
, "FCoE frame send: "
928 "src=%06x dest=%06x r_ctl=%x type=%x vlan=%04x.\n",
929 ntoh24(fh
->fh_s_id
), ntoh24(fh
->fh_d_id
), fh
->fh_r_ctl
, fh
->fh_type
,
931 if (qedf_dump_frames
)
932 print_hex_dump(KERN_WARNING
, "fcoe: ", DUMP_PREFIX_OFFSET
, 16,
933 1, skb
->data
, skb
->len
, false);
934 qed_ops
->ll2
->start_xmit(qedf
->cdev
, skb
);
939 static int qedf_alloc_sq(struct qedf_ctx
*qedf
, struct qedf_rport
*fcport
)
946 /* Calculate appropriate queue and PBL sizes */
947 fcport
->sq_mem_size
= SQ_NUM_ENTRIES
* sizeof(struct fcoe_wqe
);
948 fcport
->sq_mem_size
= ALIGN(fcport
->sq_mem_size
, QEDF_PAGE_SIZE
);
949 fcport
->sq_pbl_size
= (fcport
->sq_mem_size
/ QEDF_PAGE_SIZE
) *
951 fcport
->sq_pbl_size
= fcport
->sq_pbl_size
+ QEDF_PAGE_SIZE
;
953 fcport
->sq
= dma_alloc_coherent(&qedf
->pdev
->dev
, fcport
->sq_mem_size
,
954 &fcport
->sq_dma
, GFP_KERNEL
);
956 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate send "
961 memset(fcport
->sq
, 0, fcport
->sq_mem_size
);
963 fcport
->sq_pbl
= dma_alloc_coherent(&qedf
->pdev
->dev
,
964 fcport
->sq_pbl_size
, &fcport
->sq_pbl_dma
, GFP_KERNEL
);
965 if (!fcport
->sq_pbl
) {
966 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate send "
971 memset(fcport
->sq_pbl
, 0, fcport
->sq_pbl_size
);
974 num_pages
= fcport
->sq_mem_size
/ QEDF_PAGE_SIZE
;
975 page
= fcport
->sq_dma
;
976 pbl
= (u32
*)fcport
->sq_pbl
;
978 while (num_pages
--) {
983 page
+= QEDF_PAGE_SIZE
;
989 dma_free_coherent(&qedf
->pdev
->dev
, fcport
->sq_mem_size
, fcport
->sq
,
995 static void qedf_free_sq(struct qedf_ctx
*qedf
, struct qedf_rport
*fcport
)
998 dma_free_coherent(&qedf
->pdev
->dev
, fcport
->sq_pbl_size
,
999 fcport
->sq_pbl
, fcport
->sq_pbl_dma
);
1001 dma_free_coherent(&qedf
->pdev
->dev
, fcport
->sq_mem_size
,
1002 fcport
->sq
, fcport
->sq_dma
);
1005 static int qedf_offload_connection(struct qedf_ctx
*qedf
,
1006 struct qedf_rport
*fcport
)
1008 struct qed_fcoe_params_offload conn_info
;
1012 uint16_t total_sqe
= (fcport
->sq_mem_size
/ sizeof(struct fcoe_wqe
));
1014 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
, "Offloading connection "
1015 "portid=%06x.\n", fcport
->rdata
->ids
.port_id
);
1016 rval
= qed_ops
->acquire_conn(qedf
->cdev
, &fcport
->handle
,
1017 &fcport
->fw_cid
, &fcport
->p_doorbell
);
1019 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not acquire connection "
1020 "for portid=%06x.\n", fcport
->rdata
->ids
.port_id
);
1021 rval
= 1; /* For some reason qed returns 0 on failure here */
1025 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
, "portid=%06x "
1026 "fw_cid=%08x handle=%d.\n", fcport
->rdata
->ids
.port_id
,
1027 fcport
->fw_cid
, fcport
->handle
);
1029 memset(&conn_info
, 0, sizeof(struct qed_fcoe_params_offload
));
1031 /* Fill in the offload connection info */
1032 conn_info
.sq_pbl_addr
= fcport
->sq_pbl_dma
;
1034 conn_info
.sq_curr_page_addr
= (dma_addr_t
)(*(u64
*)fcport
->sq_pbl
);
1035 conn_info
.sq_next_page_addr
=
1036 (dma_addr_t
)(*(u64
*)(fcport
->sq_pbl
+ 8));
1038 /* Need to use our FCoE MAC for the offload session */
1039 port_id
= fc_host_port_id(qedf
->lport
->host
);
1040 lport_src_id
[2] = (port_id
& 0x000000FF);
1041 lport_src_id
[1] = (port_id
& 0x0000FF00) >> 8;
1042 lport_src_id
[0] = (port_id
& 0x00FF0000) >> 16;
1043 fc_fcoe_set_mac(conn_info
.src_mac
, lport_src_id
);
1045 ether_addr_copy(conn_info
.dst_mac
, qedf
->ctlr
.dest_addr
);
1047 conn_info
.tx_max_fc_pay_len
= fcport
->rdata
->maxframe_size
;
1048 conn_info
.e_d_tov_timer_val
= qedf
->lport
->e_d_tov
/ 20;
1049 conn_info
.rec_tov_timer_val
= 3; /* I think this is what E3 was */
1050 conn_info
.rx_max_fc_pay_len
= fcport
->rdata
->maxframe_size
;
1053 conn_info
.vlan_tag
= qedf
->vlan_id
<<
1054 FCOE_CONN_OFFLOAD_RAMROD_DATA_VLAN_ID_SHIFT
;
1055 conn_info
.vlan_tag
|=
1056 qedf_default_prio
<< FCOE_CONN_OFFLOAD_RAMROD_DATA_PRIORITY_SHIFT
;
1057 conn_info
.flags
|= (FCOE_CONN_OFFLOAD_RAMROD_DATA_B_VLAN_FLAG_MASK
<<
1058 FCOE_CONN_OFFLOAD_RAMROD_DATA_B_VLAN_FLAG_SHIFT
);
1060 /* Set host port source id */
1061 port_id
= fc_host_port_id(qedf
->lport
->host
);
1062 fcport
->sid
= port_id
;
1063 conn_info
.s_id
.addr_hi
= (port_id
& 0x000000FF);
1064 conn_info
.s_id
.addr_mid
= (port_id
& 0x0000FF00) >> 8;
1065 conn_info
.s_id
.addr_lo
= (port_id
& 0x00FF0000) >> 16;
1067 conn_info
.max_conc_seqs_c3
= fcport
->rdata
->max_seq
;
1069 /* Set remote port destination id */
1070 port_id
= fcport
->rdata
->rport
->port_id
;
1071 conn_info
.d_id
.addr_hi
= (port_id
& 0x000000FF);
1072 conn_info
.d_id
.addr_mid
= (port_id
& 0x0000FF00) >> 8;
1073 conn_info
.d_id
.addr_lo
= (port_id
& 0x00FF0000) >> 16;
1075 conn_info
.def_q_idx
= 0; /* Default index for send queue? */
1077 /* Set FC-TAPE specific flags if needed */
1078 if (fcport
->dev_type
== QEDF_RPORT_TYPE_TAPE
) {
1079 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
,
1080 "Enable CONF, REC for portid=%06x.\n",
1081 fcport
->rdata
->ids
.port_id
);
1082 conn_info
.flags
|= 1 <<
1083 FCOE_CONN_OFFLOAD_RAMROD_DATA_B_CONF_REQ_SHIFT
;
1085 ((fcport
->rdata
->sp_features
& FC_SP_FT_SEQC
) ? 1 : 0) <<
1086 FCOE_CONN_OFFLOAD_RAMROD_DATA_B_REC_VALID_SHIFT
;
1089 rval
= qed_ops
->offload_conn(qedf
->cdev
, fcport
->handle
, &conn_info
);
1091 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not offload connection "
1092 "for portid=%06x.\n", fcport
->rdata
->ids
.port_id
);
1095 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
, "Offload "
1096 "succeeded portid=%06x total_sqe=%d.\n",
1097 fcport
->rdata
->ids
.port_id
, total_sqe
);
1099 spin_lock_init(&fcport
->rport_lock
);
1100 atomic_set(&fcport
->free_sqes
, total_sqe
);
1103 qed_ops
->release_conn(qedf
->cdev
, fcport
->handle
);
1108 #define QEDF_TERM_BUFF_SIZE 10
1109 static void qedf_upload_connection(struct qedf_ctx
*qedf
,
1110 struct qedf_rport
*fcport
)
1113 dma_addr_t term_params_dma
;
1115 /* Term params needs to be a DMA coherent buffer as qed shared the
1116 * physical DMA address with the firmware. The buffer may be used in
1117 * the receive path so we may eventually have to move this.
1119 term_params
= dma_alloc_coherent(&qedf
->pdev
->dev
, QEDF_TERM_BUFF_SIZE
,
1120 &term_params_dma
, GFP_KERNEL
);
1122 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
, "Uploading connection "
1123 "port_id=%06x.\n", fcport
->rdata
->ids
.port_id
);
1125 qed_ops
->destroy_conn(qedf
->cdev
, fcport
->handle
, term_params_dma
);
1126 qed_ops
->release_conn(qedf
->cdev
, fcport
->handle
);
1128 dma_free_coherent(&qedf
->pdev
->dev
, QEDF_TERM_BUFF_SIZE
, term_params
,
1132 static void qedf_cleanup_fcport(struct qedf_ctx
*qedf
,
1133 struct qedf_rport
*fcport
)
1135 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_CONN
, "Cleaning up portid=%06x.\n",
1136 fcport
->rdata
->ids
.port_id
);
1138 /* Flush any remaining i/o's before we upload the connection */
1139 qedf_flush_active_ios(fcport
, -1);
1141 if (test_and_clear_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
))
1142 qedf_upload_connection(qedf
, fcport
);
1143 qedf_free_sq(qedf
, fcport
);
1144 fcport
->rdata
= NULL
;
1145 fcport
->qedf
= NULL
;
1149 * This event_callback is called after successful completion of libfc
1150 * initiated target login. qedf can proceed with initiating the session
1153 static void qedf_rport_event_handler(struct fc_lport
*lport
,
1154 struct fc_rport_priv
*rdata
,
1155 enum fc_rport_event event
)
1157 struct qedf_ctx
*qedf
= lport_priv(lport
);
1158 struct fc_rport
*rport
= rdata
->rport
;
1159 struct fc_rport_libfc_priv
*rp
;
1160 struct qedf_rport
*fcport
;
1163 unsigned long flags
;
1165 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "event = %d, "
1166 "port_id = 0x%x\n", event
, rdata
->ids
.port_id
);
1169 case RPORT_EV_READY
:
1171 QEDF_WARN(&(qedf
->dbg_ctx
), "rport is NULL.\n");
1175 rp
= rport
->dd_data
;
1176 fcport
= (struct qedf_rport
*)&rp
[1];
1177 fcport
->qedf
= qedf
;
1179 if (atomic_read(&qedf
->num_offloads
) >= QEDF_MAX_SESSIONS
) {
1180 QEDF_ERR(&(qedf
->dbg_ctx
), "Not offloading "
1181 "portid=0x%x as max number of offloaded sessions "
1182 "reached.\n", rdata
->ids
.port_id
);
1187 * Don't try to offload the session again. Can happen when we
1190 if (test_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
)) {
1191 QEDF_WARN(&(qedf
->dbg_ctx
), "Session already "
1192 "offloaded, portid=0x%x.\n",
1193 rdata
->ids
.port_id
);
1197 if (rport
->port_id
== FC_FID_DIR_SERV
) {
1199 * qedf_rport structure doesn't exist for
1201 * We should not come here, as lport will
1202 * take care of fabric login
1204 QEDF_WARN(&(qedf
->dbg_ctx
), "rport struct does not "
1205 "exist for dir server port_id=%x\n",
1206 rdata
->ids
.port_id
);
1210 if (rdata
->spp_type
!= FC_TYPE_FCP
) {
1211 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
1212 "Not offlading since since spp type isn't FCP\n");
1215 if (!(rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
1216 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
1217 "Not FCP target so not offloading\n");
1221 fcport
->rdata
= rdata
;
1222 fcport
->rport
= rport
;
1224 rval
= qedf_alloc_sq(qedf
, fcport
);
1226 qedf_cleanup_fcport(qedf
, fcport
);
1230 /* Set device type */
1231 if (rdata
->flags
& FC_RP_FLAGS_RETRY
&&
1232 rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_TARGET
&&
1233 !(rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_INITIATOR
)) {
1234 fcport
->dev_type
= QEDF_RPORT_TYPE_TAPE
;
1235 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
1236 "portid=%06x is a TAPE device.\n",
1237 rdata
->ids
.port_id
);
1239 fcport
->dev_type
= QEDF_RPORT_TYPE_DISK
;
1242 rval
= qedf_offload_connection(qedf
, fcport
);
1244 qedf_cleanup_fcport(qedf
, fcport
);
1248 /* Add fcport to list of qedf_ctx list of offloaded ports */
1249 spin_lock_irqsave(&qedf
->hba_lock
, flags
);
1250 list_add_rcu(&fcport
->peers
, &qedf
->fcports
);
1251 spin_unlock_irqrestore(&qedf
->hba_lock
, flags
);
1254 * Set the session ready bit to let everyone know that this
1255 * connection is ready for I/O
1257 set_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
);
1258 atomic_inc(&qedf
->num_offloads
);
1262 case RPORT_EV_FAILED
:
1264 port_id
= rdata
->ids
.port_id
;
1265 if (port_id
== FC_FID_DIR_SERV
)
1269 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
1270 "port_id=%x - rport notcreated Yet!!\n", port_id
);
1273 rp
= rport
->dd_data
;
1275 * Perform session upload. Note that rdata->peers is already
1276 * removed from disc->rports list before we get this event.
1278 fcport
= (struct qedf_rport
*)&rp
[1];
1280 /* Only free this fcport if it is offloaded already */
1281 if (test_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
)) {
1282 set_bit(QEDF_RPORT_UPLOADING_CONNECTION
, &fcport
->flags
);
1283 qedf_cleanup_fcport(qedf
, fcport
);
1286 * Remove fcport to list of qedf_ctx list of offloaded
1289 spin_lock_irqsave(&qedf
->hba_lock
, flags
);
1290 list_del_rcu(&fcport
->peers
);
1291 spin_unlock_irqrestore(&qedf
->hba_lock
, flags
);
1293 clear_bit(QEDF_RPORT_UPLOADING_CONNECTION
,
1295 atomic_dec(&qedf
->num_offloads
);
1305 static void qedf_abort_io(struct fc_lport
*lport
)
1307 /* NO-OP but need to fill in the template */
1310 static void qedf_fcp_cleanup(struct fc_lport
*lport
)
1313 * NO-OP but need to fill in template to prevent a NULL
1314 * function pointer dereference during link down. I/Os
1315 * will be flushed when port is uploaded.
1319 static struct libfc_function_template qedf_lport_template
= {
1320 .frame_send
= qedf_xmit
,
1321 .fcp_abort_io
= qedf_abort_io
,
1322 .fcp_cleanup
= qedf_fcp_cleanup
,
1323 .rport_event_callback
= qedf_rport_event_handler
,
1324 .elsct_send
= qedf_elsct_send
,
1327 static void qedf_fcoe_ctlr_setup(struct qedf_ctx
*qedf
)
1329 fcoe_ctlr_init(&qedf
->ctlr
, FIP_ST_AUTO
);
1331 qedf
->ctlr
.send
= qedf_fip_send
;
1332 qedf
->ctlr
.update_mac
= qedf_update_src_mac
;
1333 qedf
->ctlr
.get_src_addr
= qedf_get_src_mac
;
1334 ether_addr_copy(qedf
->ctlr
.ctl_src_addr
, qedf
->mac
);
1337 static int qedf_lport_setup(struct qedf_ctx
*qedf
)
1339 struct fc_lport
*lport
= qedf
->lport
;
1342 lport
->max_retry_count
= QEDF_FLOGI_RETRY_CNT
;
1343 lport
->max_rport_retry_count
= QEDF_RPORT_RETRY_CNT
;
1344 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
1345 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
1346 lport
->boot_time
= jiffies
;
1347 lport
->e_d_tov
= 2 * 1000;
1348 lport
->r_a_tov
= 10 * 1000;
1350 /* Set NPIV support */
1351 lport
->does_npiv
= 1;
1352 fc_host_max_npiv_vports(lport
->host
) = QEDF_MAX_NPIV
;
1354 fc_set_wwnn(lport
, qedf
->wwnn
);
1355 fc_set_wwpn(lport
, qedf
->wwpn
);
1357 fcoe_libfc_config(lport
, &qedf
->ctlr
, &qedf_lport_template
, 0);
1359 /* Allocate the exchange manager */
1360 fc_exch_mgr_alloc(lport
, FC_CLASS_3
, qedf
->max_scsi_xid
+ 1,
1361 qedf
->max_els_xid
, NULL
);
1363 if (fc_lport_init_stats(lport
))
1366 /* Finish lport config */
1367 fc_lport_config(lport
);
1369 /* Set max frame size */
1370 fc_set_mfs(lport
, QEDF_MFS
);
1371 fc_host_maxframe_size(lport
->host
) = lport
->mfs
;
1373 /* Set default dev_loss_tmo based on module parameter */
1374 fc_host_dev_loss_tmo(lport
->host
) = qedf_dev_loss_tmo
;
1376 /* Set symbolic node name */
1377 snprintf(fc_host_symbolic_name(lport
->host
), 256,
1378 "QLogic %s v%s", QEDF_MODULE_NAME
, QEDF_VERSION
);
1387 static int qedf_vport_libfc_config(struct fc_vport
*vport
,
1388 struct fc_lport
*lport
)
1392 lport
->max_retry_count
= QEDF_FLOGI_RETRY_CNT
;
1393 lport
->max_rport_retry_count
= QEDF_RPORT_RETRY_CNT
;
1394 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
1395 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
1396 lport
->boot_time
= jiffies
;
1397 lport
->e_d_tov
= 2 * 1000;
1398 lport
->r_a_tov
= 10 * 1000;
1399 lport
->does_npiv
= 1; /* Temporary until we add NPIV support */
1401 /* Allocate stats for vport */
1402 if (fc_lport_init_stats(lport
))
1405 /* Finish lport config */
1406 fc_lport_config(lport
);
1408 /* offload related configuration */
1409 lport
->crc_offload
= 0;
1410 lport
->seq_offload
= 0;
1411 lport
->lro_enabled
= 0;
1418 static int qedf_vport_create(struct fc_vport
*vport
, bool disabled
)
1420 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1421 struct fc_lport
*n_port
= shost_priv(shost
);
1422 struct fc_lport
*vn_port
;
1423 struct qedf_ctx
*base_qedf
= lport_priv(n_port
);
1424 struct qedf_ctx
*vport_qedf
;
1429 rc
= fcoe_validate_vport_create(vport
);
1431 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1432 QEDF_WARN(&(base_qedf
->dbg_ctx
), "Failed to create vport, "
1433 "WWPN (0x%s) already exists.\n", buf
);
1437 if (atomic_read(&base_qedf
->link_state
) != QEDF_LINK_UP
) {
1438 QEDF_WARN(&(base_qedf
->dbg_ctx
), "Cannot create vport "
1439 "because link is not up.\n");
1444 vn_port
= libfc_vport_create(vport
, sizeof(struct qedf_ctx
));
1446 QEDF_WARN(&(base_qedf
->dbg_ctx
), "Could not create lport "
1452 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1453 QEDF_ERR(&(base_qedf
->dbg_ctx
), "Creating NPIV port, WWPN=%s.\n",
1456 /* Copy some fields from base_qedf */
1457 vport_qedf
= lport_priv(vn_port
);
1458 memcpy(vport_qedf
, base_qedf
, sizeof(struct qedf_ctx
));
1460 /* Set qedf data specific to this vport */
1461 vport_qedf
->lport
= vn_port
;
1462 /* Use same hba_lock as base_qedf */
1463 vport_qedf
->hba_lock
= base_qedf
->hba_lock
;
1464 vport_qedf
->pdev
= base_qedf
->pdev
;
1465 vport_qedf
->cmd_mgr
= base_qedf
->cmd_mgr
;
1466 init_completion(&vport_qedf
->flogi_compl
);
1467 INIT_LIST_HEAD(&vport_qedf
->fcports
);
1469 rc
= qedf_vport_libfc_config(vport
, vn_port
);
1471 QEDF_ERR(&(base_qedf
->dbg_ctx
), "Could not allocate memory "
1472 "for lport stats.\n");
1476 fc_set_wwnn(vn_port
, vport
->node_name
);
1477 fc_set_wwpn(vn_port
, vport
->port_name
);
1478 vport_qedf
->wwnn
= vn_port
->wwnn
;
1479 vport_qedf
->wwpn
= vn_port
->wwpn
;
1481 vn_port
->host
->transportt
= qedf_fc_vport_transport_template
;
1482 vn_port
->host
->can_queue
= QEDF_MAX_ELS_XID
;
1483 vn_port
->host
->max_lun
= qedf_max_lun
;
1484 vn_port
->host
->sg_tablesize
= QEDF_MAX_BDS_PER_CMD
;
1485 vn_port
->host
->max_cmd_len
= QEDF_MAX_CDB_LEN
;
1487 rc
= scsi_add_host(vn_port
->host
, &vport
->dev
);
1489 QEDF_WARN(&(base_qedf
->dbg_ctx
), "Error adding Scsi_Host.\n");
1493 /* Set default dev_loss_tmo based on module parameter */
1494 fc_host_dev_loss_tmo(vn_port
->host
) = qedf_dev_loss_tmo
;
1496 /* Init libfc stuffs */
1497 memcpy(&vn_port
->tt
, &qedf_lport_template
,
1498 sizeof(qedf_lport_template
));
1499 fc_exch_init(vn_port
);
1500 fc_elsct_init(vn_port
);
1501 fc_lport_init(vn_port
);
1502 fc_disc_init(vn_port
);
1503 fc_disc_config(vn_port
, vn_port
);
1506 /* Allocate the exchange manager */
1507 shost
= vport_to_shost(vport
);
1508 n_port
= shost_priv(shost
);
1509 fc_exch_mgr_list_clone(n_port
, vn_port
);
1511 /* Set max frame size */
1512 fc_set_mfs(vn_port
, QEDF_MFS
);
1514 fc_host_port_type(vn_port
->host
) = FC_PORTTYPE_UNKNOWN
;
1517 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1519 vn_port
->boot_time
= jiffies
;
1520 fc_fabric_login(vn_port
);
1521 fc_vport_setlink(vn_port
);
1524 QEDF_INFO(&(base_qedf
->dbg_ctx
), QEDF_LOG_NPIV
, "vn_port=%p.\n",
1527 /* Set up debug context for vport */
1528 vport_qedf
->dbg_ctx
.host_no
= vn_port
->host
->host_no
;
1529 vport_qedf
->dbg_ctx
.pdev
= base_qedf
->pdev
;
1532 scsi_host_put(vn_port
->host
);
1537 static int qedf_vport_destroy(struct fc_vport
*vport
)
1539 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1540 struct fc_lport
*n_port
= shost_priv(shost
);
1541 struct fc_lport
*vn_port
= vport
->dd_data
;
1543 mutex_lock(&n_port
->lp_mutex
);
1544 list_del(&vn_port
->list
);
1545 mutex_unlock(&n_port
->lp_mutex
);
1547 fc_fabric_logoff(vn_port
);
1548 fc_lport_destroy(vn_port
);
1550 /* Detach from scsi-ml */
1551 fc_remove_host(vn_port
->host
);
1552 scsi_remove_host(vn_port
->host
);
1555 * Only try to release the exchange manager if the vn_port
1556 * configuration is complete.
1558 if (vn_port
->state
== LPORT_ST_READY
)
1559 fc_exch_mgr_free(vn_port
);
1561 /* Free memory used by statistical counters */
1562 fc_lport_free_stats(vn_port
);
1564 /* Release Scsi_Host */
1566 scsi_host_put(vn_port
->host
);
1571 static int qedf_vport_disable(struct fc_vport
*vport
, bool disable
)
1573 struct fc_lport
*lport
= vport
->dd_data
;
1576 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1577 fc_fabric_logoff(lport
);
1579 lport
->boot_time
= jiffies
;
1580 fc_fabric_login(lport
);
1581 fc_vport_setlink(lport
);
1587 * During removal we need to wait for all the vports associated with a port
1588 * to be destroyed so we avoid a race condition where libfc is still trying
1589 * to reap vports while the driver remove function has already reaped the
1590 * driver contexts associated with the physical port.
1592 static void qedf_wait_for_vport_destroy(struct qedf_ctx
*qedf
)
1594 struct fc_host_attrs
*fc_host
= shost_to_fc_host(qedf
->lport
->host
);
1596 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_NPIV
,
1598 while (fc_host
->npiv_vports_inuse
> 0) {
1599 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_NPIV
,
1600 "Waiting for all vports to be reaped.\n");
1606 * qedf_fcoe_reset - Resets the fcoe
1608 * @shost: shost the reset is from
1612 static int qedf_fcoe_reset(struct Scsi_Host
*shost
)
1614 struct fc_lport
*lport
= shost_priv(shost
);
1616 fc_fabric_logoff(lport
);
1617 fc_fabric_login(lport
);
1621 static struct fc_host_statistics
*qedf_fc_get_host_stats(struct Scsi_Host
1624 struct fc_host_statistics
*qedf_stats
;
1625 struct fc_lport
*lport
= shost_priv(shost
);
1626 struct qedf_ctx
*qedf
= lport_priv(lport
);
1627 struct qed_fcoe_stats
*fw_fcoe_stats
;
1629 qedf_stats
= fc_get_host_stats(shost
);
1631 /* We don't collect offload stats for specific NPIV ports */
1635 fw_fcoe_stats
= kmalloc(sizeof(struct qed_fcoe_stats
), GFP_KERNEL
);
1636 if (!fw_fcoe_stats
) {
1637 QEDF_ERR(&(qedf
->dbg_ctx
), "Could not allocate memory for "
1638 "fw_fcoe_stats.\n");
1642 /* Query firmware for offload stats */
1643 qed_ops
->get_stats(qedf
->cdev
, fw_fcoe_stats
);
1646 * The expectation is that we add our offload stats to the stats
1647 * being maintained by libfc each time the fc_get_host_status callback
1648 * is invoked. The additions are not carried over for each call to
1649 * the fc_get_host_stats callback.
1651 qedf_stats
->tx_frames
+= fw_fcoe_stats
->fcoe_tx_data_pkt_cnt
+
1652 fw_fcoe_stats
->fcoe_tx_xfer_pkt_cnt
+
1653 fw_fcoe_stats
->fcoe_tx_other_pkt_cnt
;
1654 qedf_stats
->rx_frames
+= fw_fcoe_stats
->fcoe_rx_data_pkt_cnt
+
1655 fw_fcoe_stats
->fcoe_rx_xfer_pkt_cnt
+
1656 fw_fcoe_stats
->fcoe_rx_other_pkt_cnt
;
1657 qedf_stats
->fcp_input_megabytes
+=
1658 do_div(fw_fcoe_stats
->fcoe_rx_byte_cnt
, 1000000);
1659 qedf_stats
->fcp_output_megabytes
+=
1660 do_div(fw_fcoe_stats
->fcoe_tx_byte_cnt
, 1000000);
1661 qedf_stats
->rx_words
+= fw_fcoe_stats
->fcoe_rx_byte_cnt
/ 4;
1662 qedf_stats
->tx_words
+= fw_fcoe_stats
->fcoe_tx_byte_cnt
/ 4;
1663 qedf_stats
->invalid_crc_count
+=
1664 fw_fcoe_stats
->fcoe_silent_drop_pkt_crc_error_cnt
;
1665 qedf_stats
->dumped_frames
=
1666 fw_fcoe_stats
->fcoe_silent_drop_total_pkt_cnt
;
1667 qedf_stats
->error_frames
+=
1668 fw_fcoe_stats
->fcoe_silent_drop_total_pkt_cnt
;
1669 qedf_stats
->fcp_input_requests
+= qedf
->input_requests
;
1670 qedf_stats
->fcp_output_requests
+= qedf
->output_requests
;
1671 qedf_stats
->fcp_control_requests
+= qedf
->control_requests
;
1672 qedf_stats
->fcp_packet_aborts
+= qedf
->packet_aborts
;
1673 qedf_stats
->fcp_frame_alloc_failures
+= qedf
->alloc_failures
;
1675 kfree(fw_fcoe_stats
);
1680 static struct fc_function_template qedf_fc_transport_fn
= {
1681 .show_host_node_name
= 1,
1682 .show_host_port_name
= 1,
1683 .show_host_supported_classes
= 1,
1684 .show_host_supported_fc4s
= 1,
1685 .show_host_active_fc4s
= 1,
1686 .show_host_maxframe_size
= 1,
1688 .show_host_port_id
= 1,
1689 .show_host_supported_speeds
= 1,
1690 .get_host_speed
= fc_get_host_speed
,
1691 .show_host_speed
= 1,
1692 .show_host_port_type
= 1,
1693 .get_host_port_state
= fc_get_host_port_state
,
1694 .show_host_port_state
= 1,
1695 .show_host_symbolic_name
= 1,
1698 * Tell FC transport to allocate enough space to store the backpointer
1699 * for the associate qedf_rport struct.
1701 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
1702 sizeof(struct qedf_rport
)),
1703 .show_rport_maxframe_size
= 1,
1704 .show_rport_supported_classes
= 1,
1705 .show_host_fabric_name
= 1,
1706 .show_starget_node_name
= 1,
1707 .show_starget_port_name
= 1,
1708 .show_starget_port_id
= 1,
1709 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
1710 .show_rport_dev_loss_tmo
= 1,
1711 .get_fc_host_stats
= qedf_fc_get_host_stats
,
1712 .issue_fc_host_lip
= qedf_fcoe_reset
,
1713 .vport_create
= qedf_vport_create
,
1714 .vport_delete
= qedf_vport_destroy
,
1715 .vport_disable
= qedf_vport_disable
,
1716 .bsg_request
= fc_lport_bsg_request
,
1719 static struct fc_function_template qedf_fc_vport_transport_fn
= {
1720 .show_host_node_name
= 1,
1721 .show_host_port_name
= 1,
1722 .show_host_supported_classes
= 1,
1723 .show_host_supported_fc4s
= 1,
1724 .show_host_active_fc4s
= 1,
1725 .show_host_maxframe_size
= 1,
1726 .show_host_port_id
= 1,
1727 .show_host_supported_speeds
= 1,
1728 .get_host_speed
= fc_get_host_speed
,
1729 .show_host_speed
= 1,
1730 .show_host_port_type
= 1,
1731 .get_host_port_state
= fc_get_host_port_state
,
1732 .show_host_port_state
= 1,
1733 .show_host_symbolic_name
= 1,
1734 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
1735 sizeof(struct qedf_rport
)),
1736 .show_rport_maxframe_size
= 1,
1737 .show_rport_supported_classes
= 1,
1738 .show_host_fabric_name
= 1,
1739 .show_starget_node_name
= 1,
1740 .show_starget_port_name
= 1,
1741 .show_starget_port_id
= 1,
1742 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
1743 .show_rport_dev_loss_tmo
= 1,
1744 .get_fc_host_stats
= fc_get_host_stats
,
1745 .issue_fc_host_lip
= qedf_fcoe_reset
,
1746 .bsg_request
= fc_lport_bsg_request
,
1749 static bool qedf_fp_has_work(struct qedf_fastpath
*fp
)
1751 struct qedf_ctx
*qedf
= fp
->qedf
;
1752 struct global_queue
*que
;
1753 struct qed_sb_info
*sb_info
= fp
->sb_info
;
1754 struct status_block
*sb
= sb_info
->sb_virt
;
1757 /* Get the pointer to the global CQ this completion is on */
1758 que
= qedf
->global_queues
[fp
->sb_id
];
1760 /* Be sure all responses have been written to PI */
1763 /* Get the current firmware producer index */
1764 prod_idx
= sb
->pi_array
[QEDF_FCOE_PARAMS_GL_RQ_PI
];
1766 return (que
->cq_prod_idx
!= prod_idx
);
1770 * Interrupt handler code.
1773 /* Process completion queue and copy CQE contents for deferred processesing
1775 * Return true if we should wake the I/O thread, false if not.
1777 static bool qedf_process_completions(struct qedf_fastpath
*fp
)
1779 struct qedf_ctx
*qedf
= fp
->qedf
;
1780 struct qed_sb_info
*sb_info
= fp
->sb_info
;
1781 struct status_block
*sb
= sb_info
->sb_virt
;
1782 struct global_queue
*que
;
1784 struct fcoe_cqe
*cqe
;
1785 struct qedf_io_work
*io_work
;
1786 int num_handled
= 0;
1788 struct qedf_ioreq
*io_req
= NULL
;
1793 /* Get the current firmware producer index */
1794 prod_idx
= sb
->pi_array
[QEDF_FCOE_PARAMS_GL_RQ_PI
];
1796 /* Get the pointer to the global CQ this completion is on */
1797 que
= qedf
->global_queues
[fp
->sb_id
];
1799 /* Calculate the amount of new elements since last processing */
1800 new_cqes
= (prod_idx
>= que
->cq_prod_idx
) ?
1801 (prod_idx
- que
->cq_prod_idx
) :
1802 0x10000 - que
->cq_prod_idx
+ prod_idx
;
1804 /* Save producer index */
1805 que
->cq_prod_idx
= prod_idx
;
1810 cqe
= &que
->cq
[que
->cq_cons_idx
];
1812 comp_type
= (cqe
->cqe_data
>> FCOE_CQE_CQE_TYPE_SHIFT
) &
1813 FCOE_CQE_CQE_TYPE_MASK
;
1816 * Process unsolicited CQEs directly in the interrupt handler
1817 * sine we need the fastpath ID
1819 if (comp_type
== FCOE_UNSOLIC_CQE_TYPE
) {
1820 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_UNSOL
,
1821 "Unsolicated CQE.\n");
1822 qedf_process_unsol_compl(qedf
, fp
->sb_id
, cqe
);
1824 * Don't add a work list item. Increment consumer
1825 * consumer index and move on.
1830 xid
= cqe
->cqe_data
& FCOE_CQE_TASK_ID_MASK
;
1831 io_req
= &qedf
->cmd_mgr
->cmds
[xid
];
1834 * Figure out which percpu thread we should queue this I/O
1838 /* If there is not io_req assocated with this CQE
1839 * just queue it on CPU 0
1844 io_req
->int_cpu
= smp_processor_id();
1847 io_work
= mempool_alloc(qedf
->io_mempool
, GFP_ATOMIC
);
1849 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate "
1850 "work for I/O completion.\n");
1853 memset(io_work
, 0, sizeof(struct qedf_io_work
));
1855 INIT_WORK(&io_work
->work
, qedf_fp_io_handler
);
1857 /* Copy contents of CQE for deferred processing */
1858 memcpy(&io_work
->cqe
, cqe
, sizeof(struct fcoe_cqe
));
1860 io_work
->qedf
= fp
->qedf
;
1861 io_work
->fp
= NULL
; /* Only used for unsolicited frames */
1863 queue_work_on(cpu
, qedf_io_wq
, &io_work
->work
);
1867 if (que
->cq_cons_idx
== fp
->cq_num_entries
)
1868 que
->cq_cons_idx
= 0;
1876 /* MSI-X fastpath handler code */
1877 static irqreturn_t
qedf_msix_handler(int irq
, void *dev_id
)
1879 struct qedf_fastpath
*fp
= dev_id
;
1882 QEDF_ERR(NULL
, "fp is null.\n");
1886 QEDF_ERR(NULL
, "fp->sb_info in null.");
1891 * Disable interrupts for this status block while we process new
1894 qed_sb_ack(fp
->sb_info
, IGU_INT_DISABLE
, 0 /*do not update*/);
1897 qedf_process_completions(fp
);
1899 if (qedf_fp_has_work(fp
) == 0) {
1900 /* Update the sb information */
1901 qed_sb_update_sb_idx(fp
->sb_info
);
1903 /* Check for more work */
1906 if (qedf_fp_has_work(fp
) == 0) {
1907 /* Re-enable interrupts */
1908 qed_sb_ack(fp
->sb_info
, IGU_INT_ENABLE
, 1);
1914 /* Do we ever want to break out of above loop? */
1918 /* simd handler for MSI/INTa */
1919 static void qedf_simd_int_handler(void *cookie
)
1921 /* Cookie is qedf_ctx struct */
1922 struct qedf_ctx
*qedf
= (struct qedf_ctx
*)cookie
;
1924 QEDF_WARN(&(qedf
->dbg_ctx
), "qedf=%p.\n", qedf
);
1927 #define QEDF_SIMD_HANDLER_NUM 0
1928 static void qedf_sync_free_irqs(struct qedf_ctx
*qedf
)
1932 if (qedf
->int_info
.msix_cnt
) {
1933 for (i
= 0; i
< qedf
->int_info
.used_cnt
; i
++) {
1934 synchronize_irq(qedf
->int_info
.msix
[i
].vector
);
1935 irq_set_affinity_hint(qedf
->int_info
.msix
[i
].vector
,
1937 irq_set_affinity_notifier(qedf
->int_info
.msix
[i
].vector
,
1939 free_irq(qedf
->int_info
.msix
[i
].vector
,
1940 &qedf
->fp_array
[i
]);
1943 qed_ops
->common
->simd_handler_clean(qedf
->cdev
,
1944 QEDF_SIMD_HANDLER_NUM
);
1946 qedf
->int_info
.used_cnt
= 0;
1947 qed_ops
->common
->set_fp_int(qedf
->cdev
, 0);
1950 static int qedf_request_msix_irq(struct qedf_ctx
*qedf
)
1954 cpu
= cpumask_first(cpu_online_mask
);
1955 for (i
= 0; i
< qedf
->num_queues
; i
++) {
1956 rc
= request_irq(qedf
->int_info
.msix
[i
].vector
,
1957 qedf_msix_handler
, 0, "qedf", &qedf
->fp_array
[i
]);
1960 QEDF_WARN(&(qedf
->dbg_ctx
), "request_irq failed.\n");
1961 qedf_sync_free_irqs(qedf
);
1965 qedf
->int_info
.used_cnt
++;
1966 rc
= irq_set_affinity_hint(qedf
->int_info
.msix
[i
].vector
,
1968 cpu
= cpumask_next(cpu
, cpu_online_mask
);
1974 static int qedf_setup_int(struct qedf_ctx
*qedf
)
1979 * Learn interrupt configuration
1981 rc
= qed_ops
->common
->set_fp_int(qedf
->cdev
, num_online_cpus());
1983 rc
= qed_ops
->common
->get_fp_int(qedf
->cdev
, &qedf
->int_info
);
1987 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Number of msix_cnt = "
1988 "0x%x num of cpus = 0x%x\n", qedf
->int_info
.msix_cnt
,
1991 if (qedf
->int_info
.msix_cnt
)
1992 return qedf_request_msix_irq(qedf
);
1994 qed_ops
->common
->simd_handler_config(qedf
->cdev
, &qedf
,
1995 QEDF_SIMD_HANDLER_NUM
, qedf_simd_int_handler
);
1996 qedf
->int_info
.used_cnt
= 1;
2001 /* Main function for libfc frame reception */
2002 static void qedf_recv_frame(struct qedf_ctx
*qedf
,
2003 struct sk_buff
*skb
)
2006 struct fc_lport
*lport
;
2007 struct fc_frame_header
*fh
;
2008 struct fcoe_crc_eof crc_eof
;
2009 struct fc_frame
*fp
;
2011 u8
*dest_mac
= NULL
;
2012 struct fcoe_hdr
*hp
;
2013 struct qedf_rport
*fcport
;
2015 lport
= qedf
->lport
;
2016 if (lport
== NULL
|| lport
->state
== LPORT_ST_DISABLED
) {
2017 QEDF_WARN(NULL
, "Invalid lport struct or lport disabled.\n");
2022 if (skb_is_nonlinear(skb
))
2024 mac
= eth_hdr(skb
)->h_source
;
2025 dest_mac
= eth_hdr(skb
)->h_dest
;
2027 /* Pull the header */
2028 hp
= (struct fcoe_hdr
*)skb
->data
;
2029 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
2030 skb_pull(skb
, sizeof(struct fcoe_hdr
));
2031 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
2033 fp
= (struct fc_frame
*)skb
;
2036 fr_sof(fp
) = hp
->fcoe_sof
;
2037 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
2041 fr_eof(fp
) = crc_eof
.fcoe_eof
;
2042 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
2043 if (pskb_trim(skb
, fr_len
)) {
2048 fh
= fc_frame_header_get(fp
);
2050 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
2051 fh
->fh_type
== FC_TYPE_FCP
) {
2052 /* Drop FCP data. We dont this in L2 path */
2056 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
2057 fh
->fh_type
== FC_TYPE_ELS
) {
2058 switch (fc_frame_payload_op(fp
)) {
2060 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
2061 /* drop non-FIP LOGO */
2069 if (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
2070 /* Drop incoming ABTS */
2076 * If a connection is uploading, drop incoming FCoE frames as there
2077 * is a small window where we could try to return a frame while libfc
2078 * is trying to clean things up.
2081 /* Get fcport associated with d_id if it exists */
2082 fcport
= qedf_fcport_lookup(qedf
, ntoh24(fh
->fh_d_id
));
2084 if (fcport
&& test_bit(QEDF_RPORT_UPLOADING_CONNECTION
,
2086 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
2087 "Connection uploading, dropping fp=%p.\n", fp
);
2092 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
, "FCoE frame receive: "
2093 "skb=%p fp=%p src=%06x dest=%06x r_ctl=%x fh_type=%x.\n", skb
, fp
,
2094 ntoh24(fh
->fh_s_id
), ntoh24(fh
->fh_d_id
), fh
->fh_r_ctl
,
2096 if (qedf_dump_frames
)
2097 print_hex_dump(KERN_WARNING
, "fcoe: ", DUMP_PREFIX_OFFSET
, 16,
2098 1, skb
->data
, skb
->len
, false);
2099 fc_exch_recv(lport
, fp
);
2102 static void qedf_ll2_process_skb(struct work_struct
*work
)
2104 struct qedf_skb_work
*skb_work
=
2105 container_of(work
, struct qedf_skb_work
, work
);
2106 struct qedf_ctx
*qedf
= skb_work
->qedf
;
2107 struct sk_buff
*skb
= skb_work
->skb
;
2111 QEDF_ERR(NULL
, "qedf is NULL\n");
2115 eh
= (struct ethhdr
*)skb
->data
;
2117 /* Undo VLAN encapsulation */
2118 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
2119 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
2120 eh
= (struct ethhdr
*)skb_pull(skb
, VLAN_HLEN
);
2121 skb_reset_mac_header(skb
);
2125 * Process either a FIP frame or FCoE frame based on the
2126 * protocol value. If it's not either just drop the
2129 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
2130 qedf_fip_recv(qedf
, skb
);
2132 } else if (eh
->h_proto
== htons(ETH_P_FCOE
)) {
2133 __skb_pull(skb
, ETH_HLEN
);
2134 qedf_recv_frame(qedf
, skb
);
2146 static int qedf_ll2_rx(void *cookie
, struct sk_buff
*skb
,
2149 struct qedf_ctx
*qedf
= (struct qedf_ctx
*)cookie
;
2150 struct qedf_skb_work
*skb_work
;
2152 skb_work
= kzalloc(sizeof(struct qedf_skb_work
), GFP_ATOMIC
);
2154 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate skb_work so "
2155 "dropping frame.\n");
2160 INIT_WORK(&skb_work
->work
, qedf_ll2_process_skb
);
2161 skb_work
->skb
= skb
;
2162 skb_work
->qedf
= qedf
;
2163 queue_work(qedf
->ll2_recv_wq
, &skb_work
->work
);
2168 static struct qed_ll2_cb_ops qedf_ll2_cb_ops
= {
2169 .rx_cb
= qedf_ll2_rx
,
2173 /* Main thread to process I/O completions */
2174 void qedf_fp_io_handler(struct work_struct
*work
)
2176 struct qedf_io_work
*io_work
=
2177 container_of(work
, struct qedf_io_work
, work
);
2181 * Deferred part of unsolicited CQE sends
2184 comp_type
= (io_work
->cqe
.cqe_data
>>
2185 FCOE_CQE_CQE_TYPE_SHIFT
) &
2186 FCOE_CQE_CQE_TYPE_MASK
;
2187 if (comp_type
== FCOE_UNSOLIC_CQE_TYPE
&&
2189 fc_exch_recv(io_work
->qedf
->lport
, io_work
->fp
);
2191 qedf_process_cqe(io_work
->qedf
, &io_work
->cqe
);
2196 static int qedf_alloc_and_init_sb(struct qedf_ctx
*qedf
,
2197 struct qed_sb_info
*sb_info
, u16 sb_id
)
2199 struct status_block
*sb_virt
;
2203 sb_virt
= dma_alloc_coherent(&qedf
->pdev
->dev
,
2204 sizeof(struct status_block
), &sb_phys
, GFP_KERNEL
);
2207 QEDF_ERR(&(qedf
->dbg_ctx
), "Status block allocation failed "
2208 "for id = %d.\n", sb_id
);
2212 ret
= qed_ops
->common
->sb_init(qedf
->cdev
, sb_info
, sb_virt
, sb_phys
,
2213 sb_id
, QED_SB_TYPE_STORAGE
);
2216 QEDF_ERR(&(qedf
->dbg_ctx
), "Status block initialization "
2217 "failed for id = %d.\n", sb_id
);
2224 static void qedf_free_sb(struct qedf_ctx
*qedf
, struct qed_sb_info
*sb_info
)
2226 if (sb_info
->sb_virt
)
2227 dma_free_coherent(&qedf
->pdev
->dev
, sizeof(*sb_info
->sb_virt
),
2228 (void *)sb_info
->sb_virt
, sb_info
->sb_phys
);
2231 static void qedf_destroy_sb(struct qedf_ctx
*qedf
)
2234 struct qedf_fastpath
*fp
= NULL
;
2236 for (id
= 0; id
< qedf
->num_queues
; id
++) {
2237 fp
= &(qedf
->fp_array
[id
]);
2238 if (fp
->sb_id
== QEDF_SB_ID_NULL
)
2240 qedf_free_sb(qedf
, fp
->sb_info
);
2243 kfree(qedf
->fp_array
);
2246 static int qedf_prepare_sb(struct qedf_ctx
*qedf
)
2249 struct qedf_fastpath
*fp
;
2253 kcalloc(qedf
->num_queues
, sizeof(struct qedf_fastpath
),
2256 if (!qedf
->fp_array
) {
2257 QEDF_ERR(&(qedf
->dbg_ctx
), "fastpath array allocation "
2262 for (id
= 0; id
< qedf
->num_queues
; id
++) {
2263 fp
= &(qedf
->fp_array
[id
]);
2264 fp
->sb_id
= QEDF_SB_ID_NULL
;
2265 fp
->sb_info
= kcalloc(1, sizeof(*fp
->sb_info
), GFP_KERNEL
);
2267 QEDF_ERR(&(qedf
->dbg_ctx
), "SB info struct "
2268 "allocation failed.\n");
2271 ret
= qedf_alloc_and_init_sb(qedf
, fp
->sb_info
, id
);
2273 QEDF_ERR(&(qedf
->dbg_ctx
), "SB allocation and "
2274 "initialization failed.\n");
2279 fp
->cq_num_entries
=
2280 qedf
->global_queues
[id
]->cq_mem_size
/
2281 sizeof(struct fcoe_cqe
);
2287 void qedf_process_cqe(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
)
2290 struct qedf_ioreq
*io_req
;
2291 struct qedf_rport
*fcport
;
2294 comp_type
= (cqe
->cqe_data
>> FCOE_CQE_CQE_TYPE_SHIFT
) &
2295 FCOE_CQE_CQE_TYPE_MASK
;
2297 xid
= cqe
->cqe_data
& FCOE_CQE_TASK_ID_MASK
;
2298 io_req
= &qedf
->cmd_mgr
->cmds
[xid
];
2300 /* Completion not for a valid I/O anymore so just return */
2304 fcport
= io_req
->fcport
;
2306 if (fcport
== NULL
) {
2307 QEDF_ERR(&(qedf
->dbg_ctx
), "fcport is NULL.\n");
2312 * Check that fcport is offloaded. If it isn't then the spinlock
2313 * isn't valid and shouldn't be taken. We should just return.
2315 if (!test_bit(QEDF_RPORT_SESSION_READY
, &fcport
->flags
)) {
2316 QEDF_ERR(&(qedf
->dbg_ctx
), "Session not offloaded yet.\n");
2321 switch (comp_type
) {
2322 case FCOE_GOOD_COMPLETION_CQE_TYPE
:
2323 atomic_inc(&fcport
->free_sqes
);
2324 switch (io_req
->cmd_type
) {
2326 qedf_scsi_completion(qedf
, cqe
, io_req
);
2329 qedf_process_els_compl(qedf
, cqe
, io_req
);
2331 case QEDF_TASK_MGMT_CMD
:
2332 qedf_process_tmf_compl(qedf
, cqe
, io_req
);
2334 case QEDF_SEQ_CLEANUP
:
2335 qedf_process_seq_cleanup_compl(qedf
, cqe
, io_req
);
2339 case FCOE_ERROR_DETECTION_CQE_TYPE
:
2340 atomic_inc(&fcport
->free_sqes
);
2341 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2342 "Error detect CQE.\n");
2343 qedf_process_error_detect(qedf
, cqe
, io_req
);
2345 case FCOE_EXCH_CLEANUP_CQE_TYPE
:
2346 atomic_inc(&fcport
->free_sqes
);
2347 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2349 qedf_process_cleanup_compl(qedf
, cqe
, io_req
);
2351 case FCOE_ABTS_CQE_TYPE
:
2352 atomic_inc(&fcport
->free_sqes
);
2353 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2355 qedf_process_abts_compl(qedf
, cqe
, io_req
);
2357 case FCOE_DUMMY_CQE_TYPE
:
2358 atomic_inc(&fcport
->free_sqes
);
2359 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2362 case FCOE_LOCAL_COMP_CQE_TYPE
:
2363 atomic_inc(&fcport
->free_sqes
);
2364 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2365 "Local completion CQE.\n");
2367 case FCOE_WARNING_CQE_TYPE
:
2368 atomic_inc(&fcport
->free_sqes
);
2369 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2371 qedf_process_warning_compl(qedf
, cqe
, io_req
);
2373 case MAX_FCOE_CQE_TYPE
:
2374 atomic_inc(&fcport
->free_sqes
);
2375 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2379 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_IO
,
2385 static void qedf_free_bdq(struct qedf_ctx
*qedf
)
2389 if (qedf
->bdq_pbl_list
)
2390 dma_free_coherent(&qedf
->pdev
->dev
, QEDF_PAGE_SIZE
,
2391 qedf
->bdq_pbl_list
, qedf
->bdq_pbl_list_dma
);
2394 dma_free_coherent(&qedf
->pdev
->dev
, qedf
->bdq_pbl_mem_size
,
2395 qedf
->bdq_pbl
, qedf
->bdq_pbl_dma
);
2397 for (i
= 0; i
< QEDF_BDQ_SIZE
; i
++) {
2398 if (qedf
->bdq
[i
].buf_addr
) {
2399 dma_free_coherent(&qedf
->pdev
->dev
, QEDF_BDQ_BUF_SIZE
,
2400 qedf
->bdq
[i
].buf_addr
, qedf
->bdq
[i
].buf_dma
);
2405 static void qedf_free_global_queues(struct qedf_ctx
*qedf
)
2408 struct global_queue
**gl
= qedf
->global_queues
;
2410 for (i
= 0; i
< qedf
->num_queues
; i
++) {
2415 dma_free_coherent(&qedf
->pdev
->dev
,
2416 gl
[i
]->cq_mem_size
, gl
[i
]->cq
, gl
[i
]->cq_dma
);
2418 dma_free_coherent(&qedf
->pdev
->dev
, gl
[i
]->cq_pbl_size
,
2419 gl
[i
]->cq_pbl
, gl
[i
]->cq_pbl_dma
);
2424 qedf_free_bdq(qedf
);
2427 static int qedf_alloc_bdq(struct qedf_ctx
*qedf
)
2430 struct scsi_bd
*pbl
;
2434 /* Alloc dma memory for BDQ buffers */
2435 for (i
= 0; i
< QEDF_BDQ_SIZE
; i
++) {
2436 qedf
->bdq
[i
].buf_addr
= dma_alloc_coherent(&qedf
->pdev
->dev
,
2437 QEDF_BDQ_BUF_SIZE
, &qedf
->bdq
[i
].buf_dma
, GFP_KERNEL
);
2438 if (!qedf
->bdq
[i
].buf_addr
) {
2439 QEDF_ERR(&(qedf
->dbg_ctx
), "Could not allocate BDQ "
2445 /* Alloc dma memory for BDQ page buffer list */
2446 qedf
->bdq_pbl_mem_size
=
2447 QEDF_BDQ_SIZE
* sizeof(struct scsi_bd
);
2448 qedf
->bdq_pbl_mem_size
=
2449 ALIGN(qedf
->bdq_pbl_mem_size
, QEDF_PAGE_SIZE
);
2451 qedf
->bdq_pbl
= dma_alloc_coherent(&qedf
->pdev
->dev
,
2452 qedf
->bdq_pbl_mem_size
, &qedf
->bdq_pbl_dma
, GFP_KERNEL
);
2453 if (!qedf
->bdq_pbl
) {
2454 QEDF_ERR(&(qedf
->dbg_ctx
), "Could not allocate BDQ PBL.\n");
2458 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2459 "BDQ PBL addr=0x%p dma=%pad\n",
2460 qedf
->bdq_pbl
, &qedf
->bdq_pbl_dma
);
2463 * Populate BDQ PBL with physical and virtual address of individual
2466 pbl
= (struct scsi_bd
*)qedf
->bdq_pbl
;
2467 for (i
= 0; i
< QEDF_BDQ_SIZE
; i
++) {
2468 pbl
->address
.hi
= cpu_to_le32(U64_HI(qedf
->bdq
[i
].buf_dma
));
2469 pbl
->address
.lo
= cpu_to_le32(U64_LO(qedf
->bdq
[i
].buf_dma
));
2471 /* Opaque lo data is an index into the BDQ array */
2472 pbl
->opaque
.lo
= cpu_to_le32(i
);
2476 /* Allocate list of PBL pages */
2477 qedf
->bdq_pbl_list
= dma_alloc_coherent(&qedf
->pdev
->dev
,
2478 QEDF_PAGE_SIZE
, &qedf
->bdq_pbl_list_dma
, GFP_KERNEL
);
2479 if (!qedf
->bdq_pbl_list
) {
2480 QEDF_ERR(&(qedf
->dbg_ctx
), "Could not allocate list of PBL "
2484 memset(qedf
->bdq_pbl_list
, 0, QEDF_PAGE_SIZE
);
2487 * Now populate PBL list with pages that contain pointers to the
2488 * individual buffers.
2490 qedf
->bdq_pbl_list_num_entries
= qedf
->bdq_pbl_mem_size
/
2492 list
= (u64
*)qedf
->bdq_pbl_list
;
2493 page
= qedf
->bdq_pbl_list_dma
;
2494 for (i
= 0; i
< qedf
->bdq_pbl_list_num_entries
; i
++) {
2495 *list
= qedf
->bdq_pbl_dma
;
2497 page
+= QEDF_PAGE_SIZE
;
2503 static int qedf_alloc_global_queues(struct qedf_ctx
*qedf
)
2512 /* Allocate and map CQs, RQs */
2514 * Number of global queues (CQ / RQ). This should
2515 * be <= number of available MSIX vectors for the PF
2517 if (!qedf
->num_queues
) {
2518 QEDF_ERR(&(qedf
->dbg_ctx
), "No MSI-X vectors available!\n");
2523 * Make sure we allocated the PBL that will contain the physical
2524 * addresses of our queues
2526 if (!qedf
->p_cpuq
) {
2528 goto mem_alloc_failure
;
2531 qedf
->global_queues
= kzalloc((sizeof(struct global_queue
*)
2532 * qedf
->num_queues
), GFP_KERNEL
);
2533 if (!qedf
->global_queues
) {
2534 QEDF_ERR(&(qedf
->dbg_ctx
), "Unable to allocate global "
2535 "queues array ptr memory\n");
2538 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2539 "qedf->global_queues=%p.\n", qedf
->global_queues
);
2541 /* Allocate DMA coherent buffers for BDQ */
2542 rc
= qedf_alloc_bdq(qedf
);
2544 goto mem_alloc_failure
;
2546 /* Allocate a CQ and an associated PBL for each MSI-X vector */
2547 for (i
= 0; i
< qedf
->num_queues
; i
++) {
2548 qedf
->global_queues
[i
] = kzalloc(sizeof(struct global_queue
),
2550 if (!qedf
->global_queues
[i
]) {
2551 QEDF_WARN(&(qedf
->dbg_ctx
), "Unable to allocation "
2552 "global queue %d.\n", i
);
2553 goto mem_alloc_failure
;
2556 qedf
->global_queues
[i
]->cq_mem_size
=
2557 FCOE_PARAMS_CQ_NUM_ENTRIES
* sizeof(struct fcoe_cqe
);
2558 qedf
->global_queues
[i
]->cq_mem_size
=
2559 ALIGN(qedf
->global_queues
[i
]->cq_mem_size
, QEDF_PAGE_SIZE
);
2561 qedf
->global_queues
[i
]->cq_pbl_size
=
2562 (qedf
->global_queues
[i
]->cq_mem_size
/
2563 PAGE_SIZE
) * sizeof(void *);
2564 qedf
->global_queues
[i
]->cq_pbl_size
=
2565 ALIGN(qedf
->global_queues
[i
]->cq_pbl_size
, QEDF_PAGE_SIZE
);
2567 qedf
->global_queues
[i
]->cq
=
2568 dma_alloc_coherent(&qedf
->pdev
->dev
,
2569 qedf
->global_queues
[i
]->cq_mem_size
,
2570 &qedf
->global_queues
[i
]->cq_dma
, GFP_KERNEL
);
2572 if (!qedf
->global_queues
[i
]->cq
) {
2573 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate "
2576 goto mem_alloc_failure
;
2578 memset(qedf
->global_queues
[i
]->cq
, 0,
2579 qedf
->global_queues
[i
]->cq_mem_size
);
2581 qedf
->global_queues
[i
]->cq_pbl
=
2582 dma_alloc_coherent(&qedf
->pdev
->dev
,
2583 qedf
->global_queues
[i
]->cq_pbl_size
,
2584 &qedf
->global_queues
[i
]->cq_pbl_dma
, GFP_KERNEL
);
2586 if (!qedf
->global_queues
[i
]->cq_pbl
) {
2587 QEDF_WARN(&(qedf
->dbg_ctx
), "Could not allocate "
2590 goto mem_alloc_failure
;
2592 memset(qedf
->global_queues
[i
]->cq_pbl
, 0,
2593 qedf
->global_queues
[i
]->cq_pbl_size
);
2596 num_pages
= qedf
->global_queues
[i
]->cq_mem_size
/
2598 page
= qedf
->global_queues
[i
]->cq_dma
;
2599 pbl
= (u32
*)qedf
->global_queues
[i
]->cq_pbl
;
2601 while (num_pages
--) {
2602 *pbl
= U64_LO(page
);
2604 *pbl
= U64_HI(page
);
2606 page
+= QEDF_PAGE_SIZE
;
2608 /* Set the initial consumer index for cq */
2609 qedf
->global_queues
[i
]->cq_cons_idx
= 0;
2612 list
= (u32
*)qedf
->p_cpuq
;
2615 * The list is built as follows: CQ#0 PBL pointer, RQ#0 PBL pointer,
2616 * CQ#1 PBL pointer, RQ#1 PBL pointer, etc. Each PBL pointer points
2617 * to the physical address which contains an array of pointers to
2618 * the physical addresses of the specific queue pages.
2620 for (i
= 0; i
< qedf
->num_queues
; i
++) {
2621 *list
= U64_LO(qedf
->global_queues
[i
]->cq_pbl_dma
);
2623 *list
= U64_HI(qedf
->global_queues
[i
]->cq_pbl_dma
);
2634 qedf_free_global_queues(qedf
);
2638 static int qedf_set_fcoe_pf_param(struct qedf_ctx
*qedf
)
2640 u8 sq_num_pbl_pages
;
2647 * The number of completion queues/fastpath interrupts/status blocks
2648 * we allocation is the minimum off:
2651 * Number of MSI-X vectors
2652 * Max number allocated in hardware (QEDF_MAX_NUM_CQS)
2654 qedf
->num_queues
= min((unsigned int)QEDF_MAX_NUM_CQS
,
2657 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Number of CQs is %d.\n",
2660 qedf
->p_cpuq
= pci_alloc_consistent(qedf
->pdev
,
2661 qedf
->num_queues
* sizeof(struct qedf_glbl_q_params
),
2664 if (!qedf
->p_cpuq
) {
2665 QEDF_ERR(&(qedf
->dbg_ctx
), "pci_alloc_consistent failed.\n");
2669 rval
= qedf_alloc_global_queues(qedf
);
2671 QEDF_ERR(&(qedf
->dbg_ctx
), "Global queue allocation "
2676 /* Calculate SQ PBL size in the same manner as in qedf_sq_alloc() */
2677 sq_mem_size
= SQ_NUM_ENTRIES
* sizeof(struct fcoe_wqe
);
2678 sq_mem_size
= ALIGN(sq_mem_size
, QEDF_PAGE_SIZE
);
2679 sq_num_pbl_pages
= (sq_mem_size
/ QEDF_PAGE_SIZE
);
2681 /* Calculate CQ num entries */
2682 cq_mem_size
= FCOE_PARAMS_CQ_NUM_ENTRIES
* sizeof(struct fcoe_cqe
);
2683 cq_mem_size
= ALIGN(cq_mem_size
, QEDF_PAGE_SIZE
);
2684 cq_num_entries
= cq_mem_size
/ sizeof(struct fcoe_cqe
);
2686 memset(&(qedf
->pf_params
), 0,
2687 sizeof(qedf
->pf_params
));
2689 /* Setup the value for fcoe PF */
2690 qedf
->pf_params
.fcoe_pf_params
.num_cons
= QEDF_MAX_SESSIONS
;
2691 qedf
->pf_params
.fcoe_pf_params
.num_tasks
= FCOE_PARAMS_NUM_TASKS
;
2692 qedf
->pf_params
.fcoe_pf_params
.glbl_q_params_addr
=
2693 (u64
)qedf
->hw_p_cpuq
;
2694 qedf
->pf_params
.fcoe_pf_params
.sq_num_pbl_pages
= sq_num_pbl_pages
;
2696 qedf
->pf_params
.fcoe_pf_params
.rq_buffer_log_size
= 0;
2698 qedf
->pf_params
.fcoe_pf_params
.cq_num_entries
= cq_num_entries
;
2699 qedf
->pf_params
.fcoe_pf_params
.num_cqs
= qedf
->num_queues
;
2701 /* log_page_size: 12 for 4KB pages */
2702 qedf
->pf_params
.fcoe_pf_params
.log_page_size
= ilog2(QEDF_PAGE_SIZE
);
2704 qedf
->pf_params
.fcoe_pf_params
.mtu
= 9000;
2705 qedf
->pf_params
.fcoe_pf_params
.gl_rq_pi
= QEDF_FCOE_PARAMS_GL_RQ_PI
;
2706 qedf
->pf_params
.fcoe_pf_params
.gl_cmd_pi
= QEDF_FCOE_PARAMS_GL_CMD_PI
;
2708 /* BDQ address and size */
2709 qedf
->pf_params
.fcoe_pf_params
.bdq_pbl_base_addr
[0] =
2710 qedf
->bdq_pbl_list_dma
;
2711 qedf
->pf_params
.fcoe_pf_params
.bdq_pbl_num_entries
[0] =
2712 qedf
->bdq_pbl_list_num_entries
;
2713 qedf
->pf_params
.fcoe_pf_params
.rq_buffer_size
= QEDF_BDQ_BUF_SIZE
;
2715 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2716 "bdq_list=%p bdq_pbl_list_dma=%llx bdq_pbl_list_entries=%d.\n",
2718 qedf
->pf_params
.fcoe_pf_params
.bdq_pbl_base_addr
[0],
2719 qedf
->pf_params
.fcoe_pf_params
.bdq_pbl_num_entries
[0]);
2721 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2722 "cq_num_entries=%d.\n",
2723 qedf
->pf_params
.fcoe_pf_params
.cq_num_entries
);
2728 /* Free DMA coherent memory for array of queue pointers we pass to qed */
2729 static void qedf_free_fcoe_pf_param(struct qedf_ctx
*qedf
)
2734 size
= qedf
->num_queues
* sizeof(struct qedf_glbl_q_params
);
2735 pci_free_consistent(qedf
->pdev
, size
, qedf
->p_cpuq
,
2739 qedf_free_global_queues(qedf
);
2741 if (qedf
->global_queues
)
2742 kfree(qedf
->global_queues
);
2746 * PCI driver functions
2749 static const struct pci_device_id qedf_pci_tbl
[] = {
2750 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, 0x165c) },
2751 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, 0x8080) },
2754 MODULE_DEVICE_TABLE(pci
, qedf_pci_tbl
);
2756 static struct pci_driver qedf_pci_driver
= {
2757 .name
= QEDF_MODULE_NAME
,
2758 .id_table
= qedf_pci_tbl
,
2759 .probe
= qedf_probe
,
2760 .remove
= qedf_remove
,
2763 static int __qedf_probe(struct pci_dev
*pdev
, int mode
)
2766 struct fc_lport
*lport
;
2767 struct qedf_ctx
*qedf
;
2768 struct Scsi_Host
*host
;
2770 struct qed_ll2_params params
;
2772 struct qed_link_params link_params
;
2774 void *task_start
, *task_end
;
2775 struct qed_slowpath_params slowpath_params
;
2776 struct qed_probe_params qed_params
;
2780 * When doing error recovery we didn't reap the lport so don't try
2783 if (mode
!= QEDF_MODE_RECOVERY
) {
2784 lport
= libfc_host_alloc(&qedf_host_template
,
2785 sizeof(struct qedf_ctx
));
2788 QEDF_ERR(NULL
, "Could not allocate lport.\n");
2793 /* Initialize qedf_ctx */
2794 qedf
= lport_priv(lport
);
2795 qedf
->lport
= lport
;
2796 qedf
->ctlr
.lp
= lport
;
2798 qedf
->dbg_ctx
.pdev
= pdev
;
2799 qedf
->dbg_ctx
.host_no
= lport
->host
->host_no
;
2800 spin_lock_init(&qedf
->hba_lock
);
2801 INIT_LIST_HEAD(&qedf
->fcports
);
2802 qedf
->curr_conn_id
= QEDF_MAX_SESSIONS
- 1;
2803 atomic_set(&qedf
->num_offloads
, 0);
2804 qedf
->stop_io_on_error
= false;
2805 pci_set_drvdata(pdev
, qedf
);
2806 init_completion(&qedf
->fipvlan_compl
);
2808 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_INFO
,
2809 "QLogic FastLinQ FCoE Module qedf %s, "
2810 "FW %d.%d.%d.%d\n", QEDF_VERSION
,
2811 FW_MAJOR_VERSION
, FW_MINOR_VERSION
, FW_REVISION_VERSION
,
2812 FW_ENGINEERING_VERSION
);
2814 /* Init pointers during recovery */
2815 qedf
= pci_get_drvdata(pdev
);
2816 lport
= qedf
->lport
;
2821 /* Allocate mempool for qedf_io_work structs */
2822 qedf
->io_mempool
= mempool_create_slab_pool(QEDF_IO_WORK_MIN
,
2823 qedf_io_work_cache
);
2824 if (qedf
->io_mempool
== NULL
) {
2825 QEDF_ERR(&(qedf
->dbg_ctx
), "qedf->io_mempool is NULL.\n");
2828 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_INFO
, "qedf->io_mempool=%p.\n",
2831 sprintf(host_buf
, "qedf_%u_link",
2832 qedf
->lport
->host
->host_no
);
2833 qedf
->link_update_wq
= create_singlethread_workqueue(host_buf
);
2834 INIT_DELAYED_WORK(&qedf
->link_update
, qedf_handle_link_update
);
2835 INIT_DELAYED_WORK(&qedf
->link_recovery
, qedf_link_recovery
);
2837 qedf
->fipvlan_retries
= qedf_fipvlan_retries
;
2840 * Common probe. Takes care of basic hardware init and pci_*
2843 memset(&qed_params
, 0, sizeof(qed_params
));
2844 qed_params
.protocol
= QED_PROTOCOL_FCOE
;
2845 qed_params
.dp_module
= qedf_dp_module
;
2846 qed_params
.dp_level
= qedf_dp_level
;
2847 qed_params
.is_vf
= is_vf
;
2848 qedf
->cdev
= qed_ops
->common
->probe(pdev
, &qed_params
);
2854 /* queue allocation code should come here
2857 * status block allocation
2858 * interrupt registration (to get min number of queues)
2860 * qed_sp_fcoe_func_start
2862 rc
= qedf_set_fcoe_pf_param(qedf
);
2864 QEDF_ERR(&(qedf
->dbg_ctx
), "Cannot set fcoe pf param.\n");
2867 qed_ops
->common
->update_pf_params(qedf
->cdev
, &qedf
->pf_params
);
2869 /* Learn information crucial for qedf to progress */
2870 rc
= qed_ops
->fill_dev_info(qedf
->cdev
, &qedf
->dev_info
);
2872 QEDF_ERR(&(qedf
->dbg_ctx
), "Failed to dev info.\n");
2876 /* Record BDQ producer doorbell addresses */
2877 qedf
->bdq_primary_prod
= qedf
->dev_info
.primary_dbq_rq_addr
;
2878 qedf
->bdq_secondary_prod
= qedf
->dev_info
.secondary_bdq_rq_addr
;
2879 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2880 "BDQ primary_prod=%p secondary_prod=%p.\n", qedf
->bdq_primary_prod
,
2881 qedf
->bdq_secondary_prod
);
2883 qed_ops
->register_ops(qedf
->cdev
, &qedf_cb_ops
, qedf
);
2885 rc
= qedf_prepare_sb(qedf
);
2888 QEDF_ERR(&(qedf
->dbg_ctx
), "Cannot start slowpath.\n");
2892 /* Start the Slowpath-process */
2893 slowpath_params
.int_mode
= QED_INT_MODE_MSIX
;
2894 slowpath_params
.drv_major
= QEDF_DRIVER_MAJOR_VER
;
2895 slowpath_params
.drv_minor
= QEDF_DRIVER_MINOR_VER
;
2896 slowpath_params
.drv_rev
= QEDF_DRIVER_REV_VER
;
2897 slowpath_params
.drv_eng
= QEDF_DRIVER_ENG_VER
;
2898 memcpy(slowpath_params
.name
, "qedf", QED_DRV_VER_STR_SIZE
);
2899 rc
= qed_ops
->common
->slowpath_start(qedf
->cdev
, &slowpath_params
);
2901 QEDF_ERR(&(qedf
->dbg_ctx
), "Cannot start slowpath.\n");
2906 * update_pf_params needs to be called before and after slowpath
2909 qed_ops
->common
->update_pf_params(qedf
->cdev
, &qedf
->pf_params
);
2911 /* Setup interrupts */
2912 rc
= qedf_setup_int(qedf
);
2916 rc
= qed_ops
->start(qedf
->cdev
, &qedf
->tasks
);
2918 QEDF_ERR(&(qedf
->dbg_ctx
), "Cannot start FCoE function.\n");
2921 task_start
= qedf_get_task_mem(&qedf
->tasks
, 0);
2922 task_end
= qedf_get_task_mem(&qedf
->tasks
, MAX_TID_BLOCKS_FCOE
- 1);
2923 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Task context start=%p, "
2924 "end=%p block_size=%u.\n", task_start
, task_end
,
2928 * We need to write the number of BDs in the BDQ we've preallocated so
2929 * the f/w will do a prefetch and we'll get an unsolicited CQE when a
2932 qedf
->bdq_prod_idx
= QEDF_BDQ_SIZE
;
2933 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
2934 "Writing %d to primary and secondary BDQ doorbell registers.\n",
2935 qedf
->bdq_prod_idx
);
2936 writew(qedf
->bdq_prod_idx
, qedf
->bdq_primary_prod
);
2937 tmp
= readw(qedf
->bdq_primary_prod
);
2938 writew(qedf
->bdq_prod_idx
, qedf
->bdq_secondary_prod
);
2939 tmp
= readw(qedf
->bdq_secondary_prod
);
2941 qed_ops
->common
->set_power_state(qedf
->cdev
, PCI_D0
);
2943 /* Now that the dev_info struct has been filled in set the MAC
2946 ether_addr_copy(qedf
->mac
, qedf
->dev_info
.common
.hw_mac
);
2947 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "MAC address is %pM.\n",
2950 /* Set the WWNN and WWPN based on the MAC address */
2951 qedf
->wwnn
= fcoe_wwn_from_mac(qedf
->mac
, 1, 0);
2952 qedf
->wwpn
= fcoe_wwn_from_mac(qedf
->mac
, 2, 0);
2953 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "WWNN=%016llx "
2954 "WWPN=%016llx.\n", qedf
->wwnn
, qedf
->wwpn
);
2956 sprintf(host_buf
, "host_%d", host
->host_no
);
2957 qed_ops
->common
->set_id(qedf
->cdev
, host_buf
, QEDF_VERSION
);
2960 /* Set xid max values */
2961 qedf
->max_scsi_xid
= QEDF_MAX_SCSI_XID
;
2962 qedf
->max_els_xid
= QEDF_MAX_ELS_XID
;
2964 /* Allocate cmd mgr */
2965 qedf
->cmd_mgr
= qedf_cmd_mgr_alloc(qedf
);
2966 if (!qedf
->cmd_mgr
) {
2967 QEDF_ERR(&(qedf
->dbg_ctx
), "Failed to allocate cmd mgr.\n");
2971 if (mode
!= QEDF_MODE_RECOVERY
) {
2972 host
->transportt
= qedf_fc_transport_template
;
2973 host
->can_queue
= QEDF_MAX_ELS_XID
;
2974 host
->max_lun
= qedf_max_lun
;
2975 host
->max_cmd_len
= QEDF_MAX_CDB_LEN
;
2976 rc
= scsi_add_host(host
, &pdev
->dev
);
2981 memset(¶ms
, 0, sizeof(params
));
2983 ether_addr_copy(params
.ll2_mac_address
, qedf
->mac
);
2985 /* Start LL2 processing thread */
2986 snprintf(host_buf
, 20, "qedf_%d_ll2", host
->host_no
);
2988 create_singlethread_workqueue(host_buf
);
2989 if (!qedf
->ll2_recv_wq
) {
2990 QEDF_ERR(&(qedf
->dbg_ctx
), "Failed to LL2 workqueue.\n");
2994 #ifdef CONFIG_DEBUG_FS
2995 qedf_dbg_host_init(&(qedf
->dbg_ctx
), &qedf_debugfs_ops
,
3000 qed_ops
->ll2
->register_cb_ops(qedf
->cdev
, &qedf_ll2_cb_ops
, qedf
);
3001 rc
= qed_ops
->ll2
->start(qedf
->cdev
, ¶ms
);
3003 QEDF_ERR(&(qedf
->dbg_ctx
), "Could not start Light L2.\n");
3006 set_bit(QEDF_LL2_STARTED
, &qedf
->flags
);
3008 /* hw will be insterting vlan tag*/
3009 qedf
->vlan_hw_insert
= 1;
3013 * No need to setup fcoe_ctlr or fc_lport objects during recovery since
3014 * they were not reaped during the unload process.
3016 if (mode
!= QEDF_MODE_RECOVERY
) {
3017 /* Setup imbedded fcoe controller */
3018 qedf_fcoe_ctlr_setup(qedf
);
3021 rc
= qedf_lport_setup(qedf
);
3023 QEDF_ERR(&(qedf
->dbg_ctx
),
3024 "qedf_lport_setup failed.\n");
3029 sprintf(host_buf
, "qedf_%u_timer", qedf
->lport
->host
->host_no
);
3030 qedf
->timer_work_queue
=
3031 create_singlethread_workqueue(host_buf
);
3032 if (!qedf
->timer_work_queue
) {
3033 QEDF_ERR(&(qedf
->dbg_ctx
), "Failed to start timer "
3038 /* DPC workqueue is not reaped during recovery unload */
3039 if (mode
!= QEDF_MODE_RECOVERY
) {
3040 sprintf(host_buf
, "qedf_%u_dpc",
3041 qedf
->lport
->host
->host_no
);
3042 qedf
->dpc_wq
= create_singlethread_workqueue(host_buf
);
3046 * GRC dump and sysfs parameters are not reaped during the recovery
3049 if (mode
!= QEDF_MODE_RECOVERY
) {
3050 qedf
->grcdump_size
= qed_ops
->common
->dbg_grc_size(qedf
->cdev
);
3051 if (qedf
->grcdump_size
) {
3052 rc
= qedf_alloc_grc_dump_buf(&qedf
->grcdump
,
3053 qedf
->grcdump_size
);
3055 QEDF_ERR(&(qedf
->dbg_ctx
),
3056 "GRC Dump buffer alloc failed.\n");
3057 qedf
->grcdump
= NULL
;
3060 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
3061 "grcdump: addr=%p, size=%u.\n",
3062 qedf
->grcdump
, qedf
->grcdump_size
);
3064 qedf_create_sysfs_ctx_attr(qedf
);
3066 /* Initialize I/O tracing for this adapter */
3067 spin_lock_init(&qedf
->io_trace_lock
);
3068 qedf
->io_trace_idx
= 0;
3071 init_completion(&qedf
->flogi_compl
);
3073 memset(&link_params
, 0, sizeof(struct qed_link_params
));
3074 link_params
.link_up
= true;
3075 status
= qed_ops
->common
->set_link(qedf
->cdev
, &link_params
);
3077 QEDF_WARN(&(qedf
->dbg_ctx
), "set_link failed.\n");
3079 /* Start/restart discovery */
3080 if (mode
== QEDF_MODE_RECOVERY
)
3081 fcoe_ctlr_link_up(&qedf
->ctlr
);
3083 fc_fabric_login(lport
);
3089 if (qedf
->ll2_recv_wq
)
3090 destroy_workqueue(qedf
->ll2_recv_wq
);
3091 fc_remove_host(qedf
->lport
->host
);
3092 scsi_remove_host(qedf
->lport
->host
);
3093 #ifdef CONFIG_DEBUG_FS
3094 qedf_dbg_host_exit(&(qedf
->dbg_ctx
));
3097 qedf_cmd_mgr_free(qedf
->cmd_mgr
);
3099 qed_ops
->stop(qedf
->cdev
);
3101 qedf_free_fcoe_pf_param(qedf
);
3102 qedf_sync_free_irqs(qedf
);
3104 qed_ops
->common
->slowpath_stop(qedf
->cdev
);
3106 qed_ops
->common
->remove(qedf
->cdev
);
3108 scsi_host_put(lport
->host
);
3113 static int qedf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
3115 return __qedf_probe(pdev
, QEDF_MODE_NORMAL
);
3118 static void __qedf_remove(struct pci_dev
*pdev
, int mode
)
3120 struct qedf_ctx
*qedf
;
3123 QEDF_ERR(NULL
, "pdev is NULL.\n");
3127 qedf
= pci_get_drvdata(pdev
);
3130 * Prevent race where we're in board disable work and then try to
3133 if (test_bit(QEDF_UNLOADING
, &qedf
->flags
)) {
3134 QEDF_ERR(&qedf
->dbg_ctx
, "Already removing PCI function.\n");
3138 if (mode
!= QEDF_MODE_RECOVERY
)
3139 set_bit(QEDF_UNLOADING
, &qedf
->flags
);
3141 /* Logoff the fabric to upload all connections */
3142 if (mode
== QEDF_MODE_RECOVERY
)
3143 fcoe_ctlr_link_down(&qedf
->ctlr
);
3145 fc_fabric_logoff(qedf
->lport
);
3146 qedf_wait_for_upload(qedf
);
3148 #ifdef CONFIG_DEBUG_FS
3149 qedf_dbg_host_exit(&(qedf
->dbg_ctx
));
3152 /* Stop any link update handling */
3153 cancel_delayed_work_sync(&qedf
->link_update
);
3154 destroy_workqueue(qedf
->link_update_wq
);
3155 qedf
->link_update_wq
= NULL
;
3157 if (qedf
->timer_work_queue
)
3158 destroy_workqueue(qedf
->timer_work_queue
);
3161 clear_bit(QEDF_LL2_STARTED
, &qedf
->flags
);
3162 qed_ops
->ll2
->stop(qedf
->cdev
);
3163 if (qedf
->ll2_recv_wq
)
3164 destroy_workqueue(qedf
->ll2_recv_wq
);
3167 qedf_sync_free_irqs(qedf
);
3168 qedf_destroy_sb(qedf
);
3171 * During recovery don't destroy OS constructs that represent the
3174 if (mode
!= QEDF_MODE_RECOVERY
) {
3175 qedf_free_grc_dump_buf(&qedf
->grcdump
);
3176 qedf_remove_sysfs_ctx_attr(qedf
);
3178 /* Remove all SCSI/libfc/libfcoe structures */
3179 fcoe_ctlr_destroy(&qedf
->ctlr
);
3180 fc_lport_destroy(qedf
->lport
);
3181 fc_remove_host(qedf
->lport
->host
);
3182 scsi_remove_host(qedf
->lport
->host
);
3185 qedf_cmd_mgr_free(qedf
->cmd_mgr
);
3187 if (mode
!= QEDF_MODE_RECOVERY
) {
3188 fc_exch_mgr_free(qedf
->lport
);
3189 fc_lport_free_stats(qedf
->lport
);
3191 /* Wait for all vports to be reaped */
3192 qedf_wait_for_vport_destroy(qedf
);
3196 * Now that all connections have been uploaded we can stop the
3197 * rest of the qed operations
3199 qed_ops
->stop(qedf
->cdev
);
3201 if (mode
!= QEDF_MODE_RECOVERY
) {
3203 /* Stop general DPC handling */
3204 destroy_workqueue(qedf
->dpc_wq
);
3205 qedf
->dpc_wq
= NULL
;
3209 /* Final shutdown for the board */
3210 qedf_free_fcoe_pf_param(qedf
);
3211 if (mode
!= QEDF_MODE_RECOVERY
) {
3212 qed_ops
->common
->set_power_state(qedf
->cdev
, PCI_D0
);
3213 pci_set_drvdata(pdev
, NULL
);
3215 qed_ops
->common
->slowpath_stop(qedf
->cdev
);
3216 qed_ops
->common
->remove(qedf
->cdev
);
3218 mempool_destroy(qedf
->io_mempool
);
3220 /* Only reap the Scsi_host on a real removal */
3221 if (mode
!= QEDF_MODE_RECOVERY
)
3222 scsi_host_put(qedf
->lport
->host
);
3225 static void qedf_remove(struct pci_dev
*pdev
)
3227 /* Check to make sure this function wasn't already disabled */
3228 if (!atomic_read(&pdev
->enable_cnt
))
3231 __qedf_remove(pdev
, QEDF_MODE_NORMAL
);
3235 * Module Init/Remove
3238 static int __init
qedf_init(void)
3242 /* If debug=1 passed, set the default log mask */
3243 if (qedf_debug
== QEDF_LOG_DEFAULT
)
3244 qedf_debug
= QEDF_DEFAULT_LOG_MASK
;
3246 /* Print driver banner */
3247 QEDF_INFO(NULL
, QEDF_LOG_INFO
, "%s v%s.\n", QEDF_DESCR
,
3250 /* Create kmem_cache for qedf_io_work structs */
3251 qedf_io_work_cache
= kmem_cache_create("qedf_io_work_cache",
3252 sizeof(struct qedf_io_work
), 0, SLAB_HWCACHE_ALIGN
, NULL
);
3253 if (qedf_io_work_cache
== NULL
) {
3254 QEDF_ERR(NULL
, "qedf_io_work_cache is NULL.\n");
3257 QEDF_INFO(NULL
, QEDF_LOG_DISC
, "qedf_io_work_cache=%p.\n",
3258 qedf_io_work_cache
);
3260 qed_ops
= qed_get_fcoe_ops();
3262 QEDF_ERR(NULL
, "Failed to get qed fcoe operations\n");
3266 #ifdef CONFIG_DEBUG_FS
3267 qedf_dbg_init("qedf");
3270 qedf_fc_transport_template
=
3271 fc_attach_transport(&qedf_fc_transport_fn
);
3272 if (!qedf_fc_transport_template
) {
3273 QEDF_ERR(NULL
, "Could not register with FC transport\n");
3277 qedf_fc_vport_transport_template
=
3278 fc_attach_transport(&qedf_fc_vport_transport_fn
);
3279 if (!qedf_fc_vport_transport_template
) {
3280 QEDF_ERR(NULL
, "Could not register vport template with FC "
3285 qedf_io_wq
= create_workqueue("qedf_io_wq");
3287 QEDF_ERR(NULL
, "Could not create qedf_io_wq.\n");
3291 qedf_cb_ops
.get_login_failures
= qedf_get_login_failures
;
3293 ret
= pci_register_driver(&qedf_pci_driver
);
3295 QEDF_ERR(NULL
, "Failed to register driver\n");
3302 destroy_workqueue(qedf_io_wq
);
3304 fc_release_transport(qedf_fc_vport_transport_template
);
3306 fc_release_transport(qedf_fc_transport_template
);
3308 #ifdef CONFIG_DEBUG_FS
3316 static void __exit
qedf_cleanup(void)
3318 pci_unregister_driver(&qedf_pci_driver
);
3320 destroy_workqueue(qedf_io_wq
);
3322 fc_release_transport(qedf_fc_vport_transport_template
);
3323 fc_release_transport(qedf_fc_transport_template
);
3324 #ifdef CONFIG_DEBUG_FS
3329 kmem_cache_destroy(qedf_io_work_cache
);
3332 MODULE_LICENSE("GPL");
3333 MODULE_DESCRIPTION("QLogic QEDF 25/40/50/100Gb FCoE Driver");
3334 MODULE_AUTHOR("QLogic Corporation");
3335 MODULE_VERSION(QEDF_VERSION
);
3336 module_init(qedf_init
);
3337 module_exit(qedf_cleanup
);