ql4_def.h 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. uint16_t flash_ddb_idx;
  268. struct dev_db_entry fw_ddb;
  269. uint8_t flash_isid[6];
  270. };
  271. #define DDB_IPADDR_LEN 64
  272. struct ql4_tuple_ddb {
  273. int port;
  274. int tpgt;
  275. char ip_addr[DDB_IPADDR_LEN];
  276. char iscsi_name[ISCSI_NAME_SIZE];
  277. uint16_t options;
  278. #define DDB_OPT_IPV6 0x0e0e
  279. #define DDB_OPT_IPV4 0x0f0f
  280. uint8_t isid[6];
  281. };
  282. /*
  283. * DDB states.
  284. */
  285. #define DDB_STATE_DEAD 0 /* We can no longer talk to
  286. * this device */
  287. #define DDB_STATE_ONLINE 1 /* Device ready to accept
  288. * commands */
  289. #define DDB_STATE_MISSING 2 /* Device logged off, trying
  290. * to re-login */
  291. /*
  292. * DDB flags.
  293. */
  294. #define DF_RELOGIN 0 /* Relogin to device */
  295. #define DF_BOOT_TGT 1 /* Boot target entry */
  296. #define DF_ISNS_DISCOVERED 2 /* Device was discovered via iSNS */
  297. #define DF_FO_MASKED 3
  298. #define DF_DISABLE_RELOGIN 4 /* Disable relogin to device */
  299. enum qla4_work_type {
  300. QLA4_EVENT_AEN,
  301. QLA4_EVENT_PING_STATUS,
  302. };
  303. struct qla4_work_evt {
  304. struct list_head list;
  305. enum qla4_work_type type;
  306. union {
  307. struct {
  308. enum iscsi_host_event_code code;
  309. uint32_t data_size;
  310. uint8_t data[0];
  311. } aen;
  312. struct {
  313. uint32_t status;
  314. uint32_t pid;
  315. uint32_t data_size;
  316. uint8_t data[0];
  317. } ping;
  318. } u;
  319. };
  320. struct ql82xx_hw_data {
  321. /* Offsets for flash/nvram access (set to ~0 if not used). */
  322. uint32_t flash_conf_off;
  323. uint32_t flash_data_off;
  324. uint32_t fdt_wrt_disable;
  325. uint32_t fdt_erase_cmd;
  326. uint32_t fdt_block_size;
  327. uint32_t fdt_unprotect_sec_cmd;
  328. uint32_t fdt_protect_sec_cmd;
  329. uint32_t flt_region_flt;
  330. uint32_t flt_region_fdt;
  331. uint32_t flt_region_boot;
  332. uint32_t flt_region_bootload;
  333. uint32_t flt_region_fw;
  334. uint32_t flt_iscsi_param;
  335. uint32_t flt_region_chap;
  336. uint32_t flt_chap_size;
  337. uint32_t flt_region_ddb;
  338. uint32_t flt_ddb_size;
  339. };
  340. struct qla4_8xxx_legacy_intr_set {
  341. uint32_t int_vec_bit;
  342. uint32_t tgt_status_reg;
  343. uint32_t tgt_mask_reg;
  344. uint32_t pci_int_reg;
  345. };
  346. /* MSI-X Support */
  347. #define QLA_MSIX_DEFAULT 0x00
  348. #define QLA_MSIX_RSP_Q 0x01
  349. #define QLA_MSIX_ENTRIES 2
  350. #define QLA_MIDX_DEFAULT 0
  351. #define QLA_MIDX_RSP_Q 1
  352. struct ql4_msix_entry {
  353. int have_irq;
  354. uint16_t msix_vector;
  355. uint16_t msix_entry;
  356. };
  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. };
  420. #define QL4_CHAP_MAX_NAME_LEN 256
  421. #define QL4_CHAP_MAX_SECRET_LEN 100
  422. #define LOCAL_CHAP 0
  423. #define BIDI_CHAP 1
  424. struct ql4_chap_format {
  425. u8 intr_chap_name[QL4_CHAP_MAX_NAME_LEN];
  426. u8 intr_secret[QL4_CHAP_MAX_SECRET_LEN];
  427. u8 target_chap_name[QL4_CHAP_MAX_NAME_LEN];
  428. u8 target_secret[QL4_CHAP_MAX_SECRET_LEN];
  429. u16 intr_chap_name_length;
  430. u16 intr_secret_length;
  431. u16 target_chap_name_length;
  432. u16 target_secret_length;
  433. };
  434. struct ip_address_format {
  435. u8 ip_type;
  436. u8 ip_address[16];
  437. };
  438. struct ql4_conn_info {
  439. u16 dest_port;
  440. struct ip_address_format dest_ipaddr;
  441. struct ql4_chap_format chap;
  442. };
  443. struct ql4_boot_session_info {
  444. u8 target_name[224];
  445. struct ql4_conn_info conn_list[1];
  446. };
  447. struct ql4_boot_tgt_info {
  448. struct ql4_boot_session_info boot_pri_sess;
  449. struct ql4_boot_session_info boot_sec_sess;
  450. };
  451. /*
  452. * Linux Host Adapter structure
  453. */
  454. struct scsi_qla_host {
  455. /* Linux adapter configuration data */
  456. unsigned long flags;
  457. #define AF_ONLINE 0 /* 0x00000001 */
  458. #define AF_INIT_DONE 1 /* 0x00000002 */
  459. #define AF_MBOX_COMMAND 2 /* 0x00000004 */
  460. #define AF_MBOX_COMMAND_DONE 3 /* 0x00000008 */
  461. #define AF_ST_DISCOVERY_IN_PROGRESS 4 /* 0x00000010 */
  462. #define AF_INTERRUPTS_ON 6 /* 0x00000040 */
  463. #define AF_GET_CRASH_RECORD 7 /* 0x00000080 */
  464. #define AF_LINK_UP 8 /* 0x00000100 */
  465. #define AF_LOOPBACK 9 /* 0x00000200 */
  466. #define AF_IRQ_ATTACHED 10 /* 0x00000400 */
  467. #define AF_DISABLE_ACB_COMPLETE 11 /* 0x00000800 */
  468. #define AF_HA_REMOVAL 12 /* 0x00001000 */
  469. #define AF_INTx_ENABLED 15 /* 0x00008000 */
  470. #define AF_MSI_ENABLED 16 /* 0x00010000 */
  471. #define AF_MSIX_ENABLED 17 /* 0x00020000 */
  472. #define AF_MBOX_COMMAND_NOPOLL 18 /* 0x00040000 */
  473. #define AF_FW_RECOVERY 19 /* 0x00080000 */
  474. #define AF_EEH_BUSY 20 /* 0x00100000 */
  475. #define AF_PCI_CHANNEL_IO_PERM_FAILURE 21 /* 0x00200000 */
  476. #define AF_BUILD_DDB_LIST 22 /* 0x00400000 */
  477. #define AF_82XX_FW_DUMPED 24 /* 0x01000000 */
  478. #define AF_8XXX_RST_OWNER 25 /* 0x02000000 */
  479. #define AF_82XX_DUMP_READING 26 /* 0x04000000 */
  480. #define AF_83XX_NO_FW_DUMP 27 /* 0x08000000 */
  481. #define AF_83XX_IOCB_INTR_ON 28 /* 0x10000000 */
  482. #define AF_83XX_MBOX_INTR_ON 29 /* 0x20000000 */
  483. unsigned long dpc_flags;
  484. #define DPC_RESET_HA 1 /* 0x00000002 */
  485. #define DPC_RETRY_RESET_HA 2 /* 0x00000004 */
  486. #define DPC_RELOGIN_DEVICE 3 /* 0x00000008 */
  487. #define DPC_RESET_HA_FW_CONTEXT 4 /* 0x00000010 */
  488. #define DPC_RESET_HA_INTR 5 /* 0x00000020 */
  489. #define DPC_ISNS_RESTART 7 /* 0x00000080 */
  490. #define DPC_AEN 9 /* 0x00000200 */
  491. #define DPC_GET_DHCP_IP_ADDR 15 /* 0x00008000 */
  492. #define DPC_LINK_CHANGED 18 /* 0x00040000 */
  493. #define DPC_RESET_ACTIVE 20 /* 0x00040000 */
  494. #define DPC_HA_UNRECOVERABLE 21 /* 0x00080000 ISP-82xx only*/
  495. #define DPC_HA_NEED_QUIESCENT 22 /* 0x00100000 ISP-82xx only*/
  496. #define DPC_POST_IDC_ACK 23 /* 0x00200000 */
  497. #define DPC_RESTORE_ACB 24 /* 0x01000000 */
  498. struct Scsi_Host *host; /* pointer to host data */
  499. uint32_t tot_ddbs;
  500. uint16_t iocb_cnt;
  501. uint16_t iocb_hiwat;
  502. /* SRB cache. */
  503. #define SRB_MIN_REQ 128
  504. mempool_t *srb_mempool;
  505. /* pci information */
  506. struct pci_dev *pdev;
  507. struct isp_reg __iomem *reg; /* Base I/O address */
  508. unsigned long pio_address;
  509. unsigned long pio_length;
  510. #define MIN_IOBASE_LEN 0x100
  511. uint16_t req_q_count;
  512. unsigned long host_no;
  513. /* NVRAM registers */
  514. struct eeprom_data *nvram;
  515. spinlock_t hardware_lock ____cacheline_aligned;
  516. uint32_t eeprom_cmd_data;
  517. /* Counters for general statistics */
  518. uint64_t isr_count;
  519. uint64_t adapter_error_count;
  520. uint64_t device_error_count;
  521. uint64_t total_io_count;
  522. uint64_t total_mbytes_xferred;
  523. uint64_t link_failure_count;
  524. uint64_t invalid_crc_count;
  525. uint32_t bytes_xfered;
  526. uint32_t spurious_int_count;
  527. uint32_t aborted_io_count;
  528. uint32_t io_timeout_count;
  529. uint32_t mailbox_timeout_count;
  530. uint32_t seconds_since_last_intr;
  531. uint32_t seconds_since_last_heartbeat;
  532. uint32_t mac_index;
  533. /* Info Needed for Management App */
  534. /* --- From GetFwVersion --- */
  535. uint32_t firmware_version[2];
  536. uint32_t patch_number;
  537. uint32_t build_number;
  538. uint32_t board_id;
  539. /* --- From Init_FW --- */
  540. /* init_cb_t *init_cb; */
  541. uint16_t firmware_options;
  542. uint8_t alias[32];
  543. uint8_t name_string[256];
  544. uint8_t heartbeat_interval;
  545. /* --- From FlashSysInfo --- */
  546. uint8_t my_mac[MAC_ADDR_LEN];
  547. uint8_t serial_number[16];
  548. uint16_t port_num;
  549. /* --- From GetFwState --- */
  550. uint32_t firmware_state;
  551. uint32_t addl_fw_state;
  552. /* Linux kernel thread */
  553. struct workqueue_struct *dpc_thread;
  554. struct work_struct dpc_work;
  555. /* Linux timer thread */
  556. struct timer_list timer;
  557. uint32_t timer_active;
  558. /* Recovery Timers */
  559. atomic_t check_relogin_timeouts;
  560. uint32_t retry_reset_ha_cnt;
  561. uint32_t isp_reset_timer; /* reset test timer */
  562. uint32_t nic_reset_timer; /* simulated nic reset test timer */
  563. int eh_start;
  564. struct list_head free_srb_q;
  565. uint16_t free_srb_q_count;
  566. uint16_t num_srbs_allocated;
  567. /* DMA Memory Block */
  568. void *queues;
  569. dma_addr_t queues_dma;
  570. unsigned long queues_len;
  571. #define MEM_ALIGN_VALUE \
  572. ((max(REQUEST_QUEUE_DEPTH, RESPONSE_QUEUE_DEPTH)) * \
  573. sizeof(struct queue_entry))
  574. /* request and response queue variables */
  575. dma_addr_t request_dma;
  576. struct queue_entry *request_ring;
  577. struct queue_entry *request_ptr;
  578. dma_addr_t response_dma;
  579. struct queue_entry *response_ring;
  580. struct queue_entry *response_ptr;
  581. dma_addr_t shadow_regs_dma;
  582. struct shadow_regs *shadow_regs;
  583. uint16_t request_in; /* Current indexes. */
  584. uint16_t request_out;
  585. uint16_t response_in;
  586. uint16_t response_out;
  587. /* aen queue variables */
  588. uint16_t aen_q_count; /* Number of available aen_q entries */
  589. uint16_t aen_in; /* Current indexes */
  590. uint16_t aen_out;
  591. struct aen aen_q[MAX_AEN_ENTRIES];
  592. struct ql4_aen_log aen_log;/* tracks all aens */
  593. /* This mutex protects several threads to do mailbox commands
  594. * concurrently.
  595. */
  596. struct mutex mbox_sem;
  597. /* temporary mailbox status registers */
  598. volatile uint8_t mbox_status_count;
  599. volatile uint32_t mbox_status[MBOX_REG_COUNT];
  600. /* FW ddb index map */
  601. struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
  602. /* Saved srb for status continuation entry processing */
  603. struct srb *status_srb;
  604. uint8_t acb_version;
  605. /* qla82xx specific fields */
  606. struct device_reg_82xx __iomem *qla4_82xx_reg; /* Base I/O address */
  607. unsigned long nx_pcibase; /* Base I/O address */
  608. uint8_t *nx_db_rd_ptr; /* Doorbell read pointer */
  609. unsigned long nx_db_wr_ptr; /* Door bell write pointer */
  610. unsigned long first_page_group_start;
  611. unsigned long first_page_group_end;
  612. uint32_t crb_win;
  613. uint32_t curr_window;
  614. uint32_t ddr_mn_window;
  615. unsigned long mn_win_crb;
  616. unsigned long ms_win_crb;
  617. int qdr_sn_window;
  618. rwlock_t hw_lock;
  619. uint16_t func_num;
  620. int link_width;
  621. struct qla4_8xxx_legacy_intr_set nx_legacy_intr;
  622. u32 nx_crb_mask;
  623. uint8_t revision_id;
  624. uint32_t fw_heartbeat_counter;
  625. struct isp_operations *isp_ops;
  626. struct ql82xx_hw_data hw;
  627. struct ql4_msix_entry msix_entries[QLA_MSIX_ENTRIES];
  628. uint32_t nx_dev_init_timeout;
  629. uint32_t nx_reset_timeout;
  630. void *fw_dump;
  631. uint32_t fw_dump_size;
  632. uint32_t fw_dump_capture_mask;
  633. void *fw_dump_tmplt_hdr;
  634. uint32_t fw_dump_tmplt_size;
  635. struct completion mbx_intr_comp;
  636. struct ipaddress_config ip_config;
  637. struct iscsi_iface *iface_ipv4;
  638. struct iscsi_iface *iface_ipv6_0;
  639. struct iscsi_iface *iface_ipv6_1;
  640. /* --- From About Firmware --- */
  641. struct about_fw_info fw_info;
  642. uint32_t fw_uptime_secs; /* seconds elapsed since fw bootup */
  643. uint32_t fw_uptime_msecs; /* milliseconds beyond elapsed seconds */
  644. uint16_t def_timeout; /* Default login timeout */
  645. uint32_t flash_state;
  646. #define QLFLASH_WAITING 0
  647. #define QLFLASH_READING 1
  648. #define QLFLASH_WRITING 2
  649. struct dma_pool *chap_dma_pool;
  650. uint8_t *chap_list; /* CHAP table cache */
  651. struct mutex chap_sem;
  652. #define CHAP_DMA_BLOCK_SIZE 512
  653. struct workqueue_struct *task_wq;
  654. unsigned long ddb_idx_map[MAX_DDB_ENTRIES / BITS_PER_LONG];
  655. #define SYSFS_FLAG_FW_SEL_BOOT 2
  656. struct iscsi_boot_kset *boot_kset;
  657. struct ql4_boot_tgt_info boot_tgt;
  658. uint16_t phy_port_num;
  659. uint16_t phy_port_cnt;
  660. uint16_t iscsi_pci_func_cnt;
  661. uint8_t model_name[16];
  662. struct completion disable_acb_comp;
  663. struct dma_pool *fw_ddb_dma_pool;
  664. #define DDB_DMA_BLOCK_SIZE 512
  665. uint16_t pri_ddb_idx;
  666. uint16_t sec_ddb_idx;
  667. int is_reset;
  668. uint16_t temperature;
  669. /* event work list */
  670. struct list_head work_list;
  671. spinlock_t work_lock;
  672. /* mbox iocb */
  673. #define MAX_MRB 128
  674. struct mrb *active_mrb_array[MAX_MRB];
  675. uint32_t mrb_index;
  676. uint32_t *reg_tbl;
  677. struct qla4_83xx_reset_template reset_tmplt;
  678. struct device_reg_83xx __iomem *qla4_83xx_reg; /* Base I/O address
  679. for ISP8324 and
  680. and ISP8042 */
  681. uint32_t pf_bit;
  682. struct qla4_83xx_idc_information idc_info;
  683. struct addr_ctrl_blk *saved_acb;
  684. };
  685. struct ql4_task_data {
  686. struct scsi_qla_host *ha;
  687. uint8_t iocb_req_cnt;
  688. dma_addr_t data_dma;
  689. void *req_buffer;
  690. dma_addr_t req_dma;
  691. uint32_t req_len;
  692. void *resp_buffer;
  693. dma_addr_t resp_dma;
  694. uint32_t resp_len;
  695. struct iscsi_task *task;
  696. struct passthru_status sts;
  697. struct work_struct task_work;
  698. };
  699. struct qla_endpoint {
  700. struct Scsi_Host *host;
  701. struct sockaddr_storage dst_addr;
  702. };
  703. struct qla_conn {
  704. struct qla_endpoint *qla_ep;
  705. };
  706. static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
  707. {
  708. return ((ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) != 0);
  709. }
  710. static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
  711. {
  712. return ((ha->ip_config.ipv6_options &
  713. IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
  714. }
  715. static inline int is_qla4010(struct scsi_qla_host *ha)
  716. {
  717. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
  718. }
  719. static inline int is_qla4022(struct scsi_qla_host *ha)
  720. {
  721. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
  722. }
  723. static inline int is_qla4032(struct scsi_qla_host *ha)
  724. {
  725. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
  726. }
  727. static inline int is_qla40XX(struct scsi_qla_host *ha)
  728. {
  729. return is_qla4032(ha) || is_qla4022(ha) || is_qla4010(ha);
  730. }
  731. static inline int is_qla8022(struct scsi_qla_host *ha)
  732. {
  733. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
  734. }
  735. static inline int is_qla8032(struct scsi_qla_host *ha)
  736. {
  737. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324;
  738. }
  739. static inline int is_qla8042(struct scsi_qla_host *ha)
  740. {
  741. return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8042;
  742. }
  743. static inline int is_qla80XX(struct scsi_qla_host *ha)
  744. {
  745. return is_qla8022(ha) || is_qla8032(ha) || is_qla8042(ha);
  746. }
  747. static inline int is_aer_supported(struct scsi_qla_host *ha)
  748. {
  749. return ((ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022) ||
  750. (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324));
  751. }
  752. static inline int adapter_up(struct scsi_qla_host *ha)
  753. {
  754. return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
  755. (test_bit(AF_LINK_UP, &ha->flags) != 0) &&
  756. (!test_bit(AF_LOOPBACK, &ha->flags));
  757. }
  758. static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
  759. {
  760. return (struct scsi_qla_host *)iscsi_host_priv(shost);
  761. }
  762. static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
  763. {
  764. return (is_qla4010(ha) ?
  765. &ha->reg->u1.isp4010.nvram :
  766. &ha->reg->u1.isp4022.semaphore);
  767. }
  768. static inline void __iomem* isp_nvram(struct scsi_qla_host *ha)
  769. {
  770. return (is_qla4010(ha) ?
  771. &ha->reg->u1.isp4010.nvram :
  772. &ha->reg->u1.isp4022.nvram);
  773. }
  774. static inline void __iomem* isp_ext_hw_conf(struct scsi_qla_host *ha)
  775. {
  776. return (is_qla4010(ha) ?
  777. &ha->reg->u2.isp4010.ext_hw_conf :
  778. &ha->reg->u2.isp4022.p0.ext_hw_conf);
  779. }
  780. static inline void __iomem* isp_port_status(struct scsi_qla_host *ha)
  781. {
  782. return (is_qla4010(ha) ?
  783. &ha->reg->u2.isp4010.port_status :
  784. &ha->reg->u2.isp4022.p0.port_status);
  785. }
  786. static inline void __iomem* isp_port_ctrl(struct scsi_qla_host *ha)
  787. {
  788. return (is_qla4010(ha) ?
  789. &ha->reg->u2.isp4010.port_ctrl :
  790. &ha->reg->u2.isp4022.p0.port_ctrl);
  791. }
  792. static inline void __iomem* isp_port_error_status(struct scsi_qla_host *ha)
  793. {
  794. return (is_qla4010(ha) ?
  795. &ha->reg->u2.isp4010.port_err_status :
  796. &ha->reg->u2.isp4022.p0.port_err_status);
  797. }
  798. static inline void __iomem * isp_gp_out(struct scsi_qla_host *ha)
  799. {
  800. return (is_qla4010(ha) ?
  801. &ha->reg->u2.isp4010.gp_out :
  802. &ha->reg->u2.isp4022.p0.gp_out);
  803. }
  804. static inline int eeprom_ext_hw_conf_offset(struct scsi_qla_host *ha)
  805. {
  806. return (is_qla4010(ha) ?
  807. offsetof(struct eeprom_data, isp4010.ext_hw_conf) / 2 :
  808. offsetof(struct eeprom_data, isp4022.ext_hw_conf) / 2);
  809. }
  810. int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
  811. void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask);
  812. int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
  813. static inline int ql4xxx_lock_flash(struct scsi_qla_host *a)
  814. {
  815. if (is_qla4010(a))
  816. return ql4xxx_sem_spinlock(a, QL4010_FLASH_SEM_MASK,
  817. QL4010_FLASH_SEM_BITS);
  818. else
  819. return ql4xxx_sem_spinlock(a, QL4022_FLASH_SEM_MASK,
  820. (QL4022_RESOURCE_BITS_BASE_CODE |
  821. (a->mac_index)) << 13);
  822. }
  823. static inline void ql4xxx_unlock_flash(struct scsi_qla_host *a)
  824. {
  825. if (is_qla4010(a))
  826. ql4xxx_sem_unlock(a, QL4010_FLASH_SEM_MASK);
  827. else
  828. ql4xxx_sem_unlock(a, QL4022_FLASH_SEM_MASK);
  829. }
  830. static inline int ql4xxx_lock_nvram(struct scsi_qla_host *a)
  831. {
  832. if (is_qla4010(a))
  833. return ql4xxx_sem_spinlock(a, QL4010_NVRAM_SEM_MASK,
  834. QL4010_NVRAM_SEM_BITS);
  835. else
  836. return ql4xxx_sem_spinlock(a, QL4022_NVRAM_SEM_MASK,
  837. (QL4022_RESOURCE_BITS_BASE_CODE |
  838. (a->mac_index)) << 10);
  839. }
  840. static inline void ql4xxx_unlock_nvram(struct scsi_qla_host *a)
  841. {
  842. if (is_qla4010(a))
  843. ql4xxx_sem_unlock(a, QL4010_NVRAM_SEM_MASK);
  844. else
  845. ql4xxx_sem_unlock(a, QL4022_NVRAM_SEM_MASK);
  846. }
  847. static inline int ql4xxx_lock_drvr(struct scsi_qla_host *a)
  848. {
  849. if (is_qla4010(a))
  850. return ql4xxx_sem_lock(a, QL4010_DRVR_SEM_MASK,
  851. QL4010_DRVR_SEM_BITS);
  852. else
  853. return ql4xxx_sem_lock(a, QL4022_DRVR_SEM_MASK,
  854. (QL4022_RESOURCE_BITS_BASE_CODE |
  855. (a->mac_index)) << 1);
  856. }
  857. static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
  858. {
  859. if (is_qla4010(a))
  860. ql4xxx_sem_unlock(a, QL4010_DRVR_SEM_MASK);
  861. else
  862. ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
  863. }
  864. static inline int ql4xxx_reset_active(struct scsi_qla_host *ha)
  865. {
  866. return test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  867. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  868. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  869. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  870. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  871. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  872. }
  873. static inline int qla4_8xxx_rd_direct(struct scsi_qla_host *ha,
  874. const uint32_t crb_reg)
  875. {
  876. return ha->isp_ops->rd_reg_direct(ha, ha->reg_tbl[crb_reg]);
  877. }
  878. static inline void qla4_8xxx_wr_direct(struct scsi_qla_host *ha,
  879. const uint32_t crb_reg,
  880. const uint32_t value)
  881. {
  882. ha->isp_ops->wr_reg_direct(ha, ha->reg_tbl[crb_reg], value);
  883. }
  884. /*---------------------------------------------------------------------------*/
  885. /* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
  886. #define INIT_ADAPTER 0
  887. #define RESET_ADAPTER 1
  888. #define PRESERVE_DDB_LIST 0
  889. #define REBUILD_DDB_LIST 1
  890. /* Defines for process_aen() */
  891. #define PROCESS_ALL_AENS 0
  892. #define FLUSH_DDB_CHANGED_AENS 1
  893. /* Defines for udev events */
  894. #define QL4_UEVENT_CODE_FW_DUMP 0
  895. #endif /*_QLA4XXX_H */