xref: /freebsd/sys/dev/ow/own.h (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1 /*-
2  * Copyright (c) 2015 M. Warner Losh <imp@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice unmodified, this list of conditions, and the following
9  *    disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef DEV_OW_OWN_H
29 #define DEV_OW_OWN_H 1
30 
31 #include "own_if.h"
32 
33 
34 #define	READ_ROM	0x33
35 #define	MATCH_ROM	0x55
36 #define	SKIP_ROM	0xcc
37 #define	ALARM_SEARCH	0xec
38 #define	SEARCH_ROM	0xf0
39 
40 static inline int
41 own_send_command(device_t pdev, struct ow_cmd *cmd)
42 {
43 	device_t ndev = device_get_parent(pdev);
44 
45 	return OWN_SEND_COMMAND(ndev, pdev, cmd);
46 }
47 
48 /*
49  * How args for own_acquire_bus
50  */
51 #define	OWN_WAIT	1
52 #define	OWN_DONTWAIT	2
53 
54 static inline int
55 own_acquire_bus(device_t pdev, int how)
56 {
57 	device_t ndev = device_get_parent(pdev);
58 
59 	return OWN_ACQUIRE_BUS(ndev, pdev, how);
60 }
61 
62 static inline void
63 own_release_bus(device_t pdev)
64 {
65 	device_t ndev = device_get_parent(pdev);
66 
67 	OWN_RELEASE_BUS(ndev, pdev);
68 }
69 
70 static inline uint8_t
71 own_crc(device_t pdev, uint8_t *buffer, size_t len)
72 {
73 	device_t ndev = device_get_parent(pdev);
74 
75 	return OWN_CRC(ndev, pdev, buffer, len);
76 }
77 
78 static inline void
79 own_self_command(device_t pdev, struct ow_cmd *cmd, uint8_t xpt_cmd)
80 {
81 	uint8_t *mep;
82 
83 	memset(cmd, 0, sizeof(*cmd));
84 	mep = ow_get_romid(pdev);
85 	cmd->rom_cmd[0] = MATCH_ROM;
86 	memcpy(&cmd->rom_cmd[1], mep, sizeof(romid_t));
87 	cmd->rom_len = 1 + sizeof(romid_t);
88 	cmd->xpt_cmd[0] = xpt_cmd;
89 	cmd->xpt_len = 1;
90 }
91 
92 static inline int
93 own_command_wait(device_t pdev, struct ow_cmd *cmd)
94 {
95 	int rv;
96 
97 	rv = own_acquire_bus(pdev, OWN_WAIT);
98 	if (rv != 0)
99 		return rv;
100 	rv = own_send_command(pdev, cmd);
101 	own_release_bus(pdev);
102 	return rv;
103 }
104 
105 #endif /* DEV_OW_OWLL_H */
106