1/***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
--- 28 unchanged lines hidden (view full) ---
37 ***********************license end**************************************/
38
39/*
40 * octeon_ebt3000_cf.c
41 *
42 */
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_ebt3000_cf.c 242201 2012-10-27 23:36:41Z jmallett $");
46
47#include <sys/param.h>
48#include <sys/bio.h>
49#include <sys/systm.h>
50#include <sys/sysctl.h>
51#include <sys/ata.h>
52#include <sys/bus.h>
53#include <sys/kernel.h>
--- 267 unchanged lines hidden (view full) ---
321static int cf_cmd_read (uint32_t nr_sectors, uint32_t start_sector, void *buf)
322{
323 unsigned long lba;
324 uint32_t count;
325 uint16_t *ptr_16;
326 uint8_t *ptr_8;
327 int error;
328
329//#define OCTEON_VISUAL_CF_0 1
330#ifdef OCTEON_VISUAL_CF_0
331 octeon_led_write_char(0, 'R');
332#endif
333 ptr_8 = (uint8_t*)buf;
334 ptr_16 = (uint16_t*)buf;
335 lba = start_sector;
336
337
338 while (nr_sectors--) {
339 error = cf_send_cmd(lba, CMD_READ_SECTOR);
340 if (error != 0) {
341 printf("%s: cf_send_cmd(CMD_READ_SECTOR) failed: %d\n", __func__, error);
342 return (error);
343 }
344
345 switch (bus_type)
--- 15 unchanged lines hidden (view full) ---
361 if ((count & 0xf) == 0)
362 (void)cf_inb_16(TF_STATUS);
363 }
364 break;
365 }
366
367 lba++;
368 }
369#ifdef OCTEON_VISUAL_CF_0
370 octeon_led_write_char(0, ' ');
371#endif
372 return (0);
373}
374
375
376/* ------------------------------------------------------------------- *
377 * cf_cmd_write() *
378 * ------------------------------------------------------------------- *
379 *
380 * Write nr_sectors to the device starting from start_sector.
381 */
382static int cf_cmd_write (uint32_t nr_sectors, uint32_t start_sector, void *buf)
383{
384 uint32_t lba;
385 uint32_t count;
386 uint16_t *ptr_16;
387 uint8_t *ptr_8;
388 int error;
389
390//#define OCTEON_VISUAL_CF_1 1
391#ifdef OCTEON_VISUAL_CF_1
392 octeon_led_write_char(1, 'W');
393#endif
394 lba = start_sector;
395 ptr_8 = (uint8_t*)buf;
396 ptr_16 = (uint16_t*)buf;
397
398 while (nr_sectors--) {
399 error = cf_send_cmd(lba, CMD_WRITE_SECTOR);
400 if (error != 0) {
401 printf("%s: cf_send_cmd(CMD_WRITE_SECTOR) failed: %d\n", __func__, error);
--- 18 unchanged lines hidden (view full) ---
420 if ((count & 0xf) == 0)
421 (void)cf_inb_16(TF_STATUS);
422 }
423 break;
424 }
425
426 lba++;
427 }
428#ifdef OCTEON_VISUAL_CF_1
429 octeon_led_write_char(1, ' ');
430#endif
431 return (0);
432}
433
434
435/* ------------------------------------------------------------------- *
436 * cf_cmd_identify() *
437 * ------------------------------------------------------------------- *
438 *
--- 99 unchanged lines hidden (view full) ---
538 * This code originally spun on DRQ. If that behavior turns out to be
539 * necessary, a flag can be added or this function can be called
540 * repeatedly as long as it is returning ENXIO.
541 */
542static int cf_wait_busy (void)
543{
544 uint8_t status;
545
546//#define OCTEON_VISUAL_CF_2 1
547#ifdef OCTEON_VISUAL_CF_2
548 static int where0 = 0;
549
550 octeon_led_run_wheel(&where0, 2);
551#endif
552
553 switch (bus_type)
554 {
555 case CF_8:
556 case CF_TRUE_IDE_8:
557 status = cf_inb_8(TF_STATUS);
558 while ((status & STATUS_BSY) == STATUS_BSY) {
559 if ((status & STATUS_DF) != 0) {
560 printf("%s: device fault (status=%x)\n", __func__, status);
--- 19 unchanged lines hidden (view full) ---
580
581 /* DRQ is only for when read data is actually available; check BSY */
582 /* Some vendors do assert DRQ, but not all. Check BSY instead. */
583 if (status & STATUS_BSY) {
584 printf("%s: device not ready (status=%x)\n", __func__, status);
585 return (ENXIO);
586 }
587
588#ifdef OCTEON_VISUAL_CF_2
589 octeon_led_write_char(2, ' ');
590#endif
591 return (0);
592}
593
594/* ------------------------------------------------------------------- *
595 * cf_swap_ascii() *
596 * ------------------------------------------------------------------- *
597 *
598 * The ascii string returned by the controller specifying
--- 162 unchanged lines hidden ---
2 * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
--- 28 unchanged lines hidden (view full) ---
37 ***********************license end**************************************/
38
39/*
40 * octeon_ebt3000_cf.c
41 *
42 */
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_ebt3000_cf.c 242201 2012-10-27 23:36:41Z jmallett $");
46
47#include <sys/param.h>
48#include <sys/bio.h>
49#include <sys/systm.h>
50#include <sys/sysctl.h>
51#include <sys/ata.h>
52#include <sys/bus.h>
53#include <sys/kernel.h>
--- 267 unchanged lines hidden (view full) ---
321static int cf_cmd_read (uint32_t nr_sectors, uint32_t start_sector, void *buf)
322{
323 unsigned long lba;
324 uint32_t count;
325 uint16_t *ptr_16;
326 uint8_t *ptr_8;
327 int error;
328
329//#define OCTEON_VISUAL_CF_0 1
330#ifdef OCTEON_VISUAL_CF_0
331 octeon_led_write_char(0, 'R');
332#endif
333 ptr_8 = (uint8_t*)buf;
334 ptr_16 = (uint16_t*)buf;
335 lba = start_sector;
336
337
338 while (nr_sectors--) {
339 error = cf_send_cmd(lba, CMD_READ_SECTOR);
340 if (error != 0) {
341 printf("%s: cf_send_cmd(CMD_READ_SECTOR) failed: %d\n", __func__, error);
342 return (error);
343 }
344
345 switch (bus_type)
--- 15 unchanged lines hidden (view full) ---
361 if ((count & 0xf) == 0)
362 (void)cf_inb_16(TF_STATUS);
363 }
364 break;
365 }
366
367 lba++;
368 }
369#ifdef OCTEON_VISUAL_CF_0
370 octeon_led_write_char(0, ' ');
371#endif
372 return (0);
373}
374
375
376/* ------------------------------------------------------------------- *
377 * cf_cmd_write() *
378 * ------------------------------------------------------------------- *
379 *
380 * Write nr_sectors to the device starting from start_sector.
381 */
382static int cf_cmd_write (uint32_t nr_sectors, uint32_t start_sector, void *buf)
383{
384 uint32_t lba;
385 uint32_t count;
386 uint16_t *ptr_16;
387 uint8_t *ptr_8;
388 int error;
389
390//#define OCTEON_VISUAL_CF_1 1
391#ifdef OCTEON_VISUAL_CF_1
392 octeon_led_write_char(1, 'W');
393#endif
394 lba = start_sector;
395 ptr_8 = (uint8_t*)buf;
396 ptr_16 = (uint16_t*)buf;
397
398 while (nr_sectors--) {
399 error = cf_send_cmd(lba, CMD_WRITE_SECTOR);
400 if (error != 0) {
401 printf("%s: cf_send_cmd(CMD_WRITE_SECTOR) failed: %d\n", __func__, error);
--- 18 unchanged lines hidden (view full) ---
420 if ((count & 0xf) == 0)
421 (void)cf_inb_16(TF_STATUS);
422 }
423 break;
424 }
425
426 lba++;
427 }
428#ifdef OCTEON_VISUAL_CF_1
429 octeon_led_write_char(1, ' ');
430#endif
431 return (0);
432}
433
434
435/* ------------------------------------------------------------------- *
436 * cf_cmd_identify() *
437 * ------------------------------------------------------------------- *
438 *
--- 99 unchanged lines hidden (view full) ---
538 * This code originally spun on DRQ. If that behavior turns out to be
539 * necessary, a flag can be added or this function can be called
540 * repeatedly as long as it is returning ENXIO.
541 */
542static int cf_wait_busy (void)
543{
544 uint8_t status;
545
546//#define OCTEON_VISUAL_CF_2 1
547#ifdef OCTEON_VISUAL_CF_2
548 static int where0 = 0;
549
550 octeon_led_run_wheel(&where0, 2);
551#endif
552
553 switch (bus_type)
554 {
555 case CF_8:
556 case CF_TRUE_IDE_8:
557 status = cf_inb_8(TF_STATUS);
558 while ((status & STATUS_BSY) == STATUS_BSY) {
559 if ((status & STATUS_DF) != 0) {
560 printf("%s: device fault (status=%x)\n", __func__, status);
--- 19 unchanged lines hidden (view full) ---
580
581 /* DRQ is only for when read data is actually available; check BSY */
582 /* Some vendors do assert DRQ, but not all. Check BSY instead. */
583 if (status & STATUS_BSY) {
584 printf("%s: device not ready (status=%x)\n", __func__, status);
585 return (ENXIO);
586 }
587
588#ifdef OCTEON_VISUAL_CF_2
589 octeon_led_write_char(2, ' ');
590#endif
591 return (0);
592}
593
594/* ------------------------------------------------------------------- *
595 * cf_swap_ascii() *
596 * ------------------------------------------------------------------- *
597 *
598 * The ascii string returned by the controller specifying
--- 162 unchanged lines hidden ---