ql4_def.h 28 KB

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