Message ID | 1422285768-1655-1-git-send-email-simon.farnsworth@onelan.co.uk (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > their I2C over AUX implementation. They work fine with Windows, but fail > with Linux. > > It turns out that they cannot keep an I2C transaction open unless the > previous read was 16 bytes; shorter reads can only be followed by a zero > byte transfer ending the I2C transaction. > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > reply, assume that there's a hardware bottleneck, and shrink our read size > to match. > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > --- > > v2 changes, after feedback from Thierry and Ville: > > * Handle short replies. I've decided (arbitrarily) that a short reply > results in us dropping back to the newly chosen size for the rest of this > I2C transaction. Thus, given an attempt to read the first 16 bytes of > EDID, and a sink that only does 4 bytes of buffering, we will see the > following AUX transfers for the EDID read (after address is set): > > <set address, block etc> > Read 16 bytes from I2C over AUX. > Reply with 4 bytes > Read 4 bytes > Reply with 4 bytes > Read 4 bytes > Reply with 4 bytes > Read 4 bytes > Reply with 4 bytes > <end I2C transaction> I think that's agaisnt the spec. IIRC you have to keep repeating the same transaction (meaning address/len are unchanged) until all the data was transferred. > Note that I've not looked at MST support - I have neither the DP 1.2 spec > nor any MST branch devices, so I can't test anything I write or check it > against a spec. It looks from the code, however, as if MST has the branch > device do the split from a big request into small transactions. > > drivers/gpu/drm/drm_dp_helper.c | 42 ++++++++++++++++++++++------------------- > include/drm/drm_dp_helper.h | 5 +++++ > 2 files changed, 28 insertions(+), 19 deletions(-) > > diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c > index 79968e3..701b201 100644 > --- a/drivers/gpu/drm/drm_dp_helper.c > +++ b/drivers/gpu/drm/drm_dp_helper.c > @@ -396,11 +396,13 @@ static u32 drm_dp_i2c_functionality(struct i2c_adapter *adapter) > * retrying the transaction as appropriate. It is assumed that the > * aux->transfer function does not modify anything in the msg other than the > * reply field. > + * > + * Returns bytes transferred on success, or a negative error code on failure. > */ > static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > { > unsigned int retry; > - int err; > + int ret; > > /* > * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device > @@ -409,14 +411,14 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > */ > for (retry = 0; retry < 7; retry++) { > mutex_lock(&aux->hw_mutex); > - err = aux->transfer(aux, msg); > + ret = aux->transfer(aux, msg); > mutex_unlock(&aux->hw_mutex); > - if (err < 0) { > - if (err == -EBUSY) > + if (ret < 0) { > + if (ret == -EBUSY) > continue; > > - DRM_DEBUG_KMS("transaction failed: %d\n", err); > - return err; > + DRM_DEBUG_KMS("transaction failed: %d\n", ret); > + return ret; > } > > > @@ -457,9 +459,7 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > * Both native ACK and I2C ACK replies received. We > * can assume the transfer was successful. > */ > - if (err < msg->size) > - return -EPROTO; > - return 0; > + return ret; > > case DP_AUX_I2C_REPLY_NACK: > DRM_DEBUG_KMS("I2C nack\n"); > @@ -487,6 +487,7 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, > { > struct drm_dp_aux *aux = adapter->algo_data; > unsigned int i, j; > + int transfer_size = DP_AUX_MAX_PAYLOAD_BYTES; > struct drm_dp_aux_msg msg; > int err = 0; > > @@ -507,20 +508,23 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, > err = drm_dp_i2c_do_msg(aux, &msg); > if (err < 0) > break; > - /* > - * Many hardware implementations support FIFOs larger than a > - * single byte, but it has been empirically determined that > - * transferring data in larger chunks can actually lead to > - * decreased performance. Therefore each message is simply > - * transferred byte-by-byte. > + /* Bizlink designed DP->DVI-D Dual Link adapters require the > + * I2C over AUX packets to be as large as possible. If not, > + * the I2C transactions never succeed. > + * > + * We therefore start by requesting 16 byte transfers. If > + * the hardware gives us a partial ACK, we stick to the new > + * smaller size from the partial ACK. > */ > - for (j = 0; j < msgs[i].len; j++) { > + for (j = 0; j < msgs[i].len; j += transfer_size) { > msg.buffer = msgs[i].buf + j; > - msg.size = 1; > + msg.size = min(transfer_size, msgs[i].len - j); > > - err = drm_dp_i2c_do_msg(aux, &msg); > - if (err < 0) > + transfer_size = drm_dp_i2c_do_msg(aux, &msg); > + if (transfer_size <= 0) { > + err = transfer_size == 0 ? -EPROTO : transfer_size; > break; > + } > } > if (err < 0) > break; > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > index 11f8c84..444d51b 100644 > --- a/include/drm/drm_dp_helper.h > +++ b/include/drm/drm_dp_helper.h > @@ -42,6 +42,8 @@ > * 1.2 formally includes both eDP and DPI definitions. > */ > > +#define DP_AUX_MAX_PAYLOAD_BYTES 16 > + > #define DP_AUX_I2C_WRITE 0x0 > #define DP_AUX_I2C_READ 0x1 > #define DP_AUX_I2C_STATUS 0x2 > @@ -519,6 +521,9 @@ struct drm_dp_aux_msg { > * transactions. The drm_dp_aux_register_i2c_bus() function registers an > * I2C adapter that can be passed to drm_probe_ddc(). Upon removal, drivers > * should call drm_dp_aux_unregister_i2c_bus() to remove the I2C adapter. > + * The I2C adapter uses long transfers by default; if a partial response is > + * received, the adapter will drop down to the size given by the partial > + * response for this transaction only. > * > * Note that the aux helper code assumes that the .transfer() function > * only modifies the reply field of the drm_dp_aux_msg structure. The > -- > 2.1.0
On Monday 26 January 2015 17:33:35 Ville Syrjälä wrote: > On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > > their I2C over AUX implementation. They work fine with Windows, but fail > > with Linux. > > > > It turns out that they cannot keep an I2C transaction open unless the > > previous read was 16 bytes; shorter reads can only be followed by a zero > > byte transfer ending the I2C transaction. > > > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > > reply, assume that there's a hardware bottleneck, and shrink our read size > > to match. > > > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > > --- > > > > v2 changes, after feedback from Thierry and Ville: > > > > * Handle short replies. I've decided (arbitrarily) that a short reply > > results in us dropping back to the newly chosen size for the rest of this > > I2C transaction. Thus, given an attempt to read the first 16 bytes of > > EDID, and a sink that only does 4 bytes of buffering, we will see the > > following AUX transfers for the EDID read (after address is set): > > > > <set address, block etc> > > Read 16 bytes from I2C over AUX. > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > <end I2C transaction> > > I think that's agaisnt the spec. IIRC you have to keep repeating the > same transaction (meaning address/len are unchanged) until all the data > was transferred. > Do you have a spec reference against the DisplayPort 1.1a (last public version) spec? My chosen behaviour matches Table 2-50 in the 1.1a spec. I can't see anything in section 2.4.5 (I2C over AUX) that prohibits me from changing the length or address mid-transaction, and there is text that says that when the address changes without the source clearing the MOT bit, the sink should do an I2C Repeated Start to change address. The length is never supplied to the I2C bus - it's purely an artifact of DisplayPort. > > Note that I've not looked at MST support - I have neither the DP 1.2 spec > > nor any MST branch devices, so I can't test anything I write or check it > > against a spec. It looks from the code, however, as if MST has the branch > > device do the split from a big request into small transactions. > > --snip code--
On Mon, Jan 26, 2015 at 05:33:35PM +0200, Ville Syrjälä wrote: > On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > > their I2C over AUX implementation. They work fine with Windows, but fail > > with Linux. > > > > It turns out that they cannot keep an I2C transaction open unless the > > previous read was 16 bytes; shorter reads can only be followed by a zero > > byte transfer ending the I2C transaction. > > > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > > reply, assume that there's a hardware bottleneck, and shrink our read size > > to match. > > > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > > --- > > > > v2 changes, after feedback from Thierry and Ville: > > > > * Handle short replies. I've decided (arbitrarily) that a short reply > > results in us dropping back to the newly chosen size for the rest of this > > I2C transaction. Thus, given an attempt to read the first 16 bytes of > > EDID, and a sink that only does 4 bytes of buffering, we will see the > > following AUX transfers for the EDID read (after address is set): > > > > <set address, block etc> > > Read 16 bytes from I2C over AUX. > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > Read 4 bytes > > Reply with 4 bytes > > <end I2C transaction> > > I think that's agaisnt the spec. IIRC you have to keep repeating the > same transaction (meaning address/len are unchanged) until all the data > was transferred. Actually for an i2c read it seems you can specify the same len or reduce the len by the amount you already received. Reducing seems more approriate as the spec goes to state that when repeating the the message with the original length the sink is likely to read more i2c data than will be needed. Althoguh maybe it can buffer it so that if the original amount of data was more than 16 bytes we might get the answer to the next message quicker. So maybe we should just keep updating the length with 'min(16, total_bytes - total_bytes_received)' ? For writes we don't seem to do anything correctly atm. When getting a defer or ack w/ M value we should issue a I2C_WRITE_STATUS_UPDATE command to prompt the sink to report back with an update M value. Currently we seem to just retry with the same write message. > > > Note that I've not looked at MST support - I have neither the DP 1.2 spec > > nor any MST branch devices, so I can't test anything I write or check it > > against a spec. It looks from the code, however, as if MST has the branch > > device do the split from a big request into small transactions. > > > > drivers/gpu/drm/drm_dp_helper.c | 42 ++++++++++++++++++++++------------------- > > include/drm/drm_dp_helper.h | 5 +++++ > > 2 files changed, 28 insertions(+), 19 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c > > index 79968e3..701b201 100644 > > --- a/drivers/gpu/drm/drm_dp_helper.c > > +++ b/drivers/gpu/drm/drm_dp_helper.c > > @@ -396,11 +396,13 @@ static u32 drm_dp_i2c_functionality(struct i2c_adapter *adapter) > > * retrying the transaction as appropriate. It is assumed that the > > * aux->transfer function does not modify anything in the msg other than the > > * reply field. > > + * > > + * Returns bytes transferred on success, or a negative error code on failure. > > */ > > static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > > { > > unsigned int retry; > > - int err; > > + int ret; > > > > /* > > * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device > > @@ -409,14 +411,14 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > > */ > > for (retry = 0; retry < 7; retry++) { > > mutex_lock(&aux->hw_mutex); > > - err = aux->transfer(aux, msg); > > + ret = aux->transfer(aux, msg); > > mutex_unlock(&aux->hw_mutex); > > - if (err < 0) { > > - if (err == -EBUSY) > > + if (ret < 0) { > > + if (ret == -EBUSY) > > continue; > > > > - DRM_DEBUG_KMS("transaction failed: %d\n", err); > > - return err; > > + DRM_DEBUG_KMS("transaction failed: %d\n", ret); > > + return ret; > > } > > > > > > @@ -457,9 +459,7 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) > > * Both native ACK and I2C ACK replies received. We > > * can assume the transfer was successful. > > */ > > - if (err < msg->size) > > - return -EPROTO; > > - return 0; > > + return ret; > > > > case DP_AUX_I2C_REPLY_NACK: > > DRM_DEBUG_KMS("I2C nack\n"); > > @@ -487,6 +487,7 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, > > { > > struct drm_dp_aux *aux = adapter->algo_data; > > unsigned int i, j; > > + int transfer_size = DP_AUX_MAX_PAYLOAD_BYTES; > > struct drm_dp_aux_msg msg; > > int err = 0; > > > > @@ -507,20 +508,23 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, > > err = drm_dp_i2c_do_msg(aux, &msg); > > if (err < 0) > > break; > > - /* > > - * Many hardware implementations support FIFOs larger than a > > - * single byte, but it has been empirically determined that > > - * transferring data in larger chunks can actually lead to > > - * decreased performance. Therefore each message is simply > > - * transferred byte-by-byte. > > + /* Bizlink designed DP->DVI-D Dual Link adapters require the > > + * I2C over AUX packets to be as large as possible. If not, > > + * the I2C transactions never succeed. > > + * > > + * We therefore start by requesting 16 byte transfers. If > > + * the hardware gives us a partial ACK, we stick to the new > > + * smaller size from the partial ACK. > > */ > > - for (j = 0; j < msgs[i].len; j++) { > > + for (j = 0; j < msgs[i].len; j += transfer_size) { > > msg.buffer = msgs[i].buf + j; > > - msg.size = 1; > > + msg.size = min(transfer_size, msgs[i].len - j); > > > > - err = drm_dp_i2c_do_msg(aux, &msg); > > - if (err < 0) > > + transfer_size = drm_dp_i2c_do_msg(aux, &msg); > > + if (transfer_size <= 0) { > > + err = transfer_size == 0 ? -EPROTO : transfer_size; > > break; > > + } > > } > > if (err < 0) > > break; > > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > > index 11f8c84..444d51b 100644 > > --- a/include/drm/drm_dp_helper.h > > +++ b/include/drm/drm_dp_helper.h > > @@ -42,6 +42,8 @@ > > * 1.2 formally includes both eDP and DPI definitions. > > */ > > > > +#define DP_AUX_MAX_PAYLOAD_BYTES 16 > > + > > #define DP_AUX_I2C_WRITE 0x0 > > #define DP_AUX_I2C_READ 0x1 > > #define DP_AUX_I2C_STATUS 0x2 > > @@ -519,6 +521,9 @@ struct drm_dp_aux_msg { > > * transactions. The drm_dp_aux_register_i2c_bus() function registers an > > * I2C adapter that can be passed to drm_probe_ddc(). Upon removal, drivers > > * should call drm_dp_aux_unregister_i2c_bus() to remove the I2C adapter. > > + * The I2C adapter uses long transfers by default; if a partial response is > > + * received, the adapter will drop down to the size given by the partial > > + * response for this transaction only. > > * > > * Note that the aux helper code assumes that the .transfer() function > > * only modifies the reply field of the drm_dp_aux_msg structure. The > > -- > > 2.1.0 > > -- > Ville Syrjälä > Intel OTC
On Mon, Jan 26, 2015 at 03:47:13PM +0000, Simon Farnsworth wrote: > On Monday 26 January 2015 17:33:35 Ville Syrjälä wrote: > > On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > > > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > > > their I2C over AUX implementation. They work fine with Windows, but fail > > > with Linux. > > > > > > It turns out that they cannot keep an I2C transaction open unless the > > > previous read was 16 bytes; shorter reads can only be followed by a zero > > > byte transfer ending the I2C transaction. > > > > > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > > > reply, assume that there's a hardware bottleneck, and shrink our read size > > > to match. > > > > > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > > > --- > > > > > > v2 changes, after feedback from Thierry and Ville: > > > > > > * Handle short replies. I've decided (arbitrarily) that a short reply > > > results in us dropping back to the newly chosen size for the rest of this > > > I2C transaction. Thus, given an attempt to read the first 16 bytes of > > > EDID, and a sink that only does 4 bytes of buffering, we will see the > > > following AUX transfers for the EDID read (after address is set): > > > > > > <set address, block etc> > > > Read 16 bytes from I2C over AUX. > > > Reply with 4 bytes > > > Read 4 bytes > > > Reply with 4 bytes > > > Read 4 bytes > > > Reply with 4 bytes > > > Read 4 bytes > > > Reply with 4 bytes > > > <end I2C transaction> > > > > I think that's agaisnt the spec. IIRC you have to keep repeating the > > same transaction (meaning address/len are unchanged) until all the data > > was transferred. > > > Do you have a spec reference against the DisplayPort 1.1a (last public > version) spec? My chosen behaviour matches Table 2-50 in the 1.1a spec. In my copy if DP v1.1 the example in 2-50 just keeps repeating w/ 16 bytes. So doesn't match what you do. And that's unchanged in v1.2. DP v1.2 has some extra clarifications for this stuff: "2.7.7 I2C-overAUX Transaction Clarifications and Implementation Rules 2.7.7.1.6.4 Upon the Reply of I2C_ACK|AUX_ACK Followed by the Total Number of Data Bytes Fewer than LEN+1, to a Request Transaction with MOT Bit Set Either to 0 or 1 The Source device must: o Repeat the identical I2C-read-over-AUX transaction with the updated LEN value equal to the original LEN value minus the total number of data bytes received so far, o Repeat the identical I2C-read-over-AUX transaction with the same LEN value as the original value, or, o Issue an address-only I2C-over-AUX with MOT bit set to 0 to prompt I2C STOP to terminate the current I2C-read-over-AUX transaction. It should be noted that when the Source device repeats the same I2C-read-over-AUX transaction with the same LEN value as the original value, the Sink device is likely to read more data bytes than the Source device needs."
On Monday 26 January 2015 18:11:01 Ville Syrjälä wrote: > On Mon, Jan 26, 2015 at 03:47:13PM +0000, Simon Farnsworth wrote: > > On Monday 26 January 2015 17:33:35 Ville Syrjälä wrote: > > > On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > > > > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > > > > their I2C over AUX implementation. They work fine with Windows, but fail > > > > with Linux. > > > > > > > > It turns out that they cannot keep an I2C transaction open unless the > > > > previous read was 16 bytes; shorter reads can only be followed by a zero > > > > byte transfer ending the I2C transaction. > > > > > > > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > > > > reply, assume that there's a hardware bottleneck, and shrink our read size > > > > to match. > > > > > > > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > > > > --- > > > > > > > > v2 changes, after feedback from Thierry and Ville: > > > > > > > > * Handle short replies. I've decided (arbitrarily) that a short reply > > > > results in us dropping back to the newly chosen size for the rest of this > > > > I2C transaction. Thus, given an attempt to read the first 16 bytes of > > > > EDID, and a sink that only does 4 bytes of buffering, we will see the > > > > following AUX transfers for the EDID read (after address is set): > > > > > > > > <set address, block etc> > > > > Read 16 bytes from I2C over AUX. > > > > Reply with 4 bytes > > > > Read 4 bytes > > > > Reply with 4 bytes > > > > Read 4 bytes > > > > Reply with 4 bytes > > > > Read 4 bytes > > > > Reply with 4 bytes > > > > <end I2C transaction> > > > > > > I think that's agaisnt the spec. IIRC you have to keep repeating the > > > same transaction (meaning address/len are unchanged) until all the data > > > was transferred. > > > > > Do you have a spec reference against the DisplayPort 1.1a (last public > > version) spec? My chosen behaviour matches Table 2-50 in the 1.1a spec. > > In my copy if DP v1.1 the example in 2-50 just keeps repeating w/ 16 bytes. > So doesn't match what you do. And that's unchanged in v1.2. > Yes, looks like I misread the table; I was more thinking about "what are the semantics of a 4 byte reply to a 16 byte read?" when I read that bit of the spec. > DP v1.2 has some extra clarifications for this stuff: > "2.7.7 I2C-overAUX Transaction Clarifications and Implementation Rules > > 2.7.7.1.6.4 Upon the Reply of I2C_ACK|AUX_ACK Followed by the Total Number of Data > Bytes Fewer than LEN+1, to a Request Transaction with MOT Bit Set Either to 0 or 1 > > The Source device must: > o Repeat the identical I2C-read-over-AUX transaction with the updated > LEN value equal to the original LEN value minus the total number of data > bytes received so far, > o Repeat the identical I2C-read-over-AUX transaction with the same LEN > value as the original value, or, > o Issue an address-only I2C-over-AUX with MOT bit set to 0 to prompt I2C STOP > to terminate the current I2C-read-over-AUX transaction. > It should be noted that when the Source device repeats the same I2C-read-over-AUX > transaction with the same LEN value as the original value, the Sink device is > likely to read more data bytes than the Source device needs." > So what would be the best implementation strategy for Linux? Bear in mind that I don't have the 1.2 spec, nor do I have any devices which give a partial response to a 16 byte read, so I'm coding blind here, based solely on the information people are giving me. The simplest strategy would be to keep repeating with 16 byte reads all the time, but Thierry's original comment and response to the first patch have suggested that that's a performance problem waiting to happen, hence the effort to find a better strategy. My strategy was intended to spot that there's probably a FIFO in the middle that's too small, and reduce the transfer size to avoid overflowing the FIFO. I could make it more complex by remembering that the last read was a partial read, finishing it off by reducing the read size, then sticking to the new smaller size, but that's added complexity and I'm not sure of its value. Should I simply stick to 16 byte reads, and cope with getting back less data than I want, or do you think we need the more complex strategy that complies with DP 1.2?
On Mon, Jan 26, 2015 at 04:39:29PM +0000, Simon Farnsworth wrote: > On Monday 26 January 2015 18:11:01 Ville Syrjälä wrote: > > On Mon, Jan 26, 2015 at 03:47:13PM +0000, Simon Farnsworth wrote: > > > On Monday 26 January 2015 17:33:35 Ville Syrjälä wrote: > > > > On Mon, Jan 26, 2015 at 03:22:48PM +0000, Simon Farnsworth wrote: > > > > > DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in > > > > > their I2C over AUX implementation. They work fine with Windows, but fail > > > > > with Linux. > > > > > > > > > > It turns out that they cannot keep an I2C transaction open unless the > > > > > previous read was 16 bytes; shorter reads can only be followed by a zero > > > > > byte transfer ending the I2C transaction. > > > > > > > > > > Copy Windows's behaviour, and read 16 bytes at a time. If we get a short > > > > > reply, assume that there's a hardware bottleneck, and shrink our read size > > > > > to match. > > > > > > > > > > Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> > > > > > --- > > > > > > > > > > v2 changes, after feedback from Thierry and Ville: > > > > > > > > > > * Handle short replies. I've decided (arbitrarily) that a short reply > > > > > results in us dropping back to the newly chosen size for the rest of this > > > > > I2C transaction. Thus, given an attempt to read the first 16 bytes of > > > > > EDID, and a sink that only does 4 bytes of buffering, we will see the > > > > > following AUX transfers for the EDID read (after address is set): > > > > > > > > > > <set address, block etc> > > > > > Read 16 bytes from I2C over AUX. > > > > > Reply with 4 bytes > > > > > Read 4 bytes > > > > > Reply with 4 bytes > > > > > Read 4 bytes > > > > > Reply with 4 bytes > > > > > Read 4 bytes > > > > > Reply with 4 bytes > > > > > <end I2C transaction> > > > > > > > > I think that's agaisnt the spec. IIRC you have to keep repeating the > > > > same transaction (meaning address/len are unchanged) until all the data > > > > was transferred. > > > > > > > Do you have a spec reference against the DisplayPort 1.1a (last public > > > version) spec? My chosen behaviour matches Table 2-50 in the 1.1a spec. > > > > In my copy if DP v1.1 the example in 2-50 just keeps repeating w/ 16 bytes. > > So doesn't match what you do. And that's unchanged in v1.2. > > > Yes, looks like I misread the table; I was more thinking about "what are the > semantics of a 4 byte reply to a 16 byte read?" when I read that bit of the > spec. > > > DP v1.2 has some extra clarifications for this stuff: > > "2.7.7 I2C-overAUX Transaction Clarifications and Implementation Rules > > > > 2.7.7.1.6.4 Upon the Reply of I2C_ACK|AUX_ACK Followed by the Total Number of Data > > Bytes Fewer than LEN+1, to a Request Transaction with MOT Bit Set Either to 0 or 1 > > > > The Source device must: > > o Repeat the identical I2C-read-over-AUX transaction with the updated > > LEN value equal to the original LEN value minus the total number of data > > bytes received so far, > > o Repeat the identical I2C-read-over-AUX transaction with the same LEN > > value as the original value, or, > > o Issue an address-only I2C-over-AUX with MOT bit set to 0 to prompt I2C STOP > > to terminate the current I2C-read-over-AUX transaction. > > It should be noted that when the Source device repeats the same I2C-read-over-AUX > > transaction with the same LEN value as the original value, the Sink device is > > likely to read more data bytes than the Source device needs." > > > So what would be the best implementation strategy for Linux? Bear in mind > that I don't have the 1.2 spec, nor do I have any devices which give a > partial response to a 16 byte read, so I'm coding blind here, based solely > on the information people are giving me. > > The simplest strategy would be to keep repeating with 16 byte reads all the > time, but Thierry's original comment and response to the first patch have > suggested that that's a performance problem waiting to happen, hence the > effort to find a better strategy. > > My strategy was intended to spot that there's probably a FIFO in the middle > that's too small, and reduce the transfer size to avoid overflowing the > FIFO. I could make it more complex by remembering that the last read was a > partial read, finishing it off by reducing the read size, then sticking to > the new smaller size, but that's added complexity and I'm not sure of its > value. > > Should I simply stick to 16 byte reads, and cope with getting back less data > than I want, or do you think we need the more complex strategy that complies > with DP 1.2? So I've been experimenting a bit with various dongles here, and sadly I've not managed to get any one of them to return short reads :( I did find one that allows changing the speed of the i2c bus, but even if I reduce it to 1khz there are no short reads, just a lot more defers. The dongle in question has OUI 001cf8. However the good news is that EDID reads seem to get faster across the board with 16 byte messages. How much faster depends on the dongle. Here are my measurements how long it took to read a single EDID block: DP->DVI (OUI 001cf8): 40ms -> 35ms DP->VGA (OUI 0022b9): 45ms -> 38ms Zotac DP->2xHDMI: 25ms -> 4ms Oh and this is how I mangled my drm_dp_i2c_xfer(): transferred = 0; while (msgs[i].len > transferred) { msg.buffer = msgs[i].buf + transferred; msg.size = min_t(unsigned int, drm_dp_i2c_msg_size, msgs[i].len - transferred); err = drm_dp_i2c_do_msg(aux, &msg); if (err < 0) break; WARN_ON(err == 0); transferred += err; } I made the msg size configurable via a module param just to help me test this stuff, but I'm thinking we might want to upstream that just to make it easier to try smaller message sizes if/when people encounter problematic sinks/dongles.
On Tue, 27 Jan 2015, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: > So I've been experimenting a bit with various dongles here, and sadly I've > not managed to get any one of them to return short reads :( > > I did find one that allows changing the speed of the i2c bus, but even if > I reduce it to 1khz there are no short reads, just a lot more defers. The > dongle in question has OUI 001cf8. > > However the good news is that EDID reads seem to get faster across the > board with 16 byte messages. How much faster depends on the dongle. > > Here are my measurements how long it took to read a single EDID block: > DP->DVI (OUI 001cf8): 40ms -> 35ms > DP->VGA (OUI 0022b9): 45ms -> 38ms > Zotac DP->2xHDMI: 25ms -> 4ms > > > Oh and this is how I mangled my drm_dp_i2c_xfer(): > transferred = 0; > while (msgs[i].len > transferred) { > msg.buffer = msgs[i].buf + transferred; > msg.size = min_t(unsigned int, drm_dp_i2c_msg_size, > msgs[i].len - transferred); > err = drm_dp_i2c_do_msg(aux, &msg); > if (err < 0) > break; > WARN_ON(err == 0); > transferred += err; > } > > I made the msg size configurable via a module param just to help me test > this stuff, but I'm thinking we might want to upstream that just to make > it easier to try smaller message sizes if/when people encounter problematic > sinks/dongles. How about just letting that happen first, to see if and how the problems occur? If there's a pattern, maybe we can fall back to 1-byte transfers in those cases (or even add OUI based quirks). I've grown really hesitant about adding new module parameters, they are ABI we can't easily remove/regress once added. BR, Jani.
On Wed, Jan 28, 2015 at 10:59:06AM +0200, Jani Nikula wrote: > On Tue, 27 Jan 2015, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: > > So I've been experimenting a bit with various dongles here, and sadly I've > > not managed to get any one of them to return short reads :( > > > > I did find one that allows changing the speed of the i2c bus, but even if > > I reduce it to 1khz there are no short reads, just a lot more defers. The > > dongle in question has OUI 001cf8. > > > > However the good news is that EDID reads seem to get faster across the > > board with 16 byte messages. How much faster depends on the dongle. > > > > Here are my measurements how long it took to read a single EDID block: > > DP->DVI (OUI 001cf8): 40ms -> 35ms > > DP->VGA (OUI 0022b9): 45ms -> 38ms > > Zotac DP->2xHDMI: 25ms -> 4ms > > > > > > Oh and this is how I mangled my drm_dp_i2c_xfer(): > > transferred = 0; > > while (msgs[i].len > transferred) { > > msg.buffer = msgs[i].buf + transferred; > > msg.size = min_t(unsigned int, drm_dp_i2c_msg_size, > > msgs[i].len - transferred); > > err = drm_dp_i2c_do_msg(aux, &msg); > > if (err < 0) > > break; > > WARN_ON(err == 0); > > transferred += err; > > } > > > > I made the msg size configurable via a module param just to help me test > > this stuff, but I'm thinking we might want to upstream that just to make > > it easier to try smaller message sizes if/when people encounter problematic > > sinks/dongles. > > How about just letting that happen first, to see if and how the problems > occur? If there's a pattern, maybe we can fall back to 1-byte transfers > in those cases (or even add OUI based quirks). I've grown really > hesitant about adding new module parameters, they are ABI we can't > easily remove/regress once added. module_param_debug takes care of any such risks imo. -Daniel
On Wed, 28 Jan 2015, Daniel Vetter <daniel@ffwll.ch> wrote: > On Wed, Jan 28, 2015 at 10:59:06AM +0200, Jani Nikula wrote: >> On Tue, 27 Jan 2015, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: >> > So I've been experimenting a bit with various dongles here, and sadly I've >> > not managed to get any one of them to return short reads :( >> > >> > I did find one that allows changing the speed of the i2c bus, but even if >> > I reduce it to 1khz there are no short reads, just a lot more defers. The >> > dongle in question has OUI 001cf8. >> > >> > However the good news is that EDID reads seem to get faster across the >> > board with 16 byte messages. How much faster depends on the dongle. >> > >> > Here are my measurements how long it took to read a single EDID block: >> > DP->DVI (OUI 001cf8): 40ms -> 35ms >> > DP->VGA (OUI 0022b9): 45ms -> 38ms >> > Zotac DP->2xHDMI: 25ms -> 4ms >> > >> > >> > Oh and this is how I mangled my drm_dp_i2c_xfer(): >> > transferred = 0; >> > while (msgs[i].len > transferred) { >> > msg.buffer = msgs[i].buf + transferred; >> > msg.size = min_t(unsigned int, drm_dp_i2c_msg_size, >> > msgs[i].len - transferred); >> > err = drm_dp_i2c_do_msg(aux, &msg); >> > if (err < 0) >> > break; >> > WARN_ON(err == 0); >> > transferred += err; >> > } >> > >> > I made the msg size configurable via a module param just to help me test >> > this stuff, but I'm thinking we might want to upstream that just to make >> > it easier to try smaller message sizes if/when people encounter problematic >> > sinks/dongles. >> >> How about just letting that happen first, to see if and how the problems >> occur? If there's a pattern, maybe we can fall back to 1-byte transfers >> in those cases (or even add OUI based quirks). I've grown really >> hesitant about adding new module parameters, they are ABI we can't >> easily remove/regress once added. > > module_param_debug takes care of any such risks imo. No such thing, maybe you mean module_param_unsafe? Jani. > -Daniel > -- > Daniel Vetter > Software Engineer, Intel Corporation > +41 (0) 79 365 57 48 - http://blog.ffwll.ch
On Wed, Jan 28, 2015 at 11:33:34AM +0200, Jani Nikula wrote: > On Wed, 28 Jan 2015, Daniel Vetter <daniel@ffwll.ch> wrote: > > On Wed, Jan 28, 2015 at 10:59:06AM +0200, Jani Nikula wrote: > >> On Tue, 27 Jan 2015, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: > >> > So I've been experimenting a bit with various dongles here, and sadly I've > >> > not managed to get any one of them to return short reads :( > >> > > >> > I did find one that allows changing the speed of the i2c bus, but even if > >> > I reduce it to 1khz there are no short reads, just a lot more defers. The > >> > dongle in question has OUI 001cf8. > >> > > >> > However the good news is that EDID reads seem to get faster across the > >> > board with 16 byte messages. How much faster depends on the dongle. > >> > > >> > Here are my measurements how long it took to read a single EDID block: > >> > DP->DVI (OUI 001cf8): 40ms -> 35ms > >> > DP->VGA (OUI 0022b9): 45ms -> 38ms > >> > Zotac DP->2xHDMI: 25ms -> 4ms > >> > > >> > > >> > Oh and this is how I mangled my drm_dp_i2c_xfer(): > >> > transferred = 0; > >> > while (msgs[i].len > transferred) { > >> > msg.buffer = msgs[i].buf + transferred; > >> > msg.size = min_t(unsigned int, drm_dp_i2c_msg_size, > >> > msgs[i].len - transferred); > >> > err = drm_dp_i2c_do_msg(aux, &msg); > >> > if (err < 0) > >> > break; > >> > WARN_ON(err == 0); > >> > transferred += err; > >> > } > >> > > >> > I made the msg size configurable via a module param just to help me test > >> > this stuff, but I'm thinking we might want to upstream that just to make > >> > it easier to try smaller message sizes if/when people encounter problematic > >> > sinks/dongles. > >> > >> How about just letting that happen first, to see if and how the problems > >> occur? If there's a pattern, maybe we can fall back to 1-byte transfers > >> in those cases (or even add OUI based quirks). I've grown really > >> hesitant about adding new module parameters, they are ABI we can't > >> easily remove/regress once added. > > > > module_param_debug takes care of any such risks imo. > > No such thing, maybe you mean module_param_unsafe? Indeed that's what I've meant. -Daniel
On Wednesday 28 January 2015 11:33:34 Jani Nikula wrote: > On Wed, 28 Jan 2015, Daniel Vetter <daniel@ffwll.ch> wrote: > > On Wed, Jan 28, 2015 at 10:59:06AM +0200, Jani Nikula wrote: > >> On Tue, 27 Jan 2015, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: --snip-- > >> > I made the msg size configurable via a module param just to help me test > >> > this stuff, but I'm thinking we might want to upstream that just to make > >> > it easier to try smaller message sizes if/when people encounter problematic > >> > sinks/dongles. > >> > >> How about just letting that happen first, to see if and how the problems > >> occur? If there's a pattern, maybe we can fall back to 1-byte transfers > >> in those cases (or even add OUI based quirks). I've grown really > >> hesitant about adding new module parameters, they are ABI we can't > >> easily remove/regress once added. > > > > module_param_debug takes care of any such risks imo. > > No such thing, maybe you mean module_param_unsafe? > > Jani. Changing to module_param_unsafe is trivial. That would taint the kernel if you play with it, hopefully making it clear that this is not permanent ABI. I'm now seeing the Bizlink adapters fail after about 45 seconds of isochronous link up, so it'll be a few days before I do a v4 of this patch, as I need Datapath's assistance analysing the differences in behaviour between us and Windows).
diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index 79968e3..701b201 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -396,11 +396,13 @@ static u32 drm_dp_i2c_functionality(struct i2c_adapter *adapter) * retrying the transaction as appropriate. It is assumed that the * aux->transfer function does not modify anything in the msg other than the * reply field. + * + * Returns bytes transferred on success, or a negative error code on failure. */ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) { unsigned int retry; - int err; + int ret; /* * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device @@ -409,14 +411,14 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) */ for (retry = 0; retry < 7; retry++) { mutex_lock(&aux->hw_mutex); - err = aux->transfer(aux, msg); + ret = aux->transfer(aux, msg); mutex_unlock(&aux->hw_mutex); - if (err < 0) { - if (err == -EBUSY) + if (ret < 0) { + if (ret == -EBUSY) continue; - DRM_DEBUG_KMS("transaction failed: %d\n", err); - return err; + DRM_DEBUG_KMS("transaction failed: %d\n", ret); + return ret; } @@ -457,9 +459,7 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) * Both native ACK and I2C ACK replies received. We * can assume the transfer was successful. */ - if (err < msg->size) - return -EPROTO; - return 0; + return ret; case DP_AUX_I2C_REPLY_NACK: DRM_DEBUG_KMS("I2C nack\n"); @@ -487,6 +487,7 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, { struct drm_dp_aux *aux = adapter->algo_data; unsigned int i, j; + int transfer_size = DP_AUX_MAX_PAYLOAD_BYTES; struct drm_dp_aux_msg msg; int err = 0; @@ -507,20 +508,23 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, err = drm_dp_i2c_do_msg(aux, &msg); if (err < 0) break; - /* - * Many hardware implementations support FIFOs larger than a - * single byte, but it has been empirically determined that - * transferring data in larger chunks can actually lead to - * decreased performance. Therefore each message is simply - * transferred byte-by-byte. + /* Bizlink designed DP->DVI-D Dual Link adapters require the + * I2C over AUX packets to be as large as possible. If not, + * the I2C transactions never succeed. + * + * We therefore start by requesting 16 byte transfers. If + * the hardware gives us a partial ACK, we stick to the new + * smaller size from the partial ACK. */ - for (j = 0; j < msgs[i].len; j++) { + for (j = 0; j < msgs[i].len; j += transfer_size) { msg.buffer = msgs[i].buf + j; - msg.size = 1; + msg.size = min(transfer_size, msgs[i].len - j); - err = drm_dp_i2c_do_msg(aux, &msg); - if (err < 0) + transfer_size = drm_dp_i2c_do_msg(aux, &msg); + if (transfer_size <= 0) { + err = transfer_size == 0 ? -EPROTO : transfer_size; break; + } } if (err < 0) break; diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index 11f8c84..444d51b 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -42,6 +42,8 @@ * 1.2 formally includes both eDP and DPI definitions. */ +#define DP_AUX_MAX_PAYLOAD_BYTES 16 + #define DP_AUX_I2C_WRITE 0x0 #define DP_AUX_I2C_READ 0x1 #define DP_AUX_I2C_STATUS 0x2 @@ -519,6 +521,9 @@ struct drm_dp_aux_msg { * transactions. The drm_dp_aux_register_i2c_bus() function registers an * I2C adapter that can be passed to drm_probe_ddc(). Upon removal, drivers * should call drm_dp_aux_unregister_i2c_bus() to remove the I2C adapter. + * The I2C adapter uses long transfers by default; if a partial response is + * received, the adapter will drop down to the size given by the partial + * response for this transaction only. * * Note that the aux helper code assumes that the .transfer() function * only modifies the reply field of the drm_dp_aux_msg structure. The
DisplayPort to DVI-D Dual Link adapters designed by Bizlink have bugs in their I2C over AUX implementation. They work fine with Windows, but fail with Linux. It turns out that they cannot keep an I2C transaction open unless the previous read was 16 bytes; shorter reads can only be followed by a zero byte transfer ending the I2C transaction. Copy Windows's behaviour, and read 16 bytes at a time. If we get a short reply, assume that there's a hardware bottleneck, and shrink our read size to match. Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk> --- v2 changes, after feedback from Thierry and Ville: * Handle short replies. I've decided (arbitrarily) that a short reply results in us dropping back to the newly chosen size for the rest of this I2C transaction. Thus, given an attempt to read the first 16 bytes of EDID, and a sink that only does 4 bytes of buffering, we will see the following AUX transfers for the EDID read (after address is set): <set address, block etc> Read 16 bytes from I2C over AUX. Reply with 4 bytes Read 4 bytes Reply with 4 bytes Read 4 bytes Reply with 4 bytes Read 4 bytes Reply with 4 bytes <end I2C transaction> Note that I've not looked at MST support - I have neither the DP 1.2 spec nor any MST branch devices, so I can't test anything I write or check it against a spec. It looks from the code, however, as if MST has the branch device do the split from a big request into small transactions. drivers/gpu/drm/drm_dp_helper.c | 42 ++++++++++++++++++++++------------------- include/drm/drm_dp_helper.h | 5 +++++ 2 files changed, 28 insertions(+), 19 deletions(-)