firewire: fw-sbp2: use one Scsi_Host for all targets
PATCH 1/3 firewire: fw-sbp2: use one Scsi_Host for all targets
This rework prepares support of multiple logical units per target. Instead of one instance of struct Scsi_Host per target, only one Scsi_Host global to fw-sbp2 is now used. We could also use one Scsi_Host per FireWire host, but that would add more overhead for no real benefit.
The following user-visible changes result:
- The generic device of the Scsi_Host is registered as a platform device. Hence it and the target devices and logical unit devices will be sitting below /sys/devices/platform/host*/ rather than within the PCI devices tree.
- In the SCSI stack's H:C:T:L tuple, the H is now constant for all fw-sbp2 devices but the T is unique. We currently allocate T as stupidly as the H was allocated before: It is simply increased whenever a target is added.
Neither of these changes should affect userspace, because none of the mentioned device properties have been of any interest to userspace before.
---
requires patches
"firewire: fw-sbp2: sanitize list handling" (update)
http://marc.info/?l=linux1394-devel&m=118566666024249
"firewire: remove unused macros"
http://marc.info/?l=linux1394-devel&m=118540673511987
update: fix memory leak in release_sbp2_device
drivers/firewire/fw-sbp2.c | 118 +++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 48 deletions(-)
drivers/firewire/fw-sbp2.c +70 -48
@@ -28,6 +28,7 @@* and many others. */ +#include <linux/err.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -39,6 +40,8 @@#include <linux/string.h> #include <linux/timer.h> +#include <asm/atomic.h> +#include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_dbg.h>
@@ -71,6 +74,7 @@ struct sbp2_device {struct fw_unit *unit;struct fw_address_handler address_handler;struct list_head orb_list; +struct scsi_device *sdev;u64 management_agent_address;u64 command_block_agent_address;u32 workarounds;
@@ -522,34 +526,35 @@ static int sbp2_agent_reset(struct fw_unreturn 0 ; } -static void sbp2_reconnect (struct work_struct *work); -static struct scsi_host_template scsi_driver_template; -static void release_sbp2_device (struct kref *kref) { struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); -struct Scsi_Host *host = - container_of((void *)sd, struct Scsi_Host, hostdata[0]); -scsi_remove_host (host); +if (sd->sdev) +scsi_remove_device (sd->sdev); +sbp2_send_management_orb (sd->unit, sd->node_id, sd->generation,SBP2_LOGOUT_REQUEST , sd->login_id,NULL );fw_core_remove_address_handler (&sd->address_handler);fw_notify ("removed sbp2 unit %s\n" , sd->unit->device.bus_id);put_device (&sd->unit->device); -scsi_host_put (host); +kfree (sd); } +static void sbp2_reconnect (struct work_struct *work); + +static struct Scsi_Host *sbp2_shost; +static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); +static void sbp2_login (struct work_struct *work) {struct sbp2_device *sd = container_of(work, struct sbp2_device, work.work); -struct Scsi_Host *host = - container_of((void *)sd, struct Scsi_Host, hostdata[0]); +struct scsi_device *sdev;struct fw_unit *unit = sd->unit;struct fw_device *device =fw_device (unit->device.parent);struct sbp2_login_response response; -int generation, node_id, local_node_id, lun, retval; +int generation, node_id, local_node_id, lun;/* FIXME: Make this work for multi-lun devices. */ lun =0 ;
@@ -597,10 +602,9 @@ static void sbp2_login(struct work_strucPREPARE_DELAYED_WORK (&sd->work, sbp2_reconnect);sbp2_agent_reset (unit); -/* FIXME: Loop over luns here. */ - lun =0 ; - retval =scsi_add_device (host,0 ,0 , lun); -if (retval <0 ) { + sdev =__scsi_add_device (sbp2_shost,0 , +atomic_inc_return (&sbp2_starget_id), lun, sd); +if (IS_ERR (sdev)) {sbp2_send_management_orb (unit, sd->node_id, sd->generation,SBP2_LOGOUT_REQUEST , sd->login_id,NULL );
@@ -609,26 +613,28 @@ static void sbp2_login(struct work_struc* retry login on bus reset. */ PREPARE_DELAYED_WORK (&sd->work, sbp2_login); + }else { + sd->sdev = sdev; +scsi_device_put (sdev); }kref_put (&sd->kref, release_sbp2_device); } +/* FIXME: Loop over luns here. */ static int sbp2_probe (struct device *dev) {struct fw_unit *unit =fw_unit (dev);struct fw_device *device =fw_device (unit->device.parent);struct sbp2_device *sd;struct fw_csr_iterator ci; -struct Scsi_Host *host; -int i, key, value, err; +int i, key, value, error;u32 model, firmware_revision; - err = -ENOMEM ; - host =scsi_host_alloc (&scsi_driver_template,sizeof (*sd)); -if (host ==NULL ) - goto fail; + error = -ENOMEM ; + sd =kzalloc (sizeof (*sd),GFP_KERNEL ); +if (!sd) + goto out_error; - sd = (struct sbp2_device *) host->hostdata; unit->device.driver_data = sd; sd->unit = unit;INIT_LIST_HEAD (&sd->orb_list);
@@ -638,18 +644,14 @@ static int sbp2_probe(struct device *dev sd->address_handler.address_callback = sbp2_status_write; sd->address_handler.callback_data = sd; - err =fw_core_add_address_handler (&sd->address_handler, - &fw_high_memory_region); -if (err <0 ) - goto fail_host; - - err =fw_device_enable_phys_dma (device); -if (err <0 ) - goto fail_address_handler; - - err =scsi_add_host (host, &unit->device); -if (err <0 ) - goto fail_address_handler; + error =fw_core_add_address_handler (&sd->address_handler, + &fw_high_memory_region); +if (error <0 ) + goto out_free; + + error =fw_device_enable_phys_dma (device); +if (error <0 ) + goto out_remove_address_handler;/* * Scan unit directory to get management agent address,
@@ -704,12 +706,12 @@ static int sbp2_probe(struct device *devreturn 0 ; - fail_address_handler: + out_remove_address_handler:fw_core_remove_address_handler (&sd->address_handler); - fail_host: -scsi_host_put (host); - fail: -return err; + out_free: +kfree (sd); + out_error: +return error; }static int sbp2_remove (struct device *dev)
@@ -890,8 +892,7 @@ complete_command_orb(struct sbp2_orb *bastatic int sbp2_command_orb_map_scatterlist (struct sbp2_command_orb *orb) { -struct sbp2_device *sd = - (struct sbp2_device *)orb->cmd->device->host->hostdata; +struct sbp2_device *sd = orb->cmd->device->hostdata;struct fw_unit *unit = sd->unit;struct fw_device *device =fw_device (unit->device.parent);struct scatterlist *sg;
@@ -978,8 +979,7 @@ static int sbp2_command_orb_map_scatterlstatic int sbp2_scsi_queuecommand (struct scsi_cmnd *cmd,scsi_done_fn_t done) { -struct sbp2_device *sd = - (struct sbp2_device *)cmd->device->host->hostdata; +struct sbp2_device *sd = cmd->device->hostdata;struct fw_unit *unit = sd->unit;struct fw_device *device =fw_device (unit->device.parent);struct sbp2_command_orb *orb;
@@ -1060,7 +1060,7 @@ static int sbp2_scsi_queuecommand(structstatic int sbp2_scsi_slave_alloc (struct scsi_device *sdev) { -struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; +struct sbp2_device *sd = sdev->hostdata; sdev->allow_restart =1 ;
@@ -1071,7 +1071,7 @@ static int sbp2_scsi_slave_alloc(structstatic int sbp2_scsi_slave_configure (struct scsi_device *sdev) { -struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata; +struct sbp2_device *sd = sdev->hostdata;struct fw_unit *unit = sd->unit; sdev->use_10_for_rw =1 ;
@@ -1096,8 +1096,7 @@ static int sbp2_scsi_slave_configure(str*/ static int sbp2_scsi_abort (struct scsi_cmnd *cmd) { -struct sbp2_device *sd = - (struct sbp2_device *)cmd->device->host->hostdata; +struct sbp2_device *sd = cmd->device->hostdata;struct fw_unit *unit = sd->unit;fw_notify ("sbp2_scsi_abort\n" );
@@ -1128,7 +1127,7 @@ sbp2_sysfs_ieee1394_id_show(struct devicif (!sdev)return 0 ; - sd = (struct sbp2_device *)sdev->host->hostdata; + sd = sdev->hostdata; unit = sd->unit; device =fw_device (unit->device.parent);
@@ -1187,12 +1186,35 @@ MODULE_ALIAS("sbp2");static int __init sbp2_init (void ) { -return driver_register (&sbp2_driver.driver); +int error = -ENOMEM ; + + sbp2_shost =scsi_host_alloc (&scsi_driver_template,0 ); +if (!sbp2_shost) + goto out_error; + + error =scsi_add_host (sbp2_shost,NULL ); +if (error) + goto out_host_put; + + error =driver_register (&sbp2_driver.driver); +if (error) + goto out_remove_host; + +return 0 ; + + out_remove_host: +scsi_remove_host (sbp2_shost); + out_host_put: +scsi_host_put (sbp2_shost); + out_error: +return error; } static void __exit sbp2_cleanup(void) {driver_unregister (&sbp2_driver.driver); +scsi_remove_host (sbp2_shost); +scsi_host_put (sbp2_shost); }module_init (sbp2_init);
Signature · 10 lines
Stefan Richter -=====-=-=== -=== ===-= http://arcgraph.de/sr/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
PATCH 2/3 firewire: fw-sbp2: split logical unit data from target data
struct sbp2_device is replaced by struct sbp2_target and struct sbp2_logical_unit. This prepares support of multiple logical units per target.
---
update: small simplifications
drivers/firewire/fw-sbp2.c | 355 ++++++++++++++++++------------------- 1 file changed, 179 insertions(+), 176 deletions(-)
drivers/firewire/fw-sbp2.c +179 -176
@@ -69,32 +69,40 @@ typedef void (*scsi_done_fn_t)(struct scstatic const char sbp2_driver_name[] ="sbp2" ; -struct sbp2_device { -struct kref kref; -struct fw_unit *unit; +struct sbp2_logical_unit { +struct sbp2_target *tgt; +struct scsi_device *sdev;struct fw_address_handler address_handler;struct list_head orb_list; -struct scsi_device *sdev; -u64 management_agent_address; +u64 command_block_agent_address; -u32 workarounds; +u16 lun;int login_id;/* -* We cache these addresses and only update them once we've -* logged in or reconnected to the sbp2 device. That way, any -* IO to the device will automatically fail and get retried if -* it happens in a window where the device is not ready to -* handle it (e.g. after a bus reset but before we reconnect). +* The generation is updated once we've logged in or reconnected to the +* logical unit. Thus, I/O to the device will automatically fail and +* get retried if it happens in a window where the device is not ready, +* e.g. after a bus reset but before we reconnect. */ -int node_id; -int address_high;int generation; -int retries;struct delayed_work work; }; +struct sbp2_target { +struct kref kref; +struct fw_unit *unit; + +u64 management_agent_address; +int node_id; +int address_high; + +unsigned workarounds; +int starget_id; +struct sbp2_logical_unit lu[1 ]; +}; +#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000#define SBP2_MAX_SECTORS 255/* Max sectors supported */ #define SBP2_ORB_TIMEOUT 2000/* Timeout in ms */
@@ -219,7 +227,7 @@ struct sbp2_command_orb { } request;struct scsi_cmnd *cmd;scsi_done_fn_t done; -struct fw_unit *unit; +struct sbp2_logical_unit *lu; struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8)));dma_addr_t page_table_bus;
@@ -287,7 +295,7 @@ sbp2_status_write(struct fw_card *card,unsigned long long offset, void *payload, size_t length, void *callback_data) { - struct sbp2_device *sd = callback_data; + struct sbp2_logical_unit *lu = callback_data;struct sbp2_orb *orb, *next;struct sbp2_status status;size_t header_size;
@@ -312,7 +320,7 @@ sbp2_status_write(struct fw_card *card,/* Lookup the orb corresponding to this status write. */ spin_lock_irqsave (&card->lock, flags); -list_for_each_entry_safe (orb, next, &sd->orb_list, link) { +list_for_each_entry_safe (orb, next, &lu->orb_list, link) {if (STATUS_GET_ORB_HIGH (status) ==0 &&STATUS_GET_ORB_LOW (status) == orb->request_bus && orb->rcode ==RCODE_COMPLETE ) {
@@ -348,11 +356,10 @@ complete_transaction(struct fw_card *car }static void -sbp2_send_orb (struct sbp2_orb *orb,struct fw_unit *unit, +sbp2_send_orb (struct sbp2_orb *orb,struct sbp2_logical_unit *lu,int node_id,int generation,u64 offset) { -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd = unit->device.driver_data; +struct fw_device *device =fw_device (lu->tgt->unit->device.parent);unsigned long flags; orb->pointer.high =0 ;
@@ -360,7 +367,7 @@ sbp2_send_orb(struct sbp2_orb *orb, strufw_memcpy_to_be32 (&orb->pointer, &orb->pointer,sizeof (orb->pointer));spin_lock_irqsave (&device->card->lock, flags); -list_add_tail (&orb->link, &sd->orb_list); +list_add_tail (&orb->link, &lu->orb_list);spin_unlock_irqrestore (&device->card->lock, flags); fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST,
@@ -369,10 +376,9 @@ sbp2_send_orb(struct sbp2_orb *orb, stru complete_transaction, orb); } -static int sbp2_cancel_orbs (struct fw_unit *unit) +static int sbp2_cancel_orbs (struct sbp2_logical_unit *lu) { -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd = unit->device.driver_data; +struct fw_device *device =fw_device (lu->tgt->unit->device.parent);struct sbp2_orb *orb, *next;struct list_head list;unsigned long flags;
@@ -380,7 +386,7 @@ static int sbp2_cancel_orbs(struct fw_unINIT_LIST_HEAD (&list);spin_lock_irqsave (&device->card->lock, flags); -list_splice_init (&sd->orb_list, &list); +list_splice_init (&lu->orb_list, &list);spin_unlock_irqrestore (&device->card->lock, flags);list_for_each_entry_safe (orb, next, &list, link) {
@@ -407,11 +413,11 @@ complete_management_orb(struct sbp2_orb }static int -sbp2_send_management_orb (struct fw_unit *unit,int node_id,int generation, -int function,int lun,void *response) +sbp2_send_management_orb (struct sbp2_logical_unit *lu,int node_id, +int generation,int function,int lun_or_login_id, +void *response) { -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd = unit->device.driver_data; +struct fw_device *device =fw_device (lu->tgt->unit->device.parent);struct sbp2_management_orb *orb;int retval = -ENOMEM ;
@@ -431,12 +437,12 @@ sbp2_send_management_orb(struct fw_unit orb->request.misc =MANAGEMENT_ORB_NOTIFY |MANAGEMENT_ORB_FUNCTION (function) | -MANAGEMENT_ORB_LUN (lun); +MANAGEMENT_ORB_LUN (lun_or_login_id); orb->request.length =MANAGEMENT_ORB_RESPONSE_LENGTH (sizeof (orb->response)); - orb->request.status_fifo.high = sd->address_handler.offset >>32 ; - orb->request.status_fifo.low = sd->address_handler.offset; + orb->request.status_fifo.high = lu->address_handler.offset >>32 ; + orb->request.status_fifo.low = lu->address_handler.offset;if (function ==SBP2_LOGIN_REQUEST ) { orb->request.misc |=
@@ -455,14 +461,14 @@ sbp2_send_management_orb(struct fw_unitif (dma_mapping_error (orb->base.request_bus)) goto fail_mapping_request; -sbp2_send_orb (&orb->base, unit, - node_id, generation, sd->management_agent_address); +sbp2_send_orb (&orb->base, lu, node_id, generation, + lu->tgt->management_agent_address);wait_for_completion_timeout (&orb->done,msecs_to_jiffies (SBP2_ORB_TIMEOUT )); retval = -EIO ; -if (sbp2_cancel_orbs (unit) ==0 ) { +if (sbp2_cancel_orbs (lu) ==0 ) {fw_error ("orb reply timed out, rcode=0x%02x\n" , orb->base.rcode); goto out;
@@ -507,10 +513,9 @@ complete_agent_reset_write(struct fw_carkfree (t); } -static int sbp2_agent_reset (struct fw_unit *unit) +static int sbp2_agent_reset (struct sbp2_logical_unit *lu) { -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd = unit->device.driver_data; +struct fw_device *device =fw_device (lu->tgt->unit->device.parent);struct fw_transaction *t;static u32 zero;
@@ -519,132 +524,138 @@ static int sbp2_agent_reset(struct fw_unreturn -ENOMEM ;fw_send_request (device->card, t,TCODE_WRITE_QUADLET_REQUEST , - sd->node_id, sd->generation, device->max_speed, - sd->command_block_agent_address +SBP2_AGENT_RESET , + lu->tgt->node_id, lu->generation, device->max_speed, + lu->command_block_agent_address +SBP2_AGENT_RESET , &zero,sizeof (zero), complete_agent_reset_write, t);return 0 ; } +/* FIXME: Loop over logical units */ static void release_sbp2_device (struct kref *kref) { - struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); + struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref); +struct sbp2_logical_unit *lu = tgt->lu; -if (sd->sdev) -scsi_remove_device (sd->sdev); +if (lu->sdev) +scsi_remove_device (lu->sdev); -sbp2_send_management_orb (sd->unit, sd->node_id, sd->generation, -SBP2_LOGOUT_REQUEST , sd->login_id,NULL ); -fw_core_remove_address_handler (&sd->address_handler); -fw_notify ("removed sbp2 unit %s\n" , sd->unit->device.bus_id); -put_device (&sd->unit->device); -kfree (sd); +sbp2_send_management_orb (lu, tgt->node_id, lu->generation, +SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); +fw_core_remove_address_handler (&lu->address_handler); +fw_notify ("removed sbp2 unit %s\n" , tgt->unit->device.bus_id); +put_device (&tgt->unit->device); +kfree (tgt); }static void sbp2_reconnect (struct work_struct *work);static struct Scsi_Host *sbp2_shost; -static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 );static void sbp2_login (struct work_struct *work) { -struct sbp2_device *sd = - container_of(work, struct sbp2_device, work.work); -struct scsi_device *sdev; -struct fw_unit *unit = sd->unit; +struct sbp2_logical_unit *lu = + container_of(work, struct sbp2_logical_unit, work.work); +struct fw_unit *unit = lu->tgt->unit;struct fw_device *device =fw_device (unit->device.parent); +int generation = device->card->generation; +int node_id = device->node->node_id; +int local_node_id = device->card->local_node->node_id; +struct scsi_device *sdev; +struct scsi_lun eight_bytes_lun = {{0 , }};struct sbp2_login_response response; -int generation, node_id, local_node_id, lun; - -/* FIXME: Make this work for multi-lun devices. */ - lun =0 ; - - generation = device->card->generation; - node_id = device->node->node_id; - local_node_id = device->card->local_node->node_id; -if (sbp2_send_management_orb (unit, node_id, generation, -SBP2_LOGIN_REQUEST , lun, &response) <0 ) { -if (sd->retries++ <5 ) { -schedule_delayed_work (&sd->work,DIV_ROUND_UP (HZ ,5 )); +if (sbp2_send_management_orb (lu, node_id, generation, +SBP2_LOGIN_REQUEST , lu->lun, &response) <0 ) { +if (lu->retries++ <5 ) { +schedule_delayed_work (&lu->work,DIV_ROUND_UP (HZ ,5 )); }else { -fw_error ("failed to login to %s\n" , - unit->device.bus_id); -kref_put (&sd->kref, release_sbp2_device); +fw_error ("failed to login to %s LUN %04x\n" , + unit->device.bus_id, lu->lun); +kref_put (&lu->tgt->kref, release_sbp2_device); }return ; } - sd->generation = generation; - sd->node_id = node_id; - sd->address_high = local_node_id <<16 ; + lu->generation = generation; + lu->tgt->node_id = node_id; + lu->tgt->address_high = local_node_id <<16 ;/* Get command block agent offset and login id. */ - sd->command_block_agent_address = + lu->command_block_agent_address = ((u64) (response.command_block_agent.high &0xffff ) <<32 ) | response.command_block_agent.low; - sd->login_id =LOGIN_RESPONSE_GET_LOGIN_ID (response); + lu->login_id =LOGIN_RESPONSE_GET_LOGIN_ID (response); -fw_notify ("logged in to sbp2 unit %s (%d retries)\n" , - unit->device.bus_id, sd->retries); +fw_notify ("logged in to sbp2 unit %s LUN %04x (%d retries)\n" , + unit->device.bus_id, lu->lun, lu->retries);fw_notify (" - management_agent_address: 0x%012llx\n" , - (unsigned long long ) sd->management_agent_address); + (unsigned long long ) lu->tgt->management_agent_address);fw_notify (" - command_block_agent_address: 0x%012llx\n" , - (unsigned long long ) sd->command_block_agent_address); + (unsigned long long ) lu->command_block_agent_address);fw_notify (" - status write address: 0x%012llx\n" , - (unsigned long long ) sd->address_handler.offset); + (unsigned long long ) lu->address_handler.offset);#if 0 /* FIXME: The linux1394 sbp2 does this last step. */ sbp2_set_busy_timeout (scsi_id);#endif -PREPARE_DELAYED_WORK (&sd->work, sbp2_reconnect); -sbp2_agent_reset (unit); +PREPARE_DELAYED_WORK (&lu->work, sbp2_reconnect); +sbp2_agent_reset (lu); - sdev =__scsi_add_device (sbp2_shost,0 , -atomic_inc_return (&sbp2_starget_id), lun, sd); + eight_bytes_lun.scsi_lun[0 ] = (lu->lun >>8 ) &0xff ; + eight_bytes_lun.scsi_lun[1 ] = lu->lun &0xff ; + sdev =__scsi_add_device (sbp2_shost,0 , lu->tgt->starget_id, +scsilun_to_int (&eight_bytes_lun), lu);if (IS_ERR (sdev)) { -sbp2_send_management_orb (unit, sd->node_id, sd->generation, -SBP2_LOGOUT_REQUEST , sd->login_id, -NULL ); +sbp2_send_management_orb (lu, node_id, generation, +SBP2_LOGOUT_REQUEST , lu->login_id,NULL );/* * Set this back to sbp2_login so we fall back and * retry login on bus reset. */ -PREPARE_DELAYED_WORK (&sd->work, sbp2_login); +PREPARE_DELAYED_WORK (&lu->work, sbp2_login); }else { - sd->sdev = sdev; + lu->sdev = sdev;scsi_device_put (sdev); } -kref_put (&sd->kref, release_sbp2_device); +kref_put (&lu->tgt->kref, release_sbp2_device); } +static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); +/* FIXME: Loop over luns here. */ static int sbp2_probe (struct device *dev) {struct fw_unit *unit =fw_unit (dev);struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd; +struct sbp2_target *tgt; +struct sbp2_logical_unit *lu;struct fw_csr_iterator ci;int i, key, value, error;u32 model, firmware_revision; error = -ENOMEM ; - sd =kzalloc (sizeof (*sd),GFP_KERNEL ); -if (!sd) + tgt =kzalloc (sizeof (*tgt),GFP_KERNEL ); +if (!tgt) goto out_error; - unit->device.driver_data = sd; - sd->unit = unit; -INIT_LIST_HEAD (&sd->orb_list); -kref_init (&sd->kref); - - sd->address_handler.length =0x100 ; - sd->address_handler.address_callback = sbp2_status_write; - sd->address_handler.callback_data = sd; + unit->device.driver_data = tgt; + tgt->unit = unit; +kref_init (&tgt->kref); + tgt->starget_id =atomic_inc_return (&sbp2_starget_id); + + lu = tgt->lu; + lu->tgt = tgt; + lu->lun =0 ; +INIT_LIST_HEAD (&lu->orb_list); + + lu->address_handler.length =0x100 ; + lu->address_handler.address_callback = sbp2_status_write; + lu->address_handler.callback_data = lu; - error =fw_core_add_address_handler (&sd->address_handler, + error =fw_core_add_address_handler (&lu->address_handler, &fw_high_memory_region);if (error <0 ) goto out_free;
@@ -664,7 +675,7 @@ static int sbp2_probe(struct device *devwhile (fw_csr_iterator_next (&ci, &key, &value)) {switch (key) {case CSR_DEPENDENT_INFO |CSR_OFFSET : - sd->management_agent_address = + tgt->management_agent_address =0xfffff0000000ULL +4 * value;break ;case SBP2_FIRMWARE_REVISION :
@@ -683,33 +694,32 @@ static int sbp2_probe(struct device *devif (sbp2_workarounds_table[i].model != model && sbp2_workarounds_table[i].model != ~0 )continue ; - sd->workarounds |= sbp2_workarounds_table[i].workarounds; + tgt->workarounds |= sbp2_workarounds_table[i].workarounds;break ; } -if (sd->workarounds) +if (tgt->workarounds)fw_notify ("Workarounds for node %s: 0x%x " "(firmware_revision 0x%06x, model_id 0x%06x)\n" , unit->device.bus_id, - sd->workarounds, firmware_revision, model); + tgt->workarounds, firmware_revision, model);get_device (&unit->device);/* -* We schedule work to do the login so we can easily -* reschedule retries. Always get the ref before scheduling -* work. +* We schedule work to do the login so we can easily reschedule retries. +* Always get the ref when scheduling work. */ -INIT_DELAYED_WORK (&sd->work, sbp2_login); -if (schedule_delayed_work (&sd->work,0 )) -kref_get (&sd->kref); +INIT_DELAYED_WORK (&lu->work, sbp2_login); +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref);return 0 ; out_remove_address_handler: -fw_core_remove_address_handler (&sd->address_handler); +fw_core_remove_address_handler (&lu->address_handler); out_free: -kfree (sd); +kfree (tgt); out_error:return error; }
@@ -717,18 +727,18 @@ static int sbp2_probe(struct device *devstatic int sbp2_remove (struct device *dev) {struct fw_unit *unit =fw_unit (dev); -struct sbp2_device *sd = unit->device.driver_data; +struct sbp2_target *tgt = unit->device.driver_data; -kref_put (&sd->kref, release_sbp2_device); +kref_put (&tgt->kref, release_sbp2_device);return 0 ; }static void sbp2_reconnect (struct work_struct *work) { -struct sbp2_device *sd = - container_of(work, struct sbp2_device, work.work); -struct fw_unit *unit = sd->unit; +struct sbp2_logical_unit *lu = + container_of(work, struct sbp2_logical_unit, work.work); +struct fw_unit *unit = lu->tgt->unit;struct fw_device *device =fw_device (unit->device.parent);int generation, node_id, local_node_id;
@@ -736,40 +746,42 @@ static void sbp2_reconnect(struct work_s node_id = device->node->node_id; local_node_id = device->card->local_node->node_id; -if (sbp2_send_management_orb (unit, node_id, generation, +if (sbp2_send_management_orb (lu, node_id, generation,SBP2_RECONNECT_REQUEST , - sd->login_id,NULL ) <0 ) { -if (sd->retries++ >=5 ) { + lu->login_id,NULL ) <0 ) { +if (lu->retries++ >=5 ) {fw_error ("failed to reconnect to %s\n" , unit->device.bus_id);/* Fall back and try to log in again. */ - sd->retries =0 ; -PREPARE_DELAYED_WORK (&sd->work, sbp2_login); + lu->retries =0 ; +PREPARE_DELAYED_WORK (&lu->work, sbp2_login); } -schedule_delayed_work (&sd->work,DIV_ROUND_UP (HZ ,5 )); +schedule_delayed_work (&lu->work,DIV_ROUND_UP (HZ ,5 ));return ; } - sd->generation = generation; - sd->node_id = node_id; - sd->address_high = local_node_id <<16 ; - -fw_notify ("reconnected to unit %s (%d retries)\n" , - unit->device.bus_id, sd->retries); -sbp2_agent_reset (unit); -sbp2_cancel_orbs (unit); -kref_put (&sd->kref, release_sbp2_device); + lu->generation = generation; + lu->tgt->node_id = node_id; + lu->tgt->address_high = local_node_id <<16 ; + +fw_notify ("reconnected to unit %s LUN %04x (%d retries)\n" , + unit->device.bus_id, lu->lun, lu->retries); +sbp2_agent_reset (lu); +sbp2_cancel_orbs (lu); +kref_put (&lu->tgt->kref, release_sbp2_device); } +/* FIXME: Loop over logical units */ static void sbp2_update (struct fw_unit *unit) {struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_device *sd = unit->device.driver_data; +struct sbp2_target *tgt = unit->device.driver_data; +struct sbp2_logical_unit *lu = tgt->lu; - sd->retries =0 ; + lu->retries =0 ;fw_device_enable_phys_dma (device); -if (schedule_delayed_work (&sd->work,0 )) -kref_get (&sd->kref); +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref); }#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
@@ -839,13 +851,12 @@ complete_command_orb(struct sbp2_orb *ba {struct sbp2_command_orb *orb = container_of(base_orb, struct sbp2_command_orb, base); -struct fw_unit *unit = orb->unit; -struct fw_device *device =fw_device (unit->device.parent); +struct fw_device *device =fw_device (orb->lu->tgt->unit->device.parent);int result;if (status !=NULL ) {if (STATUS_GET_DEAD (*status)) -sbp2_agent_reset (unit); +sbp2_agent_reset (orb->lu);switch (STATUS_GET_RESPONSE (*status)) {case SBP2_STATUS_REQUEST_COMPLETE :
@@ -890,11 +901,10 @@ complete_command_orb(struct sbp2_orb *bakfree (orb); } -static int sbp2_command_orb_map_scatterlist (struct sbp2_command_orb *orb) +static int +sbp2_map_scatterlist (struct sbp2_command_orb *orb,struct fw_device *device, +struct sbp2_logical_unit *lu) { -struct sbp2_device *sd = orb->cmd->device->hostdata; -struct fw_unit *unit = sd->unit; -struct fw_device *device =fw_device (unit->device.parent);struct scatterlist *sg;int sg_len, l, i, j, count;dma_addr_t sg_addr;
@@ -913,10 +923,9 @@ static int sbp2_command_orb_map_scatterl* tables. */ if (count ==1 &&sg_dma_len (sg) <SBP2_MAX_SG_ELEMENT_LENGTH ) { - orb->request.data_descriptor.high = sd->address_high; + orb->request.data_descriptor.high = lu->tgt->address_high; orb->request.data_descriptor.low =sg_dma_address (sg); - orb->request.misc |= -COMMAND_ORB_DATA_SIZE (sg_dma_len (sg)); + orb->request.misc |=COMMAND_ORB_DATA_SIZE (sg_dma_len (sg));return 0 ; }
@@ -960,7 +969,7 @@ static int sbp2_command_orb_map_scatterl* initiator (i.e. us), but data_descriptor can refer to data * on other nodes so we need to put our ID in descriptor.high. */ - orb->request.data_descriptor.high = sd->address_high; + orb->request.data_descriptor.high = lu->tgt->address_high; orb->request.data_descriptor.low = orb->page_table_bus; orb->request.misc |= COMMAND_ORB_PAGE_TABLE_PRESENT |
@@ -979,9 +988,8 @@ static int sbp2_command_orb_map_scatterlstatic int sbp2_scsi_queuecommand (struct scsi_cmnd *cmd,scsi_done_fn_t done) { -struct sbp2_device *sd = cmd->device->hostdata; -struct fw_unit *unit = sd->unit; -struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_logical_unit *lu = cmd->device->hostdata; +struct fw_device *device =fw_device (lu->tgt->unit->device.parent);struct sbp2_command_orb *orb;unsigned max_payload;
@@ -1005,7 +1013,7 @@ static int sbp2_scsi_queuecommand(struct/* Initialize rcode to something not RCODE_COMPLETE. */ orb->base.rcode =-1 ; - orb->unit = unit; + orb->lu = lu; orb->done = done; orb->cmd = cmd;
@@ -1031,7 +1039,7 @@ static int sbp2_scsi_queuecommand(struct orb->request.misc |=COMMAND_ORB_DIRECTION (SBP2_DIRECTION_TO_MEDIA ); -if (scsi_sg_count (cmd) &&sbp2_command_orb_map_scatterlist (orb) <0 ) +if (scsi_sg_count (cmd) &&sbp2_map_scatterlist (orb, device, lu) <0 ) goto fail_mapping;fw_memcpy_to_be32 (&orb->request, &orb->request,sizeof (orb->request));
@@ -1047,8 +1055,8 @@ static int sbp2_scsi_queuecommand(structif (dma_mapping_error (orb->base.request_bus)) goto fail_mapping; -sbp2_send_orb (&orb->base, unit, sd->node_id, sd->generation, - sd->command_block_agent_address +SBP2_ORB_POINTER ); +sbp2_send_orb (&orb->base, lu, lu->tgt->node_id, lu->generation, + lu->command_block_agent_address +SBP2_ORB_POINTER );return 0 ;
@@ -1060,32 +1068,31 @@ static int sbp2_scsi_queuecommand(structstatic int sbp2_scsi_slave_alloc (struct scsi_device *sdev) { -struct sbp2_device *sd = sdev->hostdata; +unsigned workarounds = + ((struct sbp2_logical_unit *)sdev->hostdata)->tgt->workarounds; sdev->allow_restart =1 ; -if (sd->workarounds &SBP2_WORKAROUND_INQUIRY_36 ) +if (workarounds &SBP2_WORKAROUND_INQUIRY_36 ) sdev->inquiry_len =36 ;return 0 ; }static int sbp2_scsi_slave_configure (struct scsi_device *sdev) { -struct sbp2_device *sd = sdev->hostdata; -struct fw_unit *unit = sd->unit; +unsigned workarounds = + ((struct sbp2_logical_unit *)sdev->hostdata)->tgt->workarounds; sdev->use_10_for_rw =1 ;if (sdev->type ==TYPE_ROM ) sdev->use_10_for_ms =1 ;if (sdev->type ==TYPE_DISK && - sd->workarounds &SBP2_WORKAROUND_MODE_SENSE_8 ) + workarounds &SBP2_WORKAROUND_MODE_SENSE_8 ) sdev->skip_ms_page_8 =1 ; -if (sd->workarounds &SBP2_WORKAROUND_FIX_CAPACITY ) { -fw_notify ("setting fix_capacity for %s\n" , unit->device.bus_id); +if (workarounds &SBP2_WORKAROUND_FIX_CAPACITY ) sdev->fix_capacity =1 ; - } -if (sd->workarounds &SBP2_WORKAROUND_128K_MAX_TRANS ) +if (workarounds &SBP2_WORKAROUND_128K_MAX_TRANS )blk_queue_max_sectors (sdev->request_queue,128 *1024 /512 );return 0 ; }
@@ -1096,12 +1103,11 @@ static int sbp2_scsi_slave_configure(str*/ static int sbp2_scsi_abort (struct scsi_cmnd *cmd) { -struct sbp2_device *sd = cmd->device->hostdata; -struct fw_unit *unit = sd->unit; +struct sbp2_logical_unit *lu = cmd->device->hostdata;fw_notify ("sbp2_scsi_abort\n" ); -sbp2_agent_reset (unit); -sbp2_cancel_orbs (unit); +sbp2_agent_reset (lu); +sbp2_cancel_orbs (lu);return SUCCESS ; }
@@ -1118,17 +1124,17 @@ sbp2_sysfs_ieee1394_id_show(struct devic char *buf) {struct scsi_device *sdev =to_scsi_device (dev); -struct sbp2_device *sd; +struct sbp2_logical_unit *lu;struct fw_unit *unit;struct fw_device *device;u32 directory_id;struct fw_csr_iterator ci; -int key, value, lun; +int key, value;if (!sdev)return 0 ; - sd = sdev->hostdata; - unit = sd->unit; + lu = sdev->hostdata; + unit = lu->tgt->unit; device =fw_device (unit->device.parent);/* implicit directory ID */
@@ -1143,12 +1149,9 @@ sbp2_sysfs_ieee1394_id_show(struct devicbreak ; } -/* FIXME: Make this work for multi-lun devices. */ - lun =0 ; -return sprintf (buf,"%08x%08x:%06x:%04x\n" , device->config_rom[3 ], device->config_rom[4 ], - directory_id, lun); + directory_id, lu->lun); } static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
Signature · 10 lines
Stefan Richter -=====-=-=== -=== ===-= http://arcgraph.de/sr/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
PATCH 3/3 firewire: fw-sbp2: add support for multiple logical units per target
This makes multiple logical units on a single target accessible to fw-sbp2. Successfully tested with the IOI FWB-IDE01AB dual LU bridge.
---
update:
- dynamically append logical units in a list
- simplify config ROM parsing
drivers/firewire/fw-sbp2.c | 195 ++++++++++++++++++++++++------------- 1 file changed, 130 insertions(+), 65 deletions(-)
drivers/firewire/fw-sbp2.c +130 -65
@@ -71,6 +71,7 @@ static const char sbp2_driver_name[] = "struct sbp2_logical_unit {struct sbp2_target *tgt; +struct list_head tgt_list;struct scsi_device *sdev;struct fw_address_handler address_handler;struct list_head orb_list;
@@ -100,7 +101,7 @@ struct sbp2_target {unsigned workarounds;int starget_id; -struct sbp2_logical_unit lu[1 ]; +struct list_head lu_list; };#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
@@ -113,7 +114,9 @@ struct sbp2_target {#define SBP2_DIRECTION_FROM_MEDIA 0x1/* Unit directory keys */ -#define SBP2_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 +#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4/* Flags for detected oddities and brokeness */ #define SBP2_WORKAROUND_128K_MAX_TRANS 0x1
@@ -531,18 +534,21 @@ static int sbp2_agent_reset(struct sbp2_return 0 ; } -/* FIXME: Loop over logical units */ static void release_sbp2_device (struct kref *kref) { struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref); -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu, *next; -if (lu->sdev) -scsi_remove_device (lu->sdev); +list_for_each_entry_safe (lu, next, &tgt->lu_list, tgt_list) { +if (lu->sdev) +scsi_remove_device (lu->sdev); -sbp2_send_management_orb (lu, tgt->node_id, lu->generation, -SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); -fw_core_remove_address_handler (&lu->address_handler); +sbp2_send_management_orb (lu, tgt->node_id, lu->generation, +SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); +fw_core_remove_address_handler (&lu->address_handler); +list_del (&lu->tgt_list); +kfree (lu); + }fw_notify ("removed sbp2 unit %s\n" , tgt->unit->device.bus_id);put_device (&tgt->unit->device);kfree (tgt);
@@ -623,70 +629,122 @@ static void sbp2_login(struct work_struckref_put (&lu->tgt->kref, release_sbp2_device); } -static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); - -/* FIXME: Loop over luns here. */ -static int sbp2_probe (struct device *dev) +static int sbp2_add_logical_unit (struct sbp2_target *tgt,int lun_entry) { -struct fw_unit *unit =fw_unit (dev); -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_target *tgt;struct sbp2_logical_unit *lu; -struct fw_csr_iterator ci; -int i, key, value, error; -u32 model, firmware_revision; - error = -ENOMEM ; - tgt =kzalloc (sizeof (*tgt),GFP_KERNEL ); -if (!tgt) - goto out_error; + lu =kmalloc (sizeof (*lu),GFP_KERNEL ); +if (!lu) +return -ENOMEM ; - unit->device.driver_data = tgt; - tgt->unit = unit; -kref_init (&tgt->kref); - tgt->starget_id =atomic_inc_return (&sbp2_starget_id); + lu->address_handler.length =0x100 ; + lu->address_handler.address_callback = sbp2_status_write; + lu->address_handler.callback_data = lu; + +if (fw_core_add_address_handler (&lu->address_handler, + &fw_high_memory_region) <0 ) { +kfree (lu); +return -ENOMEM ; + } - lu = tgt->lu; - lu->tgt = tgt; - lu->lun =0 ; + lu->tgt = tgt; + lu->sdev =NULL ; + lu->lun = lun_entry &0xffff ; + lu->retries =0 ;INIT_LIST_HEAD (&lu->orb_list); +INIT_DELAYED_WORK (&lu->work, sbp2_login); - lu->address_handler.length =0x100 ; - lu->address_handler.address_callback = sbp2_status_write; - lu->address_handler.callback_data = lu; +list_add_tail (&lu->tgt_list, &tgt->lu_list); +return 0 ; +} - error =fw_core_add_address_handler (&lu->address_handler, - &fw_high_memory_region); -if (error <0 ) - goto out_free; +static int sbp2_scan_logical_unit_dir (struct sbp2_target *tgt,u32 *directory) +{ +struct fw_csr_iterator ci; +int key, value; + +fw_csr_iterator_init (&ci, directory); +while (fw_csr_iterator_next (&ci, &key, &value)) +if (key ==SBP2_CSR_LOGICAL_UNIT_NUMBER && +sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +return 0 ; +} - error =fw_device_enable_phys_dma (device); -if (error <0 ) - goto out_remove_address_handler; +static int sbp2_scan_unit_dir (struct sbp2_target *tgt,u32 *directory, +u32 *model,u32 *firmware_revision) +{ +struct fw_device *dev =fw_device (tgt->unit->device.parent); +struct fw_csr_iterator ci; +int key, value; +u32 *subdir; -/* -* Scan unit directory to get management agent address, -* firmware revison and model. Initialize firmware_revision -* and model to values that wont match anything in our table. -*/ - firmware_revision =0xff000000 ; - model =0xff000000 ; -fw_csr_iterator_init (&ci, unit->directory); +fw_csr_iterator_init (&ci, directory);while (fw_csr_iterator_next (&ci, &key, &value)) {switch (key) { +case CSR_DEPENDENT_INFO |CSR_OFFSET : - tgt->management_agent_address = -0xfffff0000000ULL +4 * value; -break ; -case SBP2_FIRMWARE_REVISION : - firmware_revision = value; + tgt->management_agent_address + =0xfffff0000000ULL +4 * value;break ; +case CSR_MODEL : - model = value; + *model = value; +break ; + +case SBP2_CSR_FIRMWARE_REVISION : + *firmware_revision = value; +break ; + +case SBP2_CSR_LOGICAL_UNIT_NUMBER : +if (sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +break ; + +case SBP2_CSR_LOGICAL_UNIT_DIRECTORY : + subdir = ci.p + value; +if (subdir <= dev->config_rom +5 || + subdir >= dev->config_rom + dev->config_rom_length) +fw_error ("logical unit dir out of bounds\n" ); +else if (sbp2_scan_logical_unit_dir (tgt, subdir) <0 ) +return -ENOMEM ;break ; } } +return 0 ; +} + +static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); + +static int sbp2_probe (struct device *dev) +{ +struct fw_unit *unit =fw_unit (dev); +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_target *tgt; +struct sbp2_logical_unit *lu, *next; +int i; +u32 model, firmware_revision; + + tgt =kmalloc (sizeof (*tgt),GFP_KERNEL ); +if (!tgt) + goto out_error; + + unit->device.driver_data = tgt; + tgt->unit = unit; +kref_init (&tgt->kref); +INIT_LIST_HEAD (&tgt->lu_list); + +/* Initialize to values that won't match anything in our table. */ + model = ~0 ; + firmware_revision = ~0 ; +if (sbp2_scan_unit_dir (tgt, unit->directory, &model, + &firmware_revision) <0 ) + goto out_free; + +if (fw_device_enable_phys_dma (device) <0 ) + goto out_free; + tgt->workarounds =0 ;for (i =0 ; i <ARRAY_SIZE (sbp2_workarounds_table); i++) {if (sbp2_workarounds_table[i].firmware_revision != (firmware_revision &0xffffff00 ))
@@ -704,24 +762,29 @@ static int sbp2_probe(struct device *dev unit->device.bus_id, tgt->workarounds, firmware_revision, model); + tgt->starget_id =atomic_inc_return (&sbp2_starget_id);get_device (&unit->device);/* * We schedule work to do the login so we can easily reschedule retries. * Always get the ref when scheduling work. */ -INIT_DELAYED_WORK (&lu->work, sbp2_login); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); +list_for_each_entry (lu, &tgt->lu_list, tgt_list) +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref);return 0 ; - out_remove_address_handler: -fw_core_remove_address_handler (&lu->address_handler); out_free: +list_for_each_entry_safe (lu, next, &tgt->lu_list, tgt_list) { +fw_core_remove_address_handler (&lu->address_handler); +list_del (&lu->tgt_list); +kfree (lu); + }kfree (tgt); + out_error: -return error; +return -ENOMEM ; }static int sbp2_remove (struct device *dev)
@@ -771,17 +834,19 @@ static void sbp2_reconnect(struct work_skref_put (&lu->tgt->kref, release_sbp2_device); } -/* FIXME: Loop over logical units */ static void sbp2_update (struct fw_unit *unit) {struct fw_device *device =fw_device (unit->device.parent);struct sbp2_target *tgt = unit->device.driver_data; -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu; - lu->retries =0 ;fw_device_enable_phys_dma (device); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); + +list_for_each_entry (lu, &tgt->lu_list, tgt_list) { + lu->retries =0 ; +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref); + } }#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
Signature · 10 lines
Stefan Richter -=====-=-=== -=== ===-= http://arcgraph.de/sr/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
PATCH 1/1 firewire: fw-sbp2: add support for multiple logical units per target
This makes multiple logical units on a single target accessible to fw-sbp2. Successfully tested with the IOI FWB-IDE01AB dual LU bridge.
---
update 2:
- rectify and refactor sbp2_probe
drivers/firewire/fw-sbp2.c | 207 ++++++++++++++++++++++++------------- 1 file changed, 135 insertions(+), 72 deletions(-)
drivers/firewire/fw-sbp2.c +135 -72
@@ -71,6 +71,7 @@ static const char sbp2_driver_name[] = "struct sbp2_logical_unit {struct sbp2_target *tgt; +struct list_head tgt_list;struct scsi_device *sdev;struct fw_address_handler address_handler;struct list_head orb_list;
@@ -100,7 +101,7 @@ struct sbp2_target {unsigned workarounds;int starget_id; -struct sbp2_logical_unit lu[1 ]; +struct list_head lu_list; };#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
@@ -113,7 +114,9 @@ struct sbp2_target {#define SBP2_DIRECTION_FROM_MEDIA 0x1/* Unit directory keys */ -#define SBP2_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 +#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4/* Flags for detected oddities and brokeness */ #define SBP2_WORKAROUND_128K_MAX_TRANS 0x1
@@ -531,18 +534,21 @@ static int sbp2_agent_reset(struct sbp2_return 0 ; } -/* FIXME: Loop over logical units */ static void release_sbp2_device (struct kref *kref) { struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref); -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu, *next; -if (lu->sdev) -scsi_remove_device (lu->sdev); +list_for_each_entry_safe (lu, next, &tgt->lu_list, tgt_list) { +if (lu->sdev) +scsi_remove_device (lu->sdev); -sbp2_send_management_orb (lu, tgt->node_id, lu->generation, -SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); -fw_core_remove_address_handler (&lu->address_handler); +sbp2_send_management_orb (lu, tgt->node_id, lu->generation, +SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); +fw_core_remove_address_handler (&lu->address_handler); +list_del (&lu->tgt_list); +kfree (lu); + }fw_notify ("removed sbp2 unit %s\n" , tgt->unit->device.bus_id);put_device (&tgt->unit->device);kfree (tgt);
@@ -623,70 +629,97 @@ static void sbp2_login(struct work_struckref_put (&lu->tgt->kref, release_sbp2_device); } -static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); - -/* FIXME: Loop over luns here. */ -static int sbp2_probe (struct device *dev) +static int sbp2_add_logical_unit (struct sbp2_target *tgt,int lun_entry) { -struct fw_unit *unit =fw_unit (dev); -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_target *tgt;struct sbp2_logical_unit *lu; -struct fw_csr_iterator ci; -int i, key, value, error; -u32 model, firmware_revision; - error = -ENOMEM ; - tgt =kzalloc (sizeof (*tgt),GFP_KERNEL ); -if (!tgt) - goto out_error; + lu =kmalloc (sizeof (*lu),GFP_KERNEL ); +if (!lu) +return -ENOMEM ; - unit->device.driver_data = tgt; - tgt->unit = unit; -kref_init (&tgt->kref); - tgt->starget_id =atomic_inc_return (&sbp2_starget_id); + lu->address_handler.length =0x100 ; + lu->address_handler.address_callback = sbp2_status_write; + lu->address_handler.callback_data = lu; - lu = tgt->lu; - lu->tgt = tgt; - lu->lun =0 ; +if (fw_core_add_address_handler (&lu->address_handler, + &fw_high_memory_region) <0 ) { +kfree (lu); +return -ENOMEM ; + } + + lu->tgt = tgt; + lu->sdev =NULL ; + lu->lun = lun_entry &0xffff ; + lu->retries =0 ;INIT_LIST_HEAD (&lu->orb_list); +INIT_DELAYED_WORK (&lu->work, sbp2_login); - lu->address_handler.length =0x100 ; - lu->address_handler.address_callback = sbp2_status_write; - lu->address_handler.callback_data = lu; +list_add_tail (&lu->tgt_list, &tgt->lu_list); +return 0 ; +} - error =fw_core_add_address_handler (&lu->address_handler, - &fw_high_memory_region); -if (error <0 ) - goto out_free; - - error =fw_device_enable_phys_dma (device); -if (error <0 ) - goto out_remove_address_handler; +static int sbp2_scan_logical_unit_dir (struct sbp2_target *tgt,u32 *directory) +{ +struct fw_csr_iterator ci; +int key, value; -/* -* Scan unit directory to get management agent address, -* firmware revison and model. Initialize firmware_revision -* and model to values that wont match anything in our table. -*/ - firmware_revision =0xff000000 ; - model =0xff000000 ; -fw_csr_iterator_init (&ci, unit->directory); +fw_csr_iterator_init (&ci, directory); +while (fw_csr_iterator_next (&ci, &key, &value)) +if (key ==SBP2_CSR_LOGICAL_UNIT_NUMBER && +sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +return 0 ; +} + +static int sbp2_scan_unit_dir (struct sbp2_target *tgt,u32 *directory, +u32 *model,u32 *firmware_revision) +{ +struct fw_device *dev =fw_device (tgt->unit->device.parent); +struct fw_csr_iterator ci; +int key, value; +u32 *subdir; + +fw_csr_iterator_init (&ci, directory);while (fw_csr_iterator_next (&ci, &key, &value)) {switch (key) { +case CSR_DEPENDENT_INFO |CSR_OFFSET : - tgt->management_agent_address = -0xfffff0000000ULL +4 * value; -break ; -case SBP2_FIRMWARE_REVISION : - firmware_revision = value; + tgt->management_agent_address + =0xfffff0000000ULL +4 * value;break ; +case CSR_MODEL : - model = value; + *model = value; +break ; + +case SBP2_CSR_FIRMWARE_REVISION : + *firmware_revision = value; +break ; + +case SBP2_CSR_LOGICAL_UNIT_NUMBER : +if (sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +break ; + +case SBP2_CSR_LOGICAL_UNIT_DIRECTORY : + subdir = ci.p + value; +if (subdir <= dev->config_rom +5 || + subdir >= dev->config_rom + dev->config_rom_length) +fw_error ("logical unit dir out of bounds\n" ); +else if (sbp2_scan_logical_unit_dir (tgt, subdir) <0 ) +return -ENOMEM ;break ; } } +return 0 ; +} + +static void sbp2_init_workarounds (struct sbp2_target *tgt,u32 model, +u32 firmware_revision) +{ +int i; + tgt->workarounds =0 ;for (i =0 ; i <ARRAY_SIZE (sbp2_workarounds_table); i++) {if (sbp2_workarounds_table[i].firmware_revision != (firmware_revision &0xffffff00 ))
@@ -701,8 +734,40 @@ static int sbp2_probe(struct device *devif (tgt->workarounds)fw_notify ("Workarounds for node %s: 0x%x " "(firmware_revision 0x%06x, model_id 0x%06x)\n" , - unit->device.bus_id, + tgt->unit->device.bus_id, tgt->workarounds, firmware_revision, model); +} + +static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); + +static int sbp2_probe (struct device *dev) +{ +struct fw_unit *unit =fw_unit (dev); +struct sbp2_target *tgt; +struct sbp2_logical_unit *lu; +u32 model, firmware_revision; + + tgt =kmalloc (sizeof (*tgt),GFP_KERNEL ); +if (!tgt) +return -ENOMEM ; + + unit->device.driver_data = tgt; + tgt->unit = unit; +kref_init (&tgt->kref); +INIT_LIST_HEAD (&tgt->lu_list); + +/* Initialize to values that won't match anything in our table. */ + model =0xff000000 ; + firmware_revision =0xff000000 ; +if (sbp2_scan_unit_dir (tgt, unit->directory, &model, + &firmware_revision) <0 ) + goto out; + +if (fw_device_enable_phys_dma (fw_device (unit->device.parent)) <0 ) + goto out; + +sbp2_init_workarounds (tgt, model, firmware_revision); + tgt->starget_id =atomic_inc_return (&sbp2_starget_id);get_device (&unit->device);
@@ -710,18 +775,15 @@ static int sbp2_probe(struct device *dev* We schedule work to do the login so we can easily reschedule retries. * Always get the ref when scheduling work. */ -INIT_DELAYED_WORK (&lu->work, sbp2_login); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); +list_for_each_entry (lu, &tgt->lu_list, tgt_list) +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref);return 0 ; + out: +kref_put (&tgt->kref, release_sbp2_device); - out_remove_address_handler: -fw_core_remove_address_handler (&lu->address_handler); - out_free: -kfree (tgt); - out_error: -return error; +return -ENOMEM ; }static int sbp2_remove (struct device *dev)
@@ -771,17 +833,18 @@ static void sbp2_reconnect(struct work_skref_put (&lu->tgt->kref, release_sbp2_device); } -/* FIXME: Loop over logical units */ static void sbp2_update (struct fw_unit *unit) { -struct fw_device *device =fw_device (unit->device.parent);struct sbp2_target *tgt = unit->device.driver_data; -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu; - lu->retries =0 ; -fw_device_enable_phys_dma (device); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); +fw_device_enable_phys_dma (fw_device (unit->device.parent)); + +list_for_each_entry (lu, &tgt->lu_list, tgt_list) { + lu->retries =0 ; +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref); + } }#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
Signature · 10 lines
Stefan Richter -=====-=-=== -=== ===-= http://arcgraph.de/sr/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
Re: [PATCH update 3/3] firewire: fw-sbp2: add support for multiple logical units per target
In reply to Stefan RichterQuoted 2 lines · Stefan Richter
This makes multiple logical units on a single target accessible to fw-sbp2. Successfully tested with the IOI FWB-IDE01AB dual LU bridge.
Very nice, this is good code. I have a couple of nitpicks below.
Quoted 14 lines
Signed-off-by Stefan Richter <[email protected]>---
update:
- dynamically append logical units in a list
- simplify config ROM parsingdrivers/firewire/fw-sbp2.c | 195 ++++++++++++++++++++++++------------- 1 file changed, 130 insertions(+), 65 deletions(-)Index:
linux/drivers/firewire/fw-sbp2.c
===================================================================
drivers/firewire/fw-sbp2.c static const char sbp2_driver_name[] = " · line 74
Quoted 4 lines
drivers/firewire/fw-sbp2.c +1
-0@@ -71,6 +71,7 @@ static const char sbp2_driver_name[] = "struct sbp2_logical_unit {struct sbp2_target *tgt; +struct list_head tgt_list;
I would call this link. I've consistently named all instances of struct list_head that are used as a list link either 'link' 'something_link'. I find that it's a helpful convention for figuring out/remembering whether the field is a list head or the link part of an element in a list.
drivers/firewire/fw-sbp2.c struct sbp2_target { · line 104
Quoted 9 lines
drivers/firewire/fw-sbp2.c +1
-1struct scsi_device *sdev;struct fw_address_handler address_handler;struct list_head orb_list;@@ -100,7 +101,7 @@ struct sbp2_target {unsigned workarounds;int starget_id; -struct sbp2_logical_unit lu[1 ]; +struct list_head lu_list;
The other convention I've used is to call fields of type struct list_head that are used as the head of a list 'something_list' so this is nicely in line with that.
Quoted 159 lines
drivers/firewire/fw-sbp2.c +65
-53};#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000@@ -113,7 +114,9 @@ struct sbp2_target {#define SBP2_DIRECTION_FROM_MEDIA 0x1/* Unit directory keys */ -#define SBP2_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_FIRMWARE_REVISION 0x3c +#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 +#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4/* Flags for detected oddities and brokeness */ #define SBP2_WORKAROUND_128K_MAX_TRANS 0x1@@ -531,18 +534,21 @@ static int sbp2_agent_reset(struct sbp2_return 0 ; } -/* FIXME: Loop over logical units */ static void release_sbp2_device (struct kref *kref) { struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref); -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu, *next; -if (lu->sdev) -scsi_remove_device (lu->sdev); +list_for_each_entry_safe (lu, next, &tgt->lu_list, tgt_list) { +if (lu->sdev) +scsi_remove_device (lu->sdev); -sbp2_send_management_orb (lu, tgt->node_id, lu->generation, -SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); -fw_core_remove_address_handler (&lu->address_handler); +sbp2_send_management_orb (lu, tgt->node_id, lu->generation, +SBP2_LOGOUT_REQUEST , lu->login_id,NULL ); +fw_core_remove_address_handler (&lu->address_handler); +list_del (&lu->tgt_list); +kfree (lu); + }fw_notify ("removed sbp2 unit %s\n" , tgt->unit->device.bus_id);put_device (&tgt->unit->device);kfree (tgt);@@ -623,70 +629,122 @@ static void sbp2_login(struct work_struckref_put (&lu->tgt->kref, release_sbp2_device); } -static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); - -/* FIXME: Loop over luns here. */ -static int sbp2_probe (struct device *dev) +static int sbp2_add_logical_unit (struct sbp2_target *tgt,int lun_entry) { -struct fw_unit *unit =fw_unit (dev); -struct fw_device *device =fw_device (unit->device.parent); -struct sbp2_target *tgt;struct sbp2_logical_unit *lu; -struct fw_csr_iterator ci; -int i, key, value, error; -u32 model, firmware_revision; - error = -ENOMEM ; - tgt =kzalloc (sizeof (*tgt),GFP_KERNEL ); -if (!tgt) - goto out_error; + lu =kmalloc (sizeof (*lu),GFP_KERNEL ); +if (!lu) +return -ENOMEM ; - unit->device.driver_data = tgt; - tgt->unit = unit; -kref_init (&tgt->kref); - tgt->starget_id =atomic_inc_return (&sbp2_starget_id); + lu->address_handler.length =0x100 ; + lu->address_handler.address_callback = sbp2_status_write; + lu->address_handler.callback_data = lu; + +if (fw_core_add_address_handler (&lu->address_handler, + &fw_high_memory_region) <0 ) { +kfree (lu); +return -ENOMEM ; + } - lu = tgt->lu; - lu->tgt = tgt; - lu->lun =0 ; + lu->tgt = tgt; + lu->sdev =NULL ; + lu->lun = lun_entry &0xffff ; + lu->retries =0 ;INIT_LIST_HEAD (&lu->orb_list); +INIT_DELAYED_WORK (&lu->work, sbp2_login); - lu->address_handler.length =0x100 ; - lu->address_handler.address_callback = sbp2_status_write; - lu->address_handler.callback_data = lu; +list_add_tail (&lu->tgt_list, &tgt->lu_list); +return 0 ; +} - error =fw_core_add_address_handler (&lu->address_handler, - &fw_high_memory_region); -if (error <0 ) - goto out_free; +static int sbp2_scan_logical_unit_dir (struct sbp2_target *tgt,u32 *directory) +{ +struct fw_csr_iterator ci; +int key, value; + +fw_csr_iterator_init (&ci, directory); +while (fw_csr_iterator_next (&ci, &key, &value)) +if (key ==SBP2_CSR_LOGICAL_UNIT_NUMBER && +sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +return 0 ; +} - error =fw_device_enable_phys_dma (device); -if (error <0 ) - goto out_remove_address_handler; +static int sbp2_scan_unit_dir (struct sbp2_target *tgt,u32 *directory, +u32 *model,u32 *firmware_revision) +{ +struct fw_device *dev =fw_device (tgt->unit->device.parent); +struct fw_csr_iterator ci; +int key, value; +u32 *subdir; -/* -* Scan unit directory to get management agent address, -* firmware revison and model. Initialize firmware_revision -* and model to values that wont match anything in our table. -*/ - firmware_revision =0xff000000 ; - model =0xff000000 ; -fw_csr_iterator_init (&ci, unit->directory); +fw_csr_iterator_init (&ci, directory);while (fw_csr_iterator_next (&ci, &key, &value)) {switch (key) { +case CSR_DEPENDENT_INFO |CSR_OFFSET : - tgt->management_agent_address = -0xfffff0000000ULL +4 * value; -break ; -case SBP2_FIRMWARE_REVISION : - firmware_revision = value; + tgt->management_agent_address + =0xfffff0000000ULL +4 * value;break ; +case CSR_MODEL : - model = value; + *model = value; +break ; + +case SBP2_CSR_FIRMWARE_REVISION : + *firmware_revision = value; +break ; +
drivers/firewire/fw-sbp2.c static void sbp2_login(struct work_struc · line 708
Quoted 10 lines
drivers/firewire/fw-sbp2.c +10
-0+case SBP2_CSR_LOGICAL_UNIT_NUMBER : +if (sbp2_add_logical_unit (tgt, value) <0 ) +return -ENOMEM ; +break ; + +case SBP2_CSR_LOGICAL_UNIT_DIRECTORY : + subdir = ci.p + value; +if (subdir <= dev->config_rom +5 || + subdir >= dev->config_rom + dev->config_rom_length) +fw_error ("logical unit dir out of bounds\n" );
This check isn't necessary, read_bus_info_block ensures that all blocks read are within the config rom area.
Quoted 105 lines
drivers/firewire/fw-sbp2.c +53
-12+else if (sbp2_scan_logical_unit_dir (tgt, subdir) <0 ) +return -ENOMEM ;break ; } } +return 0 ; +} + +static atomic_t sbp2_starget_id =ATOMIC_INIT (-1 ); + +static int sbp2_probe (struct device *dev) +{ +struct fw_unit *unit =fw_unit (dev); +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_target *tgt; +struct sbp2_logical_unit *lu, *next; +int i; +u32 model, firmware_revision; + + tgt =kmalloc (sizeof (*tgt),GFP_KERNEL ); +if (!tgt) + goto out_error; + + unit->device.driver_data = tgt; + tgt->unit = unit; +kref_init (&tgt->kref); +INIT_LIST_HEAD (&tgt->lu_list); + +/* Initialize to values that won't match anything in our table. */ + model = ~0 ; + firmware_revision = ~0 ; +if (sbp2_scan_unit_dir (tgt, unit->directory, &model, + &firmware_revision) <0 ) + goto out_free; + +if (fw_device_enable_phys_dma (device) <0 ) + goto out_free; + tgt->workarounds =0 ;for (i =0 ; i <ARRAY_SIZE (sbp2_workarounds_table); i++) {if (sbp2_workarounds_table[i].firmware_revision != (firmware_revision &0xffffff00 ))@@ -704,24 +762,29 @@ static int sbp2_probe(struct device *dev unit->device.bus_id, tgt->workarounds, firmware_revision, model); + tgt->starget_id =atomic_inc_return (&sbp2_starget_id);get_device (&unit->device);/* * We schedule work to do the login so we can easily reschedule retries. * Always get the ref when scheduling work. */ -INIT_DELAYED_WORK (&lu->work, sbp2_login); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); +list_for_each_entry (lu, &tgt->lu_list, tgt_list) +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref);return 0 ; - out_remove_address_handler: -fw_core_remove_address_handler (&lu->address_handler); out_free: +list_for_each_entry_safe (lu, next, &tgt->lu_list, tgt_list) { +fw_core_remove_address_handler (&lu->address_handler); +list_del (&lu->tgt_list); +kfree (lu); + }kfree (tgt); + out_error: -return error; +return -ENOMEM ; }static int sbp2_remove (struct device *dev)@@ -771,17 +834,19 @@ static void sbp2_reconnect(struct work_skref_put (&lu->tgt->kref, release_sbp2_device); } -/* FIXME: Loop over logical units */ static void sbp2_update (struct fw_unit *unit) {struct fw_device *device =fw_device (unit->device.parent);struct sbp2_target *tgt = unit->device.driver_data; -struct sbp2_logical_unit *lu = tgt->lu; +struct sbp2_logical_unit *lu; - lu->retries =0 ;fw_device_enable_phys_dma (device); -if (schedule_delayed_work (&lu->work,0 )) -kref_get (&tgt->kref); + +list_for_each_entry (lu, &tgt->lu_list, tgt_list) { + lu->retries =0 ; +if (schedule_delayed_work (&lu->work,0 )) +kref_get (&tgt->kref); + } }#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e --
Quoted 3 lines
Stefan Richter
-=====-=-=== -=== ===-=
http://arcgraph.de/sr/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
Re: [PATCH update 3/3] firewire: fw-sbp2: add support for multiple logical units per target
Quoted 10 lines · Kristian Høgsberg
Quoted 3 lines · Stefan Richter
struct sbp2_logical_unit { struct sbp2_target *tgt;+ struct
list_headtgt_list;I would call this link. I've consistently named all instances of struct
list_headthat are used as a list link either 'link' 'something_link'. I find that it's a helpful convention for figuring out/remembering whether the field is a list head or the link part of an element in a list.
Yes, it's a good convention. I somehow missed the pattern.
Quoted 8 lines
drivers/firewire/fw-sbp2.c static void sbp2_login(struct work_struc · line 708
Quoted 5 lines
drivers/firewire/fw-sbp2.c +5
-0+case SBP2_CSR_LOGICAL_UNIT_DIRECTORY : + subdir = ci.p + value; +if (subdir <= dev->config_rom +5 || + subdir >= dev->config_rom + dev->config_rom_length) +fw_error ("logical unit dir out of bounds\n" );This check isn't necessary,
read_bus_info_blockensures that all blocks read are within the config rom area.
Right, fw_device_init fetched the directory for us, so we have it. #-)
Signature · 9 lines
Stefan Richter -=====-=-=== -=== ===== http://arcgraph.de/sr/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/