.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ff-transaction.c - a part of driver for RME Fireface series |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2015-2017 Takashi Sakamoto |
---|
5 | | - * |
---|
6 | | - * Licensed under the terms of the GNU General Public License, version 2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #include "ff.h" |
---|
.. | .. |
---|
51 | 50 | finish_transmit_midi_msg(ff, 1, rcode); |
---|
52 | 51 | } |
---|
53 | 52 | |
---|
54 | | -static inline void fill_midi_buf(struct snd_ff *ff, unsigned int port, |
---|
55 | | - unsigned int index, u8 byte) |
---|
56 | | -{ |
---|
57 | | - ff->msg_buf[port][index] = cpu_to_le32(byte); |
---|
58 | | -} |
---|
59 | | - |
---|
60 | 53 | static void transmit_midi_msg(struct snd_ff *ff, unsigned int port) |
---|
61 | 54 | { |
---|
62 | 55 | struct snd_rawmidi_substream *substream = |
---|
63 | 56 | READ_ONCE(ff->rx_midi_substreams[port]); |
---|
64 | | - u8 *buf = (u8 *)ff->msg_buf[port]; |
---|
65 | | - int i, len; |
---|
| 57 | + int quad_count; |
---|
66 | 58 | |
---|
67 | 59 | struct fw_device *fw_dev = fw_parent_device(ff->unit); |
---|
68 | 60 | unsigned long long addr; |
---|
69 | 61 | int generation; |
---|
70 | 62 | fw_transaction_callback_t callback; |
---|
| 63 | + int tcode; |
---|
71 | 64 | |
---|
72 | 65 | if (substream == NULL || snd_rawmidi_transmit_empty(substream)) |
---|
73 | 66 | return; |
---|
.. | .. |
---|
81 | 74 | return; |
---|
82 | 75 | } |
---|
83 | 76 | |
---|
84 | | - len = snd_rawmidi_transmit_peek(substream, buf, |
---|
85 | | - SND_FF_MAXIMIM_MIDI_QUADS); |
---|
86 | | - if (len <= 0) |
---|
| 77 | + quad_count = ff->spec->protocol->fill_midi_msg(ff, substream, port); |
---|
| 78 | + if (quad_count <= 0) |
---|
87 | 79 | return; |
---|
88 | 80 | |
---|
89 | | - for (i = len - 1; i >= 0; i--) |
---|
90 | | - fill_midi_buf(ff, port, i, buf[i]); |
---|
91 | | - |
---|
92 | 81 | if (port == 0) { |
---|
93 | | - addr = ff->spec->protocol->midi_rx_port_0_reg; |
---|
| 82 | + addr = ff->spec->midi_rx_addrs[0]; |
---|
94 | 83 | callback = finish_transmit_midi0_msg; |
---|
95 | 84 | } else { |
---|
96 | | - addr = ff->spec->protocol->midi_rx_port_1_reg; |
---|
| 85 | + addr = ff->spec->midi_rx_addrs[1]; |
---|
97 | 86 | callback = finish_transmit_midi1_msg; |
---|
98 | 87 | } |
---|
99 | 88 | |
---|
100 | 89 | /* Set interval to next transaction. */ |
---|
101 | 90 | ff->next_ktime[port] = ktime_add_ns(ktime_get(), |
---|
102 | | - len * 8 * (NSEC_PER_SEC / 31250)); |
---|
103 | | - ff->rx_bytes[port] = len; |
---|
| 91 | + ff->rx_bytes[port] * 8 * (NSEC_PER_SEC / 31250)); |
---|
| 92 | + |
---|
| 93 | + if (quad_count == 1) |
---|
| 94 | + tcode = TCODE_WRITE_QUADLET_REQUEST; |
---|
| 95 | + else |
---|
| 96 | + tcode = TCODE_WRITE_BLOCK_REQUEST; |
---|
104 | 97 | |
---|
105 | 98 | /* |
---|
106 | 99 | * In Linux FireWire core, when generation is updated with memory |
---|
.. | .. |
---|
112 | 105 | */ |
---|
113 | 106 | generation = fw_dev->generation; |
---|
114 | 107 | smp_rmb(); |
---|
115 | | - fw_send_request(fw_dev->card, &ff->transactions[port], |
---|
116 | | - TCODE_WRITE_BLOCK_REQUEST, |
---|
| 108 | + fw_send_request(fw_dev->card, &ff->transactions[port], tcode, |
---|
117 | 109 | fw_dev->node_id, generation, fw_dev->max_speed, |
---|
118 | | - addr, &ff->msg_buf[port], len * 4, |
---|
| 110 | + addr, &ff->msg_buf[port], quad_count * 4, |
---|
119 | 111 | callback, &ff->transactions[port]); |
---|
120 | 112 | } |
---|
121 | 113 | |
---|
.. | .. |
---|
140 | 132 | { |
---|
141 | 133 | struct snd_ff *ff = callback_data; |
---|
142 | 134 | __le32 *buf = data; |
---|
143 | | - u32 quad; |
---|
144 | | - u8 byte; |
---|
145 | | - unsigned int index; |
---|
146 | | - struct snd_rawmidi_substream *substream; |
---|
147 | | - int i; |
---|
148 | 135 | |
---|
149 | 136 | fw_send_response(card, request, RCODE_COMPLETE); |
---|
150 | 137 | |
---|
151 | | - for (i = 0; i < length / 4; i++) { |
---|
152 | | - quad = le32_to_cpu(buf[i]); |
---|
153 | | - |
---|
154 | | - /* Message in first port. */ |
---|
155 | | - /* |
---|
156 | | - * This value may represent the index of this unit when the same |
---|
157 | | - * units are on the same IEEE 1394 bus. This driver doesn't use |
---|
158 | | - * it. |
---|
159 | | - */ |
---|
160 | | - index = (quad >> 8) & 0xff; |
---|
161 | | - if (index > 0) { |
---|
162 | | - substream = READ_ONCE(ff->tx_midi_substreams[0]); |
---|
163 | | - if (substream != NULL) { |
---|
164 | | - byte = quad & 0xff; |
---|
165 | | - snd_rawmidi_receive(substream, &byte, 1); |
---|
166 | | - } |
---|
167 | | - } |
---|
168 | | - |
---|
169 | | - /* Message in second port. */ |
---|
170 | | - index = (quad >> 24) & 0xff; |
---|
171 | | - if (index > 0) { |
---|
172 | | - substream = READ_ONCE(ff->tx_midi_substreams[1]); |
---|
173 | | - if (substream != NULL) { |
---|
174 | | - byte = (quad >> 16) & 0xff; |
---|
175 | | - snd_rawmidi_receive(substream, &byte, 1); |
---|
176 | | - } |
---|
177 | | - } |
---|
178 | | - } |
---|
| 138 | + offset -= ff->async_handler.offset; |
---|
| 139 | + ff->spec->protocol->handle_midi_msg(ff, (unsigned int)offset, buf, |
---|
| 140 | + length); |
---|
179 | 141 | } |
---|
180 | 142 | |
---|
181 | 143 | static int allocate_own_address(struct snd_ff *ff, int i) |
---|
.. | .. |
---|
183 | 145 | struct fw_address_region midi_msg_region; |
---|
184 | 146 | int err; |
---|
185 | 147 | |
---|
186 | | - ff->async_handler.length = SND_FF_MAXIMIM_MIDI_QUADS * 4; |
---|
| 148 | + ff->async_handler.length = ff->spec->midi_addr_range; |
---|
187 | 149 | ff->async_handler.address_callback = handle_midi_msg; |
---|
188 | 150 | ff->async_handler.callback_data = ff; |
---|
189 | 151 | |
---|
.. | .. |
---|
202 | 164 | return err; |
---|
203 | 165 | } |
---|
204 | 166 | |
---|
205 | | -/* |
---|
206 | | - * The configuration to start asynchronous transactions for MIDI messages is in |
---|
207 | | - * 0x'0000'8010'051c. This register includes the other options, thus this driver |
---|
208 | | - * doesn't touch it and leaves the decision to userspace. The userspace MUST add |
---|
209 | | - * 0x04000000 to write transactions to the register to receive any MIDI |
---|
210 | | - * messages. |
---|
211 | | - * |
---|
212 | | - * Here, I just describe MIDI-related offsets of the register, in little-endian |
---|
213 | | - * order. |
---|
214 | | - * |
---|
215 | | - * Controllers are allowed to register higher 4 bytes of address to receive |
---|
216 | | - * the transactions. The register is 0x'0000'8010'03f4. On the other hand, the |
---|
217 | | - * controllers are not allowed to register lower 4 bytes of the address. They |
---|
218 | | - * are forced to select from 4 options by writing corresponding bits to |
---|
219 | | - * 0x'0000'8010'051c. |
---|
220 | | - * |
---|
221 | | - * The 3rd-6th bits in MSB of this register are used to indicate lower 4 bytes |
---|
222 | | - * of address to which the device transferrs the transactions. |
---|
223 | | - * - 6th: 0x'....'....'0000'0180 |
---|
224 | | - * - 5th: 0x'....'....'0000'0100 |
---|
225 | | - * - 4th: 0x'....'....'0000'0080 |
---|
226 | | - * - 3rd: 0x'....'....'0000'0000 |
---|
227 | | - * |
---|
228 | | - * This driver configure 0x'....'....'0000'0000 for units to receive MIDI |
---|
229 | | - * messages. 3rd bit of the register should be configured, however this driver |
---|
230 | | - * deligates this task to user space applications due to a restriction that |
---|
231 | | - * this register is write-only and the other bits have own effects. |
---|
232 | | - * |
---|
233 | | - * The 1st and 2nd bits in LSB of this register are used to cancel transferring |
---|
234 | | - * asynchronous transactions. These two bits have the same effect. |
---|
235 | | - * - 1st/2nd: cancel transferring |
---|
236 | | - */ |
---|
| 167 | +// Controllers are allowed to register higher 4 bytes of destination address to |
---|
| 168 | +// receive asynchronous transactions for MIDI messages, while the way to |
---|
| 169 | +// register lower 4 bytes of address is different depending on protocols. For |
---|
| 170 | +// details, please refer to comments in protocol implementations. |
---|
| 171 | +// |
---|
| 172 | +// This driver expects userspace applications to configure registers for the |
---|
| 173 | +// lower address because in most cases such registers has the other settings. |
---|
237 | 174 | int snd_ff_transaction_reregister(struct snd_ff *ff) |
---|
238 | 175 | { |
---|
239 | 176 | struct fw_card *fw_card = fw_parent_device(ff->unit)->card; |
---|
.. | .. |
---|
247 | 184 | addr = (fw_card->node_id << 16) | (ff->async_handler.offset >> 32); |
---|
248 | 185 | reg = cpu_to_le32(addr); |
---|
249 | 186 | return snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, |
---|
250 | | - ff->spec->protocol->midi_high_addr_reg, |
---|
| 187 | + ff->spec->midi_high_addr, |
---|
251 | 188 | ®, sizeof(reg), 0); |
---|
252 | 189 | } |
---|
253 | 190 | |
---|
.. | .. |
---|
288 | 225 | /* Release higher 4 bytes of address. */ |
---|
289 | 226 | reg = cpu_to_le32(0x00000000); |
---|
290 | 227 | snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, |
---|
291 | | - ff->spec->protocol->midi_high_addr_reg, |
---|
| 228 | + ff->spec->midi_high_addr, |
---|
292 | 229 | ®, sizeof(reg), 0); |
---|
293 | 230 | |
---|
294 | 231 | fw_core_remove_address_handler(&ff->async_handler); |
---|