ql4_def.h 26 KB

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