Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * PS3 Storage Library
4 *
5 * Copyright (C) 2007 Sony Computer Entertainment Inc.
6 * Copyright 2007 Sony Corp.
7 */
8
9#include <linux/dma-mapping.h>
10#include <linux/module.h>
11
12#include <asm/lv1call.h>
13#include <asm/ps3stor.h>
14
15/*
16 * A workaround for flash memory I/O errors when the internal hard disk
17 * has not been formatted for OtherOS use. Delay disk close until flash
18 * memory is closed.
19 */
20
21static struct ps3_flash_workaround {
22 int flash_open;
23 int disk_open;
24 struct ps3_system_bus_device *disk_sbd;
25} ps3_flash_workaround;
26
27static int ps3stor_open_hv_device(struct ps3_system_bus_device *sbd)
28{
29 int error = ps3_open_hv_device(sbd);
30
31 if (error)
32 return error;
33
34 if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH)
35 ps3_flash_workaround.flash_open = 1;
36
37 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
38 ps3_flash_workaround.disk_open = 1;
39
40 return 0;
41}
42
43static int ps3stor_close_hv_device(struct ps3_system_bus_device *sbd)
44{
45 int error;
46
47 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK
48 && ps3_flash_workaround.disk_open
49 && ps3_flash_workaround.flash_open) {
50 ps3_flash_workaround.disk_sbd = sbd;
51 return 0;
52 }
53
54 error = ps3_close_hv_device(sbd);
55
56 if (error)
57 return error;
58
59 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
60 ps3_flash_workaround.disk_open = 0;
61
62 if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH) {
63 ps3_flash_workaround.flash_open = 0;
64
65 if (ps3_flash_workaround.disk_sbd) {
66 ps3_close_hv_device(ps3_flash_workaround.disk_sbd);
67 ps3_flash_workaround.disk_open = 0;
68 ps3_flash_workaround.disk_sbd = NULL;
69 }
70 }
71
72 return 0;
73}
74
75static int ps3stor_probe_access(struct ps3_storage_device *dev)
76{
77 int res, error;
78 unsigned int i;
79 unsigned long n;
80
81 if (dev->sbd.match_id == PS3_MATCH_ID_STOR_ROM) {
82 /* special case: CD-ROM is assumed always accessible */
83 dev->accessible_regions = 1;
84 return 0;
85 }
86
87 error = -EPERM;
88 for (i = 0; i < dev->num_regions; i++) {
89 dev_dbg(&dev->sbd.core,
90 "%s:%u: checking accessibility of region %u\n",
91 __func__, __LINE__, i);
92
93 dev->region_idx = i;
94 res = ps3stor_read_write_sectors(dev, dev->bounce_lpar, 0, 1,
95 0);
96 if (res) {
97 dev_dbg(&dev->sbd.core, "%s:%u: read failed, "
98 "region %u is not accessible\n", __func__,
99 __LINE__, i);
100 continue;
101 }
102
103 dev_dbg(&dev->sbd.core, "%s:%u: region %u is accessible\n",
104 __func__, __LINE__, i);
105 set_bit(i, &dev->accessible_regions);
106
107 /* We can access at least one region */
108 error = 0;
109 }
110 if (error)
111 return error;
112
113 n = hweight_long(dev->accessible_regions);
114 if (n > 1)
115 dev_info(&dev->sbd.core,
116 "%s:%u: %lu accessible regions found. Only the first "
117 "one will be used\n",
118 __func__, __LINE__, n);
119 dev->region_idx = __ffs(dev->accessible_regions);
120 dev_info(&dev->sbd.core,
121 "First accessible region has index %u start %llu size %llu\n",
122 dev->region_idx, dev->regions[dev->region_idx].start,
123 dev->regions[dev->region_idx].size);
124
125 return 0;
126}
127
128
129/**
130 * ps3stor_setup - Setup a storage device before use
131 * @dev: Pointer to a struct ps3_storage_device
132 * @handler: Pointer to an interrupt handler
133 *
134 * Returns 0 for success, or an error code
135 */
136int ps3stor_setup(struct ps3_storage_device *dev, irq_handler_t handler)
137{
138 int error, res, alignment;
139 enum ps3_dma_page_size page_size;
140
141 error = ps3stor_open_hv_device(&dev->sbd);
142 if (error) {
143 dev_err(&dev->sbd.core,
144 "%s:%u: ps3_open_hv_device failed %d\n", __func__,
145 __LINE__, error);
146 goto fail;
147 }
148
149 error = ps3_sb_event_receive_port_setup(&dev->sbd, PS3_BINDING_CPU_ANY,
150 &dev->irq);
151 if (error) {
152 dev_err(&dev->sbd.core,
153 "%s:%u: ps3_sb_event_receive_port_setup failed %d\n",
154 __func__, __LINE__, error);
155 goto fail_close_device;
156 }
157
158 error = request_irq(dev->irq, handler, 0,
159 dev->sbd.core.driver->name, dev);
160 if (error) {
161 dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n",
162 __func__, __LINE__, error);
163 goto fail_sb_event_receive_port_destroy;
164 }
165
166 alignment = min(__ffs(dev->bounce_size),
167 __ffs((unsigned long)dev->bounce_buf));
168 if (alignment < 12) {
169 dev_err(&dev->sbd.core,
170 "%s:%u: bounce buffer not aligned (%lx at 0x%p)\n",
171 __func__, __LINE__, dev->bounce_size, dev->bounce_buf);
172 error = -EINVAL;
173 goto fail_free_irq;
174 } else if (alignment < 16)
175 page_size = PS3_DMA_4K;
176 else
177 page_size = PS3_DMA_64K;
178 dev->sbd.d_region = &dev->dma_region;
179 ps3_dma_region_init(&dev->sbd, &dev->dma_region, page_size,
180 PS3_DMA_OTHER, dev->bounce_buf, dev->bounce_size);
181 res = ps3_dma_region_create(&dev->dma_region);
182 if (res) {
183 dev_err(&dev->sbd.core, "%s:%u: cannot create DMA region\n",
184 __func__, __LINE__);
185 error = -ENOMEM;
186 goto fail_free_irq;
187 }
188
189 dev->bounce_lpar = ps3_mm_phys_to_lpar(__pa(dev->bounce_buf));
190 dev->bounce_dma = dma_map_single(&dev->sbd.core, dev->bounce_buf,
191 dev->bounce_size, DMA_BIDIRECTIONAL);
192 if (dma_mapping_error(&dev->sbd.core, dev->bounce_dma)) {
193 dev_err(&dev->sbd.core, "%s:%u: map DMA region failed\n",
194 __func__, __LINE__);
195 error = -ENODEV;
196 goto fail_free_dma;
197 }
198
199 error = ps3stor_probe_access(dev);
200 if (error) {
201 dev_err(&dev->sbd.core, "%s:%u: No accessible regions found\n",
202 __func__, __LINE__);
203 goto fail_unmap_dma;
204 }
205 return 0;
206
207fail_unmap_dma:
208 dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
209 DMA_BIDIRECTIONAL);
210fail_free_dma:
211 ps3_dma_region_free(&dev->dma_region);
212fail_free_irq:
213 free_irq(dev->irq, dev);
214fail_sb_event_receive_port_destroy:
215 ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
216fail_close_device:
217 ps3stor_close_hv_device(&dev->sbd);
218fail:
219 return error;
220}
221EXPORT_SYMBOL_GPL(ps3stor_setup);
222
223
224/**
225 * ps3stor_teardown - Tear down a storage device after use
226 * @dev: Pointer to a struct ps3_storage_device
227 */
228void ps3stor_teardown(struct ps3_storage_device *dev)
229{
230 int error;
231
232 dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
233 DMA_BIDIRECTIONAL);
234 ps3_dma_region_free(&dev->dma_region);
235
236 free_irq(dev->irq, dev);
237
238 error = ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
239 if (error)
240 dev_err(&dev->sbd.core,
241 "%s:%u: destroy event receive port failed %d\n",
242 __func__, __LINE__, error);
243
244 error = ps3stor_close_hv_device(&dev->sbd);
245 if (error)
246 dev_err(&dev->sbd.core,
247 "%s:%u: ps3_close_hv_device failed %d\n", __func__,
248 __LINE__, error);
249}
250EXPORT_SYMBOL_GPL(ps3stor_teardown);
251
252
253/**
254 * ps3stor_read_write_sectors - read/write from/to a storage device
255 * @dev: Pointer to a struct ps3_storage_device
256 * @lpar: HV logical partition address
257 * @start_sector: First sector to read/write
258 * @sectors: Number of sectors to read/write
259 * @write: Flag indicating write (non-zero) or read (zero)
260 *
261 * Returns 0 for success, -1 in case of failure to submit the command, or
262 * an LV1 status value in case of other errors
263 */
264u64 ps3stor_read_write_sectors(struct ps3_storage_device *dev, u64 lpar,
265 u64 start_sector, u64 sectors, int write)
266{
267 unsigned int region_id = dev->regions[dev->region_idx].id;
268 const char *op = write ? "write" : "read";
269 int res;
270
271 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
272 __func__, __LINE__, op, sectors, start_sector);
273
274 init_completion(&dev->done);
275 res = write ? lv1_storage_write(dev->sbd.dev_id, region_id,
276 start_sector, sectors, 0, lpar,
277 &dev->tag)
278 : lv1_storage_read(dev->sbd.dev_id, region_id,
279 start_sector, sectors, 0, lpar,
280 &dev->tag);
281 if (res) {
282 dev_dbg(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
283 __LINE__, op, res);
284 return -1;
285 }
286
287 wait_for_completion(&dev->done);
288 if (dev->lv1_status) {
289 dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
290 __LINE__, op, dev->lv1_status);
291 return dev->lv1_status;
292 }
293
294 dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__, __LINE__,
295 op);
296
297 return 0;
298}
299EXPORT_SYMBOL_GPL(ps3stor_read_write_sectors);
300
301
302/**
303 * ps3stor_send_command - send a device command to a storage device
304 * @dev: Pointer to a struct ps3_storage_device
305 * @cmd: Command number
306 * @arg1: First command argument
307 * @arg2: Second command argument
308 * @arg3: Third command argument
309 * @arg4: Fourth command argument
310 *
311 * Returns 0 for success, -1 in case of failure to submit the command, or
312 * an LV1 status value in case of other errors
313 */
314u64 ps3stor_send_command(struct ps3_storage_device *dev, u64 cmd, u64 arg1,
315 u64 arg2, u64 arg3, u64 arg4)
316{
317 int res;
318
319 dev_dbg(&dev->sbd.core, "%s:%u: send device command 0x%llx\n", __func__,
320 __LINE__, cmd);
321
322 init_completion(&dev->done);
323
324 res = lv1_storage_send_device_command(dev->sbd.dev_id, cmd, arg1,
325 arg2, arg3, arg4, &dev->tag);
326 if (res) {
327 dev_err(&dev->sbd.core,
328 "%s:%u: send_device_command 0x%llx failed %d\n",
329 __func__, __LINE__, cmd, res);
330 return -1;
331 }
332
333 wait_for_completion(&dev->done);
334 if (dev->lv1_status) {
335 dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx failed 0x%llx\n",
336 __func__, __LINE__, cmd, dev->lv1_status);
337 return dev->lv1_status;
338 }
339
340 dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx completed\n", __func__,
341 __LINE__, cmd);
342
343 return 0;
344}
345EXPORT_SYMBOL_GPL(ps3stor_send_command);
346
347
348MODULE_LICENSE("GPL");
349MODULE_DESCRIPTION("PS3 Storage Bus Library");
350MODULE_AUTHOR("Sony Corporation");
1/*
2 * PS3 Storage Library
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/dma-mapping.h>
22#include <linux/module.h>
23
24#include <asm/lv1call.h>
25#include <asm/ps3stor.h>
26
27/*
28 * A workaround for flash memory I/O errors when the internal hard disk
29 * has not been formatted for OtherOS use. Delay disk close until flash
30 * memory is closed.
31 */
32
33static struct ps3_flash_workaround {
34 int flash_open;
35 int disk_open;
36 struct ps3_system_bus_device *disk_sbd;
37} ps3_flash_workaround;
38
39static int ps3stor_open_hv_device(struct ps3_system_bus_device *sbd)
40{
41 int error = ps3_open_hv_device(sbd);
42
43 if (error)
44 return error;
45
46 if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH)
47 ps3_flash_workaround.flash_open = 1;
48
49 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
50 ps3_flash_workaround.disk_open = 1;
51
52 return 0;
53}
54
55static int ps3stor_close_hv_device(struct ps3_system_bus_device *sbd)
56{
57 int error;
58
59 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK
60 && ps3_flash_workaround.disk_open
61 && ps3_flash_workaround.flash_open) {
62 ps3_flash_workaround.disk_sbd = sbd;
63 return 0;
64 }
65
66 error = ps3_close_hv_device(sbd);
67
68 if (error)
69 return error;
70
71 if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
72 ps3_flash_workaround.disk_open = 0;
73
74 if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH) {
75 ps3_flash_workaround.flash_open = 0;
76
77 if (ps3_flash_workaround.disk_sbd) {
78 ps3_close_hv_device(ps3_flash_workaround.disk_sbd);
79 ps3_flash_workaround.disk_open = 0;
80 ps3_flash_workaround.disk_sbd = NULL;
81 }
82 }
83
84 return 0;
85}
86
87static int ps3stor_probe_access(struct ps3_storage_device *dev)
88{
89 int res, error;
90 unsigned int i;
91 unsigned long n;
92
93 if (dev->sbd.match_id == PS3_MATCH_ID_STOR_ROM) {
94 /* special case: CD-ROM is assumed always accessible */
95 dev->accessible_regions = 1;
96 return 0;
97 }
98
99 error = -EPERM;
100 for (i = 0; i < dev->num_regions; i++) {
101 dev_dbg(&dev->sbd.core,
102 "%s:%u: checking accessibility of region %u\n",
103 __func__, __LINE__, i);
104
105 dev->region_idx = i;
106 res = ps3stor_read_write_sectors(dev, dev->bounce_lpar, 0, 1,
107 0);
108 if (res) {
109 dev_dbg(&dev->sbd.core, "%s:%u: read failed, "
110 "region %u is not accessible\n", __func__,
111 __LINE__, i);
112 continue;
113 }
114
115 dev_dbg(&dev->sbd.core, "%s:%u: region %u is accessible\n",
116 __func__, __LINE__, i);
117 set_bit(i, &dev->accessible_regions);
118
119 /* We can access at least one region */
120 error = 0;
121 }
122 if (error)
123 return error;
124
125 n = hweight_long(dev->accessible_regions);
126 if (n > 1)
127 dev_info(&dev->sbd.core,
128 "%s:%u: %lu accessible regions found. Only the first "
129 "one will be used\n",
130 __func__, __LINE__, n);
131 dev->region_idx = __ffs(dev->accessible_regions);
132 dev_info(&dev->sbd.core,
133 "First accessible region has index %u start %llu size %llu\n",
134 dev->region_idx, dev->regions[dev->region_idx].start,
135 dev->regions[dev->region_idx].size);
136
137 return 0;
138}
139
140
141/**
142 * ps3stor_setup - Setup a storage device before use
143 * @dev: Pointer to a struct ps3_storage_device
144 * @handler: Pointer to an interrupt handler
145 *
146 * Returns 0 for success, or an error code
147 */
148int ps3stor_setup(struct ps3_storage_device *dev, irq_handler_t handler)
149{
150 int error, res, alignment;
151 enum ps3_dma_page_size page_size;
152
153 error = ps3stor_open_hv_device(&dev->sbd);
154 if (error) {
155 dev_err(&dev->sbd.core,
156 "%s:%u: ps3_open_hv_device failed %d\n", __func__,
157 __LINE__, error);
158 goto fail;
159 }
160
161 error = ps3_sb_event_receive_port_setup(&dev->sbd, PS3_BINDING_CPU_ANY,
162 &dev->irq);
163 if (error) {
164 dev_err(&dev->sbd.core,
165 "%s:%u: ps3_sb_event_receive_port_setup failed %d\n",
166 __func__, __LINE__, error);
167 goto fail_close_device;
168 }
169
170 error = request_irq(dev->irq, handler, 0,
171 dev->sbd.core.driver->name, dev);
172 if (error) {
173 dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n",
174 __func__, __LINE__, error);
175 goto fail_sb_event_receive_port_destroy;
176 }
177
178 alignment = min(__ffs(dev->bounce_size),
179 __ffs((unsigned long)dev->bounce_buf));
180 if (alignment < 12) {
181 dev_err(&dev->sbd.core,
182 "%s:%u: bounce buffer not aligned (%lx at 0x%p)\n",
183 __func__, __LINE__, dev->bounce_size, dev->bounce_buf);
184 error = -EINVAL;
185 goto fail_free_irq;
186 } else if (alignment < 16)
187 page_size = PS3_DMA_4K;
188 else
189 page_size = PS3_DMA_64K;
190 dev->sbd.d_region = &dev->dma_region;
191 ps3_dma_region_init(&dev->sbd, &dev->dma_region, page_size,
192 PS3_DMA_OTHER, dev->bounce_buf, dev->bounce_size);
193 res = ps3_dma_region_create(&dev->dma_region);
194 if (res) {
195 dev_err(&dev->sbd.core, "%s:%u: cannot create DMA region\n",
196 __func__, __LINE__);
197 error = -ENOMEM;
198 goto fail_free_irq;
199 }
200
201 dev->bounce_lpar = ps3_mm_phys_to_lpar(__pa(dev->bounce_buf));
202 dev->bounce_dma = dma_map_single(&dev->sbd.core, dev->bounce_buf,
203 dev->bounce_size, DMA_BIDIRECTIONAL);
204 if (!dev->bounce_dma) {
205 dev_err(&dev->sbd.core, "%s:%u: map DMA region failed\n",
206 __func__, __LINE__);
207 error = -ENODEV;
208 goto fail_free_dma;
209 }
210
211 error = ps3stor_probe_access(dev);
212 if (error) {
213 dev_err(&dev->sbd.core, "%s:%u: No accessible regions found\n",
214 __func__, __LINE__);
215 goto fail_unmap_dma;
216 }
217 return 0;
218
219fail_unmap_dma:
220 dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
221 DMA_BIDIRECTIONAL);
222fail_free_dma:
223 ps3_dma_region_free(&dev->dma_region);
224fail_free_irq:
225 free_irq(dev->irq, dev);
226fail_sb_event_receive_port_destroy:
227 ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
228fail_close_device:
229 ps3stor_close_hv_device(&dev->sbd);
230fail:
231 return error;
232}
233EXPORT_SYMBOL_GPL(ps3stor_setup);
234
235
236/**
237 * ps3stor_teardown - Tear down a storage device after use
238 * @dev: Pointer to a struct ps3_storage_device
239 */
240void ps3stor_teardown(struct ps3_storage_device *dev)
241{
242 int error;
243
244 dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
245 DMA_BIDIRECTIONAL);
246 ps3_dma_region_free(&dev->dma_region);
247
248 free_irq(dev->irq, dev);
249
250 error = ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
251 if (error)
252 dev_err(&dev->sbd.core,
253 "%s:%u: destroy event receive port failed %d\n",
254 __func__, __LINE__, error);
255
256 error = ps3stor_close_hv_device(&dev->sbd);
257 if (error)
258 dev_err(&dev->sbd.core,
259 "%s:%u: ps3_close_hv_device failed %d\n", __func__,
260 __LINE__, error);
261}
262EXPORT_SYMBOL_GPL(ps3stor_teardown);
263
264
265/**
266 * ps3stor_read_write_sectors - read/write from/to a storage device
267 * @dev: Pointer to a struct ps3_storage_device
268 * @lpar: HV logical partition address
269 * @start_sector: First sector to read/write
270 * @sectors: Number of sectors to read/write
271 * @write: Flag indicating write (non-zero) or read (zero)
272 *
273 * Returns 0 for success, -1 in case of failure to submit the command, or
274 * an LV1 status value in case of other errors
275 */
276u64 ps3stor_read_write_sectors(struct ps3_storage_device *dev, u64 lpar,
277 u64 start_sector, u64 sectors, int write)
278{
279 unsigned int region_id = dev->regions[dev->region_idx].id;
280 const char *op = write ? "write" : "read";
281 int res;
282
283 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
284 __func__, __LINE__, op, sectors, start_sector);
285
286 init_completion(&dev->done);
287 res = write ? lv1_storage_write(dev->sbd.dev_id, region_id,
288 start_sector, sectors, 0, lpar,
289 &dev->tag)
290 : lv1_storage_read(dev->sbd.dev_id, region_id,
291 start_sector, sectors, 0, lpar,
292 &dev->tag);
293 if (res) {
294 dev_dbg(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
295 __LINE__, op, res);
296 return -1;
297 }
298
299 wait_for_completion(&dev->done);
300 if (dev->lv1_status) {
301 dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
302 __LINE__, op, dev->lv1_status);
303 return dev->lv1_status;
304 }
305
306 dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__, __LINE__,
307 op);
308
309 return 0;
310}
311EXPORT_SYMBOL_GPL(ps3stor_read_write_sectors);
312
313
314/**
315 * ps3stor_send_command - send a device command to a storage device
316 * @dev: Pointer to a struct ps3_storage_device
317 * @cmd: Command number
318 * @arg1: First command argument
319 * @arg2: Second command argument
320 * @arg3: Third command argument
321 * @arg4: Fourth command argument
322 *
323 * Returns 0 for success, -1 in case of failure to submit the command, or
324 * an LV1 status value in case of other errors
325 */
326u64 ps3stor_send_command(struct ps3_storage_device *dev, u64 cmd, u64 arg1,
327 u64 arg2, u64 arg3, u64 arg4)
328{
329 int res;
330
331 dev_dbg(&dev->sbd.core, "%s:%u: send device command 0x%llx\n", __func__,
332 __LINE__, cmd);
333
334 init_completion(&dev->done);
335
336 res = lv1_storage_send_device_command(dev->sbd.dev_id, cmd, arg1,
337 arg2, arg3, arg4, &dev->tag);
338 if (res) {
339 dev_err(&dev->sbd.core,
340 "%s:%u: send_device_command 0x%llx failed %d\n",
341 __func__, __LINE__, cmd, res);
342 return -1;
343 }
344
345 wait_for_completion(&dev->done);
346 if (dev->lv1_status) {
347 dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx failed 0x%llx\n",
348 __func__, __LINE__, cmd, dev->lv1_status);
349 return dev->lv1_status;
350 }
351
352 dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx completed\n", __func__,
353 __LINE__, cmd);
354
355 return 0;
356}
357EXPORT_SYMBOL_GPL(ps3stor_send_command);
358
359
360MODULE_LICENSE("GPL");
361MODULE_DESCRIPTION("PS3 Storage Bus Library");
362MODULE_AUTHOR("Sony Corporation");