xref: /linux/drivers/scsi/pm8001/pm8001_sas.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1dbf9bfe6Sjack wang /*
2f5860992SSakthivel K  * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver
3dbf9bfe6Sjack wang  *
4dbf9bfe6Sjack wang  * Copyright (c) 2008-2009 USI Co., Ltd.
5dbf9bfe6Sjack wang  * All rights reserved.
6dbf9bfe6Sjack wang  *
7dbf9bfe6Sjack wang  * Redistribution and use in source and binary forms, with or without
8dbf9bfe6Sjack wang  * modification, are permitted provided that the following conditions
9dbf9bfe6Sjack wang  * are met:
10dbf9bfe6Sjack wang  * 1. Redistributions of source code must retain the above copyright
11dbf9bfe6Sjack wang  *    notice, this list of conditions, and the following disclaimer,
12dbf9bfe6Sjack wang  *    without modification.
13dbf9bfe6Sjack wang  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14dbf9bfe6Sjack wang  *    substantially similar to the "NO WARRANTY" disclaimer below
15dbf9bfe6Sjack wang  *    ("Disclaimer") and any redistribution must be conditioned upon
16dbf9bfe6Sjack wang  *    including a substantially similar Disclaimer requirement for further
17dbf9bfe6Sjack wang  *    binary redistribution.
18dbf9bfe6Sjack wang  * 3. Neither the names of the above-listed copyright holders nor the names
19dbf9bfe6Sjack wang  *    of any contributors may be used to endorse or promote products derived
20dbf9bfe6Sjack wang  *    from this software without specific prior written permission.
21dbf9bfe6Sjack wang  *
22dbf9bfe6Sjack wang  * Alternatively, this software may be distributed under the terms of the
23dbf9bfe6Sjack wang  * GNU General Public License ("GPL") version 2 as published by the Free
24dbf9bfe6Sjack wang  * Software Foundation.
25dbf9bfe6Sjack wang  *
26dbf9bfe6Sjack wang  * NO WARRANTY
27dbf9bfe6Sjack wang  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28dbf9bfe6Sjack wang  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29dbf9bfe6Sjack wang  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30dbf9bfe6Sjack wang  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31dbf9bfe6Sjack wang  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32dbf9bfe6Sjack wang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33dbf9bfe6Sjack wang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34dbf9bfe6Sjack wang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35dbf9bfe6Sjack wang  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36dbf9bfe6Sjack wang  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37dbf9bfe6Sjack wang  * POSSIBILITY OF SUCH DAMAGES.
38dbf9bfe6Sjack wang  *
39dbf9bfe6Sjack wang  */
40dbf9bfe6Sjack wang 
41dbf9bfe6Sjack wang #ifndef _PM8001_SAS_H_
42dbf9bfe6Sjack wang #define _PM8001_SAS_H_
43dbf9bfe6Sjack wang 
44dbf9bfe6Sjack wang #include <linux/kernel.h>
45dbf9bfe6Sjack wang #include <linux/module.h>
46dbf9bfe6Sjack wang #include <linux/spinlock.h>
47dbf9bfe6Sjack wang #include <linux/delay.h>
48dbf9bfe6Sjack wang #include <linux/types.h>
49dbf9bfe6Sjack wang #include <linux/ctype.h>
50dbf9bfe6Sjack wang #include <linux/dma-mapping.h>
51dbf9bfe6Sjack wang #include <linux/pci.h>
52dbf9bfe6Sjack wang #include <linux/interrupt.h>
53429305e4STejun Heo #include <linux/workqueue.h>
54dbf9bfe6Sjack wang #include <scsi/libsas.h>
55dbf9bfe6Sjack wang #include <scsi/scsi_tcq.h>
56dbf9bfe6Sjack wang #include <scsi/sas_ata.h>
5760063497SArun Sharma #include <linux/atomic.h>
5842f22fe3SJohn Garry #include <linux/blk-mq.h>
5942f22fe3SJohn Garry #include <linux/blk-mq-pci.h>
60dbf9bfe6Sjack wang #include "pm8001_defs.h"
61dbf9bfe6Sjack wang 
62a70b8fc3SSakthivel K #define DRV_NAME		"pm80xx"
6339a45d53SViswas G #define DRV_VERSION		"0.1.40"
6483e73329Sjack wang #define PM8001_FAIL_LOGGING	0x01 /* Error message logging */
65dbf9bfe6Sjack wang #define PM8001_INIT_LOGGING	0x02 /* driver init logging */
66dbf9bfe6Sjack wang #define PM8001_DISC_LOGGING	0x04 /* discovery layer logging */
67dbf9bfe6Sjack wang #define PM8001_IO_LOGGING	0x08 /* I/O path logging */
6883e73329Sjack wang #define PM8001_EH_LOGGING	0x10 /* libsas EH function logging*/
69dbf9bfe6Sjack wang #define PM8001_IOCTL_LOGGING	0x20 /* IOCTL message logging */
70dbf9bfe6Sjack wang #define PM8001_MSG_LOGGING	0x40 /* misc message logging */
717370672dSpeter chang #define PM8001_DEV_LOGGING	0x80 /* development message logging */
727370672dSpeter chang #define PM8001_DEVIO_LOGGING	0x100 /* development io message logging */
737370672dSpeter chang #define PM8001_IOERR_LOGGING	0x200 /* development io err message logging */
74b7d26c1dSAkshat Jain #define PM8001_EVENT_LOGGING	0x400 /* HW event logging */
751b5d2793SJoe Perches 
762ce6e200SJoe Perches #define pm8001_info(HBA, fmt, ...)					\
771b5d2793SJoe Perches 	pr_info("%s:: %s %d: " fmt,					\
7889eddb40SJoe Perches 		(HBA)->name, __func__, __LINE__, ##__VA_ARGS__)
791b5d2793SJoe Perches 
801b5d2793SJoe Perches #define pm8001_dbg(HBA, level, fmt, ...)				\
81dbf9bfe6Sjack wang do {									\
821b5d2793SJoe Perches 	if (unlikely((HBA)->logging_level & PM8001_##level##_LOGGING))	\
832ce6e200SJoe Perches 		pm8001_info(HBA, fmt, ##__VA_ARGS__);			\
841b5d2793SJoe Perches } while (0)
85dbf9bfe6Sjack wang 
86efa1fca4SDamien Le Moal extern bool pm8001_use_msix;
87efa1fca4SDamien Le Moal 
88a9a923e5SAnand Kumar Santhanam #define IS_SPCV_12G(dev)	((dev->device == 0X8074)		\
89a9a923e5SAnand Kumar Santhanam 				|| (dev->device == 0X8076)		\
90db9d4034SBenjamin Rood 				|| (dev->device == 0X8077)		\
91db9d4034SBenjamin Rood 				|| (dev->device == 0X8070)		\
92db9d4034SBenjamin Rood 				|| (dev->device == 0X8072))
93dbf9bfe6Sjack wang 
94dbf9bfe6Sjack wang #define PM8001_NAME_LENGTH		32/* generic length of strings */
95dbf9bfe6Sjack wang extern struct list_head hba_list;
96dbf9bfe6Sjack wang extern const struct pm8001_dispatch pm8001_8001_dispatch;
97f5860992SSakthivel K extern const struct pm8001_dispatch pm8001_80xx_dispatch;
98dbf9bfe6Sjack wang 
99dbf9bfe6Sjack wang struct pm8001_hba_info;
100dbf9bfe6Sjack wang struct pm8001_ccb_info;
101dbf9bfe6Sjack wang struct pm8001_device;
102bbfe82cdSJohn Garry 
1037c8356d9Sjack wang struct pm8001_ioctl_payload {
1047c8356d9Sjack wang 	u32	signature;
1057c8356d9Sjack wang 	u16	major_function;
1067c8356d9Sjack wang 	u16	minor_function;
1077c8356d9Sjack wang 	u16	status;
1087c8356d9Sjack wang 	u16	offset;
1097c8356d9Sjack wang 	u16	id;
1109b889846SViswas G 	u32	wr_length;
1119b889846SViswas G 	u32	rd_length;
1127c8356d9Sjack wang 	u8	*func_specific;
1137c8356d9Sjack wang };
1147c8356d9Sjack wang 
115d078b511SAnand Kumar Santhanam #define MPI_FATAL_ERROR_TABLE_OFFSET_MASK 0xFFFFFF
116d078b511SAnand Kumar Santhanam #define MPI_FATAL_ERROR_TABLE_SIZE(value) ((0xFF000000 & value) >> SHIFT24)
117d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_LO_OFFSET            0x00     /* HNFBUFL */
118d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_HI_OFFSET            0x04     /* HNFBUFH */
119d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_LENGTH               0x08     /* HNFBLEN */
120d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_HANDSHAKE            0x0C     /* FDDHSHK */
121d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_STATUS               0x10     /* FDDTSTAT */
122d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_ACCUM_LEN            0x14     /* ACCDDLEN */
123044f59deSDeepak Ukey #define MPI_FATAL_EDUMP_TABLE_TOTAL_LEN		   0x18	    /* TOTALLEN */
124044f59deSDeepak Ukey #define MPI_FATAL_EDUMP_TABLE_SIGNATURE		   0x1C     /* SIGNITURE */
125d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_HANDSHAKE_RDY              0x1
126d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_HANDSHAKE_BUSY             0x0
127d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_STAT_RSVD                 0x0
128d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_STAT_DMA_FAILED           0x1
129d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_MORE_DATA 0x2
130d078b511SAnand Kumar Santhanam #define MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE      0x3
131d078b511SAnand Kumar Santhanam #define TYPE_GSM_SPACE        1
132d078b511SAnand Kumar Santhanam #define TYPE_QUEUE            2
133d078b511SAnand Kumar Santhanam #define TYPE_FATAL            3
134d078b511SAnand Kumar Santhanam #define TYPE_NON_FATAL        4
135d078b511SAnand Kumar Santhanam #define TYPE_INBOUND          1
136d078b511SAnand Kumar Santhanam #define TYPE_OUTBOUND         2
137d078b511SAnand Kumar Santhanam struct forensic_data {
138d078b511SAnand Kumar Santhanam 	u32  data_type;
139d078b511SAnand Kumar Santhanam 	union {
140d078b511SAnand Kumar Santhanam 		struct {
141d078b511SAnand Kumar Santhanam 			u32  direct_len;
142d078b511SAnand Kumar Santhanam 			u32  direct_offset;
143d078b511SAnand Kumar Santhanam 			void  *direct_data;
144d078b511SAnand Kumar Santhanam 		} gsm_buf;
145d078b511SAnand Kumar Santhanam 		struct {
146d078b511SAnand Kumar Santhanam 			u16  queue_type;
147d078b511SAnand Kumar Santhanam 			u16  queue_index;
148d078b511SAnand Kumar Santhanam 			u32  direct_len;
149d078b511SAnand Kumar Santhanam 			void  *direct_data;
150d078b511SAnand Kumar Santhanam 		} queue_buf;
151d078b511SAnand Kumar Santhanam 		struct {
152d078b511SAnand Kumar Santhanam 			u32  direct_len;
153d078b511SAnand Kumar Santhanam 			u32  direct_offset;
154d078b511SAnand Kumar Santhanam 			u32  read_len;
155d078b511SAnand Kumar Santhanam 			void  *direct_data;
156d078b511SAnand Kumar Santhanam 		} data_buf;
157d078b511SAnand Kumar Santhanam 	};
158d078b511SAnand Kumar Santhanam };
159d078b511SAnand Kumar Santhanam 
160d078b511SAnand Kumar Santhanam /* bit31-26 - mask bar */
161d078b511SAnand Kumar Santhanam #define SCRATCH_PAD0_BAR_MASK                    0xFC000000
162d078b511SAnand Kumar Santhanam /* bit25-0  - offset mask */
163d078b511SAnand Kumar Santhanam #define SCRATCH_PAD0_OFFSET_MASK                 0x03FFFFFF
164d078b511SAnand Kumar Santhanam /* if AAP error state */
165d078b511SAnand Kumar Santhanam #define SCRATCH_PAD0_AAPERR_MASK                 0xFFFFFFFF
166d078b511SAnand Kumar Santhanam /* Inbound doorbell bit7 */
167d078b511SAnand Kumar Santhanam #define SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP	 0x80
168d078b511SAnand Kumar Santhanam /* Inbound doorbell bit7 SPCV */
169d078b511SAnand Kumar Santhanam #define SPCV_MSGU_CFG_TABLE_TRANSFER_DEBUG_INFO  0x80
170d078b511SAnand Kumar Santhanam #define MAIN_MERRDCTO_MERRDCES		         0xA0/* DWORD 0x28) */
171d078b511SAnand Kumar Santhanam 
172dbf9bfe6Sjack wang struct pm8001_dispatch {
173dbf9bfe6Sjack wang 	char *name;
174dbf9bfe6Sjack wang 	int (*chip_init)(struct pm8001_hba_info *pm8001_ha);
17598132d84SJohn Garry 	void (*chip_post_init)(struct pm8001_hba_info *pm8001_ha);
176f5860992SSakthivel K 	int (*chip_soft_rst)(struct pm8001_hba_info *pm8001_ha);
177dbf9bfe6Sjack wang 	void (*chip_rst)(struct pm8001_hba_info *pm8001_ha);
178dbf9bfe6Sjack wang 	int (*chip_ioremap)(struct pm8001_hba_info *pm8001_ha);
179dbf9bfe6Sjack wang 	void (*chip_iounmap)(struct pm8001_hba_info *pm8001_ha);
180f74cf271SSakthivel K 	irqreturn_t (*isr)(struct pm8001_hba_info *pm8001_ha, u8 vec);
181f310a4eaSColin Ian King 	u32 (*is_our_interrupt)(struct pm8001_hba_info *pm8001_ha);
182f74cf271SSakthivel K 	int (*isr_process_oq)(struct pm8001_hba_info *pm8001_ha, u8 vec);
183f74cf271SSakthivel K 	void (*interrupt_enable)(struct pm8001_hba_info *pm8001_ha, u8 vec);
184f74cf271SSakthivel K 	void (*interrupt_disable)(struct pm8001_hba_info *pm8001_ha, u8 vec);
185dbf9bfe6Sjack wang 	void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
186dbf9bfe6Sjack wang 	int (*smp_req)(struct pm8001_hba_info *pm8001_ha,
187dbf9bfe6Sjack wang 		struct pm8001_ccb_info *ccb);
188dbf9bfe6Sjack wang 	int (*ssp_io_req)(struct pm8001_hba_info *pm8001_ha,
189dbf9bfe6Sjack wang 		struct pm8001_ccb_info *ccb);
190dbf9bfe6Sjack wang 	int (*sata_req)(struct pm8001_hba_info *pm8001_ha,
191dbf9bfe6Sjack wang 		struct pm8001_ccb_info *ccb);
192dbf9bfe6Sjack wang 	int (*phy_start_req)(struct pm8001_hba_info *pm8001_ha,	u8 phy_id);
193dbf9bfe6Sjack wang 	int (*phy_stop_req)(struct pm8001_hba_info *pm8001_ha, u8 phy_id);
194dbf9bfe6Sjack wang 	int (*reg_dev_req)(struct pm8001_hba_info *pm8001_ha,
195dbf9bfe6Sjack wang 		struct pm8001_device *pm8001_dev, u32 flag);
196dbf9bfe6Sjack wang 	int (*dereg_dev_req)(struct pm8001_hba_info *pm8001_ha, u32 device_id);
197dbf9bfe6Sjack wang 	int (*phy_ctl_req)(struct pm8001_hba_info *pm8001_ha,
198dbf9bfe6Sjack wang 		u32 phy_id, u32 phy_op);
199dbf9bfe6Sjack wang 	int (*task_abort)(struct pm8001_hba_info *pm8001_ha,
2002cbbf489SJohn Garry 		struct pm8001_ccb_info *ccb);
201dbf9bfe6Sjack wang 	int (*ssp_tm_req)(struct pm8001_hba_info *pm8001_ha,
202bbfe82cdSJohn Garry 		struct pm8001_ccb_info *ccb, struct sas_tmf_task *tmf);
203dbf9bfe6Sjack wang 	int (*get_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
204dbf9bfe6Sjack wang 	int (*set_nvmd_req)(struct pm8001_hba_info *pm8001_ha, void *payload);
205dbf9bfe6Sjack wang 	int (*fw_flash_update_req)(struct pm8001_hba_info *pm8001_ha,
206dbf9bfe6Sjack wang 		void *payload);
207dbf9bfe6Sjack wang 	int (*set_dev_state_req)(struct pm8001_hba_info *pm8001_ha,
208dbf9bfe6Sjack wang 		struct pm8001_device *pm8001_dev, u32 state);
209dbf9bfe6Sjack wang 	int (*sas_diag_start_end_req)(struct pm8001_hba_info *pm8001_ha,
210dbf9bfe6Sjack wang 		u32 state);
211dbf9bfe6Sjack wang 	int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha,
212dbf9bfe6Sjack wang 		u32 state);
213d0b68041Sjack_wang 	int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
214a961ea0aSakshatzen 	int (*fatal_errors)(struct pm8001_hba_info *pm8001_ha);
215ee05cb71SAjish Koshy 	void (*hw_event_ack_req)(struct pm8001_hba_info *pm8001_ha,
216ee05cb71SAjish Koshy 		u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0,
217ee05cb71SAjish Koshy 		u32 param1);
218dbf9bfe6Sjack wang };
219dbf9bfe6Sjack wang 
220dbf9bfe6Sjack wang struct pm8001_chip_info {
221e5742101SSakthivel K 	u32     encrypt;
222dbf9bfe6Sjack wang 	u32	n_phy;
223dbf9bfe6Sjack wang 	const struct pm8001_dispatch	*dispatch;
224dbf9bfe6Sjack wang };
225dbf9bfe6Sjack wang #define PM8001_CHIP_DISP	(pm8001_ha->chip->dispatch)
226dbf9bfe6Sjack wang 
227dbf9bfe6Sjack wang struct pm8001_port {
228dbf9bfe6Sjack wang 	struct asd_sas_port	sas_port;
2291cc943aeSjack wang 	u8			port_attached;
2308414cd80SViswas G 	u16			wide_port_phymap;
2311cc943aeSjack wang 	u8			port_state;
23208d0a992SAjish Koshy 	u8			port_id;
2331cc943aeSjack wang 	struct list_head	list;
234dbf9bfe6Sjack wang };
235dbf9bfe6Sjack wang 
236dbf9bfe6Sjack wang struct pm8001_phy {
237dbf9bfe6Sjack wang 	struct pm8001_hba_info	*pm8001_ha;
238dbf9bfe6Sjack wang 	struct pm8001_port	*port;
239dbf9bfe6Sjack wang 	struct asd_sas_phy	sas_phy;
240dbf9bfe6Sjack wang 	struct sas_identify	identify;
241dbf9bfe6Sjack wang 	struct scsi_device	*sdev;
242dbf9bfe6Sjack wang 	u64			dev_sas_addr;
243dbf9bfe6Sjack wang 	u32			phy_type;
244dbf9bfe6Sjack wang 	struct completion	*enable_completion;
245dbf9bfe6Sjack wang 	u32			frame_rcvd_size;
246dbf9bfe6Sjack wang 	u8			frame_rcvd[32];
247dbf9bfe6Sjack wang 	u8			phy_attached;
248dbf9bfe6Sjack wang 	u8			phy_state;
249dbf9bfe6Sjack wang 	enum sas_linkrate	minimum_linkrate;
250dbf9bfe6Sjack wang 	enum sas_linkrate	maximum_linkrate;
251869ddbdcSViswas G 	struct completion	*reset_completion;
252869ddbdcSViswas G 	bool			port_reset_status;
253869ddbdcSViswas G 	bool			reset_success;
254dbf9bfe6Sjack wang };
255dbf9bfe6Sjack wang 
256869ddbdcSViswas G /* port reset status */
257869ddbdcSViswas G #define PORT_RESET_SUCCESS	0x00
258869ddbdcSViswas G #define PORT_RESET_TMO		0x01
259869ddbdcSViswas G 
260dbf9bfe6Sjack wang struct pm8001_device {
261aa9f8328SJames Bottomley 	enum sas_device_type	dev_type;
262dbf9bfe6Sjack wang 	struct domain_device	*sas_device;
263dbf9bfe6Sjack wang 	u32			attached_phy;
264dbf9bfe6Sjack wang 	u32			id;
265dbf9bfe6Sjack wang 	struct completion	*dcompletion;
266dbf9bfe6Sjack wang 	struct completion	*setds_completion;
267dbf9bfe6Sjack wang 	u32			device_id;
2684a2efd4bSViswas G 	atomic_t		running_req;
269dbf9bfe6Sjack wang };
270dbf9bfe6Sjack wang 
271dbf9bfe6Sjack wang struct pm8001_prd_imt {
272dbf9bfe6Sjack wang 	__le32			len;
273dbf9bfe6Sjack wang 	__le32			e;
274dbf9bfe6Sjack wang };
275dbf9bfe6Sjack wang 
276dbf9bfe6Sjack wang struct pm8001_prd {
277dbf9bfe6Sjack wang 	__le64			addr;		/* 64-bit buffer address */
278dbf9bfe6Sjack wang 	struct pm8001_prd_imt	im_len;		/* 64-bit length */
279dbf9bfe6Sjack wang } __attribute__ ((packed));
280dbf9bfe6Sjack wang /*
281dbf9bfe6Sjack wang  * CCB(Command Control Block)
282dbf9bfe6Sjack wang  */
283dbf9bfe6Sjack wang struct pm8001_ccb_info {
284dbf9bfe6Sjack wang 	struct sas_task		*task;
285dbf9bfe6Sjack wang 	u32			n_elem;
286dbf9bfe6Sjack wang 	u32			ccb_tag;
287dbf9bfe6Sjack wang 	dma_addr_t		ccb_dma_handle;
288dbf9bfe6Sjack wang 	struct pm8001_device	*device;
2895a141315SViswas G 	struct pm8001_prd	*buf_prd;
290dbf9bfe6Sjack wang 	struct fw_control_ex	*fw_control_context;
2915954d738SMark Salyzyn 	u8			open_retry;
292dbf9bfe6Sjack wang };
293dbf9bfe6Sjack wang 
294dbf9bfe6Sjack wang struct mpi_mem {
295dbf9bfe6Sjack wang 	void			*virt_ptr;
296dbf9bfe6Sjack wang 	dma_addr_t		phys_addr;
297dbf9bfe6Sjack wang 	u32			phys_addr_hi;
298dbf9bfe6Sjack wang 	u32			phys_addr_lo;
299dbf9bfe6Sjack wang 	u32			total_len;
300dbf9bfe6Sjack wang 	u32			num_elements;
301dbf9bfe6Sjack wang 	u32			element_size;
302dbf9bfe6Sjack wang 	u32			alignment;
303dbf9bfe6Sjack wang };
304dbf9bfe6Sjack wang 
305dbf9bfe6Sjack wang struct mpi_mem_req {
306dbf9bfe6Sjack wang 	/* The number of element in the  mpiMemory array */
307dbf9bfe6Sjack wang 	u32			count;
308dbf9bfe6Sjack wang 	/* The array of structures that define memroy regions*/
309dbf9bfe6Sjack wang 	struct mpi_mem		region[USI_MAX_MEMCNT];
310dbf9bfe6Sjack wang };
311dbf9bfe6Sjack wang 
312e5742101SSakthivel K struct encrypt {
313e5742101SSakthivel K 	u32	cipher_mode;
314e5742101SSakthivel K 	u32	sec_mode;
315e5742101SSakthivel K 	u32	status;
316e5742101SSakthivel K 	u32	flag;
317e5742101SSakthivel K };
318e5742101SSakthivel K 
319e5742101SSakthivel K struct sas_phy_attribute_table {
320e5742101SSakthivel K 	u32	phystart1_16[16];
321e5742101SSakthivel K 	u32	outbound_hw_event_pid1_16[16];
322e5742101SSakthivel K };
323e5742101SSakthivel K 
324e5742101SSakthivel K union main_cfg_table {
325e5742101SSakthivel K 	struct {
326dbf9bfe6Sjack wang 	u32			signature;
327dbf9bfe6Sjack wang 	u32			interface_rev;
328dbf9bfe6Sjack wang 	u32			firmware_rev;
329dbf9bfe6Sjack wang 	u32			max_out_io;
330dbf9bfe6Sjack wang 	u32			max_sgl;
331dbf9bfe6Sjack wang 	u32			ctrl_cap_flag;
332dbf9bfe6Sjack wang 	u32			gst_offset;
333dbf9bfe6Sjack wang 	u32			inbound_queue_offset;
334dbf9bfe6Sjack wang 	u32			outbound_queue_offset;
335dbf9bfe6Sjack wang 	u32			inbound_q_nppd_hppd;
336dbf9bfe6Sjack wang 	u32			outbound_hw_event_pid0_3;
337dbf9bfe6Sjack wang 	u32			outbound_hw_event_pid4_7;
338dbf9bfe6Sjack wang 	u32			outbound_ncq_event_pid0_3;
339dbf9bfe6Sjack wang 	u32			outbound_ncq_event_pid4_7;
340dbf9bfe6Sjack wang 	u32			outbound_tgt_ITNexus_event_pid0_3;
341dbf9bfe6Sjack wang 	u32			outbound_tgt_ITNexus_event_pid4_7;
342dbf9bfe6Sjack wang 	u32			outbound_tgt_ssp_event_pid0_3;
343dbf9bfe6Sjack wang 	u32			outbound_tgt_ssp_event_pid4_7;
344dbf9bfe6Sjack wang 	u32			outbound_tgt_smp_event_pid0_3;
345dbf9bfe6Sjack wang 	u32			outbound_tgt_smp_event_pid4_7;
346dbf9bfe6Sjack wang 	u32			upper_event_log_addr;
347dbf9bfe6Sjack wang 	u32			lower_event_log_addr;
348dbf9bfe6Sjack wang 	u32			event_log_size;
349dbf9bfe6Sjack wang 	u32			event_log_option;
350dbf9bfe6Sjack wang 	u32			upper_iop_event_log_addr;
351dbf9bfe6Sjack wang 	u32			lower_iop_event_log_addr;
352dbf9bfe6Sjack wang 	u32			iop_event_log_size;
353dbf9bfe6Sjack wang 	u32			iop_event_log_option;
354dbf9bfe6Sjack wang 	u32			fatal_err_interrupt;
355dbf9bfe6Sjack wang 	u32			fatal_err_dump_offset0;
356dbf9bfe6Sjack wang 	u32			fatal_err_dump_length0;
357dbf9bfe6Sjack wang 	u32			fatal_err_dump_offset1;
358dbf9bfe6Sjack wang 	u32			fatal_err_dump_length1;
359dbf9bfe6Sjack wang 	u32			hda_mode_flag;
360dbf9bfe6Sjack wang 	u32			anolog_setup_table_offset;
361e5742101SSakthivel K 	u32			rsvd[4];
362e5742101SSakthivel K 	} pm8001_tbl;
363e5742101SSakthivel K 
364e5742101SSakthivel K 	struct {
365e5742101SSakthivel K 	u32			signature;
366e5742101SSakthivel K 	u32			interface_rev;
367e5742101SSakthivel K 	u32			firmware_rev;
368e5742101SSakthivel K 	u32			max_out_io;
369e5742101SSakthivel K 	u32			max_sgl;
370e5742101SSakthivel K 	u32			ctrl_cap_flag;
371e5742101SSakthivel K 	u32			gst_offset;
372e5742101SSakthivel K 	u32			inbound_queue_offset;
373e5742101SSakthivel K 	u32			outbound_queue_offset;
374e5742101SSakthivel K 	u32			inbound_q_nppd_hppd;
375c6b9ef57SSakthivel K 	u32			rsvd[8];
376c6b9ef57SSakthivel K 	u32			crc_core_dump;
377c6b9ef57SSakthivel K 	u32			rsvd1;
378e5742101SSakthivel K 	u32			upper_event_log_addr;
379e5742101SSakthivel K 	u32			lower_event_log_addr;
380e5742101SSakthivel K 	u32			event_log_size;
381e5742101SSakthivel K 	u32			event_log_severity;
382e5742101SSakthivel K 	u32			upper_pcs_event_log_addr;
383e5742101SSakthivel K 	u32			lower_pcs_event_log_addr;
384e5742101SSakthivel K 	u32			pcs_event_log_size;
385e5742101SSakthivel K 	u32			pcs_event_log_severity;
386e5742101SSakthivel K 	u32			fatal_err_interrupt;
387e5742101SSakthivel K 	u32			fatal_err_dump_offset0;
388e5742101SSakthivel K 	u32			fatal_err_dump_length0;
389e5742101SSakthivel K 	u32			fatal_err_dump_offset1;
390e5742101SSakthivel K 	u32			fatal_err_dump_length1;
391e5742101SSakthivel K 	u32			gpio_led_mapping;
392e5742101SSakthivel K 	u32			analog_setup_table_offset;
393e5742101SSakthivel K 	u32			int_vec_table_offset;
394e5742101SSakthivel K 	u32			phy_attr_table_offset;
395e5742101SSakthivel K 	u32			port_recovery_timer;
396e5742101SSakthivel K 	u32			interrupt_reassertion_delay;
397d078b511SAnand Kumar Santhanam 	u32			fatal_n_non_fatal_dump;	        /* 0x28 */
39824fff017SViswas G 	u32			ila_version;
39924fff017SViswas G 	u32			inc_fw_version;
400e5742101SSakthivel K 	} pm80xx_tbl;
401dbf9bfe6Sjack wang };
402e5742101SSakthivel K 
403e5742101SSakthivel K union general_status_table {
404e5742101SSakthivel K 	struct {
405dbf9bfe6Sjack wang 	u32			gst_len_mpistate;
406dbf9bfe6Sjack wang 	u32			iq_freeze_state0;
407dbf9bfe6Sjack wang 	u32			iq_freeze_state1;
408dbf9bfe6Sjack wang 	u32			msgu_tcnt;
409dbf9bfe6Sjack wang 	u32			iop_tcnt;
410e5742101SSakthivel K 	u32			rsvd;
411dbf9bfe6Sjack wang 	u32			phy_state[8];
412e5742101SSakthivel K 	u32			gpio_input_val;
413e5742101SSakthivel K 	u32			rsvd1[2];
414dbf9bfe6Sjack wang 	u32			recover_err_info[8];
415e5742101SSakthivel K 	} pm8001_tbl;
416e5742101SSakthivel K 	struct {
417e5742101SSakthivel K 	u32			gst_len_mpistate;
418e5742101SSakthivel K 	u32			iq_freeze_state0;
419e5742101SSakthivel K 	u32			iq_freeze_state1;
420e5742101SSakthivel K 	u32			msgu_tcnt;
421e5742101SSakthivel K 	u32			iop_tcnt;
422e5742101SSakthivel K 	u32			rsvd[9];
423e5742101SSakthivel K 	u32			gpio_input_val;
424e5742101SSakthivel K 	u32			rsvd1[2];
425e5742101SSakthivel K 	u32			recover_err_info[8];
426e5742101SSakthivel K 	} pm80xx_tbl;
427dbf9bfe6Sjack wang };
428dbf9bfe6Sjack wang struct inbound_queue_table {
429dbf9bfe6Sjack wang 	u32			element_pri_size_cnt;
430dbf9bfe6Sjack wang 	u32			upper_base_addr;
431dbf9bfe6Sjack wang 	u32			lower_base_addr;
432dbf9bfe6Sjack wang 	u32			ci_upper_base_addr;
433dbf9bfe6Sjack wang 	u32			ci_lower_base_addr;
434dbf9bfe6Sjack wang 	u32			pi_pci_bar;
435dbf9bfe6Sjack wang 	u32			pi_offset;
436dbf9bfe6Sjack wang 	u32			total_length;
437dbf9bfe6Sjack wang 	void			*base_virt;
438dbf9bfe6Sjack wang 	void			*ci_virt;
439dbf9bfe6Sjack wang 	u32			reserved;
440dbf9bfe6Sjack wang 	__le32			consumer_index;
441dbf9bfe6Sjack wang 	u32			producer_idx;
44205c6c029SViswas G 	spinlock_t		iq_lock;
443dbf9bfe6Sjack wang };
444dbf9bfe6Sjack wang struct outbound_queue_table {
445dbf9bfe6Sjack wang 	u32			element_size_cnt;
446dbf9bfe6Sjack wang 	u32			upper_base_addr;
447dbf9bfe6Sjack wang 	u32			lower_base_addr;
448dbf9bfe6Sjack wang 	void			*base_virt;
449dbf9bfe6Sjack wang 	u32			pi_upper_base_addr;
450dbf9bfe6Sjack wang 	u32			pi_lower_base_addr;
451dbf9bfe6Sjack wang 	u32			ci_pci_bar;
452dbf9bfe6Sjack wang 	u32			ci_offset;
453dbf9bfe6Sjack wang 	u32			total_length;
454dbf9bfe6Sjack wang 	void			*pi_virt;
455dbf9bfe6Sjack wang 	u32			interrup_vec_cnt_delay;
456dbf9bfe6Sjack wang 	u32			dinterrup_to_pci_offset;
457dbf9bfe6Sjack wang 	__le32			producer_index;
458dbf9bfe6Sjack wang 	u32			consumer_idx;
4591f02beffSViswas G 	spinlock_t		oq_lock;
460b27a4053SAjish Koshy 	unsigned long		lock_flags;
461dbf9bfe6Sjack wang };
462dbf9bfe6Sjack wang struct pm8001_hba_memspace {
463dbf9bfe6Sjack wang 	void __iomem  		*memvirtaddr;
464dbf9bfe6Sjack wang 	u64			membase;
465dbf9bfe6Sjack wang 	u32			memsize;
466dbf9bfe6Sjack wang };
4676cd60b37SNikith Ganigarakoppal struct isr_param {
4686cd60b37SNikith Ganigarakoppal 	struct pm8001_hba_info *drv_inst;
4696cd60b37SNikith Ganigarakoppal 	u32 irq_id;
4706cd60b37SNikith Ganigarakoppal };
471dbf9bfe6Sjack wang struct pm8001_hba_info {
472dbf9bfe6Sjack wang 	char			name[PM8001_NAME_LENGTH];
473dbf9bfe6Sjack wang 	struct list_head	list;
474dbf9bfe6Sjack wang 	unsigned long		flags;
475dbf9bfe6Sjack wang 	spinlock_t		lock;/* host-wide lock */
476646cdf00STomas Henzl 	spinlock_t		bitmap_lock;
477dbf9bfe6Sjack wang 	struct pci_dev		*pdev;/* our device */
478dbf9bfe6Sjack wang 	struct device		*dev;
479dbf9bfe6Sjack wang 	struct pm8001_hba_memspace io_mem[6];
480dbf9bfe6Sjack wang 	struct mpi_mem_req	memoryMap;
481e5742101SSakthivel K 	struct encrypt		encrypt_info; /* support encryption */
482d078b511SAnand Kumar Santhanam 	struct forensic_data	forensic_info;
483d078b511SAnand Kumar Santhanam 	u32			fatal_bar_loc;
484d078b511SAnand Kumar Santhanam 	u32			forensic_last_offset;
485d078b511SAnand Kumar Santhanam 	u32			fatal_forensic_shift_offset;
486d078b511SAnand Kumar Santhanam 	u32			forensic_fatal_step;
487044f59deSDeepak Ukey 	u32			forensic_preserved_accumulated_transfer;
488d078b511SAnand Kumar Santhanam 	u32			evtlog_ib_offset;
489d078b511SAnand Kumar Santhanam 	u32			evtlog_ob_offset;
490dbf9bfe6Sjack wang 	void __iomem	*msg_unit_tbl_addr;/*Message Unit Table Addr*/
491dbf9bfe6Sjack wang 	void __iomem	*main_cfg_tbl_addr;/*Main Config Table Addr*/
492dbf9bfe6Sjack wang 	void __iomem	*general_stat_tbl_addr;/*General Status Table Addr*/
493dbf9bfe6Sjack wang 	void __iomem	*inbnd_q_tbl_addr;/*Inbound Queue Config Table Addr*/
494dbf9bfe6Sjack wang 	void __iomem	*outbnd_q_tbl_addr;/*Outbound Queue Config Table Addr*/
495e5742101SSakthivel K 	void __iomem	*pspa_q_tbl_addr;
496e5742101SSakthivel K 			/*MPI SAS PHY attributes Queue Config Table Addr*/
497e5742101SSakthivel K 	void __iomem	*ivt_tbl_addr; /*MPI IVT Table Addr */
498d078b511SAnand Kumar Santhanam 	void __iomem	*fatal_tbl_addr; /*MPI IVT Table Addr */
499e5742101SSakthivel K 	union main_cfg_table	main_cfg_tbl;
500e5742101SSakthivel K 	union general_status_table	gs_tbl;
50105c6c029SViswas G 	struct inbound_queue_table	inbnd_q_tbl[PM8001_MAX_INB_NUM];
50205c6c029SViswas G 	struct outbound_queue_table	outbnd_q_tbl[PM8001_MAX_OUTB_NUM];
503e5742101SSakthivel K 	struct sas_phy_attribute_table	phy_attr_table;
504e5742101SSakthivel K 					/* MPI SAS PHY attributes */
505dbf9bfe6Sjack wang 	u8			sas_addr[SAS_ADDR_SIZE];
506dbf9bfe6Sjack wang 	struct sas_ha_struct	*sas;/* SCSI/SAS glue */
507dbf9bfe6Sjack wang 	struct Scsi_Host	*shost;
508dbf9bfe6Sjack wang 	u32			chip_id;
509dbf9bfe6Sjack wang 	const struct pm8001_chip_info	*chip;
510dbf9bfe6Sjack wang 	struct completion	*nvmd_completion;
5116472cfb4SJohn Garry 	unsigned long		*rsvd_tags;
512dbf9bfe6Sjack wang 	struct pm8001_phy	phy[PM8001_MAX_PHYS];
513dbf9bfe6Sjack wang 	struct pm8001_port	port[PM8001_MAX_PHYS];
514dbf9bfe6Sjack wang 	u32			id;
515dbf9bfe6Sjack wang 	u32			irq;
516e5742101SSakthivel K 	u32			iomb_size; /* SPC and SPCV IOMB size */
517dbf9bfe6Sjack wang 	struct pm8001_device	*devices;
518dbf9bfe6Sjack wang 	struct pm8001_ccb_info	*ccb_info;
51951e6ed83SAjish Koshy 	u32			ccb_count;
520efa1fca4SDamien Le Moal 
521efa1fca4SDamien Le Moal 	bool			use_msix;
522dbf9bfe6Sjack wang 	int			number_of_intr;/*will be used in remove()*/
52372954936SVikram Auradkar 	char			intr_drvname[PM8001_MAX_MSIX_VEC]
52472954936SVikram Auradkar 				[PM8001_NAME_LENGTH+1+3+1];
5256cd60b37SNikith Ganigarakoppal 	struct tasklet_struct	tasklet[PM8001_MAX_MSIX_VEC];
526dbf9bfe6Sjack wang 	u32			logging_level;
5273e253d96Speter chang 	u32			link_rate;
528dbf9bfe6Sjack wang 	u32			fw_status;
529f5860992SSakthivel K 	u32			smp_exp_mode;
53072349b62SDeepak Ukey 	bool			controller_fatal_error;
531dbf9bfe6Sjack wang 	const struct firmware 	*fw_image;
5326cd60b37SNikith Ganigarakoppal 	struct isr_param irq_vector[PM8001_MAX_MSIX_VEC];
533dba2cc03SDeepak Ukey 	u32			non_fatal_count;
534dba2cc03SDeepak Ukey 	u32			non_fatal_read_length;
53505c6c029SViswas G 	u32 max_q_num;
53605c6c029SViswas G 	u32 ib_offset;
53705c6c029SViswas G 	u32 ob_offset;
53805c6c029SViswas G 	u32 ci_offset;
53905c6c029SViswas G 	u32 pi_offset;
54005c6c029SViswas G 	u32 max_memcnt;
541dbf9bfe6Sjack wang };
542dbf9bfe6Sjack wang 
543429305e4STejun Heo struct pm8001_work {
544429305e4STejun Heo 	struct work_struct work;
545dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha;
546dbf9bfe6Sjack wang 	void *data;
547dbf9bfe6Sjack wang 	int handler;
548dbf9bfe6Sjack wang };
549dbf9bfe6Sjack wang 
550dbf9bfe6Sjack wang struct pm8001_fw_image_header {
551dbf9bfe6Sjack wang 	u8 vender_id[8];
552dbf9bfe6Sjack wang 	u8 product_id;
553dbf9bfe6Sjack wang 	u8 hardware_rev;
554dbf9bfe6Sjack wang 	u8 dest_partition;
555dbf9bfe6Sjack wang 	u8 reserved;
556dbf9bfe6Sjack wang 	u8 fw_rev[4];
557dbf9bfe6Sjack wang 	__be32  image_length;
558dbf9bfe6Sjack wang 	__be32 image_crc;
559dbf9bfe6Sjack wang 	__be32 startup_entry;
560dbf9bfe6Sjack wang } __attribute__((packed, aligned(4)));
561dbf9bfe6Sjack wang 
5627c8356d9Sjack wang 
563dbf9bfe6Sjack wang /**
564dbf9bfe6Sjack wang  * FW Flash Update status values
565dbf9bfe6Sjack wang  */
566dbf9bfe6Sjack wang #define FLASH_UPDATE_COMPLETE_PENDING_REBOOT	0x00
567dbf9bfe6Sjack wang #define FLASH_UPDATE_IN_PROGRESS		0x01
568dbf9bfe6Sjack wang #define FLASH_UPDATE_HDR_ERR			0x02
569dbf9bfe6Sjack wang #define FLASH_UPDATE_OFFSET_ERR			0x03
570dbf9bfe6Sjack wang #define FLASH_UPDATE_CRC_ERR			0x04
571dbf9bfe6Sjack wang #define FLASH_UPDATE_LENGTH_ERR			0x05
572dbf9bfe6Sjack wang #define FLASH_UPDATE_HW_ERR			0x06
573dbf9bfe6Sjack wang #define FLASH_UPDATE_DNLD_NOT_SUPPORTED		0x10
574dbf9bfe6Sjack wang #define FLASH_UPDATE_DISABLED			0x11
575dbf9bfe6Sjack wang 
5763a1ae967SViswas G /* Device states */
5773a1ae967SViswas G #define DS_OPERATIONAL				0x01
5783a1ae967SViswas G #define DS_PORT_IN_RESET			0x02
5793a1ae967SViswas G #define DS_IN_RECOVERY				0x03
5803a1ae967SViswas G #define DS_IN_ERROR				0x04
5813a1ae967SViswas G #define DS_NON_OPERATIONAL			0x07
5823a1ae967SViswas G 
583dbf9bfe6Sjack wang /**
584dbf9bfe6Sjack wang  * brief param structure for firmware flash update.
585dbf9bfe6Sjack wang  */
586dbf9bfe6Sjack wang struct fw_flash_updata_info {
587dbf9bfe6Sjack wang 	u32			cur_image_offset;
588dbf9bfe6Sjack wang 	u32			cur_image_len;
589dbf9bfe6Sjack wang 	u32			total_image_len;
590dbf9bfe6Sjack wang 	struct pm8001_prd	sgl;
591dbf9bfe6Sjack wang };
592dbf9bfe6Sjack wang 
593dbf9bfe6Sjack wang struct fw_control_info {
594dbf9bfe6Sjack wang 	u32			retcode;/*ret code (status)*/
595dbf9bfe6Sjack wang 	u32			phase;/*ret code phase*/
596dbf9bfe6Sjack wang 	u32			phaseCmplt;/*percent complete for the current
597dbf9bfe6Sjack wang 	update phase */
598dbf9bfe6Sjack wang 	u32			version;/*Hex encoded firmware version number*/
599dbf9bfe6Sjack wang 	u32			offset;/*Used for downloading firmware	*/
600dbf9bfe6Sjack wang 	u32			len; /*len of buffer*/
601dbf9bfe6Sjack wang 	u32			size;/* Used in OS VPD and Trace get size
602dbf9bfe6Sjack wang 	operations.*/
603dbf9bfe6Sjack wang 	u32			reserved;/* padding required for 64 bit
604dbf9bfe6Sjack wang 	alignment */
605fd2f0452SGustavo A. R. Silva 	u8			buffer[];/* Start of buffer */
606dbf9bfe6Sjack wang };
607dbf9bfe6Sjack wang struct fw_control_ex {
608dbf9bfe6Sjack wang 	struct fw_control_info *fw_control;
609dbf9bfe6Sjack wang 	void			*buffer;/* keep buffer pointer to be
61025985edcSLucas De Marchi 	freed when the response comes*/
611dbf9bfe6Sjack wang 	void			*virtAddr;/* keep virtual address of the data */
612dbf9bfe6Sjack wang 	void			*usrAddr;/* keep virtual address of the
613dbf9bfe6Sjack wang 	user data */
614dbf9bfe6Sjack wang 	dma_addr_t		phys_addr;
615dbf9bfe6Sjack wang 	u32			len; /* len of buffer  */
616dbf9bfe6Sjack wang 	void			*payload; /* pointer to IOCTL Payload */
617dbf9bfe6Sjack wang 	u8			inProgress;/*if 1 - the IOCTL request is in
618dbf9bfe6Sjack wang 	progress */
619dbf9bfe6Sjack wang 	void			*param1;
620dbf9bfe6Sjack wang 	void			*param2;
621dbf9bfe6Sjack wang 	void			*param3;
622dbf9bfe6Sjack wang };
623dbf9bfe6Sjack wang 
624429305e4STejun Heo /* pm8001 workqueue */
625429305e4STejun Heo extern struct workqueue_struct *pm8001_wq;
626429305e4STejun Heo 
627dbf9bfe6Sjack wang /******************** function prototype *********************/
628dbf9bfe6Sjack wang int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out);
629dbf9bfe6Sjack wang u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag);
630dbf9bfe6Sjack wang void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
631304fe11bSDamien Le Moal 			  struct pm8001_ccb_info *ccb);
632dbf9bfe6Sjack wang int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
633dbf9bfe6Sjack wang 	void *funcdata);
634dbf9bfe6Sjack wang void pm8001_scan_start(struct Scsi_Host *shost);
635dbf9bfe6Sjack wang int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time);
63679855d17SChristoph Hellwig int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags);
637dbf9bfe6Sjack wang int pm8001_abort_task(struct sas_task *task);
638dbf9bfe6Sjack wang int pm8001_clear_task_set(struct domain_device *dev, u8 *lun);
639dbf9bfe6Sjack wang int pm8001_dev_found(struct domain_device *dev);
640dbf9bfe6Sjack wang void pm8001_dev_gone(struct domain_device *dev);
641dbf9bfe6Sjack wang int pm8001_lu_reset(struct domain_device *dev, u8 *lun);
642dbf9bfe6Sjack wang int pm8001_I_T_nexus_reset(struct domain_device *dev);
643a6cb3d01SSakthivel K int pm8001_I_T_nexus_event_handler(struct domain_device *dev);
644dbf9bfe6Sjack wang int pm8001_query_task(struct sas_task *task);
64508d0a992SAjish Koshy void pm8001_port_formed(struct asd_sas_phy *sas_phy);
6465954d738SMark Salyzyn void pm8001_open_reject_retry(
6475954d738SMark Salyzyn 	struct pm8001_hba_info *pm8001_ha,
6485954d738SMark Salyzyn 	struct sas_task *task_to_close,
6495954d738SMark Salyzyn 	struct pm8001_device *device_to_close);
650dbf9bfe6Sjack wang int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
651dbf9bfe6Sjack wang 	dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
652dbf9bfe6Sjack wang 	u32 mem_size, u32 align);
653dbf9bfe6Sjack wang 
654f74cf271SSakthivel K void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha);
655f74cf271SSakthivel K int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
656f91767a3SDamien Le Moal 			u32 q_index, u32 opCode, void *payload, size_t nb,
65791a43fa6Speter chang 			u32 responseQueue);
658f74cf271SSakthivel K int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
659f74cf271SSakthivel K 				u16 messageSize, void **messagePtr);
660f74cf271SSakthivel K u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
661f74cf271SSakthivel K 			struct outbound_queue_table *circularQ, u8 bc);
662f74cf271SSakthivel K u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
663f74cf271SSakthivel K 			struct outbound_queue_table *circularQ,
664f74cf271SSakthivel K 			void **messagePtr1, u8 *pBC);
665f74cf271SSakthivel K int pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
666f74cf271SSakthivel K 			struct pm8001_device *pm8001_dev, u32 state);
667f74cf271SSakthivel K int pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
668f74cf271SSakthivel K 					void *payload);
669f74cf271SSakthivel K int pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
670f74cf271SSakthivel K 					void *fw_flash_updata_info, u32 tag);
671f74cf271SSakthivel K int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload);
672f74cf271SSakthivel K int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload);
673f74cf271SSakthivel K int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
674f74cf271SSakthivel K 				struct pm8001_ccb_info *ccb,
675bbfe82cdSJohn Garry 				struct sas_tmf_task *tmf);
676f74cf271SSakthivel K int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
6772cbbf489SJohn Garry 				struct pm8001_ccb_info *ccb);
678f74cf271SSakthivel K int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha, u32 device_id);
679f74cf271SSakthivel K void pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd);
680f74cf271SSakthivel K void pm8001_work_fn(struct work_struct *work);
681f74cf271SSakthivel K int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha,
682f74cf271SSakthivel K 					void *data, int handler);
683f74cf271SSakthivel K void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha,
684f74cf271SSakthivel K 							void *piomb);
685f74cf271SSakthivel K void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha,
686f74cf271SSakthivel K 							void *piomb);
687f74cf271SSakthivel K void pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha,
688f74cf271SSakthivel K 							void *piomb);
689f74cf271SSakthivel K int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha,
690f74cf271SSakthivel K 							void *piomb);
691f74cf271SSakthivel K void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate);
692f74cf271SSakthivel K void pm8001_get_attached_sas_addr(struct pm8001_phy *phy, u8 *sas_addr);
693f74cf271SSakthivel K void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i);
694f74cf271SSakthivel K int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb);
695f74cf271SSakthivel K int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb);
696f74cf271SSakthivel K int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha,
697f74cf271SSakthivel K 							void *piomb);
698f74cf271SSakthivel K int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb);
699f74cf271SSakthivel K int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb);
700c6b9ef57SSakthivel K void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag);
701c6b9ef57SSakthivel K struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha,
702c6b9ef57SSakthivel K 					u32 device_id);
703a6cb3d01SSakthivel K int pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha);
704f74cf271SSakthivel K 
705d95d0001SMark Salyzyn int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue);
70627909407SAnand Kumar Santhanam void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
70727909407SAnand Kumar Santhanam 	u32 length, u8 *buf);
708c5614df7SBenjamin Rood void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha,
709c5614df7SBenjamin Rood 		u32 phy, u32 length, u32 *buf);
710d078b511SAnand Kumar Santhanam int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue);
711d078b511SAnand Kumar Santhanam ssize_t pm80xx_get_fatal_dump(struct device *cdev,
712d078b511SAnand Kumar Santhanam 		struct device_attribute *attr, char *buf);
713dba2cc03SDeepak Ukey ssize_t pm80xx_get_non_fatal_dump(struct device *cdev,
714dba2cc03SDeepak Ukey 		struct device_attribute *attr, char *buf);
715d078b511SAnand Kumar Santhanam ssize_t pm8001_get_gsm_dump(struct device *cdev, u32, char *buf);
716a961ea0aSakshatzen int pm80xx_fatal_errors(struct pm8001_hba_info *pm8001_ha);
7174f5deeb4SRuksar Devadi void pm8001_free_dev(struct pm8001_device *pm8001_dev);
718dbf9bfe6Sjack wang /* ctl shared API */
719c03b72b8SBart Van Assche extern const struct attribute_group *pm8001_host_groups[];
720*9fa095aeSIgor Pylypiv extern const struct attribute_group *pm8001_sdev_groups[];
721dbf9bfe6Sjack wang 
7227fb23a78SDamien Le Moal #define PM8001_INVALID_TAG	((u32)-1)
7237fb23a78SDamien Le Moal 
72499df0edbSDamien Le Moal /*
72599df0edbSDamien Le Moal  * Allocate a new tag and return the corresponding ccb after initializing it.
72699df0edbSDamien Le Moal  */
72799df0edbSDamien Le Moal static inline struct pm8001_ccb_info *
pm8001_ccb_alloc(struct pm8001_hba_info * pm8001_ha,struct pm8001_device * dev,struct sas_task * task)72899df0edbSDamien Le Moal pm8001_ccb_alloc(struct pm8001_hba_info *pm8001_ha,
72999df0edbSDamien Le Moal 		 struct pm8001_device *dev, struct sas_task *task)
73099df0edbSDamien Le Moal {
73199df0edbSDamien Le Moal 	struct pm8001_ccb_info *ccb;
7326472cfb4SJohn Garry 	struct request *rq = NULL;
73399df0edbSDamien Le Moal 	u32 tag;
73499df0edbSDamien Le Moal 
7356472cfb4SJohn Garry 	if (task)
7366472cfb4SJohn Garry 		rq = sas_task_find_rq(task);
7376472cfb4SJohn Garry 
7386472cfb4SJohn Garry 	if (rq) {
7396472cfb4SJohn Garry 		tag = rq->tag + PM8001_RESERVE_SLOT;
7406472cfb4SJohn Garry 	} else if (pm8001_tag_alloc(pm8001_ha, &tag)) {
74199df0edbSDamien Le Moal 		pm8001_dbg(pm8001_ha, FAIL, "Failed to allocate a tag\n");
74299df0edbSDamien Le Moal 		return NULL;
74399df0edbSDamien Le Moal 	}
74499df0edbSDamien Le Moal 
74599df0edbSDamien Le Moal 	ccb = &pm8001_ha->ccb_info[tag];
74699df0edbSDamien Le Moal 	ccb->task = task;
74799df0edbSDamien Le Moal 	ccb->n_elem = 0;
74899df0edbSDamien Le Moal 	ccb->ccb_tag = tag;
74999df0edbSDamien Le Moal 	ccb->device = dev;
75099df0edbSDamien Le Moal 	ccb->fw_control_context = NULL;
75199df0edbSDamien Le Moal 	ccb->open_retry = 0;
75299df0edbSDamien Le Moal 
75399df0edbSDamien Le Moal 	return ccb;
75499df0edbSDamien Le Moal }
75599df0edbSDamien Le Moal 
75699df0edbSDamien Le Moal /*
75799df0edbSDamien Le Moal  * Free the tag of an initialized ccb.
75899df0edbSDamien Le Moal  */
pm8001_ccb_free(struct pm8001_hba_info * pm8001_ha,struct pm8001_ccb_info * ccb)75999df0edbSDamien Le Moal static inline void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha,
76099df0edbSDamien Le Moal 				   struct pm8001_ccb_info *ccb)
76199df0edbSDamien Le Moal {
76299df0edbSDamien Le Moal 	u32 tag = ccb->ccb_tag;
76399df0edbSDamien Le Moal 
76499df0edbSDamien Le Moal 	/*
76599df0edbSDamien Le Moal 	 * Cleanup the ccb to make sure that a manual scan of the adapter
76699df0edbSDamien Le Moal 	 * ccb_info array can detect ccb's that are in use.
76799df0edbSDamien Le Moal 	 * C.f. pm8001_open_reject_retry()
76899df0edbSDamien Le Moal 	 */
76999df0edbSDamien Le Moal 	ccb->task = NULL;
77099df0edbSDamien Le Moal 	ccb->ccb_tag = PM8001_INVALID_TAG;
77199df0edbSDamien Le Moal 	ccb->device = NULL;
77299df0edbSDamien Le Moal 	ccb->fw_control_context = NULL;
77399df0edbSDamien Le Moal 
77499df0edbSDamien Le Moal 	pm8001_tag_free(pm8001_ha, tag);
77599df0edbSDamien Le Moal }
77699df0edbSDamien Le Moal 
pm8001_ccb_task_free_done(struct pm8001_hba_info * pm8001_ha,struct pm8001_ccb_info * ccb)777304fe11bSDamien Le Moal static inline void pm8001_ccb_task_free_done(struct pm8001_hba_info *pm8001_ha,
778304fe11bSDamien Le Moal 					     struct pm8001_ccb_info *ccb)
7792b01d816SSuresh Thiagarajan {
780304fe11bSDamien Le Moal 	struct sas_task *task = ccb->task;
781304fe11bSDamien Le Moal 
782304fe11bSDamien Le Moal 	pm8001_ccb_task_free(pm8001_ha, ccb);
7832b01d816SSuresh Thiagarajan 	smp_mb(); /*in order to force CPU ordering*/
7842b01d816SSuresh Thiagarajan 	task->task_done(task);
7852b01d816SSuresh Thiagarajan }
7862037a340SJohn Garry void pm8001_setds_completion(struct domain_device *dev);
787693e66a0SJohn Garry void pm8001_tmf_aborted(struct sas_task *task);
7882b01d816SSuresh Thiagarajan 
789dbf9bfe6Sjack wang #endif
790dbf9bfe6Sjack wang 
791