firewire: 2 simple updates + 2 ABI additions: PHY packet tx/rx
cover firewire: 2 simple updates + 2 ABI additions: PHY packet tx/rx
Coming as replies:
[PATCH 1/4] firewire: cdev: some clarifications to the API documentation [PATCH 2/4] firewire: core: use C99 initializer in array of ioctl handlers [PATCH 3/4 RFC] firewire: cdev: add PHY packet transmission [PATCH 4/4 RFC] firewire: cdev: add PHY packet reception
drivers/firewire/core-card.c | 1 drivers/firewire/core-cdev.c | 179 ++++++++++++++++++++++++++++++------ drivers/firewire/core-transaction.c | 5 + drivers/firewire/core.h | 2 drivers/firewire/ohci.c | 3 include/linux/firewire-cdev.h | 98 ++++++++++++++++++- include/linux/firewire.h | 3 7 files changed, 254 insertions(+), 37 deletions(-)
A libraw1394 backend counterpart to patch 3/4 will be posted to linux1394-devel. It can be tested with firecontrol.
A simple test tool for patch 4/4 will be posted to linux1394-devel too.
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
PATCH 1/4 firewire: cdev: some clarifications to the API documentation
Response events:
- are generated on more occasions than their documentation claimed.
Bus resets:
- Note that FW_CDEV_IOC_INITIATE_BUS_RESET is nonblocking and that the client is not required to observe a grace period since kernels 2.6.36+ will enforce it now (commit 02d37bed).
- The possible values of fw_cdev_initiate_bus_reset.type are listed in the kerneldoc comment already.
- Clarify that an application that uses FW_CDEV_IOC_ADD_DESCRIPTOR and FW_CDEV_IOC_REMOVE_DESCRIPTOR does not have to issue a bus reset.
Isochronous I/O contexts:
- At most one can be created per open file descriptor.
--- include/linux/firewire-cdev.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
include/linux/firewire-cdev.h +22 -7
@@ -89,8 +89,9 @@ struct fw_cdev_event_bus_reset {/** * struct fw_cdev_event_response - Sent when a response packet was received -* @closure: See &fw_cdev_event_common; -* set by %FW_CDEV_IOC_SEND_REQUEST ioctl +* @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST +* or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST +* or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE * @rcode: Response code returned by the remote node * @length: Data length, i.e. the response's payload size in bytes
@@ -100,6 +101,11 @@ struct fw_cdev_event_bus_reset {* sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses * carrying data (read and lock responses) follows immediately and can be * accessed through the @data field. +* +* The event is also generated after conclusions of transactions that do not +* involve response packets. This includes unified write transactions, +* broadcast write transactions, and transmission of asynchronous stream +* packets. @rcode indicates success or failure of such transmissions. */ struct fw_cdev_event_response {__u64 closure;
@@ -480,9 +486,14 @@ struct fw_cdev_deallocate {* Initiate a bus reset for the bus this device is on. The bus reset can be * either the original (long) bus reset or the arbitrated (short) bus reset * introduced in 1394a-2000. +* +* The ioctl returns immediately. A subsequent &fw_cdev_event_bus_reset +* indicates when the reset actually happened. Since ABI v4, this may be +* considerably later than the ioctl because the kernel ensures a grace period +* between subsequent bus resets as per IEEE 1394 bus management specification. */ struct fw_cdev_initiate_bus_reset { -__u32 type;/* FW_CDEV_SHORT_RESET or FW_CDEV_LONG_RESET */ +__u32 type; };/**
@@ -506,9 +517,10 @@ struct fw_cdev_initiate_bus_reset {* * @immediate, @key, and @data array elements are CPU-endian quadlets. * -* If successful, the kernel adds the descriptor and writes back a handle to the -* kernel-side object to be used for later removal of the descriptor block and -* immediate key. +* If successful, the kernel adds the descriptor and writes back a @handle to +* the kernel-side object to be used for later removal of the descriptor block +* and immediate key. The kernel will also generate a bus reset to signal the +* change of the configuration ROM to other nodes. * * This ioctl affects the configuration ROMs of all local nodes. * The ioctl only succeeds on device files which represent a local node.
@@ -527,7 +539,8 @@ struct fw_cdev_add_descriptor {* descriptor was added * * Remove a descriptor block and accompanying immediate key from the local -* nodes' configuration ROMs. +* nodes' configuration ROMs. The kernel will also generate a bus reset to +* signal the change of the configuration ROM to other nodes. */ struct fw_cdev_remove_descriptor {__u32 handle;
@@ -559,6 +572,8 @@ struct fw_cdev_remove_descriptor {* * Note that the effect of a @header_size > 4 depends on * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt. +* +* No more than one iso context can be created per fd. */ struct fw_cdev_create_iso_context {__u32 type;
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
PATCH 1/4 firewire: cdev: some clarifications to the API documentation
Response events:
- are generated on more occasions than their documentation claimed.
CSR allocation:
- An already occupied CSR can be determined from errno==EBUSY.
Bus resets:
- Note that FW_CDEV_IOC_INITIATE_BUS_RESET is nonblocking and that the client is not required to observe a grace period since kernels 2.6.36+ will enforce it now (commit 02d37bed).
- The possible values of fw_cdev_initiate_bus_reset.type are listed in the kerneldoc comment already.
- Clarify that an application that uses FW_CDEV_IOC_ADD_DESCRIPTOR and FW_CDEV_IOC_REMOVE_DESCRIPTOR does not have to issue a bus reset.
Isochronous I/O contexts:
- At most one can be created per open file descriptor.
---
Update: Added the occupied CSR == EBUSY sentence.
include/linux/firewire-cdev.h | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
include/linux/firewire-cdev.h +25 -8
@@ -89,8 +89,9 @@ struct fw_cdev_event_bus_reset {/** * struct fw_cdev_event_response - Sent when a response packet was received -* @closure: See &fw_cdev_event_common; -* set by %FW_CDEV_IOC_SEND_REQUEST ioctl +* @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST +* or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST +* or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE * @rcode: Response code returned by the remote node * @length: Data length, i.e. the response's payload size in bytes
@@ -100,6 +101,11 @@ struct fw_cdev_event_bus_reset {* sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses * carrying data (read and lock responses) follows immediately and can be * accessed through the @data field. +* +* The event is also generated after conclusions of transactions that do not +* involve response packets. This includes unified write transactions, +* broadcast write transactions, and transmission of asynchronous stream +* packets. @rcode indicates success or failure of such transmissions. */ struct fw_cdev_event_response {__u64 closure;
@@ -452,7 +458,9 @@ struct fw_cdev_send_response {* range to be used for later deallocation of the range. * * The address range is allocated on all local nodes. The address allocation -* is exclusive except for the FCP command and response registers. +* is exclusive except for the FCP command and response registers. If an +* exclusive address region is already in use, the ioctl fails with errno set +* to %EBUSY. */ struct fw_cdev_allocate {__u64 offset;
@@ -480,9 +488,14 @@ struct fw_cdev_deallocate {* Initiate a bus reset for the bus this device is on. The bus reset can be * either the original (long) bus reset or the arbitrated (short) bus reset * introduced in 1394a-2000. +* +* The ioctl returns immediately. A subsequent &fw_cdev_event_bus_reset +* indicates when the reset actually happened. Since ABI v4, this may be +* considerably later than the ioctl because the kernel ensures a grace period +* between subsequent bus resets as per IEEE 1394 bus management specification. */ struct fw_cdev_initiate_bus_reset { -__u32 type;/* FW_CDEV_SHORT_RESET or FW_CDEV_LONG_RESET */ +__u32 type; };/**
@@ -506,9 +519,10 @@ struct fw_cdev_initiate_bus_reset {* * @immediate, @key, and @data array elements are CPU-endian quadlets. * -* If successful, the kernel adds the descriptor and writes back a handle to the -* kernel-side object to be used for later removal of the descriptor block and -* immediate key. +* If successful, the kernel adds the descriptor and writes back a @handle to +* the kernel-side object to be used for later removal of the descriptor block +* and immediate key. The kernel will also generate a bus reset to signal the +* change of the configuration ROM to other nodes. * * This ioctl affects the configuration ROMs of all local nodes. * The ioctl only succeeds on device files which represent a local node.
@@ -527,7 +541,8 @@ struct fw_cdev_add_descriptor {* descriptor was added * * Remove a descriptor block and accompanying immediate key from the local -* nodes' configuration ROMs. +* nodes' configuration ROMs. The kernel will also generate a bus reset to +* signal the change of the configuration ROM to other nodes. */ struct fw_cdev_remove_descriptor {__u32 handle;
@@ -559,6 +574,8 @@ struct fw_cdev_remove_descriptor {* * Note that the effect of a @header_size > 4 depends on * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt. +* +* No more than one iso context can be created per fd. */ struct fw_cdev_create_iso_context {__u32 type;
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---= http://arcgraph.de/sr/
PATCH 2/4 firewire: core: use C99 initializer in array of ioctl handlers
In reply to Stefan Richterto make the correspondence of ioctl numbers and handlers more obvious.
--- drivers/firewire/core-cdev.c | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/firewire/core-cdev.c +21 -21
@@ -1386,27 +1386,27 @@ static int ioctl_send_stream_packet(stru }static int (*const ioctl_handlers[])(struct client *,union ioctl_arg *) = { - ioctl_get_info, - ioctl_send_request, - ioctl_allocate, - ioctl_deallocate, - ioctl_send_response, - ioctl_initiate_bus_reset, - ioctl_add_descriptor, - ioctl_remove_descriptor, - ioctl_create_iso_context, - ioctl_queue_iso, - ioctl_start_iso, - ioctl_stop_iso, - ioctl_get_cycle_timer, - ioctl_allocate_iso_resource, - ioctl_deallocate_iso_resource, - ioctl_allocate_iso_resource_once, - ioctl_deallocate_iso_resource_once, - ioctl_get_speed, - ioctl_send_broadcast_request, - ioctl_send_stream_packet, - ioctl_get_cycle_timer2, + [0x00 ] = ioctl_get_info, + [0x01 ] = ioctl_send_request, + [0x02 ] = ioctl_allocate, + [0x03 ] = ioctl_deallocate, + [0x04 ] = ioctl_send_response, + [0x05 ] = ioctl_initiate_bus_reset, + [0x06 ] = ioctl_add_descriptor, + [0x07 ] = ioctl_remove_descriptor, + [0x08 ] = ioctl_create_iso_context, + [0x09 ] = ioctl_queue_iso, + [0x0a ] = ioctl_start_iso, + [0x0b ] = ioctl_stop_iso, + [0x0c ] = ioctl_get_cycle_timer, + [0x0d ] = ioctl_allocate_iso_resource, + [0x0e ] = ioctl_deallocate_iso_resource, + [0x0f ] = ioctl_allocate_iso_resource_once, + [0x10 ] = ioctl_deallocate_iso_resource_once, + [0x11 ] = ioctl_get_speed, + [0x12 ] = ioctl_send_broadcast_request, + [0x13 ] = ioctl_send_stream_packet, + [0x14 ] = ioctl_get_cycle_timer2, }; static int dispatch_ioctl(struct client *client,
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
RFC PATCH 3/4 firewire: cdev: add PHY packet transmission
In reply to Stefan RichterAdd an FW_CDEV_IOC_SEND_PHY_PACKET ioctl() for /dev/fw* which can be used to implement bus management related functionality in userspace.
This is also half of the functionality (the transmit part) that is needed to support a userspace implementation of a VersaPHY transaction layer.
Safety considerations:
- PHY packets are generally broadcasts and may have interesting effects on PHYs and the bus, e.g. make asynchronous arbitration impossible due to too low gap count. Hence some kind of elevated privileges should be required of a process to be able to send PHY packets. This implementation assumes that a process that is allowed to open the /dev/fw* of a local node does have this privilege.
There was an inconclusive discussion about introducing POSIX capabilities as a means to check for user privileges for these kinds of operations.
- The kernel does not check integrity of the supplied packet data. That would be far too much code, considering the many kinds of PHY packets. A process which got the privilege to send these packets is trusted to do it correctly.
Just like with the other "send packet" ioctls, a non-blocking API is chosen; i.e. the ioctl may return even before AT DMA started. After transmission, an event for poll()/read() is enqueued. Most users are going to need a blocking API, but a blocking userspace wrapper is easy to implement, and the second of the two existing libraw1394 calls raw1394_phy_packet_write() and raw1394_start_phy_packet_write() can be better supported that way.
--- drivers/firewire/core-cdev.c | 64 ++++++++++++++++++++++++++++++++++ include/linux/firewire-cdev.h | 44 +++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-)
drivers/firewire/core-cdev.c +64 -0
@@ -195,6 +195,13 @@ struct iso_resource_event {struct fw_cdev_event_iso_resource iso_resource; }; +struct outbound_phy_packet_event { +struct event event; +struct client *client; +struct fw_packet p; +struct fw_cdev_event_phy_packet phy_packet; +}; +static inline void __user *u64_to_uptr (__u64 value) {return (void __user *)(unsigned long )value;
@@ -397,6 +404,7 @@ union ioctl_arg {struct fw_cdev_allocate_iso_resource allocate_iso_resource;struct fw_cdev_send_stream_packet send_stream_packet;struct fw_cdev_get_cycle_timer2 get_cycle_timer2; +struct fw_cdev_send_phy_packet send_phy_packet; };static int ioctl_get_info (struct client *client,union ioctl_arg *arg)
@@ -1385,6 +1393,61 @@ static int ioctl_send_stream_packet(strureturn init_request (client, &request, dest, a->speed); } +static void outbound_phy_packet_callback (struct fw_packet *packet, +struct fw_card *card,int status) +{ +struct outbound_phy_packet_event *e = + container_of(packet, struct outbound_phy_packet_event, p); + +switch (status) { +/* expected: */ +case ACK_COMPLETE : e->phy_packet.rcode =RCODE_COMPLETE ;break ; +/* should never happen with PHY packets: */ +case ACK_PENDING : e->phy_packet.rcode =RCODE_COMPLETE ;break ; +case ACK_BUSY_X : +case ACK_BUSY_A : +case ACK_BUSY_B : e->phy_packet.rcode =RCODE_BUSY ;break ; +case ACK_DATA_ERROR : e->phy_packet.rcode =RCODE_DATA_ERROR ;break ; +case ACK_TYPE_ERROR : e->phy_packet.rcode =RCODE_TYPE_ERROR ;break ; +/* stale generation; cancelled; on certain controllers: no ack */ +default : e->phy_packet.rcode = status;break ; + } + +queue_event (e->client, &e->event, + &e->phy_packet,sizeof (e->phy_packet),NULL ,0 ); +client_put (e->client); +} + +static int ioctl_send_phy_packet (struct client *client,union ioctl_arg *arg) +{ +struct fw_cdev_send_phy_packet *a = &arg->send_phy_packet; +struct fw_card *card = client->device->card; +struct outbound_phy_packet_event *e; + +/* Access policy: Allow this ioctl only on local nodes' device files. */ +if (!client->device->is_local) +return -ENOSYS ; + + e =kzalloc (sizeof (*e),GFP_KERNEL ); +if (e ==NULL ) +return -ENOMEM ; + +client_get (client); + e->client = client; + e->p.speed =SCODE_100 ; + e->p.generation = a->generation; + e->p.header[0 ] = a->data[0 ]; + e->p.header[1 ] = a->data[1 ]; + e->p.header_length =8 ; + e->p.callback = outbound_phy_packet_callback; + e->phy_packet.closure = a->closure; + e->phy_packet.type =FW_CDEV_EVENT_PHY_PACKET_SENT ; + + card->driver->send_request (card, &e->p); + +return 0 ; +} +static int (*const ioctl_handlers[])(struct client *,union ioctl_arg *) = { [0x00 ] = ioctl_get_info, [0x01 ] = ioctl_send_request,
@@ -1407,6 +1470,7 @@ static int (* const ioctl_handlers[])(st [0x12] = ioctl_send_broadcast_request, [0x13] = ioctl_send_stream_packet, [0x14] = ioctl_get_cycle_timer2, + [0x15] = ioctl_send_phy_packet, }; static int dispatch_ioctl(struct client *client,
include/linux/firewire-cdev.h +43 -1
85 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
RFC PATCH 4/4 firewire: cdev: add PHY packet reception
In reply to Stefan RichterAdd an FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl() and FW_CDEV_EVENT_PHY_PACKET_RECEIVED poll()/read() event for /dev/fw*. This can be used to get information from remote PHYs by remote access PHY packets.
This is also the 2nd half of the functionality (the receive part) to support a userspace implementation of a VersaPHY transaction layer.
Safety considerations:
- PHY packets are generally broadcasts, hence some kind of elevated privileges should be required of a process to be able to listen in on PHY packets. This implementation assumes that a process that is allowed to open the /dev/fw* of a local node does have this privilege.
There was an inconclusive discussion about introducing POSIX capabilities as a means to check for user privileges for these kinds of operations.
Other limitations:
- PHY packet reception may be switched on by ioctl() but cannot be switched off again. It would be trivial to provide an off switch, but this is not worth the code. The client should simply close() the fd then, or just ignore further events.
- For sake of simplicity of API and kernel-side implementation, no filter per packet content is provided.
--- drivers/firewire/core-card.c | 1 + drivers/firewire/core-cdev.c | 73 ++++++++++++++++++++++++++-- drivers/firewire/core-transaction.c | 5 ++ drivers/firewire/core.h | 2 + drivers/firewire/ohci.c | 3 - include/linux/firewire-cdev.h | 39 ++++++++++++--- include/linux/firewire.h | 3 + 7 files changed, 111 insertions(+), 15 deletions(-)
drivers/firewire/core-card.c +1 -0
@@ -514,6 +514,7 @@ void fw_card_initialize(struct fw_card *kref_init (&card->kref);init_completion (&card->done);INIT_LIST_HEAD (&card->transaction_list); +INIT_LIST_HEAD (&card->phy_receiver_list);spin_lock_init (&card->lock); card->local_node =NULL ;
drivers/firewire/core-cdev.c +68 -5
135 lines not on this page · raw message
drivers/firewire/core-transaction.c +5 -0
@@ -880,6 +880,11 @@ void fw_core_handle_request(struct fw_caif (p->ack !=ACK_PENDING && p->ack !=ACK_COMPLETE )return ; +if (TCODE_IS_LINK_INTERNAL (HEADER_GET_TCODE (p->header[0 ]))) { +fw_cdev_handle_phy_packet (card, p); +return ; + } + request =allocate_request (card, p);if (request ==NULL ) {/* FIXME: send statically allocated busy packet. */
drivers/firewire/core.h +2 -0
@@ -128,6 +128,7 @@ extern const struct file_operations fw_dvoid fw_device_cdev_update (struct fw_device *device);void fw_device_cdev_remove (struct fw_device *device); +void fw_cdev_handle_phy_packet (struct fw_card *card,struct fw_packet *p);/* -device */
@@ -214,6 +215,7 @@ static inline bool is_next_generation(in#define TCODE_IS_READ_REQUEST (tcode) (((tcode) & ~1) == 4)#define TCODE_IS_BLOCK_PACKET (tcode) (((tcode) & 1) != 0) +#define TCODE_IS_LINK_INTERNAL (tcode) ((tcode) == 0xe)#define TCODE_IS_REQUEST (tcode) (((tcode) & 2) == 0)#define TCODE_IS_RESPONSE (tcode) (((tcode) & 2) != 0)#define TCODE_HAS_REQUEST_DATA (tcode) (((tcode) & 12) != 4)
drivers/firewire/ohci.c +1 -2
@@ -1764,10 +1764,9 @@ static int ohci_enable(struct fw_card *c OHCI1394_HCControl_noByteSwapData);reg_write (ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus); -reg_write (ohci, OHCI1394_LinkControlClear, - OHCI1394_LinkControl_rcvPhyPkt);reg_write (ohci, OHCI1394_LinkControlSet, OHCI1394_LinkControl_rcvSelfID | + OHCI1394_LinkControl_rcvPhyPkt | OHCI1394_LinkControl_cycleTimerEnable | OHCI1394_LinkControl_cycleMaster);
include/linux/firewire-cdev.h +32 -7
@@ -40,6 +40,7 @@/* available since kernel version 2.6.36 */ #define FW_CDEV_EVENT_REQUEST2 0x06#define FW_CDEV_EVENT_PHY_PACKET_SENT 0x07 +#define FW_CDEV_EVENT_PHY_PACKET_RECEIVED 0x08/** * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
@@ -290,16 +291,24 @@ struct fw_cdev_event_iso_resource { };/** -* struct fw_cdev_event_phy_packet - A PHY packet was transmitted -* @closure: See &fw_cdev_event_common; -* set by %FW_CDEV_IOC_SEND_PHY_PACKET ioctl -* @type: %FW_CDEV_EVENT_PHY_PACKET_SENT +* struct fw_cdev_event_phy_packet - A PHY packet was transmitted or received +* @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET +* or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl +* @type: %FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED * @rcode: %RCODE_..., indicates success or failure of transmission +* @length: Data length in bytes +* @data: Incoming data +* +* If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty. +* If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data +* consists of the two PHY packet quadlets, in host byte order. */ struct fw_cdev_event_phy_packet {__u64 closure;__u32 type;__u32 rcode; +__u32 length; +__u32 data[0 ]; };/**
@@ -313,7 +322,9 @@ struct fw_cdev_event_phy_packet {* @iso_resource: Valid if @common.type == * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED -* @phy_packet: Valid if @common.type == %FW_CDEV_EVENT_PHY_PACKET_SENT +* @phy_packet: Valid if @common.type == +* %FW_CDEV_EVENT_PHY_PACKET_SENT or +* %FW_CDEV_EVENT_PHY_PACKET_RECEIVED * * Convenience union for userspace use. Events could be read(2) into an * appropriately aligned char buffer and then cast to this union for further
@@ -365,6 +376,7 @@ union fw_cdev_event {/* available since kernel version 2.6.36 */ #define FW_CDEV_IOC_SEND_PHY_PACKET _IOWR('#', 0x15, struct fw_cdev_send_phy_packet) +#define FW_CDEV_IOC_RECEIVE_PHY_PACKETS _IOW('#', 0x16, struct fw_cdev_receive_phy_packets)/* * ABI version history
@@ -381,9 +393,9 @@ union fw_cdev_event {* - shared use and auto-response for FCP registers * 3 (2.6.34) - made &fw_cdev_get_cycle_timer reliable * - added %FW_CDEV_IOC_GET_CYCLE_TIMER2 -* 4 (2.6.36) - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_SENT +* 4 (2.6.36) - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_* * - implemented &fw_cdev_event_bus_reset.bm_node_id -* - added %FW_CDEV_IOC_SEND_PHY_PACKET +* - added %FW_CDEV_IOC_SEND_PHY_PACKET, _RECEIVE_PHY_PACKETS */ #define FW_CDEV_VERSION 3/* Meaningless; don't use this macro. */
@@ -853,4 +865,17 @@ struct fw_cdev_send_phy_packet { __u32 generation; }; +/** +* struct fw_cdev_receive_phy_packets - start reception of PHY packets +* @closure: Passed back to userspace in phy packet events +* +* This ioctl activates issuing of %FW_CDEV_EVENT_PHY_PACKET_RECEIVED due to +* incoming PHY packets from any node on the same bus as the device. +* +* The ioctl is only permitted on device files which represent a local node. +*/ +struct fw_cdev_receive_phy_packets { +__u64 closure; +}; +#endif /* _LINUX_FIREWIRE_CDEV_H */
include/linux/firewire.h +2 -1
@@ -111,9 +111,10 @@ struct fw_card {bool beta_repeaters_present;int index; -struct list_head link; +struct list_head phy_receiver_list; +struct delayed_work br_work;/* bus reset job */ bool br_short;
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
PATCH 1/1 Implement raw1394_(start_)phy_packet_write() on new firewire backend
In reply to Stefan RichterRequires kernel 2.6.36 or newer at runtime and linux-headers 2.6.36 or newer at build time.
--- src/dispatch.c | 2 +- src/fw.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++-------- src/fw.h | 6 ++-- 3 files changed, 81 insertions(+), 18 deletions(-)
src/dispatch.c +1 -1
@@ -287,7 +287,7 @@ int raw1394_phy_packet_write (raw1394handle_t handle, quadlet_t data)return -1 ; }if (handle->is_fw) -return fw_phy_packet_write (handle->mode.fw, data); +return fw_phy_packet_write (handle, data);else return ieee1394_phy_packet_write (handle, data); }
src/fw.c +77 -14
115 lines not on this page · raw message
src/fw.h +3 -3
@@ -159,9 +159,6 @@ int fw_arm_get_buf(fw_handle_t handle, nodeaddr_t start, size_t length, void *buf);int fw_echo_request (fw_handle_t handle,quadlet_t data);int fw_wake_up (fw_handle_t handle); -int fw_phy_packet_write (fw_handle_t handle,quadlet_t data); -int fw_start_phy_packet_write (fw_handle_t handle, -quadlet_t data,unsigned long tag);int fw_start_read (fw_handle_t handle,nodeid_t node,nodeaddr_t addr,size_t length,quadlet_t *buffer,unsigned long tag); int fw_start_write(fw_handle_t handle, nodeid_t node, nodeaddr_t addr,
@@ -176,6 +173,8 @@ int fw_start_async_stream(fw_handle_t handle, unsigned int channel, unsigned int tag, unsigned int sy, unsigned int speed, size_t length, quadlet_t *data, unsigned long rawtag); +int fw_start_phy_packet_write (fw_handle_t handle, +quadlet_t data,unsigned long tag); int fw_start_async_send(fw_handle_t handle, size_t length, size_t header_length, unsigned int expect_response,
@@ -193,6 +192,7 @@ int fw_lock64(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,int fw_async_stream (raw1394handle_t handle,unsigned int channel,unsigned int tag,unsigned int sy,unsigned int speed,size_t length,quadlet_t *data); +int fw_phy_packet_write (raw1394handle_t handle,quadlet_t data); int fw_async_send(fw_handle_t handle, size_t length, size_t header_length, unsigned int expect_response,
Signature · 7 lines
1.7.1 -- Stefan Richter -=====-==-=- -=== =---- http://arcgraph.de/sr/
[PATCH 5/4 RFC] firewire: cdev: add PHY pinging
In reply to Stefan RichterThis extends the FW_CDEV_IOC_SEND_PHY_PACKET ioctl() for /dev/fw* to be useful for ping time measurements. One application for it would be gap count optimization in userspace that is based on ping times rather than hop count. (The latter is implemented in firewire-core itself but is not applicable to beta PHYs that act as repeater.)
---
A simple test tool will be posted at linux1394-devel.
drivers/firewire/core-cdev.c | 9 ++++++--- drivers/firewire/core.h | 5 +++++ drivers/firewire/ohci.c | 4 ++++ include/linux/firewire-cdev.h | 5 ++++- 4 files changed, 19 insertions(+), 4 deletions(-)
drivers/firewire/core-cdev.c +6 -3
@@ -1424,9 +1424,10 @@ static void outbound_phy_packet_callback/* stale generation; cancelled; on certain controllers: no ack */ default : e->phy_packet.rcode = status;break ; } + e->phy_packet.data[0 ] = packet->timestamp; -queue_event (e->client, &e->event, - &e->phy_packet,sizeof (e->phy_packet),NULL ,0 ); +queue_event (e->client, &e->event, &e->phy_packet, +sizeof (e->phy_packet) + e->phy_packet.length,NULL ,0 );client_put (e->client); }
@@ -1440,7 +1441,7 @@ static int ioctl_send_phy_packet(structif (!client->device->is_local)return -ENOSYS ; - e =kzalloc (sizeof (*e),GFP_KERNEL ); + e =kzalloc (sizeof (*e) +4 ,GFP_KERNEL );if (e ==NULL )return -ENOMEM ;
@@ -1454,6 +1455,8 @@ static int ioctl_send_phy_packet(struct e->p.callback = outbound_phy_packet_callback; e->phy_packet.closure = a->closure; e->phy_packet.type =FW_CDEV_EVENT_PHY_PACKET_SENT ; +if (is_ping_packet (a->data)) + e->phy_packet.length =4 ; card->driver->send_request (card, &e->p);
drivers/firewire/core.h +5 -0
@@ -234,4 +234,9 @@ void fw_fill_response(struct fw_packet *void fw_send_phy_config (struct fw_card *card,int node_id,int generation,int gap_count); +static inline bool is_ping_packet (u32 *data) +{ +return (data[0 ] &0xc0ffffff ) ==0 && ~data[0 ] == data[1 ]; +} +#endif /* _FIREWIRE_CORE_H */
drivers/firewire/ohci.c +4 -0
@@ -1105,6 +1105,10 @@ static int at_context_queue_packet(struc }else { last = &d[0 ]; z =2 ; + +if (packet->header_length ==8 && +is_ping_packet (packet->header)) + last->control |=cpu_to_le16 (DESCRIPTOR_PING ); } last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST |
include/linux/firewire-cdev.h +4 -1
@@ -299,7 +299,10 @@ struct fw_cdev_event_iso_resource {* @length: Data length in bytes * @data: Incoming data * -* If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty. +* If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty, +* except in case of a ping packet: Then, @length is 4, and @data[0] is the +* ping time in 49.152MHz clocks if @rcode is %RCODE_COMPLETE. +* * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data * consists of the two PHY packet quadlets, in host byte order. */
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =---= http://arcgraph.de/sr/
PHY pinging test tool
/*
* Ping packet transmission test
*
* Usage:
* - Compile with "gcc test-phy-pinging.c". * - Run with "sudo ./a.out /dev/fw*". * - It will print the ping time to all PHYs and exit.
*/
#include <fcntl.h>
#include <linux/firewire-cdev.h>
#include <poll.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
static const char *rcode_to_str(int rcode)
{
switch (rcode) {
case RCODE_COMPLETE: return "complete";
case RCODE_CONFLICT_ERROR: return "conflict error";
case RCODE_DATA_ERROR: return "data error";
case RCODE_TYPE_ERROR: return "type error";
case RCODE_ADDRESS_ERROR: return "address error";
case RCODE_SEND_ERROR: return "send error";
case RCODE_CANCELLED: return "cancelled";
case RCODE_BUSY: return "busy";
case RCODE_GENERATION: return "generation";
case RCODE_NO_ACK: return "no ack";
}
return "unknown";
}static void read_events(int fd)
{
char buffer[sizeof(struct fw_cdev_event_phy_packet) + 4];
struct fw_cdev_event_common *ec = (void *)buffer;
struct fw_cdev_event_phy_packet *epp = (void *)buffer;
ssize_t s = sizeof buffer;
struct pollfd pfd = {
.fd = fd,
.events = POLLIN | POLLHUP,
};
while (poll(&pfd, 1, 10) > 0) {
memset(buffer, 0, s);
s = read(fd, buffer, sizeof buffer);
if (s < 0) {
fprintf(stderr, "Failed read: %m\n");
return;
}
switch (ec->type) {
case FW_CDEV_EVENT_PHY_PACKET_SENT:
if (epp->rcode == RCODE_COMPLETE)
printf("PING - phy_id = %d, data = %08x (%.2f us)\n",
(int)epp->closure,
epp->data[0], epp->data[0] / 49.152);
else
printf("PING - phy_id = %d, rcode = %s\n",
(int)epp->closure,
rcode_to_str(epp->rcode));
break;
}
}
}static void cooked_ioctl(int fd, int req, void *arg)
{
if (ioctl(fd, req, arg) < 0)
fprintf(stderr, "Failed ioctl '%c' 0x%02x: %m\n",
_IOC_TYPE(req), _IOC_NR(req));
}void test_phy_pinging(const char *filename)
{
__u32 rom[5];
struct fw_cdev_event_bus_reset reset;
struct fw_cdev_get_info info = {
.version = 4,
.rom = (unsigned long)rom,
.rom_length = sizeof(rom),
.bus_reset = (unsigned long)&reset,
};
struct fw_cdev_send_phy_packet p;
int fd, ln, nn, i;
fd = open(filename, O_RDWR);
if (fd < 0) {
fprintf(stderr, "Failed to open %s: %m\n", filename);
goto out;
}
cooked_ioctl(fd, FW_CDEV_IOC_GET_INFO, &info);
if (reset.node_id != reset.local_node_id) {
fprintf(stderr, "%s: Not a local node\n", filename);
goto out_fd;
}
p.generation = reset.generation;
ln = reset.local_node_id & 63;
nn = (reset.root_node_id & 63) + 1;
printf("%s: card %d, generation %d, %d nodes, "
"local phy_id %d, EUI-64 %08x%08x\n",
filename, info.card, reset.generation,
nn, ln, rom[3], rom[4]);
for (i = 0; i < nn; i++) {
p.closure = i;
p.data[0] = i << 24;
p.data[1] = ~p.data[0];
cooked_ioctl(fd, FW_CDEV_IOC_SEND_PHY_PACKET, &p);
}
read_events(fd);
out_fd:
close(fd);
out:
printf("\n");
}int main(int argc, char **argv)
{
int i;
if (argc < 2) {
fprintf(stderr, "Usage: %s /dev/fwX [/dev/fwY ...]\n", argv[0]);
return 1;
}
for (i = 1; i < argc; i++)
test_phy_pinging(argv[i]);
return 0;
}Re: [PATCH 5/4 RFC] firewire: cdev: add PHY pinging
In reply to Stefan Richterdrivers/firewire/ohci.c static int at_context_queue_packet(struc · line 1114
Quoted 13 lines · Stefan Richter
drivers/firewire/ohci.c +4
-0@@ -1105,6 +1105,10 @@ static int at_context_queue_packet(struc }else { last = &d[0 ]; z =2 ; + +if (packet->header_length ==8 && +is_ping_packet (packet->header)) + last->control |=cpu_to_le16 (DESCRIPTOR_PING ); } last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST |
Here is a better implementation of the card driver's part. It moves the ping packet test out of an else branch that is taken for all no-payload packets into a switch block that is only reached in case of PHY packets.
drivers/firewire/ohci.c +3 -0
@@ -1068,6 +1068,9 @@ static int at_context_queue_packet(struc header[1 ] =cpu_to_le32 (packet->header[0 ]); header[2 ] =cpu_to_le32 (packet->header[1 ]); d[0 ].req_count =cpu_to_le16 (12 ); + +if (is_ping_packet (packet->header)) + d[0 ].control |=cpu_to_le16 (DESCRIPTOR_PING );break ;case 4 :
Signature · 3 lines
Stefan Richter -=====-==-=- -=== =--=- http://arcgraph.de/sr/