2 * pmcraid.c -- driver for PMC Sierra MaxRAID controller adapters
4 * Written By: PMC Sierra Corporation
6 * Copyright (C) 2008, 2009 PMC Sierra Inc
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
25 #include <linux/init.h>
26 #include <linux/types.h>
27 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/ioport.h>
30 #include <linux/delay.h>
31 #include <linux/pci.h>
32 #include <linux/wait.h>
33 #include <linux/spinlock.h>
34 #include <linux/sched.h>
35 #include <linux/interrupt.h>
36 #include <linux/blkdev.h>
37 #include <linux/firmware.h>
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/hdreg.h>
41 #include <linux/version.h>
44 #include <asm/processor.h>
45 #include <linux/libata.h>
46 #include <linux/mutex.h>
47 #include <scsi/scsi.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/scsi_eh.h>
51 #include <scsi/scsi_cmnd.h>
52 #include <scsi/scsicam.h>
57 * Module configuration parameters
59 static unsigned int pmcraid_debug_log
;
60 static unsigned int pmcraid_disable_aen
;
61 static unsigned int pmcraid_log_level
= IOASC_LOG_LEVEL_MUST
;
64 * Data structures to support multiple adapters by the LLD.
65 * pmcraid_adapter_count - count of configured adapters
67 static atomic_t pmcraid_adapter_count
= ATOMIC_INIT(0);
70 * Supporting user-level control interface through IOCTL commands.
71 * pmcraid_major - major number to use
72 * pmcraid_minor - minor number(s) to use
74 static unsigned int pmcraid_major
;
75 static struct class *pmcraid_class
;
76 DECLARE_BITMAP(pmcraid_minor
, PMCRAID_MAX_ADAPTERS
);
81 MODULE_AUTHOR("PMC Sierra Corporation, anil_ravindranath@pmc-sierra.com");
82 MODULE_DESCRIPTION("PMC Sierra MaxRAID Controller Driver");
83 MODULE_LICENSE("GPL");
84 MODULE_VERSION(PMCRAID_DRIVER_VERSION
);
86 module_param_named(log_level
, pmcraid_log_level
, uint
, (S_IRUGO
| S_IWUSR
));
87 MODULE_PARM_DESC(log_level
,
88 "Enables firmware error code logging, default :1 high-severity"
89 " errors, 2: all errors including high-severity errors,"
90 " 0: disables logging");
92 module_param_named(debug
, pmcraid_debug_log
, uint
, (S_IRUGO
| S_IWUSR
));
93 MODULE_PARM_DESC(debug
,
94 "Enable driver verbose message logging. Set 1 to enable."
97 module_param_named(disable_aen
, pmcraid_disable_aen
, uint
, (S_IRUGO
| S_IWUSR
));
98 MODULE_PARM_DESC(disable_aen
,
99 "Disable driver aen notifications to apps. Set 1 to disable."
102 /* chip specific constants for PMC MaxRAID controllers (same for
105 static struct pmcraid_chip_details pmcraid_chip_cfg
[] = {
110 .global_intr_mask
= 0x00034,
111 .ioa_host_intr
= 0x0009C,
112 .ioa_host_intr_clr
= 0x000A0,
113 .ioa_host_mask
= 0x7FC28,
114 .ioa_host_mask_clr
= 0x7FC28,
115 .host_ioa_intr
= 0x00020,
116 .host_ioa_intr_clr
= 0x00020,
117 .transop_timeout
= 300
122 * PCI device ids supported by pmcraid driver
124 static struct pci_device_id pmcraid_pci_table
[] __devinitdata
= {
125 { PCI_DEVICE(PCI_VENDOR_ID_PMC
, PCI_DEVICE_ID_PMC_MAXRAID
),
126 0, 0, (kernel_ulong_t
)&pmcraid_chip_cfg
[0]
131 MODULE_DEVICE_TABLE(pci
, pmcraid_pci_table
);
136 * pmcraid_slave_alloc - Prepare for commands to a device
137 * @scsi_dev: scsi device struct
139 * This function is called by mid-layer prior to sending any command to the new
140 * device. Stores resource entry details of the device in scsi_device struct.
141 * Queuecommand uses the resource handle and other details to fill up IOARCB
142 * while sending commands to the device.
145 * 0 on success / -ENXIO if device does not exist
147 static int pmcraid_slave_alloc(struct scsi_device
*scsi_dev
)
149 struct pmcraid_resource_entry
*temp
, *res
= NULL
;
150 struct pmcraid_instance
*pinstance
;
152 unsigned long lock_flags
;
154 pinstance
= shost_priv(scsi_dev
->host
);
156 /* Driver exposes VSET and GSCSI resources only; all other device types
157 * are not exposed. Resource list is synchronized using resource lock
158 * so any traversal or modifications to the list should be done inside
161 spin_lock_irqsave(&pinstance
->resource_lock
, lock_flags
);
162 list_for_each_entry(temp
, &pinstance
->used_res_q
, queue
) {
164 /* do not expose VSETs with order-ids >= 240 */
165 if (RES_IS_VSET(temp
->cfg_entry
)) {
166 target
= temp
->cfg_entry
.unique_flags1
;
167 if (target
>= PMCRAID_MAX_VSET_TARGETS
)
169 bus
= PMCRAID_VSET_BUS_ID
;
171 } else if (RES_IS_GSCSI(temp
->cfg_entry
)) {
172 target
= RES_TARGET(temp
->cfg_entry
.resource_address
);
173 bus
= PMCRAID_PHYS_BUS_ID
;
174 lun
= RES_LUN(temp
->cfg_entry
.resource_address
);
179 if (bus
== scsi_dev
->channel
&&
180 target
== scsi_dev
->id
&&
181 lun
== scsi_dev
->lun
) {
188 res
->scsi_dev
= scsi_dev
;
189 scsi_dev
->hostdata
= res
;
190 res
->change_detected
= 0;
191 atomic_set(&res
->read_failures
, 0);
192 atomic_set(&res
->write_failures
, 0);
195 spin_unlock_irqrestore(&pinstance
->resource_lock
, lock_flags
);
200 * pmcraid_slave_configure - Configures a SCSI device
201 * @scsi_dev: scsi device struct
203 * This fucntion is executed by SCSI mid layer just after a device is first
204 * scanned (i.e. it has responded to an INQUIRY). For VSET resources, the
205 * timeout value (default 30s) will be over-written to a higher value (60s)
206 * and max_sectors value will be over-written to 512. It also sets queue depth
207 * to host->cmd_per_lun value
212 static int pmcraid_slave_configure(struct scsi_device
*scsi_dev
)
214 struct pmcraid_resource_entry
*res
= scsi_dev
->hostdata
;
219 /* LLD exposes VSETs and Enclosure devices only */
220 if (RES_IS_GSCSI(res
->cfg_entry
) &&
221 scsi_dev
->type
!= TYPE_ENCLOSURE
)
224 pmcraid_info("configuring %x:%x:%x:%x\n",
225 scsi_dev
->host
->unique_id
,
230 if (RES_IS_GSCSI(res
->cfg_entry
)) {
231 scsi_dev
->allow_restart
= 1;
232 } else if (RES_IS_VSET(res
->cfg_entry
)) {
233 scsi_dev
->allow_restart
= 1;
234 blk_queue_rq_timeout(scsi_dev
->request_queue
,
235 PMCRAID_VSET_IO_TIMEOUT
);
236 blk_queue_max_sectors(scsi_dev
->request_queue
,
237 PMCRAID_VSET_MAX_SECTORS
);
240 if (scsi_dev
->tagged_supported
&&
241 (RES_IS_GSCSI(res
->cfg_entry
) || RES_IS_VSET(res
->cfg_entry
))) {
242 scsi_activate_tcq(scsi_dev
, scsi_dev
->queue_depth
);
243 scsi_adjust_queue_depth(scsi_dev
, MSG_SIMPLE_TAG
,
244 scsi_dev
->host
->cmd_per_lun
);
246 scsi_adjust_queue_depth(scsi_dev
, 0,
247 scsi_dev
->host
->cmd_per_lun
);
254 * pmcraid_slave_destroy - Unconfigure a SCSI device before removing it
256 * @scsi_dev: scsi device struct
258 * This is called by mid-layer before removing a device. Pointer assignments
259 * done in pmcraid_slave_alloc will be reset to NULL here.
264 static void pmcraid_slave_destroy(struct scsi_device
*scsi_dev
)
266 struct pmcraid_resource_entry
*res
;
268 res
= (struct pmcraid_resource_entry
*)scsi_dev
->hostdata
;
271 res
->scsi_dev
= NULL
;
273 scsi_dev
->hostdata
= NULL
;
277 * pmcraid_change_queue_depth - Change the device's queue depth
278 * @scsi_dev: scsi device struct
279 * @depth: depth to set
284 static int pmcraid_change_queue_depth(struct scsi_device
*scsi_dev
, int depth
)
286 if (depth
> PMCRAID_MAX_CMD_PER_LUN
)
287 depth
= PMCRAID_MAX_CMD_PER_LUN
;
289 scsi_adjust_queue_depth(scsi_dev
, scsi_get_tag_type(scsi_dev
), depth
);
291 return scsi_dev
->queue_depth
;
295 * pmcraid_change_queue_type - Change the device's queue type
296 * @scsi_dev: scsi device struct
297 * @tag: type of tags to use
300 * actual queue type set
302 static int pmcraid_change_queue_type(struct scsi_device
*scsi_dev
, int tag
)
304 struct pmcraid_resource_entry
*res
;
306 res
= (struct pmcraid_resource_entry
*)scsi_dev
->hostdata
;
308 if ((res
) && scsi_dev
->tagged_supported
&&
309 (RES_IS_GSCSI(res
->cfg_entry
) || RES_IS_VSET(res
->cfg_entry
))) {
310 scsi_set_tag_type(scsi_dev
, tag
);
313 scsi_activate_tcq(scsi_dev
, scsi_dev
->queue_depth
);
315 scsi_deactivate_tcq(scsi_dev
, scsi_dev
->queue_depth
);
324 * pmcraid_init_cmdblk - initializes a command block
326 * @cmd: pointer to struct pmcraid_cmd to be initialized
327 * @index: if >=0 first time initialization; otherwise reinitialization
332 void pmcraid_init_cmdblk(struct pmcraid_cmd
*cmd
, int index
)
334 struct pmcraid_ioarcb
*ioarcb
= &(cmd
->ioa_cb
->ioarcb
);
335 dma_addr_t dma_addr
= cmd
->ioa_cb_bus_addr
;
338 /* first time initialization (called from probe) */
340 offsetof(struct pmcraid_control_block
, ioasa
);
343 ioarcb
->response_handle
= cpu_to_le32(index
<< 2);
344 ioarcb
->ioarcb_bus_addr
= cpu_to_le64(dma_addr
);
345 ioarcb
->ioasa_bus_addr
= cpu_to_le64(dma_addr
+ ioasa_offset
);
346 ioarcb
->ioasa_len
= cpu_to_le16(sizeof(struct pmcraid_ioasa
));
348 /* re-initialization of various lengths, called once command is
351 memset(&cmd
->ioa_cb
->ioarcb
.cdb
, 0, PMCRAID_MAX_CDB_LEN
);
352 ioarcb
->request_flags0
= 0;
353 ioarcb
->request_flags1
= 0;
354 ioarcb
->cmd_timeout
= 0;
355 ioarcb
->ioarcb_bus_addr
&= (~0x1FULL
);
356 ioarcb
->ioadl_bus_addr
= 0;
357 ioarcb
->ioadl_length
= 0;
358 ioarcb
->data_transfer_length
= 0;
359 ioarcb
->add_cmd_param_length
= 0;
360 ioarcb
->add_cmd_param_offset
= 0;
361 cmd
->ioa_cb
->ioasa
.ioasc
= 0;
362 cmd
->ioa_cb
->ioasa
.residual_data_length
= 0;
363 cmd
->u
.time_left
= 0;
366 cmd
->cmd_done
= NULL
;
367 cmd
->scsi_cmd
= NULL
;
369 cmd
->completion_req
= 0;
371 init_timer(&cmd
->timer
);
375 * pmcraid_reinit_cmdblk - reinitialize a command block
377 * @cmd: pointer to struct pmcraid_cmd to be reinitialized
382 static void pmcraid_reinit_cmdblk(struct pmcraid_cmd
*cmd
)
384 pmcraid_init_cmdblk(cmd
, -1);
388 * pmcraid_get_free_cmd - get a free cmd block from command block pool
389 * @pinstance: adapter instance structure
392 * returns pointer to cmd block or NULL if no blocks are available
394 static struct pmcraid_cmd
*pmcraid_get_free_cmd(
395 struct pmcraid_instance
*pinstance
398 struct pmcraid_cmd
*cmd
= NULL
;
399 unsigned long lock_flags
;
401 /* free cmd block list is protected by free_pool_lock */
402 spin_lock_irqsave(&pinstance
->free_pool_lock
, lock_flags
);
404 if (!list_empty(&pinstance
->free_cmd_pool
)) {
405 cmd
= list_entry(pinstance
->free_cmd_pool
.next
,
406 struct pmcraid_cmd
, free_list
);
407 list_del(&cmd
->free_list
);
409 spin_unlock_irqrestore(&pinstance
->free_pool_lock
, lock_flags
);
411 /* Initialize the command block before giving it the caller */
413 pmcraid_reinit_cmdblk(cmd
);
418 * pmcraid_return_cmd - return a completed command block back into free pool
419 * @cmd: pointer to the command block
424 void pmcraid_return_cmd(struct pmcraid_cmd
*cmd
)
426 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
427 unsigned long lock_flags
;
429 spin_lock_irqsave(&pinstance
->free_pool_lock
, lock_flags
);
430 list_add_tail(&cmd
->free_list
, &pinstance
->free_cmd_pool
);
431 spin_unlock_irqrestore(&pinstance
->free_pool_lock
, lock_flags
);
435 * pmcraid_read_interrupts - reads IOA interrupts
437 * @pinstance: pointer to adapter instance structure
440 * interrupts read from IOA
442 static u32
pmcraid_read_interrupts(struct pmcraid_instance
*pinstance
)
444 return ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
448 * pmcraid_disable_interrupts - Masks and clears all specified interrupts
450 * @pinstance: pointer to per adapter instance structure
451 * @intrs: interrupts to disable
456 static void pmcraid_disable_interrupts(
457 struct pmcraid_instance
*pinstance
,
461 u32 gmask
= ioread32(pinstance
->int_regs
.global_interrupt_mask_reg
);
462 u32 nmask
= gmask
| GLOBAL_INTERRUPT_MASK
;
464 iowrite32(nmask
, pinstance
->int_regs
.global_interrupt_mask_reg
);
465 iowrite32(intrs
, pinstance
->int_regs
.ioa_host_interrupt_clr_reg
);
466 iowrite32(intrs
, pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
467 ioread32(pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
471 * pmcraid_enable_interrupts - Enables specified interrupts
473 * @pinstance: pointer to per adapter instance structure
474 * @intr: interrupts to enable
479 static void pmcraid_enable_interrupts(
480 struct pmcraid_instance
*pinstance
,
484 u32 gmask
= ioread32(pinstance
->int_regs
.global_interrupt_mask_reg
);
485 u32 nmask
= gmask
& (~GLOBAL_INTERRUPT_MASK
);
487 iowrite32(nmask
, pinstance
->int_regs
.global_interrupt_mask_reg
);
488 iowrite32(~intrs
, pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
489 ioread32(pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
491 pmcraid_info("enabled interrupts global mask = %x intr_mask = %x\n",
492 ioread32(pinstance
->int_regs
.global_interrupt_mask_reg
),
493 ioread32(pinstance
->int_regs
.ioa_host_interrupt_mask_reg
));
497 * pmcraid_reset_type - Determine the required reset type
498 * @pinstance: pointer to adapter instance structure
500 * IOA requires hard reset if any of the following conditions is true.
501 * 1. If HRRQ valid interrupt is not masked
502 * 2. IOA reset alert doorbell is set
503 * 3. If there are any error interrupts
505 static void pmcraid_reset_type(struct pmcraid_instance
*pinstance
)
511 mask
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
512 intrs
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
513 alerts
= ioread32(pinstance
->int_regs
.host_ioa_interrupt_reg
);
515 if ((mask
& INTRS_HRRQ_VALID
) == 0 ||
516 (alerts
& DOORBELL_IOA_RESET_ALERT
) ||
517 (intrs
& PMCRAID_ERROR_INTERRUPTS
)) {
518 pmcraid_info("IOA requires hard reset\n");
519 pinstance
->ioa_hard_reset
= 1;
522 /* If unit check is active, trigger the dump */
523 if (intrs
& INTRS_IOA_UNIT_CHECK
)
524 pinstance
->ioa_unit_check
= 1;
528 * pmcraid_bist_done - completion function for PCI BIST
529 * @cmd: pointer to reset command
534 static void pmcraid_ioa_reset(struct pmcraid_cmd
*);
536 static void pmcraid_bist_done(struct pmcraid_cmd
*cmd
)
538 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
539 unsigned long lock_flags
;
543 rc
= pci_read_config_word(pinstance
->pdev
, PCI_COMMAND
, &pci_reg
);
545 /* If PCI config space can't be accessed wait for another two secs */
546 if ((rc
!= PCIBIOS_SUCCESSFUL
|| (!(pci_reg
& PCI_COMMAND_MEMORY
))) &&
547 cmd
->u
.time_left
> 0) {
548 pmcraid_info("BIST not complete, waiting another 2 secs\n");
549 cmd
->timer
.expires
= jiffies
+ cmd
->u
.time_left
;
550 cmd
->u
.time_left
= 0;
551 cmd
->timer
.data
= (unsigned long)cmd
;
552 cmd
->timer
.function
=
553 (void (*)(unsigned long))pmcraid_bist_done
;
554 add_timer(&cmd
->timer
);
556 cmd
->u
.time_left
= 0;
557 pmcraid_info("BIST is complete, proceeding with reset\n");
558 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
559 pmcraid_ioa_reset(cmd
);
560 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
565 * pmcraid_start_bist - starts BIST
566 * @cmd: pointer to reset cmd
570 static void pmcraid_start_bist(struct pmcraid_cmd
*cmd
)
572 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
573 u32 doorbells
, intrs
;
575 /* proceed with bist and wait for 2 seconds */
576 iowrite32(DOORBELL_IOA_START_BIST
,
577 pinstance
->int_regs
.host_ioa_interrupt_reg
);
578 doorbells
= ioread32(pinstance
->int_regs
.host_ioa_interrupt_reg
);
579 intrs
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
580 pmcraid_info("doorbells after start bist: %x intrs: %x \n",
583 cmd
->u
.time_left
= msecs_to_jiffies(PMCRAID_BIST_TIMEOUT
);
584 cmd
->timer
.data
= (unsigned long)cmd
;
585 cmd
->timer
.expires
= jiffies
+ msecs_to_jiffies(PMCRAID_BIST_TIMEOUT
);
586 cmd
->timer
.function
= (void (*)(unsigned long))pmcraid_bist_done
;
587 add_timer(&cmd
->timer
);
591 * pmcraid_reset_alert_done - completion routine for reset_alert
592 * @cmd: pointer to command block used in reset sequence
596 static void pmcraid_reset_alert_done(struct pmcraid_cmd
*cmd
)
598 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
599 u32 status
= ioread32(pinstance
->ioa_status
);
600 unsigned long lock_flags
;
602 /* if the critical operation in progress bit is set or the wait times
603 * out, invoke reset engine to proceed with hard reset. If there is
604 * some more time to wait, restart the timer
606 if (((status
& INTRS_CRITICAL_OP_IN_PROGRESS
) == 0) ||
607 cmd
->u
.time_left
<= 0) {
608 pmcraid_info("critical op is reset proceeding with reset\n");
609 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
610 pmcraid_ioa_reset(cmd
);
611 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
613 pmcraid_info("critical op is not yet reset waiting again\n");
614 /* restart timer if some more time is available to wait */
615 cmd
->u
.time_left
-= PMCRAID_CHECK_FOR_RESET_TIMEOUT
;
616 cmd
->timer
.data
= (unsigned long)cmd
;
617 cmd
->timer
.expires
= jiffies
+ PMCRAID_CHECK_FOR_RESET_TIMEOUT
;
618 cmd
->timer
.function
=
619 (void (*)(unsigned long))pmcraid_reset_alert_done
;
620 add_timer(&cmd
->timer
);
625 * pmcraid_reset_alert - alerts IOA for a possible reset
626 * @cmd : command block to be used for reset sequence.
629 * returns 0 if pci config-space is accessible and RESET_DOORBELL is
630 * successfully written to IOA. Returns non-zero in case pci_config_space
633 static void pmcraid_reset_alert(struct pmcraid_cmd
*cmd
)
635 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
640 /* If we are able to access IOA PCI config space, alert IOA that we are
641 * going to reset it soon. This enables IOA to preserv persistent error
642 * data if any. In case memory space is not accessible, proceed with
645 rc
= pci_read_config_word(pinstance
->pdev
, PCI_COMMAND
, &pci_reg
);
646 if ((rc
== PCIBIOS_SUCCESSFUL
) && (pci_reg
& PCI_COMMAND_MEMORY
)) {
648 /* wait for IOA permission i.e until CRITICAL_OPERATION bit is
649 * reset IOA doesn't generate any interrupts when CRITICAL
650 * OPERATION bit is reset. A timer is started to wait for this
653 cmd
->u
.time_left
= PMCRAID_RESET_TIMEOUT
;
654 cmd
->timer
.data
= (unsigned long)cmd
;
655 cmd
->timer
.expires
= jiffies
+ PMCRAID_CHECK_FOR_RESET_TIMEOUT
;
656 cmd
->timer
.function
=
657 (void (*)(unsigned long))pmcraid_reset_alert_done
;
658 add_timer(&cmd
->timer
);
660 iowrite32(DOORBELL_IOA_RESET_ALERT
,
661 pinstance
->int_regs
.host_ioa_interrupt_reg
);
663 ioread32(pinstance
->int_regs
.host_ioa_interrupt_reg
);
664 pmcraid_info("doorbells after reset alert: %x\n", doorbells
);
666 pmcraid_info("PCI config is not accessible starting BIST\n");
667 pinstance
->ioa_state
= IOA_STATE_IN_HARD_RESET
;
668 pmcraid_start_bist(cmd
);
673 * pmcraid_timeout_handler - Timeout handler for internally generated ops
675 * @cmd : pointer to command structure, that got timedout
677 * This function blocks host requests and initiates an adapter reset.
682 static void pmcraid_timeout_handler(struct pmcraid_cmd
*cmd
)
684 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
685 unsigned long lock_flags
;
687 dev_err(&pinstance
->pdev
->dev
,
688 "Adapter being reset due to command timeout.\n");
690 /* Command timeouts result in hard reset sequence. The command that got
691 * timed out may be the one used as part of reset sequence. In this
692 * case restart reset sequence using the same command block even if
693 * reset is in progress. Otherwise fail this command and get a free
694 * command block to restart the reset sequence.
696 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
697 if (!pinstance
->ioa_reset_in_progress
) {
698 pinstance
->ioa_reset_attempts
= 0;
699 cmd
= pmcraid_get_free_cmd(pinstance
);
701 /* If we are out of command blocks, just return here itself.
702 * Some other command's timeout handler can do the reset job
705 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
707 pmcraid_err("no free cmnd block for timeout handler\n");
711 pinstance
->reset_cmd
= cmd
;
712 pinstance
->ioa_reset_in_progress
= 1;
714 pmcraid_info("reset is already in progress\n");
716 if (pinstance
->reset_cmd
!= cmd
) {
717 /* This command should have been given to IOA, this
718 * command will be completed by fail_outstanding_cmds
721 pmcraid_err("cmd is pending but reset in progress\n");
724 /* If this command was being used as part of the reset
725 * sequence, set cmd_done pointer to pmcraid_ioa_reset. This
726 * causes fail_outstanding_commands not to return the command
727 * block back to free pool
729 if (cmd
== pinstance
->reset_cmd
)
730 cmd
->cmd_done
= pmcraid_ioa_reset
;
734 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
735 scsi_block_requests(pinstance
->host
);
736 pmcraid_reset_alert(cmd
);
737 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
741 * pmcraid_internal_done - completion routine for internally generated cmds
743 * @cmd: command that got response from IOA
748 static void pmcraid_internal_done(struct pmcraid_cmd
*cmd
)
750 pmcraid_info("response internal cmd CDB[0] = %x ioasc = %x\n",
751 cmd
->ioa_cb
->ioarcb
.cdb
[0],
752 le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
));
754 /* Some of the internal commands are sent with callers blocking for the
755 * response. Same will be indicated as part of cmd->completion_req
756 * field. Response path needs to wake up any waiters waiting for cmd
757 * completion if this flag is set.
759 if (cmd
->completion_req
) {
760 cmd
->completion_req
= 0;
761 complete(&cmd
->wait_for_completion
);
764 /* most of the internal commands are completed by caller itself, so
765 * no need to return the command block back to free pool until we are
766 * required to do so (e.g once done with initialization).
770 pmcraid_return_cmd(cmd
);
775 * pmcraid_reinit_cfgtable_done - done function for cfg table reinitialization
777 * @cmd: command that got response from IOA
779 * This routine is called after driver re-reads configuration table due to a
780 * lost CCN. It returns the command block back to free pool and schedules
781 * worker thread to add/delete devices into the system.
786 static void pmcraid_reinit_cfgtable_done(struct pmcraid_cmd
*cmd
)
788 pmcraid_info("response internal cmd CDB[0] = %x ioasc = %x\n",
789 cmd
->ioa_cb
->ioarcb
.cdb
[0],
790 le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
));
794 pmcraid_return_cmd(cmd
);
796 pmcraid_info("scheduling worker for config table reinitialization\n");
797 schedule_work(&cmd
->drv_inst
->worker_q
);
801 * pmcraid_erp_done - Process completion of SCSI error response from device
802 * @cmd: pmcraid_command
804 * This function copies the sense buffer into the scsi_cmd struct and completes
805 * scsi_cmd by calling scsi_done function.
810 static void pmcraid_erp_done(struct pmcraid_cmd
*cmd
)
812 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
813 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
814 u32 ioasc
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
);
816 if (PMCRAID_IOASC_SENSE_KEY(ioasc
) > 0) {
817 scsi_cmd
->result
|= (DID_ERROR
<< 16);
818 pmcraid_err("command CDB[0] = %x failed with IOASC: 0x%08X\n",
819 cmd
->ioa_cb
->ioarcb
.cdb
[0], ioasc
);
822 /* if we had allocated sense buffers for request sense, copy the sense
823 * release the buffers
825 if (cmd
->sense_buffer
!= NULL
) {
826 memcpy(scsi_cmd
->sense_buffer
,
828 SCSI_SENSE_BUFFERSIZE
);
829 pci_free_consistent(pinstance
->pdev
,
830 SCSI_SENSE_BUFFERSIZE
,
831 cmd
->sense_buffer
, cmd
->sense_buffer_dma
);
832 cmd
->sense_buffer
= NULL
;
833 cmd
->sense_buffer_dma
= 0;
836 scsi_dma_unmap(scsi_cmd
);
837 pmcraid_return_cmd(cmd
);
838 scsi_cmd
->scsi_done(scsi_cmd
);
842 * pmcraid_fire_command - sends an IOA command to adapter
844 * This function adds the given block into pending command list
845 * and returns without waiting
847 * @cmd : command to be sent to the device
852 static void _pmcraid_fire_command(struct pmcraid_cmd
*cmd
)
854 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
855 unsigned long lock_flags
;
857 /* Add this command block to pending cmd pool. We do this prior to
858 * writting IOARCB to ioarrin because IOA might complete the command
859 * by the time we are about to add it to the list. Response handler
860 * (isr/tasklet) looks for cmb block in the pending pending list.
862 spin_lock_irqsave(&pinstance
->pending_pool_lock
, lock_flags
);
863 list_add_tail(&cmd
->free_list
, &pinstance
->pending_cmd_pool
);
864 spin_unlock_irqrestore(&pinstance
->pending_pool_lock
, lock_flags
);
865 atomic_inc(&pinstance
->outstanding_cmds
);
867 /* driver writes lower 32-bit value of IOARCB address only */
869 iowrite32(le32_to_cpu(cmd
->ioa_cb
->ioarcb
.ioarcb_bus_addr
),
874 * pmcraid_send_cmd - fires a command to IOA
876 * This function also sets up timeout function, and command completion
879 * @cmd: pointer to the command block to be fired to IOA
880 * @cmd_done: command completion function, called once IOA responds
881 * @timeout: timeout to wait for this command completion
882 * @timeout_func: timeout handler
887 static void pmcraid_send_cmd(
888 struct pmcraid_cmd
*cmd
,
889 void (*cmd_done
) (struct pmcraid_cmd
*),
890 unsigned long timeout
,
891 void (*timeout_func
) (struct pmcraid_cmd
*)
894 /* initialize done function */
895 cmd
->cmd_done
= cmd_done
;
898 /* setup timeout handler */
899 cmd
->timer
.data
= (unsigned long)cmd
;
900 cmd
->timer
.expires
= jiffies
+ timeout
;
901 cmd
->timer
.function
= (void (*)(unsigned long))timeout_func
;
902 add_timer(&cmd
->timer
);
905 /* fire the command to IOA */
906 _pmcraid_fire_command(cmd
);
910 * pmcraid_ioa_shutdown - sends SHUTDOWN command to ioa
912 * @cmd: pointer to the command block used as part of reset sequence
917 static void pmcraid_ioa_shutdown(struct pmcraid_cmd
*cmd
)
919 pmcraid_info("response for Cancel CCN CDB[0] = %x ioasc = %x\n",
920 cmd
->ioa_cb
->ioarcb
.cdb
[0],
921 le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
));
923 /* Note that commands sent during reset require next command to be sent
924 * to IOA. Hence reinit the done function as well as timeout function
926 pmcraid_reinit_cmdblk(cmd
);
927 cmd
->ioa_cb
->ioarcb
.request_type
= REQ_TYPE_IOACMD
;
928 cmd
->ioa_cb
->ioarcb
.resource_handle
=
929 cpu_to_le32(PMCRAID_IOA_RES_HANDLE
);
930 cmd
->ioa_cb
->ioarcb
.cdb
[0] = PMCRAID_IOA_SHUTDOWN
;
931 cmd
->ioa_cb
->ioarcb
.cdb
[1] = PMCRAID_SHUTDOWN_NORMAL
;
933 /* fire shutdown command to hardware. */
934 pmcraid_info("firing normal shutdown command (%d) to IOA\n",
935 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.response_handle
));
937 pmcraid_send_cmd(cmd
, pmcraid_ioa_reset
,
938 PMCRAID_SHUTDOWN_TIMEOUT
,
939 pmcraid_timeout_handler
);
943 * pmcraid_identify_hrrq - registers host rrq buffers with IOA
944 * @cmd: pointer to command block to be used for identify hrrq
947 * 0 in case of success, otherwise non-zero failure code
950 static void pmcraid_querycfg(struct pmcraid_cmd
*);
952 static void pmcraid_identify_hrrq(struct pmcraid_cmd
*cmd
)
954 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
955 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
957 __be64 hrrq_addr
= cpu_to_be64(pinstance
->hrrq_start_bus_addr
[index
]);
958 u32 hrrq_size
= cpu_to_be32(sizeof(u32
) * PMCRAID_MAX_CMD
);
960 pmcraid_reinit_cmdblk(cmd
);
962 /* Initialize ioarcb */
963 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
964 ioarcb
->resource_handle
= cpu_to_le32(PMCRAID_IOA_RES_HANDLE
);
966 /* initialize the hrrq number where IOA will respond to this command */
967 ioarcb
->hrrq_id
= index
;
968 ioarcb
->cdb
[0] = PMCRAID_IDENTIFY_HRRQ
;
969 ioarcb
->cdb
[1] = index
;
971 /* IOA expects 64-bit pci address to be written in B.E format
972 * (i.e cdb[2]=MSByte..cdb[9]=LSB.
974 pmcraid_info("HRRQ_IDENTIFY with hrrq:ioarcb => %llx:%llx\n",
975 hrrq_addr
, ioarcb
->ioarcb_bus_addr
);
977 memcpy(&(ioarcb
->cdb
[2]), &hrrq_addr
, sizeof(hrrq_addr
));
978 memcpy(&(ioarcb
->cdb
[10]), &hrrq_size
, sizeof(hrrq_size
));
980 /* Subsequent commands require HRRQ identification to be successful.
981 * Note that this gets called even during reset from SCSI mid-layer
984 pmcraid_send_cmd(cmd
, pmcraid_querycfg
,
985 PMCRAID_INTERNAL_TIMEOUT
,
986 pmcraid_timeout_handler
);
989 static void pmcraid_process_ccn(struct pmcraid_cmd
*cmd
);
990 static void pmcraid_process_ldn(struct pmcraid_cmd
*cmd
);
993 * pmcraid_send_hcam_cmd - send an initialized command block(HCAM) to IOA
995 * @cmd: initialized command block pointer
1000 static void pmcraid_send_hcam_cmd(struct pmcraid_cmd
*cmd
)
1002 if (cmd
->ioa_cb
->ioarcb
.cdb
[1] == PMCRAID_HCAM_CODE_CONFIG_CHANGE
)
1003 atomic_set(&(cmd
->drv_inst
->ccn
.ignore
), 0);
1005 atomic_set(&(cmd
->drv_inst
->ldn
.ignore
), 0);
1007 pmcraid_send_cmd(cmd
, cmd
->cmd_done
, 0, NULL
);
1011 * pmcraid_init_hcam - send an initialized command block(HCAM) to IOA
1013 * @pinstance: pointer to adapter instance structure
1017 * pointer to initialized pmcraid_cmd structure or NULL
1019 static struct pmcraid_cmd
*pmcraid_init_hcam
1021 struct pmcraid_instance
*pinstance
,
1025 struct pmcraid_cmd
*cmd
;
1026 struct pmcraid_ioarcb
*ioarcb
;
1027 struct pmcraid_ioadl_desc
*ioadl
;
1028 struct pmcraid_hostrcb
*hcam
;
1029 void (*cmd_done
) (struct pmcraid_cmd
*);
1033 cmd
= pmcraid_get_free_cmd(pinstance
);
1036 pmcraid_err("no free command blocks for hcam\n");
1040 if (type
== PMCRAID_HCAM_CODE_CONFIG_CHANGE
) {
1041 rcb_size
= sizeof(struct pmcraid_hcam_ccn
);
1042 cmd_done
= pmcraid_process_ccn
;
1043 dma
= pinstance
->ccn
.baddr
+ PMCRAID_AEN_HDR_SIZE
;
1044 hcam
= &pinstance
->ccn
;
1046 rcb_size
= sizeof(struct pmcraid_hcam_ldn
);
1047 cmd_done
= pmcraid_process_ldn
;
1048 dma
= pinstance
->ldn
.baddr
+ PMCRAID_AEN_HDR_SIZE
;
1049 hcam
= &pinstance
->ldn
;
1052 /* initialize command pointer used for HCAM registration */
1055 ioarcb
= &cmd
->ioa_cb
->ioarcb
;
1056 ioarcb
->ioadl_bus_addr
= cpu_to_le64((cmd
->ioa_cb_bus_addr
) +
1057 offsetof(struct pmcraid_ioarcb
,
1058 add_data
.u
.ioadl
[0]));
1059 ioarcb
->ioadl_length
= cpu_to_le32(sizeof(struct pmcraid_ioadl_desc
));
1060 ioadl
= ioarcb
->add_data
.u
.ioadl
;
1062 /* Initialize ioarcb */
1063 ioarcb
->request_type
= REQ_TYPE_HCAM
;
1064 ioarcb
->resource_handle
= cpu_to_le32(PMCRAID_IOA_RES_HANDLE
);
1065 ioarcb
->cdb
[0] = PMCRAID_HOST_CONTROLLED_ASYNC
;
1066 ioarcb
->cdb
[1] = type
;
1067 ioarcb
->cdb
[7] = (rcb_size
>> 8) & 0xFF;
1068 ioarcb
->cdb
[8] = (rcb_size
) & 0xFF;
1070 ioarcb
->data_transfer_length
= cpu_to_le32(rcb_size
);
1072 ioadl
[0].flags
|= cpu_to_le32(IOADL_FLAGS_READ_LAST
);
1073 ioadl
[0].data_len
= cpu_to_le32(rcb_size
);
1074 ioadl
[0].address
= cpu_to_le32(dma
);
1076 cmd
->cmd_done
= cmd_done
;
1081 * pmcraid_send_hcam - Send an HCAM to IOA
1082 * @pinstance: ioa config struct
1085 * This function will send a Host Controlled Async command to IOA.
1090 static void pmcraid_send_hcam(struct pmcraid_instance
*pinstance
, u8 type
)
1092 struct pmcraid_cmd
*cmd
= pmcraid_init_hcam(pinstance
, type
);
1093 pmcraid_send_hcam_cmd(cmd
);
1098 * pmcraid_prepare_cancel_cmd - prepares a command block to abort another
1100 * @cmd: pointer to cmd that is used as cancelling command
1101 * @cmd_to_cancel: pointer to the command that needs to be cancelled
1103 static void pmcraid_prepare_cancel_cmd(
1104 struct pmcraid_cmd
*cmd
,
1105 struct pmcraid_cmd
*cmd_to_cancel
1108 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
1109 __be64 ioarcb_addr
= cmd_to_cancel
->ioa_cb
->ioarcb
.ioarcb_bus_addr
;
1111 /* Get the resource handle to where the command to be aborted has been
1114 ioarcb
->resource_handle
= cmd_to_cancel
->ioa_cb
->ioarcb
.resource_handle
;
1115 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
1116 memset(ioarcb
->cdb
, 0, PMCRAID_MAX_CDB_LEN
);
1117 ioarcb
->cdb
[0] = PMCRAID_ABORT_CMD
;
1119 /* IOARCB address of the command to be cancelled is given in
1120 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in
1121 * IOARCB address are not masked.
1123 ioarcb_addr
= cpu_to_be64(ioarcb_addr
);
1124 memcpy(&(ioarcb
->cdb
[2]), &ioarcb_addr
, sizeof(ioarcb_addr
));
1128 * pmcraid_cancel_hcam - sends ABORT task to abort a given HCAM
1130 * @cmd: command to be used as cancelling command
1132 * @cmd_done: op done function for the cancelling command
1134 static void pmcraid_cancel_hcam(
1135 struct pmcraid_cmd
*cmd
,
1137 void (*cmd_done
) (struct pmcraid_cmd
*)
1140 struct pmcraid_instance
*pinstance
;
1141 struct pmcraid_hostrcb
*hcam
;
1143 pinstance
= cmd
->drv_inst
;
1144 hcam
= (type
== PMCRAID_HCAM_CODE_LOG_DATA
) ?
1145 &pinstance
->ldn
: &pinstance
->ccn
;
1147 /* prepare for cancelling previous hcam command. If the HCAM is
1148 * currently not pending with IOA, we would have hcam->cmd as non-null
1150 if (hcam
->cmd
== NULL
)
1153 pmcraid_prepare_cancel_cmd(cmd
, hcam
->cmd
);
1155 /* writing to IOARRIN must be protected by host_lock, as mid-layer
1156 * schedule queuecommand while we are doing this
1158 pmcraid_send_cmd(cmd
, cmd_done
,
1159 PMCRAID_INTERNAL_TIMEOUT
,
1160 pmcraid_timeout_handler
);
1164 * pmcraid_cancel_ccn - cancel CCN HCAM already registered with IOA
1166 * @cmd: command block to be used for cancelling the HCAM
1168 static void pmcraid_cancel_ccn(struct pmcraid_cmd
*cmd
)
1170 pmcraid_info("response for Cancel LDN CDB[0] = %x ioasc = %x\n",
1171 cmd
->ioa_cb
->ioarcb
.cdb
[0],
1172 le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
));
1174 pmcraid_reinit_cmdblk(cmd
);
1176 pmcraid_cancel_hcam(cmd
,
1177 PMCRAID_HCAM_CODE_CONFIG_CHANGE
,
1178 pmcraid_ioa_shutdown
);
1182 * pmcraid_cancel_ldn - cancel LDN HCAM already registered with IOA
1184 * @cmd: command block to be used for cancelling the HCAM
1186 static void pmcraid_cancel_ldn(struct pmcraid_cmd
*cmd
)
1188 pmcraid_cancel_hcam(cmd
,
1189 PMCRAID_HCAM_CODE_LOG_DATA
,
1190 pmcraid_cancel_ccn
);
1194 * pmcraid_expose_resource - check if the resource can be exposed to OS
1196 * @cfgte: pointer to configuration table entry of the resource
1199 * true if resource can be added to midlayer, false(0) otherwise
1201 static int pmcraid_expose_resource(struct pmcraid_config_table_entry
*cfgte
)
1205 if (cfgte
->resource_type
== RES_TYPE_VSET
)
1206 retval
= ((cfgte
->unique_flags1
& 0xFF) < 0xFE);
1207 else if (cfgte
->resource_type
== RES_TYPE_GSCSI
)
1208 retval
= (RES_BUS(cfgte
->resource_address
) !=
1209 PMCRAID_VIRTUAL_ENCL_BUS_ID
);
1213 /* attributes supported by pmcraid_event_family */
1215 PMCRAID_AEN_ATTR_UNSPEC
,
1216 PMCRAID_AEN_ATTR_EVENT
,
1217 __PMCRAID_AEN_ATTR_MAX
,
1219 #define PMCRAID_AEN_ATTR_MAX (__PMCRAID_AEN_ATTR_MAX - 1)
1221 /* commands supported by pmcraid_event_family */
1223 PMCRAID_AEN_CMD_UNSPEC
,
1224 PMCRAID_AEN_CMD_EVENT
,
1225 __PMCRAID_AEN_CMD_MAX
,
1227 #define PMCRAID_AEN_CMD_MAX (__PMCRAID_AEN_CMD_MAX - 1)
1229 static struct genl_family pmcraid_event_family
= {
1230 .id
= GENL_ID_GENERATE
,
1233 .maxattr
= PMCRAID_AEN_ATTR_MAX
1237 * pmcraid_netlink_init - registers pmcraid_event_family
1240 * 0 if the pmcraid_event_family is successfully registered
1241 * with netlink generic, non-zero otherwise
1243 static int pmcraid_netlink_init(void)
1247 result
= genl_register_family(&pmcraid_event_family
);
1252 pmcraid_info("registered NETLINK GENERIC group: %d\n",
1253 pmcraid_event_family
.id
);
1259 * pmcraid_netlink_release - unregisters pmcraid_event_family
1264 static void pmcraid_netlink_release(void)
1266 genl_unregister_family(&pmcraid_event_family
);
1270 * pmcraid_notify_aen - sends event msg to user space application
1271 * @pinstance: pointer to adapter instance structure
1275 * 0 if success, error value in case of any failure.
1277 static int pmcraid_notify_aen(struct pmcraid_instance
*pinstance
, u8 type
)
1279 struct sk_buff
*skb
;
1280 struct pmcraid_aen_msg
*aen_msg
;
1282 int data_size
, total_size
;
1286 if (type
== PMCRAID_HCAM_CODE_LOG_DATA
) {
1287 aen_msg
= pinstance
->ldn
.msg
;
1288 data_size
= pinstance
->ldn
.hcam
->data_len
;
1290 aen_msg
= pinstance
->ccn
.msg
;
1291 data_size
= pinstance
->ccn
.hcam
->data_len
;
1294 data_size
+= sizeof(struct pmcraid_hcam_hdr
);
1295 aen_msg
->hostno
= (pinstance
->host
->unique_id
<< 16 |
1296 MINOR(pinstance
->cdev
.dev
));
1297 aen_msg
->length
= data_size
;
1298 data_size
+= sizeof(*aen_msg
);
1300 total_size
= nla_total_size(data_size
);
1301 skb
= genlmsg_new(total_size
, GFP_ATOMIC
);
1305 pmcraid_err("Failed to allocate aen data SKB of size: %x\n",
1310 /* add the genetlink message header */
1311 msg_header
= genlmsg_put(skb
, 0, 0,
1312 &pmcraid_event_family
, 0,
1313 PMCRAID_AEN_CMD_EVENT
);
1315 pmcraid_err("failed to copy command details\n");
1320 result
= nla_put(skb
, PMCRAID_AEN_ATTR_EVENT
, data_size
, aen_msg
);
1323 pmcraid_err("failed to copy AEN attribute data \n");
1328 /* send genetlink multicast message to notify appplications */
1329 result
= genlmsg_end(skb
, msg_header
);
1332 pmcraid_err("genlmsg_end failed\n");
1338 genlmsg_multicast(skb
, 0, pmcraid_event_family
.id
, GFP_ATOMIC
);
1340 /* If there are no listeners, genlmsg_multicast may return non-zero
1344 pmcraid_info("failed to send %s event message %x!\n",
1345 type
== PMCRAID_HCAM_CODE_LOG_DATA
? "LDN" : "CCN",
1351 * pmcraid_handle_config_change - Handle a config change from the adapter
1352 * @pinstance: pointer to per adapter instance structure
1357 static void pmcraid_handle_config_change(struct pmcraid_instance
*pinstance
)
1359 struct pmcraid_config_table_entry
*cfg_entry
;
1360 struct pmcraid_hcam_ccn
*ccn_hcam
;
1361 struct pmcraid_cmd
*cmd
;
1362 struct pmcraid_cmd
*cfgcmd
;
1363 struct pmcraid_resource_entry
*res
= NULL
;
1365 unsigned long lock_flags
;
1366 unsigned long host_lock_flags
;
1369 ccn_hcam
= (struct pmcraid_hcam_ccn
*)pinstance
->ccn
.hcam
;
1370 cfg_entry
= &ccn_hcam
->cfg_entry
;
1373 ("CCN(%x): %x type: %x lost: %x flags: %x res: %x:%x:%x:%x\n",
1374 pinstance
->ccn
.hcam
->ilid
,
1375 pinstance
->ccn
.hcam
->op_code
,
1376 pinstance
->ccn
.hcam
->notification_type
,
1377 pinstance
->ccn
.hcam
->notification_lost
,
1378 pinstance
->ccn
.hcam
->flags
,
1379 pinstance
->host
->unique_id
,
1380 RES_IS_VSET(*cfg_entry
) ? PMCRAID_VSET_BUS_ID
:
1381 (RES_IS_GSCSI(*cfg_entry
) ? PMCRAID_PHYS_BUS_ID
:
1382 RES_BUS(cfg_entry
->resource_address
)),
1383 RES_IS_VSET(*cfg_entry
) ? cfg_entry
->unique_flags1
:
1384 RES_TARGET(cfg_entry
->resource_address
),
1385 RES_LUN(cfg_entry
->resource_address
));
1388 /* If this HCAM indicates a lost notification, read the config table */
1389 if (pinstance
->ccn
.hcam
->notification_lost
) {
1390 cfgcmd
= pmcraid_get_free_cmd(pinstance
);
1392 pmcraid_info("lost CCN, reading config table\b");
1393 pinstance
->reinit_cfg_table
= 1;
1394 pmcraid_querycfg(cfgcmd
);
1396 pmcraid_err("lost CCN, no free cmd for querycfg\n");
1398 goto out_notify_apps
;
1401 /* If this resource is not going to be added to mid-layer, just notify
1402 * applications and return
1404 if (!pmcraid_expose_resource(cfg_entry
))
1405 goto out_notify_apps
;
1407 spin_lock_irqsave(&pinstance
->resource_lock
, lock_flags
);
1408 list_for_each_entry(res
, &pinstance
->used_res_q
, queue
) {
1409 rc
= memcmp(&res
->cfg_entry
.resource_address
,
1410 &cfg_entry
->resource_address
,
1411 sizeof(cfg_entry
->resource_address
));
1420 /* If there are more number of resources than what driver can
1421 * manage, do not notify the applications about the CCN. Just
1422 * ignore this notifications and re-register the same HCAM
1424 if (list_empty(&pinstance
->free_res_q
)) {
1425 spin_unlock_irqrestore(&pinstance
->resource_lock
,
1427 pmcraid_err("too many resources attached\n");
1428 spin_lock_irqsave(pinstance
->host
->host_lock
,
1430 pmcraid_send_hcam(pinstance
,
1431 PMCRAID_HCAM_CODE_CONFIG_CHANGE
);
1432 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
1437 res
= list_entry(pinstance
->free_res_q
.next
,
1438 struct pmcraid_resource_entry
, queue
);
1440 list_del(&res
->queue
);
1441 res
->scsi_dev
= NULL
;
1442 res
->reset_progress
= 0;
1443 list_add_tail(&res
->queue
, &pinstance
->used_res_q
);
1446 memcpy(&res
->cfg_entry
, cfg_entry
,
1447 sizeof(struct pmcraid_config_table_entry
));
1449 if (pinstance
->ccn
.hcam
->notification_type
==
1450 NOTIFICATION_TYPE_ENTRY_DELETED
) {
1451 if (res
->scsi_dev
) {
1452 res
->change_detected
= RES_CHANGE_DEL
;
1453 res
->cfg_entry
.resource_handle
=
1454 PMCRAID_INVALID_RES_HANDLE
;
1455 schedule_work(&pinstance
->worker_q
);
1457 /* This may be one of the non-exposed resources */
1458 list_move_tail(&res
->queue
, &pinstance
->free_res_q
);
1460 } else if (!res
->scsi_dev
) {
1461 res
->change_detected
= RES_CHANGE_ADD
;
1462 schedule_work(&pinstance
->worker_q
);
1464 spin_unlock_irqrestore(&pinstance
->resource_lock
, lock_flags
);
1468 /* Notify configuration changes to registered applications.*/
1469 if (!pmcraid_disable_aen
)
1470 pmcraid_notify_aen(pinstance
, PMCRAID_HCAM_CODE_CONFIG_CHANGE
);
1472 cmd
= pmcraid_init_hcam(pinstance
, PMCRAID_HCAM_CODE_CONFIG_CHANGE
);
1474 pmcraid_send_hcam_cmd(cmd
);
1478 * pmcraid_get_error_info - return error string for an ioasc
1479 * @ioasc: ioasc code
1483 static struct pmcraid_ioasc_error
*pmcraid_get_error_info(u32 ioasc
)
1486 for (i
= 0; i
< ARRAY_SIZE(pmcraid_ioasc_error_table
); i
++) {
1487 if (pmcraid_ioasc_error_table
[i
].ioasc_code
== ioasc
)
1488 return &pmcraid_ioasc_error_table
[i
];
1494 * pmcraid_ioasc_logger - log IOASC information based user-settings
1495 * @ioasc: ioasc code
1496 * @cmd: pointer to command that resulted in 'ioasc'
1498 void pmcraid_ioasc_logger(u32 ioasc
, struct pmcraid_cmd
*cmd
)
1500 struct pmcraid_ioasc_error
*error_info
= pmcraid_get_error_info(ioasc
);
1502 if (error_info
== NULL
||
1503 cmd
->drv_inst
->current_log_level
< error_info
->log_level
)
1506 /* log the error string */
1507 pmcraid_err("cmd [%d] for resource %x failed with %x(%s)\n",
1508 cmd
->ioa_cb
->ioarcb
.cdb
[0],
1509 cmd
->ioa_cb
->ioarcb
.resource_handle
,
1510 le32_to_cpu(ioasc
), error_info
->error_string
);
1514 * pmcraid_handle_error_log - Handle a config change (error log) from the IOA
1516 * @pinstance: pointer to per adapter instance structure
1521 static void pmcraid_handle_error_log(struct pmcraid_instance
*pinstance
)
1523 struct pmcraid_hcam_ldn
*hcam_ldn
;
1526 hcam_ldn
= (struct pmcraid_hcam_ldn
*)pinstance
->ldn
.hcam
;
1529 ("LDN(%x): %x type: %x lost: %x flags: %x overlay id: %x\n",
1530 pinstance
->ldn
.hcam
->ilid
,
1531 pinstance
->ldn
.hcam
->op_code
,
1532 pinstance
->ldn
.hcam
->notification_type
,
1533 pinstance
->ldn
.hcam
->notification_lost
,
1534 pinstance
->ldn
.hcam
->flags
,
1535 pinstance
->ldn
.hcam
->overlay_id
);
1537 /* log only the errors, no need to log informational log entries */
1538 if (pinstance
->ldn
.hcam
->notification_type
!=
1539 NOTIFICATION_TYPE_ERROR_LOG
)
1542 if (pinstance
->ldn
.hcam
->notification_lost
==
1543 HOSTRCB_NOTIFICATIONS_LOST
)
1544 dev_err(&pinstance
->pdev
->dev
, "Error notifications lost\n");
1546 ioasc
= le32_to_cpu(hcam_ldn
->error_log
.fd_ioasc
);
1548 if (ioasc
== PMCRAID_IOASC_UA_BUS_WAS_RESET
||
1549 ioasc
== PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER
) {
1550 dev_err(&pinstance
->pdev
->dev
,
1551 "UnitAttention due to IOA Bus Reset\n");
1552 scsi_report_bus_reset(
1554 RES_BUS(hcam_ldn
->error_log
.fd_ra
));
1561 * pmcraid_process_ccn - Op done function for a CCN.
1562 * @cmd: pointer to command struct
1564 * This function is the op done function for a configuration
1565 * change notification
1570 static void pmcraid_process_ccn(struct pmcraid_cmd
*cmd
)
1572 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
1573 u32 ioasc
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
);
1574 unsigned long lock_flags
;
1576 pinstance
->ccn
.cmd
= NULL
;
1577 pmcraid_return_cmd(cmd
);
1579 /* If driver initiated IOA reset happened while this hcam was pending
1580 * with IOA, or IOA bringdown sequence is in progress, no need to
1581 * re-register the hcam
1583 if (ioasc
== PMCRAID_IOASC_IOA_WAS_RESET
||
1584 atomic_read(&pinstance
->ccn
.ignore
) == 1) {
1587 dev_err(&pinstance
->pdev
->dev
,
1588 "Host RCB (CCN) failed with IOASC: 0x%08X\n", ioasc
);
1589 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
1590 pmcraid_send_hcam(pinstance
, PMCRAID_HCAM_CODE_CONFIG_CHANGE
);
1591 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
1593 pmcraid_handle_config_change(pinstance
);
1598 * pmcraid_process_ldn - op done function for an LDN
1599 * @cmd: pointer to command block
1604 static void pmcraid_initiate_reset(struct pmcraid_instance
*);
1606 static void pmcraid_process_ldn(struct pmcraid_cmd
*cmd
)
1608 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
1609 struct pmcraid_hcam_ldn
*ldn_hcam
=
1610 (struct pmcraid_hcam_ldn
*)pinstance
->ldn
.hcam
;
1611 u32 ioasc
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
);
1612 u32 fd_ioasc
= le32_to_cpu(ldn_hcam
->error_log
.fd_ioasc
);
1613 unsigned long lock_flags
;
1615 /* return the command block back to freepool */
1616 pinstance
->ldn
.cmd
= NULL
;
1617 pmcraid_return_cmd(cmd
);
1619 /* If driver initiated IOA reset happened while this hcam was pending
1620 * with IOA, no need to re-register the hcam as reset engine will do it
1621 * once reset sequence is complete
1623 if (ioasc
== PMCRAID_IOASC_IOA_WAS_RESET
||
1624 atomic_read(&pinstance
->ccn
.ignore
) == 1) {
1626 } else if (!ioasc
) {
1627 pmcraid_handle_error_log(pinstance
);
1628 if (fd_ioasc
== PMCRAID_IOASC_NR_IOA_RESET_REQUIRED
) {
1629 spin_lock_irqsave(pinstance
->host
->host_lock
,
1631 pmcraid_initiate_reset(pinstance
);
1632 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
1637 dev_err(&pinstance
->pdev
->dev
,
1638 "Host RCB(LDN) failed with IOASC: 0x%08X\n", ioasc
);
1640 /* send netlink message for HCAM notification if enabled */
1641 if (!pmcraid_disable_aen
)
1642 pmcraid_notify_aen(pinstance
, PMCRAID_HCAM_CODE_LOG_DATA
);
1644 cmd
= pmcraid_init_hcam(pinstance
, PMCRAID_HCAM_CODE_LOG_DATA
);
1646 pmcraid_send_hcam_cmd(cmd
);
1650 * pmcraid_register_hcams - register HCAMs for CCN and LDN
1652 * @pinstance: pointer per adapter instance structure
1657 static void pmcraid_register_hcams(struct pmcraid_instance
*pinstance
)
1659 pmcraid_send_hcam(pinstance
, PMCRAID_HCAM_CODE_CONFIG_CHANGE
);
1660 pmcraid_send_hcam(pinstance
, PMCRAID_HCAM_CODE_LOG_DATA
);
1664 * pmcraid_unregister_hcams - cancel HCAMs registered already
1665 * @cmd: pointer to command used as part of reset sequence
1667 static void pmcraid_unregister_hcams(struct pmcraid_cmd
*cmd
)
1669 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
1671 /* During IOA bringdown, HCAM gets fired and tasklet proceeds with
1672 * handling hcam response though it is not necessary. In order to
1673 * prevent this, set 'ignore', so that bring-down sequence doesn't
1674 * re-send any more hcams
1676 atomic_set(&pinstance
->ccn
.ignore
, 1);
1677 atomic_set(&pinstance
->ldn
.ignore
, 1);
1679 /* If adapter reset was forced as part of runtime reset sequence,
1680 * start the reset sequence.
1682 if (pinstance
->force_ioa_reset
&& !pinstance
->ioa_bringdown
) {
1683 pinstance
->force_ioa_reset
= 0;
1684 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
1685 pmcraid_reset_alert(cmd
);
1689 /* Driver tries to cancel HCAMs by sending ABORT TASK for each HCAM
1690 * one after the other. So CCN cancellation will be triggered by
1691 * pmcraid_cancel_ldn itself.
1693 pmcraid_cancel_ldn(cmd
);
1697 * pmcraid_reset_enable_ioa - re-enable IOA after a hard reset
1698 * @pinstance: pointer to adapter instance structure
1700 * 1 if TRANSITION_TO_OPERATIONAL is active, otherwise 0
1702 static void pmcraid_reinit_buffers(struct pmcraid_instance
*);
1704 static int pmcraid_reset_enable_ioa(struct pmcraid_instance
*pinstance
)
1708 pmcraid_reinit_buffers(pinstance
);
1709 intrs
= pmcraid_read_interrupts(pinstance
);
1711 pmcraid_enable_interrupts(pinstance
, PMCRAID_PCI_INTERRUPTS
);
1713 if (intrs
& INTRS_TRANSITION_TO_OPERATIONAL
) {
1714 iowrite32(INTRS_TRANSITION_TO_OPERATIONAL
,
1715 pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
1716 iowrite32(INTRS_TRANSITION_TO_OPERATIONAL
,
1717 pinstance
->int_regs
.ioa_host_interrupt_clr_reg
);
1725 * pmcraid_soft_reset - performs a soft reset and makes IOA become ready
1726 * @cmd : pointer to reset command block
1731 static void pmcraid_soft_reset(struct pmcraid_cmd
*cmd
)
1733 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
1737 /* There will be an interrupt when Transition to Operational bit is
1738 * set so tasklet would execute next reset task. The timeout handler
1739 * would re-initiate a reset
1741 cmd
->cmd_done
= pmcraid_ioa_reset
;
1742 cmd
->timer
.data
= (unsigned long)cmd
;
1743 cmd
->timer
.expires
= jiffies
+
1744 msecs_to_jiffies(PMCRAID_TRANSOP_TIMEOUT
);
1745 cmd
->timer
.function
= (void (*)(unsigned long))pmcraid_timeout_handler
;
1747 if (!timer_pending(&cmd
->timer
))
1748 add_timer(&cmd
->timer
);
1750 /* Enable destructive diagnostics on IOA if it is not yet in
1753 doorbell
= DOORBELL_RUNTIME_RESET
|
1754 DOORBELL_ENABLE_DESTRUCTIVE_DIAGS
;
1756 iowrite32(doorbell
, pinstance
->int_regs
.host_ioa_interrupt_reg
);
1757 int_reg
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
1758 pmcraid_info("Waiting for IOA to become operational %x:%x\n",
1759 ioread32(pinstance
->int_regs
.host_ioa_interrupt_reg
),
1764 * pmcraid_get_dump - retrieves IOA dump in case of Unit Check interrupt
1766 * @pinstance: pointer to adapter instance structure
1771 static void pmcraid_get_dump(struct pmcraid_instance
*pinstance
)
1773 pmcraid_info("%s is not yet implemented\n", __func__
);
1777 * pmcraid_fail_outstanding_cmds - Fails all outstanding ops.
1778 * @pinstance: pointer to adapter instance structure
1780 * This function fails all outstanding ops. If they are submitted to IOA
1781 * already, it sends cancel all messages if IOA is still accepting IOARCBs,
1782 * otherwise just completes the commands and returns the cmd blocks to free
1788 static void pmcraid_fail_outstanding_cmds(struct pmcraid_instance
*pinstance
)
1790 struct pmcraid_cmd
*cmd
, *temp
;
1791 unsigned long lock_flags
;
1793 /* pending command list is protected by pending_pool_lock. Its
1794 * traversal must be done as within this lock
1796 spin_lock_irqsave(&pinstance
->pending_pool_lock
, lock_flags
);
1797 list_for_each_entry_safe(cmd
, temp
, &pinstance
->pending_cmd_pool
,
1799 list_del(&cmd
->free_list
);
1800 spin_unlock_irqrestore(&pinstance
->pending_pool_lock
,
1802 cmd
->ioa_cb
->ioasa
.ioasc
=
1803 cpu_to_le32(PMCRAID_IOASC_IOA_WAS_RESET
);
1804 cmd
->ioa_cb
->ioasa
.ilid
=
1805 cpu_to_be32(PMCRAID_DRIVER_ILID
);
1807 /* In case the command timer is still running */
1808 del_timer(&cmd
->timer
);
1810 /* If this is an IO command, complete it by invoking scsi_done
1811 * function. If this is one of the internal commands other
1812 * than pmcraid_ioa_reset and HCAM commands invoke cmd_done to
1815 if (cmd
->scsi_cmd
) {
1817 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
1818 __le32 resp
= cmd
->ioa_cb
->ioarcb
.response_handle
;
1820 scsi_cmd
->result
|= DID_ERROR
<< 16;
1822 scsi_dma_unmap(scsi_cmd
);
1823 pmcraid_return_cmd(cmd
);
1826 pmcraid_info("failing(%d) CDB[0] = %x result: %x\n",
1827 le32_to_cpu(resp
) >> 2,
1828 cmd
->ioa_cb
->ioarcb
.cdb
[0],
1830 scsi_cmd
->scsi_done(scsi_cmd
);
1831 } else if (cmd
->cmd_done
== pmcraid_internal_done
||
1832 cmd
->cmd_done
== pmcraid_erp_done
) {
1834 } else if (cmd
->cmd_done
!= pmcraid_ioa_reset
) {
1835 pmcraid_return_cmd(cmd
);
1838 atomic_dec(&pinstance
->outstanding_cmds
);
1839 spin_lock_irqsave(&pinstance
->pending_pool_lock
, lock_flags
);
1842 spin_unlock_irqrestore(&pinstance
->pending_pool_lock
, lock_flags
);
1846 * pmcraid_ioa_reset - Implementation of IOA reset logic
1848 * @cmd: pointer to the cmd block to be used for entire reset process
1850 * This function executes most of the steps required for IOA reset. This gets
1851 * called by user threads (modprobe/insmod/rmmod) timer, tasklet and midlayer's
1852 * 'eh_' thread. Access to variables used for controling the reset sequence is
1853 * synchronized using host lock. Various functions called during reset process
1854 * would make use of a single command block, pointer to which is also stored in
1855 * adapter instance structure.
1860 static void pmcraid_ioa_reset(struct pmcraid_cmd
*cmd
)
1862 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
1863 u8 reset_complete
= 0;
1865 pinstance
->ioa_reset_in_progress
= 1;
1867 if (pinstance
->reset_cmd
!= cmd
) {
1868 pmcraid_err("reset is called with different command block\n");
1869 pinstance
->reset_cmd
= cmd
;
1872 pmcraid_info("reset_engine: state = %d, command = %p\n",
1873 pinstance
->ioa_state
, cmd
);
1875 switch (pinstance
->ioa_state
) {
1877 case IOA_STATE_DEAD
:
1878 /* If IOA is offline, whatever may be the reset reason, just
1879 * return. callers might be waiting on the reset wait_q, wake
1882 pmcraid_err("IOA is offline no reset is possible\n");
1886 case IOA_STATE_IN_BRINGDOWN
:
1887 /* we enter here, once ioa shutdown command is processed by IOA
1888 * Alert IOA for a possible reset. If reset alert fails, IOA
1889 * goes through hard-reset
1891 pmcraid_disable_interrupts(pinstance
, ~0);
1892 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
1893 pmcraid_reset_alert(cmd
);
1896 case IOA_STATE_UNKNOWN
:
1897 /* We may be called during probe or resume. Some pre-processing
1898 * is required for prior to reset
1900 scsi_block_requests(pinstance
->host
);
1902 /* If asked to reset while IOA was processing responses or
1903 * there are any error responses then IOA may require
1906 if (pinstance
->ioa_hard_reset
== 0) {
1907 if (ioread32(pinstance
->ioa_status
) &
1908 INTRS_TRANSITION_TO_OPERATIONAL
) {
1909 pmcraid_info("sticky bit set, bring-up\n");
1910 pinstance
->ioa_state
= IOA_STATE_IN_BRINGUP
;
1911 pmcraid_reinit_cmdblk(cmd
);
1912 pmcraid_identify_hrrq(cmd
);
1914 pinstance
->ioa_state
= IOA_STATE_IN_SOFT_RESET
;
1915 pmcraid_soft_reset(cmd
);
1918 /* Alert IOA of a possible reset and wait for critical
1919 * operation in progress bit to reset
1921 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
1922 pmcraid_reset_alert(cmd
);
1926 case IOA_STATE_IN_RESET_ALERT
:
1927 /* If critical operation in progress bit is reset or wait gets
1928 * timed out, reset proceeds with starting BIST on the IOA.
1929 * pmcraid_ioa_hard_reset keeps a count of reset attempts. If
1930 * they are 3 or more, reset engine marks IOA dead and returns
1932 pinstance
->ioa_state
= IOA_STATE_IN_HARD_RESET
;
1933 pmcraid_start_bist(cmd
);
1936 case IOA_STATE_IN_HARD_RESET
:
1937 pinstance
->ioa_reset_attempts
++;
1939 /* retry reset if we haven't reached maximum allowed limit */
1940 if (pinstance
->ioa_reset_attempts
> PMCRAID_RESET_ATTEMPTS
) {
1941 pinstance
->ioa_reset_attempts
= 0;
1942 pmcraid_err("IOA didn't respond marking it as dead\n");
1943 pinstance
->ioa_state
= IOA_STATE_DEAD
;
1948 /* Once either bist or pci reset is done, restore PCI config
1949 * space. If this fails, proceed with hard reset again
1952 if (pci_restore_state(pinstance
->pdev
)) {
1953 pmcraid_info("config-space error resetting again\n");
1954 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
1955 pmcraid_reset_alert(cmd
);
1959 /* fail all pending commands */
1960 pmcraid_fail_outstanding_cmds(pinstance
);
1962 /* check if unit check is active, if so extract dump */
1963 if (pinstance
->ioa_unit_check
) {
1964 pmcraid_info("unit check is active\n");
1965 pinstance
->ioa_unit_check
= 0;
1966 pmcraid_get_dump(pinstance
);
1967 pinstance
->ioa_reset_attempts
--;
1968 pinstance
->ioa_state
= IOA_STATE_IN_RESET_ALERT
;
1969 pmcraid_reset_alert(cmd
);
1973 /* if the reset reason is to bring-down the ioa, we might be
1974 * done with the reset restore pci_config_space and complete
1977 if (pinstance
->ioa_bringdown
) {
1978 pmcraid_info("bringing down the adapter\n");
1979 pinstance
->ioa_shutdown_type
= SHUTDOWN_NONE
;
1980 pinstance
->ioa_bringdown
= 0;
1981 pinstance
->ioa_state
= IOA_STATE_UNKNOWN
;
1984 /* bring-up IOA, so proceed with soft reset
1985 * Reinitialize hrrq_buffers and their indices also
1986 * enable interrupts after a pci_restore_state
1988 if (pmcraid_reset_enable_ioa(pinstance
)) {
1989 pinstance
->ioa_state
= IOA_STATE_IN_BRINGUP
;
1990 pmcraid_info("bringing up the adapter\n");
1991 pmcraid_reinit_cmdblk(cmd
);
1992 pmcraid_identify_hrrq(cmd
);
1994 pinstance
->ioa_state
= IOA_STATE_IN_SOFT_RESET
;
1995 pmcraid_soft_reset(cmd
);
2000 case IOA_STATE_IN_SOFT_RESET
:
2001 /* TRANSITION TO OPERATIONAL is on so start initialization
2004 pmcraid_info("In softreset proceeding with bring-up\n");
2005 pinstance
->ioa_state
= IOA_STATE_IN_BRINGUP
;
2007 /* Initialization commands start with HRRQ identification. From
2008 * now on tasklet completes most of the commands as IOA is up
2009 * and intrs are enabled
2011 pmcraid_identify_hrrq(cmd
);
2014 case IOA_STATE_IN_BRINGUP
:
2015 /* we are done with bringing up of IOA, change the ioa_state to
2016 * operational and wake up any waiters
2018 pinstance
->ioa_state
= IOA_STATE_OPERATIONAL
;
2022 case IOA_STATE_OPERATIONAL
:
2024 /* When IOA is operational and a reset is requested, check for
2025 * the reset reason. If reset is to bring down IOA, unregister
2026 * HCAMs and initiate shutdown; if adapter reset is forced then
2027 * restart reset sequence again
2029 if (pinstance
->ioa_shutdown_type
== SHUTDOWN_NONE
&&
2030 pinstance
->force_ioa_reset
== 0) {
2033 if (pinstance
->ioa_shutdown_type
!= SHUTDOWN_NONE
)
2034 pinstance
->ioa_state
= IOA_STATE_IN_BRINGDOWN
;
2035 pmcraid_reinit_cmdblk(cmd
);
2036 pmcraid_unregister_hcams(cmd
);
2041 /* reset will be completed if ioa_state is either DEAD or UNKNOWN or
2042 * OPERATIONAL. Reset all control variables used during reset, wake up
2043 * any waiting threads and let the SCSI mid-layer send commands. Note
2044 * that host_lock must be held before invoking scsi_report_bus_reset.
2046 if (reset_complete
) {
2047 pinstance
->ioa_reset_in_progress
= 0;
2048 pinstance
->ioa_reset_attempts
= 0;
2049 pinstance
->reset_cmd
= NULL
;
2050 pinstance
->ioa_shutdown_type
= SHUTDOWN_NONE
;
2051 pinstance
->ioa_bringdown
= 0;
2052 pmcraid_return_cmd(cmd
);
2054 /* If target state is to bring up the adapter, proceed with
2055 * hcam registration and resource exposure to mid-layer.
2057 if (pinstance
->ioa_state
== IOA_STATE_OPERATIONAL
)
2058 pmcraid_register_hcams(pinstance
);
2060 wake_up_all(&pinstance
->reset_wait_q
);
2067 * pmcraid_initiate_reset - initiates reset sequence. This is called from
2068 * ISR/tasklet during error interrupts including IOA unit check. If reset
2069 * is already in progress, it just returns, otherwise initiates IOA reset
2070 * to bring IOA up to operational state.
2072 * @pinstance: pointer to adapter instance structure
2077 static void pmcraid_initiate_reset(struct pmcraid_instance
*pinstance
)
2079 struct pmcraid_cmd
*cmd
;
2081 /* If the reset is already in progress, just return, otherwise start
2082 * reset sequence and return
2084 if (!pinstance
->ioa_reset_in_progress
) {
2085 scsi_block_requests(pinstance
->host
);
2086 cmd
= pmcraid_get_free_cmd(pinstance
);
2089 pmcraid_err("no cmnd blocks for initiate_reset\n");
2093 pinstance
->ioa_shutdown_type
= SHUTDOWN_NONE
;
2094 pinstance
->reset_cmd
= cmd
;
2095 pinstance
->force_ioa_reset
= 1;
2096 pmcraid_ioa_reset(cmd
);
2101 * pmcraid_reset_reload - utility routine for doing IOA reset either to bringup
2103 * @pinstance: pointer adapter instance structure
2104 * @shutdown_type: shutdown type to be used NONE, NORMAL or ABRREV
2105 * @target_state: expected target state after reset
2107 * Note: This command initiates reset and waits for its completion. Hence this
2108 * should not be called from isr/timer/tasklet functions (timeout handlers,
2109 * error response handlers and interrupt handlers).
2112 * 1 in case ioa_state is not target_state, 0 otherwise.
2114 static int pmcraid_reset_reload(
2115 struct pmcraid_instance
*pinstance
,
2120 struct pmcraid_cmd
*reset_cmd
= NULL
;
2121 unsigned long lock_flags
;
2124 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
2126 if (pinstance
->ioa_reset_in_progress
) {
2127 pmcraid_info("reset_reload: reset is already in progress\n");
2129 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
2131 wait_event(pinstance
->reset_wait_q
,
2132 !pinstance
->ioa_reset_in_progress
);
2134 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
2136 if (pinstance
->ioa_state
== IOA_STATE_DEAD
) {
2137 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
2139 pmcraid_info("reset_reload: IOA is dead\n");
2141 } else if (pinstance
->ioa_state
== target_state
) {
2147 pmcraid_info("reset_reload: proceeding with reset\n");
2148 scsi_block_requests(pinstance
->host
);
2149 reset_cmd
= pmcraid_get_free_cmd(pinstance
);
2151 if (reset_cmd
== NULL
) {
2152 pmcraid_err("no free cmnd for reset_reload\n");
2153 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
2158 if (shutdown_type
== SHUTDOWN_NORMAL
)
2159 pinstance
->ioa_bringdown
= 1;
2161 pinstance
->ioa_shutdown_type
= shutdown_type
;
2162 pinstance
->reset_cmd
= reset_cmd
;
2163 pinstance
->force_ioa_reset
= reset
;
2164 pmcraid_info("reset_reload: initiating reset\n");
2165 pmcraid_ioa_reset(reset_cmd
);
2166 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
2167 pmcraid_info("reset_reload: waiting for reset to complete\n");
2168 wait_event(pinstance
->reset_wait_q
,
2169 !pinstance
->ioa_reset_in_progress
);
2171 pmcraid_info("reset_reload: reset is complete !! \n");
2172 scsi_unblock_requests(pinstance
->host
);
2173 if (pinstance
->ioa_state
== target_state
)
2181 * pmcraid_reset_bringdown - wrapper over pmcraid_reset_reload to bringdown IOA
2183 * @pinstance: pointer to adapter instance structure
2186 * whatever is returned from pmcraid_reset_reload
2188 static int pmcraid_reset_bringdown(struct pmcraid_instance
*pinstance
)
2190 return pmcraid_reset_reload(pinstance
,
2196 * pmcraid_reset_bringup - wrapper over pmcraid_reset_reload to bring up IOA
2198 * @pinstance: pointer to adapter instance structure
2201 * whatever is returned from pmcraid_reset_reload
2203 static int pmcraid_reset_bringup(struct pmcraid_instance
*pinstance
)
2205 return pmcraid_reset_reload(pinstance
,
2207 IOA_STATE_OPERATIONAL
);
2211 * pmcraid_request_sense - Send request sense to a device
2212 * @cmd: pmcraid command struct
2214 * This function sends a request sense to a device as a result of a check
2215 * condition. This method re-uses the same command block that failed earlier.
2217 static void pmcraid_request_sense(struct pmcraid_cmd
*cmd
)
2219 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
2220 struct pmcraid_ioadl_desc
*ioadl
= ioarcb
->add_data
.u
.ioadl
;
2222 /* allocate DMAable memory for sense buffers */
2223 cmd
->sense_buffer
= pci_alloc_consistent(cmd
->drv_inst
->pdev
,
2224 SCSI_SENSE_BUFFERSIZE
,
2225 &cmd
->sense_buffer_dma
);
2227 if (cmd
->sense_buffer
== NULL
) {
2229 ("couldn't allocate sense buffer for request sense\n");
2230 pmcraid_erp_done(cmd
);
2234 /* re-use the command block */
2235 memset(&cmd
->ioa_cb
->ioasa
, 0, sizeof(struct pmcraid_ioasa
));
2236 memset(ioarcb
->cdb
, 0, PMCRAID_MAX_CDB_LEN
);
2237 ioarcb
->request_flags0
= (SYNC_COMPLETE
|
2240 ioarcb
->request_type
= REQ_TYPE_SCSI
;
2241 ioarcb
->cdb
[0] = REQUEST_SENSE
;
2242 ioarcb
->cdb
[4] = SCSI_SENSE_BUFFERSIZE
;
2244 ioarcb
->ioadl_bus_addr
= cpu_to_le64((cmd
->ioa_cb_bus_addr
) +
2245 offsetof(struct pmcraid_ioarcb
,
2246 add_data
.u
.ioadl
[0]));
2247 ioarcb
->ioadl_length
= cpu_to_le32(sizeof(struct pmcraid_ioadl_desc
));
2249 ioarcb
->data_transfer_length
= cpu_to_le32(SCSI_SENSE_BUFFERSIZE
);
2251 ioadl
->address
= cpu_to_le64(cmd
->sense_buffer_dma
);
2252 ioadl
->data_len
= cpu_to_le32(SCSI_SENSE_BUFFERSIZE
);
2253 ioadl
->flags
= cpu_to_le32(IOADL_FLAGS_LAST_DESC
);
2255 /* request sense might be called as part of error response processing
2256 * which runs in tasklets context. It is possible that mid-layer might
2257 * schedule queuecommand during this time, hence, writting to IOARRIN
2258 * must be protect by host_lock
2260 pmcraid_send_cmd(cmd
, pmcraid_erp_done
,
2261 PMCRAID_REQUEST_SENSE_TIMEOUT
,
2262 pmcraid_timeout_handler
);
2266 * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error recovery
2267 * @cmd: command that failed
2268 * @sense: true if request_sense is required after cancel all
2270 * This function sends a cancel all to a device to clear the queue.
2272 static void pmcraid_cancel_all(struct pmcraid_cmd
*cmd
, u32 sense
)
2274 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
2275 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
2276 struct pmcraid_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
2277 void (*cmd_done
) (struct pmcraid_cmd
*) = sense
? pmcraid_erp_done
2278 : pmcraid_request_sense
;
2280 memset(ioarcb
->cdb
, 0, PMCRAID_MAX_CDB_LEN
);
2281 ioarcb
->request_flags0
= SYNC_OVERRIDE
;
2282 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
2283 ioarcb
->cdb
[0] = PMCRAID_CANCEL_ALL_REQUESTS
;
2285 if (RES_IS_GSCSI(res
->cfg_entry
))
2286 ioarcb
->cdb
[1] = PMCRAID_SYNC_COMPLETE_AFTER_CANCEL
;
2288 ioarcb
->ioadl_bus_addr
= 0;
2289 ioarcb
->ioadl_length
= 0;
2290 ioarcb
->data_transfer_length
= 0;
2291 ioarcb
->ioarcb_bus_addr
&= (~0x1FULL
);
2293 /* writing to IOARRIN must be protected by host_lock, as mid-layer
2294 * schedule queuecommand while we are doing this
2296 pmcraid_send_cmd(cmd
, cmd_done
,
2297 PMCRAID_REQUEST_SENSE_TIMEOUT
,
2298 pmcraid_timeout_handler
);
2302 * pmcraid_frame_auto_sense: frame fixed format sense information
2304 * @cmd: pointer to failing command block
2309 static void pmcraid_frame_auto_sense(struct pmcraid_cmd
*cmd
)
2311 u8
*sense_buf
= cmd
->scsi_cmd
->sense_buffer
;
2312 struct pmcraid_resource_entry
*res
= cmd
->scsi_cmd
->device
->hostdata
;
2313 struct pmcraid_ioasa
*ioasa
= &cmd
->ioa_cb
->ioasa
;
2314 u32 ioasc
= le32_to_cpu(ioasa
->ioasc
);
2315 u32 failing_lba
= 0;
2317 memset(sense_buf
, 0, SCSI_SENSE_BUFFERSIZE
);
2318 cmd
->scsi_cmd
->result
= SAM_STAT_CHECK_CONDITION
;
2320 if (RES_IS_VSET(res
->cfg_entry
) &&
2321 ioasc
== PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC
&&
2322 ioasa
->u
.vset
.failing_lba_hi
!= 0) {
2324 sense_buf
[0] = 0x72;
2325 sense_buf
[1] = PMCRAID_IOASC_SENSE_KEY(ioasc
);
2326 sense_buf
[2] = PMCRAID_IOASC_SENSE_CODE(ioasc
);
2327 sense_buf
[3] = PMCRAID_IOASC_SENSE_QUAL(ioasc
);
2331 sense_buf
[9] = 0x0A;
2332 sense_buf
[10] = 0x80;
2334 failing_lba
= le32_to_cpu(ioasa
->u
.vset
.failing_lba_hi
);
2336 sense_buf
[12] = (failing_lba
& 0xff000000) >> 24;
2337 sense_buf
[13] = (failing_lba
& 0x00ff0000) >> 16;
2338 sense_buf
[14] = (failing_lba
& 0x0000ff00) >> 8;
2339 sense_buf
[15] = failing_lba
& 0x000000ff;
2341 failing_lba
= le32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
2343 sense_buf
[16] = (failing_lba
& 0xff000000) >> 24;
2344 sense_buf
[17] = (failing_lba
& 0x00ff0000) >> 16;
2345 sense_buf
[18] = (failing_lba
& 0x0000ff00) >> 8;
2346 sense_buf
[19] = failing_lba
& 0x000000ff;
2348 sense_buf
[0] = 0x70;
2349 sense_buf
[2] = PMCRAID_IOASC_SENSE_KEY(ioasc
);
2350 sense_buf
[12] = PMCRAID_IOASC_SENSE_CODE(ioasc
);
2351 sense_buf
[13] = PMCRAID_IOASC_SENSE_QUAL(ioasc
);
2353 if (ioasc
== PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC
) {
2354 if (RES_IS_VSET(res
->cfg_entry
))
2356 le32_to_cpu(ioasa
->u
.
2357 vset
.failing_lba_lo
);
2358 sense_buf
[0] |= 0x80;
2359 sense_buf
[3] = (failing_lba
>> 24) & 0xff;
2360 sense_buf
[4] = (failing_lba
>> 16) & 0xff;
2361 sense_buf
[5] = (failing_lba
>> 8) & 0xff;
2362 sense_buf
[6] = failing_lba
& 0xff;
2365 sense_buf
[7] = 6; /* additional length */
2370 * pmcraid_error_handler - Error response handlers for a SCSI op
2371 * @cmd: pointer to pmcraid_cmd that has failed
2373 * This function determines whether or not to initiate ERP on the affected
2374 * device. This is called from a tasklet, which doesn't hold any locks.
2377 * 0 it caller can complete the request, otherwise 1 where in error
2378 * handler itself completes the request and returns the command block
2381 static int pmcraid_error_handler(struct pmcraid_cmd
*cmd
)
2383 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
2384 struct pmcraid_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
2385 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
2386 struct pmcraid_ioasa
*ioasa
= &cmd
->ioa_cb
->ioasa
;
2387 u32 ioasc
= le32_to_cpu(ioasa
->ioasc
);
2388 u32 masked_ioasc
= ioasc
& PMCRAID_IOASC_SENSE_MASK
;
2389 u32 sense_copied
= 0;
2392 pmcraid_info("resource pointer is NULL\n");
2396 /* If this was a SCSI read/write command keep count of errors */
2397 if (SCSI_CMD_TYPE(scsi_cmd
->cmnd
[0]) == SCSI_READ_CMD
)
2398 atomic_inc(&res
->read_failures
);
2399 else if (SCSI_CMD_TYPE(scsi_cmd
->cmnd
[0]) == SCSI_WRITE_CMD
)
2400 atomic_inc(&res
->write_failures
);
2402 if (!RES_IS_GSCSI(res
->cfg_entry
) &&
2403 masked_ioasc
!= PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR
) {
2404 pmcraid_frame_auto_sense(cmd
);
2407 /* Log IOASC/IOASA information based on user settings */
2408 pmcraid_ioasc_logger(ioasc
, cmd
);
2410 switch (masked_ioasc
) {
2412 case PMCRAID_IOASC_AC_TERMINATED_BY_HOST
:
2413 scsi_cmd
->result
|= (DID_ABORT
<< 16);
2416 case PMCRAID_IOASC_IR_INVALID_RESOURCE_HANDLE
:
2417 case PMCRAID_IOASC_HW_CANNOT_COMMUNICATE
:
2418 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
2421 case PMCRAID_IOASC_NR_SYNC_REQUIRED
:
2423 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
2426 case PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC
:
2427 scsi_cmd
->result
|= (DID_PASSTHROUGH
<< 16);
2430 case PMCRAID_IOASC_UA_BUS_WAS_RESET
:
2431 case PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER
:
2432 if (!res
->reset_progress
)
2433 scsi_report_bus_reset(pinstance
->host
,
2434 scsi_cmd
->device
->channel
);
2435 scsi_cmd
->result
|= (DID_ERROR
<< 16);
2438 case PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR
:
2439 scsi_cmd
->result
|= PMCRAID_IOASC_SENSE_STATUS(ioasc
);
2442 /* if check_condition is not active return with error otherwise
2443 * get/frame the sense buffer
2445 if (PMCRAID_IOASC_SENSE_STATUS(ioasc
) !=
2446 SAM_STAT_CHECK_CONDITION
&&
2447 PMCRAID_IOASC_SENSE_STATUS(ioasc
) != SAM_STAT_ACA_ACTIVE
)
2450 /* If we have auto sense data as part of IOASA pass it to
2453 if (ioasa
->auto_sense_length
!= 0) {
2454 short sense_len
= ioasa
->auto_sense_length
;
2455 int data_size
= min_t(u16
, le16_to_cpu(sense_len
),
2456 SCSI_SENSE_BUFFERSIZE
);
2458 memcpy(scsi_cmd
->sense_buffer
,
2464 if (RES_IS_GSCSI(res
->cfg_entry
)) {
2465 pmcraid_cancel_all(cmd
, sense_copied
);
2466 } else if (sense_copied
) {
2467 pmcraid_erp_done(cmd
);
2470 pmcraid_request_sense(cmd
);
2475 case PMCRAID_IOASC_NR_INIT_CMD_REQUIRED
:
2479 if (PMCRAID_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
2480 scsi_cmd
->result
|= (DID_ERROR
<< 16);
2487 * pmcraid_reset_device - device reset handler functions
2489 * @scsi_cmd: scsi command struct
2490 * @modifier: reset modifier indicating the reset sequence to be performed
2492 * This function issues a device reset to the affected device.
2493 * A LUN reset will be sent to the device first. If that does
2494 * not work, a target reset will be sent.
2499 static int pmcraid_reset_device(
2500 struct scsi_cmnd
*scsi_cmd
,
2501 unsigned long timeout
,
2505 struct pmcraid_cmd
*cmd
;
2506 struct pmcraid_instance
*pinstance
;
2507 struct pmcraid_resource_entry
*res
;
2508 struct pmcraid_ioarcb
*ioarcb
;
2509 unsigned long lock_flags
;
2513 (struct pmcraid_instance
*)scsi_cmd
->device
->host
->hostdata
;
2514 res
= scsi_cmd
->device
->hostdata
;
2517 pmcraid_err("reset_device: NULL resource pointer\n");
2521 /* If adapter is currently going through reset/reload, return failed.
2522 * This will force the mid-layer to call _eh_bus/host reset, which
2523 * will then go to sleep and wait for the reset to complete
2525 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
2526 if (pinstance
->ioa_reset_in_progress
||
2527 pinstance
->ioa_state
== IOA_STATE_DEAD
) {
2528 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
2532 res
->reset_progress
= 1;
2533 pmcraid_info("Resetting %s resource with addr %x\n",
2534 ((modifier
& RESET_DEVICE_LUN
) ? "LUN" :
2535 ((modifier
& RESET_DEVICE_TARGET
) ? "TARGET" : "BUS")),
2536 le32_to_cpu(res
->cfg_entry
.resource_address
));
2538 /* get a free cmd block */
2539 cmd
= pmcraid_get_free_cmd(pinstance
);
2542 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
2543 pmcraid_err("%s: no cmd blocks are available\n", __func__
);
2547 ioarcb
= &cmd
->ioa_cb
->ioarcb
;
2548 ioarcb
->resource_handle
= res
->cfg_entry
.resource_handle
;
2549 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
2550 ioarcb
->cdb
[0] = PMCRAID_RESET_DEVICE
;
2552 /* Initialize reset modifier bits */
2554 modifier
= ENABLE_RESET_MODIFIER
| modifier
;
2556 ioarcb
->cdb
[1] = modifier
;
2558 init_completion(&cmd
->wait_for_completion
);
2559 cmd
->completion_req
= 1;
2561 pmcraid_info("cmd(CDB[0] = %x) for %x with index = %d\n",
2562 cmd
->ioa_cb
->ioarcb
.cdb
[0],
2563 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.resource_handle
),
2564 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.response_handle
) >> 2);
2566 pmcraid_send_cmd(cmd
,
2567 pmcraid_internal_done
,
2569 pmcraid_timeout_handler
);
2571 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
2573 /* RESET_DEVICE command completes after all pending IOARCBs are
2574 * completed. Once this command is completed, pmcraind_internal_done
2575 * will wake up the 'completion' queue.
2577 wait_for_completion(&cmd
->wait_for_completion
);
2579 /* complete the command here itself and return the command block
2582 pmcraid_return_cmd(cmd
);
2583 res
->reset_progress
= 0;
2584 ioasc
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
);
2586 /* set the return value based on the returned ioasc */
2587 return PMCRAID_IOASC_SENSE_KEY(ioasc
) ? FAILED
: SUCCESS
;
2591 * _pmcraid_io_done - helper for pmcraid_io_done function
2593 * @cmd: pointer to pmcraid command struct
2594 * @reslen: residual data length to be set in the ioasa
2595 * @ioasc: ioasc either returned by IOA or set by driver itself.
2597 * This function is invoked by pmcraid_io_done to complete mid-layer
2601 * 0 if caller is required to return it to free_pool. Returns 1 if
2602 * caller need not worry about freeing command block as error handler
2603 * will take care of that.
2606 static int _pmcraid_io_done(struct pmcraid_cmd
*cmd
, int reslen
, int ioasc
)
2608 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
2611 scsi_set_resid(scsi_cmd
, reslen
);
2613 pmcraid_info("response(%d) CDB[0] = %x ioasc:result: %x:%x\n",
2614 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.response_handle
) >> 2,
2615 cmd
->ioa_cb
->ioarcb
.cdb
[0],
2616 ioasc
, scsi_cmd
->result
);
2618 if (PMCRAID_IOASC_SENSE_KEY(ioasc
) != 0)
2619 rc
= pmcraid_error_handler(cmd
);
2622 scsi_dma_unmap(scsi_cmd
);
2623 scsi_cmd
->scsi_done(scsi_cmd
);
2630 * pmcraid_io_done - SCSI completion function
2632 * @cmd: pointer to pmcraid command struct
2634 * This function is invoked by tasklet/mid-layer error handler to completing
2635 * the SCSI ops sent from mid-layer.
2641 static void pmcraid_io_done(struct pmcraid_cmd
*cmd
)
2643 u32 ioasc
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
);
2644 u32 reslen
= le32_to_cpu(cmd
->ioa_cb
->ioasa
.residual_data_length
);
2646 if (_pmcraid_io_done(cmd
, reslen
, ioasc
) == 0)
2647 pmcraid_return_cmd(cmd
);
2651 * pmcraid_abort_cmd - Aborts a single IOARCB already submitted to IOA
2653 * @cmd: command block of the command to be aborted
2656 * returns pointer to command structure used as cancelling cmd
2658 static struct pmcraid_cmd
*pmcraid_abort_cmd(struct pmcraid_cmd
*cmd
)
2660 struct pmcraid_cmd
*cancel_cmd
;
2661 struct pmcraid_instance
*pinstance
;
2662 struct pmcraid_resource_entry
*res
;
2664 pinstance
= (struct pmcraid_instance
*)cmd
->drv_inst
;
2665 res
= cmd
->scsi_cmd
->device
->hostdata
;
2667 cancel_cmd
= pmcraid_get_free_cmd(pinstance
);
2669 if (cancel_cmd
== NULL
) {
2670 pmcraid_err("%s: no cmd blocks are available\n", __func__
);
2674 pmcraid_prepare_cancel_cmd(cancel_cmd
, cmd
);
2676 pmcraid_info("aborting command CDB[0]= %x with index = %d\n",
2677 cmd
->ioa_cb
->ioarcb
.cdb
[0],
2678 cmd
->ioa_cb
->ioarcb
.response_handle
>> 2);
2680 init_completion(&cancel_cmd
->wait_for_completion
);
2681 cancel_cmd
->completion_req
= 1;
2683 pmcraid_info("command (%d) CDB[0] = %x for %x\n",
2684 le32_to_cpu(cancel_cmd
->ioa_cb
->ioarcb
.response_handle
) >> 2,
2685 cmd
->ioa_cb
->ioarcb
.cdb
[0],
2686 le32_to_cpu(cancel_cmd
->ioa_cb
->ioarcb
.resource_handle
));
2688 pmcraid_send_cmd(cancel_cmd
,
2689 pmcraid_internal_done
,
2690 PMCRAID_INTERNAL_TIMEOUT
,
2691 pmcraid_timeout_handler
);
2696 * pmcraid_abort_complete - Waits for ABORT TASK completion
2698 * @cancel_cmd: command block use as cancelling command
2701 * returns SUCCESS if ABORT TASK has good completion
2704 static int pmcraid_abort_complete(struct pmcraid_cmd
*cancel_cmd
)
2706 struct pmcraid_resource_entry
*res
;
2709 wait_for_completion(&cancel_cmd
->wait_for_completion
);
2710 res
= cancel_cmd
->u
.res
;
2711 cancel_cmd
->u
.res
= NULL
;
2712 ioasc
= le32_to_cpu(cancel_cmd
->ioa_cb
->ioasa
.ioasc
);
2714 /* If the abort task is not timed out we will get a Good completion
2715 * as sense_key, otherwise we may get one the following responses
2716 * due to subsquent bus reset or device reset. In case IOASC is
2717 * NR_SYNC_REQUIRED, set sync_reqd flag for the corresponding resource
2719 if (ioasc
== PMCRAID_IOASC_UA_BUS_WAS_RESET
||
2720 ioasc
== PMCRAID_IOASC_NR_SYNC_REQUIRED
) {
2721 if (ioasc
== PMCRAID_IOASC_NR_SYNC_REQUIRED
)
2726 /* complete the command here itself */
2727 pmcraid_return_cmd(cancel_cmd
);
2728 return PMCRAID_IOASC_SENSE_KEY(ioasc
) ? FAILED
: SUCCESS
;
2732 * pmcraid_eh_abort_handler - entry point for aborting a single task on errors
2734 * @scsi_cmd: scsi command struct given by mid-layer. When this is called
2735 * mid-layer ensures that no other commands are queued. This
2736 * never gets called under interrupt, but a separate eh thread.
2741 static int pmcraid_eh_abort_handler(struct scsi_cmnd
*scsi_cmd
)
2743 struct pmcraid_instance
*pinstance
;
2744 struct pmcraid_cmd
*cmd
;
2745 struct pmcraid_resource_entry
*res
;
2746 unsigned long host_lock_flags
;
2747 unsigned long pending_lock_flags
;
2748 struct pmcraid_cmd
*cancel_cmd
= NULL
;
2753 (struct pmcraid_instance
*)scsi_cmd
->device
->host
->hostdata
;
2755 dev_err(&pinstance
->pdev
->dev
,
2756 "I/O command timed out, aborting it.\n");
2758 res
= scsi_cmd
->device
->hostdata
;
2763 /* If we are currently going through reset/reload, return failed.
2764 * This will force the mid-layer to eventually call
2765 * pmcraid_eh_host_reset which will then go to sleep and wait for the
2768 spin_lock_irqsave(pinstance
->host
->host_lock
, host_lock_flags
);
2770 if (pinstance
->ioa_reset_in_progress
||
2771 pinstance
->ioa_state
== IOA_STATE_DEAD
) {
2772 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
2777 /* loop over pending cmd list to find cmd corresponding to this
2778 * scsi_cmd. Note that this command might not have been completed
2779 * already. locking: all pending commands are protected with
2780 * pending_pool_lock.
2782 spin_lock_irqsave(&pinstance
->pending_pool_lock
, pending_lock_flags
);
2783 list_for_each_entry(cmd
, &pinstance
->pending_cmd_pool
, free_list
) {
2785 if (cmd
->scsi_cmd
== scsi_cmd
) {
2791 spin_unlock_irqrestore(&pinstance
->pending_pool_lock
,
2792 pending_lock_flags
);
2794 /* If the command to be aborted was given to IOA and still pending with
2795 * it, send ABORT_TASK to abort this and wait for its completion
2798 cancel_cmd
= pmcraid_abort_cmd(cmd
);
2800 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
2804 cancel_cmd
->u
.res
= cmd
->scsi_cmd
->device
->hostdata
;
2805 rc
= pmcraid_abort_complete(cancel_cmd
);
2808 return cmd_found
? rc
: SUCCESS
;
2812 * pmcraid_eh_xxxx_reset_handler - bus/target/device reset handler callbacks
2814 * @scmd: pointer to scsi_cmd that was sent to the resource to be reset.
2816 * All these routines invokve pmcraid_reset_device with appropriate parameters.
2817 * Since these are called from mid-layer EH thread, no other IO will be queued
2818 * to the resource being reset. However, control path (IOCTL) may be active so
2819 * it is necessary to synchronize IOARRIN writes which pmcraid_reset_device
2820 * takes care by locking/unlocking host_lock.
2825 static int pmcraid_eh_device_reset_handler(struct scsi_cmnd
*scmd
)
2827 pmcraid_err("Doing device reset due to an I/O command timeout.\n");
2828 return pmcraid_reset_device(scmd
,
2829 PMCRAID_INTERNAL_TIMEOUT
,
2833 static int pmcraid_eh_bus_reset_handler(struct scsi_cmnd
*scmd
)
2835 pmcraid_err("Doing bus reset due to an I/O command timeout.\n");
2836 return pmcraid_reset_device(scmd
,
2837 PMCRAID_RESET_BUS_TIMEOUT
,
2841 static int pmcraid_eh_target_reset_handler(struct scsi_cmnd
*scmd
)
2843 pmcraid_err("Doing target reset due to an I/O command timeout.\n");
2844 return pmcraid_reset_device(scmd
,
2845 PMCRAID_INTERNAL_TIMEOUT
,
2846 RESET_DEVICE_TARGET
);
2850 * pmcraid_eh_host_reset_handler - adapter reset handler callback
2852 * @scmd: pointer to scsi_cmd that was sent to a resource of adapter
2854 * Initiates adapter reset to bring it up to operational state
2859 static int pmcraid_eh_host_reset_handler(struct scsi_cmnd
*scmd
)
2861 unsigned long interval
= 10000; /* 10 seconds interval */
2862 int waits
= jiffies_to_msecs(PMCRAID_RESET_HOST_TIMEOUT
) / interval
;
2863 struct pmcraid_instance
*pinstance
=
2864 (struct pmcraid_instance
*)(scmd
->device
->host
->hostdata
);
2867 /* wait for an additional 150 seconds just in case firmware could come
2868 * up and if it could complete all the pending commands excluding the
2869 * two HCAM (CCN and LDN).
2872 if (atomic_read(&pinstance
->outstanding_cmds
) <=
2873 PMCRAID_MAX_HCAM_CMD
)
2878 dev_err(&pinstance
->pdev
->dev
,
2879 "Adapter being reset due to an I/O command timeout.\n");
2880 return pmcraid_reset_bringup(pinstance
) == 0 ? SUCCESS
: FAILED
;
2884 * pmcraid_task_attributes - Translate SPI Q-Tags to task attributes
2885 * @scsi_cmd: scsi command struct
2888 * number of tags or 0 if the task is not tagged
2890 static u8
pmcraid_task_attributes(struct scsi_cmnd
*scsi_cmd
)
2895 if (scsi_populate_tag_msg(scsi_cmd
, tag
)) {
2897 case MSG_SIMPLE_TAG
:
2898 rc
= TASK_TAG_SIMPLE
;
2901 rc
= TASK_TAG_QUEUE_HEAD
;
2903 case MSG_ORDERED_TAG
:
2904 rc
= TASK_TAG_ORDERED
;
2914 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
2915 * @cmd: pmcraid command struct
2916 * @sgcount: count of scatter-gather elements
2919 * returns pointer pmcraid_ioadl_desc, initialized to point to internal
2920 * or external IOADLs
2922 struct pmcraid_ioadl_desc
*
2923 pmcraid_init_ioadls(struct pmcraid_cmd
*cmd
, int sgcount
)
2925 struct pmcraid_ioadl_desc
*ioadl
;
2926 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
2927 int ioadl_count
= 0;
2929 if (ioarcb
->add_cmd_param_length
)
2930 ioadl_count
= DIV_ROUND_UP(ioarcb
->add_cmd_param_length
, 16);
2931 ioarcb
->ioadl_length
=
2932 sizeof(struct pmcraid_ioadl_desc
) * sgcount
;
2934 if ((sgcount
+ ioadl_count
) > (ARRAY_SIZE(ioarcb
->add_data
.u
.ioadl
))) {
2935 /* external ioadls start at offset 0x80 from control_block
2936 * structure, re-using 24 out of 27 ioadls part of IOARCB.
2937 * It is necessary to indicate to firmware that driver is
2938 * using ioadls to be treated as external to IOARCB.
2940 ioarcb
->ioarcb_bus_addr
&= ~(0x1FULL
);
2941 ioarcb
->ioadl_bus_addr
=
2942 cpu_to_le64((cmd
->ioa_cb_bus_addr
) +
2943 offsetof(struct pmcraid_ioarcb
,
2944 add_data
.u
.ioadl
[3]));
2945 ioadl
= &ioarcb
->add_data
.u
.ioadl
[3];
2947 ioarcb
->ioadl_bus_addr
=
2948 cpu_to_le64((cmd
->ioa_cb_bus_addr
) +
2949 offsetof(struct pmcraid_ioarcb
,
2950 add_data
.u
.ioadl
[ioadl_count
]));
2952 ioadl
= &ioarcb
->add_data
.u
.ioadl
[ioadl_count
];
2953 ioarcb
->ioarcb_bus_addr
|=
2954 DIV_ROUND_CLOSEST(sgcount
+ ioadl_count
, 8);
2961 * pmcraid_build_ioadl - Build a scatter/gather list and map the buffer
2962 * @pinstance: pointer to adapter instance structure
2963 * @cmd: pmcraid command struct
2965 * This function is invoked by queuecommand entry point while sending a command
2966 * to firmware. This builds ioadl descriptors and sets up ioarcb fields.
2969 * 0 on success or -1 on failure
2971 static int pmcraid_build_ioadl(
2972 struct pmcraid_instance
*pinstance
,
2973 struct pmcraid_cmd
*cmd
2977 struct scatterlist
*sglist
;
2979 struct scsi_cmnd
*scsi_cmd
= cmd
->scsi_cmd
;
2980 struct pmcraid_ioarcb
*ioarcb
= &(cmd
->ioa_cb
->ioarcb
);
2981 struct pmcraid_ioadl_desc
*ioadl
= ioarcb
->add_data
.u
.ioadl
;
2983 u32 length
= scsi_bufflen(scsi_cmd
);
2988 nseg
= scsi_dma_map(scsi_cmd
);
2991 dev_err(&pinstance
->pdev
->dev
, "scsi_map_dma failed!\n");
2993 } else if (nseg
> PMCRAID_MAX_IOADLS
) {
2994 scsi_dma_unmap(scsi_cmd
);
2995 dev_err(&pinstance
->pdev
->dev
,
2996 "sg count is (%d) more than allowed!\n", nseg
);
3000 /* Initialize IOARCB data transfer length fields */
3001 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
)
3002 ioarcb
->request_flags0
|= TRANSFER_DIR_WRITE
;
3004 ioarcb
->request_flags0
|= NO_LINK_DESCS
;
3005 ioarcb
->data_transfer_length
= cpu_to_le32(length
);
3006 ioadl
= pmcraid_init_ioadls(cmd
, nseg
);
3008 /* Initialize IOADL descriptor addresses */
3009 scsi_for_each_sg(scsi_cmd
, sglist
, nseg
, i
) {
3010 ioadl
[i
].data_len
= cpu_to_le32(sg_dma_len(sglist
));
3011 ioadl
[i
].address
= cpu_to_le64(sg_dma_address(sglist
));
3014 /* setup last descriptor */
3015 ioadl
[i
- 1].flags
= cpu_to_le32(IOADL_FLAGS_LAST_DESC
);
3021 * pmcraid_free_sglist - Frees an allocated SG buffer list
3022 * @sglist: scatter/gather list pointer
3024 * Free a DMA'able memory previously allocated with pmcraid_alloc_sglist
3029 static void pmcraid_free_sglist(struct pmcraid_sglist
*sglist
)
3033 for (i
= 0; i
< sglist
->num_sg
; i
++)
3034 __free_pages(sg_page(&(sglist
->scatterlist
[i
])),
3041 * pmcraid_alloc_sglist - Allocates memory for a SG list
3042 * @buflen: buffer length
3044 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3048 * pointer to sglist / NULL on failure
3050 static struct pmcraid_sglist
*pmcraid_alloc_sglist(int buflen
)
3052 struct pmcraid_sglist
*sglist
;
3053 struct scatterlist
*scatterlist
;
3060 sg_size
= buflen
/ (PMCRAID_MAX_IOADLS
- 1);
3061 order
= (sg_size
> 0) ? get_order(sg_size
) : 0;
3062 bsize_elem
= PAGE_SIZE
* (1 << order
);
3064 /* Determine the actual number of sg entries needed */
3065 if (buflen
% bsize_elem
)
3066 num_elem
= (buflen
/ bsize_elem
) + 1;
3068 num_elem
= buflen
/ bsize_elem
;
3070 /* Allocate a scatter/gather list for the DMA */
3071 sglist
= kzalloc(sizeof(struct pmcraid_sglist
) +
3072 (sizeof(struct scatterlist
) * (num_elem
- 1)),
3078 scatterlist
= sglist
->scatterlist
;
3079 sg_init_table(scatterlist
, num_elem
);
3080 sglist
->order
= order
;
3081 sglist
->num_sg
= num_elem
;
3084 for (i
= 0; i
< num_elem
; i
++) {
3085 page
= alloc_pages(GFP_KERNEL
|GFP_DMA
, order
);
3087 for (j
= i
- 1; j
>= 0; j
--)
3088 __free_pages(sg_page(&scatterlist
[j
]), order
);
3093 sg_set_page(&scatterlist
[i
], page
,
3094 sg_size
< bsize_elem
? sg_size
: bsize_elem
, 0);
3095 sg_size
-= bsize_elem
;
3102 * pmcraid_copy_sglist - Copy user buffer to kernel buffer's SG list
3103 * @sglist: scatter/gather list pointer
3104 * @buffer: buffer pointer
3105 * @len: buffer length
3106 * @direction: data transfer direction
3108 * Copy a user buffer into a buffer allocated by pmcraid_alloc_sglist
3111 * 0 on success / other on failure
3113 static int pmcraid_copy_sglist(
3114 struct pmcraid_sglist
*sglist
,
3115 unsigned long buffer
,
3120 struct scatterlist
*scatterlist
;
3126 /* Determine the actual number of bytes per element */
3127 bsize_elem
= PAGE_SIZE
* (1 << sglist
->order
);
3129 scatterlist
= sglist
->scatterlist
;
3131 for (i
= 0; i
< (len
/ bsize_elem
); i
++, buffer
+= bsize_elem
) {
3132 struct page
*page
= sg_page(&scatterlist
[i
]);
3135 if (direction
== DMA_TO_DEVICE
)
3136 rc
= __copy_from_user(kaddr
,
3140 rc
= __copy_to_user((void *)buffer
, kaddr
, bsize_elem
);
3145 pmcraid_err("failed to copy user data into sg list\n");
3149 scatterlist
[i
].length
= bsize_elem
;
3152 if (len
% bsize_elem
) {
3153 struct page
*page
= sg_page(&scatterlist
[i
]);
3157 if (direction
== DMA_TO_DEVICE
)
3158 rc
= __copy_from_user(kaddr
,
3162 rc
= __copy_to_user((void *)buffer
,
3168 scatterlist
[i
].length
= len
% bsize_elem
;
3172 pmcraid_err("failed to copy user data into sg list\n");
3180 * pmcraid_queuecommand - Queue a mid-layer request
3181 * @scsi_cmd: scsi command struct
3182 * @done: done function
3184 * This function queues a request generated by the mid-layer. Midlayer calls
3185 * this routine within host->lock. Some of the functions called by queuecommand
3186 * would use cmd block queue locks (free_pool_lock and pending_pool_lock)
3190 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
3191 * SCSI_MLQUEUE_HOST_BUSY if host is busy
3193 static int pmcraid_queuecommand(
3194 struct scsi_cmnd
*scsi_cmd
,
3195 void (*done
) (struct scsi_cmnd
*)
3198 struct pmcraid_instance
*pinstance
;
3199 struct pmcraid_resource_entry
*res
;
3200 struct pmcraid_ioarcb
*ioarcb
;
3201 struct pmcraid_cmd
*cmd
;
3205 (struct pmcraid_instance
*)scsi_cmd
->device
->host
->hostdata
;
3207 scsi_cmd
->scsi_done
= done
;
3208 res
= scsi_cmd
->device
->hostdata
;
3209 scsi_cmd
->result
= (DID_OK
<< 16);
3211 /* if adapter is marked as dead, set result to DID_NO_CONNECT complete
3214 if (pinstance
->ioa_state
== IOA_STATE_DEAD
) {
3215 pmcraid_info("IOA is dead, but queuecommand is scheduled\n");
3216 scsi_cmd
->result
= (DID_NO_CONNECT
<< 16);
3217 scsi_cmd
->scsi_done(scsi_cmd
);
3221 /* If IOA reset is in progress, can't queue the commands */
3222 if (pinstance
->ioa_reset_in_progress
)
3223 return SCSI_MLQUEUE_HOST_BUSY
;
3225 /* initialize the command and IOARCB to be sent to IOA */
3226 cmd
= pmcraid_get_free_cmd(pinstance
);
3229 pmcraid_err("free command block is not available\n");
3230 return SCSI_MLQUEUE_HOST_BUSY
;
3233 cmd
->scsi_cmd
= scsi_cmd
;
3234 ioarcb
= &(cmd
->ioa_cb
->ioarcb
);
3235 memcpy(ioarcb
->cdb
, scsi_cmd
->cmnd
, scsi_cmd
->cmd_len
);
3236 ioarcb
->resource_handle
= res
->cfg_entry
.resource_handle
;
3237 ioarcb
->request_type
= REQ_TYPE_SCSI
;
3239 cmd
->cmd_done
= pmcraid_io_done
;
3241 if (RES_IS_GSCSI(res
->cfg_entry
) || RES_IS_VSET(res
->cfg_entry
)) {
3242 if (scsi_cmd
->underflow
== 0)
3243 ioarcb
->request_flags0
|= INHIBIT_UL_CHECK
;
3245 if (res
->sync_reqd
) {
3246 ioarcb
->request_flags0
|= SYNC_COMPLETE
;
3250 ioarcb
->request_flags0
|= NO_LINK_DESCS
;
3251 ioarcb
->request_flags1
|= pmcraid_task_attributes(scsi_cmd
);
3253 if (RES_IS_GSCSI(res
->cfg_entry
))
3254 ioarcb
->request_flags1
|= DELAY_AFTER_RESET
;
3257 rc
= pmcraid_build_ioadl(pinstance
, cmd
);
3259 pmcraid_info("command (%d) CDB[0] = %x for %x:%x:%x:%x\n",
3260 le32_to_cpu(ioarcb
->response_handle
) >> 2,
3261 scsi_cmd
->cmnd
[0], pinstance
->host
->unique_id
,
3262 RES_IS_VSET(res
->cfg_entry
) ? PMCRAID_VSET_BUS_ID
:
3263 PMCRAID_PHYS_BUS_ID
,
3264 RES_IS_VSET(res
->cfg_entry
) ?
3265 res
->cfg_entry
.unique_flags1
:
3266 RES_TARGET(res
->cfg_entry
.resource_address
),
3267 RES_LUN(res
->cfg_entry
.resource_address
));
3269 if (likely(rc
== 0)) {
3270 _pmcraid_fire_command(cmd
);
3272 pmcraid_err("queuecommand could not build ioadl\n");
3273 pmcraid_return_cmd(cmd
);
3274 rc
= SCSI_MLQUEUE_HOST_BUSY
;
3281 * pmcraid_open -char node "open" entry, allowed only users with admin access
3283 static int pmcraid_chr_open(struct inode
*inode
, struct file
*filep
)
3285 struct pmcraid_instance
*pinstance
;
3287 if (!capable(CAP_SYS_ADMIN
))
3290 /* Populate adapter instance * pointer for use by ioctl */
3291 pinstance
= container_of(inode
->i_cdev
, struct pmcraid_instance
, cdev
);
3292 filep
->private_data
= pinstance
;
3298 * pmcraid_release - char node "release" entry point
3300 static int pmcraid_chr_release(struct inode
*inode
, struct file
*filep
)
3302 struct pmcraid_instance
*pinstance
=
3303 ((struct pmcraid_instance
*)filep
->private_data
);
3305 filep
->private_data
= NULL
;
3306 fasync_helper(-1, filep
, 0, &pinstance
->aen_queue
);
3312 * pmcraid_fasync - Async notifier registration from applications
3314 * This function adds the calling process to a driver global queue. When an
3315 * event occurs, SIGIO will be sent to all processes in this queue.
3317 static int pmcraid_chr_fasync(int fd
, struct file
*filep
, int mode
)
3319 struct pmcraid_instance
*pinstance
;
3322 pinstance
= (struct pmcraid_instance
*)filep
->private_data
;
3323 mutex_lock(&pinstance
->aen_queue_lock
);
3324 rc
= fasync_helper(fd
, filep
, mode
, &pinstance
->aen_queue
);
3325 mutex_unlock(&pinstance
->aen_queue_lock
);
3332 * pmcraid_build_passthrough_ioadls - builds SG elements for passthrough
3333 * commands sent over IOCTL interface
3335 * @cmd : pointer to struct pmcraid_cmd
3336 * @buflen : length of the request buffer
3337 * @direction : data transfer direction
3340 * 0 on sucess, non-zero error code on failure
3342 static int pmcraid_build_passthrough_ioadls(
3343 struct pmcraid_cmd
*cmd
,
3348 struct pmcraid_sglist
*sglist
= NULL
;
3349 struct scatterlist
*sg
= NULL
;
3350 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
3351 struct pmcraid_ioadl_desc
*ioadl
;
3354 sglist
= pmcraid_alloc_sglist(buflen
);
3357 pmcraid_err("can't allocate memory for passthrough SGls\n");
3361 sglist
->num_dma_sg
= pci_map_sg(cmd
->drv_inst
->pdev
,
3362 sglist
->scatterlist
,
3363 sglist
->num_sg
, direction
);
3365 if (!sglist
->num_dma_sg
|| sglist
->num_dma_sg
> PMCRAID_MAX_IOADLS
) {
3366 dev_err(&cmd
->drv_inst
->pdev
->dev
,
3367 "Failed to map passthrough buffer!\n");
3368 pmcraid_free_sglist(sglist
);
3372 cmd
->sglist
= sglist
;
3373 ioarcb
->request_flags0
|= NO_LINK_DESCS
;
3375 ioadl
= pmcraid_init_ioadls(cmd
, sglist
->num_dma_sg
);
3377 /* Initialize IOADL descriptor addresses */
3378 for_each_sg(sglist
->scatterlist
, sg
, sglist
->num_dma_sg
, i
) {
3379 ioadl
[i
].data_len
= cpu_to_le32(sg_dma_len(sg
));
3380 ioadl
[i
].address
= cpu_to_le64(sg_dma_address(sg
));
3384 /* setup the last descriptor */
3385 ioadl
[i
- 1].flags
= cpu_to_le32(IOADL_FLAGS_LAST_DESC
);
3392 * pmcraid_release_passthrough_ioadls - release passthrough ioadls
3394 * @cmd: pointer to struct pmcraid_cmd for which ioadls were allocated
3395 * @buflen: size of the request buffer
3396 * @direction: data transfer direction
3399 * 0 on sucess, non-zero error code on failure
3401 static void pmcraid_release_passthrough_ioadls(
3402 struct pmcraid_cmd
*cmd
,
3407 struct pmcraid_sglist
*sglist
= cmd
->sglist
;
3410 pci_unmap_sg(cmd
->drv_inst
->pdev
,
3411 sglist
->scatterlist
,
3414 pmcraid_free_sglist(sglist
);
3420 * pmcraid_ioctl_passthrough - handling passthrough IOCTL commands
3422 * @pinstance: pointer to adapter instance structure
3424 * @arg: pointer to pmcraid_passthrough_buffer user buffer
3427 * 0 on sucess, non-zero error code on failure
3429 static long pmcraid_ioctl_passthrough(
3430 struct pmcraid_instance
*pinstance
,
3431 unsigned int ioctl_cmd
,
3432 unsigned int buflen
,
3436 struct pmcraid_passthrough_ioctl_buffer
*buffer
;
3437 struct pmcraid_ioarcb
*ioarcb
;
3438 struct pmcraid_cmd
*cmd
;
3439 struct pmcraid_cmd
*cancel_cmd
;
3440 unsigned long request_buffer
;
3441 unsigned long request_offset
;
3442 unsigned long lock_flags
;
3445 u8 access
, direction
;
3448 /* If IOA reset is in progress, wait 10 secs for reset to complete */
3449 if (pinstance
->ioa_reset_in_progress
) {
3450 rc
= wait_event_interruptible_timeout(
3451 pinstance
->reset_wait_q
,
3452 !pinstance
->ioa_reset_in_progress
,
3453 msecs_to_jiffies(10000));
3458 return -ERESTARTSYS
;
3461 /* If adapter is not in operational state, return error */
3462 if (pinstance
->ioa_state
!= IOA_STATE_OPERATIONAL
) {
3463 pmcraid_err("IOA is not operational\n");
3467 buffer_size
= sizeof(struct pmcraid_passthrough_ioctl_buffer
);
3468 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
3471 pmcraid_err("no memory for passthrough buffer\n");
3476 offsetof(struct pmcraid_passthrough_ioctl_buffer
, request_buffer
);
3478 request_buffer
= arg
+ request_offset
;
3480 rc
= __copy_from_user(buffer
,
3481 (struct pmcraid_passthrough_ioctl_buffer
*) arg
,
3482 sizeof(struct pmcraid_passthrough_ioctl_buffer
));
3484 pmcraid_err("ioctl: can't copy passthrough buffer\n");
3486 goto out_free_buffer
;
3489 request_size
= buffer
->ioarcb
.data_transfer_length
;
3491 if (buffer
->ioarcb
.request_flags0
& TRANSFER_DIR_WRITE
) {
3492 access
= VERIFY_READ
;
3493 direction
= DMA_TO_DEVICE
;
3495 access
= VERIFY_WRITE
;
3496 direction
= DMA_FROM_DEVICE
;
3499 if (request_size
> 0) {
3500 rc
= access_ok(access
, arg
, request_offset
+ request_size
);
3504 goto out_free_buffer
;
3508 /* check if we have any additional command parameters */
3509 if (buffer
->ioarcb
.add_cmd_param_length
> PMCRAID_ADD_CMD_PARAM_LEN
) {
3511 goto out_free_buffer
;
3514 cmd
= pmcraid_get_free_cmd(pinstance
);
3517 pmcraid_err("free command block is not available\n");
3519 goto out_free_buffer
;
3522 cmd
->scsi_cmd
= NULL
;
3523 ioarcb
= &(cmd
->ioa_cb
->ioarcb
);
3525 /* Copy the user-provided IOARCB stuff field by field */
3526 ioarcb
->resource_handle
= buffer
->ioarcb
.resource_handle
;
3527 ioarcb
->data_transfer_length
= buffer
->ioarcb
.data_transfer_length
;
3528 ioarcb
->cmd_timeout
= buffer
->ioarcb
.cmd_timeout
;
3529 ioarcb
->request_type
= buffer
->ioarcb
.request_type
;
3530 ioarcb
->request_flags0
= buffer
->ioarcb
.request_flags0
;
3531 ioarcb
->request_flags1
= buffer
->ioarcb
.request_flags1
;
3532 memcpy(ioarcb
->cdb
, buffer
->ioarcb
.cdb
, PMCRAID_MAX_CDB_LEN
);
3534 if (buffer
->ioarcb
.add_cmd_param_length
) {
3535 ioarcb
->add_cmd_param_length
=
3536 buffer
->ioarcb
.add_cmd_param_length
;
3537 ioarcb
->add_cmd_param_offset
=
3538 buffer
->ioarcb
.add_cmd_param_offset
;
3539 memcpy(ioarcb
->add_data
.u
.add_cmd_params
,
3540 buffer
->ioarcb
.add_data
.u
.add_cmd_params
,
3541 buffer
->ioarcb
.add_cmd_param_length
);
3545 rc
= pmcraid_build_passthrough_ioadls(cmd
,
3549 pmcraid_err("couldn't build passthrough ioadls\n");
3550 goto out_free_buffer
;
3554 /* If data is being written into the device, copy the data from user
3557 if (direction
== DMA_TO_DEVICE
&& request_size
> 0) {
3558 rc
= pmcraid_copy_sglist(cmd
->sglist
,
3563 pmcraid_err("failed to copy user buffer\n");
3564 goto out_free_sglist
;
3568 /* passthrough ioctl is a blocking command so, put the user to sleep
3569 * until timeout. Note that a timeout value of 0 means, do timeout.
3571 cmd
->cmd_done
= pmcraid_internal_done
;
3572 init_completion(&cmd
->wait_for_completion
);
3573 cmd
->completion_req
= 1;
3575 pmcraid_info("command(%d) (CDB[0] = %x) for %x\n",
3576 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.response_handle
) >> 2,
3577 cmd
->ioa_cb
->ioarcb
.cdb
[0],
3578 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.resource_handle
));
3580 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
3581 _pmcraid_fire_command(cmd
);
3582 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
3584 /* If command timeout is specified put caller to wait till that time,
3585 * otherwise it would be blocking wait. If command gets timed out, it
3588 if (buffer
->ioarcb
.cmd_timeout
== 0) {
3589 wait_for_completion(&cmd
->wait_for_completion
);
3590 } else if (!wait_for_completion_timeout(
3591 &cmd
->wait_for_completion
,
3592 msecs_to_jiffies(buffer
->ioarcb
.cmd_timeout
* 1000))) {
3594 pmcraid_info("aborting cmd %d (CDB[0] = %x) due to timeout\n",
3595 le32_to_cpu(cmd
->ioa_cb
->ioarcb
.response_handle
>> 2),
3596 cmd
->ioa_cb
->ioarcb
.cdb
[0]);
3599 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
3600 cancel_cmd
= pmcraid_abort_cmd(cmd
);
3601 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
3604 wait_for_completion(&cancel_cmd
->wait_for_completion
);
3605 pmcraid_return_cmd(cancel_cmd
);
3608 goto out_free_sglist
;
3611 /* If the command failed for any reason, copy entire IOASA buffer and
3612 * return IOCTL success. If copying IOASA to user-buffer fails, return
3615 if (le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
)) {
3619 offsetof(struct pmcraid_passthrough_ioctl_buffer
, ioasa
));
3621 pmcraid_info("command failed with %x\n",
3622 le32_to_cpu(cmd
->ioa_cb
->ioasa
.ioasc
));
3623 if (copy_to_user(ioasa
, &cmd
->ioa_cb
->ioasa
,
3624 sizeof(struct pmcraid_ioasa
))) {
3625 pmcraid_err("failed to copy ioasa buffer to user\n");
3629 /* If the data transfer was from device, copy the data onto user
3632 else if (direction
== DMA_FROM_DEVICE
&& request_size
> 0) {
3633 rc
= pmcraid_copy_sglist(cmd
->sglist
,
3638 pmcraid_err("failed to copy user buffer\n");
3644 pmcraid_release_passthrough_ioadls(cmd
, request_size
, direction
);
3645 pmcraid_return_cmd(cmd
);
3657 * pmcraid_ioctl_driver - ioctl handler for commands handled by driver itself
3659 * @pinstance: pointer to adapter instance structure
3660 * @cmd: ioctl command passed in
3661 * @buflen: length of user_buffer
3662 * @user_buffer: user buffer pointer
3665 * 0 in case of success, otherwise appropriate error code
3667 static long pmcraid_ioctl_driver(
3668 struct pmcraid_instance
*pinstance
,
3670 unsigned int buflen
,
3671 void __user
*user_buffer
3676 if (!access_ok(VERIFY_READ
, user_buffer
, _IOC_SIZE(cmd
))) {
3677 pmcraid_err("ioctl_driver: access fault in request buffer \n");
3682 case PMCRAID_IOCTL_RESET_ADAPTER
:
3683 pmcraid_reset_bringup(pinstance
);
3695 * pmcraid_check_ioctl_buffer - check for proper access to user buffer
3697 * @cmd: ioctl command
3699 * @hdr: pointer to kernel memory for pmcraid_ioctl_header
3702 * negetive error code if there are access issues, otherwise zero.
3703 * Upon success, returns ioctl header copied out of user buffer.
3706 static int pmcraid_check_ioctl_buffer(
3709 struct pmcraid_ioctl_header
*hdr
3713 int access
= VERIFY_READ
;
3715 if (copy_from_user(hdr
, arg
, sizeof(struct pmcraid_ioctl_header
))) {
3716 pmcraid_err("couldn't copy ioctl header from user buffer\n");
3720 /* check for valid driver signature */
3721 rc
= memcmp(hdr
->signature
,
3722 PMCRAID_IOCTL_SIGNATURE
,
3723 sizeof(hdr
->signature
));
3725 pmcraid_err("signature verification failed\n");
3729 /* buffer length can't be negetive */
3730 if (hdr
->buffer_length
< 0) {
3731 pmcraid_err("ioctl: invalid buffer length specified\n");
3735 /* check for appropriate buffer access */
3736 if ((_IOC_DIR(cmd
) & _IOC_READ
) == _IOC_READ
)
3737 access
= VERIFY_WRITE
;
3739 rc
= access_ok(access
,
3740 (arg
+ sizeof(struct pmcraid_ioctl_header
)),
3741 hdr
->buffer_length
);
3743 pmcraid_err("access failed for user buffer of size %d\n",
3744 hdr
->buffer_length
);
3752 * pmcraid_ioctl - char node ioctl entry point
3754 static long pmcraid_chr_ioctl(
3760 struct pmcraid_instance
*pinstance
= NULL
;
3761 struct pmcraid_ioctl_header
*hdr
= NULL
;
3762 int retval
= -ENOTTY
;
3764 hdr
= kmalloc(GFP_KERNEL
, sizeof(struct pmcraid_ioctl_header
));
3767 pmcraid_err("faile to allocate memory for ioctl header\n");
3771 retval
= pmcraid_check_ioctl_buffer(cmd
, (void *)arg
, hdr
);
3774 pmcraid_info("chr_ioctl: header check failed\n");
3779 pinstance
= (struct pmcraid_instance
*)filep
->private_data
;
3782 pmcraid_info("adapter instance is not found\n");
3787 switch (_IOC_TYPE(cmd
)) {
3789 case PMCRAID_PASSTHROUGH_IOCTL
:
3790 /* If ioctl code is to download microcode, we need to block
3791 * mid-layer requests.
3793 if (cmd
== PMCRAID_IOCTL_DOWNLOAD_MICROCODE
)
3794 scsi_block_requests(pinstance
->host
);
3796 retval
= pmcraid_ioctl_passthrough(pinstance
,
3801 if (cmd
== PMCRAID_IOCTL_DOWNLOAD_MICROCODE
)
3802 scsi_unblock_requests(pinstance
->host
);
3805 case PMCRAID_DRIVER_IOCTL
:
3806 arg
+= sizeof(struct pmcraid_ioctl_header
);
3807 retval
= pmcraid_ioctl_driver(pinstance
,
3810 (void __user
*)arg
);
3824 * File operations structure for management interface
3826 static const struct file_operations pmcraid_fops
= {
3827 .owner
= THIS_MODULE
,
3828 .open
= pmcraid_chr_open
,
3829 .release
= pmcraid_chr_release
,
3830 .fasync
= pmcraid_chr_fasync
,
3831 .unlocked_ioctl
= pmcraid_chr_ioctl
,
3832 #ifdef CONFIG_COMPAT
3833 .compat_ioctl
= pmcraid_chr_ioctl
,
3841 * pmcraid_show_log_level - Display adapter's error logging level
3842 * @dev: class device struct
3846 * number of bytes printed to buffer
3848 static ssize_t
pmcraid_show_log_level(
3850 struct device_attribute
*attr
,
3853 struct Scsi_Host
*shost
= class_to_shost(dev
);
3854 struct pmcraid_instance
*pinstance
=
3855 (struct pmcraid_instance
*)shost
->hostdata
;
3856 return snprintf(buf
, PAGE_SIZE
, "%d\n", pinstance
->current_log_level
);
3860 * pmcraid_store_log_level - Change the adapter's error logging level
3861 * @dev: class device struct
3866 * number of bytes printed to buffer
3868 static ssize_t
pmcraid_store_log_level(
3870 struct device_attribute
*attr
,
3875 struct Scsi_Host
*shost
;
3876 struct pmcraid_instance
*pinstance
;
3879 if (strict_strtoul(buf
, 10, &val
))
3881 /* log-level should be from 0 to 2 */
3885 shost
= class_to_shost(dev
);
3886 pinstance
= (struct pmcraid_instance
*)shost
->hostdata
;
3887 pinstance
->current_log_level
= val
;
3892 static struct device_attribute pmcraid_log_level_attr
= {
3894 .name
= "log_level",
3895 .mode
= S_IRUGO
| S_IWUSR
,
3897 .show
= pmcraid_show_log_level
,
3898 .store
= pmcraid_store_log_level
,
3902 * pmcraid_show_drv_version - Display driver version
3903 * @dev: class device struct
3907 * number of bytes printed to buffer
3909 static ssize_t
pmcraid_show_drv_version(
3911 struct device_attribute
*attr
,
3915 return snprintf(buf
, PAGE_SIZE
, "version: %s, build date: %s\n",
3916 PMCRAID_DRIVER_VERSION
, PMCRAID_DRIVER_DATE
);
3919 static struct device_attribute pmcraid_driver_version_attr
= {
3921 .name
= "drv_version",
3924 .show
= pmcraid_show_drv_version
,
3928 * pmcraid_show_io_adapter_id - Display driver assigned adapter id
3929 * @dev: class device struct
3933 * number of bytes printed to buffer
3935 static ssize_t
pmcraid_show_adapter_id(
3937 struct device_attribute
*attr
,
3941 struct Scsi_Host
*shost
= class_to_shost(dev
);
3942 struct pmcraid_instance
*pinstance
=
3943 (struct pmcraid_instance
*)shost
->hostdata
;
3944 u32 adapter_id
= (pinstance
->pdev
->bus
->number
<< 8) |
3945 pinstance
->pdev
->devfn
;
3946 u32 aen_group
= pmcraid_event_family
.id
;
3948 return snprintf(buf
, PAGE_SIZE
,
3949 "adapter id: %d\nminor: %d\naen group: %d\n",
3950 adapter_id
, MINOR(pinstance
->cdev
.dev
), aen_group
);
3953 static struct device_attribute pmcraid_adapter_id_attr
= {
3955 .name
= "adapter_id",
3956 .mode
= S_IRUGO
| S_IWUSR
,
3958 .show
= pmcraid_show_adapter_id
,
3961 static struct device_attribute
*pmcraid_host_attrs
[] = {
3962 &pmcraid_log_level_attr
,
3963 &pmcraid_driver_version_attr
,
3964 &pmcraid_adapter_id_attr
,
3969 /* host template structure for pmcraid driver */
3970 static struct scsi_host_template pmcraid_host_template
= {
3971 .module
= THIS_MODULE
,
3972 .name
= PMCRAID_DRIVER_NAME
,
3973 .queuecommand
= pmcraid_queuecommand
,
3974 .eh_abort_handler
= pmcraid_eh_abort_handler
,
3975 .eh_bus_reset_handler
= pmcraid_eh_bus_reset_handler
,
3976 .eh_target_reset_handler
= pmcraid_eh_target_reset_handler
,
3977 .eh_device_reset_handler
= pmcraid_eh_device_reset_handler
,
3978 .eh_host_reset_handler
= pmcraid_eh_host_reset_handler
,
3980 .slave_alloc
= pmcraid_slave_alloc
,
3981 .slave_configure
= pmcraid_slave_configure
,
3982 .slave_destroy
= pmcraid_slave_destroy
,
3983 .change_queue_depth
= pmcraid_change_queue_depth
,
3984 .change_queue_type
= pmcraid_change_queue_type
,
3985 .can_queue
= PMCRAID_MAX_IO_CMD
,
3987 .sg_tablesize
= PMCRAID_MAX_IOADLS
,
3988 .max_sectors
= PMCRAID_IOA_MAX_SECTORS
,
3989 .cmd_per_lun
= PMCRAID_MAX_CMD_PER_LUN
,
3990 .use_clustering
= ENABLE_CLUSTERING
,
3991 .shost_attrs
= pmcraid_host_attrs
,
3992 .proc_name
= PMCRAID_DRIVER_NAME
3996 * pmcraid_isr_common - Common interrupt handler routine
3998 * @pinstance: pointer to adapter instance
3999 * @intrs: active interrupts (contents of ioa_host_interrupt register)
4000 * @hrrq_id: Host RRQ index
4005 static void pmcraid_isr_common(
4006 struct pmcraid_instance
*pinstance
,
4012 (intrs
& INTRS_CRITICAL_OP_IN_PROGRESS
) ? intrs
4014 iowrite32(intrs_clear
,
4015 pinstance
->int_regs
.ioa_host_interrupt_clr_reg
);
4016 intrs
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
4018 /* hrrq valid bit was set, schedule tasklet to handle the response */
4019 if (intrs_clear
== INTRS_HRRQ_VALID
)
4020 tasklet_schedule(&(pinstance
->isr_tasklet
[hrrq_id
]));
4024 * pmcraid_isr - implements interrupt handling routine
4026 * @irq: interrupt vector number
4027 * @dev_id: pointer hrrq_vector
4030 * IRQ_HANDLED if interrupt is handled or IRQ_NONE if ignored
4032 static irqreturn_t
pmcraid_isr(int irq
, void *dev_id
)
4034 struct pmcraid_isr_param
*hrrq_vector
;
4035 struct pmcraid_instance
*pinstance
;
4036 unsigned long lock_flags
;
4039 /* In case of legacy interrupt mode where interrupts are shared across
4040 * isrs, it may be possible that the current interrupt is not from IOA
4043 printk(KERN_INFO
"%s(): NULL host pointer\n", __func__
);
4047 hrrq_vector
= (struct pmcraid_isr_param
*)dev_id
;
4048 pinstance
= hrrq_vector
->drv_inst
;
4050 /* Acquire the lock (currently host_lock) while processing interrupts.
4051 * This interval is small as most of the response processing is done by
4052 * tasklet without the lock.
4054 spin_lock_irqsave(pinstance
->host
->host_lock
, lock_flags
);
4055 intrs
= pmcraid_read_interrupts(pinstance
);
4057 if (unlikely((intrs
& PMCRAID_PCI_INTERRUPTS
) == 0)) {
4058 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
4062 /* Any error interrupts including unit_check, initiate IOA reset.
4063 * In case of unit check indicate to reset_sequence that IOA unit
4064 * checked and prepare for a dump during reset sequence
4066 if (intrs
& PMCRAID_ERROR_INTERRUPTS
) {
4068 if (intrs
& INTRS_IOA_UNIT_CHECK
)
4069 pinstance
->ioa_unit_check
= 1;
4072 pinstance
->int_regs
.ioa_host_interrupt_clr_reg
);
4073 pmcraid_err("ISR: error interrupts: %x initiating reset\n",
4075 intrs
= ioread32(pinstance
->int_regs
.ioa_host_interrupt_reg
);
4076 pmcraid_initiate_reset(pinstance
);
4078 pmcraid_isr_common(pinstance
, intrs
, hrrq_vector
->hrrq_id
);
4081 spin_unlock_irqrestore(pinstance
->host
->host_lock
, lock_flags
);
4088 * pmcraid_worker_function - worker thread function
4090 * @workp: pointer to struct work queue
4096 static void pmcraid_worker_function(struct work_struct
*workp
)
4098 struct pmcraid_instance
*pinstance
;
4099 struct pmcraid_resource_entry
*res
;
4100 struct pmcraid_resource_entry
*temp
;
4101 struct scsi_device
*sdev
;
4102 unsigned long lock_flags
;
4103 unsigned long host_lock_flags
;
4104 u8 bus
, target
, lun
;
4106 pinstance
= container_of(workp
, struct pmcraid_instance
, worker_q
);
4107 /* add resources only after host is added into system */
4108 if (!atomic_read(&pinstance
->expose_resources
))
4111 spin_lock_irqsave(&pinstance
->resource_lock
, lock_flags
);
4112 list_for_each_entry_safe(res
, temp
, &pinstance
->used_res_q
, queue
) {
4114 if (res
->change_detected
== RES_CHANGE_DEL
&& res
->scsi_dev
) {
4115 sdev
= res
->scsi_dev
;
4117 /* host_lock must be held before calling
4120 spin_lock_irqsave(pinstance
->host
->host_lock
,
4122 if (!scsi_device_get(sdev
)) {
4123 spin_unlock_irqrestore(
4124 pinstance
->host
->host_lock
,
4126 pmcraid_info("deleting %x from midlayer\n",
4127 res
->cfg_entry
.resource_address
);
4128 list_move_tail(&res
->queue
,
4129 &pinstance
->free_res_q
);
4130 spin_unlock_irqrestore(
4131 &pinstance
->resource_lock
,
4133 scsi_remove_device(sdev
);
4134 scsi_device_put(sdev
);
4135 spin_lock_irqsave(&pinstance
->resource_lock
,
4137 res
->change_detected
= 0;
4139 spin_unlock_irqrestore(
4140 pinstance
->host
->host_lock
,
4146 list_for_each_entry(res
, &pinstance
->used_res_q
, queue
) {
4148 if (res
->change_detected
== RES_CHANGE_ADD
) {
4150 if (!pmcraid_expose_resource(&res
->cfg_entry
))
4153 if (RES_IS_VSET(res
->cfg_entry
)) {
4154 bus
= PMCRAID_VSET_BUS_ID
;
4155 target
= res
->cfg_entry
.unique_flags1
;
4156 lun
= PMCRAID_VSET_LUN_ID
;
4158 bus
= PMCRAID_PHYS_BUS_ID
;
4161 res
->cfg_entry
.resource_address
);
4162 lun
= RES_LUN(res
->cfg_entry
.resource_address
);
4165 res
->change_detected
= 0;
4166 spin_unlock_irqrestore(&pinstance
->resource_lock
,
4168 scsi_add_device(pinstance
->host
, bus
, target
, lun
);
4169 spin_lock_irqsave(&pinstance
->resource_lock
,
4174 spin_unlock_irqrestore(&pinstance
->resource_lock
, lock_flags
);
4178 * pmcraid_tasklet_function - Tasklet function
4180 * @instance: pointer to msix param structure
4185 void pmcraid_tasklet_function(unsigned long instance
)
4187 struct pmcraid_isr_param
*hrrq_vector
;
4188 struct pmcraid_instance
*pinstance
;
4189 unsigned long hrrq_lock_flags
;
4190 unsigned long pending_lock_flags
;
4191 unsigned long host_lock_flags
;
4192 spinlock_t
*lockp
; /* hrrq buffer lock */
4197 hrrq_vector
= (struct pmcraid_isr_param
*)instance
;
4198 pinstance
= hrrq_vector
->drv_inst
;
4199 id
= hrrq_vector
->hrrq_id
;
4200 lockp
= &(pinstance
->hrrq_lock
[id
]);
4201 intrs
= pmcraid_read_interrupts(pinstance
);
4203 /* If interrupts was as part of the ioa initialization, clear and mask
4204 * it. Delete the timer and wakeup the reset engine to proceed with
4207 if (intrs
& INTRS_TRANSITION_TO_OPERATIONAL
) {
4208 iowrite32(INTRS_TRANSITION_TO_OPERATIONAL
,
4209 pinstance
->int_regs
.ioa_host_interrupt_mask_reg
);
4210 iowrite32(INTRS_TRANSITION_TO_OPERATIONAL
,
4211 pinstance
->int_regs
.ioa_host_interrupt_clr_reg
);
4213 if (pinstance
->reset_cmd
!= NULL
) {
4214 del_timer(&pinstance
->reset_cmd
->timer
);
4215 spin_lock_irqsave(pinstance
->host
->host_lock
,
4217 pinstance
->reset_cmd
->cmd_done(pinstance
->reset_cmd
);
4218 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
4224 /* loop through each of the commands responded by IOA. Each HRRQ buf is
4225 * protected by its own lock. Traversals must be done within this lock
4226 * as there may be multiple tasklets running on multiple CPUs. Note
4227 * that the lock is held just for picking up the response handle and
4228 * manipulating hrrq_curr/toggle_bit values.
4230 spin_lock_irqsave(lockp
, hrrq_lock_flags
);
4232 resp
= le32_to_cpu(*(pinstance
->hrrq_curr
[id
]));
4234 while ((resp
& HRRQ_TOGGLE_BIT
) ==
4235 pinstance
->host_toggle_bit
[id
]) {
4237 int cmd_index
= resp
>> 2;
4238 struct pmcraid_cmd
*cmd
= NULL
;
4240 if (cmd_index
< PMCRAID_MAX_CMD
) {
4241 cmd
= pinstance
->cmd_list
[cmd_index
];
4243 /* In case of invalid response handle, initiate IOA
4246 spin_unlock_irqrestore(lockp
, hrrq_lock_flags
);
4248 pmcraid_err("Invalid response %d initiating reset\n",
4251 spin_lock_irqsave(pinstance
->host
->host_lock
,
4253 pmcraid_initiate_reset(pinstance
);
4254 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
4257 spin_lock_irqsave(lockp
, hrrq_lock_flags
);
4261 if (pinstance
->hrrq_curr
[id
] < pinstance
->hrrq_end
[id
]) {
4262 pinstance
->hrrq_curr
[id
]++;
4264 pinstance
->hrrq_curr
[id
] = pinstance
->hrrq_start
[id
];
4265 pinstance
->host_toggle_bit
[id
] ^= 1u;
4268 spin_unlock_irqrestore(lockp
, hrrq_lock_flags
);
4270 spin_lock_irqsave(&pinstance
->pending_pool_lock
,
4271 pending_lock_flags
);
4272 list_del(&cmd
->free_list
);
4273 spin_unlock_irqrestore(&pinstance
->pending_pool_lock
,
4274 pending_lock_flags
);
4275 del_timer(&cmd
->timer
);
4276 atomic_dec(&pinstance
->outstanding_cmds
);
4278 if (cmd
->cmd_done
== pmcraid_ioa_reset
) {
4279 spin_lock_irqsave(pinstance
->host
->host_lock
,
4282 spin_unlock_irqrestore(pinstance
->host
->host_lock
,
4284 } else if (cmd
->cmd_done
!= NULL
) {
4287 /* loop over until we are done with all responses */
4288 spin_lock_irqsave(lockp
, hrrq_lock_flags
);
4289 resp
= le32_to_cpu(*(pinstance
->hrrq_curr
[id
]));
4292 spin_unlock_irqrestore(lockp
, hrrq_lock_flags
);
4296 * pmcraid_unregister_interrupt_handler - de-register interrupts handlers
4297 * @pinstance: pointer to adapter instance structure
4299 * This routine un-registers registered interrupt handler and
4300 * also frees irqs/vectors.
4306 void pmcraid_unregister_interrupt_handler(struct pmcraid_instance
*pinstance
)
4308 free_irq(pinstance
->pdev
->irq
, &(pinstance
->hrrq_vector
[0]));
4312 * pmcraid_register_interrupt_handler - registers interrupt handler
4313 * @pinstance: pointer to per-adapter instance structure
4316 * 0 on success, non-zero error code otherwise.
4319 pmcraid_register_interrupt_handler(struct pmcraid_instance
*pinstance
)
4321 struct pci_dev
*pdev
= pinstance
->pdev
;
4323 pinstance
->hrrq_vector
[0].hrrq_id
= 0;
4324 pinstance
->hrrq_vector
[0].drv_inst
= pinstance
;
4325 pinstance
->hrrq_vector
[0].vector
= 0;
4326 pinstance
->num_hrrq
= 1;
4327 return request_irq(pdev
->irq
, pmcraid_isr
, IRQF_SHARED
,
4328 PMCRAID_DRIVER_NAME
, &pinstance
->hrrq_vector
[0]);
4332 * pmcraid_release_cmd_blocks - release buufers allocated for command blocks
4333 * @pinstance: per adapter instance structure pointer
4334 * @max_index: number of buffer blocks to release
4340 pmcraid_release_cmd_blocks(struct pmcraid_instance
*pinstance
, int max_index
)
4343 for (i
= 0; i
< max_index
; i
++) {
4344 kmem_cache_free(pinstance
->cmd_cachep
, pinstance
->cmd_list
[i
]);
4345 pinstance
->cmd_list
[i
] = NULL
;
4347 kmem_cache_destroy(pinstance
->cmd_cachep
);
4348 pinstance
->cmd_cachep
= NULL
;
4352 * pmcraid_release_control_blocks - releases buffers alloced for control blocks
4353 * @pinstance: pointer to per adapter instance structure
4354 * @max_index: number of buffers (from 0 onwards) to release
4356 * This function assumes that the command blocks for which control blocks are
4357 * linked are not released.
4363 pmcraid_release_control_blocks(
4364 struct pmcraid_instance
*pinstance
,
4370 if (pinstance
->control_pool
== NULL
)
4373 for (i
= 0; i
< max_index
; i
++) {
4374 pci_pool_free(pinstance
->control_pool
,
4375 pinstance
->cmd_list
[i
]->ioa_cb
,
4376 pinstance
->cmd_list
[i
]->ioa_cb_bus_addr
);
4377 pinstance
->cmd_list
[i
]->ioa_cb
= NULL
;
4378 pinstance
->cmd_list
[i
]->ioa_cb_bus_addr
= 0;
4380 pci_pool_destroy(pinstance
->control_pool
);
4381 pinstance
->control_pool
= NULL
;
4385 * pmcraid_allocate_cmd_blocks - allocate memory for cmd block structures
4386 * @pinstance - pointer to per adapter instance structure
4388 * Allocates memory for command blocks using kernel slab allocator.
4391 * 0 in case of success; -ENOMEM in case of failure
4393 static int __devinit
4394 pmcraid_allocate_cmd_blocks(struct pmcraid_instance
*pinstance
)
4398 sprintf(pinstance
->cmd_pool_name
, "pmcraid_cmd_pool_%d",
4399 pinstance
->host
->unique_id
);
4402 pinstance
->cmd_cachep
= kmem_cache_create(
4403 pinstance
->cmd_pool_name
,
4404 sizeof(struct pmcraid_cmd
), 0,
4405 SLAB_HWCACHE_ALIGN
, NULL
);
4406 if (!pinstance
->cmd_cachep
)
4409 for (i
= 0; i
< PMCRAID_MAX_CMD
; i
++) {
4410 pinstance
->cmd_list
[i
] =
4411 kmem_cache_alloc(pinstance
->cmd_cachep
, GFP_KERNEL
);
4412 if (!pinstance
->cmd_list
[i
]) {
4413 pmcraid_release_cmd_blocks(pinstance
, i
);
4421 * pmcraid_allocate_control_blocks - allocates memory control blocks
4422 * @pinstance : pointer to per adapter instance structure
4424 * This function allocates PCI memory for DMAable buffers like IOARCB, IOADLs
4425 * and IOASAs. This is called after command blocks are already allocated.
4428 * 0 in case it can allocate all control blocks, otherwise -ENOMEM
4430 static int __devinit
4431 pmcraid_allocate_control_blocks(struct pmcraid_instance
*pinstance
)
4435 sprintf(pinstance
->ctl_pool_name
, "pmcraid_control_pool_%d",
4436 pinstance
->host
->unique_id
);
4438 pinstance
->control_pool
=
4439 pci_pool_create(pinstance
->ctl_pool_name
,
4441 sizeof(struct pmcraid_control_block
),
4442 PMCRAID_IOARCB_ALIGNMENT
, 0);
4444 if (!pinstance
->control_pool
)
4447 for (i
= 0; i
< PMCRAID_MAX_CMD
; i
++) {
4448 pinstance
->cmd_list
[i
]->ioa_cb
=
4450 pinstance
->control_pool
,
4452 &(pinstance
->cmd_list
[i
]->ioa_cb_bus_addr
));
4454 if (!pinstance
->cmd_list
[i
]->ioa_cb
) {
4455 pmcraid_release_control_blocks(pinstance
, i
);
4458 memset(pinstance
->cmd_list
[i
]->ioa_cb
, 0,
4459 sizeof(struct pmcraid_control_block
));
4465 * pmcraid_release_host_rrqs - release memory allocated for hrrq buffer(s)
4466 * @pinstance: pointer to per adapter instance structure
4467 * @maxindex: size of hrrq buffer pointer array
4473 pmcraid_release_host_rrqs(struct pmcraid_instance
*pinstance
, int maxindex
)
4476 for (i
= 0; i
< maxindex
; i
++) {
4478 pci_free_consistent(pinstance
->pdev
,
4479 HRRQ_ENTRY_SIZE
* PMCRAID_MAX_CMD
,
4480 pinstance
->hrrq_start
[i
],
4481 pinstance
->hrrq_start_bus_addr
[i
]);
4483 /* reset pointers and toggle bit to zeros */
4484 pinstance
->hrrq_start
[i
] = NULL
;
4485 pinstance
->hrrq_start_bus_addr
[i
] = 0;
4486 pinstance
->host_toggle_bit
[i
] = 0;
4491 * pmcraid_allocate_host_rrqs - Allocate and initialize host RRQ buffers
4492 * @pinstance: pointer to per adapter instance structure
4495 * 0 hrrq buffers are allocated, -ENOMEM otherwise.
4497 static int __devinit
4498 pmcraid_allocate_host_rrqs(struct pmcraid_instance
*pinstance
)
4501 int buf_count
= PMCRAID_MAX_CMD
/ pinstance
->num_hrrq
;
4503 for (i
= 0; i
< pinstance
->num_hrrq
; i
++) {
4504 int buffer_size
= HRRQ_ENTRY_SIZE
* buf_count
;
4506 pinstance
->hrrq_start
[i
] =
4507 pci_alloc_consistent(
4510 &(pinstance
->hrrq_start_bus_addr
[i
]));
4512 if (pinstance
->hrrq_start
[i
] == 0) {
4513 pmcraid_err("could not allocate host rrq: %d\n", i
);
4514 pmcraid_release_host_rrqs(pinstance
, i
);
4518 memset(pinstance
->hrrq_start
[i
], 0, buffer_size
);
4519 pinstance
->hrrq_curr
[i
] = pinstance
->hrrq_start
[i
];
4520 pinstance
->hrrq_end
[i
] =
4521 pinstance
->hrrq_start
[i
] + buf_count
- 1;
4522 pinstance
->host_toggle_bit
[i
] = 1;
4523 spin_lock_init(&pinstance
->hrrq_lock
[i
]);
4529 * pmcraid_release_hcams - release HCAM buffers
4531 * @pinstance: pointer to per adapter instance structure
4536 static void pmcraid_release_hcams(struct pmcraid_instance
*pinstance
)
4538 if (pinstance
->ccn
.msg
!= NULL
) {
4539 pci_free_consistent(pinstance
->pdev
,
4540 PMCRAID_AEN_HDR_SIZE
+
4541 sizeof(struct pmcraid_hcam_ccn
),
4543 pinstance
->ccn
.baddr
);
4545 pinstance
->ccn
.msg
= NULL
;
4546 pinstance
->ccn
.hcam
= NULL
;
4547 pinstance
->ccn
.baddr
= 0;
4550 if (pinstance
->ldn
.msg
!= NULL
) {
4551 pci_free_consistent(pinstance
->pdev
,
4552 PMCRAID_AEN_HDR_SIZE
+
4553 sizeof(struct pmcraid_hcam_ldn
),
4555 pinstance
->ldn
.baddr
);
4557 pinstance
->ldn
.msg
= NULL
;
4558 pinstance
->ldn
.hcam
= NULL
;
4559 pinstance
->ldn
.baddr
= 0;
4564 * pmcraid_allocate_hcams - allocates HCAM buffers
4565 * @pinstance : pointer to per adapter instance structure
4568 * 0 in case of successful allocation, non-zero otherwise
4570 static int pmcraid_allocate_hcams(struct pmcraid_instance
*pinstance
)
4572 pinstance
->ccn
.msg
= pci_alloc_consistent(
4574 PMCRAID_AEN_HDR_SIZE
+
4575 sizeof(struct pmcraid_hcam_ccn
),
4576 &(pinstance
->ccn
.baddr
));
4578 pinstance
->ldn
.msg
= pci_alloc_consistent(
4580 PMCRAID_AEN_HDR_SIZE
+
4581 sizeof(struct pmcraid_hcam_ldn
),
4582 &(pinstance
->ldn
.baddr
));
4584 if (pinstance
->ldn
.msg
== NULL
|| pinstance
->ccn
.msg
== NULL
) {
4585 pmcraid_release_hcams(pinstance
);
4587 pinstance
->ccn
.hcam
=
4588 (void *)pinstance
->ccn
.msg
+ PMCRAID_AEN_HDR_SIZE
;
4589 pinstance
->ldn
.hcam
=
4590 (void *)pinstance
->ldn
.msg
+ PMCRAID_AEN_HDR_SIZE
;
4592 atomic_set(&pinstance
->ccn
.ignore
, 0);
4593 atomic_set(&pinstance
->ldn
.ignore
, 0);
4596 return (pinstance
->ldn
.msg
== NULL
) ? -ENOMEM
: 0;
4600 * pmcraid_release_config_buffers - release config.table buffers
4601 * @pinstance: pointer to per adapter instance structure
4606 static void pmcraid_release_config_buffers(struct pmcraid_instance
*pinstance
)
4608 if (pinstance
->cfg_table
!= NULL
&&
4609 pinstance
->cfg_table_bus_addr
!= 0) {
4610 pci_free_consistent(pinstance
->pdev
,
4611 sizeof(struct pmcraid_config_table
),
4612 pinstance
->cfg_table
,
4613 pinstance
->cfg_table_bus_addr
);
4614 pinstance
->cfg_table
= NULL
;
4615 pinstance
->cfg_table_bus_addr
= 0;
4618 if (pinstance
->res_entries
!= NULL
) {
4621 for (i
= 0; i
< PMCRAID_MAX_RESOURCES
; i
++)
4622 list_del(&pinstance
->res_entries
[i
].queue
);
4623 kfree(pinstance
->res_entries
);
4624 pinstance
->res_entries
= NULL
;
4627 pmcraid_release_hcams(pinstance
);
4631 * pmcraid_allocate_config_buffers - allocates DMAable memory for config table
4632 * @pinstance : pointer to per adapter instance structure
4635 * 0 for successful allocation, -ENOMEM for any failure
4637 static int __devinit
4638 pmcraid_allocate_config_buffers(struct pmcraid_instance
*pinstance
)
4642 pinstance
->res_entries
=
4643 kzalloc(sizeof(struct pmcraid_resource_entry
) *
4644 PMCRAID_MAX_RESOURCES
, GFP_KERNEL
);
4646 if (NULL
== pinstance
->res_entries
) {
4647 pmcraid_err("failed to allocate memory for resource table\n");
4651 for (i
= 0; i
< PMCRAID_MAX_RESOURCES
; i
++)
4652 list_add_tail(&pinstance
->res_entries
[i
].queue
,
4653 &pinstance
->free_res_q
);
4655 pinstance
->cfg_table
=
4656 pci_alloc_consistent(pinstance
->pdev
,
4657 sizeof(struct pmcraid_config_table
),
4658 &pinstance
->cfg_table_bus_addr
);
4660 if (NULL
== pinstance
->cfg_table
) {
4661 pmcraid_err("couldn't alloc DMA memory for config table\n");
4662 pmcraid_release_config_buffers(pinstance
);
4666 if (pmcraid_allocate_hcams(pinstance
)) {
4667 pmcraid_err("could not alloc DMA memory for HCAMS\n");
4668 pmcraid_release_config_buffers(pinstance
);
4676 * pmcraid_init_tasklets - registers tasklets for response handling
4678 * @pinstance: pointer adapter instance structure
4683 static void pmcraid_init_tasklets(struct pmcraid_instance
*pinstance
)
4686 for (i
= 0; i
< pinstance
->num_hrrq
; i
++)
4687 tasklet_init(&pinstance
->isr_tasklet
[i
],
4688 pmcraid_tasklet_function
,
4689 (unsigned long)&pinstance
->hrrq_vector
[i
]);
4693 * pmcraid_kill_tasklets - destroys tasklets registered for response handling
4695 * @pinstance: pointer to adapter instance structure
4700 static void pmcraid_kill_tasklets(struct pmcraid_instance
*pinstance
)
4703 for (i
= 0; i
< pinstance
->num_hrrq
; i
++)
4704 tasklet_kill(&pinstance
->isr_tasklet
[i
]);
4708 * pmcraid_init_buffers - allocates memory and initializes various structures
4709 * @pinstance: pointer to per adapter instance structure
4711 * This routine pre-allocates memory based on the type of block as below:
4712 * cmdblocks(PMCRAID_MAX_CMD): kernel memory using kernel's slab_allocator,
4713 * IOARCBs(PMCRAID_MAX_CMD) : DMAable memory, using pci pool allocator
4714 * config-table entries : DMAable memory using pci_alloc_consistent
4715 * HostRRQs : DMAable memory, using pci_alloc_consistent
4718 * 0 in case all of the blocks are allocated, -ENOMEM otherwise.
4720 static int __devinit
pmcraid_init_buffers(struct pmcraid_instance
*pinstance
)
4724 if (pmcraid_allocate_host_rrqs(pinstance
)) {
4725 pmcraid_err("couldn't allocate memory for %d host rrqs\n",
4726 pinstance
->num_hrrq
);
4730 if (pmcraid_allocate_config_buffers(pinstance
)) {
4731 pmcraid_err("couldn't allocate memory for config buffers\n");
4732 pmcraid_release_host_rrqs(pinstance
, pinstance
->num_hrrq
);
4736 if (pmcraid_allocate_cmd_blocks(pinstance
)) {
4737 pmcraid_err("couldn't allocate memory for cmd blocks \n");
4738 pmcraid_release_config_buffers(pinstance
);
4739 pmcraid_release_host_rrqs(pinstance
, pinstance
->num_hrrq
);
4743 if (pmcraid_allocate_control_blocks(pinstance
)) {
4744 pmcraid_err("couldn't allocate memory control blocks \n");
4745 pmcraid_release_config_buffers(pinstance
);
4746 pmcraid_release_cmd_blocks(pinstance
, PMCRAID_MAX_CMD
);
4747 pmcraid_release_host_rrqs(pinstance
, pinstance
->num_hrrq
);
4751 /* Initialize all the command blocks and add them to free pool. No
4752 * need to lock (free_pool_lock) as this is done in initialization
4755 for (i
= 0; i
< PMCRAID_MAX_CMD
; i
++) {
4756 struct pmcraid_cmd
*cmdp
= pinstance
->cmd_list
[i
];
4757 pmcraid_init_cmdblk(cmdp
, i
);
4758 cmdp
->drv_inst
= pinstance
;
4759 list_add_tail(&cmdp
->free_list
, &pinstance
->free_cmd_pool
);
4766 * pmcraid_reinit_buffers - resets various buffer pointers
4767 * @pinstance: pointer to adapter instance
4771 static void pmcraid_reinit_buffers(struct pmcraid_instance
*pinstance
)
4774 int buffer_size
= HRRQ_ENTRY_SIZE
* PMCRAID_MAX_CMD
;
4776 for (i
= 0; i
< pinstance
->num_hrrq
; i
++) {
4777 memset(pinstance
->hrrq_start
[i
], 0, buffer_size
);
4778 pinstance
->hrrq_curr
[i
] = pinstance
->hrrq_start
[i
];
4779 pinstance
->hrrq_end
[i
] =
4780 pinstance
->hrrq_start
[i
] + PMCRAID_MAX_CMD
- 1;
4781 pinstance
->host_toggle_bit
[i
] = 1;
4786 * pmcraid_init_instance - initialize per instance data structure
4787 * @pdev: pointer to pci device structure
4788 * @host: pointer to Scsi_Host structure
4789 * @mapped_pci_addr: memory mapped IOA configuration registers
4792 * 0 on success, non-zero in case of any failure
4794 static int __devinit
pmcraid_init_instance(
4795 struct pci_dev
*pdev
,
4796 struct Scsi_Host
*host
,
4797 void __iomem
*mapped_pci_addr
4800 struct pmcraid_instance
*pinstance
=
4801 (struct pmcraid_instance
*)host
->hostdata
;
4803 pinstance
->host
= host
;
4804 pinstance
->pdev
= pdev
;
4806 /* Initialize register addresses */
4807 pinstance
->mapped_dma_addr
= mapped_pci_addr
;
4809 /* Initialize chip-specific details */
4811 struct pmcraid_chip_details
*chip_cfg
= pinstance
->chip_cfg
;
4812 struct pmcraid_interrupts
*pint_regs
= &pinstance
->int_regs
;
4814 pinstance
->ioarrin
= mapped_pci_addr
+ chip_cfg
->ioarrin
;
4816 pint_regs
->ioa_host_interrupt_reg
=
4817 mapped_pci_addr
+ chip_cfg
->ioa_host_intr
;
4818 pint_regs
->ioa_host_interrupt_clr_reg
=
4819 mapped_pci_addr
+ chip_cfg
->ioa_host_intr_clr
;
4820 pint_regs
->host_ioa_interrupt_reg
=
4821 mapped_pci_addr
+ chip_cfg
->host_ioa_intr
;
4822 pint_regs
->host_ioa_interrupt_clr_reg
=
4823 mapped_pci_addr
+ chip_cfg
->host_ioa_intr_clr
;
4825 /* Current version of firmware exposes interrupt mask set
4826 * and mask clr registers through memory mapped bar0.
4828 pinstance
->mailbox
= mapped_pci_addr
+ chip_cfg
->mailbox
;
4829 pinstance
->ioa_status
= mapped_pci_addr
+ chip_cfg
->ioastatus
;
4830 pint_regs
->ioa_host_interrupt_mask_reg
=
4831 mapped_pci_addr
+ chip_cfg
->ioa_host_mask
;
4832 pint_regs
->ioa_host_interrupt_mask_clr_reg
=
4833 mapped_pci_addr
+ chip_cfg
->ioa_host_mask_clr
;
4834 pint_regs
->global_interrupt_mask_reg
=
4835 mapped_pci_addr
+ chip_cfg
->global_intr_mask
;
4838 pinstance
->ioa_reset_attempts
= 0;
4839 init_waitqueue_head(&pinstance
->reset_wait_q
);
4841 atomic_set(&pinstance
->outstanding_cmds
, 0);
4842 atomic_set(&pinstance
->expose_resources
, 0);
4844 INIT_LIST_HEAD(&pinstance
->free_res_q
);
4845 INIT_LIST_HEAD(&pinstance
->used_res_q
);
4846 INIT_LIST_HEAD(&pinstance
->free_cmd_pool
);
4847 INIT_LIST_HEAD(&pinstance
->pending_cmd_pool
);
4849 spin_lock_init(&pinstance
->free_pool_lock
);
4850 spin_lock_init(&pinstance
->pending_pool_lock
);
4851 spin_lock_init(&pinstance
->resource_lock
);
4852 mutex_init(&pinstance
->aen_queue_lock
);
4854 /* Work-queue (Shared) for deferred processing error handling */
4855 INIT_WORK(&pinstance
->worker_q
, pmcraid_worker_function
);
4857 /* Initialize the default log_level */
4858 pinstance
->current_log_level
= pmcraid_log_level
;
4860 /* Setup variables required for reset engine */
4861 pinstance
->ioa_state
= IOA_STATE_UNKNOWN
;
4862 pinstance
->reset_cmd
= NULL
;
4867 * pmcraid_release_buffers - release per-adapter buffers allocated
4869 * @pinstance: pointer to adapter soft state
4874 static void pmcraid_release_buffers(struct pmcraid_instance
*pinstance
)
4876 pmcraid_release_config_buffers(pinstance
);
4877 pmcraid_release_control_blocks(pinstance
, PMCRAID_MAX_CMD
);
4878 pmcraid_release_cmd_blocks(pinstance
, PMCRAID_MAX_CMD
);
4879 pmcraid_release_host_rrqs(pinstance
, pinstance
->num_hrrq
);
4884 * pmcraid_shutdown - shutdown adapter controller.
4885 * @pdev: pci device struct
4887 * Issues an adapter shutdown to the card waits for its completion
4892 static void pmcraid_shutdown(struct pci_dev
*pdev
)
4894 struct pmcraid_instance
*pinstance
= pci_get_drvdata(pdev
);
4895 pmcraid_reset_bringdown(pinstance
);
4900 * pmcraid_get_minor - returns unused minor number from minor number bitmap
4902 static unsigned short pmcraid_get_minor(void)
4906 minor
= find_first_zero_bit(pmcraid_minor
, sizeof(pmcraid_minor
));
4907 __set_bit(minor
, pmcraid_minor
);
4912 * pmcraid_release_minor - releases given minor back to minor number bitmap
4914 static void pmcraid_release_minor(unsigned short minor
)
4916 __clear_bit(minor
, pmcraid_minor
);
4920 * pmcraid_setup_chrdev - allocates a minor number and registers a char device
4922 * @pinstance: pointer to adapter instance for which to register device
4925 * 0 in case of success, otherwise non-zero
4927 static int pmcraid_setup_chrdev(struct pmcraid_instance
*pinstance
)
4932 minor
= pmcraid_get_minor();
4933 cdev_init(&pinstance
->cdev
, &pmcraid_fops
);
4934 pinstance
->cdev
.owner
= THIS_MODULE
;
4936 error
= cdev_add(&pinstance
->cdev
, MKDEV(pmcraid_major
, minor
), 1);
4939 pmcraid_release_minor(minor
);
4941 device_create(pmcraid_class
, NULL
, MKDEV(pmcraid_major
, minor
),
4942 NULL
, "pmcsas%u", minor
);
4947 * pmcraid_release_chrdev - unregisters per-adapter management interface
4949 * @pinstance: pointer to adapter instance structure
4954 static void pmcraid_release_chrdev(struct pmcraid_instance
*pinstance
)
4956 pmcraid_release_minor(MINOR(pinstance
->cdev
.dev
));
4957 device_destroy(pmcraid_class
,
4958 MKDEV(pmcraid_major
, MINOR(pinstance
->cdev
.dev
)));
4959 cdev_del(&pinstance
->cdev
);
4963 * pmcraid_remove - IOA hot plug remove entry point
4964 * @pdev: pci device struct
4969 static void __devexit
pmcraid_remove(struct pci_dev
*pdev
)
4971 struct pmcraid_instance
*pinstance
= pci_get_drvdata(pdev
);
4973 /* remove the management interface (/dev file) for this device */
4974 pmcraid_release_chrdev(pinstance
);
4976 /* remove host template from scsi midlayer */
4977 scsi_remove_host(pinstance
->host
);
4979 /* block requests from mid-layer */
4980 scsi_block_requests(pinstance
->host
);
4982 /* initiate shutdown adapter */
4983 pmcraid_shutdown(pdev
);
4985 pmcraid_disable_interrupts(pinstance
, ~0);
4986 flush_scheduled_work();
4988 pmcraid_kill_tasklets(pinstance
);
4989 pmcraid_unregister_interrupt_handler(pinstance
);
4990 pmcraid_release_buffers(pinstance
);
4991 iounmap(pinstance
->mapped_dma_addr
);
4992 pci_release_regions(pdev
);
4993 scsi_host_put(pinstance
->host
);
4994 pci_disable_device(pdev
);
5001 * pmcraid_suspend - driver suspend entry point for power management
5002 * @pdev: PCI device structure
5003 * @state: PCI power state to suspend routine
5005 * Return Value - 0 always
5007 static int pmcraid_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5009 struct pmcraid_instance
*pinstance
= pci_get_drvdata(pdev
);
5011 pmcraid_shutdown(pdev
);
5012 pmcraid_disable_interrupts(pinstance
, ~0);
5013 pmcraid_kill_tasklets(pinstance
);
5014 pci_set_drvdata(pinstance
->pdev
, pinstance
);
5015 pmcraid_unregister_interrupt_handler(pinstance
);
5016 pci_save_state(pdev
);
5017 pci_disable_device(pdev
);
5018 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
5024 * pmcraid_resume - driver resume entry point PCI power management
5025 * @pdev: PCI device structure
5027 * Return Value - 0 in case of success. Error code in case of any failure
5029 static int pmcraid_resume(struct pci_dev
*pdev
)
5031 struct pmcraid_instance
*pinstance
= pci_get_drvdata(pdev
);
5032 struct Scsi_Host
*host
= pinstance
->host
;
5036 pci_set_power_state(pdev
, PCI_D0
);
5037 pci_enable_wake(pdev
, PCI_D0
, 0);
5038 pci_restore_state(pdev
);
5040 rc
= pci_enable_device(pdev
);
5043 pmcraid_err("pmcraid: Enable device failed\n");
5047 pci_set_master(pdev
);
5049 if ((sizeof(dma_addr_t
) == 4) ||
5050 pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
5051 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
5054 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
5057 dev_err(&pdev
->dev
, "Failed to set PCI DMA mask\n");
5058 goto disable_device
;
5061 atomic_set(&pinstance
->outstanding_cmds
, 0);
5062 hrrqs
= pinstance
->num_hrrq
;
5063 rc
= pmcraid_register_interrupt_handler(pinstance
);
5066 pmcraid_err("resume: couldn't register interrupt handlers\n");
5071 pmcraid_init_tasklets(pinstance
);
5072 pmcraid_enable_interrupts(pinstance
, PMCRAID_PCI_INTERRUPTS
);
5074 /* Start with hard reset sequence which brings up IOA to operational
5075 * state as well as completes the reset sequence.
5077 pinstance
->ioa_hard_reset
= 1;
5079 /* Start IOA firmware initialization and bring card to Operational
5082 if (pmcraid_reset_bringup(pinstance
)) {
5083 pmcraid_err("couldn't initialize IOA \n");
5085 goto release_tasklets
;
5091 pmcraid_kill_tasklets(pinstance
);
5092 pmcraid_unregister_interrupt_handler(pinstance
);
5095 scsi_host_put(host
);
5098 pci_disable_device(pdev
);
5105 #define pmcraid_suspend NULL
5106 #define pmcraid_resume NULL
5108 #endif /* CONFIG_PM */
5111 * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
5112 * completion of the ioa reset
5113 * @cmd: pointer to reset command block
5115 static void pmcraid_complete_ioa_reset(struct pmcraid_cmd
*cmd
)
5117 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
5118 unsigned long flags
;
5120 spin_lock_irqsave(pinstance
->host
->host_lock
, flags
);
5121 pmcraid_ioa_reset(cmd
);
5122 spin_unlock_irqrestore(pinstance
->host
->host_lock
, flags
);
5123 scsi_unblock_requests(pinstance
->host
);
5124 schedule_work(&pinstance
->worker_q
);
5128 * pmcraid_set_supported_devs - sends SET SUPPORTED DEVICES to IOAFP
5130 * @cmd: pointer to pmcraid_cmd structure
5133 * 0 for success or non-zero for failure cases
5135 static void pmcraid_set_supported_devs(struct pmcraid_cmd
*cmd
)
5137 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
5138 void (*cmd_done
) (struct pmcraid_cmd
*) = pmcraid_complete_ioa_reset
;
5140 pmcraid_reinit_cmdblk(cmd
);
5142 ioarcb
->resource_handle
= cpu_to_le32(PMCRAID_IOA_RES_HANDLE
);
5143 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
5144 ioarcb
->cdb
[0] = PMCRAID_SET_SUPPORTED_DEVICES
;
5145 ioarcb
->cdb
[1] = ALL_DEVICES_SUPPORTED
;
5147 /* If this was called as part of resource table reinitialization due to
5148 * lost CCN, it is enough to return the command block back to free pool
5149 * as part of set_supported_devs completion function.
5151 if (cmd
->drv_inst
->reinit_cfg_table
) {
5152 cmd
->drv_inst
->reinit_cfg_table
= 0;
5154 cmd_done
= pmcraid_reinit_cfgtable_done
;
5157 /* we will be done with the reset sequence after set supported devices,
5158 * setup the done function to return the command block back to free
5161 pmcraid_send_cmd(cmd
,
5163 PMCRAID_SET_SUP_DEV_TIMEOUT
,
5164 pmcraid_timeout_handler
);
5169 * pmcraid_init_res_table - Initialize the resource table
5170 * @cmd: pointer to pmcraid command struct
5172 * This function looks through the existing resource table, comparing
5173 * it with the config table. This function will take care of old/new
5174 * devices and schedule adding/removing them from the mid-layer
5180 static void pmcraid_init_res_table(struct pmcraid_cmd
*cmd
)
5182 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
5183 struct pmcraid_resource_entry
*res
, *temp
;
5184 struct pmcraid_config_table_entry
*cfgte
;
5185 unsigned long lock_flags
;
5189 if (pinstance
->cfg_table
->flags
& MICROCODE_UPDATE_REQUIRED
)
5190 dev_err(&pinstance
->pdev
->dev
, "Require microcode download\n");
5192 /* resource list is protected by pinstance->resource_lock.
5193 * init_res_table can be called from probe (user-thread) or runtime
5194 * reset (timer/tasklet)
5196 spin_lock_irqsave(&pinstance
->resource_lock
, lock_flags
);
5198 list_for_each_entry_safe(res
, temp
, &pinstance
->used_res_q
, queue
)
5199 list_move_tail(&res
->queue
, &old_res
);
5201 for (i
= 0; i
< pinstance
->cfg_table
->num_entries
; i
++) {
5202 cfgte
= &pinstance
->cfg_table
->entries
[i
];
5204 if (!pmcraid_expose_resource(cfgte
))
5209 /* If this entry was already detected and initialized */
5210 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
5212 rc
= memcmp(&res
->cfg_entry
.resource_address
,
5213 &cfgte
->resource_address
,
5214 sizeof(cfgte
->resource_address
));
5216 list_move_tail(&res
->queue
,
5217 &pinstance
->used_res_q
);
5223 /* If this is new entry, initialize it and add it the queue */
5226 if (list_empty(&pinstance
->free_res_q
)) {
5227 dev_err(&pinstance
->pdev
->dev
,
5228 "Too many devices attached\n");
5233 res
= list_entry(pinstance
->free_res_q
.next
,
5234 struct pmcraid_resource_entry
, queue
);
5236 res
->scsi_dev
= NULL
;
5237 res
->change_detected
= RES_CHANGE_ADD
;
5238 res
->reset_progress
= 0;
5239 list_move_tail(&res
->queue
, &pinstance
->used_res_q
);
5242 /* copy new configuration table entry details into driver
5243 * maintained resource entry
5246 memcpy(&res
->cfg_entry
, cfgte
,
5247 sizeof(struct pmcraid_config_table_entry
));
5248 pmcraid_info("New res type:%x, vset:%x, addr:%x:\n",
5249 res
->cfg_entry
.resource_type
,
5250 res
->cfg_entry
.unique_flags1
,
5251 le32_to_cpu(res
->cfg_entry
.resource_address
));
5255 /* Detect any deleted entries, mark them for deletion from mid-layer */
5256 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
5258 if (res
->scsi_dev
) {
5259 res
->change_detected
= RES_CHANGE_DEL
;
5260 res
->cfg_entry
.resource_handle
=
5261 PMCRAID_INVALID_RES_HANDLE
;
5262 list_move_tail(&res
->queue
, &pinstance
->used_res_q
);
5264 list_move_tail(&res
->queue
, &pinstance
->free_res_q
);
5268 /* release the resource list lock */
5269 spin_unlock_irqrestore(&pinstance
->resource_lock
, lock_flags
);
5270 pmcraid_set_supported_devs(cmd
);
5274 * pmcraid_querycfg - Send a Query IOA Config to the adapter.
5275 * @cmd: pointer pmcraid_cmd struct
5277 * This function sends a Query IOA Configuration command to the adapter to
5278 * retrieve the IOA configuration table.
5283 static void pmcraid_querycfg(struct pmcraid_cmd
*cmd
)
5285 struct pmcraid_ioarcb
*ioarcb
= &cmd
->ioa_cb
->ioarcb
;
5286 struct pmcraid_ioadl_desc
*ioadl
= ioarcb
->add_data
.u
.ioadl
;
5287 struct pmcraid_instance
*pinstance
= cmd
->drv_inst
;
5288 int cfg_table_size
= cpu_to_be32(sizeof(struct pmcraid_config_table
));
5290 ioarcb
->request_type
= REQ_TYPE_IOACMD
;
5291 ioarcb
->resource_handle
= cpu_to_le32(PMCRAID_IOA_RES_HANDLE
);
5293 ioarcb
->cdb
[0] = PMCRAID_QUERY_IOA_CONFIG
;
5295 /* firmware requires 4-byte length field, specified in B.E format */
5296 memcpy(&(ioarcb
->cdb
[10]), &cfg_table_size
, sizeof(cfg_table_size
));
5298 /* Since entire config table can be described by single IOADL, it can
5299 * be part of IOARCB itself
5301 ioarcb
->ioadl_bus_addr
= cpu_to_le64((cmd
->ioa_cb_bus_addr
) +
5302 offsetof(struct pmcraid_ioarcb
,
5303 add_data
.u
.ioadl
[0]));
5304 ioarcb
->ioadl_length
= cpu_to_le32(sizeof(struct pmcraid_ioadl_desc
));
5305 ioarcb
->ioarcb_bus_addr
&= ~(0x1FULL
);
5307 ioarcb
->request_flags0
|= NO_LINK_DESCS
;
5308 ioarcb
->data_transfer_length
=
5309 cpu_to_le32(sizeof(struct pmcraid_config_table
));
5311 ioadl
= &(ioarcb
->add_data
.u
.ioadl
[0]);
5312 ioadl
->flags
= cpu_to_le32(IOADL_FLAGS_LAST_DESC
);
5313 ioadl
->address
= cpu_to_le64(pinstance
->cfg_table_bus_addr
);
5314 ioadl
->data_len
= cpu_to_le32(sizeof(struct pmcraid_config_table
));
5316 pmcraid_send_cmd(cmd
, pmcraid_init_res_table
,
5317 PMCRAID_INTERNAL_TIMEOUT
, pmcraid_timeout_handler
);
5322 * pmcraid_probe - PCI probe entry pointer for PMC MaxRaid controller driver
5323 * @pdev: pointer to pci device structure
5324 * @dev_id: pointer to device ids structure
5327 * returns 0 if the device is claimed and successfully configured.
5328 * returns non-zero error code in case of any failure
5330 static int __devinit
pmcraid_probe(
5331 struct pci_dev
*pdev
,
5332 const struct pci_device_id
*dev_id
5335 struct pmcraid_instance
*pinstance
;
5336 struct Scsi_Host
*host
;
5337 void __iomem
*mapped_pci_addr
;
5338 int rc
= PCIBIOS_SUCCESSFUL
;
5340 if (atomic_read(&pmcraid_adapter_count
) >= PMCRAID_MAX_ADAPTERS
) {
5342 ("maximum number(%d) of supported adapters reached\n",
5343 atomic_read(&pmcraid_adapter_count
));
5347 atomic_inc(&pmcraid_adapter_count
);
5348 rc
= pci_enable_device(pdev
);
5351 dev_err(&pdev
->dev
, "Cannot enable adapter\n");
5352 atomic_dec(&pmcraid_adapter_count
);
5356 dev_info(&pdev
->dev
,
5357 "Found new IOA(%x:%x), Total IOA count: %d\n",
5358 pdev
->vendor
, pdev
->device
,
5359 atomic_read(&pmcraid_adapter_count
));
5361 rc
= pci_request_regions(pdev
, PMCRAID_DRIVER_NAME
);
5365 "Couldn't register memory range of registers\n");
5366 goto out_disable_device
;
5369 mapped_pci_addr
= pci_iomap(pdev
, 0, 0);
5371 if (!mapped_pci_addr
) {
5372 dev_err(&pdev
->dev
, "Couldn't map PCI registers memory\n");
5374 goto out_release_regions
;
5377 pci_set_master(pdev
);
5379 /* Firmware requires the system bus address of IOARCB to be within
5380 * 32-bit addressable range though it has 64-bit IOARRIN register.
5381 * However, firmware supports 64-bit streaming DMA buffers, whereas
5382 * coherent buffers are to be 32-bit. Since pci_alloc_consistent always
5383 * returns memory within 4GB (if not, change this logic), coherent
5384 * buffers are within firmware acceptible address ranges.
5386 if ((sizeof(dma_addr_t
) == 4) ||
5387 pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
5388 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
5390 /* firmware expects 32-bit DMA addresses for IOARRIN register; set 32
5391 * bit mask for pci_alloc_consistent to return addresses within 4GB
5394 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
5397 dev_err(&pdev
->dev
, "Failed to set PCI DMA mask\n");
5401 host
= scsi_host_alloc(&pmcraid_host_template
,
5402 sizeof(struct pmcraid_instance
));
5405 dev_err(&pdev
->dev
, "scsi_host_alloc failed!\n");
5410 host
->max_id
= PMCRAID_MAX_NUM_TARGETS_PER_BUS
;
5411 host
->max_lun
= PMCRAID_MAX_NUM_LUNS_PER_TARGET
;
5412 host
->unique_id
= host
->host_no
;
5413 host
->max_channel
= PMCRAID_MAX_BUS_TO_SCAN
;
5414 host
->max_cmd_len
= PMCRAID_MAX_CDB_LEN
;
5416 /* zero out entire instance structure */
5417 pinstance
= (struct pmcraid_instance
*)host
->hostdata
;
5418 memset(pinstance
, 0, sizeof(*pinstance
));
5420 pinstance
->chip_cfg
=
5421 (struct pmcraid_chip_details
*)(dev_id
->driver_data
);
5423 rc
= pmcraid_init_instance(pdev
, host
, mapped_pci_addr
);
5426 dev_err(&pdev
->dev
, "failed to initialize adapter instance\n");
5427 goto out_scsi_host_put
;
5430 pci_set_drvdata(pdev
, pinstance
);
5432 /* Save PCI config-space for use following the reset */
5433 rc
= pci_save_state(pinstance
->pdev
);
5436 dev_err(&pdev
->dev
, "Failed to save PCI config space\n");
5437 goto out_scsi_host_put
;
5440 pmcraid_disable_interrupts(pinstance
, ~0);
5442 rc
= pmcraid_register_interrupt_handler(pinstance
);
5445 pmcraid_err("couldn't register interrupt handler\n");
5446 goto out_scsi_host_put
;
5449 pmcraid_init_tasklets(pinstance
);
5451 /* allocate verious buffers used by LLD.*/
5452 rc
= pmcraid_init_buffers(pinstance
);
5455 pmcraid_err("couldn't allocate memory blocks\n");
5456 goto out_unregister_isr
;
5459 /* check the reset type required */
5460 pmcraid_reset_type(pinstance
);
5462 pmcraid_enable_interrupts(pinstance
, PMCRAID_PCI_INTERRUPTS
);
5464 /* Start IOA firmware initialization and bring card to Operational
5467 pmcraid_info("starting IOA initialization sequence\n");
5468 if (pmcraid_reset_bringup(pinstance
)) {
5469 pmcraid_err("couldn't initialize IOA \n");
5471 goto out_release_bufs
;
5474 /* Add adapter instance into mid-layer list */
5475 rc
= scsi_add_host(pinstance
->host
, &pdev
->dev
);
5477 pmcraid_err("couldn't add host into mid-layer: %d\n", rc
);
5478 goto out_release_bufs
;
5481 scsi_scan_host(pinstance
->host
);
5483 rc
= pmcraid_setup_chrdev(pinstance
);
5486 pmcraid_err("couldn't create mgmt interface, error: %x\n",
5488 goto out_remove_host
;
5491 /* Schedule worker thread to handle CCN and take care of adding and
5492 * removing devices to OS
5494 atomic_set(&pinstance
->expose_resources
, 1);
5495 schedule_work(&pinstance
->worker_q
);
5499 scsi_remove_host(host
);
5502 pmcraid_release_buffers(pinstance
);
5505 pmcraid_kill_tasklets(pinstance
);
5506 pmcraid_unregister_interrupt_handler(pinstance
);
5509 scsi_host_put(host
);
5512 iounmap(mapped_pci_addr
);
5514 out_release_regions
:
5515 pci_release_regions(pdev
);
5518 atomic_dec(&pmcraid_adapter_count
);
5519 pci_set_drvdata(pdev
, NULL
);
5520 pci_disable_device(pdev
);
5525 * PCI driver structure of pcmraid driver
5527 static struct pci_driver pmcraid_driver
= {
5528 .name
= PMCRAID_DRIVER_NAME
,
5529 .id_table
= pmcraid_pci_table
,
5530 .probe
= pmcraid_probe
,
5531 .remove
= pmcraid_remove
,
5532 .suspend
= pmcraid_suspend
,
5533 .resume
= pmcraid_resume
,
5534 .shutdown
= pmcraid_shutdown
5539 * pmcraid_init - module load entry point
5541 static int __init
pmcraid_init(void)
5546 pmcraid_info("%s Device Driver version: %s %s\n",
5547 PMCRAID_DRIVER_NAME
,
5548 PMCRAID_DRIVER_VERSION
, PMCRAID_DRIVER_DATE
);
5550 error
= alloc_chrdev_region(&dev
, 0,
5551 PMCRAID_MAX_ADAPTERS
,
5555 pmcraid_err("failed to get a major number for adapters\n");
5559 pmcraid_major
= MAJOR(dev
);
5560 pmcraid_class
= class_create(THIS_MODULE
, PMCRAID_DEVFILE
);
5562 if (IS_ERR(pmcraid_class
)) {
5563 error
= PTR_ERR(pmcraid_class
);
5564 pmcraid_err("failed to register with with sysfs, error = %x\n",
5566 goto out_unreg_chrdev
;
5570 error
= pmcraid_netlink_init();
5573 goto out_unreg_chrdev
;
5575 error
= pci_register_driver(&pmcraid_driver
);
5580 pmcraid_err("failed to register pmcraid driver, error = %x\n",
5582 class_destroy(pmcraid_class
);
5583 pmcraid_netlink_release();
5586 unregister_chrdev_region(MKDEV(pmcraid_major
, 0), PMCRAID_MAX_ADAPTERS
);
5592 * pmcraid_exit - module unload entry point
5594 static void __exit
pmcraid_exit(void)
5596 pmcraid_netlink_release();
5597 class_destroy(pmcraid_class
);
5598 unregister_chrdev_region(MKDEV(pmcraid_major
, 0),
5599 PMCRAID_MAX_ADAPTERS
);
5600 pci_unregister_driver(&pmcraid_driver
);
5603 module_init(pmcraid_init
);
5604 module_exit(pmcraid_exit
);