ql4_def.h 28 KB

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