2 * QLogic iSCSI 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
10 #include <linux/module.h>
11 #include <linux/pci.h>
12 #include <linux/kernel.h>
13 #include <linux/if_arp.h>
14 #include <scsi/iscsi_if.h>
15 #include <linux/inet.h>
17 #include <linux/list.h>
18 #include <linux/kthread.h>
20 #include <linux/if_vlan.h>
21 #include <linux/cpu.h>
22 #include <linux/iscsi_boot_sysfs.h>
24 #include <scsi/scsi_cmnd.h>
25 #include <scsi/scsi_device.h>
26 #include <scsi/scsi_eh.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi.h>
32 #include "qedi_iscsi.h"
34 static uint qedi_fw_debug;
35 module_param(qedi_fw_debug, uint, 0644);
36 MODULE_PARM_DESC(qedi_fw_debug, " Firmware debug level 0(default) to 3");
38 uint qedi_dbg_log = QEDI_LOG_WARN | QEDI_LOG_SCSI_TM;
39 module_param(qedi_dbg_log, uint, 0644);
40 MODULE_PARM_DESC(qedi_dbg_log, " Default debug level");
43 module_param(qedi_io_tracing, uint, 0644);
44 MODULE_PARM_DESC(qedi_io_tracing,
45 " Enable logging of SCSI requests/completions into trace buffer. (default off).");
47 const struct qed_iscsi_ops *qedi_ops;
48 static struct scsi_transport_template *qedi_scsi_transport;
49 static struct pci_driver qedi_pci_driver;
50 static DEFINE_PER_CPU(struct qedi_percpu_s, qedi_percpu);
51 static LIST_HEAD(qedi_udev_list);
52 /* Static function declaration */
53 static int qedi_alloc_global_queues(struct qedi_ctx *qedi);
54 static void qedi_free_global_queues(struct qedi_ctx *qedi);
55 static struct qedi_cmd *qedi_get_cmd_from_tid(struct qedi_ctx *qedi, u32 tid);
56 static void qedi_reset_uio_rings(struct qedi_uio_dev *udev);
57 static void qedi_ll2_free_skbs(struct qedi_ctx *qedi);
59 static int qedi_iscsi_event_cb(void *context, u8 fw_event_code, void *fw_handle)
61 struct qedi_ctx *qedi;
62 struct qedi_endpoint *qedi_ep;
63 struct async_data *data;
66 if (!context || !fw_handle) {
67 QEDI_ERR(NULL, "Recv event with ctx NULL\n");
71 qedi = (struct qedi_ctx *)context;
72 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
73 "Recv Event %d fw_handle %p\n", fw_event_code, fw_handle);
75 data = (struct async_data *)fw_handle;
76 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
77 "cid=0x%x tid=0x%x err-code=0x%x fw-dbg-param=0x%x\n",
78 data->cid, data->itid, data->error_code,
79 data->fw_debug_param);
81 qedi_ep = qedi->ep_tbl[data->cid];
84 QEDI_WARN(&qedi->dbg_ctx,
85 "Cannot process event, ep already disconnected, cid=0x%x\n",
91 switch (fw_event_code) {
92 case ISCSI_EVENT_TYPE_ASYN_CONNECT_COMPLETE:
93 if (qedi_ep->state == EP_STATE_OFLDCONN_START)
94 qedi_ep->state = EP_STATE_OFLDCONN_COMPL;
96 wake_up_interruptible(&qedi_ep->tcp_ofld_wait);
98 case ISCSI_EVENT_TYPE_ASYN_TERMINATE_DONE:
99 qedi_ep->state = EP_STATE_DISCONN_COMPL;
100 wake_up_interruptible(&qedi_ep->tcp_ofld_wait);
102 case ISCSI_EVENT_TYPE_ISCSI_CONN_ERROR:
103 qedi_process_iscsi_error(qedi_ep, data);
105 case ISCSI_EVENT_TYPE_ASYN_ABORT_RCVD:
106 case ISCSI_EVENT_TYPE_ASYN_SYN_RCVD:
107 case ISCSI_EVENT_TYPE_ASYN_MAX_RT_TIME:
108 case ISCSI_EVENT_TYPE_ASYN_MAX_RT_CNT:
109 case ISCSI_EVENT_TYPE_ASYN_MAX_KA_PROBES_CNT:
110 case ISCSI_EVENT_TYPE_ASYN_FIN_WAIT2:
111 case ISCSI_EVENT_TYPE_TCP_CONN_ERROR:
112 qedi_process_tcp_error(qedi_ep, data);
115 QEDI_ERR(&qedi->dbg_ctx, "Recv Unknown Event %u\n",
122 static int qedi_uio_open(struct uio_info *uinfo, struct inode *inode)
124 struct qedi_uio_dev *udev = uinfo->priv;
125 struct qedi_ctx *qedi = udev->qedi;
127 if (!capable(CAP_NET_ADMIN))
130 if (udev->uio_dev != -1)
134 udev->uio_dev = iminor(inode);
135 qedi_reset_uio_rings(udev);
136 set_bit(UIO_DEV_OPENED, &qedi->flags);
142 static int qedi_uio_close(struct uio_info *uinfo, struct inode *inode)
144 struct qedi_uio_dev *udev = uinfo->priv;
145 struct qedi_ctx *qedi = udev->qedi;
148 clear_bit(UIO_DEV_OPENED, &qedi->flags);
149 qedi_ll2_free_skbs(qedi);
153 static void __qedi_free_uio_rings(struct qedi_uio_dev *udev)
156 free_page((unsigned long)udev->uctrl);
160 if (udev->ll2_ring) {
161 free_page((unsigned long)udev->ll2_ring);
162 udev->ll2_ring = NULL;
166 free_pages((unsigned long)udev->ll2_buf, 2);
167 udev->ll2_buf = NULL;
171 static void __qedi_free_uio(struct qedi_uio_dev *udev)
173 uio_unregister_device(&udev->qedi_uinfo);
175 __qedi_free_uio_rings(udev);
177 pci_dev_put(udev->pdev);
181 static void qedi_free_uio(struct qedi_uio_dev *udev)
186 list_del_init(&udev->list);
187 __qedi_free_uio(udev);
190 static void qedi_reset_uio_rings(struct qedi_uio_dev *udev)
192 struct qedi_ctx *qedi = NULL;
193 struct qedi_uio_ctrl *uctrl = NULL;
198 spin_lock_bh(&qedi->ll2_lock);
199 uctrl->host_rx_cons = 0;
200 uctrl->hw_rx_prod = 0;
201 uctrl->hw_rx_bd_prod = 0;
202 uctrl->host_rx_bd_cons = 0;
204 memset(udev->ll2_ring, 0, udev->ll2_ring_size);
205 memset(udev->ll2_buf, 0, udev->ll2_buf_size);
206 spin_unlock_bh(&qedi->ll2_lock);
209 static int __qedi_alloc_uio_rings(struct qedi_uio_dev *udev)
213 if (udev->ll2_ring || udev->ll2_buf)
216 /* Memory for control area. */
217 udev->uctrl = (void *)get_zeroed_page(GFP_KERNEL);
221 /* Allocating memory for LL2 ring */
222 udev->ll2_ring_size = QEDI_PAGE_SIZE;
223 udev->ll2_ring = (void *)get_zeroed_page(GFP_KERNEL | __GFP_COMP);
224 if (!udev->ll2_ring) {
226 goto exit_alloc_ring;
229 /* Allocating memory for Tx/Rx pkt buffer */
230 udev->ll2_buf_size = TX_RX_RING * LL2_SINGLE_BUF_SIZE;
231 udev->ll2_buf_size = QEDI_PAGE_ALIGN(udev->ll2_buf_size);
232 udev->ll2_buf = (void *)__get_free_pages(GFP_KERNEL | __GFP_COMP |
234 if (!udev->ll2_buf) {
241 free_page((unsigned long)udev->ll2_ring);
242 udev->ll2_ring = NULL;
247 static int qedi_alloc_uio_rings(struct qedi_ctx *qedi)
249 struct qedi_uio_dev *udev = NULL;
252 list_for_each_entry(udev, &qedi_udev_list, list) {
253 if (udev->pdev == qedi->pdev) {
255 if (__qedi_alloc_uio_rings(udev)) {
264 udev = kzalloc(sizeof(*udev), GFP_KERNEL);
273 udev->pdev = qedi->pdev;
275 rc = __qedi_alloc_uio_rings(udev);
279 list_add(&udev->list, &qedi_udev_list);
281 pci_dev_get(udev->pdev);
284 udev->tx_pkt = udev->ll2_buf;
285 udev->rx_pkt = udev->ll2_buf + LL2_SINGLE_BUF_SIZE;
294 static int qedi_init_uio(struct qedi_ctx *qedi)
296 struct qedi_uio_dev *udev = qedi->udev;
297 struct uio_info *uinfo;
303 uinfo = &udev->qedi_uinfo;
305 uinfo->mem[0].addr = (unsigned long)udev->uctrl;
306 uinfo->mem[0].size = sizeof(struct qedi_uio_ctrl);
307 uinfo->mem[0].memtype = UIO_MEM_LOGICAL;
309 uinfo->mem[1].addr = (unsigned long)udev->ll2_ring;
310 uinfo->mem[1].size = udev->ll2_ring_size;
311 uinfo->mem[1].memtype = UIO_MEM_LOGICAL;
313 uinfo->mem[2].addr = (unsigned long)udev->ll2_buf;
314 uinfo->mem[2].size = udev->ll2_buf_size;
315 uinfo->mem[2].memtype = UIO_MEM_LOGICAL;
317 uinfo->name = "qedi_uio";
318 uinfo->version = QEDI_MODULE_VERSION;
319 uinfo->irq = UIO_IRQ_CUSTOM;
321 uinfo->open = qedi_uio_open;
322 uinfo->release = qedi_uio_close;
324 if (udev->uio_dev == -1) {
328 ret = uio_register_device(&udev->pdev->dev, uinfo);
330 QEDI_ERR(&qedi->dbg_ctx,
331 "UIO registration failed\n");
339 static int qedi_alloc_and_init_sb(struct qedi_ctx *qedi,
340 struct qed_sb_info *sb_info, u16 sb_id)
342 struct status_block *sb_virt;
346 sb_virt = dma_alloc_coherent(&qedi->pdev->dev,
347 sizeof(struct status_block), &sb_phys,
350 QEDI_ERR(&qedi->dbg_ctx,
351 "Status block allocation failed for id = %d.\n",
356 ret = qedi_ops->common->sb_init(qedi->cdev, sb_info, sb_virt, sb_phys,
357 sb_id, QED_SB_TYPE_STORAGE);
359 QEDI_ERR(&qedi->dbg_ctx,
360 "Status block initialization failed for id = %d.\n",
368 static void qedi_free_sb(struct qedi_ctx *qedi)
370 struct qed_sb_info *sb_info;
373 for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) {
374 sb_info = &qedi->sb_array[id];
375 if (sb_info->sb_virt)
376 dma_free_coherent(&qedi->pdev->dev,
377 sizeof(*sb_info->sb_virt),
378 (void *)sb_info->sb_virt,
383 static void qedi_free_fp(struct qedi_ctx *qedi)
385 kfree(qedi->fp_array);
386 kfree(qedi->sb_array);
389 static void qedi_destroy_fp(struct qedi_ctx *qedi)
395 static int qedi_alloc_fp(struct qedi_ctx *qedi)
399 qedi->fp_array = kcalloc(MIN_NUM_CPUS_MSIX(qedi),
400 sizeof(struct qedi_fastpath), GFP_KERNEL);
401 if (!qedi->fp_array) {
402 QEDI_ERR(&qedi->dbg_ctx,
403 "fastpath fp array allocation failed.\n");
407 qedi->sb_array = kcalloc(MIN_NUM_CPUS_MSIX(qedi),
408 sizeof(struct qed_sb_info), GFP_KERNEL);
409 if (!qedi->sb_array) {
410 QEDI_ERR(&qedi->dbg_ctx,
411 "fastpath sb array allocation failed.\n");
423 static void qedi_int_fp(struct qedi_ctx *qedi)
425 struct qedi_fastpath *fp;
428 memset(qedi->fp_array, 0, MIN_NUM_CPUS_MSIX(qedi) *
429 sizeof(*qedi->fp_array));
430 memset(qedi->sb_array, 0, MIN_NUM_CPUS_MSIX(qedi) *
431 sizeof(*qedi->sb_array));
433 for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) {
434 fp = &qedi->fp_array[id];
435 fp->sb_info = &qedi->sb_array[id];
438 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
441 /* fp_array[i] ---- irq cookie
442 * So init data which is needed in int ctx
447 static int qedi_prepare_fp(struct qedi_ctx *qedi)
449 struct qedi_fastpath *fp;
452 ret = qedi_alloc_fp(qedi);
458 for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) {
459 fp = &qedi->fp_array[id];
460 ret = qedi_alloc_and_init_sb(qedi, fp->sb_info, fp->sb_id);
462 QEDI_ERR(&qedi->dbg_ctx,
463 "SB allocation and initialization failed.\n");
478 static int qedi_setup_cid_que(struct qedi_ctx *qedi)
482 qedi->cid_que.cid_que_base = kmalloc_array(qedi->max_active_conns,
483 sizeof(u32), GFP_KERNEL);
484 if (!qedi->cid_que.cid_que_base)
487 qedi->cid_que.conn_cid_tbl = kmalloc_array(qedi->max_active_conns,
488 sizeof(struct qedi_conn *),
490 if (!qedi->cid_que.conn_cid_tbl) {
491 kfree(qedi->cid_que.cid_que_base);
492 qedi->cid_que.cid_que_base = NULL;
496 qedi->cid_que.cid_que = (u32 *)qedi->cid_que.cid_que_base;
497 qedi->cid_que.cid_q_prod_idx = 0;
498 qedi->cid_que.cid_q_cons_idx = 0;
499 qedi->cid_que.cid_q_max_idx = qedi->max_active_conns;
500 qedi->cid_que.cid_free_cnt = qedi->max_active_conns;
502 for (i = 0; i < qedi->max_active_conns; i++) {
503 qedi->cid_que.cid_que[i] = i;
504 qedi->cid_que.conn_cid_tbl[i] = NULL;
510 static void qedi_release_cid_que(struct qedi_ctx *qedi)
512 kfree(qedi->cid_que.cid_que_base);
513 qedi->cid_que.cid_que_base = NULL;
515 kfree(qedi->cid_que.conn_cid_tbl);
516 qedi->cid_que.conn_cid_tbl = NULL;
519 static int qedi_init_id_tbl(struct qedi_portid_tbl *id_tbl, u16 size,
520 u16 start_id, u16 next)
522 id_tbl->start = start_id;
525 spin_lock_init(&id_tbl->lock);
526 id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL);
533 static void qedi_free_id_tbl(struct qedi_portid_tbl *id_tbl)
535 kfree(id_tbl->table);
536 id_tbl->table = NULL;
539 int qedi_alloc_id(struct qedi_portid_tbl *id_tbl, u16 id)
544 if (id >= id_tbl->max)
547 spin_lock(&id_tbl->lock);
548 if (!test_bit(id, id_tbl->table)) {
549 set_bit(id, id_tbl->table);
552 spin_unlock(&id_tbl->lock);
556 u16 qedi_alloc_new_id(struct qedi_portid_tbl *id_tbl)
560 spin_lock(&id_tbl->lock);
561 id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next);
562 if (id >= id_tbl->max) {
563 id = QEDI_LOCAL_PORT_INVALID;
564 if (id_tbl->next != 0) {
565 id = find_first_zero_bit(id_tbl->table, id_tbl->next);
566 if (id >= id_tbl->next)
567 id = QEDI_LOCAL_PORT_INVALID;
571 if (id < id_tbl->max) {
572 set_bit(id, id_tbl->table);
573 id_tbl->next = (id + 1) & (id_tbl->max - 1);
577 spin_unlock(&id_tbl->lock);
582 void qedi_free_id(struct qedi_portid_tbl *id_tbl, u16 id)
584 if (id == QEDI_LOCAL_PORT_INVALID)
588 if (id >= id_tbl->max)
591 clear_bit(id, id_tbl->table);
594 static void qedi_cm_free_mem(struct qedi_ctx *qedi)
598 qedi_free_id_tbl(&qedi->lcl_port_tbl);
601 static int qedi_cm_alloc_mem(struct qedi_ctx *qedi)
605 qedi->ep_tbl = kzalloc((qedi->max_active_conns *
606 sizeof(struct qedi_endpoint *)), GFP_KERNEL);
609 port_id = prandom_u32() % QEDI_LOCAL_PORT_RANGE;
610 if (qedi_init_id_tbl(&qedi->lcl_port_tbl, QEDI_LOCAL_PORT_RANGE,
611 QEDI_LOCAL_PORT_MIN, port_id)) {
612 qedi_cm_free_mem(qedi);
619 static struct qedi_ctx *qedi_host_alloc(struct pci_dev *pdev)
621 struct Scsi_Host *shost;
622 struct qedi_ctx *qedi = NULL;
624 shost = iscsi_host_alloc(&qedi_host_template,
625 sizeof(struct qedi_ctx), 0);
627 QEDI_ERR(NULL, "Could not allocate shost\n");
628 goto exit_setup_shost;
631 shost->max_id = QEDI_MAX_ISCSI_CONNS_PER_HBA;
632 shost->max_channel = 0;
634 shost->max_cmd_len = 16;
635 shost->transportt = qedi_scsi_transport;
637 qedi = iscsi_host_priv(shost);
638 memset(qedi, 0, sizeof(*qedi));
640 qedi->dbg_ctx.host_no = shost->host_no;
642 qedi->dbg_ctx.pdev = pdev;
643 qedi->max_active_conns = ISCSI_MAX_SESS_PER_HBA;
644 qedi->max_sqes = QEDI_SQ_SIZE;
646 if (shost_use_blk_mq(shost))
647 shost->nr_hw_queues = MIN_NUM_CPUS_MSIX(qedi);
649 pci_set_drvdata(pdev, qedi);
655 static int qedi_ll2_rx(void *cookie, struct sk_buff *skb, u32 arg1, u32 arg2)
657 struct qedi_ctx *qedi = (struct qedi_ctx *)cookie;
658 struct qedi_uio_dev *udev;
659 struct qedi_uio_ctrl *uctrl;
660 struct skb_work_list *work;
664 QEDI_ERR(NULL, "qedi is NULL\n");
668 if (!test_bit(UIO_DEV_OPENED, &qedi->flags)) {
669 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_UIO,
670 "UIO DEV is not opened\n");
678 work = kzalloc(sizeof(*work), GFP_ATOMIC);
680 QEDI_WARN(&qedi->dbg_ctx,
681 "Could not allocate work so dropping frame.\n");
686 INIT_LIST_HEAD(&work->list);
689 if (skb_vlan_tag_present(skb))
690 work->vlan_id = skb_vlan_tag_get(skb);
693 __vlan_insert_tag(work->skb, htons(ETH_P_8021Q), work->vlan_id);
695 spin_lock_bh(&qedi->ll2_lock);
696 list_add_tail(&work->list, &qedi->ll2_skb_list);
698 ++uctrl->hw_rx_prod_cnt;
699 prod = (uctrl->hw_rx_prod + 1) % RX_RING;
700 if (prod != uctrl->host_rx_cons) {
701 uctrl->hw_rx_prod = prod;
702 spin_unlock_bh(&qedi->ll2_lock);
703 wake_up_process(qedi->ll2_recv_thread);
707 spin_unlock_bh(&qedi->ll2_lock);
711 /* map this skb to iscsiuio mmaped region */
712 static int qedi_ll2_process_skb(struct qedi_ctx *qedi, struct sk_buff *skb,
715 struct qedi_uio_dev *udev = NULL;
716 struct qedi_uio_ctrl *uctrl = NULL;
717 struct qedi_rx_bd rxbd;
718 struct qedi_rx_bd *p_rxbd;
724 QEDI_ERR(NULL, "qedi is NULL\n");
730 pkt = udev->rx_pkt + (uctrl->hw_rx_prod * LL2_SINGLE_BUF_SIZE);
731 len = min_t(u32, skb->len, (u32)LL2_SINGLE_BUF_SIZE);
732 memcpy(pkt, skb->data, len);
734 memset(&rxbd, 0, sizeof(rxbd));
735 rxbd.rx_pkt_index = uctrl->hw_rx_prod;
736 rxbd.rx_pkt_len = len;
737 rxbd.vlan_id = vlan_id;
739 uctrl->hw_rx_bd_prod = (uctrl->hw_rx_bd_prod + 1) % QEDI_NUM_RX_BD;
740 rx_bd_prod = uctrl->hw_rx_bd_prod;
741 p_rxbd = (struct qedi_rx_bd *)udev->ll2_ring;
742 p_rxbd += rx_bd_prod;
744 memcpy(p_rxbd, &rxbd, sizeof(rxbd));
746 /* notify the iscsiuio about new packet */
747 uio_event_notify(&udev->qedi_uinfo);
752 static void qedi_ll2_free_skbs(struct qedi_ctx *qedi)
754 struct skb_work_list *work, *work_tmp;
756 spin_lock_bh(&qedi->ll2_lock);
757 list_for_each_entry_safe(work, work_tmp, &qedi->ll2_skb_list, list) {
758 list_del(&work->list);
760 kfree_skb(work->skb);
763 spin_unlock_bh(&qedi->ll2_lock);
766 static int qedi_ll2_recv_thread(void *arg)
768 struct qedi_ctx *qedi = (struct qedi_ctx *)arg;
769 struct skb_work_list *work, *work_tmp;
771 set_user_nice(current, -20);
773 while (!kthread_should_stop()) {
774 spin_lock_bh(&qedi->ll2_lock);
775 list_for_each_entry_safe(work, work_tmp, &qedi->ll2_skb_list,
777 list_del(&work->list);
778 qedi_ll2_process_skb(qedi, work->skb, work->vlan_id);
779 kfree_skb(work->skb);
782 set_current_state(TASK_INTERRUPTIBLE);
783 spin_unlock_bh(&qedi->ll2_lock);
787 __set_current_state(TASK_RUNNING);
791 static int qedi_set_iscsi_pf_param(struct qedi_ctx *qedi)
797 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, "Min number of MSIX %d\n",
798 MIN_NUM_CPUS_MSIX(qedi));
800 num_sq_pages = (MAX_OUSTANDING_TASKS_PER_CON * 8) / PAGE_SIZE;
802 qedi->num_queues = MIN_NUM_CPUS_MSIX(qedi);
804 memset(&qedi->pf_params.iscsi_pf_params, 0,
805 sizeof(qedi->pf_params.iscsi_pf_params));
807 qedi->p_cpuq = pci_alloc_consistent(qedi->pdev,
808 qedi->num_queues * sizeof(struct qedi_glbl_q_params),
811 QEDI_ERR(&qedi->dbg_ctx, "pci_alloc_consistent fail\n");
816 rval = qedi_alloc_global_queues(qedi);
818 QEDI_ERR(&qedi->dbg_ctx, "Global queue allocation failed.\n");
823 qedi->pf_params.iscsi_pf_params.num_cons = QEDI_MAX_ISCSI_CONNS_PER_HBA;
824 qedi->pf_params.iscsi_pf_params.num_tasks = QEDI_MAX_ISCSI_TASK;
825 qedi->pf_params.iscsi_pf_params.half_way_close_timeout = 10;
826 qedi->pf_params.iscsi_pf_params.num_sq_pages_in_ring = num_sq_pages;
827 qedi->pf_params.iscsi_pf_params.num_r2tq_pages_in_ring = num_sq_pages;
828 qedi->pf_params.iscsi_pf_params.num_uhq_pages_in_ring = num_sq_pages;
829 qedi->pf_params.iscsi_pf_params.num_queues = qedi->num_queues;
830 qedi->pf_params.iscsi_pf_params.debug_mode = qedi_fw_debug;
831 qedi->pf_params.iscsi_pf_params.two_msl_timer = 4000;
832 qedi->pf_params.iscsi_pf_params.max_fin_rt = 2;
834 for (log_page_size = 0 ; log_page_size < 32 ; log_page_size++) {
835 if ((1 << log_page_size) == PAGE_SIZE)
838 qedi->pf_params.iscsi_pf_params.log_page_size = log_page_size;
840 qedi->pf_params.iscsi_pf_params.glbl_q_params_addr =
841 (u64)qedi->hw_p_cpuq;
843 /* RQ BDQ initializations.
844 * rq_num_entries: suggested value for Initiator is 16 (4KB RQ)
845 * rqe_log_size: 8 for 256B RQE
847 qedi->pf_params.iscsi_pf_params.rqe_log_size = 8;
848 /* BDQ address and size */
849 qedi->pf_params.iscsi_pf_params.bdq_pbl_base_addr[BDQ_ID_RQ] =
850 qedi->bdq_pbl_list_dma;
851 qedi->pf_params.iscsi_pf_params.bdq_pbl_num_entries[BDQ_ID_RQ] =
852 qedi->bdq_pbl_list_num_entries;
853 qedi->pf_params.iscsi_pf_params.rq_buffer_size = QEDI_BDQ_BUF_SIZE;
855 /* cq_num_entries: num_tasks + rq_num_entries */
856 qedi->pf_params.iscsi_pf_params.cq_num_entries = 2048;
858 qedi->pf_params.iscsi_pf_params.gl_rq_pi = QEDI_PROTO_CQ_PROD_IDX;
859 qedi->pf_params.iscsi_pf_params.gl_cmd_pi = 1;
860 qedi->pf_params.iscsi_pf_params.ooo_enable = 1;
866 /* Free DMA coherent memory for array of queue pointers we pass to qed */
867 static void qedi_free_iscsi_pf_param(struct qedi_ctx *qedi)
872 size = qedi->num_queues * sizeof(struct qedi_glbl_q_params);
873 pci_free_consistent(qedi->pdev, size, qedi->p_cpuq,
877 qedi_free_global_queues(qedi);
879 kfree(qedi->global_queues);
882 static void qedi_link_update(void *dev, struct qed_link_output *link)
884 struct qedi_ctx *qedi = (struct qedi_ctx *)dev;
887 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, "Link Up event.\n");
888 atomic_set(&qedi->link_state, QEDI_LINK_UP);
890 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
891 "Link Down event.\n");
892 atomic_set(&qedi->link_state, QEDI_LINK_DOWN);
896 static struct qed_iscsi_cb_ops qedi_cb_ops = {
898 .link_update = qedi_link_update,
902 static int qedi_queue_cqe(struct qedi_ctx *qedi, union iscsi_cqe *cqe,
903 u16 que_idx, struct qedi_percpu_s *p)
905 struct qedi_work *qedi_work;
906 struct qedi_conn *q_conn;
907 struct iscsi_conn *conn;
908 struct qedi_cmd *qedi_cmd;
912 iscsi_cid = cqe->cqe_common.conn_id;
913 q_conn = qedi->cid_que.conn_cid_tbl[iscsi_cid];
915 QEDI_WARN(&qedi->dbg_ctx,
916 "Session no longer exists for cid=0x%x!!\n",
920 conn = q_conn->cls_conn->dd_data;
922 switch (cqe->cqe_common.cqe_type) {
923 case ISCSI_CQE_TYPE_SOLICITED:
924 case ISCSI_CQE_TYPE_SOLICITED_WITH_SENSE:
925 qedi_cmd = qedi_get_cmd_from_tid(qedi, cqe->cqe_solicited.itid);
930 INIT_LIST_HEAD(&qedi_cmd->cqe_work.list);
931 qedi_cmd->cqe_work.qedi = qedi;
932 memcpy(&qedi_cmd->cqe_work.cqe, cqe, sizeof(union iscsi_cqe));
933 qedi_cmd->cqe_work.que_idx = que_idx;
934 qedi_cmd->cqe_work.is_solicited = true;
935 list_add_tail(&qedi_cmd->cqe_work.list, &p->work_list);
937 case ISCSI_CQE_TYPE_UNSOLICITED:
938 case ISCSI_CQE_TYPE_DUMMY:
939 case ISCSI_CQE_TYPE_TASK_CLEANUP:
940 qedi_work = kzalloc(sizeof(*qedi_work), GFP_ATOMIC);
945 INIT_LIST_HEAD(&qedi_work->list);
946 qedi_work->qedi = qedi;
947 memcpy(&qedi_work->cqe, cqe, sizeof(union iscsi_cqe));
948 qedi_work->que_idx = que_idx;
949 qedi_work->is_solicited = false;
950 list_add_tail(&qedi_work->list, &p->work_list);
954 QEDI_ERR(&qedi->dbg_ctx, "FW Error cqe.\n");
959 static bool qedi_process_completions(struct qedi_fastpath *fp)
961 struct qedi_ctx *qedi = fp->qedi;
962 struct qed_sb_info *sb_info = fp->sb_info;
963 struct status_block *sb = sb_info->sb_virt;
964 struct qedi_percpu_s *p = NULL;
965 struct global_queue *que;
968 union iscsi_cqe *cqe;
972 /* Get the current firmware producer index */
973 prod_idx = sb->pi_array[QEDI_PROTO_CQ_PROD_IDX];
975 if (prod_idx >= QEDI_CQ_SIZE)
976 prod_idx = prod_idx % QEDI_CQ_SIZE;
978 que = qedi->global_queues[fp->sb_id];
979 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_IO,
980 "Before: global queue=%p prod_idx=%d cons_idx=%d, sb_id=%d\n",
981 que, prod_idx, que->cq_cons_idx, fp->sb_id);
983 qedi->intr_cpu = fp->sb_id;
984 cpu = smp_processor_id();
985 p = &per_cpu(qedi_percpu, cpu);
987 if (unlikely(!p->iothread))
990 spin_lock_irqsave(&p->p_work_lock, flags);
991 while (que->cq_cons_idx != prod_idx) {
992 cqe = &que->cq[que->cq_cons_idx];
994 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_IO,
995 "cqe=%p prod_idx=%d cons_idx=%d.\n",
996 cqe, prod_idx, que->cq_cons_idx);
998 ret = qedi_queue_cqe(qedi, cqe, fp->sb_id, p);
1003 if (que->cq_cons_idx == QEDI_CQ_SIZE)
1004 que->cq_cons_idx = 0;
1006 wake_up_process(p->iothread);
1007 spin_unlock_irqrestore(&p->p_work_lock, flags);
1012 static bool qedi_fp_has_work(struct qedi_fastpath *fp)
1014 struct qedi_ctx *qedi = fp->qedi;
1015 struct global_queue *que;
1016 struct qed_sb_info *sb_info = fp->sb_info;
1017 struct status_block *sb = sb_info->sb_virt;
1022 /* Get the current firmware producer index */
1023 prod_idx = sb->pi_array[QEDI_PROTO_CQ_PROD_IDX];
1025 /* Get the pointer to the global CQ this completion is on */
1026 que = qedi->global_queues[fp->sb_id];
1028 /* prod idx wrap around uint16 */
1029 if (prod_idx >= QEDI_CQ_SIZE)
1030 prod_idx = prod_idx % QEDI_CQ_SIZE;
1032 return (que->cq_cons_idx != prod_idx);
1035 /* MSI-X fastpath handler code */
1036 static irqreturn_t qedi_msix_handler(int irq, void *dev_id)
1038 struct qedi_fastpath *fp = dev_id;
1039 struct qedi_ctx *qedi = fp->qedi;
1040 bool wake_io_thread = true;
1042 qed_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0);
1045 wake_io_thread = qedi_process_completions(fp);
1046 if (wake_io_thread) {
1047 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
1048 "process already running\n");
1051 if (qedi_fp_has_work(fp) == 0)
1052 qed_sb_update_sb_idx(fp->sb_info);
1054 /* Check for more work */
1057 if (qedi_fp_has_work(fp) == 0)
1058 qed_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
1065 /* simd handler for MSI/INTa */
1066 static void qedi_simd_int_handler(void *cookie)
1068 /* Cookie is qedi_ctx struct */
1069 struct qedi_ctx *qedi = (struct qedi_ctx *)cookie;
1071 QEDI_WARN(&qedi->dbg_ctx, "qedi=%p.\n", qedi);
1074 #define QEDI_SIMD_HANDLER_NUM 0
1075 static void qedi_sync_free_irqs(struct qedi_ctx *qedi)
1079 if (qedi->int_info.msix_cnt) {
1080 for (i = 0; i < qedi->int_info.used_cnt; i++) {
1081 synchronize_irq(qedi->int_info.msix[i].vector);
1082 irq_set_affinity_hint(qedi->int_info.msix[i].vector,
1084 free_irq(qedi->int_info.msix[i].vector,
1085 &qedi->fp_array[i]);
1088 qedi_ops->common->simd_handler_clean(qedi->cdev,
1089 QEDI_SIMD_HANDLER_NUM);
1092 qedi->int_info.used_cnt = 0;
1093 qedi_ops->common->set_fp_int(qedi->cdev, 0);
1096 static int qedi_request_msix_irq(struct qedi_ctx *qedi)
1100 cpu = cpumask_first(cpu_online_mask);
1101 for (i = 0; i < MIN_NUM_CPUS_MSIX(qedi); i++) {
1102 rc = request_irq(qedi->int_info.msix[i].vector,
1103 qedi_msix_handler, 0, "qedi",
1104 &qedi->fp_array[i]);
1107 QEDI_WARN(&qedi->dbg_ctx, "request_irq failed.\n");
1108 qedi_sync_free_irqs(qedi);
1111 qedi->int_info.used_cnt++;
1112 rc = irq_set_affinity_hint(qedi->int_info.msix[i].vector,
1114 cpu = cpumask_next(cpu, cpu_online_mask);
1120 static int qedi_setup_int(struct qedi_ctx *qedi)
1124 rc = qedi_ops->common->set_fp_int(qedi->cdev, num_online_cpus());
1125 rc = qedi_ops->common->get_fp_int(qedi->cdev, &qedi->int_info);
1127 goto exit_setup_int;
1129 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
1130 "Number of msix_cnt = 0x%x num of cpus = 0x%x\n",
1131 qedi->int_info.msix_cnt, num_online_cpus());
1133 if (qedi->int_info.msix_cnt) {
1134 rc = qedi_request_msix_irq(qedi);
1135 goto exit_setup_int;
1137 qedi_ops->common->simd_handler_config(qedi->cdev, &qedi,
1138 QEDI_SIMD_HANDLER_NUM,
1139 qedi_simd_int_handler);
1140 qedi->int_info.used_cnt = 1;
1147 static void qedi_free_nvm_iscsi_cfg(struct qedi_ctx *qedi)
1149 if (qedi->iscsi_cfg)
1150 dma_free_coherent(&qedi->pdev->dev,
1151 sizeof(struct nvm_iscsi_cfg),
1152 qedi->iscsi_cfg, qedi->nvm_buf_dma);
1155 static int qedi_alloc_nvm_iscsi_cfg(struct qedi_ctx *qedi)
1157 qedi->iscsi_cfg = dma_zalloc_coherent(&qedi->pdev->dev,
1158 sizeof(struct nvm_iscsi_cfg),
1159 &qedi->nvm_buf_dma, GFP_KERNEL);
1160 if (!qedi->iscsi_cfg) {
1161 QEDI_ERR(&qedi->dbg_ctx, "Could not allocate NVM BUF.\n");
1164 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1165 "NVM BUF addr=0x%p dma=0x%llx.\n", qedi->iscsi_cfg,
1171 static void qedi_free_bdq(struct qedi_ctx *qedi)
1175 if (qedi->bdq_pbl_list)
1176 dma_free_coherent(&qedi->pdev->dev, PAGE_SIZE,
1177 qedi->bdq_pbl_list, qedi->bdq_pbl_list_dma);
1180 dma_free_coherent(&qedi->pdev->dev, qedi->bdq_pbl_mem_size,
1181 qedi->bdq_pbl, qedi->bdq_pbl_dma);
1183 for (i = 0; i < QEDI_BDQ_NUM; i++) {
1184 if (qedi->bdq[i].buf_addr) {
1185 dma_free_coherent(&qedi->pdev->dev, QEDI_BDQ_BUF_SIZE,
1186 qedi->bdq[i].buf_addr,
1187 qedi->bdq[i].buf_dma);
1192 static void qedi_free_global_queues(struct qedi_ctx *qedi)
1195 struct global_queue **gl = qedi->global_queues;
1197 for (i = 0; i < qedi->num_queues; i++) {
1202 dma_free_coherent(&qedi->pdev->dev, gl[i]->cq_mem_size,
1203 gl[i]->cq, gl[i]->cq_dma);
1205 dma_free_coherent(&qedi->pdev->dev, gl[i]->cq_pbl_size,
1206 gl[i]->cq_pbl, gl[i]->cq_pbl_dma);
1210 qedi_free_bdq(qedi);
1211 qedi_free_nvm_iscsi_cfg(qedi);
1214 static int qedi_alloc_bdq(struct qedi_ctx *qedi)
1217 struct scsi_bd *pbl;
1221 /* Alloc dma memory for BDQ buffers */
1222 for (i = 0; i < QEDI_BDQ_NUM; i++) {
1223 qedi->bdq[i].buf_addr =
1224 dma_alloc_coherent(&qedi->pdev->dev,
1226 &qedi->bdq[i].buf_dma,
1228 if (!qedi->bdq[i].buf_addr) {
1229 QEDI_ERR(&qedi->dbg_ctx,
1230 "Could not allocate BDQ buffer %d.\n", i);
1235 /* Alloc dma memory for BDQ page buffer list */
1236 qedi->bdq_pbl_mem_size = QEDI_BDQ_NUM * sizeof(struct scsi_bd);
1237 qedi->bdq_pbl_mem_size = ALIGN(qedi->bdq_pbl_mem_size, PAGE_SIZE);
1238 qedi->rq_num_entries = qedi->bdq_pbl_mem_size / sizeof(struct scsi_bd);
1240 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN, "rq_num_entries = %d.\n",
1241 qedi->rq_num_entries);
1243 qedi->bdq_pbl = dma_alloc_coherent(&qedi->pdev->dev,
1244 qedi->bdq_pbl_mem_size,
1245 &qedi->bdq_pbl_dma, GFP_KERNEL);
1246 if (!qedi->bdq_pbl) {
1247 QEDI_ERR(&qedi->dbg_ctx, "Could not allocate BDQ PBL.\n");
1252 * Populate BDQ PBL with physical and virtual address of individual
1255 pbl = (struct scsi_bd *)qedi->bdq_pbl;
1256 for (i = 0; i < QEDI_BDQ_NUM; i++) {
1258 cpu_to_le32(QEDI_U64_HI(qedi->bdq[i].buf_dma));
1260 cpu_to_le32(QEDI_U64_LO(qedi->bdq[i].buf_dma));
1261 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1262 "pbl [0x%p] pbl->address hi [0x%llx] lo [0x%llx], idx [%d]\n",
1263 pbl, pbl->address.hi, pbl->address.lo, i);
1265 pbl->opaque.lo = cpu_to_le32(QEDI_U64_LO(i));
1269 /* Allocate list of PBL pages */
1270 qedi->bdq_pbl_list = dma_alloc_coherent(&qedi->pdev->dev,
1272 &qedi->bdq_pbl_list_dma,
1274 if (!qedi->bdq_pbl_list) {
1275 QEDI_ERR(&qedi->dbg_ctx,
1276 "Could not allocate list of PBL pages.\n");
1279 memset(qedi->bdq_pbl_list, 0, PAGE_SIZE);
1282 * Now populate PBL list with pages that contain pointers to the
1283 * individual buffers.
1285 qedi->bdq_pbl_list_num_entries = qedi->bdq_pbl_mem_size / PAGE_SIZE;
1286 list = (u64 *)qedi->bdq_pbl_list;
1287 page = qedi->bdq_pbl_list_dma;
1288 for (i = 0; i < qedi->bdq_pbl_list_num_entries; i++) {
1289 *list = qedi->bdq_pbl_dma;
1297 static int qedi_alloc_global_queues(struct qedi_ctx *qedi)
1307 * Number of global queues (CQ / RQ). This should
1308 * be <= number of available MSIX vectors for the PF
1310 if (!qedi->num_queues) {
1311 QEDI_ERR(&qedi->dbg_ctx, "No MSI-X vectors available!\n");
1315 /* Make sure we allocated the PBL that will contain the physical
1316 * addresses of our queues
1318 if (!qedi->p_cpuq) {
1320 goto mem_alloc_failure;
1323 qedi->global_queues = kzalloc((sizeof(struct global_queue *) *
1324 qedi->num_queues), GFP_KERNEL);
1325 if (!qedi->global_queues) {
1326 QEDI_ERR(&qedi->dbg_ctx,
1327 "Unable to allocate global queues array ptr memory\n");
1330 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
1331 "qedi->global_queues=%p.\n", qedi->global_queues);
1333 /* Allocate DMA coherent buffers for BDQ */
1334 rc = qedi_alloc_bdq(qedi);
1336 goto mem_alloc_failure;
1338 /* Allocate DMA coherent buffers for NVM_ISCSI_CFG */
1339 rc = qedi_alloc_nvm_iscsi_cfg(qedi);
1341 goto mem_alloc_failure;
1343 /* Allocate a CQ and an associated PBL for each MSI-X
1346 for (i = 0; i < qedi->num_queues; i++) {
1347 qedi->global_queues[i] =
1348 kzalloc(sizeof(*qedi->global_queues[0]),
1350 if (!qedi->global_queues[i]) {
1351 QEDI_ERR(&qedi->dbg_ctx,
1352 "Unable to allocation global queue %d.\n", i);
1353 goto mem_alloc_failure;
1356 qedi->global_queues[i]->cq_mem_size =
1357 (QEDI_CQ_SIZE + 8) * sizeof(union iscsi_cqe);
1358 qedi->global_queues[i]->cq_mem_size =
1359 (qedi->global_queues[i]->cq_mem_size +
1360 (QEDI_PAGE_SIZE - 1));
1362 qedi->global_queues[i]->cq_pbl_size =
1363 (qedi->global_queues[i]->cq_mem_size /
1364 QEDI_PAGE_SIZE) * sizeof(void *);
1365 qedi->global_queues[i]->cq_pbl_size =
1366 (qedi->global_queues[i]->cq_pbl_size +
1367 (QEDI_PAGE_SIZE - 1));
1369 qedi->global_queues[i]->cq =
1370 dma_alloc_coherent(&qedi->pdev->dev,
1371 qedi->global_queues[i]->cq_mem_size,
1372 &qedi->global_queues[i]->cq_dma,
1375 if (!qedi->global_queues[i]->cq) {
1376 QEDI_WARN(&qedi->dbg_ctx,
1377 "Could not allocate cq.\n");
1379 goto mem_alloc_failure;
1381 memset(qedi->global_queues[i]->cq, 0,
1382 qedi->global_queues[i]->cq_mem_size);
1384 qedi->global_queues[i]->cq_pbl =
1385 dma_alloc_coherent(&qedi->pdev->dev,
1386 qedi->global_queues[i]->cq_pbl_size,
1387 &qedi->global_queues[i]->cq_pbl_dma,
1390 if (!qedi->global_queues[i]->cq_pbl) {
1391 QEDI_WARN(&qedi->dbg_ctx,
1392 "Could not allocate cq PBL.\n");
1394 goto mem_alloc_failure;
1396 memset(qedi->global_queues[i]->cq_pbl, 0,
1397 qedi->global_queues[i]->cq_pbl_size);
1400 num_pages = qedi->global_queues[i]->cq_mem_size /
1402 page = qedi->global_queues[i]->cq_dma;
1403 pbl = (u32 *)qedi->global_queues[i]->cq_pbl;
1405 while (num_pages--) {
1408 *pbl = (u32)((u64)page >> 32);
1410 page += QEDI_PAGE_SIZE;
1414 list = (u32 *)qedi->p_cpuq;
1417 * The list is built as follows: CQ#0 PBL pointer, RQ#0 PBL pointer,
1418 * CQ#1 PBL pointer, RQ#1 PBL pointer, etc. Each PBL pointer points
1419 * to the physical address which contains an array of pointers to the
1420 * physical addresses of the specific queue pages.
1422 for (i = 0; i < qedi->num_queues; i++) {
1423 *list = (u32)qedi->global_queues[i]->cq_pbl_dma;
1425 *list = (u32)((u64)qedi->global_queues[i]->cq_pbl_dma >> 32);
1430 *list = (u32)((u64)0 >> 32);
1437 qedi_free_global_queues(qedi);
1441 int qedi_alloc_sq(struct qedi_ctx *qedi, struct qedi_endpoint *ep)
1451 /* Calculate appropriate queue and PBL sizes */
1452 ep->sq_mem_size = QEDI_SQ_SIZE * sizeof(struct iscsi_wqe);
1453 ep->sq_mem_size += QEDI_PAGE_SIZE - 1;
1455 ep->sq_pbl_size = (ep->sq_mem_size / QEDI_PAGE_SIZE) * sizeof(void *);
1456 ep->sq_pbl_size = ep->sq_pbl_size + QEDI_PAGE_SIZE;
1458 ep->sq = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_mem_size,
1459 &ep->sq_dma, GFP_KERNEL);
1461 QEDI_WARN(&qedi->dbg_ctx,
1462 "Could not allocate send queue.\n");
1466 memset(ep->sq, 0, ep->sq_mem_size);
1468 ep->sq_pbl = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size,
1469 &ep->sq_pbl_dma, GFP_KERNEL);
1471 QEDI_WARN(&qedi->dbg_ctx,
1472 "Could not allocate send queue PBL.\n");
1476 memset(ep->sq_pbl, 0, ep->sq_pbl_size);
1479 num_pages = ep->sq_mem_size / QEDI_PAGE_SIZE;
1481 pbl = (u32 *)ep->sq_pbl;
1483 while (num_pages--) {
1486 *pbl = (u32)((u64)page >> 32);
1488 page += QEDI_PAGE_SIZE;
1494 dma_free_coherent(&qedi->pdev->dev, ep->sq_mem_size, ep->sq,
1500 void qedi_free_sq(struct qedi_ctx *qedi, struct qedi_endpoint *ep)
1503 dma_free_coherent(&qedi->pdev->dev, ep->sq_pbl_size, ep->sq_pbl,
1506 dma_free_coherent(&qedi->pdev->dev, ep->sq_mem_size, ep->sq,
1510 int qedi_get_task_idx(struct qedi_ctx *qedi)
1515 tmp_idx = find_first_zero_bit(qedi->task_idx_map,
1516 MAX_ISCSI_TASK_ENTRIES);
1518 if (tmp_idx >= MAX_ISCSI_TASK_ENTRIES) {
1519 QEDI_ERR(&qedi->dbg_ctx, "FW task context pool is full.\n");
1524 if (test_and_set_bit(tmp_idx, qedi->task_idx_map))
1531 void qedi_clear_task_idx(struct qedi_ctx *qedi, int idx)
1533 if (!test_and_clear_bit(idx, qedi->task_idx_map))
1534 QEDI_ERR(&qedi->dbg_ctx,
1535 "FW task context, already cleared, tid=0x%x\n", idx);
1538 void qedi_update_itt_map(struct qedi_ctx *qedi, u32 tid, u32 proto_itt,
1539 struct qedi_cmd *cmd)
1541 qedi->itt_map[tid].itt = proto_itt;
1542 qedi->itt_map[tid].p_cmd = cmd;
1544 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1545 "update itt map tid=0x%x, with proto itt=0x%x\n", tid,
1546 qedi->itt_map[tid].itt);
1549 void qedi_get_task_tid(struct qedi_ctx *qedi, u32 itt, s16 *tid)
1553 for (i = 0; i < MAX_ISCSI_TASK_ENTRIES; i++) {
1554 if (qedi->itt_map[i].itt == itt) {
1556 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1557 "Ref itt=0x%x, found at tid=0x%x\n",
1566 void qedi_get_proto_itt(struct qedi_ctx *qedi, u32 tid, u32 *proto_itt)
1568 *proto_itt = qedi->itt_map[tid].itt;
1569 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
1570 "Get itt map tid [0x%x with proto itt[0x%x]",
1574 struct qedi_cmd *qedi_get_cmd_from_tid(struct qedi_ctx *qedi, u32 tid)
1576 struct qedi_cmd *cmd = NULL;
1578 if (tid > MAX_ISCSI_TASK_ENTRIES)
1581 cmd = qedi->itt_map[tid].p_cmd;
1582 if (cmd->task_id != tid)
1585 qedi->itt_map[tid].p_cmd = NULL;
1590 static int qedi_alloc_itt(struct qedi_ctx *qedi)
1592 qedi->itt_map = kcalloc(MAX_ISCSI_TASK_ENTRIES,
1593 sizeof(struct qedi_itt_map), GFP_KERNEL);
1594 if (!qedi->itt_map) {
1595 QEDI_ERR(&qedi->dbg_ctx,
1596 "Unable to allocate itt map array memory\n");
1602 static void qedi_free_itt(struct qedi_ctx *qedi)
1604 kfree(qedi->itt_map);
1607 static struct qed_ll2_cb_ops qedi_ll2_cb_ops = {
1608 .rx_cb = qedi_ll2_rx,
1612 static int qedi_percpu_io_thread(void *arg)
1614 struct qedi_percpu_s *p = arg;
1615 struct qedi_work *work, *tmp;
1616 unsigned long flags;
1617 LIST_HEAD(work_list);
1619 set_user_nice(current, -20);
1621 while (!kthread_should_stop()) {
1622 spin_lock_irqsave(&p->p_work_lock, flags);
1623 while (!list_empty(&p->work_list)) {
1624 list_splice_init(&p->work_list, &work_list);
1625 spin_unlock_irqrestore(&p->p_work_lock, flags);
1627 list_for_each_entry_safe(work, tmp, &work_list, list) {
1628 list_del_init(&work->list);
1629 qedi_fp_process_cqes(work);
1630 if (!work->is_solicited)
1634 spin_lock_irqsave(&p->p_work_lock, flags);
1636 set_current_state(TASK_INTERRUPTIBLE);
1637 spin_unlock_irqrestore(&p->p_work_lock, flags);
1640 __set_current_state(TASK_RUNNING);
1645 static int qedi_cpu_online(unsigned int cpu)
1647 struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu);
1648 struct task_struct *thread;
1650 thread = kthread_create_on_node(qedi_percpu_io_thread, (void *)p,
1652 "qedi_thread/%d", cpu);
1654 return PTR_ERR(thread);
1656 kthread_bind(thread, cpu);
1657 p->iothread = thread;
1658 wake_up_process(thread);
1662 static int qedi_cpu_offline(unsigned int cpu)
1664 struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu);
1665 struct qedi_work *work, *tmp;
1666 struct task_struct *thread;
1668 spin_lock_bh(&p->p_work_lock);
1669 thread = p->iothread;
1672 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
1673 list_del_init(&work->list);
1674 qedi_fp_process_cqes(work);
1675 if (!work->is_solicited)
1679 spin_unlock_bh(&p->p_work_lock);
1681 kthread_stop(thread);
1685 void qedi_reset_host_mtu(struct qedi_ctx *qedi, u16 mtu)
1687 struct qed_ll2_params params;
1689 qedi_recover_all_conns(qedi);
1691 qedi_ops->ll2->stop(qedi->cdev);
1692 qedi_ll2_free_skbs(qedi);
1694 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, "old MTU %u, new MTU %u\n",
1695 qedi->ll2_mtu, mtu);
1696 memset(¶ms, 0, sizeof(params));
1697 qedi->ll2_mtu = mtu;
1698 params.mtu = qedi->ll2_mtu + IPV6_HDR_LEN + TCP_HDR_LEN;
1699 params.drop_ttl0_packets = 0;
1700 params.rx_vlan_stripping = 1;
1701 ether_addr_copy(params.ll2_mac_address, qedi->dev_info.common.hw_mac);
1702 qedi_ops->ll2->start(qedi->cdev, ¶ms);
1706 * qedi_get_nvram_block: - Scan through the iSCSI NVRAM block (while accounting
1707 * for gaps) for the matching absolute-pf-id of the QEDI device.
1709 static struct nvm_iscsi_block *
1710 qedi_get_nvram_block(struct qedi_ctx *qedi)
1715 struct nvm_iscsi_block *block;
1717 pf = qedi->dev_info.common.abs_pf_id;
1718 block = &qedi->iscsi_cfg->block[0];
1719 for (i = 0; i < NUM_OF_ISCSI_PF_SUPPORTED; i++, block++) {
1720 flags = ((block->id) & NVM_ISCSI_CFG_BLK_CTRL_FLAG_MASK) >>
1721 NVM_ISCSI_CFG_BLK_CTRL_FLAG_OFFSET;
1722 if (flags & (NVM_ISCSI_CFG_BLK_CTRL_FLAG_IS_NOT_EMPTY |
1723 NVM_ISCSI_CFG_BLK_CTRL_FLAG_PF_MAPPED) &&
1724 (pf == (block->id & NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_MASK)
1725 >> NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_OFFSET))
1731 static ssize_t qedi_show_boot_eth_info(void *data, int type, char *buf)
1733 struct qedi_ctx *qedi = data;
1734 struct nvm_iscsi_initiator *initiator;
1737 u32 ipv6_en, dhcp_en, ip_len;
1738 struct nvm_iscsi_block *block;
1739 char *fmt, *ip, *sub, *gw;
1741 block = qedi_get_nvram_block(qedi);
1745 initiator = &block->initiator;
1746 ipv6_en = block->generic.ctrl_flags &
1747 NVM_ISCSI_CFG_GEN_IPV6_ENABLED;
1748 dhcp_en = block->generic.ctrl_flags &
1749 NVM_ISCSI_CFG_GEN_DHCP_TCPIP_CONFIG_ENABLED;
1750 /* Static IP assignments. */
1751 fmt = ipv6_en ? "%pI6\n" : "%pI4\n";
1752 ip = ipv6_en ? initiator->ipv6.addr.byte : initiator->ipv4.addr.byte;
1753 ip_len = ipv6_en ? IPV6_LEN : IPV4_LEN;
1754 sub = ipv6_en ? initiator->ipv6.subnet_mask.byte :
1755 initiator->ipv4.subnet_mask.byte;
1756 gw = ipv6_en ? initiator->ipv6.gateway.byte :
1757 initiator->ipv4.gateway.byte;
1758 /* DHCP IP adjustments. */
1759 fmt = dhcp_en ? "%s\n" : fmt;
1761 ip = ipv6_en ? "0::0" : "0.0.0.0";
1764 ip_len = ipv6_en ? 5 : 8;
1768 case ISCSI_BOOT_ETH_IP_ADDR:
1769 rc = snprintf(str, ip_len, fmt, ip);
1771 case ISCSI_BOOT_ETH_SUBNET_MASK:
1772 rc = snprintf(str, ip_len, fmt, sub);
1774 case ISCSI_BOOT_ETH_GATEWAY:
1775 rc = snprintf(str, ip_len, fmt, gw);
1777 case ISCSI_BOOT_ETH_FLAGS:
1778 rc = snprintf(str, 3, "%hhd\n",
1779 SYSFS_FLAG_FW_SEL_BOOT);
1781 case ISCSI_BOOT_ETH_INDEX:
1782 rc = snprintf(str, 3, "0\n");
1784 case ISCSI_BOOT_ETH_MAC:
1785 rc = sysfs_format_mac(str, qedi->mac, ETH_ALEN);
1787 case ISCSI_BOOT_ETH_VLAN:
1788 rc = snprintf(str, 12, "%d\n",
1789 GET_FIELD2(initiator->generic_cont0,
1790 NVM_ISCSI_CFG_INITIATOR_VLAN));
1792 case ISCSI_BOOT_ETH_ORIGIN:
1794 rc = snprintf(str, 3, "3\n");
1804 static umode_t qedi_eth_get_attr_visibility(void *data, int type)
1809 case ISCSI_BOOT_ETH_FLAGS:
1810 case ISCSI_BOOT_ETH_MAC:
1811 case ISCSI_BOOT_ETH_INDEX:
1812 case ISCSI_BOOT_ETH_IP_ADDR:
1813 case ISCSI_BOOT_ETH_SUBNET_MASK:
1814 case ISCSI_BOOT_ETH_GATEWAY:
1815 case ISCSI_BOOT_ETH_ORIGIN:
1816 case ISCSI_BOOT_ETH_VLAN:
1826 static ssize_t qedi_show_boot_ini_info(void *data, int type, char *buf)
1828 struct qedi_ctx *qedi = data;
1829 struct nvm_iscsi_initiator *initiator;
1832 struct nvm_iscsi_block *block;
1834 block = qedi_get_nvram_block(qedi);
1838 initiator = &block->initiator;
1841 case ISCSI_BOOT_INI_INITIATOR_NAME:
1842 rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n",
1843 initiator->initiator_name.byte);
1852 static umode_t qedi_ini_get_attr_visibility(void *data, int type)
1857 case ISCSI_BOOT_INI_INITIATOR_NAME:
1868 qedi_show_boot_tgt_info(struct qedi_ctx *qedi, int type,
1869 char *buf, enum qedi_nvm_tgts idx)
1873 u32 ctrl_flags, ipv6_en, chap_en, mchap_en, ip_len;
1874 struct nvm_iscsi_block *block;
1875 char *chap_name, *chap_secret;
1876 char *mchap_name, *mchap_secret;
1878 block = qedi_get_nvram_block(qedi);
1880 goto exit_show_tgt_info;
1882 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_EVT,
1883 "Port:%d, tgt_idx:%d\n",
1884 GET_FIELD2(block->id, NVM_ISCSI_CFG_BLK_MAPPED_PF_ID), idx);
1886 ctrl_flags = block->target[idx].ctrl_flags &
1887 NVM_ISCSI_CFG_TARGET_ENABLED;
1890 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_EVT,
1891 "Target disabled\n");
1892 goto exit_show_tgt_info;
1895 ipv6_en = block->generic.ctrl_flags &
1896 NVM_ISCSI_CFG_GEN_IPV6_ENABLED;
1897 ip_len = ipv6_en ? IPV6_LEN : IPV4_LEN;
1898 chap_en = block->generic.ctrl_flags &
1899 NVM_ISCSI_CFG_GEN_CHAP_ENABLED;
1900 chap_name = chap_en ? block->initiator.chap_name.byte : NULL;
1901 chap_secret = chap_en ? block->initiator.chap_password.byte : NULL;
1903 mchap_en = block->generic.ctrl_flags &
1904 NVM_ISCSI_CFG_GEN_CHAP_MUTUAL_ENABLED;
1905 mchap_name = mchap_en ? block->target[idx].chap_name.byte : NULL;
1906 mchap_secret = mchap_en ? block->target[idx].chap_password.byte : NULL;
1909 case ISCSI_BOOT_TGT_NAME:
1910 rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n",
1911 block->target[idx].target_name.byte);
1913 case ISCSI_BOOT_TGT_IP_ADDR:
1915 rc = snprintf(str, ip_len, "%pI6\n",
1916 block->target[idx].ipv6_addr.byte);
1918 rc = snprintf(str, ip_len, "%pI4\n",
1919 block->target[idx].ipv4_addr.byte);
1921 case ISCSI_BOOT_TGT_PORT:
1922 rc = snprintf(str, 12, "%d\n",
1923 GET_FIELD2(block->target[idx].generic_cont0,
1924 NVM_ISCSI_CFG_TARGET_TCP_PORT));
1926 case ISCSI_BOOT_TGT_LUN:
1927 rc = snprintf(str, 22, "%.*d\n",
1928 block->target[idx].lun.value[1],
1929 block->target[idx].lun.value[0]);
1931 case ISCSI_BOOT_TGT_CHAP_NAME:
1932 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n",
1935 case ISCSI_BOOT_TGT_CHAP_SECRET:
1936 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n",
1939 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
1940 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n",
1943 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
1944 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n",
1947 case ISCSI_BOOT_TGT_FLAGS:
1948 rc = snprintf(str, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT);
1950 case ISCSI_BOOT_TGT_NIC_ASSOC:
1951 rc = snprintf(str, 3, "0\n");
1962 static ssize_t qedi_show_boot_tgt_pri_info(void *data, int type, char *buf)
1964 struct qedi_ctx *qedi = data;
1966 return qedi_show_boot_tgt_info(qedi, type, buf, QEDI_NVM_TGT_PRI);
1969 static ssize_t qedi_show_boot_tgt_sec_info(void *data, int type, char *buf)
1971 struct qedi_ctx *qedi = data;
1973 return qedi_show_boot_tgt_info(qedi, type, buf, QEDI_NVM_TGT_SEC);
1976 static umode_t qedi_tgt_get_attr_visibility(void *data, int type)
1981 case ISCSI_BOOT_TGT_NAME:
1982 case ISCSI_BOOT_TGT_IP_ADDR:
1983 case ISCSI_BOOT_TGT_PORT:
1984 case ISCSI_BOOT_TGT_LUN:
1985 case ISCSI_BOOT_TGT_CHAP_NAME:
1986 case ISCSI_BOOT_TGT_CHAP_SECRET:
1987 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
1988 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
1989 case ISCSI_BOOT_TGT_NIC_ASSOC:
1990 case ISCSI_BOOT_TGT_FLAGS:
2000 static void qedi_boot_release(void *data)
2002 struct qedi_ctx *qedi = data;
2004 scsi_host_put(qedi->shost);
2007 static int qedi_get_boot_info(struct qedi_ctx *qedi)
2012 len = sizeof(struct nvm_iscsi_cfg);
2014 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
2015 "Get NVM iSCSI CFG image\n");
2016 ret = qedi_ops->common->nvm_get_image(qedi->cdev,
2017 QED_NVM_IMAGE_ISCSI_CFG,
2018 (char *)qedi->iscsi_cfg, len);
2020 QEDI_ERR(&qedi->dbg_ctx,
2021 "Could not get NVM image. ret = %d\n", ret);
2026 static int qedi_setup_boot_info(struct qedi_ctx *qedi)
2028 struct iscsi_boot_kobj *boot_kobj;
2030 if (qedi_get_boot_info(qedi))
2033 qedi->boot_kset = iscsi_boot_create_host_kset(qedi->shost->host_no);
2034 if (!qedi->boot_kset)
2037 if (!scsi_host_get(qedi->shost))
2040 boot_kobj = iscsi_boot_create_target(qedi->boot_kset, 0, qedi,
2041 qedi_show_boot_tgt_pri_info,
2042 qedi_tgt_get_attr_visibility,
2047 if (!scsi_host_get(qedi->shost))
2050 boot_kobj = iscsi_boot_create_target(qedi->boot_kset, 1, qedi,
2051 qedi_show_boot_tgt_sec_info,
2052 qedi_tgt_get_attr_visibility,
2057 if (!scsi_host_get(qedi->shost))
2060 boot_kobj = iscsi_boot_create_initiator(qedi->boot_kset, 0, qedi,
2061 qedi_show_boot_ini_info,
2062 qedi_ini_get_attr_visibility,
2067 if (!scsi_host_get(qedi->shost))
2070 boot_kobj = iscsi_boot_create_ethernet(qedi->boot_kset, 0, qedi,
2071 qedi_show_boot_eth_info,
2072 qedi_eth_get_attr_visibility,
2080 scsi_host_put(qedi->shost);
2082 iscsi_boot_destroy_kset(qedi->boot_kset);
2086 static void __qedi_remove(struct pci_dev *pdev, int mode)
2088 struct qedi_ctx *qedi = pci_get_drvdata(pdev);
2090 if (qedi->tmf_thread) {
2091 flush_workqueue(qedi->tmf_thread);
2092 destroy_workqueue(qedi->tmf_thread);
2093 qedi->tmf_thread = NULL;
2096 if (qedi->offload_thread) {
2097 flush_workqueue(qedi->offload_thread);
2098 destroy_workqueue(qedi->offload_thread);
2099 qedi->offload_thread = NULL;
2102 #ifdef CONFIG_DEBUG_FS
2103 qedi_dbg_host_exit(&qedi->dbg_ctx);
2105 if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags))
2106 qedi_ops->common->set_power_state(qedi->cdev, PCI_D0);
2108 qedi_sync_free_irqs(qedi);
2110 if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags)) {
2111 qedi_ops->stop(qedi->cdev);
2112 qedi_ops->ll2->stop(qedi->cdev);
2115 if (mode == QEDI_MODE_NORMAL)
2116 qedi_free_iscsi_pf_param(qedi);
2118 if (!test_bit(QEDI_IN_OFFLINE, &qedi->flags)) {
2119 qedi_ops->common->slowpath_stop(qedi->cdev);
2120 qedi_ops->common->remove(qedi->cdev);
2123 qedi_destroy_fp(qedi);
2125 if (mode == QEDI_MODE_NORMAL) {
2126 qedi_release_cid_que(qedi);
2127 qedi_cm_free_mem(qedi);
2128 qedi_free_uio(qedi->udev);
2129 qedi_free_itt(qedi);
2131 iscsi_host_remove(qedi->shost);
2132 iscsi_host_free(qedi->shost);
2134 if (qedi->ll2_recv_thread) {
2135 kthread_stop(qedi->ll2_recv_thread);
2136 qedi->ll2_recv_thread = NULL;
2138 qedi_ll2_free_skbs(qedi);
2140 if (qedi->boot_kset)
2141 iscsi_boot_destroy_kset(qedi->boot_kset);
2145 static int __qedi_probe(struct pci_dev *pdev, int mode)
2147 struct qedi_ctx *qedi;
2148 struct qed_ll2_params params;
2153 struct qed_link_params link_params;
2154 struct qed_slowpath_params sp_params;
2155 struct qed_probe_params qed_params;
2156 void *task_start, *task_end;
2160 if (mode != QEDI_MODE_RECOVERY) {
2161 qedi = qedi_host_alloc(pdev);
2167 qedi = pci_get_drvdata(pdev);
2170 memset(&qed_params, 0, sizeof(qed_params));
2171 qed_params.protocol = QED_PROTOCOL_ISCSI;
2172 qed_params.dp_module = dp_module;
2173 qed_params.dp_level = dp_level;
2174 qed_params.is_vf = is_vf;
2175 qedi->cdev = qedi_ops->common->probe(pdev, &qed_params);
2178 QEDI_ERR(&qedi->dbg_ctx, "Cannot initialize hardware\n");
2182 qedi->msix_count = MAX_NUM_MSIX_PF;
2183 atomic_set(&qedi->link_state, QEDI_LINK_DOWN);
2185 if (mode != QEDI_MODE_RECOVERY) {
2186 rc = qedi_set_iscsi_pf_param(qedi);
2189 QEDI_ERR(&qedi->dbg_ctx,
2190 "Set iSCSI pf param fail\n");
2195 qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params);
2197 rc = qedi_prepare_fp(qedi);
2199 QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath.\n");
2200 goto free_pf_params;
2203 /* Start the Slowpath-process */
2204 memset(&sp_params, 0, sizeof(struct qed_slowpath_params));
2205 sp_params.int_mode = QED_INT_MODE_MSIX;
2206 sp_params.drv_major = QEDI_DRIVER_MAJOR_VER;
2207 sp_params.drv_minor = QEDI_DRIVER_MINOR_VER;
2208 sp_params.drv_rev = QEDI_DRIVER_REV_VER;
2209 sp_params.drv_eng = QEDI_DRIVER_ENG_VER;
2210 strlcpy(sp_params.name, "qedi iSCSI", QED_DRV_VER_STR_SIZE);
2211 rc = qedi_ops->common->slowpath_start(qedi->cdev, &sp_params);
2213 QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath\n");
2217 /* update_pf_params needs to be called before and after slowpath
2220 qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params);
2222 rc = qedi_setup_int(qedi);
2224 goto stop_iscsi_func;
2226 qedi_ops->common->set_power_state(qedi->cdev, PCI_D0);
2228 /* Learn information crucial for qedi to progress */
2229 rc = qedi_ops->fill_dev_info(qedi->cdev, &qedi->dev_info);
2231 goto stop_iscsi_func;
2233 /* Record BDQ producer doorbell addresses */
2234 qedi->bdq_primary_prod = qedi->dev_info.primary_dbq_rq_addr;
2235 qedi->bdq_secondary_prod = qedi->dev_info.secondary_bdq_rq_addr;
2236 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
2237 "BDQ primary_prod=%p secondary_prod=%p.\n",
2238 qedi->bdq_primary_prod,
2239 qedi->bdq_secondary_prod);
2242 * We need to write the number of BDs in the BDQ we've preallocated so
2243 * the f/w will do a prefetch and we'll get an unsolicited CQE when a
2246 qedi->bdq_prod_idx = QEDI_BDQ_NUM;
2247 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
2248 "Writing %d to primary and secondary BDQ doorbell registers.\n",
2249 qedi->bdq_prod_idx);
2250 writew(qedi->bdq_prod_idx, qedi->bdq_primary_prod);
2251 tmp = readw(qedi->bdq_primary_prod);
2252 writew(qedi->bdq_prod_idx, qedi->bdq_secondary_prod);
2253 tmp = readw(qedi->bdq_secondary_prod);
2255 ether_addr_copy(qedi->mac, qedi->dev_info.common.hw_mac);
2256 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC, "MAC address is %pM.\n",
2259 sprintf(host_buf, "host_%d", qedi->shost->host_no);
2260 qedi_ops->common->set_name(qedi->cdev, host_buf);
2262 qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi);
2264 memset(¶ms, 0, sizeof(params));
2265 params.mtu = DEF_PATH_MTU + IPV6_HDR_LEN + TCP_HDR_LEN;
2266 qedi->ll2_mtu = DEF_PATH_MTU;
2267 params.drop_ttl0_packets = 0;
2268 params.rx_vlan_stripping = 1;
2269 ether_addr_copy(params.ll2_mac_address, qedi->dev_info.common.hw_mac);
2271 if (mode != QEDI_MODE_RECOVERY) {
2272 /* set up rx path */
2273 INIT_LIST_HEAD(&qedi->ll2_skb_list);
2274 spin_lock_init(&qedi->ll2_lock);
2275 /* start qedi context */
2276 spin_lock_init(&qedi->hba_lock);
2277 spin_lock_init(&qedi->task_idx_lock);
2279 qedi_ops->ll2->register_cb_ops(qedi->cdev, &qedi_ll2_cb_ops, qedi);
2280 qedi_ops->ll2->start(qedi->cdev, ¶ms);
2282 if (mode != QEDI_MODE_RECOVERY) {
2283 qedi->ll2_recv_thread = kthread_run(qedi_ll2_recv_thread,
2288 rc = qedi_ops->start(qedi->cdev, &qedi->tasks,
2289 qedi, qedi_iscsi_event_cb);
2292 QEDI_ERR(&qedi->dbg_ctx, "Cannot start iSCSI function\n");
2296 task_start = qedi_get_task_mem(&qedi->tasks, 0);
2297 task_end = qedi_get_task_mem(&qedi->tasks, MAX_TID_BLOCKS_ISCSI - 1);
2298 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_DISC,
2299 "Task context start=%p, end=%p block_size=%u.\n",
2300 task_start, task_end, qedi->tasks.size);
2302 memset(&link_params, 0, sizeof(link_params));
2303 link_params.link_up = true;
2304 rc = qedi_ops->common->set_link(qedi->cdev, &link_params);
2306 QEDI_WARN(&qedi->dbg_ctx, "Link set up failed.\n");
2307 atomic_set(&qedi->link_state, QEDI_LINK_DOWN);
2310 #ifdef CONFIG_DEBUG_FS
2311 qedi_dbg_host_init(&qedi->dbg_ctx, &qedi_debugfs_ops,
2314 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
2315 "QLogic FastLinQ iSCSI Module qedi %s, FW %d.%d.%d.%d\n",
2316 QEDI_MODULE_VERSION, FW_MAJOR_VERSION, FW_MINOR_VERSION,
2317 FW_REVISION_VERSION, FW_ENGINEERING_VERSION);
2319 if (mode == QEDI_MODE_NORMAL) {
2320 if (iscsi_host_add(qedi->shost, &pdev->dev)) {
2321 QEDI_ERR(&qedi->dbg_ctx,
2322 "Could not add iscsi host\n");
2327 /* Allocate uio buffers */
2328 rc = qedi_alloc_uio_rings(qedi);
2330 QEDI_ERR(&qedi->dbg_ctx,
2331 "UIO alloc ring failed err=%d\n", rc);
2335 rc = qedi_init_uio(qedi);
2337 QEDI_ERR(&qedi->dbg_ctx,
2338 "UIO init failed, err=%d\n", rc);
2342 /* host the array on iscsi_conn */
2343 rc = qedi_setup_cid_que(qedi);
2345 QEDI_ERR(&qedi->dbg_ctx,
2346 "Could not setup cid que\n");
2350 rc = qedi_cm_alloc_mem(qedi);
2352 QEDI_ERR(&qedi->dbg_ctx,
2353 "Could not alloc cm memory\n");
2357 rc = qedi_alloc_itt(qedi);
2359 QEDI_ERR(&qedi->dbg_ctx,
2360 "Could not alloc itt memory\n");
2364 sprintf(host_buf, "host_%d", qedi->shost->host_no);
2365 qedi->tmf_thread = create_singlethread_workqueue(host_buf);
2366 if (!qedi->tmf_thread) {
2367 QEDI_ERR(&qedi->dbg_ctx,
2368 "Unable to start tmf thread!\n");
2373 sprintf(host_buf, "qedi_ofld%d", qedi->shost->host_no);
2374 qedi->offload_thread = create_workqueue(host_buf);
2375 if (!qedi->offload_thread) {
2376 QEDI_ERR(&qedi->dbg_ctx,
2377 "Unable to start offload thread!\n");
2382 /* F/w needs 1st task context memory entry for performance */
2383 set_bit(QEDI_RESERVE_TASK_ID, qedi->task_idx_map);
2384 atomic_set(&qedi->num_offloads, 0);
2386 if (qedi_setup_boot_info(qedi))
2387 QEDI_ERR(&qedi->dbg_ctx,
2388 "No iSCSI boot target configured\n");
2394 qedi_release_cid_que(qedi);
2396 qedi_free_uio(qedi->udev);
2398 #ifdef CONFIG_DEBUG_FS
2399 qedi_dbg_host_exit(&qedi->dbg_ctx);
2401 iscsi_host_remove(qedi->shost);
2403 qedi_ops->stop(qedi->cdev);
2405 qedi_ops->common->slowpath_stop(qedi->cdev);
2407 qedi_ops->common->remove(qedi->cdev);
2409 qedi_free_iscsi_pf_param(qedi);
2411 iscsi_host_free(qedi->shost);
2416 static int qedi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2418 return __qedi_probe(pdev, QEDI_MODE_NORMAL);
2421 static void qedi_remove(struct pci_dev *pdev)
2423 __qedi_remove(pdev, QEDI_MODE_NORMAL);
2426 static struct pci_device_id qedi_pci_tbl[] = {
2427 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x165E) },
2428 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, 0x8084) },
2431 MODULE_DEVICE_TABLE(pci, qedi_pci_tbl);
2433 static enum cpuhp_state qedi_cpuhp_state;
2435 static struct pci_driver qedi_pci_driver = {
2436 .name = QEDI_MODULE_NAME,
2437 .id_table = qedi_pci_tbl,
2438 .probe = qedi_probe,
2439 .remove = qedi_remove,
2442 static int __init qedi_init(void)
2444 struct qedi_percpu_s *p;
2447 qedi_ops = qed_get_iscsi_ops();
2449 QEDI_ERR(NULL, "Failed to get qed iSCSI operations\n");
2453 #ifdef CONFIG_DEBUG_FS
2454 qedi_dbg_init("qedi");
2457 qedi_scsi_transport = iscsi_register_transport(&qedi_iscsi_transport);
2458 if (!qedi_scsi_transport) {
2459 QEDI_ERR(NULL, "Could not register qedi transport");
2461 goto exit_qedi_init_1;
2464 for_each_possible_cpu(cpu) {
2465 p = &per_cpu(qedi_percpu, cpu);
2466 INIT_LIST_HEAD(&p->work_list);
2467 spin_lock_init(&p->p_work_lock);
2471 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/qedi:online",
2472 qedi_cpu_online, qedi_cpu_offline);
2474 goto exit_qedi_init_2;
2475 qedi_cpuhp_state = rc;
2477 rc = pci_register_driver(&qedi_pci_driver);
2479 QEDI_ERR(NULL, "Failed to register driver\n");
2486 cpuhp_remove_state(qedi_cpuhp_state);
2488 iscsi_unregister_transport(&qedi_iscsi_transport);
2490 #ifdef CONFIG_DEBUG_FS
2493 qed_put_iscsi_ops();
2497 static void __exit qedi_cleanup(void)
2499 pci_unregister_driver(&qedi_pci_driver);
2500 cpuhp_remove_state(qedi_cpuhp_state);
2501 iscsi_unregister_transport(&qedi_iscsi_transport);
2503 #ifdef CONFIG_DEBUG_FS
2506 qed_put_iscsi_ops();
2509 MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx iSCSI Module");
2510 MODULE_LICENSE("GPL");
2511 MODULE_AUTHOR("QLogic Corporation");
2512 MODULE_VERSION(QEDI_MODULE_VERSION);
2513 module_init(qedi_init);
2514 module_exit(qedi_cleanup);