2 * sbp2.c - SBP-2 protocol driver for IEEE-1394
4 * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com)
5 * jamesg@filanet.com (JSG)
7 * Copyright (C) 2003 Ben Collins <bcollins@debian.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394
28 * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level
29 * driver. It also registers as a SCSI lower-level driver in order to accept
30 * SCSI commands for transport using SBP-2.
32 * You may access any attached SBP-2 storage devices as if they were SCSI
33 * devices (e.g. mount /dev/sda1, fdisk, mkfs, etc.).
37 * - Error Handling: SCSI aborts and bus reset requests are handled somewhat
38 * but the code needs additional debugging.
41 #include <linux/config.h>
42 #include <linux/kernel.h>
43 #include <linux/list.h>
44 #include <linux/string.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
48 #include <linux/poll.h>
49 #include <linux/module.h>
50 #include <linux/moduleparam.h>
51 #include <linux/types.h>
52 #include <linux/delay.h>
53 #include <linux/sched.h>
54 #include <linux/blkdev.h>
55 #include <linux/smp_lock.h>
56 #include <linux/init.h>
57 #include <linux/pci.h>
59 #include <asm/current.h>
60 #include <asm/uaccess.h>
62 #include <asm/byteorder.h>
63 #include <asm/atomic.h>
64 #include <asm/system.h>
65 #include <asm/scatterlist.h>
67 #include <scsi/scsi.h>
68 #include <scsi/scsi_cmnd.h>
69 #include <scsi/scsi_dbg.h>
70 #include <scsi/scsi_device.h>
71 #include <scsi/scsi_host.h>
75 #include "ieee1394_types.h"
76 #include "ieee1394_core.h"
79 #include "highlevel.h"
80 #include "ieee1394_transactions.h"
83 static char version[] __devinitdata =
84 "$Rev: 1306 $ Ben Collins <bcollins@debian.org>";
87 * Module load parameter definitions
91 * Change max_speed on module load if you have a bad IEEE-1394
92 * controller that has trouble running 2KB packets at 400mb.
94 * NOTE: On certain OHCI parts I have seen short packets on async transmit
95 * (probably due to PCI latency/throughput issues with the part). You can
96 * bump down the speed if you are running into problems.
98 static int max_speed = IEEE1394_SPEED_MAX;
99 module_param(max_speed, int, 0644);
100 MODULE_PARM_DESC(max_speed, "Force max speed (3 = 800mb, 2 = 400mb default, 1 = 200mb, 0 = 100mb)");
103 * Set serialize_io to 1 if you'd like only one scsi command sent
104 * down to us at a time (debugging). This might be necessary for very
105 * badly behaved sbp2 devices.
107 static int serialize_io;
108 module_param(serialize_io, int, 0444);
109 MODULE_PARM_DESC(serialize_io, "Serialize all I/O coming down from the scsi drivers (default = 0)");
112 * Bump up max_sectors if you'd like to support very large sized
113 * transfers. Please note that some older sbp2 bridge chips are broken for
114 * transfers greater or equal to 128KB. Default is a value of 255
115 * sectors, or just under 128KB (at 512 byte sector size). I can note that
116 * the Oxsemi sbp2 chipsets have no problems supporting very large
119 static int max_sectors = SBP2_MAX_SECTORS;
120 module_param(max_sectors, int, 0444);
121 MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = 255)");
124 * Exclusive login to sbp2 device? In most cases, the sbp2 driver should
125 * do an exclusive login, as it's generally unsafe to have two hosts
126 * talking to a single sbp2 device at the same time (filesystem coherency,
127 * etc.). If you're running an sbp2 device that supports multiple logins,
128 * and you're either running read-only filesystems or some sort of special
129 * filesystem supporting multiple hosts (one such filesystem is OpenGFS,
130 * see opengfs.sourceforge.net for more info), then set exclusive_login
131 * to zero. Note: The Oxsemi OXFW911 sbp2 chipset supports up to four
134 static int exclusive_login = 1;
135 module_param(exclusive_login, int, 0644);
136 MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device (default = 1)");
139 * SCSI inquiry hack for really badly behaved sbp2 devices. Turn this on
140 * if your sbp2 device is not properly handling the SCSI inquiry command.
141 * This hack makes the inquiry look more like a typical MS Windows
144 * If force_inquiry_hack=1 is required for your device to work,
145 * please submit the logged sbp2_firmware_revision value of this device to
146 * the linux1394-devel mailing list.
148 static int force_inquiry_hack;
149 module_param(force_inquiry_hack, int, 0444);
150 MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)");
154 * Export information about protocols/devices supported by this driver.
156 static struct ieee1394_device_id sbp2_id_table[] = {
158 .match_flags =IEEE1394_MATCH_SPECIFIER_ID |
159 IEEE1394_MATCH_VERSION,
160 .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
161 .version = SBP2_SW_VERSION_ENTRY & 0xffffff
166 MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
169 * Debug levels, configured via kernel config, or enable here.
172 #define CONFIG_IEEE1394_SBP2_DEBUG 0
173 /* #define CONFIG_IEEE1394_SBP2_DEBUG_ORBS */
174 /* #define CONFIG_IEEE1394_SBP2_DEBUG_DMA */
175 /* #define CONFIG_IEEE1394_SBP2_DEBUG 1 */
176 /* #define CONFIG_IEEE1394_SBP2_DEBUG 2 */
177 /* #define CONFIG_IEEE1394_SBP2_PACKET_DUMP */
179 #ifdef CONFIG_IEEE1394_SBP2_DEBUG_ORBS
180 #define SBP2_ORB_DEBUG(fmt, args...) HPSB_ERR("sbp2(%s): "fmt, __FUNCTION__, ## args)
181 static u32 global_outstanding_command_orbs = 0;
182 #define outstanding_orb_incr global_outstanding_command_orbs++
183 #define outstanding_orb_decr global_outstanding_command_orbs--
185 #define SBP2_ORB_DEBUG(fmt, args...)
186 #define outstanding_orb_incr
187 #define outstanding_orb_decr
190 #ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA
191 #define SBP2_DMA_ALLOC(fmt, args...) \
192 HPSB_ERR("sbp2(%s)alloc(%d): "fmt, __FUNCTION__, \
193 ++global_outstanding_dmas, ## args)
194 #define SBP2_DMA_FREE(fmt, args...) \
195 HPSB_ERR("sbp2(%s)free(%d): "fmt, __FUNCTION__, \
196 --global_outstanding_dmas, ## args)
197 static u32 global_outstanding_dmas = 0;
199 #define SBP2_DMA_ALLOC(fmt, args...)
200 #define SBP2_DMA_FREE(fmt, args...)
203 #if CONFIG_IEEE1394_SBP2_DEBUG >= 2
204 #define SBP2_DEBUG(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
205 #define SBP2_INFO(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
206 #define SBP2_NOTICE(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
207 #define SBP2_WARN(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
208 #elif CONFIG_IEEE1394_SBP2_DEBUG == 1
209 #define SBP2_DEBUG(fmt, args...) HPSB_DEBUG("sbp2: "fmt, ## args)
210 #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)
211 #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args)
212 #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args)
214 #define SBP2_DEBUG(fmt, args...)
215 #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)
216 #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args)
217 #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args)
220 #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
227 static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id,
230 static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
231 u32 scsi_status, struct scsi_cmnd *SCpnt,
232 void (*done)(struct scsi_cmnd *));
234 static struct scsi_host_template scsi_driver_template;
236 static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC };
238 static void sbp2_host_reset(struct hpsb_host *host);
240 static int sbp2_probe(struct device *dev);
241 static int sbp2_remove(struct device *dev);
242 static int sbp2_update(struct unit_directory *ud);
244 static struct hpsb_highlevel sbp2_highlevel = {
245 .name = SBP2_DEVICE_NAME,
246 .host_reset = sbp2_host_reset,
249 static struct hpsb_address_ops sbp2_ops = {
250 .write = sbp2_handle_status_write
253 #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
254 static struct hpsb_address_ops sbp2_physdma_ops = {
255 .read = sbp2_handle_physdma_read,
256 .write = sbp2_handle_physdma_write,
260 static struct hpsb_protocol_driver sbp2_driver = {
261 .name = "SBP2 Driver",
262 .id_table = sbp2_id_table,
263 .update = sbp2_update,
265 .name = SBP2_DEVICE_NAME,
266 .bus = &ieee1394_bus_type,
268 .remove = sbp2_remove,
273 /* List of device firmware's that require a forced 36 byte inquiry. */
274 static u32 sbp2_broken_inquiry_list[] = {
275 0x00002800, /* Stefan Richter <richtest@bauwesen.tu-cottbus.de> */
276 /* DViCO Momobay CX-1 */
277 0x00000200 /* Andreas Plesch <plesch@fas.harvard.edu> */
278 /* QPS Fire DVDBurner */
281 #define NUM_BROKEN_INQUIRY_DEVS \
282 (sizeof(sbp2_broken_inquiry_list)/sizeof(*sbp2_broken_inquiry_list))
284 /**************************************
285 * General utility functions
286 **************************************/
291 * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
293 static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
297 for (length = (length >> 2); length--; )
298 temp[length] = be32_to_cpu(temp[length]);
304 * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
306 static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
310 for (length = (length >> 2); length--; )
311 temp[length] = cpu_to_be32(temp[length]);
315 #else /* BIG_ENDIAN */
316 /* Why waste the cpu cycles? */
317 #define sbp2util_be32_to_cpu_buffer(x,y)
318 #define sbp2util_cpu_to_be32_buffer(x,y)
321 #ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP
323 * Debug packet dump routine. Length is in bytes.
325 static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, u32 dump_phys_addr)
328 unsigned char *dump = buffer;
330 if (!dump || !length || !dump_name)
334 printk("[%s, 0x%x]", dump_name, dump_phys_addr);
336 printk("[%s]", dump_name);
337 for (i = 0; i < length; i++) {
346 printk("%02x ", (int) dump[i]);
353 #define sbp2util_packet_dump(w,x,y,z)
357 * Goofy routine that basically does a down_timeout function.
359 static int sbp2util_down_timeout(atomic_t *done, int timeout)
363 for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) {
364 if (msleep_interruptible(100)) /* 100ms */
367 return ((i > 0) ? 0:1);
370 /* Free's an allocated packet */
371 static void sbp2_free_packet(struct hpsb_packet *packet)
373 hpsb_free_tlabel(packet);
374 hpsb_free_packet(packet);
377 /* This is much like hpsb_node_write(), except it ignores the response
378 * subaction and returns immediately. Can be used from interrupts.
380 static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
381 quadlet_t *buffer, size_t length)
383 struct hpsb_packet *packet;
385 packet = hpsb_make_writepacket(ne->host, ne->nodeid,
386 addr, buffer, length);
390 hpsb_set_packet_complete_task(packet, (void (*)(void*))sbp2_free_packet,
393 hpsb_node_fill_packet(ne, packet);
395 if (hpsb_send_packet(packet) < 0) {
396 sbp2_free_packet(packet);
404 * This function is called to create a pool of command orbs used for
405 * command processing. It is called when a new sbp2 device is detected.
407 static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id)
409 struct sbp2scsi_host_info *hi = scsi_id->hi;
411 unsigned long flags, orbs;
412 struct sbp2_command_info *command;
414 orbs = serialize_io ? 2 : SBP2_MAX_CMDS;
416 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
417 for (i = 0; i < orbs; i++) {
418 command = (struct sbp2_command_info *)
419 kmalloc(sizeof(struct sbp2_command_info), GFP_ATOMIC);
421 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
424 memset(command, '\0', sizeof(struct sbp2_command_info));
425 command->command_orb_dma =
426 pci_map_single (hi->host->pdev, &command->command_orb,
427 sizeof(struct sbp2_command_orb),
428 PCI_DMA_BIDIRECTIONAL);
429 SBP2_DMA_ALLOC("single command orb DMA");
431 pci_map_single (hi->host->pdev, &command->scatter_gather_element,
432 sizeof(command->scatter_gather_element),
433 PCI_DMA_BIDIRECTIONAL);
434 SBP2_DMA_ALLOC("scatter_gather_element");
435 INIT_LIST_HEAD(&command->list);
436 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed);
438 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
443 * This function is called to delete a pool of command orbs.
445 static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id)
447 struct hpsb_host *host = scsi_id->hi->host;
448 struct list_head *lh, *next;
449 struct sbp2_command_info *command;
452 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
453 if (!list_empty(&scsi_id->sbp2_command_orb_completed)) {
454 list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) {
455 command = list_entry(lh, struct sbp2_command_info, list);
457 /* Release our generic DMA's */
458 pci_unmap_single(host->pdev, command->command_orb_dma,
459 sizeof(struct sbp2_command_orb),
460 PCI_DMA_BIDIRECTIONAL);
461 SBP2_DMA_FREE("single command orb DMA");
462 pci_unmap_single(host->pdev, command->sge_dma,
463 sizeof(command->scatter_gather_element),
464 PCI_DMA_BIDIRECTIONAL);
465 SBP2_DMA_FREE("scatter_gather_element");
470 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
475 * This function finds the sbp2_command for a given outstanding command
476 * orb.Only looks at the inuse list.
478 static struct sbp2_command_info *sbp2util_find_command_for_orb(
479 struct scsi_id_instance_data *scsi_id, dma_addr_t orb)
481 struct sbp2_command_info *command;
484 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
485 if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
486 list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) {
487 if (command->command_orb_dma == orb) {
488 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
493 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
495 SBP2_ORB_DEBUG("could not match command orb %x", (unsigned int)orb);
501 * This function finds the sbp2_command for a given outstanding SCpnt.
502 * Only looks at the inuse list.
504 static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(struct scsi_id_instance_data *scsi_id, void *SCpnt)
506 struct sbp2_command_info *command;
509 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
510 if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
511 list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) {
512 if (command->Current_SCpnt == SCpnt) {
513 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
518 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
523 * This function allocates a command orb used to send a scsi command.
525 static struct sbp2_command_info *sbp2util_allocate_command_orb(
526 struct scsi_id_instance_data *scsi_id,
527 struct scsi_cmnd *Current_SCpnt,
528 void (*Current_done)(struct scsi_cmnd *))
530 struct list_head *lh;
531 struct sbp2_command_info *command = NULL;
534 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
535 if (!list_empty(&scsi_id->sbp2_command_orb_completed)) {
536 lh = scsi_id->sbp2_command_orb_completed.next;
538 command = list_entry(lh, struct sbp2_command_info, list);
539 command->Current_done = Current_done;
540 command->Current_SCpnt = Current_SCpnt;
541 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse);
543 SBP2_ERR("sbp2util_allocate_command_orb - No orbs available!");
545 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
550 static void sbp2util_free_command_dma(struct sbp2_command_info *command)
552 struct scsi_id_instance_data *scsi_id =
553 (struct scsi_id_instance_data *)command->Current_SCpnt->device->host->hostdata[0];
554 struct hpsb_host *host;
557 printk(KERN_ERR "%s: scsi_id == NULL\n", __FUNCTION__);
561 host = scsi_id->ud->ne->host;
563 if (command->cmd_dma) {
564 if (command->dma_type == CMD_DMA_SINGLE) {
565 pci_unmap_single(host->pdev, command->cmd_dma,
566 command->dma_size, command->dma_dir);
567 SBP2_DMA_FREE("single bulk");
568 } else if (command->dma_type == CMD_DMA_PAGE) {
569 pci_unmap_page(host->pdev, command->cmd_dma,
570 command->dma_size, command->dma_dir);
571 SBP2_DMA_FREE("single page");
572 } /* XXX: Check for CMD_DMA_NONE bug */
573 command->dma_type = CMD_DMA_NONE;
574 command->cmd_dma = 0;
577 if (command->sge_buffer) {
578 pci_unmap_sg(host->pdev, command->sge_buffer,
579 command->dma_size, command->dma_dir);
580 SBP2_DMA_FREE("scatter list");
581 command->sge_buffer = NULL;
586 * This function moves a command to the completed orb list.
588 static void sbp2util_mark_command_completed(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command)
592 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
593 list_del(&command->list);
594 sbp2util_free_command_dma(command);
595 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed);
596 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
600 * Is scsi_id valid? Is the 1394 node still present?
602 static inline int sbp2util_node_is_available(struct scsi_id_instance_data *scsi_id)
604 return scsi_id && scsi_id->ne && !scsi_id->ne->in_limbo;
609 /*********************************************
610 * IEEE-1394 core driver stack related section
611 *********************************************/
612 static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud);
614 static int sbp2_probe(struct device *dev)
616 struct unit_directory *ud;
617 struct scsi_id_instance_data *scsi_id;
619 SBP2_DEBUG("sbp2_probe");
621 ud = container_of(dev, struct unit_directory, device);
623 /* Don't probe UD's that have the LUN flag. We'll probe the LUN(s)
625 if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY)
628 scsi_id = sbp2_alloc_device(ud);
633 sbp2_parse_unit_directory(scsi_id, ud);
635 return sbp2_start_device(scsi_id);
638 static int sbp2_remove(struct device *dev)
640 struct unit_directory *ud;
641 struct scsi_id_instance_data *scsi_id;
642 struct scsi_device *sdev;
644 SBP2_DEBUG("sbp2_remove");
646 ud = container_of(dev, struct unit_directory, device);
647 scsi_id = ud->device.driver_data;
651 /* Trigger shutdown functions in scsi's highlevel. */
652 if (scsi_id->scsi_host)
653 scsi_unblock_requests(scsi_id->scsi_host);
654 sdev = scsi_id->sdev;
656 scsi_id->sdev = NULL;
657 scsi_remove_device(sdev);
660 sbp2_logout_device(scsi_id);
661 sbp2_remove_device(scsi_id);
666 static int sbp2_update(struct unit_directory *ud)
668 struct scsi_id_instance_data *scsi_id = ud->device.driver_data;
670 SBP2_DEBUG("sbp2_update");
672 if (sbp2_reconnect_device(scsi_id)) {
675 * Ok, reconnect has failed. Perhaps we didn't
676 * reconnect fast enough. Try doing a regular login, but
677 * first do a logout just in case of any weirdness.
679 sbp2_logout_device(scsi_id);
681 if (sbp2_login_device(scsi_id)) {
682 /* Login failed too, just fail, and the backend
683 * will call our sbp2_remove for us */
684 SBP2_ERR("Failed to reconnect to sbp2 device!");
689 /* Set max retries to something large on the device. */
690 sbp2_set_busy_timeout(scsi_id);
692 /* Do a SBP-2 fetch agent reset. */
693 sbp2_agent_reset(scsi_id, 1);
695 /* Get the max speed and packet size that we can use. */
696 sbp2_max_speed_and_size(scsi_id);
698 /* Complete any pending commands with busy (so they get
699 * retried) and remove them from our queue
701 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
703 /* Make sure we unblock requests (since this is likely after a bus
705 scsi_unblock_requests(scsi_id->scsi_host);
710 /* This functions is called by the sbp2_probe, for each new device. We now
711 * allocate one scsi host for each scsi_id (unit directory). */
712 static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud)
714 struct sbp2scsi_host_info *hi;
715 struct Scsi_Host *scsi_host = NULL;
716 struct scsi_id_instance_data *scsi_id = NULL;
718 SBP2_DEBUG("sbp2_alloc_device");
720 scsi_id = kmalloc(sizeof(*scsi_id), GFP_KERNEL);
722 SBP2_ERR("failed to create scsi_id");
725 memset(scsi_id, 0, sizeof(*scsi_id));
727 scsi_id->ne = ud->ne;
729 scsi_id->speed_code = IEEE1394_SPEED_100;
730 scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
731 atomic_set(&scsi_id->sbp2_login_complete, 0);
732 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse);
733 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed);
734 INIT_LIST_HEAD(&scsi_id->scsi_list);
735 spin_lock_init(&scsi_id->sbp2_command_orb_lock);
736 scsi_id->sbp2_device_type_and_lun = SBP2_DEVICE_TYPE_LUN_UNINITIALIZED;
738 ud->device.driver_data = scsi_id;
740 hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host);
742 hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host, sizeof(*hi));
744 SBP2_ERR("failed to allocate hostinfo");
747 SBP2_DEBUG("sbp2_alloc_device: allocated hostinfo");
748 hi->host = ud->ne->host;
749 INIT_LIST_HEAD(&hi->scsi_ids);
751 /* Register our sbp2 status address space... */
752 hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host, &sbp2_ops,
753 SBP2_STATUS_FIFO_ADDRESS,
754 SBP2_STATUS_FIFO_ADDRESS +
755 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(SBP2_MAX_UDS_PER_NODE+1));
756 #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
757 /* Handle data movement if physical dma is not
758 * enabled/supportedon host controller */
759 hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host, &sbp2_physdma_ops,
760 0x0ULL, 0xfffffffcULL);
766 list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids);
768 /* Register our host with the SCSI stack. */
769 scsi_host = scsi_host_alloc(&scsi_driver_template,
770 sizeof (unsigned long));
772 SBP2_ERR("failed to register scsi host");
776 scsi_host->hostdata[0] = (unsigned long)scsi_id;
778 if (!scsi_add_host(scsi_host, &ud->device)) {
779 scsi_id->scsi_host = scsi_host;
783 SBP2_ERR("failed to add scsi host");
784 scsi_host_put(scsi_host);
787 sbp2_remove_device(scsi_id);
792 static void sbp2_host_reset(struct hpsb_host *host)
794 struct sbp2scsi_host_info *hi;
795 struct scsi_id_instance_data *scsi_id;
797 hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
800 list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list)
801 scsi_block_requests(scsi_id->scsi_host);
807 * This function is where we first pull the node unique ids, and then
808 * allocate memory and register a SBP-2 device.
810 static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
812 struct sbp2scsi_host_info *hi = scsi_id->hi;
815 SBP2_DEBUG("sbp2_start_device");
818 scsi_id->login_response =
819 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_response),
820 &scsi_id->login_response_dma);
821 if (!scsi_id->login_response)
823 SBP2_DMA_ALLOC("consistent DMA region for login FIFO");
825 /* Query logins ORB DMA */
826 scsi_id->query_logins_orb =
827 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_orb),
828 &scsi_id->query_logins_orb_dma);
829 if (!scsi_id->query_logins_orb)
831 SBP2_DMA_ALLOC("consistent DMA region for query logins ORB");
833 /* Query logins response DMA */
834 scsi_id->query_logins_response =
835 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_response),
836 &scsi_id->query_logins_response_dma);
837 if (!scsi_id->query_logins_response)
839 SBP2_DMA_ALLOC("consistent DMA region for query logins response");
841 /* Reconnect ORB DMA */
842 scsi_id->reconnect_orb =
843 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_reconnect_orb),
844 &scsi_id->reconnect_orb_dma);
845 if (!scsi_id->reconnect_orb)
847 SBP2_DMA_ALLOC("consistent DMA region for reconnect ORB");
850 scsi_id->logout_orb =
851 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_logout_orb),
852 &scsi_id->logout_orb_dma);
853 if (!scsi_id->logout_orb)
855 SBP2_DMA_ALLOC("consistent DMA region for logout ORB");
859 pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_orb),
860 &scsi_id->login_orb_dma);
861 if (!scsi_id->login_orb) {
863 if (scsi_id->query_logins_response) {
864 pci_free_consistent(hi->host->pdev,
865 sizeof(struct sbp2_query_logins_response),
866 scsi_id->query_logins_response,
867 scsi_id->query_logins_response_dma);
868 SBP2_DMA_FREE("query logins response DMA");
871 if (scsi_id->query_logins_orb) {
872 pci_free_consistent(hi->host->pdev,
873 sizeof(struct sbp2_query_logins_orb),
874 scsi_id->query_logins_orb,
875 scsi_id->query_logins_orb_dma);
876 SBP2_DMA_FREE("query logins ORB DMA");
879 if (scsi_id->logout_orb) {
880 pci_free_consistent(hi->host->pdev,
881 sizeof(struct sbp2_logout_orb),
883 scsi_id->logout_orb_dma);
884 SBP2_DMA_FREE("logout ORB DMA");
887 if (scsi_id->reconnect_orb) {
888 pci_free_consistent(hi->host->pdev,
889 sizeof(struct sbp2_reconnect_orb),
890 scsi_id->reconnect_orb,
891 scsi_id->reconnect_orb_dma);
892 SBP2_DMA_FREE("reconnect ORB DMA");
895 if (scsi_id->login_response) {
896 pci_free_consistent(hi->host->pdev,
897 sizeof(struct sbp2_login_response),
898 scsi_id->login_response,
899 scsi_id->login_response_dma);
900 SBP2_DMA_FREE("login FIFO DMA");
903 list_del(&scsi_id->scsi_list);
907 SBP2_ERR ("Could not allocate memory for scsi_id");
911 SBP2_DMA_ALLOC("consistent DMA region for login ORB");
913 SBP2_DEBUG("New SBP-2 device inserted, SCSI ID = %x", scsi_id->ud->id);
916 * Create our command orb pool
918 if (sbp2util_create_command_orb_pool(scsi_id)) {
919 SBP2_ERR("sbp2util_create_command_orb_pool failed!");
920 sbp2_remove_device(scsi_id);
924 /* Schedule a timeout here. The reason is that we may be so close
925 * to a bus reset, that the device is not available for logins.
926 * This can happen when the bus reset is caused by the host
927 * connected to the sbp2 device being removed. That host would
928 * have a certain amount of time to relogin before the sbp2 device
929 * allows someone else to login instead. One second makes sense. */
930 msleep_interruptible(1000);
931 if (signal_pending(current)) {
932 SBP2_WARN("aborting sbp2_start_device due to event");
933 sbp2_remove_device(scsi_id);
938 * Login to the sbp-2 device
940 if (sbp2_login_device(scsi_id)) {
941 /* Login failed, just remove the device. */
942 sbp2_remove_device(scsi_id);
947 * Set max retries to something large on the device
949 sbp2_set_busy_timeout(scsi_id);
952 * Do a SBP-2 fetch agent reset
954 sbp2_agent_reset(scsi_id, 1);
957 * Get the max speed and packet size that we can use
959 sbp2_max_speed_and_size(scsi_id);
961 /* Add this device to the scsi layer now */
962 error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0);
964 SBP2_ERR("scsi_add_device failed");
972 * This function removes an sbp2 device from the sbp2scsi_host_info struct.
974 static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
976 struct sbp2scsi_host_info *hi;
978 SBP2_DEBUG("sbp2_remove_device");
985 /* This will remove our scsi device aswell */
986 if (scsi_id->scsi_host) {
987 scsi_remove_host(scsi_id->scsi_host);
988 scsi_host_put(scsi_id->scsi_host);
991 sbp2util_remove_command_orb_pool(scsi_id);
993 list_del(&scsi_id->scsi_list);
995 if (scsi_id->login_response) {
996 pci_free_consistent(hi->host->pdev,
997 sizeof(struct sbp2_login_response),
998 scsi_id->login_response,
999 scsi_id->login_response_dma);
1000 SBP2_DMA_FREE("single login FIFO");
1003 if (scsi_id->login_orb) {
1004 pci_free_consistent(hi->host->pdev,
1005 sizeof(struct sbp2_login_orb),
1007 scsi_id->login_orb_dma);
1008 SBP2_DMA_FREE("single login ORB");
1011 if (scsi_id->reconnect_orb) {
1012 pci_free_consistent(hi->host->pdev,
1013 sizeof(struct sbp2_reconnect_orb),
1014 scsi_id->reconnect_orb,
1015 scsi_id->reconnect_orb_dma);
1016 SBP2_DMA_FREE("single reconnect orb");
1019 if (scsi_id->logout_orb) {
1020 pci_free_consistent(hi->host->pdev,
1021 sizeof(struct sbp2_logout_orb),
1022 scsi_id->logout_orb,
1023 scsi_id->logout_orb_dma);
1024 SBP2_DMA_FREE("single logout orb");
1027 if (scsi_id->query_logins_orb) {
1028 pci_free_consistent(hi->host->pdev,
1029 sizeof(struct sbp2_query_logins_orb),
1030 scsi_id->query_logins_orb,
1031 scsi_id->query_logins_orb_dma);
1032 SBP2_DMA_FREE("single query logins orb");
1035 if (scsi_id->query_logins_response) {
1036 pci_free_consistent(hi->host->pdev,
1037 sizeof(struct sbp2_query_logins_response),
1038 scsi_id->query_logins_response,
1039 scsi_id->query_logins_response_dma);
1040 SBP2_DMA_FREE("single query logins data");
1043 scsi_id->ud->device.driver_data = NULL;
1045 SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->ud->id);
1050 #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
1052 * This function deals with physical dma write requests (for adapters that do not support
1053 * physical dma in hardware). Mostly just here for debugging...
1055 static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, int destid, quadlet_t *data,
1056 u64 addr, size_t length, u16 flags)
1060 * Manually put the data in the right place.
1062 memcpy(bus_to_virt((u32)addr), data, length);
1063 sbp2util_packet_dump(data, length, "sbp2 phys dma write by device", (u32)addr);
1064 return(RCODE_COMPLETE);
1068 * This function deals with physical dma read requests (for adapters that do not support
1069 * physical dma in hardware). Mostly just here for debugging...
1071 static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, quadlet_t *data,
1072 u64 addr, size_t length, u16 flags)
1076 * Grab data from memory and send a read response.
1078 memcpy(data, bus_to_virt((u32)addr), length);
1079 sbp2util_packet_dump(data, length, "sbp2 phys dma read by device", (u32)addr);
1080 return(RCODE_COMPLETE);
1085 /**************************************
1086 * SBP-2 protocol related section
1087 **************************************/
1090 * This function determines if we should convert scsi commands for a particular sbp2 device type
1092 static __inline__ int sbp2_command_conversion_device_type(u8 device_type)
1094 return (((device_type == TYPE_DISK) ||
1095 (device_type == TYPE_RBC) ||
1096 (device_type == TYPE_ROM)) ? 1:0);
1100 * This function queries the device for the maximum concurrent logins it
1103 static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1105 struct sbp2scsi_host_info *hi = scsi_id->hi;
1110 SBP2_DEBUG("sbp2_query_logins");
1112 scsi_id->query_logins_orb->reserved1 = 0x0;
1113 scsi_id->query_logins_orb->reserved2 = 0x0;
1115 scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma;
1116 scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
1117 SBP2_DEBUG("sbp2_query_logins: query_response_hi/lo initialized");
1119 scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST);
1120 scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
1121 if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
1122 scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun);
1123 SBP2_DEBUG("sbp2_query_logins: set lun to %d",
1124 ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun));
1126 SBP2_DEBUG("sbp2_query_logins: lun_misc initialized");
1128 scsi_id->query_logins_orb->reserved_resp_length =
1129 ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response));
1130 SBP2_DEBUG("sbp2_query_logins: reserved_resp_length initialized");
1132 scsi_id->query_logins_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO +
1133 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->ud->id);
1134 scsi_id->query_logins_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
1135 SBP2_STATUS_FIFO_ADDRESS_HI);
1136 SBP2_DEBUG("sbp2_query_logins: status FIFO initialized");
1138 sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb));
1140 SBP2_DEBUG("sbp2_query_logins: orb byte-swapped");
1142 sbp2util_packet_dump(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb),
1143 "sbp2 query logins orb", scsi_id->query_logins_orb_dma);
1145 memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response));
1146 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1148 SBP2_DEBUG("sbp2_query_logins: query_logins_response/status FIFO memset");
1150 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1151 data[1] = scsi_id->query_logins_orb_dma;
1152 sbp2util_cpu_to_be32_buffer(data, 8);
1154 atomic_set(&scsi_id->sbp2_login_complete, 0);
1156 SBP2_DEBUG("sbp2_query_logins: prepared to write");
1157 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1158 SBP2_DEBUG("sbp2_query_logins: written");
1160 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) {
1161 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
1165 if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) {
1166 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
1170 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
1171 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
1172 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1174 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
1178 sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response));
1180 SBP2_DEBUG("length_max_logins = %x",
1181 (unsigned int)scsi_id->query_logins_response->length_max_logins);
1183 SBP2_DEBUG("Query logins to SBP-2 device successful");
1185 max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins);
1186 SBP2_DEBUG("Maximum concurrent logins supported: %d", max_logins);
1188 active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins);
1189 SBP2_DEBUG("Number of active logins: %d", active_logins);
1191 if (active_logins >= max_logins) {
1199 * This function is called in order to login to a particular SBP-2 device,
1200 * after a bus reset.
1202 static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1204 struct sbp2scsi_host_info *hi = scsi_id->hi;
1207 SBP2_DEBUG("sbp2_login_device");
1209 if (!scsi_id->login_orb) {
1210 SBP2_DEBUG("sbp2_login_device: login_orb not alloc'd!");
1214 if (!exclusive_login) {
1215 if (sbp2_query_logins(scsi_id)) {
1216 SBP2_INFO("Device does not support any more concurrent logins");
1221 /* Set-up login ORB, assume no password */
1222 scsi_id->login_orb->password_hi = 0;
1223 scsi_id->login_orb->password_lo = 0;
1224 SBP2_DEBUG("sbp2_login_device: password_hi/lo initialized");
1226 scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma;
1227 scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
1228 SBP2_DEBUG("sbp2_login_device: login_response_hi/lo initialized");
1230 scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
1231 scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */
1232 scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */
1233 scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */
1234 /* Set the lun if we were able to pull it from the device's unit directory */
1235 if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
1236 scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun);
1237 SBP2_DEBUG("sbp2_query_logins: set lun to %d",
1238 ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun));
1240 SBP2_DEBUG("sbp2_login_device: lun_misc initialized");
1242 scsi_id->login_orb->passwd_resp_lengths =
1243 ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
1244 SBP2_DEBUG("sbp2_login_device: passwd_resp_lengths initialized");
1246 scsi_id->login_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO +
1247 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->ud->id);
1248 scsi_id->login_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
1249 SBP2_STATUS_FIFO_ADDRESS_HI);
1250 SBP2_DEBUG("sbp2_login_device: status FIFO initialized");
1253 * Byte swap ORB if necessary
1255 sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb));
1257 SBP2_DEBUG("sbp2_login_device: orb byte-swapped");
1259 sbp2util_packet_dump(scsi_id->login_orb, sizeof(struct sbp2_login_orb),
1260 "sbp2 login orb", scsi_id->login_orb_dma);
1263 * Initialize login response and status fifo
1265 memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response));
1266 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1268 SBP2_DEBUG("sbp2_login_device: login_response/status FIFO memset");
1271 * Ok, let's write to the target's management agent register
1273 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1274 data[1] = scsi_id->login_orb_dma;
1275 sbp2util_cpu_to_be32_buffer(data, 8);
1277 atomic_set(&scsi_id->sbp2_login_complete, 0);
1279 SBP2_DEBUG("sbp2_login_device: prepared to write to %08x",
1280 (unsigned int)scsi_id->sbp2_management_agent_addr);
1281 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1282 SBP2_DEBUG("sbp2_login_device: written");
1285 * Wait for login status (up to 20 seconds)...
1287 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) {
1288 SBP2_ERR("Error logging into SBP-2 device - login timed-out");
1293 * Sanity. Make sure status returned matches login orb.
1295 if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) {
1296 SBP2_ERR("Error logging into SBP-2 device - login timed-out");
1303 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
1304 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
1305 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1307 SBP2_ERR("Error logging into SBP-2 device - login failed");
1312 * Byte swap the login response, for use when reconnecting or
1315 sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response));
1318 * Grab our command block agent address from the login response.
1320 SBP2_DEBUG("command_block_agent_hi = %x",
1321 (unsigned int)scsi_id->login_response->command_block_agent_hi);
1322 SBP2_DEBUG("command_block_agent_lo = %x",
1323 (unsigned int)scsi_id->login_response->command_block_agent_lo);
1325 scsi_id->sbp2_command_block_agent_addr =
1326 ((u64)scsi_id->login_response->command_block_agent_hi) << 32;
1327 scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo);
1328 scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL;
1330 SBP2_INFO("Logged into SBP-2 device");
1337 * This function is called in order to logout from a particular SBP-2
1338 * device, usually called during driver unload.
1340 static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1342 struct sbp2scsi_host_info *hi = scsi_id->hi;
1346 SBP2_DEBUG("sbp2_logout_device");
1351 scsi_id->logout_orb->reserved1 = 0x0;
1352 scsi_id->logout_orb->reserved2 = 0x0;
1353 scsi_id->logout_orb->reserved3 = 0x0;
1354 scsi_id->logout_orb->reserved4 = 0x0;
1356 scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST);
1357 scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
1359 /* Notify us when complete */
1360 scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
1362 scsi_id->logout_orb->reserved5 = 0x0;
1363 scsi_id->logout_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO +
1364 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->ud->id);
1365 scsi_id->logout_orb->status_FIFO_hi = (ORB_SET_NODE_ID(hi->host->node_id) |
1366 SBP2_STATUS_FIFO_ADDRESS_HI);
1369 * Byte swap ORB if necessary
1371 sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb));
1373 sbp2util_packet_dump(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb),
1374 "sbp2 logout orb", scsi_id->logout_orb_dma);
1377 * Ok, let's write to the target's management agent register
1379 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1380 data[1] = scsi_id->logout_orb_dma;
1381 sbp2util_cpu_to_be32_buffer(data, 8);
1383 atomic_set(&scsi_id->sbp2_login_complete, 0);
1385 error = hpsb_node_write(scsi_id->ne,
1386 scsi_id->sbp2_management_agent_addr,
1391 /* Wait for device to logout...1 second. */
1392 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ))
1395 SBP2_INFO("Logged out of SBP-2 device");
1402 * This function is called in order to reconnect to a particular SBP-2
1403 * device, after a bus reset.
1405 static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1407 struct sbp2scsi_host_info *hi = scsi_id->hi;
1411 SBP2_DEBUG("sbp2_reconnect_device");
1414 * Set-up reconnect ORB
1416 scsi_id->reconnect_orb->reserved1 = 0x0;
1417 scsi_id->reconnect_orb->reserved2 = 0x0;
1418 scsi_id->reconnect_orb->reserved3 = 0x0;
1419 scsi_id->reconnect_orb->reserved4 = 0x0;
1421 scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST);
1422 scsi_id->reconnect_orb->login_ID_misc |=
1423 ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
1425 /* Notify us when complete */
1426 scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
1428 scsi_id->reconnect_orb->reserved5 = 0x0;
1429 scsi_id->reconnect_orb->status_FIFO_lo = SBP2_STATUS_FIFO_ADDRESS_LO +
1430 SBP2_STATUS_FIFO_ENTRY_TO_OFFSET(scsi_id->ud->id);
1431 scsi_id->reconnect_orb->status_FIFO_hi =
1432 (ORB_SET_NODE_ID(hi->host->node_id) | SBP2_STATUS_FIFO_ADDRESS_HI);
1435 * Byte swap ORB if necessary
1437 sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb));
1439 sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb),
1440 "sbp2 reconnect orb", scsi_id->reconnect_orb_dma);
1443 * Initialize status fifo
1445 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1448 * Ok, let's write to the target's management agent register
1450 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1451 data[1] = scsi_id->reconnect_orb_dma;
1452 sbp2util_cpu_to_be32_buffer(data, 8);
1454 atomic_set(&scsi_id->sbp2_login_complete, 0);
1456 error = hpsb_node_write(scsi_id->ne,
1457 scsi_id->sbp2_management_agent_addr,
1463 * Wait for reconnect status (up to 1 second)...
1465 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) {
1466 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out");
1471 * Sanity. Make sure status returned matches reconnect orb.
1473 if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) {
1474 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out");
1481 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
1482 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
1483 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1485 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed");
1489 HPSB_DEBUG("Reconnected to SBP-2 device");
1496 * This function is called in order to set the busy timeout (number of
1497 * retries to attempt) on the sbp2 device.
1499 static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id)
1503 SBP2_DEBUG("sbp2_set_busy_timeout");
1506 * Ok, let's write to the target's busy timeout register
1508 data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
1510 if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) {
1511 SBP2_ERR("sbp2_set_busy_timeout error");
1519 * This function is called to parse sbp2 device's config rom unit
1520 * directory. Used to determine things like sbp2 management agent offset,
1521 * and command set used (SCSI or RBC).
1523 static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1524 struct unit_directory *ud)
1526 struct csr1212_keyval *kv;
1527 struct csr1212_dentry *dentry;
1528 u64 management_agent_addr;
1529 u32 command_set_spec_id, command_set, unit_characteristics,
1530 firmware_revision, workarounds;
1533 SBP2_DEBUG("sbp2_parse_unit_directory");
1535 management_agent_addr = 0x0;
1536 command_set_spec_id = 0x0;
1538 unit_characteristics = 0x0;
1539 firmware_revision = 0x0;
1541 /* Handle different fields in the unit directory, based on keys */
1542 csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) {
1543 switch (kv->key.id) {
1544 case CSR1212_KV_ID_DEPENDENT_INFO:
1545 if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) {
1546 /* Save off the management agent address */
1547 management_agent_addr =
1548 CSR1212_REGISTER_SPACE_BASE +
1549 (kv->value.csr_offset << 2);
1551 SBP2_DEBUG("sbp2_management_agent_addr = %x",
1552 (unsigned int) management_agent_addr);
1553 } else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
1554 scsi_id->sbp2_device_type_and_lun = kv->value.immediate;
1558 case SBP2_COMMAND_SET_SPEC_ID_KEY:
1559 /* Command spec organization */
1560 command_set_spec_id = kv->value.immediate;
1561 SBP2_DEBUG("sbp2_command_set_spec_id = %x",
1562 (unsigned int) command_set_spec_id);
1565 case SBP2_COMMAND_SET_KEY:
1566 /* Command set used by sbp2 device */
1567 command_set = kv->value.immediate;
1568 SBP2_DEBUG("sbp2_command_set = %x",
1569 (unsigned int) command_set);
1572 case SBP2_UNIT_CHARACTERISTICS_KEY:
1574 * Unit characterisitcs (orb related stuff
1575 * that I'm not yet paying attention to)
1577 unit_characteristics = kv->value.immediate;
1578 SBP2_DEBUG("sbp2_unit_characteristics = %x",
1579 (unsigned int) unit_characteristics);
1582 case SBP2_FIRMWARE_REVISION_KEY:
1583 /* Firmware revision */
1584 firmware_revision = kv->value.immediate;
1585 if (force_inquiry_hack)
1586 SBP2_INFO("sbp2_firmware_revision = %x",
1587 (unsigned int) firmware_revision);
1588 else SBP2_DEBUG("sbp2_firmware_revision = %x",
1589 (unsigned int) firmware_revision);
1597 /* This is the start of our broken device checking. We try to hack
1598 * around oddities and known defects. */
1601 /* If the vendor id is 0xa0b8 (Symbios vendor id), then we have a
1602 * bridge with 128KB max transfer size limitation. For sanity, we
1603 * only voice this when the current max_sectors setting
1604 * exceeds the 128k limit. By default, that is not the case.
1606 * It would be really nice if we could detect this before the scsi
1607 * host gets initialized. That way we can down-force the
1608 * max_sectors to account for it. That is not currently
1610 if ((firmware_revision & 0xffff00) ==
1611 SBP2_128KB_BROKEN_FIRMWARE &&
1612 (max_sectors * 512) > (128*1024)) {
1613 SBP2_WARN("Node " NODE_BUS_FMT ": Bridge only supports 128KB max transfer size.",
1614 NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid));
1615 SBP2_WARN("WARNING: Current max_sectors setting is larger than 128KB (%d sectors)!",
1617 workarounds |= SBP2_BREAKAGE_128K_MAX_TRANSFER;
1620 /* Check for a blacklisted set of devices that require us to force
1621 * a 36 byte host inquiry. This can be overriden as a module param
1622 * (to force all hosts). */
1623 for (i = 0; i < NUM_BROKEN_INQUIRY_DEVS; i++) {
1624 if ((firmware_revision & 0xffff00) ==
1625 sbp2_broken_inquiry_list[i]) {
1626 SBP2_WARN("Node " NODE_BUS_FMT ": Using 36byte inquiry workaround",
1627 NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid));
1628 workarounds |= SBP2_BREAKAGE_INQUIRY_HACK;
1629 break; /* No need to continue. */
1633 /* If this is a logical unit directory entry, process the parent
1634 * to get the values. */
1635 if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) {
1636 struct unit_directory *parent_ud =
1637 container_of(ud->device.parent, struct unit_directory, device);
1638 sbp2_parse_unit_directory(scsi_id, parent_ud);
1640 scsi_id->sbp2_management_agent_addr = management_agent_addr;
1641 scsi_id->sbp2_command_set_spec_id = command_set_spec_id;
1642 scsi_id->sbp2_command_set = command_set;
1643 scsi_id->sbp2_unit_characteristics = unit_characteristics;
1644 scsi_id->sbp2_firmware_revision = firmware_revision;
1645 scsi_id->workarounds = workarounds;
1646 if (ud->flags & UNIT_DIRECTORY_HAS_LUN)
1647 scsi_id->sbp2_device_type_and_lun = ud->lun;
1652 * This function is called in order to determine the max speed and packet
1653 * size we can use in our ORBs. Note, that we (the driver and host) only
1654 * initiate the transaction. The SBP-2 device actually transfers the data
1655 * (by reading from the DMA area we tell it). This means that the SBP-2
1656 * device decides the actual maximum data it can transfer. We just tell it
1657 * the speed that it needs to use, and the max_rec the host supports, and
1658 * it takes care of the rest.
1660 static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1662 struct sbp2scsi_host_info *hi = scsi_id->hi;
1664 SBP2_DEBUG("sbp2_max_speed_and_size");
1666 /* Initial setting comes from the hosts speed map */
1667 scsi_id->speed_code = hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64
1668 + NODEID_TO_NODE(scsi_id->ne->nodeid)];
1670 /* Bump down our speed if the user requested it */
1671 if (scsi_id->speed_code > max_speed) {
1672 scsi_id->speed_code = max_speed;
1673 SBP2_ERR("Forcing SBP-2 max speed down to %s",
1674 hpsb_speedto_str[scsi_id->speed_code]);
1677 /* Payload size is the lesser of what our speed supports and what
1678 * our host supports. */
1679 scsi_id->max_payload_size = min(sbp2_speedto_max_payload[scsi_id->speed_code],
1680 (u8)(hi->host->csr.max_rec - 1));
1682 HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]",
1683 NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid),
1684 hpsb_speedto_str[scsi_id->speed_code],
1685 1 << ((u32)scsi_id->max_payload_size + 2));
1691 * This function is called in order to perform a SBP-2 agent reset.
1693 static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1699 SBP2_DEBUG("sbp2_agent_reset");
1702 * Ok, let's write to the target's management agent register
1704 data = ntohl(SBP2_AGENT_RESET_DATA);
1705 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
1708 retval = hpsb_node_write(scsi_id->ne, addr, &data, 4);
1710 retval = sbp2util_node_write_no_wait(scsi_id->ne, addr, &data, 4);
1713 SBP2_ERR("hpsb_node_write failed.\n");
1718 * Need to make sure orb pointer is written on next command
1720 scsi_id->last_orb = NULL;
1726 * This function is called to create the actual command orb and s/g list
1727 * out of the scsi command itself.
1729 static int sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1730 struct sbp2_command_info *command,
1732 unsigned int scsi_use_sg,
1733 unsigned int scsi_request_bufflen,
1734 void *scsi_request_buffer,
1735 enum dma_data_direction dma_dir)
1738 struct sbp2scsi_host_info *hi = scsi_id->hi;
1739 struct scatterlist *sgpnt = (struct scatterlist *) scsi_request_buffer;
1740 struct sbp2_command_orb *command_orb = &command->command_orb;
1741 struct sbp2_unrestricted_page_table *scatter_gather_element =
1742 &command->scatter_gather_element[0];
1743 u32 sg_count, sg_len, orb_direction;
1748 * Set-up our command ORB..
1750 * NOTE: We're doing unrestricted page tables (s/g), as this is
1751 * best performance (at least with the devices I have). This means
1752 * that data_size becomes the number of s/g elements, and
1753 * page_size should be zero (for unrestricted).
1755 command_orb->next_ORB_hi = ORB_SET_NULL_PTR(1);
1756 command_orb->next_ORB_lo = 0x0;
1757 command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size);
1758 command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code);
1759 command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */
1762 * Get the direction of the transfer. If the direction is unknown, then use our
1763 * goofy table as a back-up.
1767 orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
1770 orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA;
1772 case DMA_FROM_DEVICE:
1773 orb_direction = ORB_DIRECTION_READ_FROM_MEDIA;
1775 case DMA_BIDIRECTIONAL:
1777 SBP2_ERR("SCSI data transfer direction not specified. "
1778 "Update the SBP2 direction table in sbp2.h if "
1779 "necessary for your application");
1780 __scsi_print_command(scsi_cmd);
1781 orb_direction = sbp2scsi_direction_table[*scsi_cmd];
1786 * Set-up our pagetable stuff... unfortunately, this has become
1787 * messier than I'd like. Need to clean this up a bit. ;-)
1789 if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
1791 SBP2_DEBUG("No data transfer");
1794 * Handle no data transfer
1796 command_orb->data_descriptor_hi = 0x0;
1797 command_orb->data_descriptor_lo = 0x0;
1798 command_orb->misc |= ORB_SET_DIRECTION(1);
1800 } else if (scsi_use_sg) {
1802 SBP2_DEBUG("Use scatter/gather");
1805 * Special case if only one element (and less than 64KB in size)
1807 if ((scsi_use_sg == 1) && (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) {
1809 SBP2_DEBUG("Only one s/g element");
1810 command->dma_dir = dma_dir;
1811 command->dma_size = sgpnt[0].length;
1812 command->dma_type = CMD_DMA_PAGE;
1813 command->cmd_dma = pci_map_page(hi->host->pdev,
1818 SBP2_DMA_ALLOC("single page scatter element");
1820 command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1821 command_orb->data_descriptor_lo = command->cmd_dma;
1822 command_orb->misc |= ORB_SET_DATA_SIZE(command->dma_size);
1823 command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
1826 int count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, dma_dir);
1827 SBP2_DMA_ALLOC("scatter list");
1829 command->dma_size = scsi_use_sg;
1830 command->dma_dir = dma_dir;
1831 command->sge_buffer = sgpnt;
1833 /* use page tables (s/g) */
1834 command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
1835 command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
1836 command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1837 command_orb->data_descriptor_lo = command->sge_dma;
1840 * Loop through and fill out our sbp-2 page tables
1841 * (and split up anything too large)
1843 for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) {
1844 sg_len = sg_dma_len(sgpnt);
1845 sg_addr = sg_dma_address(sgpnt);
1847 scatter_gather_element[sg_count].segment_base_lo = sg_addr;
1848 if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
1849 scatter_gather_element[sg_count].length_segment_base_hi =
1850 PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
1851 sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
1852 sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
1854 scatter_gather_element[sg_count].length_segment_base_hi =
1855 PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
1862 /* Number of page table (s/g) elements */
1863 command_orb->misc |= ORB_SET_DATA_SIZE(sg_count);
1865 sbp2util_packet_dump(scatter_gather_element,
1866 (sizeof(struct sbp2_unrestricted_page_table)) * sg_count,
1867 "sbp2 s/g list", command->sge_dma);
1870 * Byte swap page tables if necessary
1872 sbp2util_cpu_to_be32_buffer(scatter_gather_element,
1873 (sizeof(struct sbp2_unrestricted_page_table)) *
1880 SBP2_DEBUG("No scatter/gather");
1882 command->dma_dir = dma_dir;
1883 command->dma_size = scsi_request_bufflen;
1884 command->dma_type = CMD_DMA_SINGLE;
1885 command->cmd_dma = pci_map_single (hi->host->pdev, scsi_request_buffer,
1888 SBP2_DMA_ALLOC("single bulk");
1891 * Handle case where we get a command w/o s/g enabled (but
1892 * check for transfers larger than 64K)
1894 if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) {
1896 command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1897 command_orb->data_descriptor_lo = command->cmd_dma;
1898 command_orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen);
1899 command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
1902 * Sanity, in case our direction table is not
1905 if (!scsi_request_bufflen) {
1906 command_orb->data_descriptor_hi = 0x0;
1907 command_orb->data_descriptor_lo = 0x0;
1908 command_orb->misc |= ORB_SET_DIRECTION(1);
1913 * Need to turn this into page tables, since the
1914 * buffer is too large.
1916 command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1917 command_orb->data_descriptor_lo = command->sge_dma;
1919 /* Use page tables (s/g) */
1920 command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
1921 command_orb->misc |= ORB_SET_DIRECTION(orb_direction);
1924 * fill out our sbp-2 page tables (and split up
1928 sg_len = scsi_request_bufflen;
1929 sg_addr = command->cmd_dma;
1931 scatter_gather_element[sg_count].segment_base_lo = sg_addr;
1932 if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
1933 scatter_gather_element[sg_count].length_segment_base_hi =
1934 PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
1935 sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
1936 sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
1938 scatter_gather_element[sg_count].length_segment_base_hi =
1939 PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
1945 /* Number of page table (s/g) elements */
1946 command_orb->misc |= ORB_SET_DATA_SIZE(sg_count);
1948 sbp2util_packet_dump(scatter_gather_element,
1949 (sizeof(struct sbp2_unrestricted_page_table)) * sg_count,
1950 "sbp2 s/g list", command->sge_dma);
1953 * Byte swap page tables if necessary
1955 sbp2util_cpu_to_be32_buffer(scatter_gather_element,
1956 (sizeof(struct sbp2_unrestricted_page_table)) *
1964 * Byte swap command ORB if necessary
1966 sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb));
1969 * Put our scsi command in the command ORB
1971 memset(command_orb->cdb, 0, 12);
1972 memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
1978 * This function is called in order to begin a regular SBP-2 command.
1980 static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1981 struct sbp2_command_info *command)
1983 struct sbp2scsi_host_info *hi = scsi_id->hi;
1984 struct sbp2_command_orb *command_orb = &command->command_orb;
1985 struct node_entry *ne = scsi_id->ne;
1988 outstanding_orb_incr;
1989 SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x",
1990 command_orb, global_outstanding_command_orbs);
1992 pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma,
1993 sizeof(struct sbp2_command_orb),
1994 PCI_DMA_BIDIRECTIONAL);
1995 pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma,
1996 sizeof(command->scatter_gather_element),
1997 PCI_DMA_BIDIRECTIONAL);
1999 * Check to see if there are any previous orbs to use
2001 if (scsi_id->last_orb == NULL) {
2005 * Ok, let's write to the target's management agent register
2007 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_ORB_POINTER_OFFSET;
2008 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
2009 data[1] = command->command_orb_dma;
2010 sbp2util_cpu_to_be32_buffer(data, 8);
2012 SBP2_ORB_DEBUG("write command agent, command orb %p", command_orb);
2014 if (sbp2util_node_write_no_wait(ne, addr, data, 8) < 0) {
2015 SBP2_ERR("sbp2util_node_write_no_wait failed.\n");
2019 SBP2_ORB_DEBUG("write command agent complete");
2021 scsi_id->last_orb = command_orb;
2022 scsi_id->last_orb_dma = command->command_orb_dma;
2028 * We have an orb already sent (maybe or maybe not
2029 * processed) that we can append this orb to. So do so,
2030 * and ring the doorbell. Have to be very careful
2031 * modifying these next orb pointers, as they are accessed
2032 * both by the sbp2 device and us.
2034 scsi_id->last_orb->next_ORB_lo =
2035 cpu_to_be32(command->command_orb_dma);
2036 /* Tells hardware that this pointer is valid */
2037 scsi_id->last_orb->next_ORB_hi = 0x0;
2038 pci_dma_sync_single_for_device(hi->host->pdev, scsi_id->last_orb_dma,
2039 sizeof(struct sbp2_command_orb),
2040 PCI_DMA_BIDIRECTIONAL);
2045 data = cpu_to_be32(command->command_orb_dma);
2046 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_DOORBELL_OFFSET;
2048 SBP2_ORB_DEBUG("ring doorbell, command orb %p", command_orb);
2050 if (sbp2util_node_write_no_wait(ne, addr, &data, 4) < 0) {
2051 SBP2_ERR("sbp2util_node_write_no_wait failed");
2055 scsi_id->last_orb = command_orb;
2056 scsi_id->last_orb_dma = command->command_orb_dma;
2063 * This function is called in order to begin a regular SBP-2 command.
2065 static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
2066 struct scsi_cmnd *SCpnt,
2067 void (*done)(struct scsi_cmnd *))
2069 unchar *cmd = (unchar *) SCpnt->cmnd;
2070 unsigned int request_bufflen = SCpnt->request_bufflen;
2071 struct sbp2_command_info *command;
2073 SBP2_DEBUG("sbp2_send_command");
2074 #if (CONFIG_IEEE1394_SBP2_DEBUG >= 2) || defined(CONFIG_IEEE1394_SBP2_PACKET_DUMP)
2075 printk("[scsi command]\n ");
2076 scsi_print_command(SCpnt);
2078 SBP2_DEBUG("SCSI transfer size = %x", request_bufflen);
2079 SBP2_DEBUG("SCSI s/g elements = %x", (unsigned int)SCpnt->use_sg);
2082 * Allocate a command orb and s/g structure
2084 command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done);
2090 * The scsi stack sends down a request_bufflen which does not match the
2091 * length field in the scsi cdb. This causes some sbp2 devices to
2092 * reject this inquiry command. Fix the request_bufflen.
2094 if (*cmd == INQUIRY) {
2095 if (force_inquiry_hack || scsi_id->workarounds & SBP2_BREAKAGE_INQUIRY_HACK)
2096 request_bufflen = cmd[4] = 0x24;
2098 request_bufflen = cmd[4];
2102 * Now actually fill in the comamnd orb and sbp2 s/g list
2104 sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg,
2105 request_bufflen, SCpnt->request_buffer,
2106 SCpnt->sc_data_direction);
2108 * Update our cdb if necessary (to handle sbp2 RBC command set
2109 * differences). This is where the command set hacks go! =)
2111 sbp2_check_sbp2_command(scsi_id, command->command_orb.cdb);
2113 sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb),
2114 "sbp2 command orb", command->command_orb_dma);
2117 * Initialize status fifo
2119 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
2122 * Link up the orb, and ring the doorbell if needed
2124 sbp2_link_orb_command(scsi_id, command);
2131 * This function deals with command set differences between Linux scsi
2132 * command set and sbp2 RBC command set.
2134 static void sbp2_check_sbp2_command(struct scsi_id_instance_data *scsi_id, unchar *cmd)
2137 u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
2139 SBP2_DEBUG("sbp2_check_sbp2_command");
2145 if (sbp2_command_conversion_device_type(device_type)) {
2147 SBP2_DEBUG("Convert READ_6 to READ_10");
2150 * Need to turn read_6 into read_10
2153 new_cmd[1] = (cmd[1] & 0xe0);
2155 new_cmd[3] = (cmd[1] & 0x1f);
2156 new_cmd[4] = cmd[2];
2157 new_cmd[5] = cmd[3];
2160 new_cmd[8] = cmd[4];
2161 new_cmd[9] = cmd[5];
2163 memcpy(cmd, new_cmd, 10);
2171 if (sbp2_command_conversion_device_type(device_type)) {
2173 SBP2_DEBUG("Convert WRITE_6 to WRITE_10");
2176 * Need to turn write_6 into write_10
2179 new_cmd[1] = (cmd[1] & 0xe0);
2181 new_cmd[3] = (cmd[1] & 0x1f);
2182 new_cmd[4] = cmd[2];
2183 new_cmd[5] = cmd[3];
2186 new_cmd[8] = cmd[4];
2187 new_cmd[9] = cmd[5];
2189 memcpy(cmd, new_cmd, 10);
2197 if (sbp2_command_conversion_device_type(device_type)) {
2199 SBP2_DEBUG("Convert MODE_SENSE_6 to MODE_SENSE_10");
2202 * Need to turn mode_sense_6 into mode_sense_10
2205 new_cmd[1] = cmd[1];
2206 new_cmd[2] = cmd[2];
2212 new_cmd[8] = cmd[4];
2213 new_cmd[9] = cmd[5];
2215 memcpy(cmd, new_cmd, 10);
2224 * TODO. Probably need to change mode select to 10 byte version
2235 * Translates SBP-2 status into SCSI sense data for check conditions
2237 static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data)
2239 SBP2_DEBUG("sbp2_status_to_sense_data");
2242 * Ok, it's pretty ugly... ;-)
2244 sense_data[0] = 0x70;
2245 sense_data[1] = 0x0;
2246 sense_data[2] = sbp2_status[9];
2247 sense_data[3] = sbp2_status[12];
2248 sense_data[4] = sbp2_status[13];
2249 sense_data[5] = sbp2_status[14];
2250 sense_data[6] = sbp2_status[15];
2252 sense_data[8] = sbp2_status[16];
2253 sense_data[9] = sbp2_status[17];
2254 sense_data[10] = sbp2_status[18];
2255 sense_data[11] = sbp2_status[19];
2256 sense_data[12] = sbp2_status[10];
2257 sense_data[13] = sbp2_status[11];
2258 sense_data[14] = sbp2_status[20];
2259 sense_data[15] = sbp2_status[21];
2261 return(sbp2_status[8] & 0x3f); /* return scsi status */
2265 * This function is called after a command is completed, in order to do any necessary SBP-2
2266 * response data translations for the SCSI stack
2268 static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2269 struct scsi_cmnd *SCpnt)
2271 u8 *scsi_buf = SCpnt->request_buffer;
2272 u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
2274 SBP2_DEBUG("sbp2_check_sbp2_response");
2276 switch (SCpnt->cmnd[0]) {
2281 * If scsi_id->sbp2_device_type_and_lun is uninitialized, then fill
2282 * this information in from the inquiry response data. Lun is set to zero.
2284 if (scsi_id->sbp2_device_type_and_lun == SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) {
2285 SBP2_DEBUG("Creating sbp2_device_type_and_lun from scsi inquiry data");
2286 scsi_id->sbp2_device_type_and_lun = (scsi_buf[0] & 0x1f) << 16;
2290 * Make sure data length is ok. Minimum length is 36 bytes
2292 if (scsi_buf[4] == 0) {
2293 scsi_buf[4] = 36 - 5;
2297 * Check for Simple Direct Access Device and change it to TYPE_DISK
2299 if ((scsi_buf[0] & 0x1f) == TYPE_RBC) {
2300 SBP2_DEBUG("Changing TYPE_RBC to TYPE_DISK");
2301 scsi_buf[0] &= 0xe0;
2305 * Fix ansi revision and response data format
2308 scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2;
2314 if (sbp2_command_conversion_device_type(device_type)) {
2316 SBP2_DEBUG("Modify mode sense response (10 byte version)");
2318 scsi_buf[0] = scsi_buf[1]; /* Mode data length */
2319 scsi_buf[1] = scsi_buf[2]; /* Medium type */
2320 scsi_buf[2] = scsi_buf[3]; /* Device specific parameter */
2321 scsi_buf[3] = scsi_buf[7]; /* Block descriptor length */
2322 memcpy(scsi_buf + 4, scsi_buf + 8, scsi_buf[0]);
2330 * TODO. Probably need to change mode select to 10 byte version
2340 * This function deals with status writes from the SBP-2 device
2342 static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid,
2343 quadlet_t *data, u64 addr, size_t length, u16 fl)
2345 struct sbp2scsi_host_info *hi;
2346 struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp;
2348 struct scsi_cmnd *SCpnt = NULL;
2349 u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
2350 struct sbp2_command_info *command;
2352 SBP2_DEBUG("sbp2_handle_status_write");
2354 sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr);
2357 SBP2_ERR("host is NULL - this is bad!");
2358 return(RCODE_ADDRESS_ERROR);
2361 hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
2364 SBP2_ERR("host info is NULL - this is bad!");
2365 return(RCODE_ADDRESS_ERROR);
2369 * Find our scsi_id structure by looking at the status fifo address written to by
2372 id = SBP2_STATUS_FIFO_OFFSET_TO_ENTRY((u32)(addr - SBP2_STATUS_FIFO_ADDRESS));
2373 list_for_each_entry(scsi_id_tmp, &hi->scsi_ids, scsi_list) {
2374 if (scsi_id_tmp->ne->nodeid == nodeid && scsi_id_tmp->ud->id == id) {
2375 scsi_id = scsi_id_tmp;
2381 SBP2_ERR("scsi_id is NULL - device is gone?");
2382 return(RCODE_ADDRESS_ERROR);
2386 * Put response into scsi_id status fifo...
2388 memcpy(&scsi_id->status_block, data, length);
2391 * Byte swap first two quadlets (8 bytes) of status for processing
2393 sbp2util_be32_to_cpu_buffer(&scsi_id->status_block, 8);
2396 * Handle command ORB status here if necessary. First, need to match status with command.
2398 command = sbp2util_find_command_for_orb(scsi_id, scsi_id->status_block.ORB_offset_lo);
2401 SBP2_DEBUG("Found status for command ORB");
2402 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma,
2403 sizeof(struct sbp2_command_orb),
2404 PCI_DMA_BIDIRECTIONAL);
2405 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma,
2406 sizeof(command->scatter_gather_element),
2407 PCI_DMA_BIDIRECTIONAL);
2409 SBP2_ORB_DEBUG("matched command orb %p", &command->command_orb);
2410 outstanding_orb_decr;
2413 * Matched status with command, now grab scsi command pointers and check status
2415 SCpnt = command->Current_SCpnt;
2416 sbp2util_mark_command_completed(scsi_id, command);
2421 * See if the target stored any scsi status information
2423 if (STATUS_GET_LENGTH(scsi_id->status_block.ORB_offset_hi_misc) > 1) {
2425 * Translate SBP-2 status to SCSI sense data
2427 SBP2_DEBUG("CHECK CONDITION");
2428 scsi_status = sbp2_status_to_sense_data((unchar *)&scsi_id->status_block, SCpnt->sense_buffer);
2432 * Check to see if the dead bit is set. If so, we'll have to initiate
2433 * a fetch agent reset.
2435 if (STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc)) {
2438 * Initiate a fetch agent reset.
2440 SBP2_DEBUG("Dead bit set - initiating fetch agent reset");
2441 sbp2_agent_reset(scsi_id, 0);
2444 SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb);
2448 * Check here to see if there are no commands in-use. If there are none, we can
2449 * null out last orb so that next time around we write directly to the orb pointer...
2450 * Quick start saves one 1394 bus transaction.
2452 if (list_empty(&scsi_id->sbp2_command_orb_inuse)) {
2453 scsi_id->last_orb = NULL;
2459 * It's probably a login/logout/reconnect status.
2461 if ((scsi_id->login_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
2462 (scsi_id->query_logins_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
2463 (scsi_id->reconnect_orb_dma == scsi_id->status_block.ORB_offset_lo) ||
2464 (scsi_id->logout_orb_dma == scsi_id->status_block.ORB_offset_lo)) {
2465 atomic_set(&scsi_id->sbp2_login_complete, 1);
2471 /* Complete the SCSI command. */
2472 SBP2_DEBUG("Completing SCSI command");
2473 sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt,
2474 command->Current_done);
2475 SBP2_ORB_DEBUG("command orb completed");
2478 return(RCODE_COMPLETE);
2482 /**************************************
2483 * SCSI interface related section
2484 **************************************/
2487 * This routine is the main request entry routine for doing I/O. It is
2488 * called from the scsi stack directly.
2490 static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
2491 void (*done)(struct scsi_cmnd *))
2493 struct scsi_id_instance_data *scsi_id =
2494 (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0];
2495 struct sbp2scsi_host_info *hi;
2496 int result = DID_NO_CONNECT << 16;
2498 SBP2_DEBUG("sbp2scsi_queuecommand");
2500 if (!sbp2util_node_is_available(scsi_id))
2506 SBP2_ERR("sbp2scsi_host_info is NULL - this is bad!");
2511 * Until we handle multiple luns, just return selection time-out
2512 * to any IO directed at non-zero LUNs
2514 if (SCpnt->device->lun)
2518 * Check for request sense command, and handle it here
2519 * (autorequest sense)
2521 if (SCpnt->cmnd[0] == REQUEST_SENSE) {
2522 SBP2_DEBUG("REQUEST_SENSE");
2523 memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen);
2524 memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer));
2525 sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_GOOD, SCpnt, done);
2530 * Check to see if we are in the middle of a bus reset.
2532 if (!hpsb_node_entry_valid(scsi_id->ne)) {
2533 SBP2_ERR("Bus reset in progress - rejecting command");
2534 result = DID_BUS_BUSY << 16;
2539 * Try and send our SCSI command
2541 if (sbp2_send_command(scsi_id, SCpnt, done)) {
2542 SBP2_ERR("Error sending SCSI command");
2543 sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
2549 SCpnt->result = result;
2555 * This function is called in order to complete all outstanding SBP-2
2556 * commands (in case of resets, etc.).
2558 static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id,
2561 struct sbp2scsi_host_info *hi = scsi_id->hi;
2562 struct list_head *lh;
2563 struct sbp2_command_info *command;
2565 SBP2_DEBUG("sbp2scsi_complete_all_commands");
2567 while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
2568 SBP2_DEBUG("Found pending command to complete");
2569 lh = scsi_id->sbp2_command_orb_inuse.next;
2570 command = list_entry(lh, struct sbp2_command_info, list);
2571 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma,
2572 sizeof(struct sbp2_command_orb),
2573 PCI_DMA_BIDIRECTIONAL);
2574 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma,
2575 sizeof(command->scatter_gather_element),
2576 PCI_DMA_BIDIRECTIONAL);
2577 sbp2util_mark_command_completed(scsi_id, command);
2578 if (command->Current_SCpnt) {
2579 command->Current_SCpnt->result = status << 16;
2580 command->Current_done(command->Current_SCpnt);
2588 * This function is called in order to complete a regular SBP-2 command.
2590 * This can be called in interrupt context.
2592 static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2593 u32 scsi_status, struct scsi_cmnd *SCpnt,
2594 void (*done)(struct scsi_cmnd *))
2596 SBP2_DEBUG("sbp2scsi_complete_command");
2602 SBP2_ERR("SCpnt is NULL");
2607 * If a bus reset is in progress and there was an error, don't
2608 * complete the command, just let it get retried at the end of the
2611 if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
2612 SBP2_ERR("Bus reset in progress - retry command later");
2617 * Switch on scsi status
2619 switch (scsi_status) {
2620 case SBP2_SCSI_STATUS_GOOD:
2621 SCpnt->result = DID_OK;
2624 case SBP2_SCSI_STATUS_BUSY:
2625 SBP2_ERR("SBP2_SCSI_STATUS_BUSY");
2626 SCpnt->result = DID_BUS_BUSY << 16;
2629 case SBP2_SCSI_STATUS_CHECK_CONDITION:
2630 SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION");
2631 SCpnt->result = CHECK_CONDITION << 1;
2636 #if CONFIG_IEEE1394_SBP2_DEBUG >= 1
2637 scsi_print_command(SCpnt);
2638 scsi_print_sense("bh", SCpnt);
2643 case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
2644 SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT");
2645 SCpnt->result = DID_NO_CONNECT << 16;
2646 scsi_print_command(SCpnt);
2649 case SBP2_SCSI_STATUS_CONDITION_MET:
2650 case SBP2_SCSI_STATUS_RESERVATION_CONFLICT:
2651 case SBP2_SCSI_STATUS_COMMAND_TERMINATED:
2652 SBP2_ERR("Bad SCSI status = %x", scsi_status);
2653 SCpnt->result = DID_ERROR << 16;
2654 scsi_print_command(SCpnt);
2658 SBP2_ERR("Unsupported SCSI status = %x", scsi_status);
2659 SCpnt->result = DID_ERROR << 16;
2663 * Take care of any sbp2 response data mucking here (RBC stuff, etc.)
2665 if (SCpnt->result == DID_OK) {
2666 sbp2_check_sbp2_response(scsi_id, SCpnt);
2670 * If a bus reset is in progress and there was an error, complete
2671 * the command as busy so that it will get retried.
2673 if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
2674 SBP2_ERR("Completing command with busy (bus reset)");
2675 SCpnt->result = DID_BUS_BUSY << 16;
2679 * If a unit attention occurs, return busy status so it gets
2680 * retried... it could have happened because of a 1394 bus reset
2684 if ((scsi_status == SBP2_SCSI_STATUS_CHECK_CONDITION) &&
2685 (SCpnt->sense_buffer[2] == UNIT_ATTENTION)) {
2686 SBP2_DEBUG("UNIT ATTENTION - return busy");
2687 SCpnt->result = DID_BUS_BUSY << 16;
2692 * Tell scsi stack that we're done with this command
2698 static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
2700 ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = sdev;
2705 static int sbp2scsi_slave_configure(struct scsi_device *sdev)
2707 blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
2712 static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
2714 ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = NULL;
2720 * Called by scsi stack when something has really gone wrong. Usually
2721 * called when a command has timed-out for some reason.
2723 static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2725 struct scsi_id_instance_data *scsi_id =
2726 (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0];
2727 struct sbp2scsi_host_info *hi = scsi_id->hi;
2728 struct sbp2_command_info *command;
2730 SBP2_ERR("aborting sbp2 command");
2731 scsi_print_command(SCpnt);
2733 if (sbp2util_node_is_available(scsi_id)) {
2736 * Right now, just return any matching command structures
2739 command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt);
2741 SBP2_DEBUG("Found command to abort");
2742 pci_dma_sync_single_for_cpu(hi->host->pdev,
2743 command->command_orb_dma,
2744 sizeof(struct sbp2_command_orb),
2745 PCI_DMA_BIDIRECTIONAL);
2746 pci_dma_sync_single_for_cpu(hi->host->pdev,
2748 sizeof(command->scatter_gather_element),
2749 PCI_DMA_BIDIRECTIONAL);
2750 sbp2util_mark_command_completed(scsi_id, command);
2751 if (command->Current_SCpnt) {
2752 command->Current_SCpnt->result = DID_ABORT << 16;
2753 command->Current_done(command->Current_SCpnt);
2758 * Initiate a fetch agent reset.
2760 sbp2_agent_reset(scsi_id, 0);
2761 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
2768 * Called by scsi stack when something has really gone wrong.
2770 static int sbp2scsi_reset(struct scsi_cmnd *SCpnt)
2772 struct scsi_id_instance_data *scsi_id =
2773 (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0];
2774 unsigned long flags;
2776 SBP2_ERR("reset requested");
2778 spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
2780 if (sbp2util_node_is_available(scsi_id)) {
2781 SBP2_ERR("Generating sbp2 fetch agent reset");
2782 sbp2_agent_reset(scsi_id, 0);
2785 spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
2790 static const char *sbp2scsi_info (struct Scsi_Host *host)
2792 return "SCSI emulation for IEEE-1394 SBP-2 Devices";
2795 static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, char *buf)
2797 struct scsi_device *sdev;
2798 struct scsi_id_instance_data *scsi_id;
2801 if (!(sdev = to_scsi_device(dev)))
2804 if (!(scsi_id = (struct scsi_id_instance_data *)sdev->host->hostdata[0]))
2807 if (scsi_id->sbp2_device_type_and_lun == SBP2_DEVICE_TYPE_LUN_UNINITIALIZED)
2810 lun = ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun);
2812 return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)scsi_id->ne->guid,
2813 scsi_id->ud->id, lun);
2815 static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
2817 static struct device_attribute *sbp2_sysfs_sdev_attrs[] = {
2818 &dev_attr_ieee1394_id,
2822 MODULE_AUTHOR("Ben Collins <bcollins@debian.org>");
2823 MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
2824 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
2825 MODULE_LICENSE("GPL");
2827 /* SCSI host template */
2828 static struct scsi_host_template scsi_driver_template = {
2829 .module = THIS_MODULE,
2830 .name = "SBP-2 IEEE-1394",
2831 .proc_name = SBP2_DEVICE_NAME,
2832 .info = sbp2scsi_info,
2833 .queuecommand = sbp2scsi_queuecommand,
2834 .eh_abort_handler = sbp2scsi_abort,
2835 .eh_device_reset_handler = sbp2scsi_reset,
2836 .eh_bus_reset_handler = sbp2scsi_reset,
2837 .eh_host_reset_handler = sbp2scsi_reset,
2838 .slave_alloc = sbp2scsi_slave_alloc,
2839 .slave_configure = sbp2scsi_slave_configure,
2840 .slave_destroy = sbp2scsi_slave_destroy,
2842 .sg_tablesize = SG_ALL,
2843 .use_clustering = ENABLE_CLUSTERING,
2844 .cmd_per_lun = SBP2_MAX_CMDS,
2845 .can_queue = SBP2_MAX_CMDS,
2847 .sdev_attrs = sbp2_sysfs_sdev_attrs,
2850 static int sbp2_module_init(void)
2854 SBP2_DEBUG("sbp2_module_init");
2856 printk(KERN_INFO "sbp2: %s\n", version);
2858 /* Module load debug option to force one command at a time (serializing I/O) */
2860 SBP2_ERR("Driver forced to serialize I/O (serialize_io = 1)");
2861 scsi_driver_template.can_queue = 1;
2862 scsi_driver_template.cmd_per_lun = 1;
2865 /* Set max sectors (module load option). Default is 255 sectors. */
2866 scsi_driver_template.max_sectors = max_sectors;
2869 /* Register our high level driver with 1394 stack */
2870 hpsb_register_highlevel(&sbp2_highlevel);
2872 ret = hpsb_register_protocol(&sbp2_driver);
2874 SBP2_ERR("Failed to register protocol");
2875 hpsb_unregister_highlevel(&sbp2_highlevel);
2882 static void __exit sbp2_module_exit(void)
2884 SBP2_DEBUG("sbp2_module_exit");
2886 hpsb_unregister_protocol(&sbp2_driver);
2888 hpsb_unregister_highlevel(&sbp2_highlevel);
2891 module_init(sbp2_module_init);
2892 module_exit(sbp2_module_exit);