aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/fw-ohci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firewire/fw-ohci.c')
-rw-r--r--drivers/firewire/fw-ohci.c402
1 files changed, 328 insertions, 74 deletions
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
index ca6d51efd8bb..4f02c55f13e1 100644
--- a/drivers/firewire/fw-ohci.c
+++ b/drivers/firewire/fw-ohci.c
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
30#include <linux/pci.h> 31#include <linux/pci.h>
31#include <linux/spinlock.h> 32#include <linux/spinlock.h>
32 33
@@ -177,9 +178,10 @@ struct fw_ohci {
177 struct tasklet_struct bus_reset_tasklet; 178 struct tasklet_struct bus_reset_tasklet;
178 int node_id; 179 int node_id;
179 int generation; 180 int generation;
180 int request_generation; 181 int request_generation; /* for timestamping incoming requests */
181 u32 bus_seconds; 182 u32 bus_seconds;
182 bool old_uninorth; 183 bool old_uninorth;
184 bool bus_reset_packet_quirk;
183 185
184 /* 186 /*
185 * Spinlock for accessing fw_ohci data. Never call out of 187 * Spinlock for accessing fw_ohci data. Never call out of
@@ -237,6 +239,196 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card)
237 239
238static char ohci_driver_name[] = KBUILD_MODNAME; 240static char ohci_driver_name[] = KBUILD_MODNAME;
239 241
242#ifdef CONFIG_FIREWIRE_OHCI_DEBUG
243
244#define OHCI_PARAM_DEBUG_AT_AR 1
245#define OHCI_PARAM_DEBUG_SELFIDS 2
246#define OHCI_PARAM_DEBUG_IRQS 4
247#define OHCI_PARAM_DEBUG_BUSRESETS 8 /* only effective before chip init */
248
249static int param_debug;
250module_param_named(debug, param_debug, int, 0644);
251MODULE_PARM_DESC(debug, "Verbose logging (default = 0"
252 ", AT/AR events = " __stringify(OHCI_PARAM_DEBUG_AT_AR)
253 ", self-IDs = " __stringify(OHCI_PARAM_DEBUG_SELFIDS)
254 ", IRQs = " __stringify(OHCI_PARAM_DEBUG_IRQS)
255 ", busReset events = " __stringify(OHCI_PARAM_DEBUG_BUSRESETS)
256 ", or a combination, or all = -1)");
257
258static void log_irqs(u32 evt)
259{
260 if (likely(!(param_debug &
261 (OHCI_PARAM_DEBUG_IRQS | OHCI_PARAM_DEBUG_BUSRESETS))))
262 return;
263
264 if (!(param_debug & OHCI_PARAM_DEBUG_IRQS) &&
265 !(evt & OHCI1394_busReset))
266 return;
267
268 printk(KERN_DEBUG KBUILD_MODNAME ": IRQ "
269 "%08x%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
270 evt,
271 evt & OHCI1394_selfIDComplete ? " selfID" : "",
272 evt & OHCI1394_RQPkt ? " AR_req" : "",
273 evt & OHCI1394_RSPkt ? " AR_resp" : "",
274 evt & OHCI1394_reqTxComplete ? " AT_req" : "",
275 evt & OHCI1394_respTxComplete ? " AT_resp" : "",
276 evt & OHCI1394_isochRx ? " IR" : "",
277 evt & OHCI1394_isochTx ? " IT" : "",
278 evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "",
279 evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "",
280 evt & OHCI1394_cycle64Seconds ? " cycle64Seconds" : "",
281 evt & OHCI1394_regAccessFail ? " regAccessFail" : "",
282 evt & OHCI1394_busReset ? " busReset" : "",
283 evt & ~(OHCI1394_selfIDComplete | OHCI1394_RQPkt |
284 OHCI1394_RSPkt | OHCI1394_reqTxComplete |
285 OHCI1394_respTxComplete | OHCI1394_isochRx |
286 OHCI1394_isochTx | OHCI1394_postedWriteErr |
287 OHCI1394_cycleTooLong | OHCI1394_cycle64Seconds |
288 OHCI1394_regAccessFail | OHCI1394_busReset)
289 ? " ?" : "");
290}
291
292static const char *speed[] = {
293 [0] = "S100", [1] = "S200", [2] = "S400", [3] = "beta",
294};
295static const char *power[] = {
296 [0] = "+0W", [1] = "+15W", [2] = "+30W", [3] = "+45W",
297 [4] = "-3W", [5] = " ?W", [6] = "-3..-6W", [7] = "-3..-10W",
298};
299static const char port[] = { '.', '-', 'p', 'c', };
300
301static char _p(u32 *s, int shift)
302{
303 return port[*s >> shift & 3];
304}
305
306static void log_selfids(int node_id, int generation, int self_id_count, u32 *s)
307{
308 if (likely(!(param_debug & OHCI_PARAM_DEBUG_SELFIDS)))
309 return;
310
311 printk(KERN_DEBUG KBUILD_MODNAME ": %d selfIDs, generation %d, "
312 "local node ID %04x\n", self_id_count, generation, node_id);
313
314 for (; self_id_count--; ++s)
315 if ((*s & 1 << 23) == 0)
316 printk(KERN_DEBUG "selfID 0: %08x, phy %d [%c%c%c] "
317 "%s gc=%d %s %s%s%s\n",
318 *s, *s >> 24 & 63, _p(s, 6), _p(s, 4), _p(s, 2),
319 speed[*s >> 14 & 3], *s >> 16 & 63,
320 power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "",
321 *s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : "");
322 else
323 printk(KERN_DEBUG "selfID n: %08x, phy %d "
324 "[%c%c%c%c%c%c%c%c]\n",
325 *s, *s >> 24 & 63,
326 _p(s, 16), _p(s, 14), _p(s, 12), _p(s, 10),
327 _p(s, 8), _p(s, 6), _p(s, 4), _p(s, 2));
328}
329
330static const char *evts[] = {
331 [0x00] = "evt_no_status", [0x01] = "-reserved-",
332 [0x02] = "evt_long_packet", [0x03] = "evt_missing_ack",
333 [0x04] = "evt_underrun", [0x05] = "evt_overrun",
334 [0x06] = "evt_descriptor_read", [0x07] = "evt_data_read",
335 [0x08] = "evt_data_write", [0x09] = "evt_bus_reset",
336 [0x0a] = "evt_timeout", [0x0b] = "evt_tcode_err",
337 [0x0c] = "-reserved-", [0x0d] = "-reserved-",
338 [0x0e] = "evt_unknown", [0x0f] = "evt_flushed",
339 [0x10] = "-reserved-", [0x11] = "ack_complete",
340 [0x12] = "ack_pending ", [0x13] = "-reserved-",
341 [0x14] = "ack_busy_X", [0x15] = "ack_busy_A",
342 [0x16] = "ack_busy_B", [0x17] = "-reserved-",
343 [0x18] = "-reserved-", [0x19] = "-reserved-",
344 [0x1a] = "-reserved-", [0x1b] = "ack_tardy",
345 [0x1c] = "-reserved-", [0x1d] = "ack_data_error",
346 [0x1e] = "ack_type_error", [0x1f] = "-reserved-",
347 [0x20] = "pending/cancelled",
348};
349static const char *tcodes[] = {
350 [0x0] = "QW req", [0x1] = "BW req",
351 [0x2] = "W resp", [0x3] = "-reserved-",
352 [0x4] = "QR req", [0x5] = "BR req",
353 [0x6] = "QR resp", [0x7] = "BR resp",
354 [0x8] = "cycle start", [0x9] = "Lk req",
355 [0xa] = "async stream packet", [0xb] = "Lk resp",
356 [0xc] = "-reserved-", [0xd] = "-reserved-",
357 [0xe] = "link internal", [0xf] = "-reserved-",
358};
359static const char *phys[] = {
360 [0x0] = "phy config packet", [0x1] = "link-on packet",
361 [0x2] = "self-id packet", [0x3] = "-reserved-",
362};
363
364static void log_ar_at_event(char dir, int speed, u32 *header, int evt)
365{
366 int tcode = header[0] >> 4 & 0xf;
367 char specific[12];
368
369 if (likely(!(param_debug & OHCI_PARAM_DEBUG_AT_AR)))
370 return;
371
372 if (unlikely(evt >= ARRAY_SIZE(evts)))
373 evt = 0x1f;
374
375 if (evt == OHCI1394_evt_bus_reset) {
376 printk(KERN_DEBUG "A%c evt_bus_reset, generation %d\n",
377 dir, (header[2] >> 16) & 0xff);
378 return;
379 }
380
381 if (header[0] == ~header[1]) {
382 printk(KERN_DEBUG "A%c %s, %s, %08x\n",
383 dir, evts[evt], phys[header[0] >> 30 & 0x3],
384 header[0]);
385 return;
386 }
387
388 switch (tcode) {
389 case 0x0: case 0x6: case 0x8:
390 snprintf(specific, sizeof(specific), " = %08x",
391 be32_to_cpu((__force __be32)header[3]));
392 break;
393 case 0x1: case 0x5: case 0x7: case 0x9: case 0xb:
394 snprintf(specific, sizeof(specific), " %x,%x",
395 header[3] >> 16, header[3] & 0xffff);
396 break;
397 default:
398 specific[0] = '\0';
399 }
400
401 switch (tcode) {
402 case 0xe: case 0xa:
403 printk(KERN_DEBUG "A%c %s, %s\n",
404 dir, evts[evt], tcodes[tcode]);
405 break;
406 case 0x0: case 0x1: case 0x4: case 0x5: case 0x9:
407 printk(KERN_DEBUG "A%c spd %x tl %02x, "
408 "%04x -> %04x, %s, "
409 "%s, %04x%08x%s\n",
410 dir, speed, header[0] >> 10 & 0x3f,
411 header[1] >> 16, header[0] >> 16, evts[evt],
412 tcodes[tcode], header[1] & 0xffff, header[2], specific);
413 break;
414 default:
415 printk(KERN_DEBUG "A%c spd %x tl %02x, "
416 "%04x -> %04x, %s, "
417 "%s%s\n",
418 dir, speed, header[0] >> 10 & 0x3f,
419 header[1] >> 16, header[0] >> 16, evts[evt],
420 tcodes[tcode], specific);
421 }
422}
423
424#else
425
426#define log_irqs(evt)
427#define log_selfids(node_id, generation, self_id_count, sid)
428#define log_ar_at_event(dir, speed, header, evt)
429
430#endif /* CONFIG_FIREWIRE_OHCI_DEBUG */
431
240static inline void reg_write(const struct fw_ohci *ohci, int offset, u32 data) 432static inline void reg_write(const struct fw_ohci *ohci, int offset, u32 data)
241{ 433{
242 writel(data, ohci->registers + offset); 434 writel(data, ohci->registers + offset);
@@ -320,6 +512,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
320 struct fw_ohci *ohci = ctx->ohci; 512 struct fw_ohci *ohci = ctx->ohci;
321 struct fw_packet p; 513 struct fw_packet p;
322 u32 status, length, tcode; 514 u32 status, length, tcode;
515 int evt;
323 516
324 p.header[0] = cond_le32_to_cpu(buffer[0]); 517 p.header[0] = cond_le32_to_cpu(buffer[0]);
325 p.header[1] = cond_le32_to_cpu(buffer[1]); 518 p.header[1] = cond_le32_to_cpu(buffer[1]);
@@ -362,12 +555,15 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
362 /* FIXME: What to do about evt_* errors? */ 555 /* FIXME: What to do about evt_* errors? */
363 length = (p.header_length + p.payload_length + 3) / 4; 556 length = (p.header_length + p.payload_length + 3) / 4;
364 status = cond_le32_to_cpu(buffer[length]); 557 status = cond_le32_to_cpu(buffer[length]);
558 evt = (status >> 16) & 0x1f;
365 559
366 p.ack = ((status >> 16) & 0x1f) - 16; 560 p.ack = evt - 16;
367 p.speed = (status >> 21) & 0x7; 561 p.speed = (status >> 21) & 0x7;
368 p.timestamp = status & 0xffff; 562 p.timestamp = status & 0xffff;
369 p.generation = ohci->request_generation; 563 p.generation = ohci->request_generation;
370 564
565 log_ar_at_event('R', p.speed, p.header, evt);
566
371 /* 567 /*
372 * The OHCI bus reset handler synthesizes a phy packet with 568 * The OHCI bus reset handler synthesizes a phy packet with
373 * the new generation number when a bus reset happens (see 569 * the new generation number when a bus reset happens (see
@@ -376,14 +572,19 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
376 * generation. We only need this for requests; for responses 572 * generation. We only need this for requests; for responses
377 * we use the unique tlabel for finding the matching 573 * we use the unique tlabel for finding the matching
378 * request. 574 * request.
575 *
576 * Alas some chips sometimes emit bus reset packets with a
577 * wrong generation. We set the correct generation for these
578 * at a slightly incorrect time (in bus_reset_tasklet).
379 */ 579 */
380 580 if (evt == OHCI1394_evt_bus_reset) {
381 if (p.ack + 16 == 0x09) 581 if (!ohci->bus_reset_packet_quirk)
382 ohci->request_generation = (p.header[2] >> 16) & 0xff; 582 ohci->request_generation = (p.header[2] >> 16) & 0xff;
383 else if (ctx == &ohci->ar_request_ctx) 583 } else if (ctx == &ohci->ar_request_ctx) {
384 fw_core_handle_request(&ohci->card, &p); 584 fw_core_handle_request(&ohci->card, &p);
385 else 585 } else {
386 fw_core_handle_response(&ohci->card, &p); 586 fw_core_handle_response(&ohci->card, &p);
587 }
387 588
388 return buffer + length + 1; 589 return buffer + length + 1;
389} 590}
@@ -770,8 +971,19 @@ at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
770 DESCRIPTOR_IRQ_ALWAYS | 971 DESCRIPTOR_IRQ_ALWAYS |
771 DESCRIPTOR_BRANCH_ALWAYS); 972 DESCRIPTOR_BRANCH_ALWAYS);
772 973
773 /* FIXME: Document how the locking works. */ 974 /*
774 if (ohci->generation != packet->generation) { 975 * If the controller and packet generations don't match, we need to
976 * bail out and try again. If IntEvent.busReset is set, the AT context
977 * is halted, so appending to the context and trying to run it is
978 * futile. Most controllers do the right thing and just flush the AT
979 * queue (per section 7.2.3.2 of the OHCI 1.1 specification), but
980 * some controllers (like a JMicron JMB381 PCI-e) misbehave and wind
981 * up stalling out. So we just bail out in software and try again
982 * later, and everyone is happy.
983 * FIXME: Document how the locking works.
984 */
985 if (ohci->generation != packet->generation ||
986 reg_read(ohci, OHCI1394_IntEventSet) & OHCI1394_busReset) {
775 if (packet->payload_length > 0) 987 if (packet->payload_length > 0)
776 dma_unmap_single(ohci->card.device, payload_bus, 988 dma_unmap_single(ohci->card.device, payload_bus,
777 packet->payload_length, DMA_TO_DEVICE); 989 packet->payload_length, DMA_TO_DEVICE);
@@ -817,6 +1029,8 @@ static int handle_at_packet(struct context *context,
817 evt = le16_to_cpu(last->transfer_status) & 0x1f; 1029 evt = le16_to_cpu(last->transfer_status) & 0x1f;
818 packet->timestamp = le16_to_cpu(last->res_count); 1030 packet->timestamp = le16_to_cpu(last->res_count);
819 1031
1032 log_ar_at_event('T', packet->speed, packet->header, evt);
1033
820 switch (evt) { 1034 switch (evt) {
821 case OHCI1394_evt_timeout: 1035 case OHCI1394_evt_timeout:
822 /* Async response transmit timed out. */ 1036 /* Async response transmit timed out. */
@@ -1019,20 +1233,30 @@ static void bus_reset_tasklet(unsigned long data)
1019 ohci->node_id = reg & (OHCI1394_NodeID_busNumber | 1233 ohci->node_id = reg & (OHCI1394_NodeID_busNumber |
1020 OHCI1394_NodeID_nodeNumber); 1234 OHCI1394_NodeID_nodeNumber);
1021 1235
1236 reg = reg_read(ohci, OHCI1394_SelfIDCount);
1237 if (reg & OHCI1394_SelfIDCount_selfIDError) {
1238 fw_notify("inconsistent self IDs\n");
1239 return;
1240 }
1022 /* 1241 /*
1023 * The count in the SelfIDCount register is the number of 1242 * The count in the SelfIDCount register is the number of
1024 * bytes in the self ID receive buffer. Since we also receive 1243 * bytes in the self ID receive buffer. Since we also receive
1025 * the inverted quadlets and a header quadlet, we shift one 1244 * the inverted quadlets and a header quadlet, we shift one
1026 * bit extra to get the actual number of self IDs. 1245 * bit extra to get the actual number of self IDs.
1027 */ 1246 */
1028 1247 self_id_count = (reg >> 3) & 0x3ff;
1029 self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff; 1248 if (self_id_count == 0) {
1249 fw_notify("inconsistent self IDs\n");
1250 return;
1251 }
1030 generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; 1252 generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff;
1031 rmb(); 1253 rmb();
1032 1254
1033 for (i = 1, j = 0; j < self_id_count; i += 2, j++) { 1255 for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
1034 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) 1256 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) {
1035 fw_error("inconsistent self IDs\n"); 1257 fw_notify("inconsistent self IDs\n");
1258 return;
1259 }
1036 ohci->self_id_buffer[j] = 1260 ohci->self_id_buffer[j] =
1037 cond_le32_to_cpu(ohci->self_id_cpu[i]); 1261 cond_le32_to_cpu(ohci->self_id_cpu[i]);
1038 } 1262 }
@@ -1067,6 +1291,9 @@ static void bus_reset_tasklet(unsigned long data)
1067 context_stop(&ohci->at_response_ctx); 1291 context_stop(&ohci->at_response_ctx);
1068 reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); 1292 reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
1069 1293
1294 if (ohci->bus_reset_packet_quirk)
1295 ohci->request_generation = generation;
1296
1070 /* 1297 /*
1071 * This next bit is unrelated to the AT context stuff but we 1298 * This next bit is unrelated to the AT context stuff but we
1072 * have to do it under the spinlock also. If a new config rom 1299 * have to do it under the spinlock also. If a new config rom
@@ -1097,12 +1324,20 @@ static void bus_reset_tasklet(unsigned long data)
1097 reg_write(ohci, OHCI1394_ConfigROMhdr, ohci->next_header); 1324 reg_write(ohci, OHCI1394_ConfigROMhdr, ohci->next_header);
1098 } 1325 }
1099 1326
1327#ifdef CONFIG_FIREWIRE_OHCI_REMOTE_DMA
1328 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
1329 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
1330#endif
1331
1100 spin_unlock_irqrestore(&ohci->lock, flags); 1332 spin_unlock_irqrestore(&ohci->lock, flags);
1101 1333
1102 if (free_rom) 1334 if (free_rom)
1103 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, 1335 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
1104 free_rom, free_rom_bus); 1336 free_rom, free_rom_bus);
1105 1337
1338 log_selfids(ohci->node_id, generation,
1339 self_id_count, ohci->self_id_buffer);
1340
1106 fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation, 1341 fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation,
1107 self_id_count, ohci->self_id_buffer); 1342 self_id_count, ohci->self_id_buffer);
1108} 1343}
@@ -1118,7 +1353,9 @@ static irqreturn_t irq_handler(int irq, void *data)
1118 if (!event || !~event) 1353 if (!event || !~event)
1119 return IRQ_NONE; 1354 return IRQ_NONE;
1120 1355
1121 reg_write(ohci, OHCI1394_IntEventClear, event); 1356 /* busReset must not be cleared yet, see OHCI 1.1 clause 7.2.3.2 */
1357 reg_write(ohci, OHCI1394_IntEventClear, event & ~OHCI1394_busReset);
1358 log_irqs(event);
1122 1359
1123 if (event & OHCI1394_selfIDComplete) 1360 if (event & OHCI1394_selfIDComplete)
1124 tasklet_schedule(&ohci->bus_reset_tasklet); 1361 tasklet_schedule(&ohci->bus_reset_tasklet);
@@ -1153,6 +1390,10 @@ static irqreturn_t irq_handler(int irq, void *data)
1153 iso_event &= ~(1 << i); 1390 iso_event &= ~(1 << i);
1154 } 1391 }
1155 1392
1393 if (unlikely(event & OHCI1394_regAccessFail))
1394 fw_error("Register access failure - "
1395 "please notify linux1394-devel@lists.sf.net\n");
1396
1156 if (unlikely(event & OHCI1394_postedWriteErr)) 1397 if (unlikely(event & OHCI1394_postedWriteErr))
1157 fw_error("PCI posted write error\n"); 1398 fw_error("PCI posted write error\n");
1158 1399
@@ -1192,6 +1433,8 @@ static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
1192{ 1433{
1193 struct fw_ohci *ohci = fw_ohci(card); 1434 struct fw_ohci *ohci = fw_ohci(card);
1194 struct pci_dev *dev = to_pci_dev(card->device); 1435 struct pci_dev *dev = to_pci_dev(card->device);
1436 u32 lps;
1437 int i;
1195 1438
1196 if (software_reset(ohci)) { 1439 if (software_reset(ohci)) {
1197 fw_error("Failed to reset ohci card.\n"); 1440 fw_error("Failed to reset ohci card.\n");
@@ -1203,13 +1446,24 @@ static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
1203 * most of the registers. In fact, on some cards (ALI M5251), 1446 * most of the registers. In fact, on some cards (ALI M5251),
1204 * accessing registers in the SClk domain without LPS enabled 1447 * accessing registers in the SClk domain without LPS enabled
1205 * will lock up the machine. Wait 50msec to make sure we have 1448 * will lock up the machine. Wait 50msec to make sure we have
1206 * full link enabled. 1449 * full link enabled. However, with some cards (well, at least
1450 * a JMicron PCIe card), we have to try again sometimes.
1207 */ 1451 */
1208 reg_write(ohci, OHCI1394_HCControlSet, 1452 reg_write(ohci, OHCI1394_HCControlSet,
1209 OHCI1394_HCControl_LPS | 1453 OHCI1394_HCControl_LPS |
1210 OHCI1394_HCControl_postedWriteEnable); 1454 OHCI1394_HCControl_postedWriteEnable);
1211 flush_writes(ohci); 1455 flush_writes(ohci);
1212 msleep(50); 1456
1457 for (lps = 0, i = 0; !lps && i < 3; i++) {
1458 msleep(50);
1459 lps = reg_read(ohci, OHCI1394_HCControlSet) &
1460 OHCI1394_HCControl_LPS;
1461 }
1462
1463 if (!lps) {
1464 fw_error("Failed to set Link Power Status\n");
1465 return -EIO;
1466 }
1213 1467
1214 reg_write(ohci, OHCI1394_HCControlClear, 1468 reg_write(ohci, OHCI1394_HCControlClear,
1215 OHCI1394_HCControl_noByteSwapData); 1469 OHCI1394_HCControl_noByteSwapData);
@@ -1237,7 +1491,10 @@ static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
1237 OHCI1394_reqTxComplete | OHCI1394_respTxComplete | 1491 OHCI1394_reqTxComplete | OHCI1394_respTxComplete |
1238 OHCI1394_isochRx | OHCI1394_isochTx | 1492 OHCI1394_isochRx | OHCI1394_isochTx |
1239 OHCI1394_postedWriteErr | OHCI1394_cycleTooLong | 1493 OHCI1394_postedWriteErr | OHCI1394_cycleTooLong |
1240 OHCI1394_cycle64Seconds | OHCI1394_masterIntEnable); 1494 OHCI1394_cycle64Seconds | OHCI1394_regAccessFail |
1495 OHCI1394_masterIntEnable);
1496 if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS)
1497 reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
1241 1498
1242 /* Activate link_on bit and contender bit in our self ID packets.*/ 1499 /* Activate link_on bit and contender bit in our self ID packets.*/
1243 if (ohci_update_phy_reg(card, 4, 0, 1500 if (ohci_update_phy_reg(card, 4, 0,
@@ -1421,6 +1678,7 @@ static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)
1421 if (packet->ack != 0) 1678 if (packet->ack != 0)
1422 goto out; 1679 goto out;
1423 1680
1681 log_ar_at_event('T', packet->speed, packet->header, 0x20);
1424 driver_data->packet = NULL; 1682 driver_data->packet = NULL;
1425 packet->ack = RCODE_CANCELLED; 1683 packet->ack = RCODE_CANCELLED;
1426 packet->callback(packet, &ohci->card, packet->ack); 1684 packet->callback(packet, &ohci->card, packet->ack);
@@ -1435,6 +1693,9 @@ static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)
1435static int 1693static int
1436ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation) 1694ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation)
1437{ 1695{
1696#ifdef CONFIG_FIREWIRE_OHCI_REMOTE_DMA
1697 return 0;
1698#else
1438 struct fw_ohci *ohci = fw_ohci(card); 1699 struct fw_ohci *ohci = fw_ohci(card);
1439 unsigned long flags; 1700 unsigned long flags;
1440 int n, retval = 0; 1701 int n, retval = 0;
@@ -1466,6 +1727,7 @@ ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation)
1466 out: 1727 out:
1467 spin_unlock_irqrestore(&ohci->lock, flags); 1728 spin_unlock_irqrestore(&ohci->lock, flags);
1468 return retval; 1729 return retval;
1730#endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */
1469} 1731}
1470 1732
1471static u64 1733static u64
@@ -2045,17 +2307,9 @@ static const struct fw_card_driver ohci_driver = {
2045 .stop_iso = ohci_stop_iso, 2307 .stop_iso = ohci_stop_iso,
2046}; 2308};
2047 2309
2048static int __devinit
2049pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2050{
2051 struct fw_ohci *ohci;
2052 u32 bus_options, max_receive, link_speed;
2053 u64 guid;
2054 int err;
2055 size_t size;
2056
2057#ifdef CONFIG_PPC_PMAC 2310#ifdef CONFIG_PPC_PMAC
2058 /* Necessary on some machines if fw-ohci was loaded/ unloaded before */ 2311static void ohci_pmac_on(struct pci_dev *dev)
2312{
2059 if (machine_is(powermac)) { 2313 if (machine_is(powermac)) {
2060 struct device_node *ofn = pci_device_to_OF_node(dev); 2314 struct device_node *ofn = pci_device_to_OF_node(dev);
2061 2315
@@ -2064,8 +2318,33 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2064 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); 2318 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1);
2065 } 2319 }
2066 } 2320 }
2321}
2322
2323static void ohci_pmac_off(struct pci_dev *dev)
2324{
2325 if (machine_is(powermac)) {
2326 struct device_node *ofn = pci_device_to_OF_node(dev);
2327
2328 if (ofn) {
2329 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0);
2330 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0);
2331 }
2332 }
2333}
2334#else
2335#define ohci_pmac_on(dev)
2336#define ohci_pmac_off(dev)
2067#endif /* CONFIG_PPC_PMAC */ 2337#endif /* CONFIG_PPC_PMAC */
2068 2338
2339static int __devinit
2340pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2341{
2342 struct fw_ohci *ohci;
2343 u32 bus_options, max_receive, link_speed;
2344 u64 guid;
2345 int err;
2346 size_t size;
2347
2069 ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); 2348 ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
2070 if (ohci == NULL) { 2349 if (ohci == NULL) {
2071 fw_error("Could not malloc fw_ohci data.\n"); 2350 fw_error("Could not malloc fw_ohci data.\n");
@@ -2074,10 +2353,12 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2074 2353
2075 fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); 2354 fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev);
2076 2355
2356 ohci_pmac_on(dev);
2357
2077 err = pci_enable_device(dev); 2358 err = pci_enable_device(dev);
2078 if (err) { 2359 if (err) {
2079 fw_error("Failed to enable OHCI hardware.\n"); 2360 fw_error("Failed to enable OHCI hardware.\n");
2080 goto fail_put_card; 2361 goto fail_free;
2081 } 2362 }
2082 2363
2083 pci_set_master(dev); 2364 pci_set_master(dev);
@@ -2088,6 +2369,8 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2088 ohci->old_uninorth = dev->vendor == PCI_VENDOR_ID_APPLE && 2369 ohci->old_uninorth = dev->vendor == PCI_VENDOR_ID_APPLE &&
2089 dev->device == PCI_DEVICE_ID_APPLE_UNI_N_FW; 2370 dev->device == PCI_DEVICE_ID_APPLE_UNI_N_FW;
2090#endif 2371#endif
2372 ohci->bus_reset_packet_quirk = dev->vendor == PCI_VENDOR_ID_TI;
2373
2091 spin_lock_init(&ohci->lock); 2374 spin_lock_init(&ohci->lock);
2092 2375
2093 tasklet_init(&ohci->bus_reset_tasklet, 2376 tasklet_init(&ohci->bus_reset_tasklet,
@@ -2173,8 +2456,9 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
2173 pci_release_region(dev, 0); 2456 pci_release_region(dev, 0);
2174 fail_disable: 2457 fail_disable:
2175 pci_disable_device(dev); 2458 pci_disable_device(dev);
2176 fail_put_card: 2459 fail_free:
2177 fw_card_put(&ohci->card); 2460 kfree(&ohci->card);
2461 ohci_pmac_off(dev);
2178 2462
2179 return err; 2463 return err;
2180} 2464}
@@ -2202,72 +2486,42 @@ static void pci_remove(struct pci_dev *dev)
2202 pci_iounmap(dev, ohci->registers); 2486 pci_iounmap(dev, ohci->registers);
2203 pci_release_region(dev, 0); 2487 pci_release_region(dev, 0);
2204 pci_disable_device(dev); 2488 pci_disable_device(dev);
2205 fw_card_put(&ohci->card); 2489 kfree(&ohci->card);
2206 2490 ohci_pmac_off(dev);
2207#ifdef CONFIG_PPC_PMAC
2208 /* On UniNorth, power down the cable and turn off the chip clock
2209 * to save power on laptops */
2210 if (machine_is(powermac)) {
2211 struct device_node *ofn = pci_device_to_OF_node(dev);
2212
2213 if (ofn) {
2214 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0);
2215 pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0);
2216 }
2217 }
2218#endif /* CONFIG_PPC_PMAC */
2219 2491
2220 fw_notify("Removed fw-ohci device.\n"); 2492 fw_notify("Removed fw-ohci device.\n");
2221} 2493}
2222 2494
2223#ifdef CONFIG_PM 2495#ifdef CONFIG_PM
2224static int pci_suspend(struct pci_dev *pdev, pm_message_t state) 2496static int pci_suspend(struct pci_dev *dev, pm_message_t state)
2225{ 2497{
2226 struct fw_ohci *ohci = pci_get_drvdata(pdev); 2498 struct fw_ohci *ohci = pci_get_drvdata(dev);
2227 int err; 2499 int err;
2228 2500
2229 software_reset(ohci); 2501 software_reset(ohci);
2230 free_irq(pdev->irq, ohci); 2502 free_irq(dev->irq, ohci);
2231 err = pci_save_state(pdev); 2503 err = pci_save_state(dev);
2232 if (err) { 2504 if (err) {
2233 fw_error("pci_save_state failed\n"); 2505 fw_error("pci_save_state failed\n");
2234 return err; 2506 return err;
2235 } 2507 }
2236 err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2508 err = pci_set_power_state(dev, pci_choose_state(dev, state));
2237 if (err) 2509 if (err)
2238 fw_error("pci_set_power_state failed with %d\n", err); 2510 fw_error("pci_set_power_state failed with %d\n", err);
2239 2511 ohci_pmac_off(dev);
2240/* PowerMac suspend code comes last */
2241#ifdef CONFIG_PPC_PMAC
2242 if (machine_is(powermac)) {
2243 struct device_node *ofn = pci_device_to_OF_node(pdev);
2244
2245 if (ofn)
2246 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0);
2247 }
2248#endif /* CONFIG_PPC_PMAC */
2249 2512
2250 return 0; 2513 return 0;
2251} 2514}
2252 2515
2253static int pci_resume(struct pci_dev *pdev) 2516static int pci_resume(struct pci_dev *dev)
2254{ 2517{
2255 struct fw_ohci *ohci = pci_get_drvdata(pdev); 2518 struct fw_ohci *ohci = pci_get_drvdata(dev);
2256 int err; 2519 int err;
2257 2520
2258/* PowerMac resume code comes first */ 2521 ohci_pmac_on(dev);
2259#ifdef CONFIG_PPC_PMAC 2522 pci_set_power_state(dev, PCI_D0);
2260 if (machine_is(powermac)) { 2523 pci_restore_state(dev);
2261 struct device_node *ofn = pci_device_to_OF_node(pdev); 2524 err = pci_enable_device(dev);
2262
2263 if (ofn)
2264 pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1);
2265 }
2266#endif /* CONFIG_PPC_PMAC */
2267
2268 pci_set_power_state(pdev, PCI_D0);
2269 pci_restore_state(pdev);
2270 err = pci_enable_device(pdev);
2271 if (err) { 2525 if (err) {
2272 fw_error("pci_enable_device failed\n"); 2526 fw_error("pci_enable_device failed\n");
2273 return err; 2527 return err;