ql4_def.h 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #ifndef __QL4_DEF_H
  8. #define __QL4_DEF_H
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/types.h>
  12. #include <linux/module.h>
  13. #include <linux/list.h>
  14. #include <linux/pci.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/sched.h>
  17. #include <linux/slab.h>
  18. #include <linux/dmapool.h>
  19. #include <linux/mempool.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/mutex.h>
  25. #include <linux/aer.h>
  26. #include <linux/bsg-lib.h>
  27. #include <linux/vmalloc.h>
  28. #include <net/tcp.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_cmnd.h>
  33. #include <scsi/scsi_transport.h>
  34. #include <scsi/scsi_transport_iscsi.h>
  35. #include <scsi/scsi_bsg_iscsi.h>
  36. #include <scsi/scsi_netlink.h>
  37. #include <scsi/libiscsi.h>
  38. #include "ql4_dbg.h"
  39. #include "ql4_nx.h"
  40. #include "ql4_fw.h"
  41. #include "ql4_nvram.h"
  42. #include "ql4_83xx.h"
  43. #ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
  44. #define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010
  45. #endif
  46. #ifndef PCI_DEVICE_ID_QLOGIC_ISP4022
  47. #define PCI_DEVICE_ID_QLOGIC_ISP4022 0x4022
  48. #endif
  49. #ifndef PCI_DEVICE_ID_QLOGIC_ISP4032
  50. #define PCI_DEVICE_ID_QLOGIC_ISP4032 0x4032
  51. #endif
  52. #ifndef PCI_DEVICE_ID_QLOGIC_ISP8022
  53. #define PCI_DEVICE_ID_QLOGIC_ISP8022 0x8022
  54. #endif
  55. #ifndef PCI_DEVICE_ID_QLOGIC_ISP8324
  56. #define PCI_DEVICE_ID_QLOGIC_ISP8324 0x8032
  57. #endif
  58. #ifndef PCI_DEVICE_ID_QLOGIC_ISP8042
  59. #define PCI_DEVICE_ID_QLOGIC_ISP8042 0x8042
  60. #endif
  61. #define ISP4XXX_PCI_FN_1 0x1
  62. #define ISP4XXX_PCI_FN_2 0x3
  63. #define QLA_SUCCESS 0
  64. #define QLA_ERROR 1
  65. #define STATUS(status) status == QLA_ERROR ? "FAILED" : "SUCCEEDED"
  66. /*
  67. * Data bit definitions
  68. */
  69. #define BIT_0 0x1
  70. #define BIT_1 0x2
  71. #define BIT_2 0x4
  72. #define BIT_3 0x8
  73. #define BIT_4 0x10
  74. #define BIT_5 0x20
  75. #define BIT_6 0x40
  76. #define BIT_7 0x80
  77. #define BIT_8 0x100
  78. #define BIT_9 0x200
  79. #define BIT_10 0x400
  80. #define BIT_11 0x800
  81. #define BIT_12 0x1000
  82. #define BIT_13 0x2000
  83. #define BIT_14 0x4000
  84. #define BIT_15 0x8000
  85. #define BIT_16 0x10000
  86. #define BIT_17 0x20000
  87. #define BIT_18 0x40000
  88. #define BIT_19 0x80000
  89. #define BIT_20 0x100000
  90. #define BIT_21 0x200000
  91. #define BIT_22 0x400000
  92. #define BIT_23 0x800000
  93. #define BIT_24 0x1000000
  94. #define BIT_25 0x2000000
  95. #define BIT_26 0x4000000
  96. #define BIT_27 0x8000000
  97. #define BIT_28 0x10000000
  98. #define BIT_29 0x20000000
  99. #define BIT_30 0x40000000
  100. #define BIT_31 0x80000000
  101. /**
  102. * Macros to help code, maintain, etc.
  103. **/
  104. #define ql4_printk(level, ha, format, arg...) \
  105. dev_printk(level , &((ha)->pdev->dev) , format , ## arg)
  106. /*
  107. * Host adapter default definitions
  108. ***********************************/
  109. #define MAX_HBAS 16
  110. #define MAX_BUSES 1
  111. #define MAX_TARGETS MAX_DEV_DB_ENTRIES
  112. #define MAX_LUNS 0xffff
  113. #define MAX_AEN_ENTRIES MAX_DEV_DB_ENTRIES
  114. #define MAX_DDB_ENTRIES MAX_DEV_DB_ENTRIES
  115. #define MAX_PDU_ENTRIES 32
  116. #define INVALID_ENTRY 0xFFFF
  117. #define MAX_CMDS_TO_RISC 1024
  118. #define MAX_SRBS MAX_CMDS_TO_RISC
  119. #define MBOX_AEN_REG_COUNT 8
  120. #define MAX_INIT_RETRIES 5
  121. /*
  122. * Buffer sizes
  123. */
  124. #define REQUEST_QUEUE_DEPTH MAX_CMDS_TO_RISC
  125. #define RESPONSE_QUEUE_DEPTH 64
  126. #define QUEUE_SIZE 64
  127. #define DMA_BUFFER_SIZE 512
  128. #define IOCB_HIWAT_CUSHION 4
  129. /*
  130. * Misc
  131. */
  132. #define MAC_ADDR_LEN 6 /* in bytes */
  133. #define IP_ADDR_LEN 4 /* in bytes */
  134. #define IPv6_ADDR_LEN 16 /* IPv6 address size */
  135. #define DRIVER_NAME "qla4xxx"
  136. #define MAX_LINKED_CMDS_PER_LUN 3
  137. #define MAX_REQS_SERVICED_PER_INTR 1
  138. #define ISCSI_IPADDR_SIZE 4 /* IP address size */
  139. #define ISCSI_ALIAS_SIZE 32 /* ISCSI Alias name size */
  140. #define ISCSI_NAME_SIZE 0xE0 /* ISCSI Name size */
  141. #define QL4_SESS_RECOVERY_TMO 120 /* iSCSI session */
  142. /* recovery timeout */
  143. #define LSDW(x) ((u32)((u64)(x)))
  144. #define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16))
  145. #define DEV_DB_NON_PERSISTENT 0
  146. #define DEV_DB_PERSISTENT 1
  147. #define QL4_ISP_REG_DISCONNECT 0xffffffffU
  148. #define COPY_ISID(dst_isid, src_isid) { \
  149. int i, j; \
  150. for (i = 0, j = ISID_SIZE - 1; i < ISID_SIZE;) \
  151. dst_isid[i++] = src_isid[j--]; \
  152. }
  153. #define SET_BITVAL(o, n, v) { \
  154. if (o) \
  155. n |= v; \
  156. else \
  157. n &= ~v; \
  158. }
  159. #define OP_STATE(o, f, p) { \
  160. p = (o & f) ? "enable" : "disable"; \
  161. }
  162. /*
  163. * Retry & Timeout Values
  164. */
  165. #define MBOX_TOV 60
  166. #define SOFT_RESET_TOV 30
  167. #define RESET_INTR_TOV 3
  168. #define SEMAPHORE_TOV 10
  169. #define ADAPTER_INIT_TOV 30
  170. #define ADAPTER_RESET_TOV 180
  171. #define EXTEND_CMD_TOV 60
  172. #define WAIT_CMD_TOV 5
  173. #define EH_WAIT_CMD_TOV 120
  174. #define FIRMWARE_UP_TOV 60
  175. #define RESET_FIRMWARE_TOV 30
  176. #define LOGOUT_TOV 10
  177. #define IOCB_TOV_MARGIN 10
  178. #define RELOGIN_TOV 18
  179. #define ISNS_DEREG_TOV 5
  180. #define HBA_ONLINE_TOV 30
  181. #define DISABLE_ACB_TOV 30
  182. #define IP_CONFIG_TOV 30
  183. #define LOGIN_TOV 12
  184. #define BOOT_LOGIN_RESP_TOV 60
  185. #define MAX_RESET_HA_RETRIES 2
  186. #define FW_ALIVE_WAIT_TOV 3
  187. #define IDC_EXTEND_TOV 8
  188. #define IDC_COMP_TOV 5
  189. #define LINK_UP_COMP_TOV 30
  190. #define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
  191. /*
  192. * SCSI Request Block structure (srb) that is placed
  193. * on cmd->SCp location of every I/O [We have 22 bytes available]
  194. */
  195. struct srb {
  196. struct list_head list; /* (8) */
  197. struct scsi_qla_host *ha; /* HA the SP is queued on */
  198. struct ddb_entry *ddb;
  199. uint16_t flags; /* (1) Status flags. */
  200. #define SRB_DMA_VALID BIT_3 /* DMA Buffer mapped. */
  201. #define SRB_GOT_SENSE BIT_4 /* sense data received. */
  202. uint8_t state; /* (1) Status flags. */
  203. #define SRB_NO_QUEUE_STATE 0 /* Request is in between states */
  204. #define SRB_FREE_STATE 1
  205. #define SRB_ACTIVE_STATE 3
  206. #define SRB_ACTIVE_TIMEOUT_STATE 4
  207. #define SRB_SUSPENDED_STATE 7 /* Request in suspended state */
  208. struct scsi_cmnd *cmd; /* (4) SCSI command block */
  209. dma_addr_t dma_handle; /* (4) for unmap of single transfers */
  210. struct kref srb_ref; /* reference count for this srb */
  211. uint8_t err_id; /* error id */
  212. #define SRB_ERR_PORT 1 /* Request failed because "port down" */
  213. #define SRB_ERR_LOOP 2 /* Request failed because "loop down" */
  214. #define SRB_ERR_DEVICE 3 /* Request failed because "device error" */
  215. #define SRB_ERR_OTHER 4
  216. uint16_t reserved;
  217. uint16_t iocb_tov;
  218. uint16_t iocb_cnt; /* Number of used iocbs */
  219. uint16_t cc_stat;
  220. /* Used for extended sense / status continuation */
  221. uint8_t *req_sense_ptr;
  222. uint16_t req_sense_len;
  223. uint16_t reserved2;
  224. };
  225. /* Mailbox request block structure */
  226. struct mrb {
  227. struct scsi_qla_host *ha;
  228. struct mbox_cmd_iocb *mbox;
  229. uint32_t mbox_cmd;
  230. uint16_t iocb_cnt; /* Number of used iocbs */
  231. uint32_t pid;
  232. };
  233. /*
  234. * Asynchronous Event Queue structure
  235. */
  236. struct aen {
  237. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  238. };
  239. struct ql4_aen_log {
  240. int count;
  241. struct aen entry[MAX_AEN_ENTRIES];
  242. };
  243. /*
  244. * Device Database (DDB) structure
  245. */
  246. struct ddb_entry {
  247. struct scsi_qla_host *ha;
  248. struct iscsi_cls_session *sess;
  249. struct iscsi_cls_conn *conn;
  250. uint16_t fw_ddb_index; /* DDB firmware index */
  251. uint32_t fw_ddb_device_state; /* F/W Device State -- see ql4_fw.h */
  252. uint16_t ddb_type;
  253. #define FLASH_DDB 0x01
  254. struct dev_db_entry fw_ddb_entry;
  255. int (*unblock_sess)(struct iscsi_cls_session *cls_session);
  256. int (*ddb_change)(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
  257. struct ddb_entry *ddb_entry, uint32_t state);
  258. /* Driver Re-login */
  259. unsigned long flags; /* DDB Flags */
  260. #define DDB_CONN_CLOSE_FAILURE 0 /* 0x00000001 */
  261. uint16_t default_relogin_timeout; /* Max time to wait for
  262. * relogin to complete */
  263. atomic_t retry_relogin_timer; /* Min Time between relogins
  264. * (4000 only) */
  265. atomic_t relogin_timer; /* Max Time to wait for
  266. * relogin to complete */
  267. atomic_t relogin_retry_count; /* Num of times relogin has been
  268. * retried */
  269. uint32_t default_time2wait; /* Default Min time between
  270. * relogins (+aens) */
  271. uint16_t chap_tbl_idx;
  272. };
  273. struct qla_ddb_index {
  274. struct list_head list;
  275. uint16_t fw_ddb_idx;
  276. uint16_t flash_ddb_idx;
  277. struct dev_db_entry fw_ddb;
  278. uint8_t flash_isid[6];
  279. };
  280. #define DDB_IPADDR_LEN 64
  281. struct ql4_tuple_ddb {
  282. int port;
  283. int tpgt;
  284. char ip_addr[DDB_IPADDR_LEN];
  285. char iscsi_name[ISCSI_NAME_SIZE];
  286. uint16_t options;
  287. #define DDB_OPT_IPV6 0x0e0e
  288. #define DDB_OPT_IPV4 0x0f0f
  289. uint8_t isid[6];
  290. };
  291. /*
  292. * DDB states.
  293. */
  294. #define DDB_STATE_DEAD 0 /* We can no longer talk to
  295. * this device */
  296. #define DDB_STATE_ONLINE 1 /* Device ready to accept
  297. * commands */
  298. #define DDB_STATE_MISSING 2 /* Device logged off, trying
  299. * to re-login */
  300. /*
  301. * DDB flags.
  302. */
  303. #define DF_RELOGIN 0 /* Relogin to device */
  304. #define DF_BOOT_TGT 1 /* Boot target entry */
  305. #define DF_ISNS_DISCOVERED 2 /* Device was discovered via iSNS */
  306. #define DF_FO_MASKED 3
  307. #define DF_DISABLE_RELOGIN 4 /* Disable relogin to device */
  308. enum qla4_work_type {
  309. QLA4_EVENT_AEN,
  310. QLA4_EVENT_PING_STATUS,
  311. };
  312. struct qla4_work_evt {
  313. struct list_head list;
  314. enum qla4_work_type type;
  315. union {
  316. struct {
  317. enum iscsi_host_event_code code;
  318. uint32_t data_size;
  319. uint8_t data[0];
  320. } aen;
  321. struct {
  322. uint32_t status;
  323. uint32_t pid;
  324. uint32_t data_size;
  325. uint8_t data[0];
  326. } ping;
  327. } u;
  328. };
  329. struct ql82xx_hw_data {
  330. /* Offsets for flash/nvram access (set to ~0 if not used). */
  331. uint32_t flash_conf_off;
  332. uint32_t flash_data_off;
  333. uint32_t fdt_wrt_disable;
  334. uint32_t fdt_erase_cmd;
  335. uint32_t fdt_block_size;
  336. uint32_t fdt_unprotect_sec_cmd;
  337. uint32_t fdt_protect_sec_cmd;
  338. uint32_t flt_region_flt;
  339. uint32_t flt_region_fdt;
  340. uint32_t flt_region_boot;
  341. uint32_t flt_region_bootload;
  342. uint32_t flt_region_fw;
  343. uint32_t flt_iscsi_param;
  344. uint32_t flt_region_chap;
  345. uint32_t flt_chap_size;
  346. uint32_t flt_region_ddb;
  347. uint32_t flt_ddb_size;
  348. };
  349. struct qla4_8xxx_legacy_intr_set {
  350. uint32_t int_vec_bit;
  351. uint32_t tgt_status_reg;
  352. uint32_t tgt_mask_reg;
  353. uint32_t pci_int_reg;
  354. };
  355. /* MSI-X Support */
  356. #define QLA_MSIX_DEFAULT 0x00
  357. #define QLA_MSIX_RSP_Q 0x01
  358. #define QLA_MSIX_ENTRIES 2
  359. #define QLA_MIDX_DEFAULT 0
  360. #define QLA_MIDX_RSP_Q 1
  361. struct ql4_msix_entry {
  362. int have_irq;
  363. uint16_t msix_vector;
  364. uint16_t msix_entry;
  365. };
  366. /*
  367. * ISP Operations
  368. */
  369. struct isp_operations {
  370. int (*iospace_config) (struct scsi_qla_host *ha);
  371. void (*pci_config) (struct scsi_qla_host *);
  372. void (*disable_intrs) (struct scsi_qla_host *);
  373. void (*enable_intrs) (struct scsi_qla_host *);
  374. int (*start_firmware) (struct scsi_qla_host *);
  375. int (*restart_firmware) (struct scsi_qla_host *);
  376. irqreturn_t (*intr_handler) (int , void *);
  377. void (*interrupt_service_routine) (struct scsi_qla_host *, uint32_t);
  378. int (*need_reset) (struct scsi_qla_host *);
  379. int (*reset_chip) (struct scsi_qla_host *);
  380. int (*reset_firmware) (struct scsi_qla_host *);
  381. void (*queue_iocb) (struct scsi_qla_host *);
  382. void (*complete_iocb) (struct scsi_qla_host *);
  383. uint16_t (*rd_shdw_req_q_out) (struct scsi_qla_host *);
  384. uint16_t (*rd_shdw_rsp_q_in) (struct scsi_qla_host *);
  385. int (*get_sys_info) (struct scsi_qla_host *);
  386. uint32_t (*rd_reg_direct) (struct scsi_qla_host *, ulong);
  387. void (*wr_reg_direct) (struct scsi_qla_host *, ulong, uint32_t);
  388. int (*rd_reg_indirect) (struct scsi_qla_host *, uint32_t, uint32_t *);
  389. int (*wr_reg_indirect) (struct scsi_qla_host *, uint32_t, uint32_t);
  390. int (*idc_lock) (struct scsi_qla_host *);
  391. void (*idc_unlock) (struct scsi_qla_host *);
  392. void (*rom_lock_recovery) (struct scsi_qla_host *);
  393. void (*queue_mailbox_command) (struct scsi_qla_host *, uint32_t *, int);
  394. void (*process_mailbox_interrupt) (struct scsi_qla_host *, int);
  395. };
  396. struct ql4_mdump_size_table {
  397. uint32_t size;
  398. uint32_t size_cmask_02;
  399. uint32_t size_cmask_04;
  400. uint32_t size_cmask_08;
  401. uint32_t size_cmask_10;
  402. uint32_t size_cmask_FF;
  403. uint32_t version;
  404. };
  405. /*qla4xxx ipaddress configuration details */
  406. struct ipaddress_config {
  407. uint16_t ipv4_options;
  408. uint16_t tcp_options;
  409. uint16_t ipv4_vlan_tag;
  410. uint8_t ipv4_addr_state;
  411. uint8_t ip_address[IP_ADDR_LEN];
  412. uint8_t subnet_mask[IP_ADDR_LEN];
  413. uint8_t gateway[IP_ADDR_LEN];
  414. uint32_t ipv6_options;
  415. uint32_t ipv6_addl_options;
  416. uint8_t ipv6_link_local_state;
  417. uint8_t ipv6_addr0_state;
  418. uint8_t ipv6_addr1_state;
  419. uint8_t ipv6_default_router_state;
  420. uint16_t ipv6_vlan_tag;
  421. struct in6_addr ipv6_link_local_addr;
  422. struct in6_addr ipv6_addr0;
  423. struct in6_addr ipv6_addr1;
  424. struct in6_addr ipv6_default_router_addr;
  425. uint16_t eth_mtu_size;
  426. uint16_t ipv4_port;
  427. uint16_t ipv6_port;
  428. uint8_t control;
  429. uint16_t ipv6_tcp_options;
  430. uint8_t tcp_wsf;
  431. uint8_t ipv6_tcp_wsf;
  432. uint8_t ipv4_tos;
  433. uint8_t ipv4_cache_id;
  434. uint8_t ipv6_cache_id;
  435. uint8_t ipv4_alt_cid_len;
  436. uint8_t ipv4_alt_cid[11];
  437. uint8_t ipv4_vid_len;
  438. uint8_t ipv4_vid[11];
  439. uint8_t ipv4_ttl;
  440. uint16_t ipv6_flow_lbl;
  441. uint8_t ipv6_traffic_class;
  442. uint8_t ipv6_hop_limit;
  443. uint32_t ipv6_nd_reach_time;
  444. uint32_t ipv6_nd_rexmit_timer;
  445. uint32_t ipv6_nd_stale_timeout;
  446. uint8_t ipv6_dup_addr_detect_count;
  447. uint32_t ipv6_gw_advrt_mtu;
  448. uint16_t def_timeout;
  449. uint8_t abort_timer;
  450. uint16_t iscsi_options;
  451. uint16_t iscsi_max_pdu_size;
  452. uint16_t iscsi_first_burst_len;
  453. uint16_t iscsi_max_outstnd_r2t;
  454. uint16_t iscsi_max_burst_len;
  455. uint8_t iscsi_name[224];
  456. };
  457. #define QL4_CHAP_MAX_NAME_LEN 256
  458. #define QL4_CHAP_MAX_SECRET_LEN 100
  459. #define LOCAL_CHAP 0
  460. #define BIDI_CHAP 1
  461. struct ql4_chap_format {
  462. u8 intr_chap_name[QL4_CHAP_MAX_NAME_LEN];
  463. u8 intr_secret[QL4_CHAP_MAX_SECRET_LEN];
  464. u8 target_chap_name[QL4_CHAP_MAX_NAME_LEN];
  465. u8 target_secret[QL4_CHAP_MAX_SECRET_LEN];
  466. u16 intr_chap_name_length;
  467. u16 intr_secret_length;
  468. u16 target_chap_name_length;
  469. u16 target_secret_length;
  470. };
  471. struct ip_address_format {
  472. u8 ip_type;
  473. u8 ip_address[16];
  474. };
  475. struct ql4_conn_info {
  476. u16 dest_port;
  477. struct ip_address_format dest_ipaddr;
  478. struct ql4_chap_format chap;
  479. };
  480. struct ql4_boot_session_info {
  481. u8 target_name[224];
  482. struct ql4_conn_info conn_list[1];
  483. };
  484. struct ql4_boot_tgt_info {
  485. struct ql4_boot_session_info boot_pri_sess;
  486. struct ql4_boot_session_info boot_sec_sess;
  487. };
  488. /*
  489. * Linux Host Adapter structure
  490. */
  491. struct scsi_qla_host {
  492. /* Linux adapter configuration data */
  493. unsigned long flags;
  494. #define AF_ONLINE 0 /* 0x00000001 */
  495. #define AF_INIT_DONE 1 /* 0x00000002 */
  496. #define AF_MBOX_COMMAND 2 /* 0x00000004 */
  497. #define AF_MBOX_COMMAND_DONE 3 /* 0x00000008 */
  498. #define AF_ST_DISCOVERY_IN_PROGRESS 4 /* 0x00000010 */
  499. #define AF_INTERRUPTS_ON 6 /* 0x00000040 */
  500. #define AF_GET_CRASH_RECORD 7 /* 0x00000080 */
  501. #define AF_LINK_UP 8 /* 0x00000100 */
  502. #define AF_LOOPBACK 9 /* 0x00000200 */
  503. #define AF_IRQ_ATTACHED 10 /* 0x00000400 */
  504. #define AF_DISABLE_ACB_COMPLETE 11 /* 0x00000800 */
  505. #define AF_HA_REMOVAL 12 /* 0x00001000 */
  506. #define AF_INTx_ENABLED 15 /* 0x00008000 */
  507. #define AF_MSI_ENABLED 16 /* 0x00010000 */
  508. #define AF_MSIX_ENABLED 17 /* 0x00020000 */
  509. #define AF_MBOX_COMMAND_NOPOLL 18 /* 0x00040000 */
  510. #define AF_FW_RECOVERY 19 /* 0x00080000 */
  511. #define AF_EEH_BUSY 20 /* 0x00100000 */
  512. #define AF_PCI_CHANNEL_IO_PERM_FAILURE 21 /* 0x00200000 */
  513. #define AF_BUILD_DDB_LIST 22 /* 0x00400000 */
  514. #define AF_82XX_FW_DUMPED 24 /* 0x01000000 */
  515. #define AF_8XXX_RST_OWNER 25 /* 0x02000000 */
  516. #define AF_82XX_DUMP_READING 26 /* 0x04000000 */
  517. #define AF_83XX_IOCB_INTR_ON 28 /* 0x10000000 */
  518. #define AF_83XX_MBOX_INTR_ON 29 /* 0x20000000 */
  519. unsigned long dpc_flags;
  520. #define DPC_RESET_HA 1 /* 0x00000002 */
  521. #define DPC_RETRY_RESET_HA 2 /* 0x00000004 */
  522. #define DPC_RELOGIN_DEVICE 3 /* 0x00000008 */
  523. #define DPC_RESET_HA_FW_CONTEXT 4 /* 0x00000010 */
  524. #define DPC_RESET_HA_INTR 5 /* 0x00000020 */
  525. #define DPC_ISNS_RESTART 7 /* 0x00000080 */
  526. #define DPC_AEN 9 /* 0x00000200 */
  527. #define DPC_GET_DHCP_IP_ADDR 15 /* 0x00008000 */
  528. #define DPC_LINK_CHANGED 18 /* 0x00040000 */
  529. #define DPC_RESET_ACTIVE 20 /* 0x00100000 */
  530. #define DPC_HA_UNRECOVERABLE 21 /* 0x00200000 ISP-82xx only*/
  531. #define DPC_HA_NEED_QUIESCENT 22 /* 0x00400000 ISP-82xx only*/
  532. #define DPC_POST_IDC_ACK 23 /* 0x00800000 */
  533. #define DPC_RESTORE_ACB 24 /* 0x01000000 */
  534. #define DPC_SYSFS_DDB_EXPORT 25 /* 0x02000000 */
  535. struct Scsi_Host *host; /* pointer to host data */
  536. uint32_t tot_ddbs;
  537. uint16_t iocb_cnt;
  538. uint16_t iocb_hiwat;
  539. /* SRB cache. */
  540. #define SRB_MIN_REQ 128
  541. mempool_t *srb_mempool;
  542. /* pci information */
  543. struct pci_dev *pdev;
  544. struct isp_reg __iomem *reg; /* Base I/O address */
  545. unsigned long pio_address;
  546. unsigned long pio_length;
  547. #define MIN_IOBASE_LEN 0x100
  548. uint16_t req_q_count;
  549. unsigned long host_no;
  550. /* NVRAM registers */
  551. struct eeprom_data *nvram;
  552. spinlock_t hardware_lock ____cacheline_aligned;
  553. uint32_t eeprom_cmd_data;
  554. /* Counters for general statistics */
  555. uint64_t isr_count;
  556. uint64_t adapter_error_count;
  557. uint64_t device_error_count;
  558. uint64_t total_io_count;
  559. uint64_t total_mbytes_xferred;
  560. uint64_t link_failure_count;
  561. uint64_t invalid_crc_count;
  562. uint32_t bytes_xfered;
  563. uint32_t spurious_int_count;
  564. uint32_t aborted_io_count;
  565. uint32_t io_timeout_count;
  566. uint32_t mailbox_timeout_count;
  567. uint32_t seconds_since_last_intr;
  568. uint32_t seconds_since_last_heartbeat;
  569. uint32_t mac_index;
  570. /* Info Needed for Management App */
  571. /* --- From GetFwVersion --- */
  572. uint32_t firmware_version[2];
  573. uint32_t patch_number;
  574. uint32_t build_number;
  575. uint32_t board_id;
  576. /* --- From Init_FW --- */
  577. /* init_cb_t *init_cb; */
  578. uint16_t firmware_options;
  579. uint8_t alias[32];
  580. uint8_t name_string[256];
  581. uint8_t heartbeat_interval;
  582. /* --- From FlashSysInfo --- */
  583. uint8_t my_mac[MAC_ADDR_LEN];
  584. uint8_t serial_number[16];
  585. uint16_t port_num;
  586. /* --- From GetFwState --- */
  587. uint32_t firmware_state;
  588. uint32_t addl_fw_state;
  589. /* Linux kernel thread */
  590. struct workqueue_struct *dpc_thread;
  591. struct work_struct dpc_work;
  592. /* Linux timer thread */
  593. struct timer_list timer;
  594. uint32_t timer_active;
  595. /* Recovery Timers */
  596. atomic_t check_relogin_timeouts;
  597. uint32_t retry_reset_ha_cnt;
  598. uint32_t isp_reset_timer; /* reset test timer */
  599. uint32_t nic_reset_timer; /* simulated nic reset test timer */
  600. int eh_start;
  601. struct list_head free_srb_q;
  602. uint16_t free_srb_q_count;
  603. uint16_t num_srbs_allocated;
  604. /* DMA Memory Block */
  605. void *queues;
  606. dma_addr_t queues_dma;
  607. unsigned long queues_len;
  608. #define MEM_ALIGN_VALUE \
  609. ((max(REQUEST_QUEUE_DEPTH, RESPONSE_QUEUE_DEPTH)) * \
  610. sizeof(struct queue_entry))
  611. /* request and response queue variables */
  612. dma_addr_t request_dma;
  613. struct queue_entry *request_ring;
  614. struct queue_entry *request_ptr;
  615. dma_addr_t response_dma;
  616. struct queue_entry *response_ring;
  617. struct queue_entry *response_ptr;
  618. dma_addr_t shadow_regs_dma;
  619. struct shadow_regs *shadow_regs;
  620. uint16_t request_in; /* Current indexes. */
  621. uint16_t request_out;
  622. uint16_t response_in;
  623. uint16_t response_out;
  624. /* aen queue variables */
  625. uint16_t aen_q_count; /* Number of available aen_q entries */
  626. uint16_t aen_in; /* Current indexes */
  627. uint16_t aen_out;
  628. struct aen aen_q[MAX_AEN_ENTRIES];
  629. struct ql4_aen_log aen_log;/* tracks all aens */
  630. /* This mutex protects several threads to do mailbox commands
  631. * concurrently.
  632. */
  633. struct mutex mbox_sem;
  634. /* temporary mailbox status registers */
  635. volatile uint8_t mbox_status_count;
  636. volatile uint32_t mbox_status[MBOX_REG_COUNT];
  637. /* FW ddb index map */
  638. struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
  639. /* Saved srb for status continuation entry processing */
  640. struct srb *status_srb;
  641. uint8_t acb_version;
  642. /* qla82xx specific fields */
  643. struct device_reg_82xx __iomem *qla4_82xx_reg; /* Base I/O address */
  644. unsigned long nx_pcibase; /* Base I/O address */
  645. uint8_t *nx_db_rd_ptr; /* Doorbell read pointer */
  646. unsigned long nx_db_wr_ptr; /* Door bell write pointer */
  647. unsigned long first_page_group_start;
  648. unsigned long first_page_group_end;
  649. uint32_t crb_win;
  650. uint32_t curr_window;
  651. uint32_t ddr_mn_window;
  652. unsigned long mn_win_crb;
  653. unsigned long ms_win_crb;
  654. int qdr_sn_window;
  655. rwlock_t hw_lock;
  656. uint16_t func_num;
  657. int link_width;
  658. struct qla4_8xxx_legacy_intr_set nx_legacy_intr;
  659. u32 nx_crb_mask;
  660. uint8_t revision_id;
  661. uint32_t fw_heartbeat_counter;
  662. struct isp_operations *isp_ops;
  663. struct ql82xx_hw_data hw;
  664. struct ql4_msix_entry msix_entries[QLA_MSIX_ENTRIES];
  665. uint32_t nx_dev_init_timeout;
  666. uint32_t nx_reset_timeout;
  667. void *fw_dump;
  668. uint32_t fw_dump_size;
  669. uint32_t fw_dump_capture_mask;
  670. void *fw_dump_tmplt_hdr;
  671. uint32_t fw_dump_tmplt_size;
  672. uint32_t fw_dump_skip_size;
  673. struct completion mbx_intr_comp;
  674. struct ipaddress_config ip_config;
  675. struct iscsi_iface *iface_ipv4;
  676. struct iscsi_iface *iface_ipv6_0;
  677. struct iscsi_iface *iface_ipv6_1;
  678. /* --- From About Firmware --- */
  679. struct about_fw_info fw_info;
  680. uint32_t fw_uptime_secs; /* seconds elapsed since fw bootup */
  681. uint32_t fw_uptime_msecs; /* milliseconds beyond elapsed seconds */
  682. uint16_t def_timeout; /* Default login timeout */
  683. uint32_t flash_state;
  684. #define QLFLASH_WAITING 0
  685. #define QLFLASH_READING 1
  686. #define QLFLASH_WRITING 2
  687. struct dma_pool *chap_dma_pool;
  688. uint8_t *chap_list; /* CHAP table cache */
  689. struct mutex chap_sem;
  690. #define CHAP_DMA_BLOCK_SIZE 512
  691. struct workqueue_struct *task_wq;
  692. unsigned long ddb_idx_map[MAX_DDB_ENTRIES / BITS_PER_LONG];
  693. #define SYSFS_FLAG_FW_SEL_BOOT 2
  694. struct iscsi_boot_kset *boot_kset;
  695. struct ql4_boot_tgt_info boot_tgt;
  696. uint16_t phy_port_num;
  697. uint16_t phy_port_cnt;
  698. uint16_t iscsi_pci_func_cnt;
  699. uint8_t model_name[16];
  700. struct completion disable_acb_comp;
  701. struct dma_pool *fw_ddb_dma_pool;
  702. #define DDB_DMA_BLOCK_SIZE 512
  703. uint16_t pri_ddb_idx;
  704. uint16_t sec_ddb_idx;
  705. int is_reset;
  706. uint16_t temperature;
  707. /* event work list */
  708. struct list_head work_list;
  709. spinlock_t work_lock;
  710. /* mbox iocb */
  711. #define MAX_MRB 128
  712. struct mrb *active_mrb_array[MAX_MRB];
  713. uint32_t mrb_index;
  714. uint32_t *reg_tbl;
  715. struct qla4_83xx_reset_template reset_tmplt;
  716. struct device_reg_83xx __iomem *qla4_83xx_reg; /* Base I/O address
  717. for ISP8324 and
  718. and ISP8042 */
  719. uint32_t pf_bit;
  720. struct qla4_83xx_idc_information idc_info;
  721. struct addr_ctrl_blk *saved_acb;
  722. int notify_idc_comp;
  723. int notify_link_up_comp;
  724. int idc_extend_tmo;
  725. struct completion idc_comp;
  726. struct completion link_up_comp;
  727. };
  728. struct ql4_task_data {
  729. struct scsi_qla_host *ha;
  730. uint8_t iocb_req_cnt;
  731. dma_addr_t data_dma;
  732. void *req_buffer;
  733. dma_addr_t req_dma;
  734. uint32_t req_len;
  735. void *resp_buffer;
  736. dma_addr_t resp_dma;
  737. uint32_t resp_len;
  738. struct iscsi_task *task;
  739. struct passthru_status sts;
  740. struct work_struct task_work;
  741. };
  742. struct qla_endpoint {
  743. struct Scsi_Host *host;
  744. struct sockaddr_storage dst_addr;
  745. };
  746. struct qla_conn {
  747. struct qla_endpoint *qla_ep;
  748. };
  749. static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
  750. {
  751. return ((ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) != 0);
  752. }
  753. static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
  754. {
  755. return ((ha->ip_config.ipv6_options &
  756. IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
  757. }
  758. static inline int is_qla4010(struct scsi_qla_host *ha)
  759. {
  760. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
  761. }
  762. static inline int is_qla4022(struct scsi_qla_host *ha)
  763. {
  764. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
  765. }
  766. static inline int is_qla4032(struct scsi_qla_host *ha)
  767. {
  768. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
  769. }
  770. static inline int is_qla40XX(struct scsi_qla_host *ha)
  771. {
  772. return is_qla4032(ha) || is_qla4022(ha) || is_qla4010(ha);
  773. }
  774. static inline int is_qla8022(struct scsi_qla_host *ha)
  775. {
  776. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
  777. }
  778. static inline int is_qla8032(struct scsi_qla_host *ha)
  779. {
  780. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324;
  781. }
  782. static inline int is_qla8042(struct scsi_qla_host *ha)
  783. {
  784. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8042;
  785. }
  786. static inline int is_qla80XX(struct scsi_qla_host *ha)
  787. {
  788. return is_qla8022(ha) || is_qla8032(ha) || is_qla8042(ha);
  789. }
  790. static inline int is_aer_supported(struct scsi_qla_host *ha)
  791. {
  792. return ((ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022) ||
  793. (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324) ||
  794. (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8042));
  795. }
  796. static inline int adapter_up(struct scsi_qla_host *ha)
  797. {
  798. return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
  799. (test_bit(AF_LINK_UP, &ha->flags) != 0) &&
  800. (!test_bit(AF_LOOPBACK, &ha->flags));
  801. }
  802. static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
  803. {
  804. return (struct scsi_qla_host *)iscsi_host_priv(shost);
  805. }
  806. static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
  807. {
  808. return (is_qla4010(ha) ?
  809. &ha->reg->u1.isp4010.nvram :
  810. &ha->reg->u1.isp4022.semaphore);
  811. }
  812. static inline void __iomem* isp_nvram(struct scsi_qla_host *ha)
  813. {
  814. return (is_qla4010(ha) ?
  815. &ha->reg->u1.isp4010.nvram :
  816. &ha->reg->u1.isp4022.nvram);
  817. }
  818. static inline void __iomem* isp_ext_hw_conf(struct scsi_qla_host *ha)
  819. {
  820. return (is_qla4010(ha) ?
  821. &ha->reg->u2.isp4010.ext_hw_conf :
  822. &ha->reg->u2.isp4022.p0.ext_hw_conf);
  823. }
  824. static inline void __iomem* isp_port_status(struct scsi_qla_host *ha)
  825. {
  826. return (is_qla4010(ha) ?
  827. &ha->reg->u2.isp4010.port_status :
  828. &ha->reg->u2.isp4022.p0.port_status);
  829. }
  830. static inline void __iomem* isp_port_ctrl(struct scsi_qla_host *ha)
  831. {
  832. return (is_qla4010(ha) ?
  833. &ha->reg->u2.isp4010.port_ctrl :
  834. &ha->reg->u2.isp4022.p0.port_ctrl);
  835. }
  836. static inline void __iomem* isp_port_error_status(struct scsi_qla_host *ha)
  837. {
  838. return (is_qla4010(ha) ?
  839. &ha->reg->u2.isp4010.port_err_status :
  840. &ha->reg->u2.isp4022.p0.port_err_status);
  841. }
  842. static inline void __iomem * isp_gp_out(struct scsi_qla_host *ha)
  843. {
  844. return (is_qla4010(ha) ?
  845. &ha->reg->u2.isp4010.gp_out :
  846. &ha->reg->u2.isp4022.p0.gp_out);
  847. }
  848. static inline int eeprom_ext_hw_conf_offset(struct scsi_qla_host *ha)
  849. {
  850. return (is_qla4010(ha) ?
  851. offsetof(struct eeprom_data, isp4010.ext_hw_conf) / 2 :
  852. offsetof(struct eeprom_data, isp4022.ext_hw_conf) / 2);
  853. }
  854. int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
  855. void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask);
  856. int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
  857. static inline int ql4xxx_lock_flash(struct scsi_qla_host *a)
  858. {
  859. if (is_qla4010(a))
  860. return ql4xxx_sem_spinlock(a, QL4010_FLASH_SEM_MASK,
  861. QL4010_FLASH_SEM_BITS);
  862. else
  863. return ql4xxx_sem_spinlock(a, QL4022_FLASH_SEM_MASK,
  864. (QL4022_RESOURCE_BITS_BASE_CODE |
  865. (a->mac_index)) << 13);
  866. }
  867. static inline void ql4xxx_unlock_flash(struct scsi_qla_host *a)
  868. {
  869. if (is_qla4010(a))
  870. ql4xxx_sem_unlock(a, QL4010_FLASH_SEM_MASK);
  871. else
  872. ql4xxx_sem_unlock(a, QL4022_FLASH_SEM_MASK);
  873. }
  874. static inline int ql4xxx_lock_nvram(struct scsi_qla_host *a)
  875. {
  876. if (is_qla4010(a))
  877. return ql4xxx_sem_spinlock(a, QL4010_NVRAM_SEM_MASK,
  878. QL4010_NVRAM_SEM_BITS);
  879. else
  880. return ql4xxx_sem_spinlock(a, QL4022_NVRAM_SEM_MASK,
  881. (QL4022_RESOURCE_BITS_BASE_CODE |
  882. (a->mac_index)) << 10);
  883. }
  884. static inline void ql4xxx_unlock_nvram(struct scsi_qla_host *a)
  885. {
  886. if (is_qla4010(a))
  887. ql4xxx_sem_unlock(a, QL4010_NVRAM_SEM_MASK);
  888. else
  889. ql4xxx_sem_unlock(a, QL4022_NVRAM_SEM_MASK);
  890. }
  891. static inline int ql4xxx_lock_drvr(struct scsi_qla_host *a)
  892. {
  893. if (is_qla4010(a))
  894. return ql4xxx_sem_lock(a, QL4010_DRVR_SEM_MASK,
  895. QL4010_DRVR_SEM_BITS);
  896. else
  897. return ql4xxx_sem_lock(a, QL4022_DRVR_SEM_MASK,
  898. (QL4022_RESOURCE_BITS_BASE_CODE |
  899. (a->mac_index)) << 1);
  900. }
  901. static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
  902. {
  903. if (is_qla4010(a))
  904. ql4xxx_sem_unlock(a, QL4010_DRVR_SEM_MASK);
  905. else
  906. ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
  907. }
  908. static inline int ql4xxx_reset_active(struct scsi_qla_host *ha)
  909. {
  910. return test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  911. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  912. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  913. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  914. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  915. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  916. }
  917. static inline int qla4_8xxx_rd_direct(struct scsi_qla_host *ha,
  918. const uint32_t crb_reg)
  919. {
  920. return ha->isp_ops->rd_reg_direct(ha, ha->reg_tbl[crb_reg]);
  921. }
  922. static inline void qla4_8xxx_wr_direct(struct scsi_qla_host *ha,
  923. const uint32_t crb_reg,
  924. const uint32_t value)
  925. {
  926. ha->isp_ops->wr_reg_direct(ha, ha->reg_tbl[crb_reg], value);
  927. }
  928. /*---------------------------------------------------------------------------*/
  929. /* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
  930. #define INIT_ADAPTER 0
  931. #define RESET_ADAPTER 1
  932. #define PRESERVE_DDB_LIST 0
  933. #define REBUILD_DDB_LIST 1
  934. /* Defines for process_aen() */
  935. #define PROCESS_ALL_AENS 0
  936. #define FLUSH_DDB_CHANGED_AENS 1
  937. /* Defines for udev events */
  938. #define QL4_UEVENT_CODE_FW_DUMP 0
  939. #endif /*_QLA4XXX_H */