1*7380a3a4Skrw /* $OpenBSD: qlavar.h,v 1.12 2020/07/22 13:16:04 krw Exp $ */ 24cd89cf2Sjmatthew 34cd89cf2Sjmatthew /* 44cd89cf2Sjmatthew * Copyright (c) 2013, 2014 Jonathan Matthew <jmatthew@openbsd.org> 54cd89cf2Sjmatthew * 64cd89cf2Sjmatthew * Permission to use, copy, modify, and distribute this software for any 74cd89cf2Sjmatthew * purpose with or without fee is hereby granted, provided that the above 84cd89cf2Sjmatthew * copyright notice and this permission notice appear in all copies. 94cd89cf2Sjmatthew * 104cd89cf2Sjmatthew * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 114cd89cf2Sjmatthew * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 124cd89cf2Sjmatthew * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 134cd89cf2Sjmatthew * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 144cd89cf2Sjmatthew * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 154cd89cf2Sjmatthew * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 164cd89cf2Sjmatthew * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 174cd89cf2Sjmatthew */ 184cd89cf2Sjmatthew 19944e332aSjmatthew #include <sys/task.h> 204cd89cf2Sjmatthew 214cd89cf2Sjmatthew #define QLA_DEFAULT_PORT_NAME 0x400000007F000003ULL /* from isp(4) */ 224cd89cf2Sjmatthew 234cd89cf2Sjmatthew #define QLA_WAIT_FOR_LOOP 10 244cd89cf2Sjmatthew 254cd89cf2Sjmatthew /* maximum number of segments allowed for in a single io */ 264cd89cf2Sjmatthew #define QLA_MAX_SEGS 16 274cd89cf2Sjmatthew 28b6400b02Sdlg struct qla_softc; 29b6400b02Sdlg 304cd89cf2Sjmatthew enum qla_isp_gen { 314cd89cf2Sjmatthew QLA_GEN_ISP2100 = 1, 324cd89cf2Sjmatthew QLA_GEN_ISP2200, 334cd89cf2Sjmatthew QLA_GEN_ISP23XX, 344cd89cf2Sjmatthew }; 354cd89cf2Sjmatthew 364cd89cf2Sjmatthew enum qla_isp_type { 374cd89cf2Sjmatthew QLA_ISP2100 = 1, 384cd89cf2Sjmatthew QLA_ISP2200, 394cd89cf2Sjmatthew QLA_ISP2300, 404cd89cf2Sjmatthew QLA_ISP2312, 414cd89cf2Sjmatthew QLA_ISP2322 424cd89cf2Sjmatthew }; 434cd89cf2Sjmatthew 4468858f63Sdlg struct qla_regs { 45b6400b02Sdlg u_int16_t (*read)(struct qla_softc *, bus_size_t); 4668858f63Sdlg int (*read_isr)(struct qla_softc *, 4768858f63Sdlg u_int16_t *, u_int16_t *); 48b6400b02Sdlg 49b6400b02Sdlg bus_size_t req_in; 50b6400b02Sdlg bus_size_t req_out; 51b6400b02Sdlg bus_size_t res_in; 52b6400b02Sdlg bus_size_t res_out; 534cd89cf2Sjmatthew }; 544cd89cf2Sjmatthew 554cd89cf2Sjmatthew /* port database things */ 564cd89cf2Sjmatthew #define QLA_SCRATCH_SIZE 0x1000 574cd89cf2Sjmatthew 584cd89cf2Sjmatthew enum qla_port_disp { 594cd89cf2Sjmatthew QLA_PORT_DISP_NEW, 604cd89cf2Sjmatthew QLA_PORT_DISP_GONE, 614cd89cf2Sjmatthew QLA_PORT_DISP_SAME, 624cd89cf2Sjmatthew QLA_PORT_DISP_CHANGED, 634cd89cf2Sjmatthew QLA_PORT_DISP_MOVED, 644cd89cf2Sjmatthew QLA_PORT_DISP_DUP 654cd89cf2Sjmatthew }; 664cd89cf2Sjmatthew 67d10165e5Sjmatthew #define QLA_LOCATION_LOOP (1 << 24) 68d10165e5Sjmatthew #define QLA_LOCATION_FABRIC (2 << 24) 69d10165e5Sjmatthew #define QLA_LOCATION_LOOP_ID(l) (l | QLA_LOCATION_LOOP) 70d10165e5Sjmatthew #define QLA_LOCATION_PORT_ID(p) (p | QLA_LOCATION_FABRIC) 714cd89cf2Sjmatthew 724cd89cf2Sjmatthew struct qla_fc_port { 734cd89cf2Sjmatthew TAILQ_ENTRY(qla_fc_port) ports; 744cd89cf2Sjmatthew TAILQ_ENTRY(qla_fc_port) update; 754cd89cf2Sjmatthew 764cd89cf2Sjmatthew u_int64_t node_name; 774cd89cf2Sjmatthew u_int64_t port_name; 784cd89cf2Sjmatthew u_int32_t location; /* port id or loop id */ 794cd89cf2Sjmatthew 804cd89cf2Sjmatthew int flags; 814cd89cf2Sjmatthew #define QLA_PORT_FLAG_IS_TARGET 1 824cd89cf2Sjmatthew #define QLA_PORT_FLAG_NEEDS_LOGIN 2 834cd89cf2Sjmatthew 844cd89cf2Sjmatthew u_int32_t portid; 854cd89cf2Sjmatthew u_int16_t loopid; 864cd89cf2Sjmatthew }; 874cd89cf2Sjmatthew 884cd89cf2Sjmatthew 894cd89cf2Sjmatthew /* request/response queue stuff */ 904cd89cf2Sjmatthew #define QLA_QUEUE_ENTRY_SIZE 64 914cd89cf2Sjmatthew 924cd89cf2Sjmatthew struct qla_ccb { 934cd89cf2Sjmatthew struct qla_softc *ccb_sc; 944cd89cf2Sjmatthew int ccb_id; 954cd89cf2Sjmatthew struct scsi_xfer *ccb_xs; 964cd89cf2Sjmatthew 974cd89cf2Sjmatthew bus_dmamap_t ccb_dmamap; 984cd89cf2Sjmatthew 994cd89cf2Sjmatthew struct qla_iocb_seg *ccb_t4segs; 1004cd89cf2Sjmatthew u_int64_t ccb_seg_offset; 10191637d79Sdlg u_int64_t ccb_seg_dva; 1024cd89cf2Sjmatthew 1034cd89cf2Sjmatthew SIMPLEQ_ENTRY(qla_ccb) ccb_link; 1044cd89cf2Sjmatthew }; 1054cd89cf2Sjmatthew 1064cd89cf2Sjmatthew SIMPLEQ_HEAD(qla_ccb_list, qla_ccb); 1074cd89cf2Sjmatthew 1084cd89cf2Sjmatthew struct qla_dmamem { 1094cd89cf2Sjmatthew bus_dmamap_t qdm_map; 1104cd89cf2Sjmatthew bus_dma_segment_t qdm_seg; 1114cd89cf2Sjmatthew size_t qdm_size; 1124cd89cf2Sjmatthew caddr_t qdm_kva; 1134cd89cf2Sjmatthew }; 1144cd89cf2Sjmatthew #define QLA_DMA_MAP(_qdm) ((_qdm)->qdm_map) 1154cd89cf2Sjmatthew #define QLA_DMA_LEN(_qdm) ((_qdm)->qdm_size) 1164cd89cf2Sjmatthew #define QLA_DMA_DVA(_qdm) ((u_int64_t)(_qdm)->qdm_map->dm_segs[0].ds_addr) 1174cd89cf2Sjmatthew #define QLA_DMA_KVA(_qdm) ((void *)(_qdm)->qdm_kva) 1184cd89cf2Sjmatthew 1194cd89cf2Sjmatthew struct qla_softc { 1204cd89cf2Sjmatthew struct device sc_dev; 1214cd89cf2Sjmatthew 1224cd89cf2Sjmatthew bus_space_tag_t sc_iot; 1234cd89cf2Sjmatthew bus_space_handle_t sc_ioh; 1244cd89cf2Sjmatthew bus_size_t sc_ios; 1254cd89cf2Sjmatthew bus_dma_tag_t sc_dmat; 1264cd89cf2Sjmatthew 1274cd89cf2Sjmatthew struct scsibus_softc *sc_scsibus; 1284cd89cf2Sjmatthew 1294cd89cf2Sjmatthew enum qla_isp_type sc_isp_type; 1304cd89cf2Sjmatthew enum qla_isp_gen sc_isp_gen; 1314cd89cf2Sjmatthew int sc_port; 1324cd89cf2Sjmatthew int sc_expanded_lun; 1334cd89cf2Sjmatthew int sc_fabric; 1344cd89cf2Sjmatthew int sc_2k_logins; 1354cd89cf2Sjmatthew 13668858f63Sdlg const struct qla_regs *sc_regs; 137b6400b02Sdlg 1384cd89cf2Sjmatthew int sc_mbox_base; 1394cd89cf2Sjmatthew u_int16_t sc_mbox[12]; 1404cd89cf2Sjmatthew int sc_mbox_pending; 14186376500Sjmatthew struct mutex sc_mbox_mtx; 1424cd89cf2Sjmatthew 1434cd89cf2Sjmatthew int sc_loop_up; 1444cd89cf2Sjmatthew int sc_topology; 1454cd89cf2Sjmatthew int sc_loop_id; 1464cd89cf2Sjmatthew int sc_port_id; 147aa14606aSjmatthew int sc_loop_max_id; 148aa14606aSjmatthew u_int64_t sc_sns_port_name; 1494cd89cf2Sjmatthew 1504cd89cf2Sjmatthew struct mutex sc_port_mtx; 1514cd89cf2Sjmatthew TAILQ_HEAD(, qla_fc_port) sc_ports; 1524cd89cf2Sjmatthew TAILQ_HEAD(, qla_fc_port) sc_ports_new; 1534cd89cf2Sjmatthew TAILQ_HEAD(, qla_fc_port) sc_ports_gone; 154d10165e5Sjmatthew TAILQ_HEAD(, qla_fc_port) sc_ports_found; 155d5c56ff1Sjmatthew struct qla_fc_port *sc_targets[QLA_2KL_BUSWIDTH]; 156944e332aSjmatthew 157944e332aSjmatthew struct taskq *sc_update_taskq; 158944e332aSjmatthew struct task sc_update_task; 159944e332aSjmatthew int sc_update; 160944e332aSjmatthew int sc_update_tasks; 161944e332aSjmatthew #define QLA_UPDATE_TASK_CLEAR_ALL 0x00000001 162944e332aSjmatthew #define QLA_UPDATE_TASK_SOFTRESET 0x00000002 163944e332aSjmatthew #define QLA_UPDATE_TASK_UPDATE_TOPO 0x00000004 164944e332aSjmatthew #define QLA_UPDATE_TASK_GET_PORT_LIST 0x00000008 165944e332aSjmatthew #define QLA_UPDATE_TASK_PORT_LIST 0x00000010 166944e332aSjmatthew #define QLA_UPDATE_TASK_SCAN_FABRIC 0x00000020 167944e332aSjmatthew #define QLA_UPDATE_TASK_SCANNING_FABRIC 0x00000040 168944e332aSjmatthew #define QLA_UPDATE_TASK_FABRIC_LOGIN 0x00000080 169944e332aSjmatthew #define QLA_UPDATE_TASK_FABRIC_RELOGIN 0x00000100 170944e332aSjmatthew #define QLA_UPDATE_TASK_DETACH_TARGET 0x00000200 171944e332aSjmatthew #define QLA_UPDATE_TASK_ATTACH_TARGET 0x00000400 1724cd89cf2Sjmatthew 1734cd89cf2Sjmatthew int sc_maxcmds; 1744cd89cf2Sjmatthew struct qla_dmamem *sc_requests; 1754cd89cf2Sjmatthew struct qla_dmamem *sc_responses; 1764cd89cf2Sjmatthew struct qla_dmamem *sc_segments; 1774cd89cf2Sjmatthew struct qla_dmamem *sc_scratch; 1784cd89cf2Sjmatthew struct qla_ccb *sc_ccbs; 1794cd89cf2Sjmatthew struct qla_ccb_list sc_ccb_free; 1804cd89cf2Sjmatthew struct mutex sc_ccb_mtx; 1814cd89cf2Sjmatthew struct mutex sc_queue_mtx; 1824cd89cf2Sjmatthew struct scsi_iopool sc_iopool; 1834cd89cf2Sjmatthew u_int16_t sc_next_req_id; 1844cd89cf2Sjmatthew u_int16_t sc_last_resp_id; 1854cd89cf2Sjmatthew int sc_marker_required; 1864cd89cf2Sjmatthew 1874cd89cf2Sjmatthew struct qla_nvram sc_nvram; 1884cd89cf2Sjmatthew int sc_nvram_valid; 18907286c37Skettenis u_int64_t sc_node_name; 19007286c37Skettenis u_int64_t sc_port_name; 1914cd89cf2Sjmatthew }; 1924cd89cf2Sjmatthew #define DEVNAME(_sc) ((_sc)->sc_dev.dv_xname) 1934cd89cf2Sjmatthew 1944cd89cf2Sjmatthew int qla_attach(struct qla_softc *); 1954cd89cf2Sjmatthew int qla_detach(struct qla_softc *, int); 1964cd89cf2Sjmatthew 1974cd89cf2Sjmatthew int qla_intr(void *); 198