ql4_def.h 27 KB

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