]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/suse-2.6.27.25/patches.drivers/qla4xxx-5.01.00-k8_sles11-03-update
Reenabled linux-xen and xen-image build
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.drivers / qla4xxx-5.01.00-k8_sles11-03-update
CommitLineData
00e5a55c
BS
1From: David Somayajulu <david.somayajulu@qlogic.com>
2Subject: Update qla4xxx to 5.01.00-k8_sles11-03
3References: bnc#444884
4
5This patch updates the qla4xxx driver to 5.01.00-k8_sles11-03.
6
7
8Signed-off-by: David Somayajulu <david.somayajulu@qlogic.com>
9Signed-off-by: Hannes Reinecke <hare@suse.de>
10
11---
12 drivers/scsi/qla4xxx/ql4_dbg.c | 36 --
13 drivers/scsi/qla4xxx/ql4_dbg.h | 59 ++--
14 drivers/scsi/qla4xxx/ql4_def.h | 11
15 drivers/scsi/qla4xxx/ql4_glbl.h | 10
16 drivers/scsi/qla4xxx/ql4_init.c | 172 +++++++-----
17 drivers/scsi/qla4xxx/ql4_inline.h | 143 ++++++++++
18 drivers/scsi/qla4xxx/ql4_iocb.c | 161 +----------
19 drivers/scsi/qla4xxx/ql4_isr.c | 36 +-
20 drivers/scsi/qla4xxx/ql4_mbx.c | 11
21 drivers/scsi/qla4xxx/ql4_os.c | 499 ++++++++++++++++++++-----------------
22 drivers/scsi/qla4xxx/ql4_os.h | 125 +++++++++
23 drivers/scsi/qla4xxx/ql4_version.h | 3
24 12 files changed, 736 insertions(+), 530 deletions(-)
25
26--- a/drivers/scsi/qla4xxx/ql4_dbg.c
27+++ b/drivers/scsi/qla4xxx/ql4_dbg.c
28@@ -13,28 +13,6 @@
29
30 #include <scsi/scsi_dbg.h>
31
32-static void qla4xxx_print_srb_info(struct srb * srb)
33-{
34- printk("%s: srb = 0x%p, flags=0x%02x\n", __func__, srb, srb->flags);
35- printk("%s: cmd = 0x%p, saved_dma_handle = 0x%lx\n",
36- __func__, srb->cmd, (unsigned long) srb->dma_handle);
37- printk("%s: fw_ddb_index = %d, lun = %d\n",
38- __func__, srb->fw_ddb_index, srb->cmd->device->lun);
39- printk("%s: iocb_tov = %d\n",
40- __func__, srb->iocb_tov);
41- printk("%s: cc_stat = 0x%x\n", __func__, srb->cc_stat);
42-}
43-
44-void qla4xxx_print_scsi_cmd(struct scsi_cmnd *cmd)
45-{
46- printk("SCSI Command = 0x%p, Handle=0x%p\n", cmd, cmd->host_scribble);
47- printk(" b=%d, t=%02xh, l=%02xh, cmd_len = %02xh\n",
48- cmd->device->channel, cmd->device->id, cmd->device->lun,
49- cmd->cmd_len);
50- scsi_print_command(cmd);
51- qla4xxx_print_srb_info((struct srb *) cmd->SCp.ptr);
52-}
53-
54 void __dump_registers(struct scsi_qla_host *ha)
55 {
56 uint8_t i;
57@@ -143,17 +121,6 @@ void __dump_registers(struct scsi_qla_ho
58 }
59 }
60
61-void qla4xxx_dump_mbox_registers(struct scsi_qla_host *ha)
62-{
63- unsigned long flags = 0;
64- int i = 0;
65- spin_lock_irqsave(&ha->hardware_lock, flags);
66- for (i = 1; i < MBOX_REG_COUNT; i++)
67- printk(KERN_INFO " Mailbox[%d] = %08x\n", i,
68- readw(&ha->reg->mailbox[i]));
69- spin_unlock_irqrestore(&ha->hardware_lock, flags);
70-}
71-
72 void qla4xxx_dump_registers(struct scsi_qla_host *ha)
73 {
74 unsigned long flags = 0;
75@@ -179,6 +146,5 @@ void qla4xxx_dump_buffer(void *b, uint32
76 else
77 printk(KERN_DEBUG " ");
78 }
79- if (cnt % 16)
80- printk(KERN_DEBUG "\n");
81+ printk(KERN_DEBUG "\n");
82 }
83--- a/drivers/scsi/qla4xxx/ql4_dbg.h
84+++ b/drivers/scsi/qla4xxx/ql4_dbg.h
85@@ -14,49 +14,44 @@
86 /* #define QL_DEBUG_LEVEL_5 */
87 /* #define QL_DEBUG_LEVEL_6 */
88 /* #define QL_DEBUG_LEVEL_9 */
89+#ifndef _QL4_DBG_
90+#define _QL4_DBG_
91
92 #define QL_DEBUG_LEVEL_2 /* ALways enable error messagess */
93 #if defined(QL_DEBUG)
94-#define DEBUG(x) do {x;} while (0);
95+#define DEBUG(x) do {if(extended_error_logging & 0x01) x;} while (0);
96 #else
97-#define DEBUG(x) do {} while (0);
98+#define DEBUG(x)
99 #endif
100
101 #if defined(QL_DEBUG_LEVEL_2)
102-#define DEBUG2(x) do {if(extended_error_logging == 2) x;} while (0);
103-#define DEBUG2_3(x) do {x;} while (0);
104-#else /* */
105-#define DEBUG2(x) do {} while (0);
106-#endif /* */
107+#define DEBUG2(x) do {if(extended_error_logging & 0x02) x;} while (0);
108+#else
109+#define DEBUG2(x)
110+#endif
111
112 #if defined(QL_DEBUG_LEVEL_3)
113-#define DEBUG3(x) do {if(extended_error_logging == 3) x;} while (0);
114-#else /* */
115-#define DEBUG3(x) do {} while (0);
116-#if !defined(QL_DEBUG_LEVEL_2)
117-#define DEBUG2_3(x) do {} while (0);
118-#endif /* */
119-#endif /* */
120+#define DEBUG3(x) do {if(extended_error_logging & 0x04) x;} while (0);
121+#else
122+#define DEBUG3(x)
123+#endif
124+
125 #if defined(QL_DEBUG_LEVEL_4)
126-#define DEBUG4(x) do {x;} while (0);
127-#else /* */
128-#define DEBUG4(x) do {} while (0);
129-#endif /* */
130+#define DEBUG4(x) do {if(extended_error_logging & 0x08) x;} while (0);
131+#else
132+#define DEBUG4(x)
133+#endif
134
135 #if defined(QL_DEBUG_LEVEL_5)
136-#define DEBUG5(x) do {x;} while (0);
137-#else /* */
138-#define DEBUG5(x) do {} while (0);
139-#endif /* */
140+#define DEBUG5(x) do {if(extended_error_logging & 0x10) x;} while (0);
141+#else
142+#define DEBUG5(x)
143+#endif
144
145 #if defined(QL_DEBUG_LEVEL_6)
146-#define DEBUG6(x) do {x;} while (0);
147-#else /* */
148-#define DEBUG6(x) do {} while (0);
149-#endif /* */
150-
151-#if defined(QL_DEBUG_LEVEL_9)
152-#define DEBUG9(x) do {x;} while (0);
153-#else /* */
154-#define DEBUG9(x) do {} while (0);
155-#endif /* */
156+#define DEBUG6(x) do {if(extended_error_logging & 0x20) x;} while (0);
157+#else
158+#define DEBUG6(x)
159+#endif
160+
161+#endif /*_QL4_DBG_*/
162--- a/drivers/scsi/qla4xxx/ql4_def.h
163+++ b/drivers/scsi/qla4xxx/ql4_def.h
164@@ -144,7 +144,6 @@
165 #define RESET_FIRMWARE_TOV 30
166 #define LOGOUT_TOV 10
167 #define IOCB_TOV_MARGIN 10
168-#define RELOGIN_TOV 18
169 #define ISNS_DEREG_TOV 5
170
171 #define MAX_RESET_HA_RETRIES 2
172@@ -252,6 +251,8 @@ struct ddb_entry {
173 #define DF_NO_RELOGIN 1 /* Do not relogin if IOCTL
174 * logged it out */
175 #define DF_SCAN_ISSUED 2
176+#define DF_OFFLINE 3 /* Offline Device */
177+#define DF_DELETED 4 /* Device has been removed */
178
179 /*
180 * Asynchronous Event Queue structure
181@@ -286,7 +287,6 @@ struct scsi_qla_host {
182 uint32_t tot_ddbs;
183 unsigned long flags;
184
185-#define AF_ISNS_CMD_DONE 13 /* 0x00002000 */
186 #define AF_ONLINE 0 /* 0x00000001 */
187 #define AF_INIT_DONE 1 /* 0x00000002 */
188 #define AF_MBOX_COMMAND 2 /* 0x00000004 */
189@@ -294,9 +294,9 @@ struct scsi_qla_host {
190 #define AF_INTERRUPTS_ON 6 /* 0x00000040 Not Used */
191 #define AF_GET_CRASH_RECORD 7 /* 0x00000080 */
192 #define AF_LINK_UP 8 /* 0x00000100 */
193-#define AF_TOPCAT_CHIP_PRESENT 9 /* 0x00000200 */
194 #define AF_IRQ_ATTACHED 10 /* 0x00000400 */
195 #define AF_DISABLE_ACB_COMPLETE 11 /* 0x00000800 */
196+#define AF_OS_INDEX_VALID 12 /* 0x00001000 */
197
198 unsigned long dpc_flags;
199
200@@ -308,6 +308,8 @@ struct scsi_qla_host {
201 #define DPC_ISNS_RESTART 7 /* 0x00000080 */
202 #define DPC_AEN 9 /* 0x00000200 */
203 #define DPC_GET_DHCP_IP_ADDR 15 /* 0x00008000 */
204+#define DPC_OFFLINE_DEVICE 16 /* 0x00010000 */
205+#define DPC_DELETE_DEVICE 17 /* 0x00020000 */
206
207 uint16_t iocb_cnt;
208 uint16_t iocb_hiwat;
209@@ -460,7 +462,7 @@ struct scsi_qla_host {
210 void (*ql4getaenlog)(struct scsi_qla_host *ha, struct ql4_aen_log *aenl);
211 #define QL_INDICES_PER_ENTRY 32
212 #define QL_OSINDEX_ENTRIES (MAX_DDB_ENTRIES/QL_INDICES_PER_ENTRY)
213- volatile uint32_t os_map[QL_OSINDEX_ENTRIES];
214+ volatile unsigned long os_map[QL_OSINDEX_ENTRIES];
215 };
216
217 static inline int is_qla4010(struct scsi_qla_host *ha)
218@@ -468,6 +470,7 @@ static inline int is_qla4010(struct scsi
219 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
220 }
221
222+
223 static inline int is_qla4022(struct scsi_qla_host *ha)
224 {
225 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
226--- a/drivers/scsi/qla4xxx/ql4_glbl.h
227+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
228@@ -10,7 +10,7 @@
229
230 struct iscsi_cls_conn;
231
232-void qla4xxx_hw_reset(struct scsi_qla_host *ha);
233+void qla4xxx_hw_reset(struct scsi_qla_host *ha, int hw_lock);
234 int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a);
235 int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
236 int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port);
237@@ -18,9 +18,9 @@ int qla4xxx_send_command_to_isp(struct s
238 int qla4xxx_initialize_adapter(struct scsi_qla_host * ha,
239 uint8_t renew_ddb_list);
240 int qla4xxx_soft_reset(struct scsi_qla_host *ha);
241-irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id);
242
243 void qla4xxx_free_ddb_list(struct scsi_qla_host * ha);
244+void qla4xxx_free_ddb(struct scsi_qla_host *, struct ddb_entry *);
245 void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen);
246
247 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha);
248@@ -47,6 +47,8 @@ int qla4xxx_get_fwddb_entry(struct scsi_
249 uint16_t *tcp_source_port_num,
250 uint16_t *connection_id);
251
252+struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host * ha,
253+ uint32_t fw_ddb_index);
254 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
255 dma_addr_t fw_ddb_entry_dma);
256
257@@ -77,10 +79,6 @@ int qla4xxx_process_ddb_changed(struct s
258
259 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
260 uint8_t outCount, uint32_t *mbx_cmd, uint32_t *mbx_sts);
261-int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
262- struct ddb_entry *ddb_entry, int lun);
263-
264-
265
266 extern int extended_error_logging;
267 extern int ql4xdiscoverywait;
268--- a/drivers/scsi/qla4xxx/ql4_init.c
269+++ b/drivers/scsi/qla4xxx/ql4_init.c
270@@ -10,6 +10,7 @@
271 #include "ql4_glbl.h"
272 #include "ql4_dbg.h"
273 #include "ql4_inline.h"
274+#include "ql4_os.h"
275
276 /* link auto negotiation normally takes roughly 2s. */
277 /* If we don't have link in 3 times that period quit. */
278@@ -19,9 +20,6 @@
279 * QLogic ISP4xxx Hardware Support Function Prototypes.
280 */
281
282-static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
283- uint32_t fw_ddb_index);
284-
285 static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
286 {
287 uint32_t value;
288@@ -52,15 +50,14 @@ static void ql4xxx_set_mac_number(struct
289 }
290
291 /**
292- * qla4xxx_free_ddb - deallocate ddb
293+ * qla4xxx_free_ddb - deallocate ddb
294 * @ha: pointer to host adapter structure.
295 * @ddb_entry: pointer to device database entry
296 *
297 * This routine deallocates and unlinks the specified ddb_entry from the
298 * adapter's
299 **/
300-static void qla4xxx_free_ddb(struct scsi_qla_host *ha,
301- struct ddb_entry *ddb_entry)
302+void qla4xxx_free_ddb(struct scsi_qla_host *ha, struct ddb_entry *ddb_entry)
303 {
304 /* Remove device entry from list */
305 list_del_init(&ddb_entry->list);
306@@ -359,8 +356,8 @@ static void qla4xxx_fill_ddb(struct ddb_
307 * This routine allocates a ddb_entry, ititializes some values, and
308 * inserts it into the ddb list.
309 **/
310-static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
311- uint32_t fw_ddb_index)
312+struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
313+ uint32_t fw_ddb_index)
314 {
315 struct ddb_entry *ddb_entry;
316
317@@ -478,7 +475,7 @@ static int qla4xxx_build_ddb_list(struct
318 (strlen(fw_ddb_entry->iscsi_name) != 0)){
319 ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
320 if (ddb_entry == NULL) {
321- DEBUG2(dev_info(&ha->pdev->dev,"%s alloc_ddb %d "
322+ DEBUG2(dev_info(&ha->pdev->dev,"%s alloc_ddb %d"
323 "failed\n", __func__, fw_ddb_index));
324 goto exit_ddb_list;
325 }
326@@ -488,7 +485,7 @@ static int qla4xxx_build_ddb_list(struct
327 ddb_entry->connection_id = conn_id;
328 qla4xxx_fill_ddb(ddb_entry, fw_ddb_entry);
329 ddb_entry->fw_ddb_device_state = ddb_state;
330-
331+
332 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
333 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
334 dev_info(&ha->pdev->dev,
335@@ -695,6 +692,8 @@ static int qla4xxx_initialize_ddb_list(s
336
337 qla4xxx_flush_AENS(ha);
338
339+ /* Wait for an AEN */
340+ qla4xxx_devices_ready(ha);
341
342 /*
343 * First perform device discovery for active
344@@ -704,9 +703,6 @@ static int qla4xxx_initialize_ddb_list(s
345 if ((status = qla4xxx_build_ddb_list(ha)) == QLA_ERROR)
346 return status;
347
348- /* Wait for an AEN */
349- qla4xxx_devices_ready(ha);
350-
351 /*
352 * Targets can come online after the inital discovery, so processing
353 * the aens here will catch them.
354@@ -747,13 +743,15 @@ int qla4xxx_reinitialize_ddb_list(struct
355
356 qla4xxx_fill_ddb(ddb_entry, fw_ddb_entry);
357
358- if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
359+ if (ddb_entry->fw_ddb_device_state ==
360+ DDB_DS_SESSION_ACTIVE) {
361 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
362 dev_info(&ha->pdev->dev,
363- "scsi%ld: %s: ddb[%d] os[%d] marked ONLINE\n",
364- ha->host_no, __func__, ddb_entry->fw_ddb_index,
365+ "%s: ddb[%d] os[%d] marked ONLINE\n",
366+ __func__, ddb_entry->fw_ddb_index,
367 ddb_entry->os_target_id);
368- } else if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
369+ } else if (atomic_read(&ddb_entry->state) ==
370+ DDB_STATE_ONLINE)
371 qla4xxx_mark_device_missing(ha, ddb_entry);
372 }
373 }
374@@ -884,8 +882,8 @@ static int qla4xxx_start_firmware_from_f
375 writel(set_rmask(NVR_WRITE_ENABLE),
376 &ha->reg->u1.isp4022.nvram);
377
378- writel(2, &ha->reg->mailbox[6]);
379- readl(&ha->reg->mailbox[6]);
380+ writel(2, &ha->reg->mailbox[6]);
381+ readl(&ha->reg->mailbox[6]);
382
383 writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status);
384 readl(&ha->reg->ctrl_status);
385@@ -1054,7 +1052,7 @@ static int qla4xxx_start_firmware(struct
386 }
387 config_chip = 1;
388
389- /* Reset clears the semaphore, so acquire again */
390+ /* Reset clears the semaphore, so aquire again */
391 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
392 return QLA_ERROR;
393 }
394@@ -1083,7 +1081,7 @@ static int qla4xxx_start_firmware(struct
395 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
396 * after adapter recovery has completed.
397 * 0=preserve ddb list, 1=destroy and rebuild ddb list
398- *
399+ *
400 * This routine parforms all of the steps necessary to initialize the adapter.
401 *
402 **/
403@@ -1119,12 +1117,12 @@ int qla4xxx_initialize_adapter(struct sc
404 * followed by 0x8014 aen" to trigger the tgt discovery process.
405 */
406 if (ha->firmware_state & FW_STATE_DHCP_IN_PROGRESS)
407- goto exit_init_online;
408+ goto exit_init_hba0;
409
410 /* Skip device discovery if ip and subnet is zero */
411 if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 ||
412 memcmp(ha->subnet_mask, ip_address, IP_ADDR_LEN) == 0)
413- goto exit_init_online;
414+ goto exit_init_hba0;
415
416 if (renew_ddb_list == PRESERVE_DDB_LIST) {
417 /*
418@@ -1153,8 +1151,10 @@ int qla4xxx_initialize_adapter(struct sc
419 ha->host_no));
420 }
421
422-exit_init_online:
423+exit_init_hba0:
424 set_bit(AF_ONLINE, &ha->flags);
425+ dev_info(&ha->pdev->dev, "%s: adapter ONLINE\n", __func__);
426+
427 exit_init_hba:
428 return status;
429 }
430@@ -1204,40 +1204,63 @@ static void qla4xxx_add_device_dynamical
431 }
432 }
433
434- if (!found)
435- ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
436- else if (ddb_entry->fw_ddb_index != fw_ddb_index) {
437- /* Target has been bound to a new fw_ddb_index */
438- qla4xxx_free_ddb(ha, ddb_entry);
439+ if (!found) {
440 ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
441- }
442
443- if (ddb_entry == NULL) {
444- DEBUG2(dev_info(&ha->pdev->dev, "%s NULL DDB %d\n",
445- __func__, fw_ddb_index));
446- goto exit_dyn_add;
447- }
448+ if (ddb_entry == NULL) {
449+ DEBUG2(dev_info(&ha->pdev->dev, "%s NULL DDB %d\n",
450+ __func__, fw_ddb_index));
451+ goto exit_dyn_add;
452+ }
453
454- ddb_entry->fw_ddb_index = fw_ddb_index;
455- ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
456- ddb_entry->tcp_source_port_num = src_port;
457- ddb_entry->connection_id = conn_id;
458- qla4xxx_fill_ddb(ddb_entry, fw_ddb_entry);
459- ddb_entry->fw_ddb_device_state = ddb_state;
460+ ddb_entry->fw_ddb_index = fw_ddb_index;
461+ ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
462+ ddb_entry->tcp_source_port_num = src_port;
463+ ddb_entry->connection_id = conn_id;
464+ qla4xxx_fill_ddb(ddb_entry, fw_ddb_entry);
465+ ddb_entry->fw_ddb_device_state = ddb_state;
466+
467+ if (probe)
468+ goto exit_dyn_add;
469
470- if (!probe) {
471 if (qla4xxx_add_sess(ddb_entry, 1)) {
472- DEBUG2(printk(KERN_WARNING
473- "scsi%ld: failed to add new device at index "
474- "[%d]\n Unable to add connection and session\n",
475- ha->host_no, fw_ddb_index));
476+ DEBUG2(dev_info(&ha->pdev->dev,
477+ "%s: failed to add new ddb %d\n",
478+ __func__, fw_ddb_index));
479 qla4xxx_free_ddb(ha, ddb_entry);
480+ } else {
481+ DEBUG6(dev_info(&ha->pdev->dev,
482+ "%s added ddb 0x%p sess 0x%p"
483+ " conn 0x%p state 0x%x\n",
484+ __func__, ddb_entry,
485+ ddb_entry->sess, ddb_entry->conn,
486+ ddb_entry->state));
487 }
488- }
489+ } else if (ddb_entry->fw_ddb_index != fw_ddb_index) {
490+ /* Target has been bound to a new fw_ddb_index */
491+ ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = NULL;
492+ ddb_entry->fw_ddb_index = fw_ddb_index;
493+ ddb_entry->fw_ddb_device_state = ddb_state;
494+ ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
495+ atomic_set(&ddb_entry->port_down_timer,
496+ ha->port_down_retry_count);
497+ atomic_set(&ddb_entry->relogin_retry_count, 0);
498+ atomic_set(&ddb_entry->relogin_timer, 0);
499+ clear_bit(DF_RELOGIN, &ddb_entry->flags);
500+ clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
501+ atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
502
503- DEBUG6(dev_info(&ha->pdev->dev, "%s added ddb 0x%p sess 0x%p conn 0x%p"
504- " state 0x%x\n", __func__, ddb_entry, ddb_entry->sess,
505- ddb_entry->conn, ddb_entry->state));
506+ dev_info(&ha->pdev->dev,
507+ "scsi%ld: %s: ddb[%d] os[%d] marked ONLINE sess:%p conn:%p\n",
508+ ha->host_no, __func__, ddb_entry->fw_ddb_index,
509+ ddb_entry->os_target_id, ddb_entry->sess, ddb_entry->conn);
510+
511+ if (!probe)
512+ qla4xxx_conn_start(ddb_entry->conn);
513+ DEBUG6(dev_info(&ha->pdev->dev, "%s calling conn_start ddb 0x%p sess 0x%p"
514+ " conn 0x%p state 0x%x\n", __func__, ddb_entry, ddb_entry->sess,
515+ ddb_entry->conn, ddb_entry->state));
516+ }
517 exit_dyn_add:
518 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
519 fw_ddb_entry_dma);
520@@ -1272,15 +1295,15 @@ int qla4xxx_process_ddb_changed(struct s
521 qla4xxx_add_device_dynamically(ha, fw_ddb_index, probe);
522 return QLA_SUCCESS;
523 }
524- DEBUG6(dev_info(&ha->pdev->dev, "%s ddb_entry 0x%p ostate 0x%x"
525- " sess 0x%p conn 0x%p\n", __func__, ddb_entry,
526- ddb_entry->state, ddb_entry->sess, ddb_entry->conn));
527+ DEBUG6(dev_info(&ha->pdev->dev, "%s ddb[%d] os[%d] ostate 0x%x"
528+ " sess 0x%p conn 0x%p o_fwstate 0x%x n_fwstate ox%x \n",
529+ __func__, ddb_entry->fw_ddb_index, ddb_entry->os_target_id,
530+ ddb_entry->state, ddb_entry->sess, ddb_entry->conn,
531+ ddb_entry->fw_ddb_device_state, state));
532
533 /* Device already exists in our database. */
534 old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
535- DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
536- "index [%d]\n", ha->host_no, __func__,
537- ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
538+
539 if (old_fw_ddb_device_state == state &&
540 state == DDB_DS_SESSION_ACTIVE) {
541 /* Do nothing, state not changed. */
542@@ -1297,26 +1320,33 @@ int qla4xxx_process_ddb_changed(struct s
543 atomic_set(&ddb_entry->port_down_timer,
544 ha->port_down_retry_count);
545 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
546+ dev_info(&ha->pdev->dev,
547+ "%s: ddb[%d] os[%d] marked ONLINE\n",
548+ __func__, ddb_entry->fw_ddb_index,
549+ ddb_entry->os_target_id);
550+
551 atomic_set(&ddb_entry->relogin_retry_count, 0);
552 atomic_set(&ddb_entry->relogin_timer, 0);
553 clear_bit(DF_RELOGIN, &ddb_entry->flags);
554 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
555
556- DEBUG6(dev_info(&ha->pdev->dev, "%s conn startddb_entry 0x%p"
557- " sess 0x%p conn 0x%p\n",
558- __func__, ddb_entry, ddb_entry->sess, ddb_entry->conn));
559-
560- qla4xxx_conn_start(ddb_entry->conn);
561-
562- DEBUG6(dev_info(&ha->pdev->dev, "%s conn start done "
563- "ddb_entry 0x%p sess 0x%p conn 0x%p\n",
564- __func__, ddb_entry, ddb_entry->sess, ddb_entry->conn));
565-
566- if (!test_bit(DF_SCAN_ISSUED, &ddb_entry->flags)) {
567- scsi_scan_target(&ddb_entry->sess->dev, 0,
568- ddb_entry->sess->target_id,
569- SCAN_WILD_CARD, 0);
570- set_bit(DF_SCAN_ISSUED, &ddb_entry->flags);
571+ if (ddb_entry->conn) {
572+ DEBUG6(dev_info(&ha->pdev->dev,
573+ "%s conn startddb_entry 0x%p"
574+ " sess 0x%p conn 0x%p\n",
575+ __func__,
576+ ddb_entry, ddb_entry->sess, ddb_entry->conn));
577+
578+ qla4xxx_conn_start(ddb_entry->conn);
579+
580+ DEBUG6(dev_info(&ha->pdev->dev, "%s conn start done "
581+ "ddb_entry 0x%p sess 0x%p conn 0x%p\n",
582+ __func__, ddb_entry, ddb_entry->sess, ddb_entry->conn));
583+
584+ if (!test_bit(DF_SCAN_ISSUED, &ddb_entry->flags)) {
585+ qla4xxx_scan_target(ddb_entry);
586+ set_bit(DF_SCAN_ISSUED, &ddb_entry->flags);
587+ }
588 }
589 } else {
590 /* Device went away, try to relogin. */
591--- a/drivers/scsi/qla4xxx/ql4_inline.h
592+++ b/drivers/scsi/qla4xxx/ql4_inline.h
593@@ -34,6 +34,34 @@ qla4xxx_lookup_ddb_by_fw_index(struct sc
594 return ddb_entry;
595 }
596
597+/*
598+ * The MBOX_CMD_CLEAR_DATABASE_ENTRY (0x31) mailbox command does not
599+ * result in an AEN, so we need to process it seperately.
600+ */
601+static inline void qla4xxx_check_for_clear_ddb(struct scsi_qla_host *ha,
602+ uint32_t *mbox_cmd)
603+{
604+ uint32_t fw_ddb_index;
605+ struct ddb_entry *ddb_entry = NULL;
606+
607+ if (mbox_cmd[0] == MBOX_CMD_CLEAR_DATABASE_ENTRY) {
608+
609+ fw_ddb_index = mbox_cmd[1];
610+
611+ if (fw_ddb_index < MAX_DDB_ENTRIES)
612+ ddb_entry = ha->fw_ddb_index_map[fw_ddb_index];
613+
614+ if (ddb_entry) {
615+ dev_info(&ha->pdev->dev, "%s: ddb[%d] os[%d] freed\n",
616+ __func__, ddb_entry->fw_ddb_index,
617+ ddb_entry->os_target_id);
618+ set_bit(DF_DELETED, &ddb_entry->flags);
619+ set_bit(DPC_DELETE_DEVICE, &ha->dpc_flags);
620+ queue_work(ha->dpc_thread, &ha->dpc_work);
621+ }
622+ }
623+}
624+
625 static inline void
626 __qla4xxx_enable_intrs(struct scsi_qla_host *ha)
627 {
628@@ -81,3 +109,118 @@ qla4xxx_disable_intrs(struct scsi_qla_ho
629 __qla4xxx_disable_intrs(ha);
630 spin_unlock_irqrestore(&ha->hardware_lock, flags);
631 }
632+
633+static inline int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
634+ struct queue_entry **queue_entry)
635+{
636+ uint16_t request_in;
637+ uint8_t status = QLA_SUCCESS;
638+
639+ *queue_entry = ha->request_ptr;
640+
641+ /* get the latest request_in and request_out index */
642+ request_in = ha->request_in;
643+ ha->request_out = (uint16_t) le32_to_cpu(ha->shadow_regs->req_q_out);
644+
645+ /* Advance request queue pointer and check for queue full */
646+ if (request_in == (REQUEST_QUEUE_DEPTH - 1)) {
647+ request_in = 0;
648+ ha->request_ptr = ha->request_ring;
649+ } else {
650+ request_in++;
651+ ha->request_ptr++;
652+ }
653+
654+ /* request queue is full, try again later */
655+ if ((ha->iocb_cnt + 1) >= ha->iocb_hiwat) {
656+ /* restore request pointer */
657+ ha->request_ptr = *queue_entry;
658+ status = QLA_ERROR;
659+ } else {
660+ ha->request_in = request_in;
661+ memset(*queue_entry, 0, sizeof(**queue_entry));
662+ }
663+
664+ return status;
665+}
666+
667+/**
668+ * qla4xxx_send_marker_iocb - issues marker iocb to HBA
669+ * @ha: Pointer to host adapter structure.
670+ * @ddb_entry: Pointer to device database entry
671+ * @lun: SCSI LUN
672+ * @marker_type: marker identifier
673+ *
674+ * This routine issues a marker IOCB.
675+ **/
676+static inline int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
677+ struct ddb_entry *ddb_entry, int lun)
678+{
679+ struct marker_entry *marker_entry;
680+ unsigned long flags = 0;
681+ uint8_t status = QLA_SUCCESS;
682+
683+ /* Acquire hardware specific lock */
684+ spin_lock_irqsave(&ha->hardware_lock, flags);
685+
686+ /* Get pointer to the queue entry for the marker */
687+ if (qla4xxx_get_req_pkt(ha, (struct queue_entry **) &marker_entry) !=
688+ QLA_SUCCESS) {
689+ status = QLA_ERROR;
690+ goto exit_send_marker;
691+ }
692+
693+ /* Put the marker in the request queue */
694+ marker_entry->hdr.entryType = ET_MARKER;
695+ marker_entry->hdr.entryCount = 1;
696+ marker_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
697+ marker_entry->modifier = cpu_to_le16(MM_LUN_RESET);
698+ int_to_scsilun(lun, &marker_entry->lun);
699+ wmb();
700+
701+ /* Tell ISP it's got a new I/O request */
702+ writel(ha->request_in, &ha->reg->req_q_in);
703+ readl(&ha->reg->req_q_in);
704+
705+exit_send_marker:
706+ spin_unlock_irqrestore(&ha->hardware_lock, flags);
707+ return status;
708+}
709+
710+static inline struct continuation_t1_entry* qla4xxx_alloc_cont_entry(
711+ struct scsi_qla_host *ha)
712+{
713+ struct continuation_t1_entry *cont_entry;
714+
715+ cont_entry = (struct continuation_t1_entry *)ha->request_ptr;
716+
717+ /* Advance request queue pointer */
718+ if (ha->request_in == (REQUEST_QUEUE_DEPTH - 1)) {
719+ ha->request_in = 0;
720+ ha->request_ptr = ha->request_ring;
721+ } else {
722+ ha->request_in++;
723+ ha->request_ptr++;
724+ }
725+
726+ /* Load packet defaults */
727+ cont_entry->hdr.entryType = ET_CONTINUE;
728+ cont_entry->hdr.entryCount = 1;
729+ cont_entry->hdr.systemDefined = (uint8_t) cpu_to_le16(ha->request_in);
730+
731+ return cont_entry;
732+}
733+
734+static inline uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
735+{
736+ uint16_t iocbs;
737+
738+ iocbs = 1;
739+ if (dsds > COMMAND_SEG) {
740+ iocbs += (dsds - COMMAND_SEG) / CONTINUE_SEG;
741+ if ((dsds - COMMAND_SEG) % CONTINUE_SEG)
742+ iocbs++;
743+ }
744+ return iocbs;
745+}
746+
747--- a/drivers/scsi/qla4xxx/ql4_iocb.c
748+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
749@@ -11,133 +11,8 @@
750 #include "ql4_dbg.h"
751 #include "ql4_inline.h"
752
753-#define VMWARE_CMD_TIMEOUT 30
754 #include <scsi/scsi_tcq.h>
755
756-/**
757- * qla4xxx_get_req_pkt - returns a valid entry in request queue.
758- * @ha: Pointer to host adapter structure.
759- * @queue_entry: Pointer to pointer to queue entry structure
760- *
761- * This routine performs the following tasks:
762- * - returns the current request_in pointer (if queue not full)
763- * - advances the request_in pointer
764- * - checks for queue full
765- **/
766-static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
767- struct queue_entry **queue_entry)
768-{
769- uint16_t request_in;
770- uint8_t status = QLA_SUCCESS;
771-
772- *queue_entry = ha->request_ptr;
773-
774- /* get the latest request_in and request_out index */
775- request_in = ha->request_in;
776- ha->request_out = (uint16_t) le32_to_cpu(ha->shadow_regs->req_q_out);
777-
778- /* Advance request queue pointer and check for queue full */
779- if (request_in == (REQUEST_QUEUE_DEPTH - 1)) {
780- request_in = 0;
781- ha->request_ptr = ha->request_ring;
782- } else {
783- request_in++;
784- ha->request_ptr++;
785- }
786-
787- /* request queue is full, try again later */
788- if ((ha->iocb_cnt + 1) >= ha->iocb_hiwat) {
789- /* restore request pointer */
790- ha->request_ptr = *queue_entry;
791- status = QLA_ERROR;
792- } else {
793- ha->request_in = request_in;
794- memset(*queue_entry, 0, sizeof(**queue_entry));
795- }
796-
797- return status;
798-}
799-
800-/**
801- * qla4xxx_send_marker_iocb - issues marker iocb to HBA
802- * @ha: Pointer to host adapter structure.
803- * @ddb_entry: Pointer to device database entry
804- * @lun: SCSI LUN
805- * @marker_type: marker identifier
806- *
807- * This routine issues a marker IOCB.
808- **/
809-int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
810- struct ddb_entry *ddb_entry, int lun)
811-{
812- struct marker_entry *marker_entry;
813- unsigned long flags = 0;
814- uint8_t status = QLA_SUCCESS;
815-
816- /* Acquire hardware specific lock */
817- spin_lock_irqsave(&ha->hardware_lock, flags);
818-
819- /* Get pointer to the queue entry for the marker */
820- if (qla4xxx_get_req_pkt(ha, (struct queue_entry **) &marker_entry) !=
821- QLA_SUCCESS) {
822- status = QLA_ERROR;
823- goto exit_send_marker;
824- }
825-
826- /* Put the marker in the request queue */
827- marker_entry->hdr.entryType = ET_MARKER;
828- marker_entry->hdr.entryCount = 1;
829- marker_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
830- marker_entry->modifier = cpu_to_le16(MM_LUN_RESET);
831- int_to_scsilun(lun, &marker_entry->lun);
832- wmb();
833-
834- /* Tell ISP it's got a new I/O request */
835- writel(ha->request_in, &ha->reg->req_q_in);
836- readl(&ha->reg->req_q_in);
837-
838-exit_send_marker:
839- spin_unlock_irqrestore(&ha->hardware_lock, flags);
840- return status;
841-}
842-
843-static struct continuation_t1_entry* qla4xxx_alloc_cont_entry(
844- struct scsi_qla_host *ha)
845-{
846- struct continuation_t1_entry *cont_entry;
847-
848- cont_entry = (struct continuation_t1_entry *)ha->request_ptr;
849-
850- /* Advance request queue pointer */
851- if (ha->request_in == (REQUEST_QUEUE_DEPTH - 1)) {
852- ha->request_in = 0;
853- ha->request_ptr = ha->request_ring;
854- } else {
855- ha->request_in++;
856- ha->request_ptr++;
857- }
858-
859- /* Load packet defaults */
860- cont_entry->hdr.entryType = ET_CONTINUE;
861- cont_entry->hdr.entryCount = 1;
862- cont_entry->hdr.systemDefined = (uint8_t) cpu_to_le16(ha->request_in);
863-
864- return cont_entry;
865-}
866-
867-static uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
868-{
869- uint16_t iocbs;
870-
871- iocbs = 1;
872- if (dsds > COMMAND_SEG) {
873- iocbs += (dsds - COMMAND_SEG) / CONTINUE_SEG;
874- if ((dsds - COMMAND_SEG) % CONTINUE_SEG)
875- iocbs++;
876- }
877- return iocbs;
878-}
879-
880 static void qla4xxx_build_scsi_iocbs(struct srb *srb,
881 struct command_t3_entry *cmd_entry,
882 uint16_t tot_dsds)
883@@ -224,6 +99,7 @@ int qla4xxx_send_command_to_isp(struct s
884 /* Acquire hardware specific lock */
885 spin_lock_irqsave(&ha->hardware_lock, flags);
886
887+ //index = (uint32_t)cmd->request->tag;
888 index = ha->current_active_index;
889 for (i = 0; i < MAX_SRBS; i++) {
890 index++;
891@@ -242,10 +118,14 @@ int qla4xxx_send_command_to_isp(struct s
892 }
893
894 /* Calculate the number of request entries needed. */
895- nseg = scsi_dma_map(cmd);
896- if (nseg < 0)
897- goto queuing_error;
898- tot_dsds = nseg;
899+ if (srb->flags & SRB_SCSI_PASSTHRU)
900+ tot_dsds = 1;
901+ else {
902+ nseg = scsi_dma_map(cmd);
903+ if (nseg < 0)
904+ goto queuing_error;
905+ tot_dsds = nseg;
906+ }
907
908 req_cnt = qla4xxx_calc_request_entries(tot_dsds);
909
910@@ -281,9 +161,9 @@ int qla4xxx_send_command_to_isp(struct s
911 cmd_entry->hdr.entryCount = req_cnt;
912
913 /* Set data transfer direction control flags
914- * NOTE: Look at data_direction bits iff there is data to be
915- * transferred, as the data direction bit is sometimed filled
916- * in when there is no data to be transferred */
917+ * NOTE: Look at data_direction bits iff there is data to be
918+ * transferred, as the data direction bit is sometimed filled
919+ * in when there is no data to be transferred */
920 cmd_entry->control_flags = CF_NO_DATA;
921 if (scsi_bufflen(cmd)) {
922 if (cmd->sc_data_direction == DMA_TO_DEVICE)
923@@ -324,10 +204,10 @@ int qla4xxx_send_command_to_isp(struct s
924
925 /*
926 * Check to see if adapter is online before placing request on
927- * request queue. If a reset occurs and a request is in the queue,
928- * the firmware will still attempt to process the request, retrieving
929- * garbage for pointers.
930- */
931+ * request queue. If a reset occurs and a request is in the queue,
932+ * the firmware will still attempt to process the request, retrieving
933+ * garbage for pointers.
934+ */
935 if (!test_bit(AF_ONLINE, &ha->flags)) {
936 DEBUG2(printk("scsi%ld: %s: Adapter OFFLINE! "
937 "Do not issue command.\n",
938@@ -355,13 +235,12 @@ int qla4xxx_send_command_to_isp(struct s
939 return QLA_SUCCESS;
940
941 queuing_error:
942- if (srb->flags & SRB_SCSI_PASSTHRU)
943- return QLA_ERROR;
944-
945- if (tot_dsds)
946- scsi_dma_unmap(cmd);
947+ if (!(srb->flags & SRB_SCSI_PASSTHRU))
948+ if (tot_dsds)
949+ scsi_dma_unmap(cmd);
950
951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
952
953 return QLA_ERROR;
954 }
955+
956--- a/drivers/scsi/qla4xxx/ql4_isr.c
957+++ b/drivers/scsi/qla4xxx/ql4_isr.c
958@@ -10,6 +10,7 @@
959 #include "ql4_glbl.h"
960 #include "ql4_dbg.h"
961 #include "ql4_inline.h"
962+#include "ql4_os.h"
963
964 /**
965 * qla4xxx_status_entry - processes status IOCBs
966@@ -59,8 +60,8 @@ static void qla4xxx_status_entry(struct
967 break;
968 }
969 if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) {
970- scsi_set_resid(cmd, residual);
971- if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
972+ QL_SET_SCSI_RESID(cmd, residual);
973+ if (!scsi_status && ((QL_SCSI_BUFFLEN(cmd) - residual) <
974 cmd->underflow)) {
975 cmd->result = DID_ERROR << 16;
976 break;
977@@ -144,7 +145,7 @@ static void qla4xxx_status_entry(struct
978 break;
979 }
980
981- scsi_set_resid(cmd, residual);
982+ QL_SET_SCSI_RESID(cmd, residual);
983
984 /*
985 * If there is scsi_status, it takes precedense over
986@@ -184,7 +185,7 @@ static void qla4xxx_status_entry(struct
987 if ((sts_entry->iscsiFlags &
988 ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
989 cmd->result = DID_BUS_BUSY << 16;
990- } else if ((scsi_bufflen(cmd) - residual) <
991+ } else if ((QL_SCSI_BUFFLEN(cmd) - residual) <
992 cmd->underflow) {
993 /*
994 * Handle mid-layer underflow???
995@@ -203,7 +204,7 @@ static void qla4xxx_status_entry(struct
996 "resid = 0x%x, compstat = 0x%x\n",
997 ha->host_no, cmd->device->channel,
998 cmd->device->id, cmd->device->lun,
999- __func__, scsi_bufflen(cmd),
1000+ __func__, QL_SCSI_BUFFLEN(cmd),
1001 residual,
1002 sts_entry->completionStatus));
1003
1004@@ -396,13 +397,13 @@ static void qla4xxx_isr_decode_mailbox(s
1005 /* Immediately process the AENs that don't require much work.
1006 * Only queue the database_changed AENs */
1007
1008- dev_info(&ha->pdev->dev, "%s mbx0 0x%08x mbx1 0x%08x"
1009+ DEBUG6(dev_info(&ha->pdev->dev, "%s mbx0 0x%08x mbx1 0x%08x"
1010 " mbx2 0x%08x mbx3 0x%08x mbx4 0x%08x mbx5 0x%08x "
1011 "mbx6 0x%08x mbx7 0x%08x\n", __func__,
1012 readl(&ha->reg->mailbox[0]), readl(&ha->reg->mailbox[1]),
1013 readl(&ha->reg->mailbox[2]), readl(&ha->reg->mailbox[3]),
1014 readl(&ha->reg->mailbox[4]), readl(&ha->reg->mailbox[5]),
1015- readl(&ha->reg->mailbox[6]), readl(&ha->reg->mailbox[7]));
1016+ readl(&ha->reg->mailbox[6]), readl(&ha->reg->mailbox[7])));
1017
1018 if (ha->aen_log.count < MAX_AEN_ENTRIES) {
1019 for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
1020@@ -412,11 +413,13 @@ static void qla4xxx_isr_decode_mailbox(s
1021 }
1022 switch (mbox_status) {
1023 case MBOX_ASTS_SYSTEM_ERROR:
1024+ dev_info(&ha->pdev->dev, "%s: System Err\n", __func__);
1025 /* Log Mailbox registers */
1026 if (ql4xdontresethba) {
1027 DEBUG2(printk("%s:Dont Reset HBA\n",
1028 __func__));
1029 } else {
1030+ qla4xxx_hw_reset(ha, 0);
1031 set_bit(AF_GET_CRASH_RECORD, &ha->flags);
1032 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1033 }
1034@@ -433,15 +436,13 @@ static void qla4xxx_isr_decode_mailbox(s
1035 break;
1036
1037 case MBOX_ASTS_LINK_UP:
1038- DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK UP\n",
1039- ha->host_no, mbox_status));
1040 set_bit(AF_LINK_UP, &ha->flags);
1041+ dev_info(&ha->pdev->dev, "%s: LINK UP\n", __func__);
1042 break;
1043
1044 case MBOX_ASTS_LINK_DOWN:
1045- DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK DOWN\n",
1046- ha->host_no, mbox_status));
1047 clear_bit(AF_LINK_UP, &ha->flags);
1048+ dev_info(&ha->pdev->dev, "%s: LINK DOWN\n", __func__);
1049 break;
1050
1051 case MBOX_ASTS_HEARTBEAT:
1052@@ -470,9 +471,9 @@ static void qla4xxx_isr_decode_mailbox(s
1053 mbox_stat2 = readl(&ha->reg->mailbox[2]);
1054 mbox_stat3 = readl(&ha->reg->mailbox[3]);
1055
1056- if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
1057+ if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
1058 set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
1059- else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
1060+ else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
1061 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1062 break;
1063
1064@@ -591,10 +592,10 @@ void qla4xxx_interrupt_service_routine(s
1065 * qla4xxx_intr_handler - hardware interrupt handler.
1066 * @irq: Unused
1067 * @dev_id: Pointer to host adapter structure
1068+ * @regs: Unused
1069 **/
1070-irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
1071+QL_DECLARE_INTR_HANDLER(qla4xxx_intr_handler, irq, dev_id, regs)
1072 {
1073-
1074 struct scsi_qla_host *ha;
1075 uint32_t intr_status;
1076 unsigned long flags = 0;
1077@@ -625,8 +626,7 @@ irqreturn_t qla4xxx_intr_handler(int irq
1078 intr_status = readl(&ha->reg->ctrl_status);
1079
1080 if ((intr_status &
1081- (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) ==
1082- 0) {
1083+ (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
1084 if (reqs_count == 0)
1085 ha->spurious_int_count++;
1086 break;
1087@@ -662,6 +662,8 @@ irqreturn_t qla4xxx_intr_handler(int irq
1088 break;
1089 } else if (intr_status & CSR_SCSI_RESET_INTR) {
1090 clear_bit(AF_ONLINE, &ha->flags);
1091+ dev_info(&ha->pdev->dev,"%s: adapter OFFLINE\n",
1092+ __func__);
1093 __qla4xxx_disable_intrs(ha);
1094
1095 writel(set_rmask(CSR_SCSI_RESET_INTR),
1096--- a/drivers/scsi/qla4xxx/ql4_mbx.c
1097+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
1098@@ -10,6 +10,7 @@
1099 #include "ql4_glbl.h"
1100 #include "ql4_dbg.h"
1101 #include "ql4_inline.h"
1102+#include "ql4_os.h"
1103
1104
1105 /**
1106@@ -43,6 +44,7 @@ int qla4xxx_mailbox_command(struct scsi_
1107
1108 /* Mailbox code active */
1109 wait_count = MBOX_TOV * 100;
1110+
1111 while (wait_count--) {
1112 mutex_lock(&ha->mbox_sem);
1113 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
1114@@ -166,6 +168,8 @@ int qla4xxx_mailbox_command(struct scsi_
1115 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1116
1117 mbox_exit:
1118+ if (status == QLA_SUCCESS)
1119+ qla4xxx_check_for_clear_ddb(ha, mbx_cmd);
1120 mutex_lock(&ha->mbox_sem);
1121 clear_bit(AF_MBOX_COMMAND, &ha->flags);
1122 mutex_unlock(&ha->mbox_sem);
1123@@ -851,8 +855,8 @@ int qla4xxx_get_flash(struct scsi_qla_ho
1124 * qla4xxx_get_fw_version - gets firmware version
1125 * @ha: Pointer to host adapter structure.
1126 *
1127- * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1128- * hold an address for data. Make sure that we write 0 to those mailboxes,
1129+ * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1130+ * hold an address for data. Make sure that we write 0 to those mailboxes,
1131 * if unused.
1132 **/
1133 int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1134@@ -882,8 +886,7 @@ int qla4xxx_get_fw_version(struct scsi_q
1135 return QLA_SUCCESS;
1136 }
1137
1138-static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1139- dma_addr_t dma_addr)
1140+int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, dma_addr_t dma_addr)
1141 {
1142 uint32_t mbox_cmd[MBOX_REG_COUNT];
1143 uint32_t mbox_sts[MBOX_REG_COUNT];
1144--- a/drivers/scsi/qla4xxx/ql4_os.c
1145+++ b/drivers/scsi/qla4xxx/ql4_os.c
1146@@ -15,6 +15,8 @@
1147 #include "ql4_glbl.h"
1148 #include "ql4_dbg.h"
1149 #include "ql4_inline.h"
1150+#include "ql4_os.h"
1151+
1152
1153 /*
1154 * Driver version
1155@@ -56,24 +58,32 @@ MODULE_PARM_DESC(extended_error_logging,
1156 "Option to enable extended error logging, "
1157 "Default is 0 - no logging, 1 - debug logging");
1158
1159+/* Command Timeout before ddb state goes to MISSING */
1160+int cmd_timeout = IOCB_CMD_TIMEOUT;
1161+module_param(cmd_timeout, int, S_IRUGO | S_IRUSR);
1162+MODULE_PARM_DESC(cmd_timeout, "Command Timeout");
1163+
1164+/* Timeout before ddb state MISSING goes DEAD */
1165+int recovery_tmo = RECOVERY_TIMEOUT;
1166+module_param(recovery_tmo, int, S_IRUGO | S_IRUSR);
1167+MODULE_PARM_DESC(recovery_tmo, "Recovery Timeout");
1168+
1169 int ql4_mod_unload = 0;
1170 /*
1171 * SCSI host template entry points
1172 */
1173-static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
1174+
1175+void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
1176
1177 /*
1178 * iSCSI template entry points
1179 */
1180-static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
1181- enum iscsi_tgt_dscvr type, uint32_t enable,
1182- struct sockaddr *dst_addr);
1183+static int qla4xxx_host_get_param(struct Scsi_Host *,
1184+ enum iscsi_host_param, char *);
1185 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
1186 enum iscsi_param param, char *buf);
1187 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
1188 enum iscsi_param param, char *buf);
1189-static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1190- enum iscsi_host_param param, char *buf);
1191 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
1192
1193 /*
1194@@ -85,11 +95,13 @@ static int qla4xxx_eh_device_reset(struc
1195 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
1196 static int qla4xxx_slave_alloc(struct scsi_device *device);
1197 static int qla4xxx_slave_configure(struct scsi_device *device);
1198+static void qla4xxx_slave_destroy(struct scsi_device *device);
1199
1200 static struct scsi_host_template qla4xxx_driver_template = {
1201 .module = THIS_MODULE,
1202 .name = DRIVER_NAME,
1203 .proc_name = DRIVER_NAME,
1204+ .proc_info = qla4xxx_proc_info,
1205 .queuecommand = qla4xxx_queuecommand,
1206
1207 .eh_device_reset_handler = qla4xxx_eh_device_reset,
1208@@ -97,6 +109,7 @@ static struct scsi_host_template qla4xxx
1209
1210 .slave_configure = qla4xxx_slave_configure,
1211 .slave_alloc = qla4xxx_slave_alloc,
1212+ .slave_destroy = qla4xxx_slave_destroy,
1213
1214 .this_id = -1,
1215 .cmd_per_lun = 3,
1216@@ -113,10 +126,13 @@ static struct iscsi_transport qla4xxx_is
1217 ISCSI_CONN_ADDRESS |
1218 ISCSI_TARGET_NAME |
1219 ISCSI_TPGT,
1220- .tgt_dscvr = qla4xxx_tgt_dscvr,
1221+
1222+ QL_INIT_SESSION_DATASIZE(sessiondata_size)
1223+ QL_INIT_HOST_TEMPLATE(host_template)
1224+
1225+ .get_host_param = qla4xxx_host_get_param,
1226 .get_conn_param = qla4xxx_conn_get_param,
1227 .get_session_param = qla4xxx_sess_get_param,
1228- .get_host_param = qla4xxx_host_get_param,
1229 .session_recovery_timedout = qla4xxx_recovery_timedout,
1230 };
1231
1232@@ -134,31 +150,9 @@ static void qla4xxx_recovery_timedout(st
1233 ddb_entry->fw_ddb_index, ddb_entry->os_target_id,
1234 ha->port_down_retry_count);
1235
1236- DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
1237- "0x%lx\n", ha->host_no, __func__, ha->dpc_flags));
1238- queue_work(ha->dpc_thread, &ha->dpc_work);
1239-}
1240-
1241-static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1242- enum iscsi_host_param param, char *buf)
1243-{
1244- struct scsi_qla_host *ha = to_qla_host(shost);
1245- int len;
1246-
1247- switch (param) {
1248- case ISCSI_HOST_PARAM_IPADDRESS:
1249- len = sprintf(buf, "%d.%d.%d.%d", ha->ip_address[0],
1250- ha->ip_address[1], ha->ip_address[2],
1251- ha->ip_address[3]);
1252- break;
1253- case ISCSI_HOST_PARAM_INITIATOR_NAME:
1254- len = sprintf(buf, "%s", ha->name_string);
1255- break;
1256- default:
1257- return -ENOSYS;
1258- }
1259+ QL_SET_DDB_OFFLINE(ha, ddb_entry);
1260
1261- return len;
1262+ queue_work(ha->dpc_thread, &ha->dpc_work);
1263 }
1264
1265 int qla4xxx_conn_start(struct iscsi_cls_conn *conn)
1266@@ -166,7 +160,8 @@ int qla4xxx_conn_start(struct iscsi_cls_
1267 struct iscsi_cls_session *session;
1268 struct ddb_entry *ddb_entry;
1269
1270- session = iscsi_dev_to_session(conn->dev.parent);
1271+ session = QL_ISCSI_CONN_TO_SESS(conn);
1272+
1273 ddb_entry = session->dd_data;
1274
1275 DEBUG2(printk("scsi%ld: %s: index [%d] starting conn\n",
1276@@ -181,7 +176,8 @@ static void qla4xxx_conn_stop(struct isc
1277 struct iscsi_cls_session *session;
1278 struct ddb_entry *ddb_entry;
1279
1280- session = iscsi_dev_to_session(conn->dev.parent);
1281+ session = QL_ISCSI_CONN_TO_SESS(conn);
1282+
1283 ddb_entry = session->dd_data;
1284
1285 DEBUG2(printk("scsi%ld: %s: index [%d] stopping conn\n",
1286@@ -207,6 +203,12 @@ static int qla4xxx_sess_get_param(struct
1287 case ISCSI_PARAM_TPGT:
1288 len = sprintf(buf, "%u", ddb_entry->tpgt);
1289 break;
1290+
1291+#ifdef ISCSI_ISID
1292+ case ISCSI_PARAM_ISID:
1293+ len = sprintf(buf, "%u", QL_ISCSI_SESSION_ID(ddb_entry));
1294+ break;
1295+#endif
1296 default:
1297 return -ENOSYS;
1298 }
1299@@ -221,7 +223,8 @@ static int qla4xxx_conn_get_param(struct
1300 struct ddb_entry *ddb_entry;
1301 int len;
1302
1303- session = iscsi_dev_to_session(conn->dev.parent);
1304+ session = QL_ISCSI_CONN_TO_SESS(conn);
1305+
1306 ddb_entry = session->dd_data;
1307
1308 switch (param) {
1309@@ -240,47 +243,53 @@ static int qla4xxx_conn_get_param(struct
1310 return len;
1311 }
1312
1313-static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
1314- enum iscsi_tgt_dscvr type, uint32_t enable,
1315- struct sockaddr *dst_addr)
1316+static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1317+ enum iscsi_host_param param, char *buf)
1318 {
1319- struct scsi_qla_host *ha;
1320- struct sockaddr_in *addr;
1321- struct sockaddr_in6 *addr6;
1322- int ret = 0;
1323-
1324- ha = (struct scsi_qla_host *) shost->hostdata;
1325-
1326- switch (type) {
1327- case ISCSI_TGT_DSCVR_SEND_TARGETS:
1328- if (dst_addr->sa_family == AF_INET) {
1329- addr = (struct sockaddr_in *)dst_addr;
1330- if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
1331- addr->sin_port) != QLA_SUCCESS)
1332- ret = -EIO;
1333- } else if (dst_addr->sa_family == AF_INET6) {
1334- /*
1335- * TODO: fix qla4xxx_send_tgts
1336- */
1337- addr6 = (struct sockaddr_in6 *)dst_addr;
1338- if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
1339- addr6->sin6_port) != QLA_SUCCESS)
1340- ret = -EIO;
1341- } else
1342- ret = -ENOSYS;
1343+ struct scsi_qla_host *ha = to_qla_host(shost);
1344+ int len;
1345+
1346+ switch (param) {
1347+ case ISCSI_HOST_PARAM_IPADDRESS:
1348+ len = sprintf(buf, "%d.%d.%d.%d", ha->ip_address[0],
1349+ ha->ip_address[1], ha->ip_address[2],
1350+ ha->ip_address[3]);
1351+ break;
1352+ case ISCSI_HOST_PARAM_INITIATOR_NAME:
1353+ len = sprintf(buf, "%s", ha->name_string);
1354 break;
1355 default:
1356- ret = -ENOSYS;
1357+ return -ENOSYS;
1358 }
1359- return ret;
1360+
1361+ return len;
1362+}
1363+
1364+static int ql_alloc_osindex(struct scsi_qla_host *ha)
1365+{
1366+ unsigned int idx;
1367+
1368+ for (idx = 0; idx < MAX_DDB_ENTRIES; idx++)
1369+ if (test_and_set_bit((idx & 0x1F), &ha->os_map[(idx >> 5)]) == 0)
1370+ return idx;
1371+ return -1;
1372+}
1373+
1374+static void free_osindex(struct scsi_qla_host *ha, uint32_t idx)
1375+{
1376+ clear_bit((idx & 0x1F), &ha->os_map[idx >> 5]);
1377 }
1378
1379+
1380 void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
1381 {
1382 if (!ddb_entry->sess)
1383 return;
1384+ free_osindex(ddb_entry->ha, ddb_entry->os_target_id);
1385
1386 if (ddb_entry->conn) {
1387+ QL_ISCSI_IF_DESTROY_SESSION_DONE(ddb_entry);
1388+ QL_ISCSI_DESTROY_CONN(ddb_entry);
1389 iscsi_remove_session(ddb_entry->sess);
1390 }
1391 iscsi_free_session(ddb_entry->sess);
1392@@ -290,25 +299,27 @@ int qla4xxx_add_sess(struct ddb_entry *d
1393 {
1394 int err;
1395
1396- err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
1397+ err = QL_ISCSI_ADD_SESS(ddb_entry);
1398+
1399 if (err) {
1400 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
1401 return err;
1402 }
1403
1404- ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
1405+ ddb_entry->conn = QL_ISCSI_CREATE_CONN(ddb_entry);
1406+
1407 if (!ddb_entry->conn) {
1408 iscsi_remove_session(ddb_entry->sess);
1409 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
1410 return -ENOMEM;
1411 }
1412
1413- ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
1414- if (scan)
1415- scsi_scan_target(&ddb_entry->sess->dev, 0,
1416- ddb_entry->sess->target_id,
1417- SCAN_WILD_CARD, 0);
1418- iscsi_unblock_session(ddb_entry->sess);
1419+ ddb_entry->sess->recovery_tmo = QL_SESS_RECOVERY_TO(ddb_entry);
1420+
1421+ qla4xxx_scan_target(ddb_entry);
1422+
1423+ QL_ISCSI_CREATE_SESS_DONE(ddb_entry);
1424+
1425 return 0;
1426 }
1427
1428@@ -317,13 +328,20 @@ struct ddb_entry *qla4xxx_alloc_sess(str
1429 struct ddb_entry *ddb_entry;
1430 struct iscsi_cls_session *sess;
1431
1432- sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
1433- sizeof(struct ddb_entry));
1434- if (!sess)
1435+ int os_idx;
1436+
1437+ if ((os_idx = ql_alloc_osindex(ha)) >= MAX_DDB_ENTRIES)
1438+ return NULL;
1439+
1440+ sess = QL_ISCSI_ALLOC_SESSION(ha, &qla4xxx_iscsi_transport);
1441+ if (!sess) {
1442+ free_osindex(ha, os_idx);
1443 return NULL;
1444+ }
1445
1446 ddb_entry = sess->dd_data;
1447 memset(ddb_entry, 0, sizeof(*ddb_entry));
1448+ ddb_entry->os_target_id = os_idx;
1449 ddb_entry->ha = ha;
1450 ddb_entry->sess = sess;
1451 return ddb_entry;
1452@@ -371,9 +389,9 @@ void qla4xxx_mark_device_missing(struct
1453 }
1454
1455 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1456- struct ddb_entry *ddb_entry,
1457- struct scsi_cmnd *cmd,
1458- void (*done)(struct scsi_cmnd *))
1459+ struct ddb_entry *ddb_entry,
1460+ struct scsi_cmnd *cmd,
1461+ void (*done)(struct scsi_cmnd *))
1462 {
1463 struct srb *srb;
1464
1465@@ -392,17 +410,6 @@ static struct srb* qla4xxx_get_new_srb(s
1466 return srb;
1467 }
1468
1469-static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1470-{
1471- struct scsi_cmnd *cmd = srb->cmd;
1472-
1473- if (srb->flags & SRB_DMA_VALID) {
1474- scsi_dma_unmap(cmd);
1475- srb->flags &= ~SRB_DMA_VALID;
1476- }
1477- cmd->SCp.ptr = NULL;
1478-}
1479-
1480 void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
1481 {
1482 struct scsi_cmnd *cmd = srb->cmd;
1483@@ -418,14 +425,14 @@ void qla4xxx_srb_compl(struct scsi_qla_h
1484 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
1485 * @cmd: Pointer to Linux's SCSI command structure
1486 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
1487- * that the command has been processed.
1488+ * that the command has been processed.
1489 *
1490 * Remarks:
1491 * This routine is invoked by Linux to send a SCSI command to the driver.
1492 * The mid-level driver tries to ensure that queuecommand never gets
1493 * invoked concurrently with itself or the interrupt handler (although
1494 * the interrupt handler may call this routine as part of request-
1495- * completion handling). Unfortunely, it sometimes calls the scheduler
1496+ * completion handling). Unfortunely, it sometimes calls the scheduler
1497 * in interrupt context which is a big NO! NO!.
1498 **/
1499 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
1500@@ -546,7 +553,7 @@ static int qla4xxx_mem_alloc(struct scsi
1501 align = 0;
1502 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1503 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1504- (MEM_ALIGN_VALUE - 1));
1505+ (MEM_ALIGN_VALUE - 1));
1506
1507 /* Update request and response queue pointers. */
1508 ha->request_dma = ha->queues_dma + align;
1509@@ -554,16 +561,16 @@ static int qla4xxx_mem_alloc(struct scsi
1510 ha->response_dma = ha->queues_dma + align +
1511 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1512 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1513- (REQUEST_QUEUE_DEPTH *
1514- QUEUE_SIZE));
1515+ (REQUEST_QUEUE_DEPTH *
1516+ QUEUE_SIZE));
1517 ha->shadow_regs_dma = ha->queues_dma + align +
1518 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1519 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1520 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1521 (REQUEST_QUEUE_DEPTH *
1522- QUEUE_SIZE) +
1523+ QUEUE_SIZE) +
1524 (RESPONSE_QUEUE_DEPTH *
1525- QUEUE_SIZE));
1526+ QUEUE_SIZE));
1527
1528 /* Allocate memory for srb pool. */
1529 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1530@@ -595,12 +602,12 @@ static void qla4xxx_timer(struct scsi_ql
1531 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1532 /* Count down time between sending relogins */
1533 if (adapter_up(ha) &&
1534- !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
1535- atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1536+ !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
1537+ atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1538 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
1539- INVALID_ENTRY) {
1540+ INVALID_ENTRY) {
1541 if (atomic_read(&ddb_entry->retry_relogin_timer)
1542- == 0) {
1543+ == 0) {
1544 atomic_set(&ddb_entry->
1545 retry_relogin_timer,
1546 INVALID_ENTRY);
1547@@ -608,9 +615,9 @@ static void qla4xxx_timer(struct scsi_ql
1548 &ha->dpc_flags);
1549 set_bit(DF_RELOGIN, &ddb_entry->flags);
1550 DEBUG2(printk("scsi%ld: %s: index [%d]"
1551- " login device\n",
1552- ha->host_no, __func__,
1553- ddb_entry->fw_ddb_index));
1554+ " login device\n",
1555+ ha->host_no, __func__,
1556+ ddb_entry->fw_ddb_index));
1557 } else
1558 atomic_dec(&ddb_entry->
1559 retry_relogin_timer);
1560@@ -619,64 +626,64 @@ static void qla4xxx_timer(struct scsi_ql
1561
1562 /* Wait for relogin to timeout */
1563 if (atomic_read(&ddb_entry->relogin_timer) &&
1564- (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
1565+ (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
1566 /*
1567 * If the relogin times out and the device is
1568 * still NOT ONLINE then try and relogin again.
1569 */
1570 if (atomic_read(&ddb_entry->state) !=
1571- DDB_STATE_ONLINE &&
1572- ddb_entry->fw_ddb_device_state ==
1573- DDB_DS_SESSION_FAILED) {
1574+ DDB_STATE_ONLINE &&
1575+ ddb_entry->fw_ddb_device_state ==
1576+ DDB_DS_SESSION_FAILED) {
1577 /* Reset retry relogin timer */
1578 atomic_inc(&ddb_entry->relogin_retry_count);
1579 DEBUG2(printk("scsi%ld: index[%d] relogin"
1580- " timed out-retrying"
1581- " relogin (%d)\n",
1582- ha->host_no,
1583- ddb_entry->fw_ddb_index,
1584- atomic_read(&ddb_entry->
1585+ " timed out-retrying"
1586+ " relogin (%d)\n",
1587+ ha->host_no,
1588+ ddb_entry->fw_ddb_index,
1589+ atomic_read(&ddb_entry->
1590 relogin_retry_count))
1591 );
1592 start_dpc++;
1593 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
1594- "initate relogin after"
1595- " %d seconds\n",
1596- ha->host_no, ddb_entry->bus,
1597- ddb_entry->target,
1598- ddb_entry->fw_ddb_index,
1599- ddb_entry->default_time2wait + 4)
1600- );
1601+ "initate relogin after"
1602+ " %d seconds\n",
1603+ ha->host_no, ddb_entry->bus,
1604+ ddb_entry->target,
1605+ ddb_entry->fw_ddb_index,
1606+ ddb_entry->default_time2wait + 4));
1607
1608 atomic_set(&ddb_entry->retry_relogin_timer,
1609- ddb_entry->default_time2wait + 4);
1610+ ddb_entry->default_time2wait + 4);
1611 }
1612 }
1613 }
1614
1615 /* Check for heartbeat interval. */
1616 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1617- ha->heartbeat_interval != 0) {
1618+ ha->heartbeat_interval != 0) {
1619 ha->seconds_since_last_heartbeat++;
1620 if (ha->seconds_since_last_heartbeat >
1621- ha->heartbeat_interval + 2)
1622+ ha->heartbeat_interval + 2)
1623 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1624 }
1625
1626
1627 /* Wakeup the dpc routine for this adapter, if needed. */
1628 if ((start_dpc ||
1629- test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1630- test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1631- test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
1632- test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1633- test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1634- test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
1635- test_bit(DPC_AEN, &ha->dpc_flags)) &&
1636- ha->dpc_thread) {
1637+ test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1638+ test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1639+ test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
1640+ test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1641+ test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1642+ test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
1643+ QL_DPC_OFFLINE_SET(ha) ||
1644+ test_bit(DPC_AEN, &ha->dpc_flags)) &&
1645+ ha->dpc_thread) {
1646 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1647- " - dpc flags = 0x%lx\n",
1648- ha->host_no, __func__, ha->dpc_flags));
1649+ " - dpc flags = 0x%lx\n",
1650+ ha->host_no, __func__, ha->dpc_flags));
1651 queue_work(ha->dpc_thread, &ha->dpc_work);
1652 }
1653
1654@@ -732,14 +739,15 @@ static int qla4xxx_cmd_wait(struct scsi_
1655 return stat;
1656 }
1657
1658-void qla4xxx_hw_reset(struct scsi_qla_host *ha)
1659+void qla4xxx_hw_reset(struct scsi_qla_host *ha, int hw_lock)
1660 {
1661 uint32_t ctrl_status;
1662 unsigned long flags = 0;
1663
1664 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
1665
1666- spin_lock_irqsave(&ha->hardware_lock, flags);
1667+ if (hw_lock)
1668+ spin_lock_irqsave(&ha->hardware_lock, flags);
1669 /*
1670 * If the SCSI Reset Interrupt bit is set, clear it.
1671 * Otherwise, the Soft Reset won't work.
1672@@ -752,7 +760,8 @@ void qla4xxx_hw_reset(struct scsi_qla_ho
1673 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1674 readl(&ha->reg->ctrl_status);
1675
1676- spin_unlock_irqrestore(&ha->hardware_lock, flags);
1677+ if (hw_lock)
1678+ spin_unlock_irqrestore(&ha->hardware_lock, flags);
1679 }
1680
1681 /**
1682@@ -766,7 +775,7 @@ int qla4xxx_soft_reset(struct scsi_qla_h
1683 int status = QLA_ERROR;
1684 uint32_t ctrl_status;
1685
1686- qla4xxx_hw_reset(ha);
1687+ qla4xxx_hw_reset(ha, 1);
1688
1689 /* Wait until the Network Reset Intr bit is cleared */
1690 max_wait_time = RESET_INTR_TOV;
1691@@ -783,9 +792,9 @@ int qla4xxx_soft_reset(struct scsi_qla_h
1692
1693 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
1694 DEBUG2(printk(KERN_WARNING
1695- "scsi%ld: Network Reset Intr not cleared by "
1696- "Network function, clearing it now!\n",
1697- ha->host_no));
1698+ "scsi%ld: Network Reset Intr not cleared by "
1699+ "Network function, clearing it now!\n",
1700+ ha->host_no));
1701 spin_lock_irqsave(&ha->hardware_lock, flags);
1702 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
1703 readl(&ha->reg->ctrl_status);
1704@@ -881,14 +890,13 @@ static void qla4xxx_flush_active_srbs(st
1705 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1706 * @ha: Pointer to host adapter structure.
1707 **/
1708-static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
1709+static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
1710 {
1711 int status;
1712
1713 /* Stall incoming I/O until we are done */
1714 clear_bit(AF_ONLINE, &ha->flags);
1715- DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
1716- __func__));
1717+ dev_info(&ha->pdev->dev, "%s: adapter OFFLINE\n", __func__);
1718
1719 /* Wait for outstanding commands to complete.
1720 * Stalls the driver for max 30 secs
1721@@ -905,7 +913,7 @@ static int qla4xxx_recover_adapter(struc
1722 */
1723 if (status == QLA_SUCCESS) {
1724 DEBUG2(printk(KERN_ERR "scsi%ld: %s - Performing soft reset..\n",
1725- ha->host_no, __func__));
1726+ ha->host_no, __func__));
1727 qla4xxx_flush_active_srbs(ha);
1728 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
1729 status = qla4xxx_soft_reset(ha);
1730@@ -920,24 +928,26 @@ static int qla4xxx_recover_adapter(struc
1731 * with ISP interrupts enabled */
1732 if (status == QLA_SUCCESS) {
1733 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
1734- ha->host_no, __func__));
1735+ ha->host_no, __func__));
1736
1737 /* If successful, AF_ONLINE flag set in
1738 * qla4xxx_initialize_adapter */
1739+ if (ha->mac_index == 3)
1740+ ssleep(6);
1741 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1742 }
1743
1744 /* Failed adapter initialization?
1745 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
1746 if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
1747- (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
1748+ (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
1749 /* Adapter initialization failed, see if we can retry
1750 * resetting the ha */
1751 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1752 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1753 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1754- "(%d) more times\n", ha->host_no,
1755- ha->retry_reset_ha_cnt));
1756+ "(%d) more times\n", ha->host_no,
1757+ ha->retry_reset_ha_cnt));
1758 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1759 status = QLA_ERROR;
1760 } else {
1761@@ -945,9 +955,9 @@ static int qla4xxx_recover_adapter(struc
1762 /* Schedule another Reset HA--DPC will retry */
1763 ha->retry_reset_ha_cnt--;
1764 DEBUG2(printk("scsi%ld: recover adapter - "
1765- "retry remaining %d\n",
1766- ha->host_no,
1767- ha->retry_reset_ha_cnt));
1768+ "retry remaining %d\n",
1769+ ha->host_no,
1770+ ha->retry_reset_ha_cnt));
1771 status = QLA_ERROR;
1772 }
1773
1774@@ -955,8 +965,8 @@ static int qla4xxx_recover_adapter(struc
1775 /* Recover adapter retries have been exhausted.
1776 * Adapter DEAD */
1777 DEBUG2(printk("scsi%ld: recover adapter "
1778- "failed - board disabled\n",
1779- ha->host_no));
1780+ "failed - board disabled\n",
1781+ ha->host_no));
1782 qla4xxx_flush_active_srbs(ha);
1783 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1784 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1785@@ -991,10 +1001,9 @@ static int qla4xxx_recover_adapter(struc
1786 * the mid-level tries to sleep when it reaches the driver threshold
1787 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1788 **/
1789-static void qla4xxx_do_dpc(struct work_struct *work)
1790+static QL_DECLARE_DPC(qla4xxx_do_dpc, data)
1791 {
1792- struct scsi_qla_host *ha =
1793- container_of(work, struct scsi_qla_host, dpc_work);
1794+ struct scsi_qla_host *ha = QL_DPC_DATA_TO_HA(data);
1795 struct ddb_entry *ddb_entry, *dtemp;
1796 int status = QLA_ERROR;
1797
1798@@ -1009,11 +1018,11 @@ static void qla4xxx_do_dpc(struct work_s
1799 return;
1800
1801 if (adapter_up(ha) ||
1802- test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1803- test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1804- test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
1805+ test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1806+ test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1807+ test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
1808 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1809- test_bit(DPC_RESET_HA, &ha->dpc_flags))
1810+ test_bit(DPC_RESET_HA, &ha->dpc_flags))
1811 qla4xxx_recover_adapter(ha);
1812
1813 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1814@@ -1025,14 +1034,15 @@ static void qla4xxx_do_dpc(struct work_s
1815 break;
1816 msleep(1000);
1817 }
1818+
1819 if (wait_time == 0)
1820 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1821- "bit not cleared-- resetting\n",
1822- ha->host_no, __func__));
1823+ "bit not cleared-- resetting\n",
1824+ ha->host_no, __func__));
1825 qla4xxx_flush_active_srbs(ha);
1826 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1827 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1828- status = qla4xxx_initialize_adapter(ha,
1829+ status = qla4xxx_initialize_adapter(ha,
1830 PRESERVE_DDB_LIST);
1831 }
1832 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1833@@ -1049,13 +1059,42 @@ static void qla4xxx_do_dpc(struct work_s
1834 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1835 qla4xxx_get_dhcp_ip_address(ha);
1836
1837+ qla4xxx_check_dev_offline(ha);
1838+
1839+ if (test_and_clear_bit(DPC_DELETE_DEVICE, &ha->dpc_flags)) {
1840+ list_for_each_entry_safe(ddb_entry, dtemp,
1841+ &ha->ddb_list, list) {
1842+ if (test_and_clear_bit(DF_DELETED,
1843+ &ddb_entry->flags)) {
1844+ if (atomic_read(&ddb_entry->state) ==
1845+ DDB_STATE_DEAD) {
1846+ dev_info(&ha->pdev->dev,
1847+ "%s: ddb[%d] os[%d] - "
1848+ "delete\n",
1849+ __func__,
1850+ ddb_entry->fw_ddb_index,
1851+ ddb_entry->os_target_id);
1852+ } else {
1853+ dev_info(&ha->pdev->dev,
1854+ "%s: ddb[%d] os[%d] - "
1855+ "ddb state not dead but"
1856+ " marked for delete\n",
1857+ __func__,
1858+ ddb_entry->fw_ddb_index,
1859+ ddb_entry->os_target_id);
1860+ }
1861+ }
1862+ }
1863+ }
1864+
1865 /* ---- relogin device? --- */
1866 if (adapter_up(ha) &&
1867- test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1868+ test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1869 list_for_each_entry_safe(ddb_entry, dtemp,
1870 &ha->ddb_list, list) {
1871 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1872- atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1873+ (atomic_read(&ddb_entry->state) !=
1874+ DDB_STATE_ONLINE))
1875 qla4xxx_relogin_device(ha, ddb_entry);
1876
1877 /*
1878@@ -1092,7 +1131,7 @@ static void qla4xxx_free_adapter(struct
1879
1880 /* Issue Soft Reset to put firmware in unknown state */
1881 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
1882- qla4xxx_hw_reset(ha);
1883+ qla4xxx_hw_reset(ha, 1);
1884
1885 /* Remove timer thread, if present */
1886 if (ha->timer_active)
1887@@ -1142,6 +1181,7 @@ static int qla4xxx_iospace_config(struct
1888 if (!(mmio_flags & IORESOURCE_MEM)) {
1889 dev_err(&ha->pdev->dev,
1890 "region #0 not an MMIO resource, aborting\n");
1891+
1892 goto iospace_error_exit;
1893 }
1894 if (mmio_len < MIN_IOBASE_LEN) {
1895@@ -1173,14 +1213,6 @@ iospace_error_exit:
1896 return -ENOMEM;
1897 }
1898
1899-static void ql4_get_aen_log(struct scsi_qla_host *ha, struct ql4_aen_log *aenl)
1900-{
1901- if (aenl) {
1902- memcpy(aenl, &ha->aen_log, sizeof (ha->aen_log));
1903- ha->aen_log.count = 0;
1904- }
1905-}
1906-
1907 /**
1908 * qla4xxx_probe_adapter - callback function to probe HBA
1909 * @pdev: pointer to pci_dev structure
1910@@ -1191,7 +1223,7 @@ static void ql4_get_aen_log(struct scsi_
1911 * the driver.
1912 **/
1913 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1914- const struct pci_device_id *ent)
1915+ const struct pci_device_id *ent)
1916 {
1917 int ret = -ENODEV, status;
1918 struct Scsi_Host *host;
1919@@ -1206,7 +1238,7 @@ static int __devinit qla4xxx_probe_adapt
1920 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1921 if (host == NULL) {
1922 printk(KERN_WARNING
1923- "qla4xxx: Couldn't allocate host from scsi layer!\n");
1924+ "qla4xxx: Couldn't allocate host from scsi layer!\n");
1925 goto probe_disable_device;
1926 }
1927
1928@@ -1218,10 +1250,7 @@ static int __devinit qla4xxx_probe_adapt
1929 ha->pdev = pdev;
1930 ha->host = host;
1931 ha->host_no = host->host_no;
1932-
1933- ha->ql4mbx = qla4xxx_mailbox_command;
1934- ha->ql4cmd = qla4xxx_send_command_to_isp;
1935- ha->ql4getaenlog = ql4_get_aen_log;
1936+ set_bit(AF_OS_INDEX_VALID, &ha->flags);
1937
1938 /* Configure PCI I/O space. */
1939 ret = qla4xxx_iospace_config(ha);
1940@@ -1229,7 +1258,7 @@ static int __devinit qla4xxx_probe_adapt
1941 goto probe_failed;
1942
1943 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1944- pdev->device, pdev->irq, ha->reg);
1945+ pdev->device, pdev->irq, ha->reg);
1946
1947 qla4xxx_config_dma_addressing(ha);
1948
1949@@ -1245,7 +1274,7 @@ static int __devinit qla4xxx_probe_adapt
1950 /* Allocate dma buffers */
1951 if (qla4xxx_mem_alloc(ha)) {
1952 dev_warn(&ha->pdev->dev,
1953- "[ERROR] Failed to allocate memory for adapter\n");
1954+ "[ERROR] Failed to allocate memory for adapter\n");
1955
1956 ret = -ENOMEM;
1957 goto probe_failed;
1958@@ -1258,8 +1287,8 @@ static int __devinit qla4xxx_probe_adapt
1959 */
1960 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1961 while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
1962- DEBUG2(printk(KERN_ERR "scsi%ld: %s: retrying adapter initialization "
1963- "(%d)\n", ha->host_no, __func__, init_retry_count));
1964+ DEBUG2(dev_info(&ha->pdev->dev, "%s: retry adapter init %d\n",
1965+ __func__, init_retry_count));
1966 qla4xxx_soft_reset(ha);
1967 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1968 }
1969@@ -1280,7 +1309,7 @@ static int __devinit qla4xxx_probe_adapt
1970
1971 /* Startup the kernel thread for this host adapter. */
1972 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1973- "qla4xxx_dpc\n", __func__));
1974+ "qla4xxx_dpc\n", __func__));
1975 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1976 ha->dpc_thread = create_singlethread_workqueue(buf);
1977 if (!ha->dpc_thread) {
1978@@ -1288,9 +1317,11 @@ static int __devinit qla4xxx_probe_adapt
1979 ret = -ENODEV;
1980 goto probe_failed;
1981 }
1982- INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
1983+ QL_INIT_WORK(ha, qla4xxx_do_dpc);
1984+
1985 ret = request_irq(pdev->irq, qla4xxx_intr_handler,
1986- IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
1987+ QL_REQ_IRQ_FLAGS, "qla4xxx", ha);
1988+
1989 if (ret) {
1990 dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
1991 " already in use.\n", pdev->irq);
1992@@ -1298,7 +1329,7 @@ static int __devinit qla4xxx_probe_adapt
1993 }
1994 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1995 host->irq = pdev->irq;
1996- DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
1997+ dev_info(&ha->pdev->dev, "irq %d attached\n", ha->pdev->irq);
1998
1999 qla4xxx_enable_intrs(ha);
2000
2001@@ -1313,6 +1344,9 @@ static int __devinit qla4xxx_probe_adapt
2002 if (ret)
2003 goto probe_failed;
2004
2005+ if ((ret = QL_ISCSI_REGISTER_HOST(host, qla4xxx_scsi_transport)))
2006+ goto remove_host;
2007+
2008 /* Update transport device information for all devices. */
2009 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
2010
2011@@ -1320,25 +1354,36 @@ static int __devinit qla4xxx_probe_adapt
2012 set_bit(DF_SCAN_ISSUED, &ddb_entry->flags);
2013
2014 if (qla4xxx_add_sess(ddb_entry,
2015- test_bit(DF_SCAN_ISSUED, &ddb_entry->flags)))
2016+ test_bit(DF_SCAN_ISSUED, &ddb_entry->flags))) {
2017+ QL_ISCSI_UNREGISTER_HOST(host, qla4xxx_scsi_transport);
2018 goto remove_host;
2019+ }
2020 if (!test_bit(DF_SCAN_ISSUED, &ddb_entry->flags))
2021 qla4xxx_mark_device_missing(ha, ddb_entry);
2022 }
2023
2024- printk(KERN_INFO
2025- " QLogic iSCSI HBA Driver version: %s\n"
2026- " QLogic ISP%04x @ %s, pdev = %p host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2027- qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), pdev,
2028- ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2029- ha->patch_number, ha->build_number);
2030+ dev_info(&ha->pdev->dev, " QLogic iSCSI HBA Driver version: %s\n"
2031+ " QLogic ISP%04x @ %s, pdev = %p host#=%ld,"
2032+ " fw=%02d.%02d.%02d.%02d\n", qla4xxx_version_str,
2033+ ha->pdev->device, pci_name(ha->pdev), pdev,
2034+ ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2035+ ha->patch_number, ha->build_number);
2036
2037 /* Insert new entry into the list of adapters. */
2038 klist_add_tail(&ha->node, &qla4xxx_hostlist);
2039 ha->instance = atomic_inc_return(&qla4xxx_hba_count) - 1;
2040
2041- DEBUG2(printk("qla4xxx: listhead=%p, done adding ha=%p i=%d\n",
2042- &qla4xxx_hostlist, &ha->node, ha->instance));
2043+ if (qla4xxx_ioctl_init(ha)) {
2044+ dev_info(&ha->pdev->dev, "ioctl init failed\n");
2045+ QL_ISCSI_UNREGISTER_HOST(host, qla4xxx_scsi_transport);
2046+ goto remove_host;
2047+ }
2048+
2049+ DEBUG2(dev_info(&ha->pdev->dev, "listhead=%p, done adding ha=%p i=%d\n",
2050+ &qla4xxx_hostlist, &ha->node, ha->instance));
2051+
2052+// set_bit(AF_INIT_DONE, &ha->flags);
2053+ dev_info(&ha->pdev->dev, "%s: AF_INIT_DONE\n", __func__);
2054
2055 return 0;
2056
2057@@ -1377,8 +1422,12 @@ static void __devexit qla4xxx_remove_ada
2058 /* remove devs from iscsi_sessions to scsi_devices */
2059 qla4xxx_free_ddb_list(ha);
2060
2061+ QL_ISCSI_UNREGISTER_HOST(ha->host, qla4xxx_scsi_transport);
2062+
2063 scsi_remove_host(ha->host);
2064
2065+ qla4xxx_ioctl_exit(ha);
2066+
2067 qla4xxx_free_adapter(ha);
2068
2069 scsi_host_put(ha->host);
2070@@ -1393,7 +1442,7 @@ static void __devexit qla4xxx_remove_ada
2071 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2072 * supported addressing method.
2073 */
2074-static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
2075+void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
2076 {
2077 int retval;
2078
2079@@ -1402,9 +1451,9 @@ static void qla4xxx_config_dma_addressin
2080 if (pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
2081 dev_dbg(&ha->pdev->dev,
2082 "Failed to set 64 bit PCI consistent mask; "
2083- "using 32 bit.\n");
2084+ "using 32 bit.\n");
2085 retval = pci_set_consistent_dma_mask(ha->pdev,
2086- DMA_32BIT_MASK);
2087+ DMA_32BIT_MASK);
2088 }
2089 } else
2090 retval = pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
2091@@ -1412,7 +1461,7 @@ static void qla4xxx_config_dma_addressin
2092
2093 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
2094 {
2095- struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
2096+ struct iscsi_cls_session *sess = QL_ISCSI_SDEV_TO_SESS(sdev);
2097
2098 if (sess) {
2099 sdev->hostdata = sess->dd_data;
2100@@ -1431,6 +1480,11 @@ static int qla4xxx_slave_configure(struc
2101 return 0;
2102 }
2103
2104+static void qla4xxx_slave_destroy(struct scsi_device *sdev)
2105+{
2106+ sdev->hostdata = NULL;
2107+}
2108+
2109 /**
2110 * qla4xxx_del_from_active_array - returns an active srb
2111 * @ha: Pointer to host adapter structure.
2112@@ -1470,7 +1524,7 @@ struct srb * qla4xxx_del_from_active_arr
2113 * for some max time.
2114 **/
2115 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
2116- struct scsi_cmnd *cmd)
2117+ struct scsi_cmnd *cmd)
2118 {
2119 int done = 0;
2120 struct srb *rp;
2121@@ -1564,8 +1618,8 @@ static int qla4xxx_eh_device_reset(struc
2122 return ret;
2123
2124 dev_info(&ha->pdev->dev,
2125- "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2126- cmd->device->channel, cmd->device->id, cmd->device->lun);
2127+ "%s: %d:%d:%d: DEVICE RESET ISSUED.\n", __func__,
2128+ cmd->device->channel, cmd->device->id, cmd->device->lun);
2129
2130 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2131 dev_info(&ha->pdev->dev, "%s: HBA OFFLINE: FAILED\n", __func__);
2132@@ -1584,12 +1638,12 @@ static int qla4xxx_eh_device_reset(struc
2133 */
2134 if (cmd->device->host->shost_state == SHOST_RECOVERY) {
2135 if (qla4xxx_eh_wait_for_active_target_commands(ha,
2136- cmd->device->id,
2137- cmd->device->
2138- lun)) {
2139+ cmd->device->id,
2140+ cmd->device->
2141+ lun)) {
2142 dev_info(&ha->pdev->dev,
2143- "DEVICE RESET FAILED - waiting for "
2144- "commands.\n");
2145+ "DEVICE RESET FAILED - waiting for "
2146+ "commands.\n");
2147 goto eh_dev_reset_done;
2148 }
2149 }
2150@@ -1598,9 +1652,9 @@ static int qla4xxx_eh_device_reset(struc
2151 goto eh_dev_reset_done;
2152
2153 dev_info(&ha->pdev->dev,
2154- "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2155- ha->host_no, cmd->device->channel, cmd->device->id,
2156- cmd->device->lun);
2157+ "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2158+ ha->host_no, cmd->device->channel, cmd->device->id,
2159+ cmd->device->lun);
2160
2161 ret = SUCCESS;
2162
2163@@ -1635,7 +1689,7 @@ static int qla4xxx_eh_host_reset(struct
2164 }
2165
2166 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
2167- return_status == FAILED ? "FAILED" : "SUCCEDED");
2168+ return_status == FAILED ? "FAILED" : "SUCCEDED");
2169
2170 return return_status;
2171 }
2172@@ -1664,7 +1718,7 @@ static struct pci_device_id qla4xxx_pci_
2173 };
2174 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
2175
2176-static struct pci_driver qla4xxx_pci_driver = {
2177+struct pci_driver qla4xxx_pci_driver = {
2178 .name = DRIVER_NAME,
2179 .id_table = qla4xxx_pci_tbl,
2180 .probe = qla4xxx_probe_adapter,
2181@@ -1678,12 +1732,11 @@ static int __init qla4xxx_module_init(vo
2182 atomic_set(&qla4xxx_hba_count, 0);
2183 klist_init(&qla4xxx_hostlist, NULL, NULL);
2184 /* Allocate cache for SRBs. */
2185- srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
2186- SLAB_HWCACHE_ALIGN, NULL);
2187+ srb_cachep = ql_kmem_cache_create();
2188+
2189 if (srb_cachep == NULL) {
2190- printk(KERN_ERR
2191- "%s: Unable to allocate SRB cache..."
2192- "Failing load!\n", DRIVER_NAME);
2193+ printk(KERN_ERR "%s: Unable to allocate SRB cache..."
2194+ "Failing load!\n", DRIVER_NAME);
2195 ret = -ENOMEM;
2196 goto no_srp_cache;
2197 }
2198@@ -1700,7 +1753,14 @@ static int __init qla4xxx_module_init(vo
2199 goto release_srb_cache;
2200 }
2201
2202+ ret = QL_MISC_INIT;
2203+ if (ret) {
2204+ printk(KERN_INFO "QLogic iSCSI HBA Driver ioctl init failed\n");
2205+ goto unregister_transport;
2206+ }
2207+
2208 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
2209+
2210 ret = pci_register_driver(&qla4xxx_pci_driver);
2211 if (ret)
2212 goto unregister_transport;
2213@@ -1718,6 +1778,9 @@ no_srp_cache:
2214 static void __exit qla4xxx_module_exit(void)
2215 {
2216 ql4_mod_unload = 1;
2217+
2218+ QL_MISC_EXIT;
2219+
2220 pci_unregister_driver(&qla4xxx_pci_driver);
2221 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2222 kmem_cache_destroy(srb_cachep);
2223--- /dev/null
2224+++ b/drivers/scsi/qla4xxx/ql4_os.h
2225@@ -0,0 +1,125 @@
2226+/*
2227+ * QLogic iSCSI HBA Driver
2228+ * Copyright (c) 2003-2006 QLogic Corporation
2229+ *
2230+ * See LICENSE.qla4xxx for copyright and licensing details.
2231+ */
2232+
2233+/*
2234+ * This file encapsulates RHEL5 Specific Code
2235+ */
2236+
2237+#ifndef __QLA4x_OS_H
2238+#define __QLA4x_OS_H
2239+
2240+/* Common across all O.S platforms */
2241+#define IOCB_CMD_TIMEOUT 30
2242+#define RELOGIN_TOV 18
2243+#define RECOVERY_TIMEOUT 20 /* ddb state MISSING -> DEAD */
2244+
2245+#define QL_IOCB_CMD_TIMEOUT(cmd)
2246+
2247+#define QL_SET_DDB_OFFLINE(ha, ddb_entry)
2248+
2249+#define QL_SESS_RECOVERY_TO(ddb_entry) ddb_entry->ha->port_down_retry_count
2250+
2251+#define QL_DPC_OFFLINE_SET(ha) 0
2252+
2253+#define QL_ISCSI_CONN_TO_SESS(conn) iscsi_dev_to_session(conn->dev.parent)
2254+
2255+#define QL_ISCSI_SDEV_TO_SESS(sdev) starget_to_session(sdev->sdev_target)
2256+
2257+#define QL_ISCSI_ADD_SESS(ddb_entry) \
2258+ iscsi_add_session(ddb_entry->sess, ddb_entry->os_target_id)
2259+
2260+#define QL_ISCSI_REGISTER_HOST(host, trans) 0
2261+#define QL_ISCSI_UNREGISTER_HOST(host, trans)
2262+
2263+#define QL_ISCSI_SESSION_ID(ddb_entry) ddb_entry->sess->sid
2264+#define QL_ISCSI_IF_DESTROY_SESSION_DONE(ddb_entry)
2265+#define QL_ISCSI_DESTROY_CONN(ddb_entry)
2266+#define QL_ISCSI_CREATE_CONN(ddb_entry) \
2267+ iscsi_create_conn(ddb_entry->sess, 0, 0)
2268+#define QL_ISCSI_CREATE_SESS_DONE(ddb_entry) \
2269+ iscsi_unblock_session(ddb_entry->sess)
2270+#define QL_ISCSI_ALLOC_SESSION(ha, trans) \
2271+ iscsi_alloc_session(ha->host, trans, sizeof(struct ddb_entry))
2272+
2273+
2274+#define QL_MISC_INIT 0
2275+#define QL_MISC_EXIT
2276+
2277+#define qla4xxx_check_dev_offline(ha)
2278+#define qla4xxx_proc_info NULL
2279+
2280+#define QL_SET_SCSI_RESID(cmd, residual) scsi_set_resid(cmd, residual)
2281+#define QL_SCSI_BUFFLEN(cmd) scsi_bufflen(cmd)
2282+
2283+#define QL_DPC_DATA_TO_HA(work) \
2284+ container_of((struct work_struct *)work, struct scsi_qla_host, dpc_work)
2285+
2286+#define QL_INIT_WORK(ha, dpc_func) INIT_WORK(&ha->dpc_work, dpc_func)
2287+
2288+#define QL_REQ_IRQ_FLAGS (IRQF_DISABLED | IRQF_SHARED)
2289+
2290+#define QL_DECLARE_INTR_HANDLER(intr_func, irq, dev_id, regs) \
2291+ irqreturn_t intr_func(int irq, void *dev_id)
2292+
2293+#define QL_DECLARE_DPC(dpc_func, data) \
2294+ void dpc_func(struct work_struct *data)
2295+
2296+#define QL_INIT_SESSION_DATASIZE(sessiondata_size)
2297+// .sessiondata_size = sizeof(struct ddb_entry),
2298+
2299+#define QL_INIT_HOST_TEMPLATE(host_template)
2300+// .host_template = &qla4xxx_driver_template,
2301+
2302+QL_DECLARE_INTR_HANDLER(qla4xxx_intr_handler, irq, dev_id, regs);
2303+
2304+static inline struct kmem_cache *ql_kmem_cache_create(void)
2305+{
2306+ return (kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
2307+ SLAB_HWCACHE_ALIGN, NULL));
2308+}
2309+
2310+static inline void qla4xxx_scan_target(struct ddb_entry * ddb_entry)
2311+{
2312+ scsi_scan_target(&ddb_entry->sess->dev, 0,
2313+ ddb_entry->sess->target_id, SCAN_WILD_CARD, 0);
2314+}
2315+
2316+static void ql4_get_aen_log(struct scsi_qla_host *ha, struct ql4_aen_log *aenl)
2317+{
2318+ if (aenl) {
2319+ memcpy(aenl, &ha->aen_log, sizeof (ha->aen_log));
2320+ ha->aen_log.count = 0;
2321+ }
2322+}
2323+
2324+static inline int qla4xxx_ioctl_init(struct scsi_qla_host *ha)
2325+{
2326+ ha->ql4mbx = qla4xxx_mailbox_command;
2327+ ha->ql4cmd = qla4xxx_send_command_to_isp;
2328+ ha->ql4getaenlog = ql4_get_aen_log;
2329+ return 0;
2330+}
2331+
2332+static inline void qla4xxx_ioctl_exit(struct scsi_qla_host *ha)
2333+{
2334+ return;
2335+}
2336+
2337+static inline void qla4xxx_srb_free_dma(struct scsi_qla_host *ha,
2338+ struct srb *srb)
2339+{
2340+ struct scsi_cmnd *cmd = srb->cmd;
2341+
2342+ if (srb->flags & SRB_DMA_VALID) {
2343+ scsi_dma_unmap(cmd);
2344+ srb->flags &= ~SRB_DMA_VALID;
2345+ }
2346+
2347+ cmd->SCp.ptr = NULL;
2348+}
2349+
2350+#endif /* _QLA4x_OS_H */
2351--- a/drivers/scsi/qla4xxx/ql4_version.h
2352+++ b/drivers/scsi/qla4xxx/ql4_version.h
2353@@ -5,6 +5,5 @@
2354 * See LICENSE.qla4xxx for copyright and licensing details.
2355 */
2356
2357-#define QLA4XXX_DRIVER_VERSION "5.01.00-k8_sles11-01"
2358-
2359+#define QLA4XXX_DRIVER_VERSION "5.01.00-k8_sles11-03"
2360