blob: a989a94c38da3f43238bbb875d65c22b9dec2629 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070018#ifndef __BFA_HCB_IOIM_H__
19#define __BFA_HCB_IOIM_H__
Jing Huang7725ccf2009-09-23 17:46:15 -070020
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#include "bfa_os_inc.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070022/*
23 * task attribute values in FCP-2 FCP_CMND IU
24 */
25#define SIMPLE_Q 0
26#define HEAD_OF_Q 1
27#define ORDERED_Q 2
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028#define ACA_Q 4
Jing Huang7725ccf2009-09-23 17:46:15 -070029#define UNTAGGED 5
30
31static inline lun_t
32bfad_int_to_lun(u32 luno)
33{
34 union {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070035 u16 scsi_lun[4];
36 lun_t bfa_lun;
Jing Huang7725ccf2009-09-23 17:46:15 -070037 } lun;
38
39 lun.bfa_lun = 0;
40 lun.scsi_lun[0] = bfa_os_htons(luno);
41
Jing Huangf8ceafd2009-09-25 12:29:54 -070042 return lun.bfa_lun;
Jing Huang7725ccf2009-09-23 17:46:15 -070043}
44
45/**
46 * Get LUN for the I/O request
47 */
48#define bfa_cb_ioim_get_lun(__dio) \
49 bfad_int_to_lun(((struct scsi_cmnd *)__dio)->device->lun)
50
51/**
52 * Get CDB for the I/O request
53 */
54static inline u8 *
55bfa_cb_ioim_get_cdb(struct bfad_ioim_s *dio)
56{
57 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
58
Jing Huangf8ceafd2009-09-25 12:29:54 -070059 return (u8 *) cmnd->cmnd;
Jing Huang7725ccf2009-09-23 17:46:15 -070060}
61
62/**
63 * Get I/O direction (read/write) for the I/O request
64 */
65static inline enum fcp_iodir
66bfa_cb_ioim_get_iodir(struct bfad_ioim_s *dio)
67{
68 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
69 enum dma_data_direction dmadir;
70
71 dmadir = cmnd->sc_data_direction;
72 if (dmadir == DMA_TO_DEVICE)
73 return FCP_IODIR_WRITE;
74 else if (dmadir == DMA_FROM_DEVICE)
75 return FCP_IODIR_READ;
76 else
77 return FCP_IODIR_NONE;
78}
79
80/**
81 * Get IO size in bytes for the I/O request
82 */
83static inline u32
84bfa_cb_ioim_get_size(struct bfad_ioim_s *dio)
85{
86 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
87
Jing Huangf8ceafd2009-09-25 12:29:54 -070088 return scsi_bufflen(cmnd);
Jing Huang7725ccf2009-09-23 17:46:15 -070089}
90
91/**
92 * Get timeout for the I/O request
93 */
94static inline u8
95bfa_cb_ioim_get_timeout(struct bfad_ioim_s *dio)
96{
97 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
98 /*
99 * TBD: need a timeout for scsi passthru
100 */
101 if (cmnd->device->host == NULL)
102 return 4;
103
104 return 0;
105}
106
107/**
Jing Huang7725ccf2009-09-23 17:46:15 -0700108 * Get Command Reference Number for the I/O request. 0 if none.
109 */
110static inline u8
111bfa_cb_ioim_get_crn(struct bfad_ioim_s *dio)
112{
113 return 0;
114}
115
116/**
117 * Get SAM-3 priority for the I/O request. 0 is default.
118 */
119static inline u8
120bfa_cb_ioim_get_priority(struct bfad_ioim_s *dio)
121{
122 return 0;
123}
124
125/**
126 * Get task attributes for the I/O request. Default is FCP_TASK_ATTR_SIMPLE(0).
127 */
128static inline u8
129bfa_cb_ioim_get_taskattr(struct bfad_ioim_s *dio)
130{
131 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 u8 task_attr = UNTAGGED;
Jing Huang7725ccf2009-09-23 17:46:15 -0700133
134 if (cmnd->device->tagged_supported) {
135 switch (cmnd->tag) {
136 case HEAD_OF_QUEUE_TAG:
137 task_attr = HEAD_OF_Q;
138 break;
139 case ORDERED_QUEUE_TAG:
140 task_attr = ORDERED_Q;
141 break;
142 default:
143 task_attr = SIMPLE_Q;
144 break;
145 }
146 }
147
148 return task_attr;
149}
150
151/**
152 * Get CDB length in bytes for the I/O request. Default is FCP_CMND_CDB_LEN(16).
153 */
154static inline u8
155bfa_cb_ioim_get_cdblen(struct bfad_ioim_s *dio)
156{
157 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
158
Jing Huangf8ceafd2009-09-25 12:29:54 -0700159 return cmnd->cmd_len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700160}
161
Jing Huang36d345a2010-07-08 19:57:33 -0700162/**
163 * Assign queue to be used for the I/O request. This value depends on whether
164 * the driver wants to use the queues via any specific algorithm. Currently,
165 * this is not supported.
166 */
167#define bfa_cb_ioim_get_reqq(__dio) BFA_FALSE
Jing Huang7725ccf2009-09-23 17:46:15 -0700168
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169#endif /* __BFA_HCB_IOIM_H__ */