xref: /freebsd/sys/dev/ips/ips.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
12aedd662SScott Long /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
42aedd662SScott Long  * Copyright (c) 2002 Adaptec Inc.
52aedd662SScott Long  * All rights reserved.
62aedd662SScott Long  *
72aedd662SScott Long  * Written by: David Jeffery
82aedd662SScott Long  *
92aedd662SScott Long  * Redistribution and use in source and binary forms, with or without
102aedd662SScott Long  * modification, are permitted provided that the following conditions
112aedd662SScott Long  * are met:
122aedd662SScott Long  * 1. Redistributions of source code must retain the above copyright
132aedd662SScott Long  *    notice, this list of conditions and the following disclaimer.
142aedd662SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
152aedd662SScott Long  *    notice, this list of conditions and the following disclaimer in the
162aedd662SScott Long  *    documentation and/or other materials provided with the distribution.
172aedd662SScott Long  *
182aedd662SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
192aedd662SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202aedd662SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212aedd662SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
222aedd662SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232aedd662SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242aedd662SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252aedd662SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262aedd662SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272aedd662SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282aedd662SScott Long  * SUCH DAMAGE.
292aedd662SScott Long  */
30f94dfeb4SScott Long #ifndef _IPS_H
31f94dfeb4SScott Long #define _IPS_H
322aedd662SScott Long 
33f94dfeb4SScott Long #ifdef _KERNEL
342aedd662SScott Long 
352aedd662SScott Long #include <sys/param.h>
362aedd662SScott Long #include <sys/systm.h>
372aedd662SScott Long #include <sys/kernel.h>
38fe12f24bSPoul-Henning Kamp #include <sys/module.h>
392aedd662SScott Long #include <sys/bus.h>
402aedd662SScott Long #include <sys/conf.h>
412aedd662SScott Long #include <sys/types.h>
422aedd662SScott Long #include <sys/queue.h>
432aedd662SScott Long #include <sys/bio.h>
442aedd662SScott Long #include <sys/malloc.h>
452aedd662SScott Long #include <sys/mutex.h>
46b234a120SScott Long #include <sys/sema.h>
477633e7f1SMartin Blapp #include <sys/time.h>
482aedd662SScott Long 
492aedd662SScott Long #include <machine/bus.h>
502aedd662SScott Long #include <sys/rman.h>
512aedd662SScott Long #include <machine/resource.h>
522aedd662SScott Long 
53dd83a01eSScott Long MALLOC_DECLARE(M_IPSBUF);
54dd83a01eSScott Long 
552aedd662SScott Long /*
562aedd662SScott Long  *  IPS MACROS
572aedd662SScott Long  */
582aedd662SScott Long 
59352176c8SJohn Baldwin #define ips_read_1(sc,offset)		bus_read_1(sc->iores, offset)
60352176c8SJohn Baldwin #define ips_read_2(sc,offset) 		bus_read_2(sc->iores, offset)
61352176c8SJohn Baldwin #define ips_read_4(sc,offset)		bus_read_4(sc->iores, offset)
622aedd662SScott Long 
63352176c8SJohn Baldwin #define ips_write_1(sc,offset,value)	bus_write_1(sc->iores, offset, value)
64352176c8SJohn Baldwin #define ips_write_2(sc,offset,value) 	bus_write_2(sc->iores, offset, value)
65352176c8SJohn Baldwin #define ips_write_4(sc,offset,value)	bus_write_4(sc->iores, offset, value)
662aedd662SScott Long 
672aedd662SScott Long /* this is ugly.  It zeros the end elements in an ips_command_t struct starting with the status element */
682aedd662SScott Long #define clear_ips_command(command)	bzero(&((command)->status), (unsigned long)(&(command)[1])-(unsigned long)&((command)->status))
692aedd662SScott Long 
702aedd662SScott Long #define ips_read_request(iobuf)		((iobuf)->bio_cmd == BIO_READ)
712aedd662SScott Long 
722eea7051SScott Long #define COMMAND_ERROR(command)		(((command)->status.fields.basic_status & IPS_GSC_STATUS_MASK) >= IPS_MIN_ERROR)
732eea7051SScott Long 
742eea7051SScott Long #define ips_set_error(command, error)	do {				\
752eea7051SScott Long 	(command)->status.fields.basic_status = IPS_DRV_ERROR;		\
762eea7051SScott Long 	(command)->status.fields.reserved = ((error) & 0x0f);		\
771a3c917fSWarner Losh } while (0)
782aedd662SScott Long 
792aedd662SScott Long #ifndef IPS_DEBUG
802aedd662SScott Long #define DEVICE_PRINTF(x...)
812aedd662SScott Long #define PRINTF(x...)
822aedd662SScott Long #else
832aedd662SScott Long #define DEVICE_PRINTF(level,x...)	if(IPS_DEBUG >= level)device_printf(x)
842aedd662SScott Long #define PRINTF(level,x...)		if(IPS_DEBUG >= level)printf(x)
852aedd662SScott Long #endif
862eea7051SScott Long 
872aedd662SScott Long struct ips_softc;
882aedd662SScott Long 
892aedd662SScott Long typedef struct {
902aedd662SScott Long 	u_int32_t 	status[IPS_MAX_CMD_NUM];
912aedd662SScott Long 	u_int32_t 	base_phys_addr;
922aedd662SScott Long 	int 		nextstatus;
932aedd662SScott Long 	bus_dma_tag_t	dmatag;
942aedd662SScott Long 	bus_dmamap_t	dmamap;
952aedd662SScott Long } ips_copper_queue_t;
962aedd662SScott Long 
972aedd662SScott Long /* used to keep track of current commands to the card */
982aedd662SScott Long typedef struct ips_command{
992aedd662SScott Long 	u_int8_t		command_number;
1002aedd662SScott Long 	u_int8_t 		id;
1012aedd662SScott Long 	u_int8_t		timeout;
1022aedd662SScott Long 	struct ips_softc *	sc;
10303a908f2SScott Long 	bus_dma_tag_t		data_dmatag;
10403a908f2SScott Long 	bus_dmamap_t		data_dmamap;
1052aedd662SScott Long 	bus_dmamap_t		command_dmamap;
1062aedd662SScott Long 	void *			command_buffer;
1072aedd662SScott Long 	u_int32_t		command_phys_addr;/*WARNING! must be changed if 64bit addressing ever used*/
1082aedd662SScott Long 	ips_cmd_status_t	status;
1092aedd662SScott Long 	SLIST_ENTRY(ips_command)	next;
1102aedd662SScott Long 	void *			data_buffer;
1112aedd662SScott Long 	void *			arg;
1122aedd662SScott Long 	void			(* callback)(struct ips_command *command);
1132aedd662SScott Long }ips_command_t;
1142aedd662SScott Long 
1152aedd662SScott Long typedef struct ips_softc{
1162aedd662SScott Long         struct resource *       iores;
1172aedd662SScott Long         struct resource *       irqres;
118faf13262SPaul Saab         struct intr_config_hook ips_ich;
119dea4622dSScott Long         int                     configured;
1202aedd662SScott Long         int                     state;
1212aedd662SScott Long         int                     iotype;
1222aedd662SScott Long         int                     rid;
1232aedd662SScott Long         int                     irqrid;
1242aedd662SScott Long         void *                  irqcookie;
1252aedd662SScott Long 	bus_dma_tag_t	        adapter_dmatag;
1262aedd662SScott Long 	bus_dma_tag_t		command_dmatag;
1272aedd662SScott Long 	bus_dma_tag_t		sg_dmatag;
1282aedd662SScott Long         device_t                dev;
12989c9c53dSPoul-Henning Kamp         struct cdev *device_file;
130352176c8SJohn Baldwin 	struct callout		timer;
1317633e7f1SMartin Blapp 	u_int16_t		adapter_type;
1322aedd662SScott Long 	ips_adapter_info_t	adapter_info;
1332aedd662SScott Long 	device_t		diskdev[IPS_MAX_NUM_DRIVES];
1342aedd662SScott Long 	ips_drive_t		drives[IPS_MAX_NUM_DRIVES];
1352aedd662SScott Long 	u_int8_t		drivecount;
1367633e7f1SMartin Blapp 	u_int16_t		ffdc_resetcount;
1377633e7f1SMartin Blapp 	struct timeval		ffdc_resettime;
1382aedd662SScott Long 	u_int8_t		next_drive;
1392aedd662SScott Long 	u_int8_t		max_cmds;
1402aedd662SScott Long 	volatile u_int8_t	used_commands;
14103a908f2SScott Long 	ips_command_t		*commandarray;
14203a908f2SScott Long 	ips_command_t		*staticcmd;
1432aedd662SScott Long 	SLIST_HEAD(command_list, ips_command) free_cmd_list;
1442aedd662SScott Long 	int			(* ips_adapter_reinit)(struct ips_softc *sc,
1452aedd662SScott Long 						       int force);
1462aedd662SScott Long         void                    (* ips_adapter_intr)(void *sc);
1472aedd662SScott Long 	void			(* ips_issue_cmd)(ips_command_t *command);
1487765040eSScott Long 	void			(* ips_poll_cmd)(ips_command_t *command);
1492aedd662SScott Long 	ips_copper_queue_t *	copper_queue;
150b234a120SScott Long 	struct mtx		queue_mtx;
151b234a120SScott Long 	struct bio_queue_head	queue;
15203a908f2SScott Long 	struct sema		cmd_sema;
153b234a120SScott Long 
1542aedd662SScott Long }ips_softc_t;
1552aedd662SScott Long 
1562aedd662SScott Long /* function defines from ips_ioctl.c */
1572aedd662SScott Long extern int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_cmd, caddr_t addr,
1582aedd662SScott Long 				int32_t flags);
1592aedd662SScott Long /* function defines from ips_disk.c */
1602aedd662SScott Long extern void ipsd_finish(struct bio *iobuf);
1612aedd662SScott Long 
1622aedd662SScott Long /* function defines from ips_commands.c */
1632aedd662SScott Long extern int ips_flush_cache(ips_softc_t *sc);
164b234a120SScott Long extern void ips_start_io_request(ips_softc_t *sc);
1652aedd662SScott Long extern int ips_get_drive_info(ips_softc_t *sc);
1662aedd662SScott Long extern int ips_get_adapter_info(ips_softc_t *sc);
1677633e7f1SMartin Blapp extern int ips_ffdc_reset(ips_softc_t *sc);
1682aedd662SScott Long extern int ips_update_nvram(ips_softc_t *sc);
1692aedd662SScott Long extern int ips_clear_adapter(ips_softc_t *sc);
1702aedd662SScott Long 
1712aedd662SScott Long /* function defines from ips.c */
17203a908f2SScott Long extern int ips_get_free_cmd(ips_softc_t *sc, ips_command_t **command, unsigned long flags);
1732aedd662SScott Long extern void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command);
1742aedd662SScott Long extern int ips_adapter_init(ips_softc_t *sc);
1752aedd662SScott Long extern int ips_morpheus_reinit(ips_softc_t *sc, int force);
1762aedd662SScott Long extern int ips_adapter_free(ips_softc_t *sc);
1772aedd662SScott Long extern void ips_morpheus_intr(void *sc);
1782aedd662SScott Long extern void ips_issue_morpheus_cmd(ips_command_t *command);
1797765040eSScott Long extern void ips_morpheus_poll(ips_command_t *command);
1802aedd662SScott Long extern int ips_copperhead_reinit(ips_softc_t *sc, int force);
1812aedd662SScott Long extern void ips_copperhead_intr(void *sc);
1822aedd662SScott Long extern void ips_issue_copperhead_cmd(ips_command_t *command);
1837765040eSScott Long extern void ips_copperhead_poll(ips_command_t *command);
1842aedd662SScott Long 
185f94dfeb4SScott Long #endif
186f94dfeb4SScott Long #endif
187