module_put(mod);
}
+static inline bool zcrypt_card_compare(struct zcrypt_card *zc,
+ struct zcrypt_card *pref_zc,
+ unsigned weight, unsigned pref_weight)
+{
+ if (!pref_zc)
+ return 0;
+ weight += atomic_read(&zc->load);
+ pref_weight += atomic_read(&pref_zc->load);
+ if (weight == pref_weight)
+ return atomic_read(&zc->card->total_request_count) >
+ atomic_read(&pref_zc->card->total_request_count);
+ return weight > pref_weight;
+}
+
+static inline bool zcrypt_queue_compare(struct zcrypt_queue *zq,
+ struct zcrypt_queue *pref_zq,
+ unsigned weight, unsigned pref_weight)
+{
+ if (!pref_zq)
+ return 0;
+ weight += atomic_read(&zq->load);
+ pref_weight += atomic_read(&pref_zq->load);
+ if (weight == pref_weight)
+ return &zq->queue->total_request_count >
+ &pref_zq->queue->total_request_count;
+ return weight > pref_weight;
+}
+
/*
* zcrypt ioctls.
*/
continue;
/* get weight index of the card device */
weight = zc->speed_rating[func_code];
- if (pref_zc && atomic_read(&zc->load) + weight >=
- atomic_read(&pref_zc->load) + pref_weight)
+ if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
continue;
for_each_zcrypt_queue(zq, zc) {
/* check if device is online and eligible */
if (!zq->online)
continue;
- if (pref_zq && atomic_read(&zq->load) + weight >=
- atomic_read(&pref_zq->load) + pref_weight)
+ if (zcrypt_queue_compare(zq, pref_zq,
+ weight, pref_weight))
continue;
pref_zc = zc;
pref_zq = zq;
continue;
/* get weight index of the card device */
weight = zc->speed_rating[func_code];
- if (pref_zc && atomic_read(&zc->load) + weight >=
- atomic_read(&pref_zc->load) + pref_weight)
+ if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
continue;
for_each_zcrypt_queue(zq, zc) {
/* check if device is online and eligible */
if (!zq->online)
continue;
- if (pref_zq && atomic_read(&zq->load) + weight >=
- atomic_read(&pref_zq->load) + pref_weight)
+ if (zcrypt_queue_compare(zq, pref_zq,
+ weight, pref_weight))
continue;
pref_zc = zc;
pref_zq = zq;
continue;
/* get weight index of the card device */
weight = speed_idx_cca(func_code) * zc->speed_rating[SECKEY];
- if (pref_zc && atomic_read(&zc->load) + weight >=
- atomic_read(&pref_zc->load) + pref_weight)
+ if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
continue;
for_each_zcrypt_queue(zq, zc) {
/* check if device is online and eligible */
((*domain != (unsigned short) AUTOSELECT) &&
(*domain != AP_QID_QUEUE(zq->queue->qid))))
continue;
- if (pref_zq && atomic_read(&zq->load) + weight >=
- atomic_read(&pref_zq->load) + pref_weight)
+ if (zcrypt_queue_compare(zq, pref_zq,
+ weight, pref_weight))
continue;
pref_zc = zc;
pref_zq = zq;
continue;
/* get weight index of the card device */
weight = speed_idx_ep11(func_code) * zc->speed_rating[SECKEY];
- if (pref_zc && atomic_read(&zc->load) + weight >=
- atomic_read(&pref_zc->load) + pref_weight)
+ if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
continue;
for_each_zcrypt_queue(zq, zc) {
/* check if device is online and eligible */
!is_desired_ep11_queue(zq->queue->qid,
target_num, targets)))
continue;
- if (pref_zq && atomic_read(&zq->load) + weight >=
- atomic_read(&pref_zq->load) + pref_weight)
+ if (zcrypt_queue_compare(zq, pref_zq,
+ weight, pref_weight))
continue;
pref_zc = zc;
pref_zq = zq;
continue;
/* get weight index of the card device */
weight = zc->speed_rating[func_code];
- if (pref_zc && atomic_read(&zc->load) + weight >=
- atomic_read(&pref_zc->load) + pref_weight)
+ if (zcrypt_card_compare(zc, pref_zc, weight, pref_weight))
continue;
for_each_zcrypt_queue(zq, zc) {
/* check if device is online and eligible */
if (!zq->online)
continue;
- if (pref_zq && atomic_read(&zq->load) + weight >=
- atomic_read(&pref_zq->load) + pref_weight)
+ if (zcrypt_queue_compare(zq, pref_zq,
+ weight, pref_weight))
continue;
pref_zc = zc;
pref_zq = zq;