ql4_def.h 28 KB

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