Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pm8001_sas.h
Go to the documentation of this file.
1 /*
2  * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
3  *
4  * Copyright (c) 2008-2009 USI Co., Ltd.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions, and the following disclaimer,
12  * without modification.
13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14  * substantially similar to the "NO WARRANTY" disclaimer below
15  * ("Disclaimer") and any redistribution must be conditioned upon
16  * including a substantially similar Disclaimer requirement for further
17  * binary redistribution.
18  * 3. Neither the names of the above-listed copyright holders nor the names
19  * of any contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * Alternatively, this software may be distributed under the terms of the
23  * GNU General Public License ("GPL") version 2 as published by the Free
24  * Software Foundation.
25  *
26  * NO WARRANTY
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGES.
38  *
39  */
40 
41 #ifndef _PM8001_SAS_H_
42 #define _PM8001_SAS_H_
43 
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/spinlock.h>
47 #include <linux/delay.h>
48 #include <linux/types.h>
49 #include <linux/ctype.h>
50 #include <linux/dma-mapping.h>
51 #include <linux/pci.h>
52 #include <linux/interrupt.h>
53 #include <linux/workqueue.h>
54 #include <scsi/libsas.h>
55 #include <scsi/scsi_tcq.h>
56 #include <scsi/sas_ata.h>
57 #include <linux/atomic.h>
58 #include "pm8001_defs.h"
59 
60 #define DRV_NAME "pm8001"
61 #define DRV_VERSION "0.1.36"
62 #define PM8001_FAIL_LOGGING 0x01 /* Error message logging */
63 #define PM8001_INIT_LOGGING 0x02 /* driver init logging */
64 #define PM8001_DISC_LOGGING 0x04 /* discovery layer logging */
65 #define PM8001_IO_LOGGING 0x08 /* I/O path logging */
66 #define PM8001_EH_LOGGING 0x10 /* libsas EH function logging*/
67 #define PM8001_IOCTL_LOGGING 0x20 /* IOCTL message logging */
68 #define PM8001_MSG_LOGGING 0x40 /* misc message logging */
69 #define pm8001_printk(format, arg...) printk(KERN_INFO "%s %d:" format,\
70  __func__, __LINE__, ## arg)
71 #define PM8001_CHECK_LOGGING(HBA, LEVEL, CMD) \
72 do { \
73  if (unlikely(HBA->logging_level & LEVEL)) \
74  do { \
75  CMD; \
76  } while (0); \
77 } while (0);
78 
79 #define PM8001_EH_DBG(HBA, CMD) \
80  PM8001_CHECK_LOGGING(HBA, PM8001_EH_LOGGING, CMD)
81 
82 #define PM8001_INIT_DBG(HBA, CMD) \
83  PM8001_CHECK_LOGGING(HBA, PM8001_INIT_LOGGING, CMD)
84 
85 #define PM8001_DISC_DBG(HBA, CMD) \
86  PM8001_CHECK_LOGGING(HBA, PM8001_DISC_LOGGING, CMD)
87 
88 #define PM8001_IO_DBG(HBA, CMD) \
89  PM8001_CHECK_LOGGING(HBA, PM8001_IO_LOGGING, CMD)
90 
91 #define PM8001_FAIL_DBG(HBA, CMD) \
92  PM8001_CHECK_LOGGING(HBA, PM8001_FAIL_LOGGING, CMD)
93 
94 #define PM8001_IOCTL_DBG(HBA, CMD) \
95  PM8001_CHECK_LOGGING(HBA, PM8001_IOCTL_LOGGING, CMD)
96 
97 #define PM8001_MSG_DBG(HBA, CMD) \
98  PM8001_CHECK_LOGGING(HBA, PM8001_MSG_LOGGING, CMD)
99 
100 
101 #define PM8001_USE_TASKLET
102 #define PM8001_USE_MSIX
103 #define PM8001_READ_VPD
104 
105 
106 #define DEV_IS_EXPANDER(type) ((type == EDGE_DEV) || (type == FANOUT_DEV))
107 
108 #define PM8001_NAME_LENGTH 32/* generic length of strings */
109 extern struct list_head hba_list;
110 extern const struct pm8001_dispatch pm8001_8001_dispatch;
111 
112 struct pm8001_hba_info;
113 struct pm8001_ccb_info;
114 struct pm8001_device;
115 /* define task management IU */
119 };
129 };
130 
132  char *name;
133  int (*chip_init)(struct pm8001_hba_info *pm8001_ha);
135  void (*chip_rst)(struct pm8001_hba_info *pm8001_ha);
136  int (*chip_ioremap)(struct pm8001_hba_info *pm8001_ha);
137  void (*chip_iounmap)(struct pm8001_hba_info *pm8001_ha);
138  irqreturn_t (*isr)(struct pm8001_hba_info *pm8001_ha);
139  u32 (*is_our_interupt)(struct pm8001_hba_info *pm8001_ha);
140  int (*isr_process_oq)(struct pm8001_hba_info *pm8001_ha);
141  void (*interrupt_enable)(struct pm8001_hba_info *pm8001_ha);
142  void (*interrupt_disable)(struct pm8001_hba_info *pm8001_ha);
143  void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
144  int (*smp_req)(struct pm8001_hba_info *pm8001_ha,
145  struct pm8001_ccb_info *ccb);
146  int (*ssp_io_req)(struct pm8001_hba_info *pm8001_ha,
147  struct pm8001_ccb_info *ccb);
148  int (*sata_req)(struct pm8001_hba_info *pm8001_ha,
149  struct pm8001_ccb_info *ccb);
150  int (*phy_start_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id);
151  int (*phy_stop_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id);
152  int (*reg_dev_req)(struct pm8001_hba_info *pm8001_ha,
153  struct pm8001_device *pm8001_dev, u32 flag);
155  int (*phy_ctl_req)(struct pm8001_hba_info *pm8001_ha,
156  u32 phy_id, u32 phy_op);
157  int (*task_abort)(struct pm8001_hba_info *pm8001_ha,
158  struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag,
159  u32 cmd_tag);
160  int (*ssp_tm_req)(struct pm8001_hba_info *pm8001_ha,
161  struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf);
162  int (*get_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
163  int (*set_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
165  void *payload);
166  int (*set_dev_state_req)(struct pm8001_hba_info *pm8001_ha,
167  struct pm8001_device *pm8001_dev, u32 state);
169  u32 state);
171  u32 state);
172  int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
173 };
174 
177  const struct pm8001_dispatch *dispatch;
178 };
179 #define PM8001_CHIP_DISP (pm8001_ha->chip->dispatch)
180 
181 struct pm8001_port {
186  struct list_head list;
187 };
188 
189 struct pm8001_phy {
191  struct pm8001_port *port;
194  struct scsi_device *sdev;
204 };
205 
215 };
216 
220 };
221 
222 struct pm8001_prd {
223  __le64 addr; /* 64-bit buffer address */
224  struct pm8001_prd_imt im_len; /* 64-bit length */
225 } __attribute__ ((packed));
226 /*
227  * CCB(Command Control Block)
228  */
230  struct list_head entry;
231  struct sas_task *task;
239 };
240 
241 struct mpi_mem {
242  void *virt_ptr;
250 };
251 
252 struct mpi_mem_req {
253  /* The number of element in the mpiMemory array */
255  /* The array of structures that define memroy regions*/
257 };
258 
295 };
308 };
318  void *base_virt;
319  void *ci_virt;
323 };
328  void *base_virt;
334  void *pi_virt;
339 };
344 };
347  struct list_head list;
348  unsigned long flags;
349  spinlock_t lock;/* host-wide lock */
350  struct pci_dev *pdev;/* our device */
351  struct device *dev;
354  void __iomem *msg_unit_tbl_addr;/*Message Unit Table Addr*/
355  void __iomem *main_cfg_tbl_addr;/*Main Config Table Addr*/
356  void __iomem *general_stat_tbl_addr;/*General Status Table Addr*/
357  void __iomem *inbnd_q_tbl_addr;/*Inbound Queue Config Table Addr*/
358  void __iomem *outbnd_q_tbl_addr;/*Outbound Queue Config Table Addr*/
364  struct sas_ha_struct *sas;/* SCSI/SAS glue */
365  struct Scsi_Host *shost;
367  const struct pm8001_chip_info *chip;
369  int tags_num;
370  unsigned long *tags;
377 #ifdef PM8001_USE_MSIX
378  struct msix_entry msix_entries[16];/*for msi-x interrupt*/
379  int number_of_intr;/*will be used in remove()*/
380 #endif
381 #ifdef PM8001_USE_TASKLET
383 #endif
386  const struct firmware *fw_image;
387 };
388 
389 struct pm8001_work {
392  void *data;
393  int handler;
394 };
395 
402  u8 fw_rev[4];
406 } __attribute__((packed, aligned(4)));
412 #define FLASH_UPDATE_COMPLETE_PENDING_REBOOT 0x00
413 #define FLASH_UPDATE_IN_PROGRESS 0x01
414 #define FLASH_UPDATE_HDR_ERR 0x02
415 #define FLASH_UPDATE_OFFSET_ERR 0x03
416 #define FLASH_UPDATE_CRC_ERR 0x04
417 #define FLASH_UPDATE_LENGTH_ERR 0x05
418 #define FLASH_UPDATE_HW_ERR 0x06
419 #define FLASH_UPDATE_DNLD_NOT_SUPPORTED 0x10
420 #define FLASH_UPDATE_DISABLED 0x11
421 
429  struct pm8001_prd sgl;
430 };
431 
433  u32 retcode;/*ret code (status)*/
434  u32 phase;/*ret code phase*/
435  u32 phaseCmplt;/*percent complete for the current
436  update phase */
437  u32 version;/*Hex encoded firmware version number*/
438  u32 offset;/*Used for downloading firmware */
439  u32 len; /*len of buffer*/
440  u32 size;/* Used in OS VPD and Trace get size
441  operations.*/
442  u32 reserved;/* padding required for 64 bit
443  alignment */
444  u8 buffer[1];/* Start of buffer */
445 };
448  void *buffer;/* keep buffer pointer to be
449  freed when the response comes*/
450  void *virtAddr;/* keep virtual address of the data */
451  void *usrAddr;/* keep virtual address of the
452  user data */
454  u32 len; /* len of buffer */
455  void *payload; /* pointer to IOCTL Payload */
456  u8 inProgress;/*if 1 - the IOCTL request is in
457  progress */
458  void *param1;
459  void *param2;
460  void *param3;
461 };
462 
463 /* pm8001 workqueue */
464 extern struct workqueue_struct *pm8001_wq;
465 
466 /******************** function prototype *********************/
467 int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out);
468 void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha);
470 void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, u32 ccb_idx);
471 void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
472  struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx);
474  void *funcdata);
475 void pm8001_scan_start(struct Scsi_Host *shost);
476 int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time);
477 int pm8001_queue_command(struct sas_task *task, const int num,
478  gfp_t gfp_flags);
479 int pm8001_abort_task(struct sas_task *task);
481 int pm8001_clear_aca(struct domain_device *dev, u8 *lun);
483 int pm8001_dev_found(struct domain_device *dev);
484 void pm8001_dev_gone(struct domain_device *dev);
485 int pm8001_lu_reset(struct domain_device *dev, u8 *lun);
487 int pm8001_query_task(struct sas_task *task);
489  struct pm8001_hba_info *pm8001_ha,
490  struct sas_task *task_to_close,
491  struct pm8001_device *device_to_close);
492 int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
493  dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
494  u32 mem_size, u32 align);
495 
496 int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue);
497 
498 /* ctl shared API */
499 extern struct device_attribute *pm8001_host_attrs[];
500 
501 #endif
502