diff options
Diffstat (limited to 'drivers/firewire/fw-device.c')
-rw-r--r-- | drivers/firewire/fw-device.c | 203 |
1 files changed, 121 insertions, 82 deletions
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index bf53acb45652..a47e2129d83d 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c | |||
@@ -18,22 +18,26 @@ | |||
18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/module.h> | 21 | #include <linux/ctype.h> |
22 | #include <linux/wait.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/kthread.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
23 | #include <linux/device.h> | ||
24 | #include <linux/errno.h> | ||
27 | #include <linux/idr.h> | 25 | #include <linux/idr.h> |
28 | #include <linux/jiffies.h> | 26 | #include <linux/jiffies.h> |
29 | #include <linux/string.h> | 27 | #include <linux/kobject.h> |
28 | #include <linux/list.h> | ||
29 | #include <linux/mutex.h> | ||
30 | #include <linux/rwsem.h> | 30 | #include <linux/rwsem.h> |
31 | #include <linux/semaphore.h> | 31 | #include <linux/semaphore.h> |
32 | #include <linux/spinlock.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/workqueue.h> | ||
35 | |||
32 | #include <asm/system.h> | 36 | #include <asm/system.h> |
33 | #include <linux/ctype.h> | 37 | |
34 | #include "fw-transaction.h" | ||
35 | #include "fw-topology.h" | ||
36 | #include "fw-device.h" | 38 | #include "fw-device.h" |
39 | #include "fw-topology.h" | ||
40 | #include "fw-transaction.h" | ||
37 | 41 | ||
38 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 * p) | 42 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 * p) |
39 | { | 43 | { |
@@ -132,8 +136,7 @@ static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size) | |||
132 | vendor, model, specifier_id, version); | 136 | vendor, model, specifier_id, version); |
133 | } | 137 | } |
134 | 138 | ||
135 | static int | 139 | static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env) |
136 | fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
137 | { | 140 | { |
138 | struct fw_unit *unit = fw_unit(dev); | 141 | struct fw_unit *unit = fw_unit(dev); |
139 | char modalias[64]; | 142 | char modalias[64]; |
@@ -152,27 +155,6 @@ struct bus_type fw_bus_type = { | |||
152 | }; | 155 | }; |
153 | EXPORT_SYMBOL(fw_bus_type); | 156 | EXPORT_SYMBOL(fw_bus_type); |
154 | 157 | ||
155 | static void fw_device_release(struct device *dev) | ||
156 | { | ||
157 | struct fw_device *device = fw_device(dev); | ||
158 | struct fw_card *card = device->card; | ||
159 | unsigned long flags; | ||
160 | |||
161 | /* | ||
162 | * Take the card lock so we don't set this to NULL while a | ||
163 | * FW_NODE_UPDATED callback is being handled or while the | ||
164 | * bus manager work looks at this node. | ||
165 | */ | ||
166 | spin_lock_irqsave(&card->lock, flags); | ||
167 | device->node->data = NULL; | ||
168 | spin_unlock_irqrestore(&card->lock, flags); | ||
169 | |||
170 | fw_node_put(device->node); | ||
171 | kfree(device->config_rom); | ||
172 | kfree(device); | ||
173 | fw_card_put(card); | ||
174 | } | ||
175 | |||
176 | int fw_device_enable_phys_dma(struct fw_device *device) | 158 | int fw_device_enable_phys_dma(struct fw_device *device) |
177 | { | 159 | { |
178 | int generation = device->generation; | 160 | int generation = device->generation; |
@@ -191,8 +173,8 @@ struct config_rom_attribute { | |||
191 | u32 key; | 173 | u32 key; |
192 | }; | 174 | }; |
193 | 175 | ||
194 | static ssize_t | 176 | static ssize_t show_immediate(struct device *dev, |
195 | show_immediate(struct device *dev, struct device_attribute *dattr, char *buf) | 177 | struct device_attribute *dattr, char *buf) |
196 | { | 178 | { |
197 | struct config_rom_attribute *attr = | 179 | struct config_rom_attribute *attr = |
198 | container_of(dattr, struct config_rom_attribute, attr); | 180 | container_of(dattr, struct config_rom_attribute, attr); |
@@ -223,8 +205,8 @@ show_immediate(struct device *dev, struct device_attribute *dattr, char *buf) | |||
223 | #define IMMEDIATE_ATTR(name, key) \ | 205 | #define IMMEDIATE_ATTR(name, key) \ |
224 | { __ATTR(name, S_IRUGO, show_immediate, NULL), key } | 206 | { __ATTR(name, S_IRUGO, show_immediate, NULL), key } |
225 | 207 | ||
226 | static ssize_t | 208 | static ssize_t show_text_leaf(struct device *dev, |
227 | show_text_leaf(struct device *dev, struct device_attribute *dattr, char *buf) | 209 | struct device_attribute *dattr, char *buf) |
228 | { | 210 | { |
229 | struct config_rom_attribute *attr = | 211 | struct config_rom_attribute *attr = |
230 | container_of(dattr, struct config_rom_attribute, attr); | 212 | container_of(dattr, struct config_rom_attribute, attr); |
@@ -293,10 +275,9 @@ static struct config_rom_attribute config_rom_attributes[] = { | |||
293 | TEXT_LEAF_ATTR(hardware_version_name, CSR_HARDWARE_VERSION), | 275 | TEXT_LEAF_ATTR(hardware_version_name, CSR_HARDWARE_VERSION), |
294 | }; | 276 | }; |
295 | 277 | ||
296 | static void | 278 | static void init_fw_attribute_group(struct device *dev, |
297 | init_fw_attribute_group(struct device *dev, | 279 | struct device_attribute *attrs, |
298 | struct device_attribute *attrs, | 280 | struct fw_attribute_group *group) |
299 | struct fw_attribute_group *group) | ||
300 | { | 281 | { |
301 | struct device_attribute *attr; | 282 | struct device_attribute *attr; |
302 | int i, j; | 283 | int i, j; |
@@ -319,9 +300,8 @@ init_fw_attribute_group(struct device *dev, | |||
319 | dev->groups = group->groups; | 300 | dev->groups = group->groups; |
320 | } | 301 | } |
321 | 302 | ||
322 | static ssize_t | 303 | static ssize_t modalias_show(struct device *dev, |
323 | modalias_show(struct device *dev, | 304 | struct device_attribute *attr, char *buf) |
324 | struct device_attribute *attr, char *buf) | ||
325 | { | 305 | { |
326 | struct fw_unit *unit = fw_unit(dev); | 306 | struct fw_unit *unit = fw_unit(dev); |
327 | int length; | 307 | int length; |
@@ -332,9 +312,8 @@ modalias_show(struct device *dev, | |||
332 | return length + 1; | 312 | return length + 1; |
333 | } | 313 | } |
334 | 314 | ||
335 | static ssize_t | 315 | static ssize_t rom_index_show(struct device *dev, |
336 | rom_index_show(struct device *dev, | 316 | struct device_attribute *attr, char *buf) |
337 | struct device_attribute *attr, char *buf) | ||
338 | { | 317 | { |
339 | struct fw_device *device = fw_device(dev->parent); | 318 | struct fw_device *device = fw_device(dev->parent); |
340 | struct fw_unit *unit = fw_unit(dev); | 319 | struct fw_unit *unit = fw_unit(dev); |
@@ -349,8 +328,8 @@ static struct device_attribute fw_unit_attributes[] = { | |||
349 | __ATTR_NULL, | 328 | __ATTR_NULL, |
350 | }; | 329 | }; |
351 | 330 | ||
352 | static ssize_t | 331 | static ssize_t config_rom_show(struct device *dev, |
353 | config_rom_show(struct device *dev, struct device_attribute *attr, char *buf) | 332 | struct device_attribute *attr, char *buf) |
354 | { | 333 | { |
355 | struct fw_device *device = fw_device(dev); | 334 | struct fw_device *device = fw_device(dev); |
356 | size_t length; | 335 | size_t length; |
@@ -363,8 +342,8 @@ config_rom_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
363 | return length; | 342 | return length; |
364 | } | 343 | } |
365 | 344 | ||
366 | static ssize_t | 345 | static ssize_t guid_show(struct device *dev, |
367 | guid_show(struct device *dev, struct device_attribute *attr, char *buf) | 346 | struct device_attribute *attr, char *buf) |
368 | { | 347 | { |
369 | struct fw_device *device = fw_device(dev); | 348 | struct fw_device *device = fw_device(dev); |
370 | int ret; | 349 | int ret; |
@@ -383,8 +362,8 @@ static struct device_attribute fw_device_attributes[] = { | |||
383 | __ATTR_NULL, | 362 | __ATTR_NULL, |
384 | }; | 363 | }; |
385 | 364 | ||
386 | static int | 365 | static int read_rom(struct fw_device *device, |
387 | read_rom(struct fw_device *device, int generation, int index, u32 *data) | 366 | int generation, int index, u32 *data) |
388 | { | 367 | { |
389 | int rcode; | 368 | int rcode; |
390 | 369 | ||
@@ -539,7 +518,7 @@ static int read_bus_info_block(struct fw_device *device, int generation) | |||
539 | 518 | ||
540 | kfree(old_rom); | 519 | kfree(old_rom); |
541 | ret = 0; | 520 | ret = 0; |
542 | device->cmc = rom[2] & 1 << 30; | 521 | device->cmc = rom[2] >> 30 & 1; |
543 | out: | 522 | out: |
544 | kfree(rom); | 523 | kfree(rom); |
545 | 524 | ||
@@ -679,11 +658,53 @@ static void fw_device_shutdown(struct work_struct *work) | |||
679 | fw_device_put(device); | 658 | fw_device_put(device); |
680 | } | 659 | } |
681 | 660 | ||
661 | static void fw_device_release(struct device *dev) | ||
662 | { | ||
663 | struct fw_device *device = fw_device(dev); | ||
664 | struct fw_card *card = device->card; | ||
665 | unsigned long flags; | ||
666 | |||
667 | /* | ||
668 | * Take the card lock so we don't set this to NULL while a | ||
669 | * FW_NODE_UPDATED callback is being handled or while the | ||
670 | * bus manager work looks at this node. | ||
671 | */ | ||
672 | spin_lock_irqsave(&card->lock, flags); | ||
673 | device->node->data = NULL; | ||
674 | spin_unlock_irqrestore(&card->lock, flags); | ||
675 | |||
676 | fw_node_put(device->node); | ||
677 | kfree(device->config_rom); | ||
678 | kfree(device); | ||
679 | fw_card_put(card); | ||
680 | } | ||
681 | |||
682 | static struct device_type fw_device_type = { | 682 | static struct device_type fw_device_type = { |
683 | .release = fw_device_release, | 683 | .release = fw_device_release, |
684 | }; | 684 | }; |
685 | 685 | ||
686 | static void fw_device_update(struct work_struct *work); | 686 | static int update_unit(struct device *dev, void *data) |
687 | { | ||
688 | struct fw_unit *unit = fw_unit(dev); | ||
689 | struct fw_driver *driver = (struct fw_driver *)dev->driver; | ||
690 | |||
691 | if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) { | ||
692 | down(&dev->sem); | ||
693 | driver->update(unit); | ||
694 | up(&dev->sem); | ||
695 | } | ||
696 | |||
697 | return 0; | ||
698 | } | ||
699 | |||
700 | static void fw_device_update(struct work_struct *work) | ||
701 | { | ||
702 | struct fw_device *device = | ||
703 | container_of(work, struct fw_device, work.work); | ||
704 | |||
705 | fw_device_cdev_update(device); | ||
706 | device_for_each_child(&device->device, NULL, update_unit); | ||
707 | } | ||
687 | 708 | ||
688 | /* | 709 | /* |
689 | * If a device was pending for deletion because its node went away but its | 710 | * If a device was pending for deletion because its node went away but its |
@@ -735,12 +756,50 @@ static int lookup_existing_device(struct device *dev, void *data) | |||
735 | return match; | 756 | return match; |
736 | } | 757 | } |
737 | 758 | ||
759 | enum { BC_UNKNOWN = 0, BC_UNIMPLEMENTED, BC_IMPLEMENTED, }; | ||
760 | |||
761 | void fw_device_set_broadcast_channel(struct fw_device *device, int generation) | ||
762 | { | ||
763 | struct fw_card *card = device->card; | ||
764 | __be32 data; | ||
765 | int rcode; | ||
766 | |||
767 | if (!card->broadcast_channel_allocated) | ||
768 | return; | ||
769 | |||
770 | if (device->bc_implemented == BC_UNKNOWN) { | ||
771 | rcode = fw_run_transaction(card, TCODE_READ_QUADLET_REQUEST, | ||
772 | device->node_id, generation, device->max_speed, | ||
773 | CSR_REGISTER_BASE + CSR_BROADCAST_CHANNEL, | ||
774 | &data, 4); | ||
775 | switch (rcode) { | ||
776 | case RCODE_COMPLETE: | ||
777 | if (data & cpu_to_be32(1 << 31)) { | ||
778 | device->bc_implemented = BC_IMPLEMENTED; | ||
779 | break; | ||
780 | } | ||
781 | /* else fall through to case address error */ | ||
782 | case RCODE_ADDRESS_ERROR: | ||
783 | device->bc_implemented = BC_UNIMPLEMENTED; | ||
784 | } | ||
785 | } | ||
786 | |||
787 | if (device->bc_implemented == BC_IMPLEMENTED) { | ||
788 | data = cpu_to_be32(BROADCAST_CHANNEL_INITIAL | | ||
789 | BROADCAST_CHANNEL_VALID); | ||
790 | fw_run_transaction(card, TCODE_WRITE_QUADLET_REQUEST, | ||
791 | device->node_id, generation, device->max_speed, | ||
792 | CSR_REGISTER_BASE + CSR_BROADCAST_CHANNEL, | ||
793 | &data, 4); | ||
794 | } | ||
795 | } | ||
796 | |||
738 | static void fw_device_init(struct work_struct *work) | 797 | static void fw_device_init(struct work_struct *work) |
739 | { | 798 | { |
740 | struct fw_device *device = | 799 | struct fw_device *device = |
741 | container_of(work, struct fw_device, work.work); | 800 | container_of(work, struct fw_device, work.work); |
742 | struct device *revived_dev; | 801 | struct device *revived_dev; |
743 | int minor, err; | 802 | int minor, ret; |
744 | 803 | ||
745 | /* | 804 | /* |
746 | * All failure paths here set node->data to NULL, so that we | 805 | * All failure paths here set node->data to NULL, so that we |
@@ -776,12 +835,12 @@ static void fw_device_init(struct work_struct *work) | |||
776 | 835 | ||
777 | fw_device_get(device); | 836 | fw_device_get(device); |
778 | down_write(&fw_device_rwsem); | 837 | down_write(&fw_device_rwsem); |
779 | err = idr_pre_get(&fw_device_idr, GFP_KERNEL) ? | 838 | ret = idr_pre_get(&fw_device_idr, GFP_KERNEL) ? |
780 | idr_get_new(&fw_device_idr, device, &minor) : | 839 | idr_get_new(&fw_device_idr, device, &minor) : |
781 | -ENOMEM; | 840 | -ENOMEM; |
782 | up_write(&fw_device_rwsem); | 841 | up_write(&fw_device_rwsem); |
783 | 842 | ||
784 | if (err < 0) | 843 | if (ret < 0) |
785 | goto error; | 844 | goto error; |
786 | 845 | ||
787 | device->device.bus = &fw_bus_type; | 846 | device->device.bus = &fw_bus_type; |
@@ -828,6 +887,8 @@ static void fw_device_init(struct work_struct *work) | |||
828 | device->config_rom[3], device->config_rom[4], | 887 | device->config_rom[3], device->config_rom[4], |
829 | 1 << device->max_speed); | 888 | 1 << device->max_speed); |
830 | device->config_rom_retries = 0; | 889 | device->config_rom_retries = 0; |
890 | |||
891 | fw_device_set_broadcast_channel(device, device->generation); | ||
831 | } | 892 | } |
832 | 893 | ||
833 | /* | 894 | /* |
@@ -851,29 +912,6 @@ static void fw_device_init(struct work_struct *work) | |||
851 | put_device(&device->device); /* our reference */ | 912 | put_device(&device->device); /* our reference */ |
852 | } | 913 | } |
853 | 914 | ||
854 | static int update_unit(struct device *dev, void *data) | ||
855 | { | ||
856 | struct fw_unit *unit = fw_unit(dev); | ||
857 | struct fw_driver *driver = (struct fw_driver *)dev->driver; | ||
858 | |||
859 | if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) { | ||
860 | down(&dev->sem); | ||
861 | driver->update(unit); | ||
862 | up(&dev->sem); | ||
863 | } | ||
864 | |||
865 | return 0; | ||
866 | } | ||
867 | |||
868 | static void fw_device_update(struct work_struct *work) | ||
869 | { | ||
870 | struct fw_device *device = | ||
871 | container_of(work, struct fw_device, work.work); | ||
872 | |||
873 | fw_device_cdev_update(device); | ||
874 | device_for_each_child(&device->device, NULL, update_unit); | ||
875 | } | ||
876 | |||
877 | enum { | 915 | enum { |
878 | REREAD_BIB_ERROR, | 916 | REREAD_BIB_ERROR, |
879 | REREAD_BIB_GONE, | 917 | REREAD_BIB_GONE, |
@@ -894,7 +932,7 @@ static int reread_bus_info_block(struct fw_device *device, int generation) | |||
894 | if (i == 0 && q == 0) | 932 | if (i == 0 && q == 0) |
895 | return REREAD_BIB_GONE; | 933 | return REREAD_BIB_GONE; |
896 | 934 | ||
897 | if (i > device->config_rom_length || q != device->config_rom[i]) | 935 | if (q != device->config_rom[i]) |
898 | return REREAD_BIB_CHANGED; | 936 | return REREAD_BIB_CHANGED; |
899 | } | 937 | } |
900 | 938 | ||
@@ -1004,6 +1042,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event) | |||
1004 | device->node = fw_node_get(node); | 1042 | device->node = fw_node_get(node); |
1005 | device->node_id = node->node_id; | 1043 | device->node_id = node->node_id; |
1006 | device->generation = card->generation; | 1044 | device->generation = card->generation; |
1045 | mutex_init(&device->client_list_mutex); | ||
1007 | INIT_LIST_HEAD(&device->client_list); | 1046 | INIT_LIST_HEAD(&device->client_list); |
1008 | 1047 | ||
1009 | /* | 1048 | /* |