19 #include <linux/errno.h>
22 #include <linux/pci.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
30 #include <scsi/scsi.h>
49 static const char *fnic_ioreq_state_str[] = {
56 static const char *fcpio_status_str[] = {
86 static const char *fnic_ioreq_state_to_str(
unsigned int state)
88 if (state >=
ARRAY_SIZE(fnic_ioreq_state_str) ||
89 !fnic_ioreq_state_str[state])
92 return fnic_ioreq_state_str[
state];
95 static const char *fnic_fcpio_status_to_str(
unsigned int status)
97 if (status >=
ARRAY_SIZE(fcpio_status_str) || !fcpio_status_str[status])
100 return fcpio_status_str[
status];
103 static void fnic_cleanup_io(
struct fnic *
fnic,
int exclude_id);
117 static void fnic_release_ioreq_buf(
struct fnic *
fnic,
136 static int free_wq_copy_descs(
struct fnic *fnic,
struct vnic_wq_copy *
wq)
150 wq->
ring.desc_avail += (wq->
ring.desc_count
184 free_wq_copy_descs(fnic, wq);
186 if (!vnic_wq_copy_desc_avail(wq))
195 "Issued fw reset\n");
198 "Failed to issue fw reset\n");
219 free_wq_copy_descs(fnic, wq);
221 if (!vnic_wq_copy_desc_avail(wq)) {
223 goto flogi_reg_ioreq_end;
226 if (fnic->
ctlr.map_dest) {
240 "FLOGI FIP reg issued fcid %x src %pM dest %pM\n",
244 format, fc_id, gw_mac);
246 "FLOGI reg issued fcid %x map %d dest %pM\n",
247 fc_id, fnic->
ctlr.map_dest, gw_mac);
259 static inline int fnic_queue_wq_copy_desc(
struct fnic *fnic,
271 unsigned long intr_flags;
290 sizeof(io_req->
sgl_list[0]) * sg_count,
303 scsi_populate_tag_msg(sc, msg);
311 free_wq_copy_descs(fnic, wq);
313 if (
unlikely(!vnic_wq_copy_desc_avail(wq))) {
314 spin_unlock_irqrestore(&fnic->
wq_copy_lock[0], intr_flags);
329 fnic_queue_wq_copy_desc_icmnd_16(wq, sc->
request->tag,
330 0, exch_flags, io_req->
sgl_cnt,
339 fc_lun.scsi_lun, io_req->
port_id,
343 spin_unlock_irqrestore(&fnic->
wq_copy_lock[0], intr_flags);
365 ret = fc_remote_port_chkready(rport);
372 lp = shost_priv(sc->
device->host);
381 spin_unlock(lp->
host->host_lock);
384 fnic = lport_priv(lp);
391 memset(io_req, 0,
sizeof(*io_req));
422 (((
unsigned long) ptr
423 + FNIC_SG_DESC_ALIGN - 1)
424 & ~(FNIC_SG_DESC_ALIGN - 1));
431 CMD_SP(sc) = (
char *)io_req;
436 ret = fnic_queue_wq_copy_desc(fnic, wq, io_req, sc, sg_count);
448 spin_unlock_irqrestore(io_lock, flags);
450 fnic_release_ioreq_buf(fnic, io_req, sc);
456 spin_lock(lp->
host->host_lock);
466 static
int fnic_fcpio_fw_reset_cmpl_handler(
struct fnic *fnic,
475 fcpio_header_dec(&desc->hdr, &type, &hdr_status, &
tag);
487 "reset cmpl success\n");
493 "fnic fw_reset : failed %s\n",
494 fnic_fcpio_status_to_str(hdr_status));
508 "Unexpected state %s while processing"
514 if (fnic->remove_wait)
521 if (fnic->remove_wait || ret) {
522 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
524 goto reset_cmpl_handler_end;
527 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
531 reset_cmpl_handler_end:
539 static int fnic_fcpio_flogi_reg_cmpl_handler(
struct fnic *fnic,
548 fcpio_header_dec(&desc->
hdr, &type, &hdr_status, &
tag);
558 "flog reg succeeded\n");
563 "fnic flogi reg :failed %s\n",
564 fnic_fcpio_status_to_str(hdr_status));
570 "Unexpected fnic state %s while"
571 " processing flogi reg completion\n",
578 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
579 goto reg_cmpl_handler_end;
581 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
586 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
589 reg_cmpl_handler_end:
593 static inline int is_ack_index_in_range(
struct vnic_wq_copy *wq,
598 if (request_out < wq->to_clean_index ||
603 if (request_out < wq->to_clean_index &&
618 static inline void fnic_fcpio_ack_handler(
struct fnic *fnic,
619 unsigned int cq_index,
623 u16 request_out = desc->
u.
ack.request_out;
630 if (is_ack_index_in_range(wq, request_out)) {
641 static void fnic_fcpio_icmnd_cmpl_handler(
struct fnic *fnic,
656 fcpio_header_dec(&desc->
hdr, &type, &hdr_status, &
tag);
657 fcpio_tag_id_dec(&
tag, &
id);
662 sc = scsi_host_find_tag(fnic->
lport->host,
id);
667 io_lock = fnic_io_lock_hash(fnic, sc);
672 spin_unlock_irqrestore(io_lock, flags);
684 spin_unlock_irqrestore(io_lock, flags);
693 switch (hdr_status) {
696 xfer_len = scsi_bufflen(sc);
697 scsi_set_resid(sc, icmnd_cmpl->
residual);
721 qd = t_sdev->
host->cmd_per_lun;
725 "] queue full detected,"
727 t_sdev->
host->host_no,
729 t_sdev->
id, t_sdev->
lun,
745 scsi_set_resid(sc, icmnd_cmpl->
residual);
761 fnic_fcpio_status_to_str(hdr_status));
769 spin_unlock_irqrestore(io_lock, flags);
771 fnic_release_ioreq_buf(fnic, io_req, sc);
776 fnic->
lport->host_stats.fcp_input_requests++;
779 fnic->
lport->host_stats.fcp_output_requests++;
782 fnic->
lport->host_stats.fcp_control_requests++;
793 static void fnic_fcpio_itmf_cmpl_handler(
struct fnic *fnic,
805 fcpio_header_dec(&desc->
hdr, &type, &hdr_status, &
tag);
806 fcpio_tag_id_dec(&
tag, &
id);
811 sc = scsi_host_find_tag(fnic->
lport->host,
id & FNIC_TAG_MASK);
816 io_lock = fnic_io_lock_hash(fnic, sc);
821 spin_unlock_irqrestore(io_lock, flags);
829 spin_unlock_irqrestore(io_lock, flags);
836 "abts cmpl recd. id %d status %s\n",
837 (
int)(
id & FNIC_TAG_MASK),
838 fnic_fcpio_status_to_str(hdr_status));
847 spin_unlock_irqrestore(io_lock, flags);
850 "abts cmpl, completing IO\n");
854 spin_unlock_irqrestore(io_lock, flags);
856 fnic_release_ioreq_buf(fnic, io_req, sc);
867 "dev reset cmpl recd. id %d status %s\n",
868 (
int)(
id & FNIC_TAG_MASK),
869 fnic_fcpio_status_to_str(hdr_status));
872 spin_unlock_irqrestore(io_lock, flags);
876 "Unexpected itmf io state %s tag %x\n",
877 fnic_ioreq_state_to_str(
CMD_STATE(sc)),
id);
878 spin_unlock_irqrestore(io_lock, flags);
887 static int fnic_fcpio_cmpl_handler(
struct vnic_dev *vdev,
888 unsigned int cq_index,
894 switch (desc->
hdr.type) {
896 fnic_fcpio_ack_handler(fnic, cq_index, desc);
900 fnic_fcpio_icmnd_cmpl_handler(fnic, desc);
904 fnic_fcpio_itmf_cmpl_handler(fnic, desc);
909 ret = fnic_fcpio_flogi_reg_cmpl_handler(fnic, desc);
913 ret = fnic_fcpio_fw_reset_cmpl_handler(fnic, desc);
918 "firmware completion type %d\n",
932 unsigned int wq_work_done = 0;
933 unsigned int i, cq_index;
934 unsigned int cur_work_done;
938 cur_work_done = vnic_cq_copy_service(&fnic->
cq[cq_index],
939 fnic_fcpio_cmpl_handler,
941 wq_work_done += cur_work_done;
946 static void fnic_cleanup_io(
struct fnic *fnic,
int exclude_id)
950 unsigned long flags = 0;
958 sc = scsi_host_find_tag(fnic->
lport->host, i);
962 io_lock = fnic_io_lock_hash(fnic, sc);
966 spin_unlock_irqrestore(io_lock, flags);
967 goto cleanup_scsi_cmd;
972 spin_unlock_irqrestore(io_lock, flags);
978 fnic_release_ioreq_buf(fnic, io_req, sc);
984 " DID_TRANSPORT_DISRUPTED\n");
1003 fcpio_tag_id_dec(&desc->
hdr.tag, &
id);
1006 if (
id >= FNIC_MAX_IO_REQ)
1009 sc = scsi_host_find_tag(fnic->
lport->host,
id);
1013 io_lock = fnic_io_lock_hash(fnic, sc);
1022 spin_unlock_irqrestore(io_lock, flags);
1023 goto wq_copy_cleanup_scsi_cmd;
1028 spin_unlock_irqrestore(io_lock, flags);
1030 fnic_release_ioreq_buf(fnic, io_req, sc);
1033 wq_copy_cleanup_scsi_cmd:
1036 " DID_NO_CONNECT\n");
1042 static inline int fnic_queue_abort_io_req(
struct fnic *fnic,
int tag,
1043 u32 task_req,
u8 *fc_lun,
1047 unsigned long flags;
1052 free_wq_copy_descs(fnic, wq);
1054 if (!vnic_wq_copy_desc_avail(wq)) {
1058 fnic_queue_wq_copy_desc_itmf(wq, tag | FNIC_TAG_ABORT,
1059 0, task_req, tag, fc_lun, io_req->
port_id,
1071 unsigned long flags;
1078 "fnic_rport_reset_exch called portid 0x%06x\n",
1085 sc = scsi_host_find_tag(fnic->
lport->host, tag);
1089 io_lock = fnic_io_lock_hash(fnic, sc);
1094 if (!io_req || io_req->
port_id != port_id) {
1095 spin_unlock_irqrestore(io_lock, flags);
1104 spin_unlock_irqrestore(io_lock, flags);
1114 "fnic_rport_reset_exch: Issuing abts\n");
1116 spin_unlock_irqrestore(io_lock, flags);
1121 if (fnic_queue_abort_io_req(fnic, tag,
1130 io_lock = fnic_io_lock_hash(fnic, sc);
1135 spin_unlock_irqrestore(io_lock, flags);
1146 unsigned long flags;
1151 struct fnic *fnic = lport_priv(lport);
1156 fnic->
lport->host,
"fnic_terminate_rport_io called"
1157 " wwpn 0x%llx, wwnn0x%llx, portid 0x%06x\n",
1165 sc = scsi_host_find_tag(fnic->
lport->host, tag);
1170 if (rport != cmd_rport)
1173 io_lock = fnic_io_lock_hash(fnic, sc);
1178 if (!io_req || rport != cmd_rport) {
1179 spin_unlock_irqrestore(io_lock, flags);
1188 spin_unlock_irqrestore(io_lock, flags);
1199 "fnic_terminate_rport_io: Issuing abts\n");
1201 spin_unlock_irqrestore(io_lock, flags);
1206 if (fnic_queue_abort_io_req(fnic, tag,
1215 io_lock = fnic_io_lock_hash(fnic, sc);
1220 spin_unlock_irqrestore(io_lock, flags);
1238 unsigned long flags;
1248 lp = shost_priv(sc->
device->host);
1250 fnic = lport_priv(lp);
1253 "Abort Cmd called FCID 0x%x, LUN 0x%x TAG %d\n",
1258 goto fnic_abort_cmd_end;
1273 io_lock = fnic_io_lock_hash(fnic, sc);
1277 spin_unlock_irqrestore(io_lock, flags);
1278 goto fnic_abort_cmd_end;
1284 spin_unlock_irqrestore(io_lock, flags);
1296 spin_unlock_irqrestore(io_lock, flags);
1303 if (fc_remote_port_chkready(rport) == 0)
1311 if (fnic_queue_abort_io_req(fnic, sc->
request->tag, task_req,
1317 spin_unlock_irqrestore(io_lock, flags);
1319 goto fnic_abort_cmd_end;
1330 (2 * fnic->
config.ra_tov +
1338 spin_unlock_irqrestore(io_lock, flags);
1340 goto fnic_abort_cmd_end;
1346 spin_unlock_irqrestore(io_lock, flags);
1348 goto fnic_abort_cmd_end;
1360 spin_unlock_irqrestore(io_lock, flags);
1362 fnic_release_ioreq_buf(fnic, io_req, sc);
1367 "Returning from abort cmd %s\n",
1369 "SUCCESS" :
"FAILED");
1373 static inline int fnic_queue_dr_io_req(
struct fnic *fnic,
1380 unsigned long intr_flags;
1385 free_wq_copy_descs(fnic, wq);
1387 if (!vnic_wq_copy_desc_avail(wq)) {
1395 fnic_queue_wq_copy_desc_itmf(wq, sc->
request->tag | FNIC_TAG_DEV_RST,
1397 fc_lun.scsi_lun, io_req->
port_id,
1401 spin_unlock_irqrestore(&fnic->
wq_copy_lock[0], intr_flags);
1412 static int fnic_clean_pending_aborts(
struct fnic *fnic,
1418 unsigned long flags;
1426 sc = scsi_host_find_tag(fnic->
lport->host, tag);
1431 if (!sc || sc == lr_sc || sc->
device != lun_dev)
1434 io_lock = fnic_io_lock_hash(fnic, sc);
1439 if (!io_req || sc->
device != lun_dev) {
1440 spin_unlock_irqrestore(io_lock, flags);
1449 "Found IO in %s on lun\n",
1450 fnic_ioreq_state_to_str(
CMD_STATE(sc)));
1456 spin_unlock_irqrestore(io_lock, flags);
1461 if (fnic_queue_abort_io_req(fnic, tag,
1463 fc_lun.scsi_lun, io_req)) {
1468 spin_unlock_irqrestore(io_lock, flags);
1470 goto clean_pending_aborts_end;
1481 spin_unlock_irqrestore(io_lock, flags);
1483 goto clean_pending_aborts_end;
1490 spin_unlock_irqrestore(io_lock, flags);
1492 goto clean_pending_aborts_end;
1495 spin_unlock_irqrestore(io_lock, flags);
1497 fnic_release_ioreq_buf(fnic, io_req, sc);
1501 clean_pending_aborts_end:
1519 unsigned long flags;
1526 lp = shost_priv(sc->
device->host);
1528 fnic = lport_priv(lp);
1532 "Device reset called FCID 0x%x, LUN 0x%x\n",
1536 goto fnic_device_reset_end;
1539 if (fc_remote_port_chkready(rport))
1540 goto fnic_device_reset_end;
1542 io_lock = fnic_io_lock_hash(fnic, sc);
1553 spin_unlock_irqrestore(io_lock, flags);
1554 goto fnic_device_reset_end;
1556 memset(io_req, 0,
sizeof(*io_req));
1558 CMD_SP(sc) = (
char *)io_req;
1563 spin_unlock_irqrestore(io_lock, flags);
1572 if (fnic_queue_dr_io_req(fnic, sc, io_req)) {
1577 goto fnic_device_reset_clean;
1590 spin_unlock_irqrestore(io_lock, flags);
1591 goto fnic_device_reset_end;
1596 spin_unlock_irqrestore(io_lock, flags);
1604 "Device reset timed out\n");
1605 goto fnic_device_reset_end;
1613 "Device reset completed - failed\n");
1615 goto fnic_device_reset_clean;
1625 if (fnic_clean_pending_aborts(fnic, sc)) {
1629 "Device reset failed"
1630 " since could not abort all IOs\n");
1631 goto fnic_device_reset_clean;
1641 fnic_device_reset_clean:
1645 spin_unlock_irqrestore(io_lock, flags);
1648 fnic_release_ioreq_buf(fnic, io_req, sc);
1652 fnic_device_reset_end:
1654 "Returning from device reset %s\n",
1656 "SUCCESS" :
"FAILED");
1667 lp = shost_priv(shost);
1668 fnic = lport_priv(lp);
1671 "fnic_reset called\n");
1677 if (lp->
tt.lport_reset(lp))
1681 "Returning from fnic reset %s\n",
1683 "SUCCESS" :
"FAILED");
1700 unsigned long wait_host_tmo;
1702 struct fc_lport *lp = shost_priv(shost);
1732 unsigned long flags;
1734 struct fnic *fnic = lport_priv(lp);
1740 old_state = fnic->
state;
1743 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
1749 fnic->
state = old_state;
1751 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
1762 "fnic_scsi_abort_io %s\n",
1764 "SUCCESS" :
"FAILED");
1765 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
1774 unsigned long flags;
1776 struct fnic *fnic = lport_priv(lp);
1780 old_state = fnic->
state;
1783 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
1788 fnic->
state = old_state;
1789 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
1800 struct fnic *fnic = lport_priv(lp);
1804 goto call_fc_exch_mgr_reset;
1808 goto call_fc_exch_mgr_reset;
1821 call_fc_exch_mgr_reset: