From e8509800b2ba31aa8c85c4d5ced70dd8a900a4ca Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 6 Apr 2019 23:21:29 +0000 Subject: [PATCH] qla2x00t-32gbit: Backport to RHEL 6 Untested. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8169 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t-32gbit/btree-backport.h | 286 ++++++++++++++++++++ qla2x00t-32gbit/qla_def.h | 9 +- qla2x00t-32gbit/qla_os.c | 28 +- qla2x00t-32gbit/qla_target.h | 8 + qla2x00t-32gbit/target_core_base-backport.h | 29 ++ 5 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 qla2x00t-32gbit/btree-backport.h create mode 100644 qla2x00t-32gbit/target_core_base-backport.h diff --git a/qla2x00t-32gbit/btree-backport.h b/qla2x00t-32gbit/btree-backport.h new file mode 100644 index 000000000..9c40b60bd --- /dev/null +++ b/qla2x00t-32gbit/btree-backport.h @@ -0,0 +1,286 @@ +#ifndef _BTREE_BACKPORT_H_ +#define _BTREE_BACKPORT_H_ + +struct btree_head32 { + struct list_head head; +}; + +struct btree_node32 { + struct list_head entry; + u32 key; + void *val; +}; + +struct btree_head64 { + struct list_head head; +}; + +struct btree_node64 { + struct list_head entry; + u64 key; + void *val; +}; + +/** + * btree_init - initialise a btree + * + * @head: the btree head to initialise + * + * This function allocates the memory pool that the + * btree needs. Returns zero or a negative error code + * (-%ENOMEM) when memory allocation fails. + */ +static inline int __must_check btree_init32(struct btree_head32 *head) +{ + INIT_LIST_HEAD(&head->head); + return 0; +} + +static inline int __must_check btree_init64(struct btree_head64 *head) +{ + INIT_LIST_HEAD(&head->head); + return 0; +} + +/** + * btree_destroy - destroy mempool + * + * @head: the btree head to destroy + * + * This function destroys the internal memory pool, use only + * when using btree_init(), not with btree_init_mempool(). + */ +static inline void btree_destroy32(struct btree_head32 *head) +{ +} + +static inline void btree_destroy64(struct btree_head64 *head) +{ +} + +/** + * btree_lookup - look up a key in the btree + * + * @head: the btree to look in + * @geo: the btree geometry + * @key: the key to look up + * + * This function returns the value for the given key, or %NULL. + */ +static inline void *btree_lookup32(struct btree_head32 *head, u32 key) +{ + struct btree_node32 *n; + + list_for_each_entry(n, &head->head, entry) { + if (n->key == key) + return n->val; + } + return NULL; +} + +static inline void *btree_lookup64(struct btree_head64 *head, u64 key) +{ + struct btree_node64 *n; + + list_for_each_entry(n, &head->head, entry) { + if (n->key == key) + return n->val; + } + return NULL; +} + +/** + * btree_insert - insert an entry into the btree + * + * @head: the btree to add to + * @geo: the btree geometry + * @key: the key to add (must not already be present) + * @val: the value to add (must not be %NULL) + * @gfp: allocation flags for node allocations + * + * This function returns 0 if the item could be added, or an + * error code if it failed (may fail due to memory pressure). + */ +static inline int __must_check btree_insert32(struct btree_head32 *head, + u32 key, void *val, gfp_t gfp) +{ + struct btree_node32 *n, *p; + + n = kmalloc(sizeof(*n), gfp); + if (IS_ERR(n)) + return PTR_ERR(n); + n->key = key; + n->val = val; + list_for_each_entry(p, &head->head, entry) { + if (p->key > key) + break; + } + list_add(p->entry.prev, &n->entry); + return 0; +} + +static inline int __must_check btree_insert64(struct btree_head64 *head, + u64 key, void *val, gfp_t gfp) +{ + struct btree_node64 *n, *p; + + n = kmalloc(sizeof(*n), gfp); + if (IS_ERR(n)) + return PTR_ERR(n); + n->key = key; + n->val = val; + list_for_each_entry(p, &head->head, entry) { + if (p->key > key) + break; + } + list_add(p->entry.prev, &n->entry); + return 0; +} + +/** + * btree_update - update an entry in the btree + * + * @head: the btree to update + * @geo: the btree geometry + * @key: the key to update + * @val: the value to change it to (must not be %NULL) + * + * This function returns 0 if the update was successful, or + * -%ENOENT if the key could not be found. + */ +static inline int btree_update32(struct btree_head32 *head, u32 key, void *val) +{ + struct btree_node32 *p; + + list_for_each_entry(p, &head->head, entry) { + if (p->key == key) { + p->val = val; + return 0; + } + } + return -ENOENT; +} + +/** + * btree_remove - remove an entry from the btree + * + * @head: the btree to update + * @geo: the btree geometry + * @key: the key to remove + * + * This function returns the removed entry, or %NULL if the key + * could not be found. + */ +static inline void *btree_remove32(struct btree_head32 *head, u32 key) +{ + struct btree_node32 *p; + void *val; + + list_for_each_entry(p, &head->head, entry) { + if (p->key == key) { + val = p->val; + list_del(&p->entry); + kfree(p); + return val; + } + } + return NULL; +} + +static inline void *btree_remove64(struct btree_head64 *head, u64 key) +{ + struct btree_node64 *p; + void *val; + + list_for_each_entry(p, &head->head, entry) { + if (p->key == key) { + val = p->val; + list_del(&p->entry); + kfree(p); + return val; + } + } + return NULL; +} + +/** + * btree_last - get last entry in btree + * + * @head: btree head + * @geo: btree geometry + * @key: last key + * + * Returns the last entry in the btree, and sets @key to the key + * of that entry; returns NULL if the tree is empty, in that case + * key is not changed. + */ +static inline void *btree_last32(struct btree_head32 *head, u32 *key) +{ + struct btree_node32 *p; + + if (list_empty(&head->head)) + return NULL; + p = list_last_entry(&head->head, typeof(*p), entry); + *key = p->key; + return p->val; +} + +static inline void *btree_last64(struct btree_head64 *head, u64 *key) +{ + struct btree_node64 *p; + + if (list_empty(&head->head)) + return NULL; + p = list_last_entry(&head->head, typeof(*p), entry); + *key = p->key; + return p->val; +} + +/** + * btree_get_prev - get previous entry + * + * @head: btree head + * @geo: btree geometry + * @key: pointer to key + * + * The function returns the next item right before the value pointed to by + * @key, and updates @key with its key, or returns %NULL when there is no + * entry with a key smaller than the given key. + */ +static inline void *btree_get_prev32(struct btree_head32 *head, u32 *key) +{ + struct btree_node32 *p; + + list_for_each_entry_reverse(p, &head->head, entry) { + if (p->key < *key) { + *key = p->key; + return p->val; + } + } + return NULL; +} + +static inline void *btree_get_prev64(struct btree_head64 *head, u64 *key) +{ + struct btree_node64 *p; + + list_for_each_entry_reverse(p, &head->head, entry) { + if (p->key < *key) { + *key = p->key; + return p->val; + } + } + return NULL; +} + +#define btree_for_each_safe32(head, key, val) \ + for (val = btree_last32(head, &key); \ + val; \ + val = btree_get_prev32(head, &key)) + +#define btree_for_each_safe64(head, key, val) \ + for (val = btree_last64(head, &key); \ + val; \ + val = btree_get_prev64(head, &key)) + +#endif /* _BTREE_BACKPORT_H_ */ diff --git a/qla2x00t-32gbit/qla_def.h b/qla2x00t-32gbit/qla_def.h index 2ac999f4c..0f984b3fb 100644 --- a/qla2x00t-32gbit/qla_def.h +++ b/qla2x00t-32gbit/qla_def.h @@ -25,8 +25,15 @@ #include #include #include -#include #include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) +/* + * See also commit 5db53f3e80de ("[LogFS] add new flash file system") # v2.6.34. + */ +#include +#else +#include "btree-backport.h" +#endif #include #include diff --git a/qla2x00t-32gbit/qla_os.c b/qla2x00t-32gbit/qla_os.c index 27a47f5d6..2a3f71c3f 100644 --- a/qla2x00t-32gbit/qla_os.c +++ b/qla2x00t-32gbit/qla_os.c @@ -13,13 +13,14 @@ #include #include #include +#include +#include #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) #include #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #include #endif -#include #include #include @@ -331,7 +332,13 @@ static int qla2xxx_slave_alloc(struct scsi_device *); static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); static void qla2xxx_scan_start(struct Scsi_Host *); static void qla2xxx_slave_destroy(struct scsi_device *); +#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 >= 2 +static int qla2xxx_queuecommand(struct scsi_cmnd *scmnd, + void (*done)(struct scsi_cmnd *)); + +#else static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); +#endif static int qla2xxx_eh_abort(struct scsi_cmnd *); static int qla2xxx_eh_device_reset(struct scsi_cmnd *); static int qla2xxx_eh_target_reset(struct scsi_cmnd *); @@ -924,8 +931,23 @@ qla2xxx_qpair_sp_compl(void *ptr, int res) cmd->scsi_done(cmd); } +#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 >= 2 +static int +qla2xxx_queuecommand_wrk(struct Scsi_Host *host, struct scsi_cmnd *cmd); + +static int qla2xxx_queuecommand(struct scsi_cmnd *scmnd, + void (*done)(struct scsi_cmnd *)) +{ + scmnd->scsi_done = done; + return qla2xxx_queuecommand_wrk(scmnd->device->host, scmnd); +} + +static int +qla2xxx_queuecommand_wrk(struct Scsi_Host *host, struct scsi_cmnd *cmd) +#else static int qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) +#endif { scsi_qla_host_t *vha = shost_priv(host); fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; @@ -5061,7 +5083,11 @@ void qla24xx_sched_upd_fcport(fc_port_t *fcport) fcport->disc_state = DSC_UPD_FCPORT; spin_unlock_irqrestore(&fcport->vha->work_lock, flags); +#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 <= 6 + schedule_work(&fcport->reg_work); +#else queue_work(system_unbound_wq, &fcport->reg_work); +#endif } static diff --git a/qla2x00t-32gbit/qla_target.h b/qla2x00t-32gbit/qla_target.h index 55d056e03..1e8715a7a 100644 --- a/qla2x00t-32gbit/qla_target.h +++ b/qla2x00t-32gbit/qla_target.h @@ -738,7 +738,15 @@ struct qla_tgt_func_tmpl { int qla2x00_wait_for_hba_online(struct scsi_qla_host *); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) +/* + * See also commit c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0") + * # v2.6.38. + */ #include +#else +#include "target_core_base-backport.h" +#endif #define QLA_TGT_TIMEOUT 10 /* in seconds */ diff --git a/qla2x00t-32gbit/target_core_base-backport.h b/qla2x00t-32gbit/target_core_base-backport.h new file mode 100644 index 000000000..5f2e42b19 --- /dev/null +++ b/qla2x00t-32gbit/target_core_base-backport.h @@ -0,0 +1,29 @@ +#ifndef _TARGET_CORE_BASE_BACKPORT_H_ +#define _TARGET_CORE_BASE_BACKPORT_H_ + +#define TRANSPORT_SENSE_BUFFER 96 + +enum se_cmd_flags_table { + SCF_OVERFLOW_BIT = 0x00001000, + SCF_UNDERFLOW_BIT = 0x00002000, +}; + +/* for sam_task_attr */ +#define TCM_SIMPLE_TAG 0x20 +#define TCM_HEAD_TAG 0x21 +#define TCM_ORDERED_TAG 0x22 +#define TCM_ACA_TAG 0x24 + +struct se_cmd { + u64 tag; /* SAM command identifier aka task tag */ + u32 se_cmd_flags; + u32 residual_count; + u64 t_task_lba; + int cpuid; +}; + +struct se_session { + void *fabric_sess_ptr; +}; + +#endif /* _TARGET_CORE_BASE_BACKPORT_H_ */