1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic iSCSI Offload Driver
4 * Copyright (c) 2016 Cavium Inc.
7 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/if_arp.h>
11 #include <scsi/iscsi_if.h>
12 #include <linux/inet.h>
14 #include <linux/list.h>
15 #include <linux/kthread.h>
17 #include <linux/if_vlan.h>
18 #include <linux/cpu.h>
19 #include <linux/iscsi_boot_sysfs.h>
21 #include <scsi/scsi_cmnd.h>
22 #include <scsi/scsi_device.h>
23 #include <scsi/scsi_eh.h>
24 #include <scsi/scsi_host.h>
25 #include <scsi/scsi.h>
29 #include "qedi_iscsi.h"
31 static uint qedi_fw_debug
;
32 module_param(qedi_fw_debug
, uint
, 0644);
33 MODULE_PARM_DESC(qedi_fw_debug
, " Firmware debug level 0(default) to 3");
35 uint qedi_dbg_log
= QEDI_LOG_WARN
| QEDI_LOG_SCSI_TM
;
36 module_param(qedi_dbg_log
, uint
, 0644);
37 MODULE_PARM_DESC(qedi_dbg_log
, " Default debug level");
40 module_param(qedi_io_tracing
, uint
, 0644);
41 MODULE_PARM_DESC(qedi_io_tracing
,
42 " Enable logging of SCSI requests/completions into trace buffer. (default off).");
44 uint qedi_ll2_buf_size
= 0x400;
45 module_param(qedi_ll2_buf_size
, uint
, 0644);
46 MODULE_PARM_DESC(qedi_ll2_buf_size
,
47 "parameter to set ping packet size, default - 0x400, Jumbo packets - 0x2400.");
49 const struct qed_iscsi_ops
*qedi_ops
;
50 static struct scsi_transport_template
*qedi_scsi_transport
;
51 static struct pci_driver qedi_pci_driver
;
52 static DEFINE_PER_CPU(struct qedi_percpu_s
, qedi_percpu
);
53 static LIST_HEAD(qedi_udev_list
);
54 /* Static function declaration */
55 static int qedi_alloc_global_queues(struct qedi_ctx
*qedi
);
56 static void qedi_free_global_queues(struct qedi_ctx
*qedi
);
57 static struct qedi_cmd
*qedi_get_cmd_from_tid(struct qedi_ctx
*qedi
, u32 tid
);
58 static void qedi_reset_uio_rings(struct qedi_uio_dev
*udev
);
59 static void qedi_ll2_free_skbs(struct qedi_ctx
*qedi
);
60 static struct nvm_iscsi_block
*qedi_get_nvram_block(struct qedi_ctx
*qedi
);
62 static int qedi_iscsi_event_cb(void *context
, u8 fw_event_code
, void *fw_handle
)
64 struct qedi_ctx
*qedi
;
65 struct qedi_endpoint
*qedi_ep
;
66 struct iscsi_eqe_data
*data
;
69 if (!context
|| !fw_handle
) {
70 QEDI_ERR(NULL
, "Recv event with ctx NULL\n");
74 qedi
= (struct qedi_ctx
*)context
;
75 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
76 "Recv Event %d fw_handle %p\n", fw_event_code
, fw_handle
);
78 data
= (struct iscsi_eqe_data
*)fw_handle
;
79 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
80 "icid=0x%x conn_id=0x%x err-code=0x%x error-pdu-opcode-reserved=0x%x\n",
81 data
->icid
, data
->conn_id
, data
->error_code
,
82 data
->error_pdu_opcode_reserved
);
84 qedi_ep
= qedi
->ep_tbl
[data
->icid
];
87 QEDI_WARN(&qedi
->dbg_ctx
,
88 "Cannot process event, ep already disconnected, cid=0x%x\n",
94 switch (fw_event_code
) {
95 case ISCSI_EVENT_TYPE_ASYN_CONNECT_COMPLETE
:
96 if (qedi_ep
->state
== EP_STATE_OFLDCONN_START
)
97 qedi_ep
->state
= EP_STATE_OFLDCONN_COMPL
;
99 wake_up_interruptible(&qedi_ep
->tcp_ofld_wait
);
101 case ISCSI_EVENT_TYPE_ASYN_TERMINATE_DONE
:
102 qedi_ep
->state
= EP_STATE_DISCONN_COMPL
;
103 wake_up_interruptible(&qedi_ep
->tcp_ofld_wait
);
105 case ISCSI_EVENT_TYPE_ISCSI_CONN_ERROR
:
106 qedi_process_iscsi_error(qedi_ep
, data
);
108 case ISCSI_EVENT_TYPE_ASYN_ABORT_RCVD
:
109 case ISCSI_EVENT_TYPE_ASYN_SYN_RCVD
:
110 case ISCSI_EVENT_TYPE_ASYN_MAX_RT_TIME
:
111 case ISCSI_EVENT_TYPE_ASYN_MAX_RT_CNT
:
112 case ISCSI_EVENT_TYPE_ASYN_MAX_KA_PROBES_CNT
:
113 case ISCSI_EVENT_TYPE_ASYN_FIN_WAIT2
:
114 case ISCSI_EVENT_TYPE_TCP_CONN_ERROR
:
115 qedi_process_tcp_error(qedi_ep
, data
);
118 QEDI_ERR(&qedi
->dbg_ctx
, "Recv Unknown Event %u\n",
125 static int qedi_uio_open(struct uio_info
*uinfo
, struct inode
*inode
)
127 struct qedi_uio_dev
*udev
= uinfo
->priv
;
128 struct qedi_ctx
*qedi
= udev
->qedi
;
130 if (!capable(CAP_NET_ADMIN
))
133 if (udev
->uio_dev
!= -1)
137 udev
->uio_dev
= iminor(inode
);
138 qedi_reset_uio_rings(udev
);
139 set_bit(UIO_DEV_OPENED
, &qedi
->flags
);
145 static int qedi_uio_close(struct uio_info
*uinfo
, struct inode
*inode
)
147 struct qedi_uio_dev
*udev
= uinfo
->priv
;
148 struct qedi_ctx
*qedi
= udev
->qedi
;
151 clear_bit(UIO_DEV_OPENED
, &qedi
->flags
);
152 qedi_ll2_free_skbs(qedi
);
156 static void __qedi_free_uio_rings(struct qedi_uio_dev
*udev
)
159 free_page((unsigned long)udev
->uctrl
);
163 if (udev
->ll2_ring
) {
164 free_page((unsigned long)udev
->ll2_ring
);
165 udev
->ll2_ring
= NULL
;
169 free_pages((unsigned long)udev
->ll2_buf
, 2);
170 udev
->ll2_buf
= NULL
;
174 static void __qedi_free_uio(struct qedi_uio_dev
*udev
)
176 uio_unregister_device(&udev
->qedi_uinfo
);
178 __qedi_free_uio_rings(udev
);
180 pci_dev_put(udev
->pdev
);
184 static void qedi_free_uio(struct qedi_uio_dev
*udev
)
189 list_del_init(&udev
->list
);
190 __qedi_free_uio(udev
);
193 static void qedi_reset_uio_rings(struct qedi_uio_dev
*udev
)
195 struct qedi_ctx
*qedi
= NULL
;
196 struct qedi_uio_ctrl
*uctrl
= NULL
;
201 spin_lock_bh(&qedi
->ll2_lock
);
202 uctrl
->host_rx_cons
= 0;
203 uctrl
->hw_rx_prod
= 0;
204 uctrl
->hw_rx_bd_prod
= 0;
205 uctrl
->host_rx_bd_cons
= 0;
207 memset(udev
->ll2_ring
, 0, udev
->ll2_ring_size
);
208 memset(udev
->ll2_buf
, 0, udev
->ll2_buf_size
);
209 spin_unlock_bh(&qedi
->ll2_lock
);
212 static int __qedi_alloc_uio_rings(struct qedi_uio_dev
*udev
)
216 if (udev
->ll2_ring
|| udev
->ll2_buf
)
219 /* Memory for control area. */
220 udev
->uctrl
= (void *)get_zeroed_page(GFP_KERNEL
);
224 /* Allocating memory for LL2 ring */
225 udev
->ll2_ring_size
= QEDI_PAGE_SIZE
;
226 udev
->ll2_ring
= (void *)get_zeroed_page(GFP_KERNEL
| __GFP_COMP
);
227 if (!udev
->ll2_ring
) {
229 goto exit_alloc_ring
;
232 /* Allocating memory for Tx/Rx pkt buffer */
233 udev
->ll2_buf_size
= TX_RX_RING
* qedi_ll2_buf_size
;
234 udev
->ll2_buf_size
= QEDI_PAGE_ALIGN(udev
->ll2_buf_size
);
235 udev
->ll2_buf
= (void *)__get_free_pages(GFP_KERNEL
| __GFP_COMP
|
237 if (!udev
->ll2_buf
) {
244 free_page((unsigned long)udev
->ll2_ring
);
245 udev
->ll2_ring
= NULL
;
250 static int qedi_alloc_uio_rings(struct qedi_ctx
*qedi
)
252 struct qedi_uio_dev
*udev
= NULL
;
255 list_for_each_entry(udev
, &qedi_udev_list
, list
) {
256 if (udev
->pdev
== qedi
->pdev
) {
258 if (__qedi_alloc_uio_rings(udev
)) {
267 udev
= kzalloc(sizeof(*udev
), GFP_KERNEL
);
276 udev
->pdev
= qedi
->pdev
;
278 rc
= __qedi_alloc_uio_rings(udev
);
282 list_add(&udev
->list
, &qedi_udev_list
);
284 pci_dev_get(udev
->pdev
);
287 udev
->tx_pkt
= udev
->ll2_buf
;
288 udev
->rx_pkt
= udev
->ll2_buf
+ qedi_ll2_buf_size
;
297 static int qedi_init_uio(struct qedi_ctx
*qedi
)
299 struct qedi_uio_dev
*udev
= qedi
->udev
;
300 struct uio_info
*uinfo
;
306 uinfo
= &udev
->qedi_uinfo
;
308 uinfo
->mem
[0].addr
= (unsigned long)udev
->uctrl
;
309 uinfo
->mem
[0].size
= sizeof(struct qedi_uio_ctrl
);
310 uinfo
->mem
[0].memtype
= UIO_MEM_LOGICAL
;
312 uinfo
->mem
[1].addr
= (unsigned long)udev
->ll2_ring
;
313 uinfo
->mem
[1].size
= udev
->ll2_ring_size
;
314 uinfo
->mem
[1].memtype
= UIO_MEM_LOGICAL
;
316 uinfo
->mem
[2].addr
= (unsigned long)udev
->ll2_buf
;
317 uinfo
->mem
[2].size
= udev
->ll2_buf_size
;
318 uinfo
->mem
[2].memtype
= UIO_MEM_LOGICAL
;
320 uinfo
->name
= "qedi_uio";
321 uinfo
->version
= QEDI_MODULE_VERSION
;
322 uinfo
->irq
= UIO_IRQ_CUSTOM
;
324 uinfo
->open
= qedi_uio_open
;
325 uinfo
->release
= qedi_uio_close
;
327 if (udev
->uio_dev
== -1) {
331 ret
= uio_register_device(&udev
->pdev
->dev
, uinfo
);
333 QEDI_ERR(&qedi
->dbg_ctx
,
334 "UIO registration failed\n");
342 static int qedi_alloc_and_init_sb(struct qedi_ctx
*qedi
,
343 struct qed_sb_info
*sb_info
, u16 sb_id
)
345 struct status_block_e4
*sb_virt
;
349 sb_virt
= dma_alloc_coherent(&qedi
->pdev
->dev
,
350 sizeof(struct status_block_e4
), &sb_phys
,
353 QEDI_ERR(&qedi
->dbg_ctx
,
354 "Status block allocation failed for id = %d.\n",
359 ret
= qedi_ops
->common
->sb_init(qedi
->cdev
, sb_info
, sb_virt
, sb_phys
,
360 sb_id
, QED_SB_TYPE_STORAGE
);
362 QEDI_ERR(&qedi
->dbg_ctx
,
363 "Status block initialization failed for id = %d.\n",
371 static void qedi_free_sb(struct qedi_ctx
*qedi
)
373 struct qed_sb_info
*sb_info
;
376 for (id
= 0; id
< MIN_NUM_CPUS_MSIX(qedi
); id
++) {
377 sb_info
= &qedi
->sb_array
[id
];
378 if (sb_info
->sb_virt
)
379 dma_free_coherent(&qedi
->pdev
->dev
,
380 sizeof(*sb_info
->sb_virt
),
381 (void *)sb_info
->sb_virt
,
386 static void qedi_free_fp(struct qedi_ctx
*qedi
)
388 kfree(qedi
->fp_array
);
389 kfree(qedi
->sb_array
);
392 static void qedi_destroy_fp(struct qedi_ctx
*qedi
)
398 static int qedi_alloc_fp(struct qedi_ctx
*qedi
)
402 qedi
->fp_array
= kcalloc(MIN_NUM_CPUS_MSIX(qedi
),
403 sizeof(struct qedi_fastpath
), GFP_KERNEL
);
404 if (!qedi
->fp_array
) {
405 QEDI_ERR(&qedi
->dbg_ctx
,
406 "fastpath fp array allocation failed.\n");
410 qedi
->sb_array
= kcalloc(MIN_NUM_CPUS_MSIX(qedi
),
411 sizeof(struct qed_sb_info
), GFP_KERNEL
);
412 if (!qedi
->sb_array
) {
413 QEDI_ERR(&qedi
->dbg_ctx
,
414 "fastpath sb array allocation failed.\n");
426 static void qedi_int_fp(struct qedi_ctx
*qedi
)
428 struct qedi_fastpath
*fp
;
431 memset(qedi
->fp_array
, 0, MIN_NUM_CPUS_MSIX(qedi
) *
432 sizeof(*qedi
->fp_array
));
433 memset(qedi
->sb_array
, 0, MIN_NUM_CPUS_MSIX(qedi
) *
434 sizeof(*qedi
->sb_array
));
436 for (id
= 0; id
< MIN_NUM_CPUS_MSIX(qedi
); id
++) {
437 fp
= &qedi
->fp_array
[id
];
438 fp
->sb_info
= &qedi
->sb_array
[id
];
441 snprintf(fp
->name
, sizeof(fp
->name
), "%s-fp-%d",
444 /* fp_array[i] ---- irq cookie
445 * So init data which is needed in int ctx
450 static int qedi_prepare_fp(struct qedi_ctx
*qedi
)
452 struct qedi_fastpath
*fp
;
455 ret
= qedi_alloc_fp(qedi
);
461 for (id
= 0; id
< MIN_NUM_CPUS_MSIX(qedi
); id
++) {
462 fp
= &qedi
->fp_array
[id
];
463 ret
= qedi_alloc_and_init_sb(qedi
, fp
->sb_info
, fp
->sb_id
);
465 QEDI_ERR(&qedi
->dbg_ctx
,
466 "SB allocation and initialization failed.\n");
481 static int qedi_setup_cid_que(struct qedi_ctx
*qedi
)
485 qedi
->cid_que
.cid_que_base
= kmalloc_array(qedi
->max_active_conns
,
486 sizeof(u32
), GFP_KERNEL
);
487 if (!qedi
->cid_que
.cid_que_base
)
490 qedi
->cid_que
.conn_cid_tbl
= kmalloc_array(qedi
->max_active_conns
,
491 sizeof(struct qedi_conn
*),
493 if (!qedi
->cid_que
.conn_cid_tbl
) {
494 kfree(qedi
->cid_que
.cid_que_base
);
495 qedi
->cid_que
.cid_que_base
= NULL
;
499 qedi
->cid_que
.cid_que
= (u32
*)qedi
->cid_que
.cid_que_base
;
500 qedi
->cid_que
.cid_q_prod_idx
= 0;
501 qedi
->cid_que
.cid_q_cons_idx
= 0;
502 qedi
->cid_que
.cid_q_max_idx
= qedi
->max_active_conns
;
503 qedi
->cid_que
.cid_free_cnt
= qedi
->max_active_conns
;
505 for (i
= 0; i
< qedi
->max_active_conns
; i
++) {
506 qedi
->cid_que
.cid_que
[i
] = i
;
507 qedi
->cid_que
.conn_cid_tbl
[i
] = NULL
;
513 static void qedi_release_cid_que(struct qedi_ctx
*qedi
)
515 kfree(qedi
->cid_que
.cid_que_base
);
516 qedi
->cid_que
.cid_que_base
= NULL
;
518 kfree(qedi
->cid_que
.conn_cid_tbl
);
519 qedi
->cid_que
.conn_cid_tbl
= NULL
;
522 static int qedi_init_id_tbl(struct qedi_portid_tbl
*id_tbl
, u16 size
,
523 u16 start_id
, u16 next
)
525 id_tbl
->start
= start_id
;
528 spin_lock_init(&id_tbl
->lock
);
529 id_tbl
->table
= kcalloc(BITS_TO_LONGS(size
), sizeof(long), GFP_KERNEL
);
536 static void qedi_free_id_tbl(struct qedi_portid_tbl
*id_tbl
)
538 kfree(id_tbl
->table
);
539 id_tbl
->table
= NULL
;
542 int qedi_alloc_id(struct qedi_portid_tbl
*id_tbl
, u16 id
)
547 if (id
>= id_tbl
->max
)
550 spin_lock(&id_tbl
->lock
);
551 if (!test_bit(id
, id_tbl
->table
)) {
552 set_bit(id
, id_tbl
->table
);
555 spin_unlock(&id_tbl
->lock
);
559 u16
qedi_alloc_new_id(struct qedi_portid_tbl
*id_tbl
)
563 spin_lock(&id_tbl
->lock
);
564 id
= find_next_zero_bit(id_tbl
->table
, id_tbl
->max
, id_tbl
->next
);
565 if (id
>= id_tbl
->max
) {
566 id
= QEDI_LOCAL_PORT_INVALID
;
567 if (id_tbl
->next
!= 0) {
568 id
= find_first_zero_bit(id_tbl
->table
, id_tbl
->next
);
569 if (id
>= id_tbl
->next
)
570 id
= QEDI_LOCAL_PORT_INVALID
;
574 if (id
< id_tbl
->max
) {
575 set_bit(id
, id_tbl
->table
);
576 id_tbl
->next
= (id
+ 1) & (id_tbl
->max
- 1);
580 spin_unlock(&id_tbl
->lock
);
585 void qedi_free_id(struct qedi_portid_tbl
*id_tbl
, u16 id
)
587 if (id
== QEDI_LOCAL_PORT_INVALID
)
591 if (id
>= id_tbl
->max
)
594 clear_bit(id
, id_tbl
->table
);
597 static void qedi_cm_free_mem(struct qedi_ctx
*qedi
)
601 qedi_free_id_tbl(&qedi
->lcl_port_tbl
);
604 static int qedi_cm_alloc_mem(struct qedi_ctx
*qedi
)
608 qedi
->ep_tbl
= kzalloc((qedi
->max_active_conns
*
609 sizeof(struct qedi_endpoint
*)), GFP_KERNEL
);
612 port_id
= prandom_u32() % QEDI_LOCAL_PORT_RANGE
;
613 if (qedi_init_id_tbl(&qedi
->lcl_port_tbl
, QEDI_LOCAL_PORT_RANGE
,
614 QEDI_LOCAL_PORT_MIN
, port_id
)) {
615 qedi_cm_free_mem(qedi
);
622 static struct qedi_ctx
*qedi_host_alloc(struct pci_dev
*pdev
)
624 struct Scsi_Host
*shost
;
625 struct qedi_ctx
*qedi
= NULL
;
627 shost
= iscsi_host_alloc(&qedi_host_template
,
628 sizeof(struct qedi_ctx
), 0);
630 QEDI_ERR(NULL
, "Could not allocate shost\n");
631 goto exit_setup_shost
;
634 shost
->max_id
= QEDI_MAX_ISCSI_CONNS_PER_HBA
;
635 shost
->max_channel
= 0;
637 shost
->max_cmd_len
= 16;
638 shost
->transportt
= qedi_scsi_transport
;
640 qedi
= iscsi_host_priv(shost
);
641 memset(qedi
, 0, sizeof(*qedi
));
643 qedi
->dbg_ctx
.host_no
= shost
->host_no
;
645 qedi
->dbg_ctx
.pdev
= pdev
;
646 qedi
->max_active_conns
= ISCSI_MAX_SESS_PER_HBA
;
647 qedi
->max_sqes
= QEDI_SQ_SIZE
;
649 shost
->nr_hw_queues
= MIN_NUM_CPUS_MSIX(qedi
);
651 pci_set_drvdata(pdev
, qedi
);
657 static int qedi_ll2_rx(void *cookie
, struct sk_buff
*skb
, u32 arg1
, u32 arg2
)
659 struct qedi_ctx
*qedi
= (struct qedi_ctx
*)cookie
;
660 struct qedi_uio_dev
*udev
;
661 struct qedi_uio_ctrl
*uctrl
;
662 struct skb_work_list
*work
;
666 QEDI_ERR(NULL
, "qedi is NULL\n");
670 if (!test_bit(UIO_DEV_OPENED
, &qedi
->flags
)) {
671 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_UIO
,
672 "UIO DEV is not opened\n");
677 eh
= (struct ethhdr
*)skb
->data
;
678 /* Undo VLAN encapsulation */
679 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
680 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
681 eh
= (struct ethhdr
*)skb_pull(skb
, VLAN_HLEN
);
682 skb_reset_mac_header(skb
);
685 /* Filter out non FIP/FCoE frames here to free them faster */
686 if (eh
->h_proto
!= htons(ETH_P_ARP
) &&
687 eh
->h_proto
!= htons(ETH_P_IP
) &&
688 eh
->h_proto
!= htons(ETH_P_IPV6
)) {
689 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_LL2
,
690 "Dropping frame ethertype [0x%x] len [0x%x].\n",
691 eh
->h_proto
, skb
->len
);
696 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_LL2
,
697 "Allowed frame ethertype [0x%x] len [0x%x].\n",
698 eh
->h_proto
, skb
->len
);
703 work
= kzalloc(sizeof(*work
), GFP_ATOMIC
);
705 QEDI_WARN(&qedi
->dbg_ctx
,
706 "Could not allocate work so dropping frame.\n");
711 INIT_LIST_HEAD(&work
->list
);
714 if (skb_vlan_tag_present(skb
))
715 work
->vlan_id
= skb_vlan_tag_get(skb
);
718 __vlan_insert_tag(work
->skb
, htons(ETH_P_8021Q
), work
->vlan_id
);
720 spin_lock_bh(&qedi
->ll2_lock
);
721 list_add_tail(&work
->list
, &qedi
->ll2_skb_list
);
722 spin_unlock_bh(&qedi
->ll2_lock
);
724 wake_up_process(qedi
->ll2_recv_thread
);
729 /* map this skb to iscsiuio mmaped region */
730 static int qedi_ll2_process_skb(struct qedi_ctx
*qedi
, struct sk_buff
*skb
,
733 struct qedi_uio_dev
*udev
= NULL
;
734 struct qedi_uio_ctrl
*uctrl
= NULL
;
735 struct qedi_rx_bd rxbd
;
736 struct qedi_rx_bd
*p_rxbd
;
743 QEDI_ERR(NULL
, "qedi is NULL\n");
750 ++uctrl
->hw_rx_prod_cnt
;
751 prod
= (uctrl
->hw_rx_prod
+ 1) % RX_RING
;
753 pkt
= udev
->rx_pkt
+ (prod
* qedi_ll2_buf_size
);
754 len
= min_t(u32
, skb
->len
, (u32
)qedi_ll2_buf_size
);
755 memcpy(pkt
, skb
->data
, len
);
757 memset(&rxbd
, 0, sizeof(rxbd
));
758 rxbd
.rx_pkt_index
= prod
;
759 rxbd
.rx_pkt_len
= len
;
760 rxbd
.vlan_id
= vlan_id
;
762 uctrl
->hw_rx_bd_prod
= (uctrl
->hw_rx_bd_prod
+ 1) % QEDI_NUM_RX_BD
;
763 rx_bd_prod
= uctrl
->hw_rx_bd_prod
;
764 p_rxbd
= (struct qedi_rx_bd
*)udev
->ll2_ring
;
765 p_rxbd
+= rx_bd_prod
;
767 memcpy(p_rxbd
, &rxbd
, sizeof(rxbd
));
769 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_LL2
,
770 "hw_rx_prod [%d] prod [%d] hw_rx_bd_prod [%d] rx_pkt_idx [%d] rx_len [%d].\n",
771 uctrl
->hw_rx_prod
, prod
, uctrl
->hw_rx_bd_prod
,
772 rxbd
.rx_pkt_index
, rxbd
.rx_pkt_len
);
773 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_LL2
,
774 "host_rx_cons [%d] hw_rx_bd_cons [%d].\n",
775 uctrl
->host_rx_cons
, uctrl
->host_rx_bd_cons
);
777 uctrl
->hw_rx_prod
= prod
;
779 /* notify the iscsiuio about new packet */
780 uio_event_notify(&udev
->qedi_uinfo
);
785 static void qedi_ll2_free_skbs(struct qedi_ctx
*qedi
)
787 struct skb_work_list
*work
, *work_tmp
;
789 spin_lock_bh(&qedi
->ll2_lock
);
790 list_for_each_entry_safe(work
, work_tmp
, &qedi
->ll2_skb_list
, list
) {
791 list_del(&work
->list
);
793 kfree_skb(work
->skb
);
796 spin_unlock_bh(&qedi
->ll2_lock
);
799 static int qedi_ll2_recv_thread(void *arg
)
801 struct qedi_ctx
*qedi
= (struct qedi_ctx
*)arg
;
802 struct skb_work_list
*work
, *work_tmp
;
804 set_user_nice(current
, -20);
806 while (!kthread_should_stop()) {
807 spin_lock_bh(&qedi
->ll2_lock
);
808 list_for_each_entry_safe(work
, work_tmp
, &qedi
->ll2_skb_list
,
810 list_del(&work
->list
);
811 qedi_ll2_process_skb(qedi
, work
->skb
, work
->vlan_id
);
812 kfree_skb(work
->skb
);
815 set_current_state(TASK_INTERRUPTIBLE
);
816 spin_unlock_bh(&qedi
->ll2_lock
);
820 __set_current_state(TASK_RUNNING
);
824 static int qedi_set_iscsi_pf_param(struct qedi_ctx
*qedi
)
831 num_sq_pages
= (MAX_OUTSTANDING_TASKS_PER_CON
* 8) / QEDI_PAGE_SIZE
;
833 qedi
->num_queues
= MIN_NUM_CPUS_MSIX(qedi
);
835 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
836 "Number of CQ count is %d\n", qedi
->num_queues
);
838 memset(&qedi
->pf_params
.iscsi_pf_params
, 0,
839 sizeof(qedi
->pf_params
.iscsi_pf_params
));
841 qedi
->p_cpuq
= dma_alloc_coherent(&qedi
->pdev
->dev
,
842 qedi
->num_queues
* sizeof(struct qedi_glbl_q_params
),
843 &qedi
->hw_p_cpuq
, GFP_KERNEL
);
845 QEDI_ERR(&qedi
->dbg_ctx
, "dma_alloc_coherent fail\n");
850 rval
= qedi_alloc_global_queues(qedi
);
852 QEDI_ERR(&qedi
->dbg_ctx
, "Global queue allocation failed.\n");
857 qedi
->pf_params
.iscsi_pf_params
.num_cons
= QEDI_MAX_ISCSI_CONNS_PER_HBA
;
858 qedi
->pf_params
.iscsi_pf_params
.num_tasks
= QEDI_MAX_ISCSI_TASK
;
859 qedi
->pf_params
.iscsi_pf_params
.half_way_close_timeout
= 10;
860 qedi
->pf_params
.iscsi_pf_params
.num_sq_pages_in_ring
= num_sq_pages
;
861 qedi
->pf_params
.iscsi_pf_params
.num_r2tq_pages_in_ring
= num_sq_pages
;
862 qedi
->pf_params
.iscsi_pf_params
.num_uhq_pages_in_ring
= num_sq_pages
;
863 qedi
->pf_params
.iscsi_pf_params
.num_queues
= qedi
->num_queues
;
864 qedi
->pf_params
.iscsi_pf_params
.debug_mode
= qedi_fw_debug
;
865 qedi
->pf_params
.iscsi_pf_params
.two_msl_timer
= 4000;
866 qedi
->pf_params
.iscsi_pf_params
.max_fin_rt
= 2;
868 for (log_page_size
= 0 ; log_page_size
< 32 ; log_page_size
++) {
869 if ((1 << log_page_size
) == QEDI_PAGE_SIZE
)
872 qedi
->pf_params
.iscsi_pf_params
.log_page_size
= log_page_size
;
874 qedi
->pf_params
.iscsi_pf_params
.glbl_q_params_addr
=
875 (u64
)qedi
->hw_p_cpuq
;
877 /* RQ BDQ initializations.
878 * rq_num_entries: suggested value for Initiator is 16 (4KB RQ)
879 * rqe_log_size: 8 for 256B RQE
881 qedi
->pf_params
.iscsi_pf_params
.rqe_log_size
= 8;
882 /* BDQ address and size */
883 qedi
->pf_params
.iscsi_pf_params
.bdq_pbl_base_addr
[BDQ_ID_RQ
] =
884 qedi
->bdq_pbl_list_dma
;
885 qedi
->pf_params
.iscsi_pf_params
.bdq_pbl_num_entries
[BDQ_ID_RQ
] =
886 qedi
->bdq_pbl_list_num_entries
;
887 qedi
->pf_params
.iscsi_pf_params
.rq_buffer_size
= QEDI_BDQ_BUF_SIZE
;
889 /* cq_num_entries: num_tasks + rq_num_entries */
890 qedi
->pf_params
.iscsi_pf_params
.cq_num_entries
= 2048;
892 qedi
->pf_params
.iscsi_pf_params
.gl_rq_pi
= QEDI_PROTO_CQ_PROD_IDX
;
893 qedi
->pf_params
.iscsi_pf_params
.gl_cmd_pi
= 1;
899 /* Free DMA coherent memory for array of queue pointers we pass to qed */
900 static void qedi_free_iscsi_pf_param(struct qedi_ctx
*qedi
)
905 size
= qedi
->num_queues
* sizeof(struct qedi_glbl_q_params
);
906 dma_free_coherent(&qedi
->pdev
->dev
, size
, qedi
->p_cpuq
,
910 qedi_free_global_queues(qedi
);
912 kfree(qedi
->global_queues
);
915 static void qedi_get_boot_tgt_info(struct nvm_iscsi_block
*block
,
916 struct qedi_boot_target
*tgt
, u8 index
)
920 ipv6_en
= !!(block
->generic
.ctrl_flags
&
921 NVM_ISCSI_CFG_GEN_IPV6_ENABLED
);
923 snprintf(tgt
->iscsi_name
, sizeof(tgt
->iscsi_name
), "%s\n",
924 block
->target
[index
].target_name
.byte
);
926 tgt
->ipv6_en
= ipv6_en
;
929 snprintf(tgt
->ip_addr
, IPV6_LEN
, "%pI6\n",
930 block
->target
[index
].ipv6_addr
.byte
);
932 snprintf(tgt
->ip_addr
, IPV4_LEN
, "%pI4\n",
933 block
->target
[index
].ipv4_addr
.byte
);
936 static int qedi_find_boot_info(struct qedi_ctx
*qedi
,
937 struct qed_mfw_tlv_iscsi
*iscsi
,
938 struct nvm_iscsi_block
*block
)
940 struct qedi_boot_target
*pri_tgt
= NULL
, *sec_tgt
= NULL
;
941 u32 pri_ctrl_flags
= 0, sec_ctrl_flags
= 0, found
= 0;
942 struct iscsi_cls_session
*cls_sess
;
943 struct iscsi_cls_conn
*cls_conn
;
944 struct qedi_conn
*qedi_conn
;
945 struct iscsi_session
*sess
;
946 struct iscsi_conn
*conn
;
950 pri_ctrl_flags
= !!(block
->target
[0].ctrl_flags
&
951 NVM_ISCSI_CFG_TARGET_ENABLED
);
952 if (pri_ctrl_flags
) {
953 pri_tgt
= kzalloc(sizeof(*pri_tgt
), GFP_KERNEL
);
956 qedi_get_boot_tgt_info(block
, pri_tgt
, 0);
959 sec_ctrl_flags
= !!(block
->target
[1].ctrl_flags
&
960 NVM_ISCSI_CFG_TARGET_ENABLED
);
961 if (sec_ctrl_flags
) {
962 sec_tgt
= kzalloc(sizeof(*sec_tgt
), GFP_KERNEL
);
967 qedi_get_boot_tgt_info(block
, sec_tgt
, 1);
970 for (i
= 0; i
< qedi
->max_active_conns
; i
++) {
971 qedi_conn
= qedi_get_conn_from_id(qedi
, i
);
975 if (qedi_conn
->ep
->ip_type
== TCP_IPV4
)
976 snprintf(ep_ip_addr
, IPV4_LEN
, "%pI4\n",
977 qedi_conn
->ep
->dst_addr
);
979 snprintf(ep_ip_addr
, IPV6_LEN
, "%pI6\n",
980 qedi_conn
->ep
->dst_addr
);
982 cls_conn
= qedi_conn
->cls_conn
;
983 conn
= cls_conn
->dd_data
;
984 cls_sess
= iscsi_conn_to_session(cls_conn
);
985 sess
= cls_sess
->dd_data
;
987 if (!iscsi_is_session_online(cls_sess
))
990 if (!sess
->targetname
)
993 if (pri_ctrl_flags
) {
994 if (!strcmp(pri_tgt
->iscsi_name
, sess
->targetname
) &&
995 !strcmp(pri_tgt
->ip_addr
, ep_ip_addr
)) {
1001 if (sec_ctrl_flags
) {
1002 if (!strcmp(sec_tgt
->iscsi_name
, sess
->targetname
) &&
1003 !strcmp(sec_tgt
->ip_addr
, ep_ip_addr
)) {
1011 if (conn
->hdrdgst_en
) {
1012 iscsi
->header_digest_set
= true;
1013 iscsi
->header_digest
= 1;
1016 if (conn
->datadgst_en
) {
1017 iscsi
->data_digest_set
= true;
1018 iscsi
->data_digest
= 1;
1020 iscsi
->boot_taget_portal_set
= true;
1021 iscsi
->boot_taget_portal
= sess
->tpgt
;
1036 static void qedi_get_generic_tlv_data(void *dev
, struct qed_generic_tlvs
*data
)
1038 struct qedi_ctx
*qedi
;
1041 QEDI_INFO(NULL
, QEDI_LOG_EVT
,
1042 "dev is NULL so ignoring get_generic_tlv_data request.\n");
1045 qedi
= (struct qedi_ctx
*)dev
;
1047 memset(data
, 0, sizeof(struct qed_generic_tlvs
));
1048 ether_addr_copy(data
->mac
[0], qedi
->mac
);
1052 * Protocol TLV handler
1054 static void qedi_get_protocol_tlv_data(void *dev
, void *data
)
1056 struct qed_mfw_tlv_iscsi
*iscsi
= data
;
1057 struct qed_iscsi_stats
*fw_iscsi_stats
;
1058 struct nvm_iscsi_block
*block
= NULL
;
1059 u32 chap_en
= 0, mchap_en
= 0;
1060 struct qedi_ctx
*qedi
= dev
;
1063 fw_iscsi_stats
= kmalloc(sizeof(*fw_iscsi_stats
), GFP_KERNEL
);
1064 if (!fw_iscsi_stats
) {
1065 QEDI_ERR(&qedi
->dbg_ctx
,
1066 "Could not allocate memory for fw_iscsi_stats.\n");
1070 mutex_lock(&qedi
->stats_lock
);
1071 /* Query firmware for offload stats */
1072 qedi_ops
->get_stats(qedi
->cdev
, fw_iscsi_stats
);
1073 mutex_unlock(&qedi
->stats_lock
);
1075 iscsi
->rx_frames_set
= true;
1076 iscsi
->rx_frames
= fw_iscsi_stats
->iscsi_rx_packet_cnt
;
1077 iscsi
->rx_bytes_set
= true;
1078 iscsi
->rx_bytes
= fw_iscsi_stats
->iscsi_rx_bytes_cnt
;
1079 iscsi
->tx_frames_set
= true;
1080 iscsi
->tx_frames
= fw_iscsi_stats
->iscsi_tx_packet_cnt
;
1081 iscsi
->tx_bytes_set
= true;
1082 iscsi
->tx_bytes
= fw_iscsi_stats
->iscsi_tx_bytes_cnt
;
1083 iscsi
->frame_size_set
= true;
1084 iscsi
->frame_size
= qedi
->ll2_mtu
;
1085 block
= qedi_get_nvram_block(qedi
);
1087 chap_en
= !!(block
->generic
.ctrl_flags
&
1088 NVM_ISCSI_CFG_GEN_CHAP_ENABLED
);
1089 mchap_en
= !!(block
->generic
.ctrl_flags
&
1090 NVM_ISCSI_CFG_GEN_CHAP_MUTUAL_ENABLED
);
1092 iscsi
->auth_method_set
= (chap_en
|| mchap_en
) ? true : false;
1093 iscsi
->auth_method
= 1;
1095 iscsi
->auth_method
= 2;
1097 iscsi
->auth_method
= 3;
1099 iscsi
->tx_desc_size_set
= true;
1100 iscsi
->tx_desc_size
= QEDI_SQ_SIZE
;
1101 iscsi
->rx_desc_size_set
= true;
1102 iscsi
->rx_desc_size
= QEDI_CQ_SIZE
;
1104 /* tpgt, hdr digest, data digest */
1105 rval
= qedi_find_boot_info(qedi
, iscsi
, block
);
1107 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1108 "Boot target not set");
1111 kfree(fw_iscsi_stats
);
1116 static void qedi_link_update(void *dev
, struct qed_link_output
*link
)
1118 struct qedi_ctx
*qedi
= (struct qedi_ctx
*)dev
;
1120 if (link
->link_up
) {
1121 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
, "Link Up event.\n");
1122 atomic_set(&qedi
->link_state
, QEDI_LINK_UP
);
1124 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1125 "Link Down event.\n");
1126 atomic_set(&qedi
->link_state
, QEDI_LINK_DOWN
);
1130 static struct qed_iscsi_cb_ops qedi_cb_ops
= {
1132 .link_update
= qedi_link_update
,
1133 .get_protocol_tlv_data
= qedi_get_protocol_tlv_data
,
1134 .get_generic_tlv_data
= qedi_get_generic_tlv_data
,
1138 static int qedi_queue_cqe(struct qedi_ctx
*qedi
, union iscsi_cqe
*cqe
,
1139 u16 que_idx
, struct qedi_percpu_s
*p
)
1141 struct qedi_work
*qedi_work
;
1142 struct qedi_conn
*q_conn
;
1143 struct iscsi_conn
*conn
;
1144 struct qedi_cmd
*qedi_cmd
;
1148 iscsi_cid
= cqe
->cqe_common
.conn_id
;
1149 q_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
1151 QEDI_WARN(&qedi
->dbg_ctx
,
1152 "Session no longer exists for cid=0x%x!!\n",
1156 conn
= q_conn
->cls_conn
->dd_data
;
1158 switch (cqe
->cqe_common
.cqe_type
) {
1159 case ISCSI_CQE_TYPE_SOLICITED
:
1160 case ISCSI_CQE_TYPE_SOLICITED_WITH_SENSE
:
1161 qedi_cmd
= qedi_get_cmd_from_tid(qedi
, cqe
->cqe_solicited
.itid
);
1166 INIT_LIST_HEAD(&qedi_cmd
->cqe_work
.list
);
1167 qedi_cmd
->cqe_work
.qedi
= qedi
;
1168 memcpy(&qedi_cmd
->cqe_work
.cqe
, cqe
, sizeof(union iscsi_cqe
));
1169 qedi_cmd
->cqe_work
.que_idx
= que_idx
;
1170 qedi_cmd
->cqe_work
.is_solicited
= true;
1171 list_add_tail(&qedi_cmd
->cqe_work
.list
, &p
->work_list
);
1173 case ISCSI_CQE_TYPE_UNSOLICITED
:
1174 case ISCSI_CQE_TYPE_DUMMY
:
1175 case ISCSI_CQE_TYPE_TASK_CLEANUP
:
1176 qedi_work
= kzalloc(sizeof(*qedi_work
), GFP_ATOMIC
);
1181 INIT_LIST_HEAD(&qedi_work
->list
);
1182 qedi_work
->qedi
= qedi
;
1183 memcpy(&qedi_work
->cqe
, cqe
, sizeof(union iscsi_cqe
));
1184 qedi_work
->que_idx
= que_idx
;
1185 qedi_work
->is_solicited
= false;
1186 list_add_tail(&qedi_work
->list
, &p
->work_list
);
1190 QEDI_ERR(&qedi
->dbg_ctx
, "FW Error cqe.\n");
1195 static bool qedi_process_completions(struct qedi_fastpath
*fp
)
1197 struct qedi_ctx
*qedi
= fp
->qedi
;
1198 struct qed_sb_info
*sb_info
= fp
->sb_info
;
1199 struct status_block_e4
*sb
= sb_info
->sb_virt
;
1200 struct qedi_percpu_s
*p
= NULL
;
1201 struct global_queue
*que
;
1203 unsigned long flags
;
1204 union iscsi_cqe
*cqe
;
1208 /* Get the current firmware producer index */
1209 prod_idx
= sb
->pi_array
[QEDI_PROTO_CQ_PROD_IDX
];
1211 if (prod_idx
>= QEDI_CQ_SIZE
)
1212 prod_idx
= prod_idx
% QEDI_CQ_SIZE
;
1214 que
= qedi
->global_queues
[fp
->sb_id
];
1215 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
1216 "Before: global queue=%p prod_idx=%d cons_idx=%d, sb_id=%d\n",
1217 que
, prod_idx
, que
->cq_cons_idx
, fp
->sb_id
);
1219 qedi
->intr_cpu
= fp
->sb_id
;
1220 cpu
= smp_processor_id();
1221 p
= &per_cpu(qedi_percpu
, cpu
);
1223 if (unlikely(!p
->iothread
))
1226 spin_lock_irqsave(&p
->p_work_lock
, flags
);
1227 while (que
->cq_cons_idx
!= prod_idx
) {
1228 cqe
= &que
->cq
[que
->cq_cons_idx
];
1230 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
1231 "cqe=%p prod_idx=%d cons_idx=%d.\n",
1232 cqe
, prod_idx
, que
->cq_cons_idx
);
1234 ret
= qedi_queue_cqe(qedi
, cqe
, fp
->sb_id
, p
);
1236 QEDI_WARN(&qedi
->dbg_ctx
,
1237 "Dropping CQE 0x%x for cid=0x%x.\n",
1238 que
->cq_cons_idx
, cqe
->cqe_common
.conn_id
);
1241 if (que
->cq_cons_idx
== QEDI_CQ_SIZE
)
1242 que
->cq_cons_idx
= 0;
1244 wake_up_process(p
->iothread
);
1245 spin_unlock_irqrestore(&p
->p_work_lock
, flags
);
1250 static bool qedi_fp_has_work(struct qedi_fastpath
*fp
)
1252 struct qedi_ctx
*qedi
= fp
->qedi
;
1253 struct global_queue
*que
;
1254 struct qed_sb_info
*sb_info
= fp
->sb_info
;
1255 struct status_block_e4
*sb
= sb_info
->sb_virt
;
1260 /* Get the current firmware producer index */
1261 prod_idx
= sb
->pi_array
[QEDI_PROTO_CQ_PROD_IDX
];
1263 /* Get the pointer to the global CQ this completion is on */
1264 que
= qedi
->global_queues
[fp
->sb_id
];
1266 /* prod idx wrap around uint16 */
1267 if (prod_idx
>= QEDI_CQ_SIZE
)
1268 prod_idx
= prod_idx
% QEDI_CQ_SIZE
;
1270 return (que
->cq_cons_idx
!= prod_idx
);
1273 /* MSI-X fastpath handler code */
1274 static irqreturn_t
qedi_msix_handler(int irq
, void *dev_id
)
1276 struct qedi_fastpath
*fp
= dev_id
;
1277 struct qedi_ctx
*qedi
= fp
->qedi
;
1278 bool wake_io_thread
= true;
1280 qed_sb_ack(fp
->sb_info
, IGU_INT_DISABLE
, 0);
1283 wake_io_thread
= qedi_process_completions(fp
);
1284 if (wake_io_thread
) {
1285 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
1286 "process already running\n");
1289 if (qedi_fp_has_work(fp
) == 0)
1290 qed_sb_update_sb_idx(fp
->sb_info
);
1292 /* Check for more work */
1295 if (qedi_fp_has_work(fp
) == 0)
1296 qed_sb_ack(fp
->sb_info
, IGU_INT_ENABLE
, 1);
1303 /* simd handler for MSI/INTa */
1304 static void qedi_simd_int_handler(void *cookie
)
1306 /* Cookie is qedi_ctx struct */
1307 struct qedi_ctx
*qedi
= (struct qedi_ctx
*)cookie
;
1309 QEDI_WARN(&qedi
->dbg_ctx
, "qedi=%p.\n", qedi
);
1312 #define QEDI_SIMD_HANDLER_NUM 0
1313 static void qedi_sync_free_irqs(struct qedi_ctx
*qedi
)
1318 if (qedi
->int_info
.msix_cnt
) {
1319 for (i
= 0; i
< qedi
->int_info
.used_cnt
; i
++) {
1320 idx
= i
* qedi
->dev_info
.common
.num_hwfns
+
1321 qedi_ops
->common
->get_affin_hwfn_idx(qedi
->cdev
);
1323 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1324 "Freeing IRQ #%d vector_idx=%d.\n", i
, idx
);
1326 synchronize_irq(qedi
->int_info
.msix
[idx
].vector
);
1327 irq_set_affinity_hint(qedi
->int_info
.msix
[idx
].vector
,
1329 free_irq(qedi
->int_info
.msix
[idx
].vector
,
1330 &qedi
->fp_array
[i
]);
1333 qedi_ops
->common
->simd_handler_clean(qedi
->cdev
,
1334 QEDI_SIMD_HANDLER_NUM
);
1337 qedi
->int_info
.used_cnt
= 0;
1338 qedi_ops
->common
->set_fp_int(qedi
->cdev
, 0);
1341 static int qedi_request_msix_irq(struct qedi_ctx
*qedi
)
1346 cpu
= cpumask_first(cpu_online_mask
);
1347 for (i
= 0; i
< MIN_NUM_CPUS_MSIX(qedi
); i
++) {
1348 idx
= i
* qedi
->dev_info
.common
.num_hwfns
+
1349 qedi_ops
->common
->get_affin_hwfn_idx(qedi
->cdev
);
1351 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1352 "dev_info: num_hwfns=%d affin_hwfn_idx=%d.\n",
1353 qedi
->dev_info
.common
.num_hwfns
,
1354 qedi_ops
->common
->get_affin_hwfn_idx(qedi
->cdev
));
1356 rc
= request_irq(qedi
->int_info
.msix
[idx
].vector
,
1357 qedi_msix_handler
, 0, "qedi",
1358 &qedi
->fp_array
[i
]);
1360 QEDI_WARN(&qedi
->dbg_ctx
, "request_irq failed.\n");
1361 qedi_sync_free_irqs(qedi
);
1364 qedi
->int_info
.used_cnt
++;
1365 rc
= irq_set_affinity_hint(qedi
->int_info
.msix
[idx
].vector
,
1367 cpu
= cpumask_next(cpu
, cpu_online_mask
);
1373 static int qedi_setup_int(struct qedi_ctx
*qedi
)
1377 rc
= qedi_ops
->common
->set_fp_int(qedi
->cdev
, num_online_cpus());
1378 rc
= qedi_ops
->common
->get_fp_int(qedi
->cdev
, &qedi
->int_info
);
1380 goto exit_setup_int
;
1382 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
1383 "Number of msix_cnt = 0x%x num of cpus = 0x%x\n",
1384 qedi
->int_info
.msix_cnt
, num_online_cpus());
1386 if (qedi
->int_info
.msix_cnt
) {
1387 rc
= qedi_request_msix_irq(qedi
);
1388 goto exit_setup_int
;
1390 qedi_ops
->common
->simd_handler_config(qedi
->cdev
, &qedi
,
1391 QEDI_SIMD_HANDLER_NUM
,
1392 qedi_simd_int_handler
);
1393 qedi
->int_info
.used_cnt
= 1;
1400 static void qedi_free_nvm_iscsi_cfg(struct qedi_ctx
*qedi
)
1402 if (qedi
->iscsi_image
)
1403 dma_free_coherent(&qedi
->pdev
->dev
,
1404 sizeof(struct qedi_nvm_iscsi_image
),
1405 qedi
->iscsi_image
, qedi
->nvm_buf_dma
);
1408 static int qedi_alloc_nvm_iscsi_cfg(struct qedi_ctx
*qedi
)
1410 qedi
->iscsi_image
= dma_alloc_coherent(&qedi
->pdev
->dev
,
1411 sizeof(struct qedi_nvm_iscsi_image
),
1412 &qedi
->nvm_buf_dma
, GFP_KERNEL
);
1413 if (!qedi
->iscsi_image
) {
1414 QEDI_ERR(&qedi
->dbg_ctx
, "Could not allocate NVM BUF.\n");
1417 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1418 "NVM BUF addr=0x%p dma=0x%llx.\n", qedi
->iscsi_image
,
1424 static void qedi_free_bdq(struct qedi_ctx
*qedi
)
1428 if (qedi
->bdq_pbl_list
)
1429 dma_free_coherent(&qedi
->pdev
->dev
, QEDI_PAGE_SIZE
,
1430 qedi
->bdq_pbl_list
, qedi
->bdq_pbl_list_dma
);
1433 dma_free_coherent(&qedi
->pdev
->dev
, qedi
->bdq_pbl_mem_size
,
1434 qedi
->bdq_pbl
, qedi
->bdq_pbl_dma
);
1436 for (i
= 0; i
< QEDI_BDQ_NUM
; i
++) {
1437 if (qedi
->bdq
[i
].buf_addr
) {
1438 dma_free_coherent(&qedi
->pdev
->dev
, QEDI_BDQ_BUF_SIZE
,
1439 qedi
->bdq
[i
].buf_addr
,
1440 qedi
->bdq
[i
].buf_dma
);
1445 static void qedi_free_global_queues(struct qedi_ctx
*qedi
)
1448 struct global_queue
**gl
= qedi
->global_queues
;
1450 for (i
= 0; i
< qedi
->num_queues
; i
++) {
1455 dma_free_coherent(&qedi
->pdev
->dev
, gl
[i
]->cq_mem_size
,
1456 gl
[i
]->cq
, gl
[i
]->cq_dma
);
1458 dma_free_coherent(&qedi
->pdev
->dev
, gl
[i
]->cq_pbl_size
,
1459 gl
[i
]->cq_pbl
, gl
[i
]->cq_pbl_dma
);
1463 qedi_free_bdq(qedi
);
1464 qedi_free_nvm_iscsi_cfg(qedi
);
1467 static int qedi_alloc_bdq(struct qedi_ctx
*qedi
)
1470 struct scsi_bd
*pbl
;
1474 /* Alloc dma memory for BDQ buffers */
1475 for (i
= 0; i
< QEDI_BDQ_NUM
; i
++) {
1476 qedi
->bdq
[i
].buf_addr
=
1477 dma_alloc_coherent(&qedi
->pdev
->dev
,
1479 &qedi
->bdq
[i
].buf_dma
,
1481 if (!qedi
->bdq
[i
].buf_addr
) {
1482 QEDI_ERR(&qedi
->dbg_ctx
,
1483 "Could not allocate BDQ buffer %d.\n", i
);
1488 /* Alloc dma memory for BDQ page buffer list */
1489 qedi
->bdq_pbl_mem_size
= QEDI_BDQ_NUM
* sizeof(struct scsi_bd
);
1490 qedi
->bdq_pbl_mem_size
= ALIGN(qedi
->bdq_pbl_mem_size
, QEDI_PAGE_SIZE
);
1491 qedi
->rq_num_entries
= qedi
->bdq_pbl_mem_size
/ sizeof(struct scsi_bd
);
1493 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
, "rq_num_entries = %d.\n",
1494 qedi
->rq_num_entries
);
1496 qedi
->bdq_pbl
= dma_alloc_coherent(&qedi
->pdev
->dev
,
1497 qedi
->bdq_pbl_mem_size
,
1498 &qedi
->bdq_pbl_dma
, GFP_KERNEL
);
1499 if (!qedi
->bdq_pbl
) {
1500 QEDI_ERR(&qedi
->dbg_ctx
, "Could not allocate BDQ PBL.\n");
1505 * Populate BDQ PBL with physical and virtual address of individual
1508 pbl
= (struct scsi_bd
*)qedi
->bdq_pbl
;
1509 for (i
= 0; i
< QEDI_BDQ_NUM
; i
++) {
1511 cpu_to_le32(QEDI_U64_HI(qedi
->bdq
[i
].buf_dma
));
1513 cpu_to_le32(QEDI_U64_LO(qedi
->bdq
[i
].buf_dma
));
1514 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1515 "pbl [0x%p] pbl->address hi [0x%llx] lo [0x%llx], idx [%d]\n",
1516 pbl
, pbl
->address
.hi
, pbl
->address
.lo
, i
);
1517 pbl
->opaque
.iscsi_opaque
.reserved_zero
[0] = 0;
1518 pbl
->opaque
.iscsi_opaque
.reserved_zero
[1] = 0;
1519 pbl
->opaque
.iscsi_opaque
.reserved_zero
[2] = 0;
1520 pbl
->opaque
.iscsi_opaque
.opaque
= cpu_to_le16(i
);
1524 /* Allocate list of PBL pages */
1525 qedi
->bdq_pbl_list
= dma_alloc_coherent(&qedi
->pdev
->dev
,
1527 &qedi
->bdq_pbl_list_dma
,
1529 if (!qedi
->bdq_pbl_list
) {
1530 QEDI_ERR(&qedi
->dbg_ctx
,
1531 "Could not allocate list of PBL pages.\n");
1536 * Now populate PBL list with pages that contain pointers to the
1537 * individual buffers.
1539 qedi
->bdq_pbl_list_num_entries
= qedi
->bdq_pbl_mem_size
/
1541 list
= (u64
*)qedi
->bdq_pbl_list
;
1542 page
= qedi
->bdq_pbl_list_dma
;
1543 for (i
= 0; i
< qedi
->bdq_pbl_list_num_entries
; i
++) {
1544 *list
= qedi
->bdq_pbl_dma
;
1546 page
+= QEDI_PAGE_SIZE
;
1552 static int qedi_alloc_global_queues(struct qedi_ctx
*qedi
)
1562 * Number of global queues (CQ / RQ). This should
1563 * be <= number of available MSIX vectors for the PF
1565 if (!qedi
->num_queues
) {
1566 QEDI_ERR(&qedi
->dbg_ctx
, "No MSI-X vectors available!\n");
1570 /* Make sure we allocated the PBL that will contain the physical
1571 * addresses of our queues
1573 if (!qedi
->p_cpuq
) {
1575 goto mem_alloc_failure
;
1578 qedi
->global_queues
= kzalloc((sizeof(struct global_queue
*) *
1579 qedi
->num_queues
), GFP_KERNEL
);
1580 if (!qedi
->global_queues
) {
1581 QEDI_ERR(&qedi
->dbg_ctx
,
1582 "Unable to allocate global queues array ptr memory\n");
1585 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
1586 "qedi->global_queues=%p.\n", qedi
->global_queues
);
1588 /* Allocate DMA coherent buffers for BDQ */
1589 rc
= qedi_alloc_bdq(qedi
);
1591 goto mem_alloc_failure
;
1593 /* Allocate DMA coherent buffers for NVM_ISCSI_CFG */
1594 rc
= qedi_alloc_nvm_iscsi_cfg(qedi
);
1596 goto mem_alloc_failure
;
1598 /* Allocate a CQ and an associated PBL for each MSI-X
1601 for (i
= 0; i
< qedi
->num_queues
; i
++) {
1602 qedi
->global_queues
[i
] =
1603 kzalloc(sizeof(*qedi
->global_queues
[0]),
1605 if (!qedi
->global_queues
[i
]) {
1606 QEDI_ERR(&qedi
->dbg_ctx
,
1607 "Unable to allocation global queue %d.\n", i
);
1608 goto mem_alloc_failure
;
1611 qedi
->global_queues
[i
]->cq_mem_size
=
1612 (QEDI_CQ_SIZE
+ 8) * sizeof(union iscsi_cqe
);
1613 qedi
->global_queues
[i
]->cq_mem_size
=
1614 (qedi
->global_queues
[i
]->cq_mem_size
+
1615 (QEDI_PAGE_SIZE
- 1));
1617 qedi
->global_queues
[i
]->cq_pbl_size
=
1618 (qedi
->global_queues
[i
]->cq_mem_size
/
1619 QEDI_PAGE_SIZE
) * sizeof(void *);
1620 qedi
->global_queues
[i
]->cq_pbl_size
=
1621 (qedi
->global_queues
[i
]->cq_pbl_size
+
1622 (QEDI_PAGE_SIZE
- 1));
1624 qedi
->global_queues
[i
]->cq
= dma_alloc_coherent(&qedi
->pdev
->dev
,
1625 qedi
->global_queues
[i
]->cq_mem_size
,
1626 &qedi
->global_queues
[i
]->cq_dma
,
1629 if (!qedi
->global_queues
[i
]->cq
) {
1630 QEDI_WARN(&qedi
->dbg_ctx
,
1631 "Could not allocate cq.\n");
1633 goto mem_alloc_failure
;
1635 qedi
->global_queues
[i
]->cq_pbl
= dma_alloc_coherent(&qedi
->pdev
->dev
,
1636 qedi
->global_queues
[i
]->cq_pbl_size
,
1637 &qedi
->global_queues
[i
]->cq_pbl_dma
,
1640 if (!qedi
->global_queues
[i
]->cq_pbl
) {
1641 QEDI_WARN(&qedi
->dbg_ctx
,
1642 "Could not allocate cq PBL.\n");
1644 goto mem_alloc_failure
;
1648 num_pages
= qedi
->global_queues
[i
]->cq_mem_size
/
1650 page
= qedi
->global_queues
[i
]->cq_dma
;
1651 pbl
= (u32
*)qedi
->global_queues
[i
]->cq_pbl
;
1653 while (num_pages
--) {
1656 *pbl
= (u32
)((u64
)page
>> 32);
1658 page
+= QEDI_PAGE_SIZE
;
1662 list
= (u32
*)qedi
->p_cpuq
;
1665 * The list is built as follows: CQ#0 PBL pointer, RQ#0 PBL pointer,
1666 * CQ#1 PBL pointer, RQ#1 PBL pointer, etc. Each PBL pointer points
1667 * to the physical address which contains an array of pointers to the
1668 * physical addresses of the specific queue pages.
1670 for (i
= 0; i
< qedi
->num_queues
; i
++) {
1671 *list
= (u32
)qedi
->global_queues
[i
]->cq_pbl_dma
;
1673 *list
= (u32
)((u64
)qedi
->global_queues
[i
]->cq_pbl_dma
>> 32);
1678 *list
= (u32
)((u64
)0 >> 32);
1685 qedi_free_global_queues(qedi
);
1689 int qedi_alloc_sq(struct qedi_ctx
*qedi
, struct qedi_endpoint
*ep
)
1699 /* Calculate appropriate queue and PBL sizes */
1700 ep
->sq_mem_size
= QEDI_SQ_SIZE
* sizeof(struct iscsi_wqe
);
1701 ep
->sq_mem_size
+= QEDI_PAGE_SIZE
- 1;
1703 ep
->sq_pbl_size
= (ep
->sq_mem_size
/ QEDI_PAGE_SIZE
) * sizeof(void *);
1704 ep
->sq_pbl_size
= ep
->sq_pbl_size
+ QEDI_PAGE_SIZE
;
1706 ep
->sq
= dma_alloc_coherent(&qedi
->pdev
->dev
, ep
->sq_mem_size
,
1707 &ep
->sq_dma
, GFP_KERNEL
);
1709 QEDI_WARN(&qedi
->dbg_ctx
,
1710 "Could not allocate send queue.\n");
1714 ep
->sq_pbl
= dma_alloc_coherent(&qedi
->pdev
->dev
, ep
->sq_pbl_size
,
1715 &ep
->sq_pbl_dma
, GFP_KERNEL
);
1717 QEDI_WARN(&qedi
->dbg_ctx
,
1718 "Could not allocate send queue PBL.\n");
1724 num_pages
= ep
->sq_mem_size
/ QEDI_PAGE_SIZE
;
1726 pbl
= (u32
*)ep
->sq_pbl
;
1728 while (num_pages
--) {
1731 *pbl
= (u32
)((u64
)page
>> 32);
1733 page
+= QEDI_PAGE_SIZE
;
1739 dma_free_coherent(&qedi
->pdev
->dev
, ep
->sq_mem_size
, ep
->sq
,
1745 void qedi_free_sq(struct qedi_ctx
*qedi
, struct qedi_endpoint
*ep
)
1748 dma_free_coherent(&qedi
->pdev
->dev
, ep
->sq_pbl_size
, ep
->sq_pbl
,
1751 dma_free_coherent(&qedi
->pdev
->dev
, ep
->sq_mem_size
, ep
->sq
,
1755 int qedi_get_task_idx(struct qedi_ctx
*qedi
)
1760 tmp_idx
= find_first_zero_bit(qedi
->task_idx_map
,
1761 MAX_ISCSI_TASK_ENTRIES
);
1763 if (tmp_idx
>= MAX_ISCSI_TASK_ENTRIES
) {
1764 QEDI_ERR(&qedi
->dbg_ctx
, "FW task context pool is full.\n");
1769 if (test_and_set_bit(tmp_idx
, qedi
->task_idx_map
))
1776 void qedi_clear_task_idx(struct qedi_ctx
*qedi
, int idx
)
1778 if (!test_and_clear_bit(idx
, qedi
->task_idx_map
))
1779 QEDI_ERR(&qedi
->dbg_ctx
,
1780 "FW task context, already cleared, tid=0x%x\n", idx
);
1783 void qedi_update_itt_map(struct qedi_ctx
*qedi
, u32 tid
, u32 proto_itt
,
1784 struct qedi_cmd
*cmd
)
1786 qedi
->itt_map
[tid
].itt
= proto_itt
;
1787 qedi
->itt_map
[tid
].p_cmd
= cmd
;
1789 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1790 "update itt map tid=0x%x, with proto itt=0x%x\n", tid
,
1791 qedi
->itt_map
[tid
].itt
);
1794 void qedi_get_task_tid(struct qedi_ctx
*qedi
, u32 itt
, s16
*tid
)
1798 for (i
= 0; i
< MAX_ISCSI_TASK_ENTRIES
; i
++) {
1799 if (qedi
->itt_map
[i
].itt
== itt
) {
1801 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1802 "Ref itt=0x%x, found at tid=0x%x\n",
1811 void qedi_get_proto_itt(struct qedi_ctx
*qedi
, u32 tid
, u32
*proto_itt
)
1813 *proto_itt
= qedi
->itt_map
[tid
].itt
;
1814 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
1815 "Get itt map tid [0x%x with proto itt[0x%x]",
1819 struct qedi_cmd
*qedi_get_cmd_from_tid(struct qedi_ctx
*qedi
, u32 tid
)
1821 struct qedi_cmd
*cmd
= NULL
;
1823 if (tid
>= MAX_ISCSI_TASK_ENTRIES
)
1826 cmd
= qedi
->itt_map
[tid
].p_cmd
;
1827 if (cmd
->task_id
!= tid
)
1830 qedi
->itt_map
[tid
].p_cmd
= NULL
;
1835 static int qedi_alloc_itt(struct qedi_ctx
*qedi
)
1837 qedi
->itt_map
= kcalloc(MAX_ISCSI_TASK_ENTRIES
,
1838 sizeof(struct qedi_itt_map
), GFP_KERNEL
);
1839 if (!qedi
->itt_map
) {
1840 QEDI_ERR(&qedi
->dbg_ctx
,
1841 "Unable to allocate itt map array memory\n");
1847 static void qedi_free_itt(struct qedi_ctx
*qedi
)
1849 kfree(qedi
->itt_map
);
1852 static struct qed_ll2_cb_ops qedi_ll2_cb_ops
= {
1853 .rx_cb
= qedi_ll2_rx
,
1857 static int qedi_percpu_io_thread(void *arg
)
1859 struct qedi_percpu_s
*p
= arg
;
1860 struct qedi_work
*work
, *tmp
;
1861 unsigned long flags
;
1862 LIST_HEAD(work_list
);
1864 set_user_nice(current
, -20);
1866 while (!kthread_should_stop()) {
1867 spin_lock_irqsave(&p
->p_work_lock
, flags
);
1868 while (!list_empty(&p
->work_list
)) {
1869 list_splice_init(&p
->work_list
, &work_list
);
1870 spin_unlock_irqrestore(&p
->p_work_lock
, flags
);
1872 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
1873 list_del_init(&work
->list
);
1874 qedi_fp_process_cqes(work
);
1875 if (!work
->is_solicited
)
1879 spin_lock_irqsave(&p
->p_work_lock
, flags
);
1881 set_current_state(TASK_INTERRUPTIBLE
);
1882 spin_unlock_irqrestore(&p
->p_work_lock
, flags
);
1885 __set_current_state(TASK_RUNNING
);
1890 static int qedi_cpu_online(unsigned int cpu
)
1892 struct qedi_percpu_s
*p
= this_cpu_ptr(&qedi_percpu
);
1893 struct task_struct
*thread
;
1895 thread
= kthread_create_on_node(qedi_percpu_io_thread
, (void *)p
,
1897 "qedi_thread/%d", cpu
);
1899 return PTR_ERR(thread
);
1901 kthread_bind(thread
, cpu
);
1902 p
->iothread
= thread
;
1903 wake_up_process(thread
);
1907 static int qedi_cpu_offline(unsigned int cpu
)
1909 struct qedi_percpu_s
*p
= this_cpu_ptr(&qedi_percpu
);
1910 struct qedi_work
*work
, *tmp
;
1911 struct task_struct
*thread
;
1913 spin_lock_bh(&p
->p_work_lock
);
1914 thread
= p
->iothread
;
1917 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
1918 list_del_init(&work
->list
);
1919 qedi_fp_process_cqes(work
);
1920 if (!work
->is_solicited
)
1924 spin_unlock_bh(&p
->p_work_lock
);
1926 kthread_stop(thread
);
1930 void qedi_reset_host_mtu(struct qedi_ctx
*qedi
, u16 mtu
)
1932 struct qed_ll2_params params
;
1934 qedi_recover_all_conns(qedi
);
1936 qedi_ops
->ll2
->stop(qedi
->cdev
);
1937 qedi_ll2_free_skbs(qedi
);
1939 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
, "old MTU %u, new MTU %u\n",
1940 qedi
->ll2_mtu
, mtu
);
1941 memset(¶ms
, 0, sizeof(params
));
1942 qedi
->ll2_mtu
= mtu
;
1943 params
.mtu
= qedi
->ll2_mtu
+ IPV6_HDR_LEN
+ TCP_HDR_LEN
;
1944 params
.drop_ttl0_packets
= 0;
1945 params
.rx_vlan_stripping
= 1;
1946 ether_addr_copy(params
.ll2_mac_address
, qedi
->dev_info
.common
.hw_mac
);
1947 qedi_ops
->ll2
->start(qedi
->cdev
, ¶ms
);
1951 * qedi_get_nvram_block: - Scan through the iSCSI NVRAM block (while accounting
1952 * for gaps) for the matching absolute-pf-id of the QEDI device.
1954 static struct nvm_iscsi_block
*
1955 qedi_get_nvram_block(struct qedi_ctx
*qedi
)
1960 struct nvm_iscsi_block
*block
;
1962 pf
= qedi
->dev_info
.common
.abs_pf_id
;
1963 block
= &qedi
->iscsi_image
->iscsi_cfg
.block
[0];
1964 for (i
= 0; i
< NUM_OF_ISCSI_PF_SUPPORTED
; i
++, block
++) {
1965 flags
= ((block
->id
) & NVM_ISCSI_CFG_BLK_CTRL_FLAG_MASK
) >>
1966 NVM_ISCSI_CFG_BLK_CTRL_FLAG_OFFSET
;
1967 if (flags
& (NVM_ISCSI_CFG_BLK_CTRL_FLAG_IS_NOT_EMPTY
|
1968 NVM_ISCSI_CFG_BLK_CTRL_FLAG_PF_MAPPED
) &&
1969 (pf
== (block
->id
& NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_MASK
)
1970 >> NVM_ISCSI_CFG_BLK_MAPPED_PF_ID_OFFSET
))
1976 static ssize_t
qedi_show_boot_eth_info(void *data
, int type
, char *buf
)
1978 struct qedi_ctx
*qedi
= data
;
1979 struct nvm_iscsi_initiator
*initiator
;
1981 u32 ipv6_en
, dhcp_en
, ip_len
;
1982 struct nvm_iscsi_block
*block
;
1983 char *fmt
, *ip
, *sub
, *gw
;
1985 block
= qedi_get_nvram_block(qedi
);
1989 initiator
= &block
->initiator
;
1990 ipv6_en
= block
->generic
.ctrl_flags
&
1991 NVM_ISCSI_CFG_GEN_IPV6_ENABLED
;
1992 dhcp_en
= block
->generic
.ctrl_flags
&
1993 NVM_ISCSI_CFG_GEN_DHCP_TCPIP_CONFIG_ENABLED
;
1994 /* Static IP assignments. */
1995 fmt
= ipv6_en
? "%pI6\n" : "%pI4\n";
1996 ip
= ipv6_en
? initiator
->ipv6
.addr
.byte
: initiator
->ipv4
.addr
.byte
;
1997 ip_len
= ipv6_en
? IPV6_LEN
: IPV4_LEN
;
1998 sub
= ipv6_en
? initiator
->ipv6
.subnet_mask
.byte
:
1999 initiator
->ipv4
.subnet_mask
.byte
;
2000 gw
= ipv6_en
? initiator
->ipv6
.gateway
.byte
:
2001 initiator
->ipv4
.gateway
.byte
;
2002 /* DHCP IP adjustments. */
2003 fmt
= dhcp_en
? "%s\n" : fmt
;
2005 ip
= ipv6_en
? "0::0" : "0.0.0.0";
2008 ip_len
= ipv6_en
? 5 : 8;
2012 case ISCSI_BOOT_ETH_IP_ADDR
:
2013 rc
= snprintf(buf
, ip_len
, fmt
, ip
);
2015 case ISCSI_BOOT_ETH_SUBNET_MASK
:
2016 rc
= snprintf(buf
, ip_len
, fmt
, sub
);
2018 case ISCSI_BOOT_ETH_GATEWAY
:
2019 rc
= snprintf(buf
, ip_len
, fmt
, gw
);
2021 case ISCSI_BOOT_ETH_FLAGS
:
2022 rc
= snprintf(buf
, 3, "%hhd\n",
2023 SYSFS_FLAG_FW_SEL_BOOT
);
2025 case ISCSI_BOOT_ETH_INDEX
:
2026 rc
= snprintf(buf
, 3, "0\n");
2028 case ISCSI_BOOT_ETH_MAC
:
2029 rc
= sysfs_format_mac(buf
, qedi
->mac
, ETH_ALEN
);
2031 case ISCSI_BOOT_ETH_VLAN
:
2032 rc
= snprintf(buf
, 12, "%d\n",
2033 GET_FIELD2(initiator
->generic_cont0
,
2034 NVM_ISCSI_CFG_INITIATOR_VLAN
));
2036 case ISCSI_BOOT_ETH_ORIGIN
:
2038 rc
= snprintf(buf
, 3, "3\n");
2048 static umode_t
qedi_eth_get_attr_visibility(void *data
, int type
)
2053 case ISCSI_BOOT_ETH_FLAGS
:
2054 case ISCSI_BOOT_ETH_MAC
:
2055 case ISCSI_BOOT_ETH_INDEX
:
2056 case ISCSI_BOOT_ETH_IP_ADDR
:
2057 case ISCSI_BOOT_ETH_SUBNET_MASK
:
2058 case ISCSI_BOOT_ETH_GATEWAY
:
2059 case ISCSI_BOOT_ETH_ORIGIN
:
2060 case ISCSI_BOOT_ETH_VLAN
:
2070 static ssize_t
qedi_show_boot_ini_info(void *data
, int type
, char *buf
)
2072 struct qedi_ctx
*qedi
= data
;
2073 struct nvm_iscsi_initiator
*initiator
;
2075 struct nvm_iscsi_block
*block
;
2077 block
= qedi_get_nvram_block(qedi
);
2081 initiator
= &block
->initiator
;
2084 case ISCSI_BOOT_INI_INITIATOR_NAME
:
2085 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN
,
2086 initiator
->initiator_name
.byte
);
2095 static umode_t
qedi_ini_get_attr_visibility(void *data
, int type
)
2100 case ISCSI_BOOT_INI_INITIATOR_NAME
:
2111 qedi_show_boot_tgt_info(struct qedi_ctx
*qedi
, int type
,
2112 char *buf
, enum qedi_nvm_tgts idx
)
2115 u32 ctrl_flags
, ipv6_en
, chap_en
, mchap_en
, ip_len
;
2116 struct nvm_iscsi_block
*block
;
2117 char *chap_name
, *chap_secret
;
2118 char *mchap_name
, *mchap_secret
;
2120 block
= qedi_get_nvram_block(qedi
);
2122 goto exit_show_tgt_info
;
2124 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_EVT
,
2125 "Port:%d, tgt_idx:%d\n",
2126 GET_FIELD2(block
->id
, NVM_ISCSI_CFG_BLK_MAPPED_PF_ID
), idx
);
2128 ctrl_flags
= block
->target
[idx
].ctrl_flags
&
2129 NVM_ISCSI_CFG_TARGET_ENABLED
;
2132 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_EVT
,
2133 "Target disabled\n");
2134 goto exit_show_tgt_info
;
2137 ipv6_en
= block
->generic
.ctrl_flags
&
2138 NVM_ISCSI_CFG_GEN_IPV6_ENABLED
;
2139 ip_len
= ipv6_en
? IPV6_LEN
: IPV4_LEN
;
2140 chap_en
= block
->generic
.ctrl_flags
&
2141 NVM_ISCSI_CFG_GEN_CHAP_ENABLED
;
2142 chap_name
= chap_en
? block
->initiator
.chap_name
.byte
: NULL
;
2143 chap_secret
= chap_en
? block
->initiator
.chap_password
.byte
: NULL
;
2145 mchap_en
= block
->generic
.ctrl_flags
&
2146 NVM_ISCSI_CFG_GEN_CHAP_MUTUAL_ENABLED
;
2147 mchap_name
= mchap_en
? block
->target
[idx
].chap_name
.byte
: NULL
;
2148 mchap_secret
= mchap_en
? block
->target
[idx
].chap_password
.byte
: NULL
;
2151 case ISCSI_BOOT_TGT_NAME
:
2152 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN
,
2153 block
->target
[idx
].target_name
.byte
);
2155 case ISCSI_BOOT_TGT_IP_ADDR
:
2157 rc
= snprintf(buf
, ip_len
, "%pI6\n",
2158 block
->target
[idx
].ipv6_addr
.byte
);
2160 rc
= snprintf(buf
, ip_len
, "%pI4\n",
2161 block
->target
[idx
].ipv4_addr
.byte
);
2163 case ISCSI_BOOT_TGT_PORT
:
2164 rc
= snprintf(buf
, 12, "%d\n",
2165 GET_FIELD2(block
->target
[idx
].generic_cont0
,
2166 NVM_ISCSI_CFG_TARGET_TCP_PORT
));
2168 case ISCSI_BOOT_TGT_LUN
:
2169 rc
= snprintf(buf
, 22, "%.*d\n",
2170 block
->target
[idx
].lun
.value
[1],
2171 block
->target
[idx
].lun
.value
[0]);
2173 case ISCSI_BOOT_TGT_CHAP_NAME
:
2174 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN
,
2177 case ISCSI_BOOT_TGT_CHAP_SECRET
:
2178 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN
,
2181 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
2182 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN
,
2185 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
2186 rc
= sprintf(buf
, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN
,
2189 case ISCSI_BOOT_TGT_FLAGS
:
2190 rc
= snprintf(buf
, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT
);
2192 case ISCSI_BOOT_TGT_NIC_ASSOC
:
2193 rc
= snprintf(buf
, 3, "0\n");
2204 static ssize_t
qedi_show_boot_tgt_pri_info(void *data
, int type
, char *buf
)
2206 struct qedi_ctx
*qedi
= data
;
2208 return qedi_show_boot_tgt_info(qedi
, type
, buf
, QEDI_NVM_TGT_PRI
);
2211 static ssize_t
qedi_show_boot_tgt_sec_info(void *data
, int type
, char *buf
)
2213 struct qedi_ctx
*qedi
= data
;
2215 return qedi_show_boot_tgt_info(qedi
, type
, buf
, QEDI_NVM_TGT_SEC
);
2218 static umode_t
qedi_tgt_get_attr_visibility(void *data
, int type
)
2223 case ISCSI_BOOT_TGT_NAME
:
2224 case ISCSI_BOOT_TGT_IP_ADDR
:
2225 case ISCSI_BOOT_TGT_PORT
:
2226 case ISCSI_BOOT_TGT_LUN
:
2227 case ISCSI_BOOT_TGT_CHAP_NAME
:
2228 case ISCSI_BOOT_TGT_CHAP_SECRET
:
2229 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
2230 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
2231 case ISCSI_BOOT_TGT_NIC_ASSOC
:
2232 case ISCSI_BOOT_TGT_FLAGS
:
2242 static void qedi_boot_release(void *data
)
2244 struct qedi_ctx
*qedi
= data
;
2246 scsi_host_put(qedi
->shost
);
2249 static int qedi_get_boot_info(struct qedi_ctx
*qedi
)
2253 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
2254 "Get NVM iSCSI CFG image\n");
2255 ret
= qedi_ops
->common
->nvm_get_image(qedi
->cdev
,
2256 QED_NVM_IMAGE_ISCSI_CFG
,
2257 (char *)qedi
->iscsi_image
,
2258 sizeof(struct qedi_nvm_iscsi_image
));
2260 QEDI_ERR(&qedi
->dbg_ctx
,
2261 "Could not get NVM image. ret = %d\n", ret
);
2266 static int qedi_setup_boot_info(struct qedi_ctx
*qedi
)
2268 struct iscsi_boot_kobj
*boot_kobj
;
2270 if (qedi_get_boot_info(qedi
))
2273 qedi
->boot_kset
= iscsi_boot_create_host_kset(qedi
->shost
->host_no
);
2274 if (!qedi
->boot_kset
)
2277 if (!scsi_host_get(qedi
->shost
))
2280 boot_kobj
= iscsi_boot_create_target(qedi
->boot_kset
, 0, qedi
,
2281 qedi_show_boot_tgt_pri_info
,
2282 qedi_tgt_get_attr_visibility
,
2287 if (!scsi_host_get(qedi
->shost
))
2290 boot_kobj
= iscsi_boot_create_target(qedi
->boot_kset
, 1, qedi
,
2291 qedi_show_boot_tgt_sec_info
,
2292 qedi_tgt_get_attr_visibility
,
2297 if (!scsi_host_get(qedi
->shost
))
2300 boot_kobj
= iscsi_boot_create_initiator(qedi
->boot_kset
, 0, qedi
,
2301 qedi_show_boot_ini_info
,
2302 qedi_ini_get_attr_visibility
,
2307 if (!scsi_host_get(qedi
->shost
))
2310 boot_kobj
= iscsi_boot_create_ethernet(qedi
->boot_kset
, 0, qedi
,
2311 qedi_show_boot_eth_info
,
2312 qedi_eth_get_attr_visibility
,
2320 scsi_host_put(qedi
->shost
);
2322 iscsi_boot_destroy_kset(qedi
->boot_kset
);
2326 static void __qedi_remove(struct pci_dev
*pdev
, int mode
)
2328 struct qedi_ctx
*qedi
= pci_get_drvdata(pdev
);
2331 if (qedi
->tmf_thread
) {
2332 flush_workqueue(qedi
->tmf_thread
);
2333 destroy_workqueue(qedi
->tmf_thread
);
2334 qedi
->tmf_thread
= NULL
;
2337 if (qedi
->offload_thread
) {
2338 flush_workqueue(qedi
->offload_thread
);
2339 destroy_workqueue(qedi
->offload_thread
);
2340 qedi
->offload_thread
= NULL
;
2343 #ifdef CONFIG_DEBUG_FS
2344 qedi_dbg_host_exit(&qedi
->dbg_ctx
);
2346 if (!test_bit(QEDI_IN_OFFLINE
, &qedi
->flags
))
2347 qedi_ops
->common
->set_power_state(qedi
->cdev
, PCI_D0
);
2349 qedi_sync_free_irqs(qedi
);
2351 if (!test_bit(QEDI_IN_OFFLINE
, &qedi
->flags
)) {
2352 qedi_ops
->stop(qedi
->cdev
);
2353 qedi_ops
->ll2
->stop(qedi
->cdev
);
2356 if (mode
== QEDI_MODE_NORMAL
)
2357 qedi_free_iscsi_pf_param(qedi
);
2359 rval
= qedi_ops
->common
->update_drv_state(qedi
->cdev
, false);
2361 QEDI_ERR(&qedi
->dbg_ctx
, "Failed to send drv state to MFW\n");
2363 if (!test_bit(QEDI_IN_OFFLINE
, &qedi
->flags
)) {
2364 qedi_ops
->common
->slowpath_stop(qedi
->cdev
);
2365 qedi_ops
->common
->remove(qedi
->cdev
);
2368 qedi_destroy_fp(qedi
);
2370 if (mode
== QEDI_MODE_NORMAL
) {
2371 qedi_release_cid_que(qedi
);
2372 qedi_cm_free_mem(qedi
);
2373 qedi_free_uio(qedi
->udev
);
2374 qedi_free_itt(qedi
);
2376 iscsi_host_remove(qedi
->shost
);
2377 iscsi_host_free(qedi
->shost
);
2379 if (qedi
->ll2_recv_thread
) {
2380 kthread_stop(qedi
->ll2_recv_thread
);
2381 qedi
->ll2_recv_thread
= NULL
;
2383 qedi_ll2_free_skbs(qedi
);
2385 if (qedi
->boot_kset
)
2386 iscsi_boot_destroy_kset(qedi
->boot_kset
);
2390 static int __qedi_probe(struct pci_dev
*pdev
, int mode
)
2392 struct qedi_ctx
*qedi
;
2393 struct qed_ll2_params params
;
2398 struct qed_link_params link_params
;
2399 struct qed_slowpath_params sp_params
;
2400 struct qed_probe_params qed_params
;
2401 void *task_start
, *task_end
;
2405 if (mode
!= QEDI_MODE_RECOVERY
) {
2406 qedi
= qedi_host_alloc(pdev
);
2412 qedi
= pci_get_drvdata(pdev
);
2415 memset(&qed_params
, 0, sizeof(qed_params
));
2416 qed_params
.protocol
= QED_PROTOCOL_ISCSI
;
2417 qed_params
.dp_module
= dp_module
;
2418 qed_params
.dp_level
= dp_level
;
2419 qed_params
.is_vf
= is_vf
;
2420 qedi
->cdev
= qedi_ops
->common
->probe(pdev
, &qed_params
);
2423 QEDI_ERR(&qedi
->dbg_ctx
, "Cannot initialize hardware\n");
2427 atomic_set(&qedi
->link_state
, QEDI_LINK_DOWN
);
2429 rc
= qedi_ops
->fill_dev_info(qedi
->cdev
, &qedi
->dev_info
);
2433 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
2434 "dev_info: num_hwfns=%d affin_hwfn_idx=%d.\n",
2435 qedi
->dev_info
.common
.num_hwfns
,
2436 qedi_ops
->common
->get_affin_hwfn_idx(qedi
->cdev
));
2438 if (mode
!= QEDI_MODE_RECOVERY
) {
2439 rc
= qedi_set_iscsi_pf_param(qedi
);
2442 QEDI_ERR(&qedi
->dbg_ctx
,
2443 "Set iSCSI pf param fail\n");
2448 qedi_ops
->common
->update_pf_params(qedi
->cdev
, &qedi
->pf_params
);
2450 rc
= qedi_prepare_fp(qedi
);
2452 QEDI_ERR(&qedi
->dbg_ctx
, "Cannot start slowpath.\n");
2453 goto free_pf_params
;
2456 /* Start the Slowpath-process */
2457 memset(&sp_params
, 0, sizeof(struct qed_slowpath_params
));
2458 sp_params
.int_mode
= QED_INT_MODE_MSIX
;
2459 sp_params
.drv_major
= QEDI_DRIVER_MAJOR_VER
;
2460 sp_params
.drv_minor
= QEDI_DRIVER_MINOR_VER
;
2461 sp_params
.drv_rev
= QEDI_DRIVER_REV_VER
;
2462 sp_params
.drv_eng
= QEDI_DRIVER_ENG_VER
;
2463 strlcpy(sp_params
.name
, "qedi iSCSI", QED_DRV_VER_STR_SIZE
);
2464 rc
= qedi_ops
->common
->slowpath_start(qedi
->cdev
, &sp_params
);
2466 QEDI_ERR(&qedi
->dbg_ctx
, "Cannot start slowpath\n");
2470 /* update_pf_params needs to be called before and after slowpath
2473 qedi_ops
->common
->update_pf_params(qedi
->cdev
, &qedi
->pf_params
);
2475 rc
= qedi_setup_int(qedi
);
2477 goto stop_iscsi_func
;
2479 qedi_ops
->common
->set_power_state(qedi
->cdev
, PCI_D0
);
2481 /* Learn information crucial for qedi to progress */
2482 rc
= qedi_ops
->fill_dev_info(qedi
->cdev
, &qedi
->dev_info
);
2484 goto stop_iscsi_func
;
2486 /* Record BDQ producer doorbell addresses */
2487 qedi
->bdq_primary_prod
= qedi
->dev_info
.primary_dbq_rq_addr
;
2488 qedi
->bdq_secondary_prod
= qedi
->dev_info
.secondary_bdq_rq_addr
;
2489 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
2490 "BDQ primary_prod=%p secondary_prod=%p.\n",
2491 qedi
->bdq_primary_prod
,
2492 qedi
->bdq_secondary_prod
);
2495 * We need to write the number of BDs in the BDQ we've preallocated so
2496 * the f/w will do a prefetch and we'll get an unsolicited CQE when a
2499 qedi
->bdq_prod_idx
= QEDI_BDQ_NUM
;
2500 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
2501 "Writing %d to primary and secondary BDQ doorbell registers.\n",
2502 qedi
->bdq_prod_idx
);
2503 writew(qedi
->bdq_prod_idx
, qedi
->bdq_primary_prod
);
2504 tmp
= readw(qedi
->bdq_primary_prod
);
2505 writew(qedi
->bdq_prod_idx
, qedi
->bdq_secondary_prod
);
2506 tmp
= readw(qedi
->bdq_secondary_prod
);
2508 ether_addr_copy(qedi
->mac
, qedi
->dev_info
.common
.hw_mac
);
2509 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
, "MAC address is %pM.\n",
2512 sprintf(host_buf
, "host_%d", qedi
->shost
->host_no
);
2513 qedi_ops
->common
->set_name(qedi
->cdev
, host_buf
);
2515 qedi_ops
->register_ops(qedi
->cdev
, &qedi_cb_ops
, qedi
);
2517 memset(¶ms
, 0, sizeof(params
));
2518 params
.mtu
= DEF_PATH_MTU
+ IPV6_HDR_LEN
+ TCP_HDR_LEN
;
2519 qedi
->ll2_mtu
= DEF_PATH_MTU
;
2520 params
.drop_ttl0_packets
= 0;
2521 params
.rx_vlan_stripping
= 1;
2522 ether_addr_copy(params
.ll2_mac_address
, qedi
->dev_info
.common
.hw_mac
);
2524 if (mode
!= QEDI_MODE_RECOVERY
) {
2525 /* set up rx path */
2526 INIT_LIST_HEAD(&qedi
->ll2_skb_list
);
2527 spin_lock_init(&qedi
->ll2_lock
);
2528 /* start qedi context */
2529 spin_lock_init(&qedi
->hba_lock
);
2530 spin_lock_init(&qedi
->task_idx_lock
);
2531 mutex_init(&qedi
->stats_lock
);
2533 qedi_ops
->ll2
->register_cb_ops(qedi
->cdev
, &qedi_ll2_cb_ops
, qedi
);
2534 qedi_ops
->ll2
->start(qedi
->cdev
, ¶ms
);
2536 if (mode
!= QEDI_MODE_RECOVERY
) {
2537 qedi
->ll2_recv_thread
= kthread_run(qedi_ll2_recv_thread
,
2542 rc
= qedi_ops
->start(qedi
->cdev
, &qedi
->tasks
,
2543 qedi
, qedi_iscsi_event_cb
);
2546 QEDI_ERR(&qedi
->dbg_ctx
, "Cannot start iSCSI function\n");
2550 task_start
= qedi_get_task_mem(&qedi
->tasks
, 0);
2551 task_end
= qedi_get_task_mem(&qedi
->tasks
, MAX_TID_BLOCKS_ISCSI
- 1);
2552 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_DISC
,
2553 "Task context start=%p, end=%p block_size=%u.\n",
2554 task_start
, task_end
, qedi
->tasks
.size
);
2556 memset(&link_params
, 0, sizeof(link_params
));
2557 link_params
.link_up
= true;
2558 rc
= qedi_ops
->common
->set_link(qedi
->cdev
, &link_params
);
2560 QEDI_WARN(&qedi
->dbg_ctx
, "Link set up failed.\n");
2561 atomic_set(&qedi
->link_state
, QEDI_LINK_DOWN
);
2564 #ifdef CONFIG_DEBUG_FS
2565 qedi_dbg_host_init(&qedi
->dbg_ctx
, qedi_debugfs_ops
,
2568 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
2569 "QLogic FastLinQ iSCSI Module qedi %s, FW %d.%d.%d.%d\n",
2570 QEDI_MODULE_VERSION
, FW_MAJOR_VERSION
, FW_MINOR_VERSION
,
2571 FW_REVISION_VERSION
, FW_ENGINEERING_VERSION
);
2573 if (mode
== QEDI_MODE_NORMAL
) {
2574 if (iscsi_host_add(qedi
->shost
, &pdev
->dev
)) {
2575 QEDI_ERR(&qedi
->dbg_ctx
,
2576 "Could not add iscsi host\n");
2581 /* Allocate uio buffers */
2582 rc
= qedi_alloc_uio_rings(qedi
);
2584 QEDI_ERR(&qedi
->dbg_ctx
,
2585 "UIO alloc ring failed err=%d\n", rc
);
2589 rc
= qedi_init_uio(qedi
);
2591 QEDI_ERR(&qedi
->dbg_ctx
,
2592 "UIO init failed, err=%d\n", rc
);
2596 /* host the array on iscsi_conn */
2597 rc
= qedi_setup_cid_que(qedi
);
2599 QEDI_ERR(&qedi
->dbg_ctx
,
2600 "Could not setup cid que\n");
2604 rc
= qedi_cm_alloc_mem(qedi
);
2606 QEDI_ERR(&qedi
->dbg_ctx
,
2607 "Could not alloc cm memory\n");
2611 rc
= qedi_alloc_itt(qedi
);
2613 QEDI_ERR(&qedi
->dbg_ctx
,
2614 "Could not alloc itt memory\n");
2618 sprintf(host_buf
, "host_%d", qedi
->shost
->host_no
);
2619 qedi
->tmf_thread
= create_singlethread_workqueue(host_buf
);
2620 if (!qedi
->tmf_thread
) {
2621 QEDI_ERR(&qedi
->dbg_ctx
,
2622 "Unable to start tmf thread!\n");
2627 sprintf(host_buf
, "qedi_ofld%d", qedi
->shost
->host_no
);
2628 qedi
->offload_thread
= create_workqueue(host_buf
);
2629 if (!qedi
->offload_thread
) {
2630 QEDI_ERR(&qedi
->dbg_ctx
,
2631 "Unable to start offload thread!\n");
2636 /* F/w needs 1st task context memory entry for performance */
2637 set_bit(QEDI_RESERVE_TASK_ID
, qedi
->task_idx_map
);
2638 atomic_set(&qedi
->num_offloads
, 0);
2640 if (qedi_setup_boot_info(qedi
))
2641 QEDI_ERR(&qedi
->dbg_ctx
,
2642 "No iSCSI boot target configured\n");
2644 rc
= qedi_ops
->common
->update_drv_state(qedi
->cdev
, true);
2646 QEDI_ERR(&qedi
->dbg_ctx
,
2647 "Failed to send drv state to MFW\n");
2654 qedi_release_cid_que(qedi
);
2656 qedi_free_uio(qedi
->udev
);
2658 #ifdef CONFIG_DEBUG_FS
2659 qedi_dbg_host_exit(&qedi
->dbg_ctx
);
2661 iscsi_host_remove(qedi
->shost
);
2663 qedi_ops
->stop(qedi
->cdev
);
2665 qedi_ops
->common
->slowpath_stop(qedi
->cdev
);
2667 qedi_ops
->common
->remove(qedi
->cdev
);
2669 qedi_free_iscsi_pf_param(qedi
);
2671 iscsi_host_free(qedi
->shost
);
2676 static int qedi_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2678 return __qedi_probe(pdev
, QEDI_MODE_NORMAL
);
2681 static void qedi_remove(struct pci_dev
*pdev
)
2683 __qedi_remove(pdev
, QEDI_MODE_NORMAL
);
2686 static struct pci_device_id qedi_pci_tbl
[] = {
2687 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, 0x165E) },
2688 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, 0x8084) },
2691 MODULE_DEVICE_TABLE(pci
, qedi_pci_tbl
);
2693 static enum cpuhp_state qedi_cpuhp_state
;
2695 static struct pci_driver qedi_pci_driver
= {
2696 .name
= QEDI_MODULE_NAME
,
2697 .id_table
= qedi_pci_tbl
,
2698 .probe
= qedi_probe
,
2699 .remove
= qedi_remove
,
2702 static int __init
qedi_init(void)
2704 struct qedi_percpu_s
*p
;
2707 qedi_ops
= qed_get_iscsi_ops();
2709 QEDI_ERR(NULL
, "Failed to get qed iSCSI operations\n");
2713 #ifdef CONFIG_DEBUG_FS
2714 qedi_dbg_init("qedi");
2717 qedi_scsi_transport
= iscsi_register_transport(&qedi_iscsi_transport
);
2718 if (!qedi_scsi_transport
) {
2719 QEDI_ERR(NULL
, "Could not register qedi transport");
2721 goto exit_qedi_init_1
;
2724 for_each_possible_cpu(cpu
) {
2725 p
= &per_cpu(qedi_percpu
, cpu
);
2726 INIT_LIST_HEAD(&p
->work_list
);
2727 spin_lock_init(&p
->p_work_lock
);
2731 rc
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "scsi/qedi:online",
2732 qedi_cpu_online
, qedi_cpu_offline
);
2734 goto exit_qedi_init_2
;
2735 qedi_cpuhp_state
= rc
;
2737 rc
= pci_register_driver(&qedi_pci_driver
);
2739 QEDI_ERR(NULL
, "Failed to register driver\n");
2746 cpuhp_remove_state(qedi_cpuhp_state
);
2748 iscsi_unregister_transport(&qedi_iscsi_transport
);
2750 #ifdef CONFIG_DEBUG_FS
2753 qed_put_iscsi_ops();
2757 static void __exit
qedi_cleanup(void)
2759 pci_unregister_driver(&qedi_pci_driver
);
2760 cpuhp_remove_state(qedi_cpuhp_state
);
2761 iscsi_unregister_transport(&qedi_iscsi_transport
);
2763 #ifdef CONFIG_DEBUG_FS
2766 qed_put_iscsi_ops();
2769 MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx iSCSI Module");
2770 MODULE_LICENSE("GPL");
2771 MODULE_AUTHOR("QLogic Corporation");
2772 MODULE_VERSION(QEDI_MODULE_VERSION
);
2773 module_init(qedi_init
);
2774 module_exit(qedi_cleanup
);