zfcp_fsf.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  13. {
  14. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  15. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
  16. NULL);
  17. }
  18. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  19. unsigned long timeout)
  20. {
  21. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  22. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  23. fsf_req->timer.expires = jiffies + timeout;
  24. add_timer(&fsf_req->timer);
  25. }
  26. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  27. {
  28. BUG_ON(!fsf_req->erp_action);
  29. fsf_req->timer.function = zfcp_erp_timeout_handler;
  30. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  31. fsf_req->timer.expires = jiffies + 30 * HZ;
  32. add_timer(&fsf_req->timer);
  33. }
  34. /* association between FSF command and FSF QTCB type */
  35. static u32 fsf_qtcb_type[] = {
  36. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  37. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  38. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  46. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  47. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  49. };
  50. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  51. {
  52. u16 subtable = table >> 16;
  53. u16 rule = table & 0xffff;
  54. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  55. if (subtable && subtable < ARRAY_SIZE(act_type))
  56. dev_warn(&adapter->ccw_device->dev,
  57. "Access denied according to ACT rule type %s, "
  58. "rule %d\n", act_type[subtable], rule);
  59. }
  60. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  61. struct zfcp_port *port)
  62. {
  63. struct fsf_qtcb_header *header = &req->qtcb->header;
  64. dev_warn(&req->adapter->ccw_device->dev,
  65. "Access denied to port 0x%016Lx\n",
  66. (unsigned long long)port->wwpn);
  67. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  68. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  69. zfcp_erp_port_access_denied(port, 55, req);
  70. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  71. }
  72. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  73. struct zfcp_unit *unit)
  74. {
  75. struct fsf_qtcb_header *header = &req->qtcb->header;
  76. dev_warn(&req->adapter->ccw_device->dev,
  77. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  78. (unsigned long long)unit->fcp_lun,
  79. (unsigned long long)unit->port->wwpn);
  80. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  81. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  82. zfcp_erp_unit_access_denied(unit, 59, req);
  83. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  84. }
  85. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  86. {
  87. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  88. "operational because of an unsupported FC class\n");
  89. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  90. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  91. }
  92. /**
  93. * zfcp_fsf_req_free - free memory used by fsf request
  94. * @fsf_req: pointer to struct zfcp_fsf_req
  95. */
  96. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  97. {
  98. if (likely(req->pool)) {
  99. mempool_free(req, req->pool);
  100. return;
  101. }
  102. if (req->qtcb) {
  103. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  104. return;
  105. }
  106. }
  107. /**
  108. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  109. * @adapter: pointer to struct zfcp_adapter
  110. *
  111. * Never ever call this without shutting down the adapter first.
  112. * Otherwise the adapter would continue using and corrupting s390 storage.
  113. * Included BUG_ON() call to ensure this is done.
  114. * ERP is supposed to be the only user of this function.
  115. */
  116. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  117. {
  118. struct zfcp_fsf_req *req, *tmp;
  119. unsigned long flags;
  120. LIST_HEAD(remove_queue);
  121. unsigned int i;
  122. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  123. spin_lock_irqsave(&adapter->req_list_lock, flags);
  124. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  125. list_splice_init(&adapter->req_list[i], &remove_queue);
  126. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  127. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  128. list_del(&req->list);
  129. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  130. zfcp_fsf_req_complete(req);
  131. }
  132. }
  133. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  134. {
  135. struct fsf_status_read_buffer *sr_buf = req->data;
  136. struct zfcp_adapter *adapter = req->adapter;
  137. struct zfcp_port *port;
  138. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  139. unsigned long flags;
  140. read_lock_irqsave(&zfcp_data.config_lock, flags);
  141. list_for_each_entry(port, &adapter->port_list_head, list)
  142. if (port->d_id == d_id) {
  143. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  144. switch (sr_buf->status_subtype) {
  145. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  146. zfcp_erp_port_reopen(port, 0, 101, req);
  147. break;
  148. case FSF_STATUS_READ_SUB_ERROR_PORT:
  149. zfcp_erp_port_shutdown(port, 0, 122, req);
  150. break;
  151. }
  152. return;
  153. }
  154. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  155. }
  156. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
  157. struct fsf_link_down_info *link_down)
  158. {
  159. struct zfcp_adapter *adapter = req->adapter;
  160. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  161. return;
  162. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  163. if (!link_down)
  164. goto out;
  165. switch (link_down->error_code) {
  166. case FSF_PSQ_LINK_NO_LIGHT:
  167. dev_warn(&req->adapter->ccw_device->dev,
  168. "There is no light signal from the local "
  169. "fibre channel cable\n");
  170. break;
  171. case FSF_PSQ_LINK_WRAP_PLUG:
  172. dev_warn(&req->adapter->ccw_device->dev,
  173. "There is a wrap plug instead of a fibre "
  174. "channel cable\n");
  175. break;
  176. case FSF_PSQ_LINK_NO_FCP:
  177. dev_warn(&req->adapter->ccw_device->dev,
  178. "The adjacent fibre channel node does not "
  179. "support FCP\n");
  180. break;
  181. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  182. dev_warn(&req->adapter->ccw_device->dev,
  183. "The FCP device is suspended because of a "
  184. "firmware update\n");
  185. break;
  186. case FSF_PSQ_LINK_INVALID_WWPN:
  187. dev_warn(&req->adapter->ccw_device->dev,
  188. "The FCP device detected a WWPN that is "
  189. "duplicate or not valid\n");
  190. break;
  191. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  192. dev_warn(&req->adapter->ccw_device->dev,
  193. "The fibre channel fabric does not support NPIV\n");
  194. break;
  195. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  196. dev_warn(&req->adapter->ccw_device->dev,
  197. "The FCP adapter cannot support more NPIV ports\n");
  198. break;
  199. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  200. dev_warn(&req->adapter->ccw_device->dev,
  201. "The adjacent switch cannot support "
  202. "more NPIV ports\n");
  203. break;
  204. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  205. dev_warn(&req->adapter->ccw_device->dev,
  206. "The FCP adapter could not log in to the "
  207. "fibre channel fabric\n");
  208. break;
  209. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  210. dev_warn(&req->adapter->ccw_device->dev,
  211. "The WWPN assignment file on the FCP adapter "
  212. "has been damaged\n");
  213. break;
  214. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  215. dev_warn(&req->adapter->ccw_device->dev,
  216. "The mode table on the FCP adapter "
  217. "has been damaged\n");
  218. break;
  219. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  220. dev_warn(&req->adapter->ccw_device->dev,
  221. "All NPIV ports on the FCP adapter have "
  222. "been assigned\n");
  223. break;
  224. default:
  225. dev_warn(&req->adapter->ccw_device->dev,
  226. "The link between the FCP adapter and "
  227. "the FC fabric is down\n");
  228. }
  229. out:
  230. zfcp_erp_adapter_failed(adapter, id, req);
  231. }
  232. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  233. {
  234. struct fsf_status_read_buffer *sr_buf = req->data;
  235. struct fsf_link_down_info *ldi =
  236. (struct fsf_link_down_info *) &sr_buf->payload;
  237. switch (sr_buf->status_subtype) {
  238. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  239. zfcp_fsf_link_down_info_eval(req, 38, ldi);
  240. break;
  241. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  242. zfcp_fsf_link_down_info_eval(req, 39, ldi);
  243. break;
  244. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  245. zfcp_fsf_link_down_info_eval(req, 40, NULL);
  246. };
  247. }
  248. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  249. {
  250. struct zfcp_adapter *adapter = req->adapter;
  251. struct fsf_status_read_buffer *sr_buf = req->data;
  252. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  253. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  254. mempool_free(sr_buf, adapter->pool.data_status_read);
  255. zfcp_fsf_req_free(req);
  256. return;
  257. }
  258. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  259. switch (sr_buf->status_type) {
  260. case FSF_STATUS_READ_PORT_CLOSED:
  261. zfcp_fsf_status_read_port_closed(req);
  262. break;
  263. case FSF_STATUS_READ_INCOMING_ELS:
  264. zfcp_fc_incoming_els(req);
  265. break;
  266. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  267. break;
  268. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  269. dev_warn(&adapter->ccw_device->dev,
  270. "The error threshold for checksum statistics "
  271. "has been exceeded\n");
  272. zfcp_hba_dbf_event_berr(adapter, req);
  273. break;
  274. case FSF_STATUS_READ_LINK_DOWN:
  275. zfcp_fsf_status_read_link_down(req);
  276. break;
  277. case FSF_STATUS_READ_LINK_UP:
  278. dev_info(&adapter->ccw_device->dev,
  279. "The local link has been restored\n");
  280. /* All ports should be marked as ready to run again */
  281. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  282. ZFCP_STATUS_COMMON_RUNNING,
  283. ZFCP_SET);
  284. zfcp_erp_adapter_reopen(adapter,
  285. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  286. ZFCP_STATUS_COMMON_ERP_FAILED,
  287. 102, req);
  288. break;
  289. case FSF_STATUS_READ_NOTIFICATION_LOST:
  290. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  291. zfcp_erp_adapter_access_changed(adapter, 135, req);
  292. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  293. schedule_work(&adapter->scan_work);
  294. break;
  295. case FSF_STATUS_READ_CFDC_UPDATED:
  296. zfcp_erp_adapter_access_changed(adapter, 136, req);
  297. break;
  298. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  299. adapter->adapter_features = sr_buf->payload.word[0];
  300. break;
  301. }
  302. mempool_free(sr_buf, adapter->pool.data_status_read);
  303. zfcp_fsf_req_free(req);
  304. atomic_inc(&adapter->stat_miss);
  305. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  306. }
  307. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  308. {
  309. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  310. case FSF_SQ_FCP_RSP_AVAILABLE:
  311. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  312. case FSF_SQ_NO_RETRY_POSSIBLE:
  313. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  314. return;
  315. case FSF_SQ_COMMAND_ABORTED:
  316. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  317. break;
  318. case FSF_SQ_NO_RECOM:
  319. dev_err(&req->adapter->ccw_device->dev,
  320. "The FCP adapter reported a problem "
  321. "that cannot be recovered\n");
  322. zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
  323. break;
  324. }
  325. /* all non-return stats set FSFREQ_ERROR*/
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. }
  328. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  329. {
  330. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  331. return;
  332. switch (req->qtcb->header.fsf_status) {
  333. case FSF_UNKNOWN_COMMAND:
  334. dev_err(&req->adapter->ccw_device->dev,
  335. "The FCP adapter does not recognize the command 0x%x\n",
  336. req->qtcb->header.fsf_command);
  337. zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
  338. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  339. break;
  340. case FSF_ADAPTER_STATUS_AVAILABLE:
  341. zfcp_fsf_fsfstatus_qual_eval(req);
  342. break;
  343. }
  344. }
  345. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  346. {
  347. struct zfcp_adapter *adapter = req->adapter;
  348. struct fsf_qtcb *qtcb = req->qtcb;
  349. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  350. zfcp_hba_dbf_event_fsf_response(req);
  351. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  352. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  353. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  354. return;
  355. }
  356. switch (qtcb->prefix.prot_status) {
  357. case FSF_PROT_GOOD:
  358. case FSF_PROT_FSF_STATUS_PRESENTED:
  359. return;
  360. case FSF_PROT_QTCB_VERSION_ERROR:
  361. dev_err(&adapter->ccw_device->dev,
  362. "QTCB version 0x%x not supported by FCP adapter "
  363. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  364. psq->word[0], psq->word[1]);
  365. zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
  366. break;
  367. case FSF_PROT_ERROR_STATE:
  368. case FSF_PROT_SEQ_NUMB_ERROR:
  369. zfcp_erp_adapter_reopen(adapter, 0, 98, req);
  370. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  371. break;
  372. case FSF_PROT_UNSUPP_QTCB_TYPE:
  373. dev_err(&adapter->ccw_device->dev,
  374. "The QTCB type is not supported by the FCP adapter\n");
  375. zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
  376. break;
  377. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  378. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  379. &adapter->status);
  380. break;
  381. case FSF_PROT_DUPLICATE_REQUEST_ID:
  382. dev_err(&adapter->ccw_device->dev,
  383. "0x%Lx is an ambiguous request identifier\n",
  384. (unsigned long long)qtcb->bottom.support.req_handle);
  385. zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
  386. break;
  387. case FSF_PROT_LINK_DOWN:
  388. zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
  389. /* FIXME: reopening adapter now? better wait for link up */
  390. zfcp_erp_adapter_reopen(adapter, 0, 79, req);
  391. break;
  392. case FSF_PROT_REEST_QUEUE:
  393. /* All ports should be marked as ready to run again */
  394. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  395. ZFCP_STATUS_COMMON_RUNNING,
  396. ZFCP_SET);
  397. zfcp_erp_adapter_reopen(adapter,
  398. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  399. ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
  400. break;
  401. default:
  402. dev_err(&adapter->ccw_device->dev,
  403. "0x%x is not a valid transfer protocol status\n",
  404. qtcb->prefix.prot_status);
  405. zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
  406. }
  407. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  408. }
  409. /**
  410. * zfcp_fsf_req_complete - process completion of a FSF request
  411. * @fsf_req: The FSF request that has been completed.
  412. *
  413. * When a request has been completed either from the FCP adapter,
  414. * or it has been dismissed due to a queue shutdown, this function
  415. * is called to process the completion status and trigger further
  416. * events related to the FSF request.
  417. */
  418. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  419. {
  420. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  421. zfcp_fsf_status_read_handler(req);
  422. return;
  423. }
  424. del_timer(&req->timer);
  425. zfcp_fsf_protstatus_eval(req);
  426. zfcp_fsf_fsfstatus_eval(req);
  427. req->handler(req);
  428. if (req->erp_action)
  429. zfcp_erp_notify(req->erp_action, 0);
  430. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  431. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  432. zfcp_fsf_req_free(req);
  433. else
  434. /* notify initiator waiting for the requests completion */
  435. /*
  436. * FIXME: Race! We must not access fsf_req here as it might have been
  437. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  438. * flag. It's an improbable case. But, we have the same paranoia for
  439. * the cleanup flag already.
  440. * Might better be handled using complete()?
  441. * (setting the flag and doing wakeup ought to be atomic
  442. * with regard to checking the flag as long as waitqueue is
  443. * part of the to be released structure)
  444. */
  445. wake_up(&req->completion_wq);
  446. }
  447. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  448. {
  449. struct fsf_qtcb_bottom_config *bottom;
  450. struct zfcp_adapter *adapter = req->adapter;
  451. struct Scsi_Host *shost = adapter->scsi_host;
  452. bottom = &req->qtcb->bottom.config;
  453. if (req->data)
  454. memcpy(req->data, bottom, sizeof(*bottom));
  455. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  456. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  457. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  458. fc_host_speed(shost) = bottom->fc_link_speed;
  459. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  460. adapter->hydra_version = bottom->adapter_type;
  461. adapter->timer_ticks = bottom->timer_interval;
  462. if (fc_host_permanent_port_name(shost) == -1)
  463. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  464. switch (bottom->fc_topology) {
  465. case FSF_TOPO_P2P:
  466. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  467. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  468. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  469. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  470. break;
  471. case FSF_TOPO_FABRIC:
  472. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  473. break;
  474. case FSF_TOPO_AL:
  475. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  476. default:
  477. dev_err(&adapter->ccw_device->dev,
  478. "Unknown or unsupported arbitrated loop "
  479. "fibre channel topology detected\n");
  480. zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
  481. return -EIO;
  482. }
  483. return 0;
  484. }
  485. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  486. {
  487. struct zfcp_adapter *adapter = req->adapter;
  488. struct fsf_qtcb *qtcb = req->qtcb;
  489. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  490. struct Scsi_Host *shost = adapter->scsi_host;
  491. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  492. return;
  493. adapter->fsf_lic_version = bottom->lic_version;
  494. adapter->adapter_features = bottom->adapter_features;
  495. adapter->connection_features = bottom->connection_features;
  496. adapter->peer_wwpn = 0;
  497. adapter->peer_wwnn = 0;
  498. adapter->peer_d_id = 0;
  499. switch (qtcb->header.fsf_status) {
  500. case FSF_GOOD:
  501. if (zfcp_fsf_exchange_config_evaluate(req))
  502. return;
  503. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  504. dev_err(&adapter->ccw_device->dev,
  505. "FCP adapter maximum QTCB size (%d bytes) "
  506. "is too small\n",
  507. bottom->max_qtcb_size);
  508. zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
  509. return;
  510. }
  511. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  512. &adapter->status);
  513. break;
  514. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  515. fc_host_node_name(shost) = 0;
  516. fc_host_port_name(shost) = 0;
  517. fc_host_port_id(shost) = 0;
  518. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  519. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  520. adapter->hydra_version = 0;
  521. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  522. &adapter->status);
  523. zfcp_fsf_link_down_info_eval(req, 42,
  524. &qtcb->header.fsf_status_qual.link_down_info);
  525. break;
  526. default:
  527. zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
  528. return;
  529. }
  530. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  531. adapter->hardware_version = bottom->hardware_version;
  532. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  533. min(FC_SERIAL_NUMBER_SIZE, 17));
  534. EBCASC(fc_host_serial_number(shost),
  535. min(FC_SERIAL_NUMBER_SIZE, 17));
  536. }
  537. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  538. dev_err(&adapter->ccw_device->dev,
  539. "The FCP adapter only supports newer "
  540. "control block versions\n");
  541. zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
  542. return;
  543. }
  544. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  545. dev_err(&adapter->ccw_device->dev,
  546. "The FCP adapter only supports older "
  547. "control block versions\n");
  548. zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
  549. }
  550. }
  551. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  552. {
  553. struct zfcp_adapter *adapter = req->adapter;
  554. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  555. struct Scsi_Host *shost = adapter->scsi_host;
  556. if (req->data)
  557. memcpy(req->data, bottom, sizeof(*bottom));
  558. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  559. fc_host_permanent_port_name(shost) = bottom->wwpn;
  560. else
  561. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  562. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  563. fc_host_supported_speeds(shost) = bottom->supported_speed;
  564. }
  565. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  566. {
  567. struct fsf_qtcb *qtcb = req->qtcb;
  568. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  569. return;
  570. switch (qtcb->header.fsf_status) {
  571. case FSF_GOOD:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. break;
  574. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  575. zfcp_fsf_exchange_port_evaluate(req);
  576. zfcp_fsf_link_down_info_eval(req, 43,
  577. &qtcb->header.fsf_status_qual.link_down_info);
  578. break;
  579. }
  580. }
  581. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  582. {
  583. if (atomic_read(&adapter->req_q.count) > 0)
  584. return 1;
  585. atomic_inc(&adapter->qdio_outb_full);
  586. return 0;
  587. }
  588. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  589. __releases(&adapter->req_q_lock)
  590. __acquires(&adapter->req_q_lock)
  591. {
  592. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  593. long ret;
  594. if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
  595. return -EIO;
  596. if (atomic_read(&req_q->count) > 0)
  597. return 0;
  598. atomic_dec(&req_q->count);
  599. spin_unlock_bh(&adapter->req_q_lock);
  600. ret = wait_event_interruptible_timeout(adapter->request_wq,
  601. atomic_read(&req_q->count) >= 0,
  602. 5 * HZ);
  603. spin_lock_bh(&adapter->req_q_lock);
  604. atomic_inc(&req_q->count);
  605. if (ret > 0)
  606. return 0;
  607. if (!ret)
  608. atomic_inc(&adapter->qdio_outb_full);
  609. return -EIO;
  610. }
  611. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  612. {
  613. struct zfcp_fsf_req *req;
  614. req = mempool_alloc(pool, GFP_ATOMIC);
  615. if (!req)
  616. return NULL;
  617. memset(req, 0, sizeof(*req));
  618. req->pool = pool;
  619. return req;
  620. }
  621. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  622. {
  623. struct zfcp_fsf_req_qtcb *qtcb;
  624. if (likely(pool))
  625. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  626. else
  627. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  628. GFP_ATOMIC);
  629. if (unlikely(!qtcb))
  630. return NULL;
  631. memset(qtcb, 0, sizeof(*qtcb));
  632. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  633. qtcb->fsf_req.pool = pool;
  634. return &qtcb->fsf_req;
  635. }
  636. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  637. u32 fsf_cmd, int req_flags,
  638. mempool_t *pool)
  639. {
  640. struct qdio_buffer_element *sbale;
  641. struct zfcp_fsf_req *req;
  642. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  643. if (req_flags & ZFCP_REQ_NO_QTCB)
  644. req = zfcp_fsf_alloc_noqtcb(pool);
  645. else
  646. req = zfcp_fsf_alloc_qtcb(pool);
  647. if (unlikely(!req))
  648. return ERR_PTR(-EIO);
  649. if (adapter->req_no == 0)
  650. adapter->req_no++;
  651. INIT_LIST_HEAD(&req->list);
  652. init_timer(&req->timer);
  653. init_waitqueue_head(&req->completion_wq);
  654. req->adapter = adapter;
  655. req->fsf_command = fsf_cmd;
  656. req->req_id = adapter->req_no;
  657. req->sbal_number = 1;
  658. req->sbal_first = req_q->first;
  659. req->sbal_last = req_q->first;
  660. req->sbale_curr = 1;
  661. sbale = zfcp_qdio_sbale_req(req);
  662. sbale[0].addr = (void *) req->req_id;
  663. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  664. if (likely(req->qtcb)) {
  665. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  666. req->qtcb->prefix.req_id = req->req_id;
  667. req->qtcb->prefix.ulp_info = 26;
  668. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  669. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  670. req->qtcb->header.req_handle = req->req_id;
  671. req->qtcb->header.fsf_command = req->fsf_command;
  672. req->seq_no = adapter->fsf_req_seq_no;
  673. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  674. sbale[1].addr = (void *) req->qtcb;
  675. sbale[1].length = sizeof(struct fsf_qtcb);
  676. }
  677. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  678. zfcp_fsf_req_free(req);
  679. return ERR_PTR(-EIO);
  680. }
  681. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  682. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  683. return req;
  684. }
  685. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  686. {
  687. struct zfcp_adapter *adapter = req->adapter;
  688. unsigned long flags;
  689. int idx;
  690. /* put allocated FSF request into hash table */
  691. spin_lock_irqsave(&adapter->req_list_lock, flags);
  692. idx = zfcp_reqlist_hash(req->req_id);
  693. list_add_tail(&req->list, &adapter->req_list[idx]);
  694. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  695. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  696. req->issued = get_clock();
  697. if (zfcp_qdio_send(req)) {
  698. del_timer(&req->timer);
  699. spin_lock_irqsave(&adapter->req_list_lock, flags);
  700. /* lookup request again, list might have changed */
  701. if (zfcp_reqlist_find_safe(adapter, req))
  702. zfcp_reqlist_remove(adapter, req);
  703. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  704. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  705. return -EIO;
  706. }
  707. /* Don't increase for unsolicited status */
  708. if (req->qtcb)
  709. adapter->fsf_req_seq_no++;
  710. adapter->req_no++;
  711. return 0;
  712. }
  713. /**
  714. * zfcp_fsf_status_read - send status read request
  715. * @adapter: pointer to struct zfcp_adapter
  716. * @req_flags: request flags
  717. * Returns: 0 on success, ERROR otherwise
  718. */
  719. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  720. {
  721. struct zfcp_fsf_req *req;
  722. struct fsf_status_read_buffer *sr_buf;
  723. struct qdio_buffer_element *sbale;
  724. int retval = -EIO;
  725. spin_lock_bh(&adapter->req_q_lock);
  726. if (zfcp_fsf_req_sbal_get(adapter))
  727. goto out;
  728. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  729. ZFCP_REQ_NO_QTCB,
  730. adapter->pool.fsf_req_status_read);
  731. if (IS_ERR(req)) {
  732. retval = PTR_ERR(req);
  733. goto out;
  734. }
  735. sbale = zfcp_qdio_sbale_req(req);
  736. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  737. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  738. req->sbale_curr = 2;
  739. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  740. if (!sr_buf) {
  741. retval = -ENOMEM;
  742. goto failed_buf;
  743. }
  744. memset(sr_buf, 0, sizeof(*sr_buf));
  745. req->data = sr_buf;
  746. sbale = zfcp_qdio_sbale_curr(req);
  747. sbale->addr = (void *) sr_buf;
  748. sbale->length = sizeof(*sr_buf);
  749. retval = zfcp_fsf_req_send(req);
  750. if (retval)
  751. goto failed_req_send;
  752. goto out;
  753. failed_req_send:
  754. mempool_free(sr_buf, adapter->pool.data_status_read);
  755. failed_buf:
  756. zfcp_fsf_req_free(req);
  757. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  758. out:
  759. spin_unlock_bh(&adapter->req_q_lock);
  760. return retval;
  761. }
  762. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  763. {
  764. struct zfcp_unit *unit = req->data;
  765. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  766. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  767. return;
  768. switch (req->qtcb->header.fsf_status) {
  769. case FSF_PORT_HANDLE_NOT_VALID:
  770. if (fsq->word[0] == fsq->word[1]) {
  771. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  772. req);
  773. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  774. }
  775. break;
  776. case FSF_LUN_HANDLE_NOT_VALID:
  777. if (fsq->word[0] == fsq->word[1]) {
  778. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  779. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  780. }
  781. break;
  782. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  783. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  784. break;
  785. case FSF_PORT_BOXED:
  786. zfcp_erp_port_boxed(unit->port, 47, req);
  787. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  788. ZFCP_STATUS_FSFREQ_RETRY;
  789. break;
  790. case FSF_LUN_BOXED:
  791. zfcp_erp_unit_boxed(unit, 48, req);
  792. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  793. ZFCP_STATUS_FSFREQ_RETRY;
  794. break;
  795. case FSF_ADAPTER_STATUS_AVAILABLE:
  796. switch (fsq->word[0]) {
  797. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  798. zfcp_test_link(unit->port);
  799. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  800. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  801. break;
  802. }
  803. break;
  804. case FSF_GOOD:
  805. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  806. break;
  807. }
  808. }
  809. /**
  810. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  811. * @old_req_id: unsigned long
  812. * @adapter: pointer to struct zfcp_adapter
  813. * @unit: pointer to struct zfcp_unit
  814. * @req_flags: integer specifying the request flags
  815. * Returns: pointer to struct zfcp_fsf_req
  816. *
  817. * FIXME(design): should be watched by a timeout !!!
  818. */
  819. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  820. struct zfcp_adapter *adapter,
  821. struct zfcp_unit *unit,
  822. int req_flags)
  823. {
  824. struct qdio_buffer_element *sbale;
  825. struct zfcp_fsf_req *req = NULL;
  826. spin_lock_bh(&adapter->req_q_lock);
  827. if (zfcp_fsf_req_sbal_get(adapter))
  828. goto out;
  829. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  830. req_flags, adapter->pool.fsf_req_abort);
  831. if (IS_ERR(req)) {
  832. req = NULL;
  833. goto out;
  834. }
  835. if (unlikely(!(atomic_read(&unit->status) &
  836. ZFCP_STATUS_COMMON_UNBLOCKED)))
  837. goto out_error_free;
  838. sbale = zfcp_qdio_sbale_req(req);
  839. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  840. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  841. req->data = unit;
  842. req->handler = zfcp_fsf_abort_fcp_command_handler;
  843. req->qtcb->header.lun_handle = unit->handle;
  844. req->qtcb->header.port_handle = unit->port->handle;
  845. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  846. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  847. if (!zfcp_fsf_req_send(req))
  848. goto out;
  849. out_error_free:
  850. zfcp_fsf_req_free(req);
  851. req = NULL;
  852. out:
  853. spin_unlock_bh(&adapter->req_q_lock);
  854. return req;
  855. }
  856. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  857. {
  858. struct zfcp_adapter *adapter = req->adapter;
  859. struct zfcp_send_ct *send_ct = req->data;
  860. struct fsf_qtcb_header *header = &req->qtcb->header;
  861. send_ct->status = -EINVAL;
  862. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  863. goto skip_fsfstatus;
  864. switch (header->fsf_status) {
  865. case FSF_GOOD:
  866. zfcp_san_dbf_event_ct_response(req);
  867. send_ct->status = 0;
  868. break;
  869. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  870. zfcp_fsf_class_not_supp(req);
  871. break;
  872. case FSF_ADAPTER_STATUS_AVAILABLE:
  873. switch (header->fsf_status_qual.word[0]){
  874. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  875. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  876. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  877. break;
  878. }
  879. break;
  880. case FSF_ACCESS_DENIED:
  881. break;
  882. case FSF_PORT_BOXED:
  883. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  884. ZFCP_STATUS_FSFREQ_RETRY;
  885. break;
  886. case FSF_PORT_HANDLE_NOT_VALID:
  887. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  888. case FSF_GENERIC_COMMAND_REJECTED:
  889. case FSF_PAYLOAD_SIZE_MISMATCH:
  890. case FSF_REQUEST_SIZE_TOO_LARGE:
  891. case FSF_RESPONSE_SIZE_TOO_LARGE:
  892. case FSF_SBAL_MISMATCH:
  893. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  894. break;
  895. }
  896. skip_fsfstatus:
  897. if (send_ct->handler)
  898. send_ct->handler(send_ct->handler_data);
  899. }
  900. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  901. struct scatterlist *sg_req,
  902. struct scatterlist *sg_resp,
  903. int max_sbals)
  904. {
  905. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  906. u32 feat = req->adapter->adapter_features;
  907. int bytes;
  908. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  909. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  910. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  911. return -EOPNOTSUPP;
  912. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  913. sbale[2].addr = sg_virt(sg_req);
  914. sbale[2].length = sg_req->length;
  915. sbale[3].addr = sg_virt(sg_resp);
  916. sbale[3].length = sg_resp->length;
  917. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  918. return 0;
  919. }
  920. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  921. sg_req, max_sbals);
  922. if (bytes <= 0)
  923. return -ENOMEM;
  924. req->qtcb->bottom.support.req_buf_length = bytes;
  925. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  926. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  927. sg_resp, max_sbals);
  928. if (bytes <= 0)
  929. return -ENOMEM;
  930. req->qtcb->bottom.support.resp_buf_length = bytes;
  931. return 0;
  932. }
  933. /**
  934. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  935. * @ct: pointer to struct zfcp_send_ct with data for request
  936. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  937. * @erp_action: if non-null the Generic Service request sent within ERP
  938. */
  939. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  940. struct zfcp_erp_action *erp_action)
  941. {
  942. struct zfcp_wka_port *wka_port = ct->wka_port;
  943. struct zfcp_adapter *adapter = wka_port->adapter;
  944. struct zfcp_fsf_req *req;
  945. int ret = -EIO;
  946. spin_lock_bh(&adapter->req_q_lock);
  947. if (zfcp_fsf_req_sbal_get(adapter))
  948. goto out;
  949. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  950. ZFCP_REQ_AUTO_CLEANUP, pool);
  951. if (IS_ERR(req)) {
  952. ret = PTR_ERR(req);
  953. goto out;
  954. }
  955. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  956. FSF_MAX_SBALS_PER_REQ);
  957. if (ret)
  958. goto failed_send;
  959. req->handler = zfcp_fsf_send_ct_handler;
  960. req->qtcb->header.port_handle = wka_port->handle;
  961. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  962. req->qtcb->bottom.support.timeout = ct->timeout;
  963. req->data = ct;
  964. zfcp_san_dbf_event_ct_request(req);
  965. if (erp_action) {
  966. erp_action->fsf_req = req;
  967. req->erp_action = erp_action;
  968. zfcp_fsf_start_erp_timer(req);
  969. } else
  970. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  971. ret = zfcp_fsf_req_send(req);
  972. if (ret)
  973. goto failed_send;
  974. goto out;
  975. failed_send:
  976. zfcp_fsf_req_free(req);
  977. if (erp_action)
  978. erp_action->fsf_req = NULL;
  979. out:
  980. spin_unlock_bh(&adapter->req_q_lock);
  981. return ret;
  982. }
  983. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  984. {
  985. struct zfcp_send_els *send_els = req->data;
  986. struct zfcp_port *port = send_els->port;
  987. struct fsf_qtcb_header *header = &req->qtcb->header;
  988. send_els->status = -EINVAL;
  989. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  990. goto skip_fsfstatus;
  991. switch (header->fsf_status) {
  992. case FSF_GOOD:
  993. zfcp_san_dbf_event_els_response(req);
  994. send_els->status = 0;
  995. break;
  996. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  997. zfcp_fsf_class_not_supp(req);
  998. break;
  999. case FSF_ADAPTER_STATUS_AVAILABLE:
  1000. switch (header->fsf_status_qual.word[0]){
  1001. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1002. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1003. zfcp_test_link(port);
  1004. /*fall through */
  1005. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1006. case FSF_SQ_RETRY_IF_POSSIBLE:
  1007. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1008. break;
  1009. }
  1010. break;
  1011. case FSF_ELS_COMMAND_REJECTED:
  1012. case FSF_PAYLOAD_SIZE_MISMATCH:
  1013. case FSF_REQUEST_SIZE_TOO_LARGE:
  1014. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1015. break;
  1016. case FSF_ACCESS_DENIED:
  1017. zfcp_fsf_access_denied_port(req, port);
  1018. break;
  1019. case FSF_SBAL_MISMATCH:
  1020. /* should never occure, avoided in zfcp_fsf_send_els */
  1021. /* fall through */
  1022. default:
  1023. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1024. break;
  1025. }
  1026. skip_fsfstatus:
  1027. if (send_els->handler)
  1028. send_els->handler(send_els->handler_data);
  1029. }
  1030. /**
  1031. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1032. * @els: pointer to struct zfcp_send_els with data for the command
  1033. */
  1034. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1035. {
  1036. struct zfcp_fsf_req *req;
  1037. struct zfcp_adapter *adapter = els->adapter;
  1038. struct fsf_qtcb_bottom_support *bottom;
  1039. int ret = -EIO;
  1040. if (unlikely(!(atomic_read(&els->port->status) &
  1041. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1042. return -EBUSY;
  1043. spin_lock(&adapter->req_q_lock);
  1044. if (!zfcp_fsf_sbal_available(adapter))
  1045. goto out;
  1046. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1047. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1048. if (IS_ERR(req)) {
  1049. ret = PTR_ERR(req);
  1050. goto out;
  1051. }
  1052. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1053. if (ret)
  1054. goto failed_send;
  1055. bottom = &req->qtcb->bottom.support;
  1056. req->handler = zfcp_fsf_send_els_handler;
  1057. bottom->d_id = els->d_id;
  1058. bottom->service_class = FSF_CLASS_3;
  1059. bottom->timeout = 2 * R_A_TOV;
  1060. req->data = els;
  1061. zfcp_san_dbf_event_els_request(req);
  1062. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1063. ret = zfcp_fsf_req_send(req);
  1064. if (ret)
  1065. goto failed_send;
  1066. goto out;
  1067. failed_send:
  1068. zfcp_fsf_req_free(req);
  1069. out:
  1070. spin_unlock(&adapter->req_q_lock);
  1071. return ret;
  1072. }
  1073. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1074. {
  1075. struct qdio_buffer_element *sbale;
  1076. struct zfcp_fsf_req *req;
  1077. struct zfcp_adapter *adapter = erp_action->adapter;
  1078. int retval = -EIO;
  1079. spin_lock_bh(&adapter->req_q_lock);
  1080. if (zfcp_fsf_req_sbal_get(adapter))
  1081. goto out;
  1082. req = zfcp_fsf_req_create(adapter,
  1083. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1084. ZFCP_REQ_AUTO_CLEANUP,
  1085. adapter->pool.fsf_req_erp);
  1086. if (IS_ERR(req)) {
  1087. retval = PTR_ERR(req);
  1088. goto out;
  1089. }
  1090. sbale = zfcp_qdio_sbale_req(req);
  1091. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1092. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1093. req->qtcb->bottom.config.feature_selection =
  1094. FSF_FEATURE_CFDC |
  1095. FSF_FEATURE_LUN_SHARING |
  1096. FSF_FEATURE_NOTIFICATION_LOST |
  1097. FSF_FEATURE_UPDATE_ALERT;
  1098. req->erp_action = erp_action;
  1099. req->handler = zfcp_fsf_exchange_config_data_handler;
  1100. erp_action->fsf_req = req;
  1101. zfcp_fsf_start_erp_timer(req);
  1102. retval = zfcp_fsf_req_send(req);
  1103. if (retval) {
  1104. zfcp_fsf_req_free(req);
  1105. erp_action->fsf_req = NULL;
  1106. }
  1107. out:
  1108. spin_unlock_bh(&adapter->req_q_lock);
  1109. return retval;
  1110. }
  1111. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1112. struct fsf_qtcb_bottom_config *data)
  1113. {
  1114. struct qdio_buffer_element *sbale;
  1115. struct zfcp_fsf_req *req = NULL;
  1116. int retval = -EIO;
  1117. spin_lock_bh(&adapter->req_q_lock);
  1118. if (zfcp_fsf_req_sbal_get(adapter))
  1119. goto out;
  1120. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1121. 0, NULL);
  1122. if (IS_ERR(req)) {
  1123. retval = PTR_ERR(req);
  1124. goto out;
  1125. }
  1126. sbale = zfcp_qdio_sbale_req(req);
  1127. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1128. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1129. req->handler = zfcp_fsf_exchange_config_data_handler;
  1130. req->qtcb->bottom.config.feature_selection =
  1131. FSF_FEATURE_CFDC |
  1132. FSF_FEATURE_LUN_SHARING |
  1133. FSF_FEATURE_NOTIFICATION_LOST |
  1134. FSF_FEATURE_UPDATE_ALERT;
  1135. if (data)
  1136. req->data = data;
  1137. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1138. retval = zfcp_fsf_req_send(req);
  1139. out:
  1140. spin_unlock_bh(&adapter->req_q_lock);
  1141. if (!retval)
  1142. wait_event(req->completion_wq,
  1143. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1144. zfcp_fsf_req_free(req);
  1145. return retval;
  1146. }
  1147. /**
  1148. * zfcp_fsf_exchange_port_data - request information about local port
  1149. * @erp_action: ERP action for the adapter for which port data is requested
  1150. * Returns: 0 on success, error otherwise
  1151. */
  1152. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1153. {
  1154. struct qdio_buffer_element *sbale;
  1155. struct zfcp_fsf_req *req;
  1156. struct zfcp_adapter *adapter = erp_action->adapter;
  1157. int retval = -EIO;
  1158. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1159. return -EOPNOTSUPP;
  1160. spin_lock_bh(&adapter->req_q_lock);
  1161. if (zfcp_fsf_req_sbal_get(adapter))
  1162. goto out;
  1163. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1164. ZFCP_REQ_AUTO_CLEANUP,
  1165. adapter->pool.fsf_req_erp);
  1166. if (IS_ERR(req)) {
  1167. retval = PTR_ERR(req);
  1168. goto out;
  1169. }
  1170. sbale = zfcp_qdio_sbale_req(req);
  1171. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1172. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1173. req->handler = zfcp_fsf_exchange_port_data_handler;
  1174. req->erp_action = erp_action;
  1175. erp_action->fsf_req = req;
  1176. zfcp_fsf_start_erp_timer(req);
  1177. retval = zfcp_fsf_req_send(req);
  1178. if (retval) {
  1179. zfcp_fsf_req_free(req);
  1180. erp_action->fsf_req = NULL;
  1181. }
  1182. out:
  1183. spin_unlock_bh(&adapter->req_q_lock);
  1184. return retval;
  1185. }
  1186. /**
  1187. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1188. * @adapter: pointer to struct zfcp_adapter
  1189. * @data: pointer to struct fsf_qtcb_bottom_port
  1190. * Returns: 0 on success, error otherwise
  1191. */
  1192. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1193. struct fsf_qtcb_bottom_port *data)
  1194. {
  1195. struct qdio_buffer_element *sbale;
  1196. struct zfcp_fsf_req *req = NULL;
  1197. int retval = -EIO;
  1198. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1199. return -EOPNOTSUPP;
  1200. spin_lock_bh(&adapter->req_q_lock);
  1201. if (zfcp_fsf_req_sbal_get(adapter))
  1202. goto out;
  1203. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1204. NULL);
  1205. if (IS_ERR(req)) {
  1206. retval = PTR_ERR(req);
  1207. goto out;
  1208. }
  1209. if (data)
  1210. req->data = data;
  1211. sbale = zfcp_qdio_sbale_req(req);
  1212. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1213. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1214. req->handler = zfcp_fsf_exchange_port_data_handler;
  1215. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1216. retval = zfcp_fsf_req_send(req);
  1217. out:
  1218. spin_unlock_bh(&adapter->req_q_lock);
  1219. if (!retval)
  1220. wait_event(req->completion_wq,
  1221. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1222. zfcp_fsf_req_free(req);
  1223. return retval;
  1224. }
  1225. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1226. {
  1227. struct zfcp_port *port = req->data;
  1228. struct fsf_qtcb_header *header = &req->qtcb->header;
  1229. struct fsf_plogi *plogi;
  1230. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1231. return;
  1232. switch (header->fsf_status) {
  1233. case FSF_PORT_ALREADY_OPEN:
  1234. break;
  1235. case FSF_ACCESS_DENIED:
  1236. zfcp_fsf_access_denied_port(req, port);
  1237. break;
  1238. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1239. dev_warn(&req->adapter->ccw_device->dev,
  1240. "Not enough FCP adapter resources to open "
  1241. "remote port 0x%016Lx\n",
  1242. (unsigned long long)port->wwpn);
  1243. zfcp_erp_port_failed(port, 31, req);
  1244. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1245. break;
  1246. case FSF_ADAPTER_STATUS_AVAILABLE:
  1247. switch (header->fsf_status_qual.word[0]) {
  1248. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1249. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1250. case FSF_SQ_NO_RETRY_POSSIBLE:
  1251. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1252. break;
  1253. }
  1254. break;
  1255. case FSF_GOOD:
  1256. port->handle = header->port_handle;
  1257. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1258. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1259. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1260. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1261. &port->status);
  1262. /* check whether D_ID has changed during open */
  1263. /*
  1264. * FIXME: This check is not airtight, as the FCP channel does
  1265. * not monitor closures of target port connections caused on
  1266. * the remote side. Thus, they might miss out on invalidating
  1267. * locally cached WWPNs (and other N_Port parameters) of gone
  1268. * target ports. So, our heroic attempt to make things safe
  1269. * could be undermined by 'open port' response data tagged with
  1270. * obsolete WWPNs. Another reason to monitor potential
  1271. * connection closures ourself at least (by interpreting
  1272. * incoming ELS' and unsolicited status). It just crosses my
  1273. * mind that one should be able to cross-check by means of
  1274. * another GID_PN straight after a port has been opened.
  1275. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1276. */
  1277. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1278. if (req->qtcb->bottom.support.els1_length >=
  1279. FSF_PLOGI_MIN_LEN) {
  1280. if (plogi->serv_param.wwpn != port->wwpn)
  1281. port->d_id = 0;
  1282. else {
  1283. port->wwnn = plogi->serv_param.wwnn;
  1284. zfcp_fc_plogi_evaluate(port, plogi);
  1285. }
  1286. }
  1287. break;
  1288. case FSF_UNKNOWN_OP_SUBTYPE:
  1289. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1290. break;
  1291. }
  1292. }
  1293. /**
  1294. * zfcp_fsf_open_port - create and send open port request
  1295. * @erp_action: pointer to struct zfcp_erp_action
  1296. * Returns: 0 on success, error otherwise
  1297. */
  1298. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1299. {
  1300. struct qdio_buffer_element *sbale;
  1301. struct zfcp_adapter *adapter = erp_action->adapter;
  1302. struct zfcp_fsf_req *req;
  1303. int retval = -EIO;
  1304. spin_lock_bh(&adapter->req_q_lock);
  1305. if (zfcp_fsf_req_sbal_get(adapter))
  1306. goto out;
  1307. req = zfcp_fsf_req_create(adapter,
  1308. FSF_QTCB_OPEN_PORT_WITH_DID,
  1309. ZFCP_REQ_AUTO_CLEANUP,
  1310. adapter->pool.fsf_req_erp);
  1311. if (IS_ERR(req)) {
  1312. retval = PTR_ERR(req);
  1313. goto out;
  1314. }
  1315. sbale = zfcp_qdio_sbale_req(req);
  1316. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1317. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1318. req->handler = zfcp_fsf_open_port_handler;
  1319. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1320. req->data = erp_action->port;
  1321. req->erp_action = erp_action;
  1322. erp_action->fsf_req = req;
  1323. zfcp_fsf_start_erp_timer(req);
  1324. retval = zfcp_fsf_req_send(req);
  1325. if (retval) {
  1326. zfcp_fsf_req_free(req);
  1327. erp_action->fsf_req = NULL;
  1328. }
  1329. out:
  1330. spin_unlock_bh(&adapter->req_q_lock);
  1331. return retval;
  1332. }
  1333. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1334. {
  1335. struct zfcp_port *port = req->data;
  1336. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1337. return;
  1338. switch (req->qtcb->header.fsf_status) {
  1339. case FSF_PORT_HANDLE_NOT_VALID:
  1340. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1341. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1342. break;
  1343. case FSF_ADAPTER_STATUS_AVAILABLE:
  1344. break;
  1345. case FSF_GOOD:
  1346. zfcp_erp_modify_port_status(port, 33, req,
  1347. ZFCP_STATUS_COMMON_OPEN,
  1348. ZFCP_CLEAR);
  1349. break;
  1350. }
  1351. }
  1352. /**
  1353. * zfcp_fsf_close_port - create and send close port request
  1354. * @erp_action: pointer to struct zfcp_erp_action
  1355. * Returns: 0 on success, error otherwise
  1356. */
  1357. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1358. {
  1359. struct qdio_buffer_element *sbale;
  1360. struct zfcp_adapter *adapter = erp_action->adapter;
  1361. struct zfcp_fsf_req *req;
  1362. int retval = -EIO;
  1363. spin_lock_bh(&adapter->req_q_lock);
  1364. if (zfcp_fsf_req_sbal_get(adapter))
  1365. goto out;
  1366. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1367. ZFCP_REQ_AUTO_CLEANUP,
  1368. adapter->pool.fsf_req_erp);
  1369. if (IS_ERR(req)) {
  1370. retval = PTR_ERR(req);
  1371. goto out;
  1372. }
  1373. sbale = zfcp_qdio_sbale_req(req);
  1374. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1375. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1376. req->handler = zfcp_fsf_close_port_handler;
  1377. req->data = erp_action->port;
  1378. req->erp_action = erp_action;
  1379. req->qtcb->header.port_handle = erp_action->port->handle;
  1380. erp_action->fsf_req = req;
  1381. zfcp_fsf_start_erp_timer(req);
  1382. retval = zfcp_fsf_req_send(req);
  1383. if (retval) {
  1384. zfcp_fsf_req_free(req);
  1385. erp_action->fsf_req = NULL;
  1386. }
  1387. out:
  1388. spin_unlock_bh(&adapter->req_q_lock);
  1389. return retval;
  1390. }
  1391. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1392. {
  1393. struct zfcp_wka_port *wka_port = req->data;
  1394. struct fsf_qtcb_header *header = &req->qtcb->header;
  1395. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1396. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1397. goto out;
  1398. }
  1399. switch (header->fsf_status) {
  1400. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1401. dev_warn(&req->adapter->ccw_device->dev,
  1402. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1403. case FSF_ADAPTER_STATUS_AVAILABLE:
  1404. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1405. case FSF_ACCESS_DENIED:
  1406. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1407. break;
  1408. case FSF_PORT_ALREADY_OPEN:
  1409. break;
  1410. case FSF_GOOD:
  1411. wka_port->handle = header->port_handle;
  1412. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1413. }
  1414. out:
  1415. wake_up(&wka_port->completion_wq);
  1416. }
  1417. /**
  1418. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1419. * @wka_port: pointer to struct zfcp_wka_port
  1420. * Returns: 0 on success, error otherwise
  1421. */
  1422. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1423. {
  1424. struct qdio_buffer_element *sbale;
  1425. struct zfcp_adapter *adapter = wka_port->adapter;
  1426. struct zfcp_fsf_req *req;
  1427. int retval = -EIO;
  1428. spin_lock_bh(&adapter->req_q_lock);
  1429. if (zfcp_fsf_req_sbal_get(adapter))
  1430. goto out;
  1431. req = zfcp_fsf_req_create(adapter,
  1432. FSF_QTCB_OPEN_PORT_WITH_DID,
  1433. ZFCP_REQ_AUTO_CLEANUP,
  1434. adapter->pool.fsf_req_erp);
  1435. if (unlikely(IS_ERR(req))) {
  1436. retval = PTR_ERR(req);
  1437. goto out;
  1438. }
  1439. sbale = zfcp_qdio_sbale_req(req);
  1440. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1441. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1442. req->handler = zfcp_fsf_open_wka_port_handler;
  1443. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1444. req->data = wka_port;
  1445. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1446. retval = zfcp_fsf_req_send(req);
  1447. if (retval)
  1448. zfcp_fsf_req_free(req);
  1449. out:
  1450. spin_unlock_bh(&adapter->req_q_lock);
  1451. return retval;
  1452. }
  1453. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1454. {
  1455. struct zfcp_wka_port *wka_port = req->data;
  1456. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1457. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1458. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
  1459. }
  1460. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1461. wake_up(&wka_port->completion_wq);
  1462. }
  1463. /**
  1464. * zfcp_fsf_close_wka_port - create and send close wka port request
  1465. * @erp_action: pointer to struct zfcp_erp_action
  1466. * Returns: 0 on success, error otherwise
  1467. */
  1468. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1469. {
  1470. struct qdio_buffer_element *sbale;
  1471. struct zfcp_adapter *adapter = wka_port->adapter;
  1472. struct zfcp_fsf_req *req;
  1473. int retval = -EIO;
  1474. spin_lock_bh(&adapter->req_q_lock);
  1475. if (zfcp_fsf_req_sbal_get(adapter))
  1476. goto out;
  1477. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1478. ZFCP_REQ_AUTO_CLEANUP,
  1479. adapter->pool.fsf_req_erp);
  1480. if (unlikely(IS_ERR(req))) {
  1481. retval = PTR_ERR(req);
  1482. goto out;
  1483. }
  1484. sbale = zfcp_qdio_sbale_req(req);
  1485. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1486. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1487. req->handler = zfcp_fsf_close_wka_port_handler;
  1488. req->data = wka_port;
  1489. req->qtcb->header.port_handle = wka_port->handle;
  1490. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1491. retval = zfcp_fsf_req_send(req);
  1492. if (retval)
  1493. zfcp_fsf_req_free(req);
  1494. out:
  1495. spin_unlock_bh(&adapter->req_q_lock);
  1496. return retval;
  1497. }
  1498. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1499. {
  1500. struct zfcp_port *port = req->data;
  1501. struct fsf_qtcb_header *header = &req->qtcb->header;
  1502. struct zfcp_unit *unit;
  1503. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1504. return;
  1505. switch (header->fsf_status) {
  1506. case FSF_PORT_HANDLE_NOT_VALID:
  1507. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1508. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1509. break;
  1510. case FSF_ACCESS_DENIED:
  1511. zfcp_fsf_access_denied_port(req, port);
  1512. break;
  1513. case FSF_PORT_BOXED:
  1514. zfcp_erp_port_boxed(port, 50, req);
  1515. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1516. ZFCP_STATUS_FSFREQ_RETRY;
  1517. /* can't use generic zfcp_erp_modify_port_status because
  1518. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1519. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1520. list_for_each_entry(unit, &port->unit_list_head, list)
  1521. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1522. &unit->status);
  1523. break;
  1524. case FSF_ADAPTER_STATUS_AVAILABLE:
  1525. switch (header->fsf_status_qual.word[0]) {
  1526. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1527. /* fall through */
  1528. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1529. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1530. break;
  1531. }
  1532. break;
  1533. case FSF_GOOD:
  1534. /* can't use generic zfcp_erp_modify_port_status because
  1535. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1536. */
  1537. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1538. list_for_each_entry(unit, &port->unit_list_head, list)
  1539. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1540. &unit->status);
  1541. break;
  1542. }
  1543. }
  1544. /**
  1545. * zfcp_fsf_close_physical_port - close physical port
  1546. * @erp_action: pointer to struct zfcp_erp_action
  1547. * Returns: 0 on success
  1548. */
  1549. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1550. {
  1551. struct qdio_buffer_element *sbale;
  1552. struct zfcp_adapter *adapter = erp_action->adapter;
  1553. struct zfcp_fsf_req *req;
  1554. int retval = -EIO;
  1555. spin_lock_bh(&adapter->req_q_lock);
  1556. if (zfcp_fsf_req_sbal_get(adapter))
  1557. goto out;
  1558. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1559. ZFCP_REQ_AUTO_CLEANUP,
  1560. adapter->pool.fsf_req_erp);
  1561. if (IS_ERR(req)) {
  1562. retval = PTR_ERR(req);
  1563. goto out;
  1564. }
  1565. sbale = zfcp_qdio_sbale_req(req);
  1566. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1567. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1568. req->data = erp_action->port;
  1569. req->qtcb->header.port_handle = erp_action->port->handle;
  1570. req->erp_action = erp_action;
  1571. req->handler = zfcp_fsf_close_physical_port_handler;
  1572. erp_action->fsf_req = req;
  1573. zfcp_fsf_start_erp_timer(req);
  1574. retval = zfcp_fsf_req_send(req);
  1575. if (retval) {
  1576. zfcp_fsf_req_free(req);
  1577. erp_action->fsf_req = NULL;
  1578. }
  1579. out:
  1580. spin_unlock_bh(&adapter->req_q_lock);
  1581. return retval;
  1582. }
  1583. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1584. {
  1585. struct zfcp_adapter *adapter = req->adapter;
  1586. struct zfcp_unit *unit = req->data;
  1587. struct fsf_qtcb_header *header = &req->qtcb->header;
  1588. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1589. struct fsf_queue_designator *queue_designator =
  1590. &header->fsf_status_qual.fsf_queue_designator;
  1591. int exclusive, readwrite;
  1592. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1593. return;
  1594. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1595. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1596. ZFCP_STATUS_UNIT_SHARED |
  1597. ZFCP_STATUS_UNIT_READONLY,
  1598. &unit->status);
  1599. switch (header->fsf_status) {
  1600. case FSF_PORT_HANDLE_NOT_VALID:
  1601. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1602. /* fall through */
  1603. case FSF_LUN_ALREADY_OPEN:
  1604. break;
  1605. case FSF_ACCESS_DENIED:
  1606. zfcp_fsf_access_denied_unit(req, unit);
  1607. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1608. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1609. break;
  1610. case FSF_PORT_BOXED:
  1611. zfcp_erp_port_boxed(unit->port, 51, req);
  1612. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1613. ZFCP_STATUS_FSFREQ_RETRY;
  1614. break;
  1615. case FSF_LUN_SHARING_VIOLATION:
  1616. if (header->fsf_status_qual.word[0])
  1617. dev_warn(&adapter->ccw_device->dev,
  1618. "LUN 0x%Lx on port 0x%Lx is already in "
  1619. "use by CSS%d, MIF Image ID %x\n",
  1620. (unsigned long long)unit->fcp_lun,
  1621. (unsigned long long)unit->port->wwpn,
  1622. queue_designator->cssid,
  1623. queue_designator->hla);
  1624. else
  1625. zfcp_act_eval_err(adapter,
  1626. header->fsf_status_qual.word[2]);
  1627. zfcp_erp_unit_access_denied(unit, 60, req);
  1628. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1629. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1630. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1631. break;
  1632. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1633. dev_warn(&adapter->ccw_device->dev,
  1634. "No handle is available for LUN "
  1635. "0x%016Lx on port 0x%016Lx\n",
  1636. (unsigned long long)unit->fcp_lun,
  1637. (unsigned long long)unit->port->wwpn);
  1638. zfcp_erp_unit_failed(unit, 34, req);
  1639. /* fall through */
  1640. case FSF_INVALID_COMMAND_OPTION:
  1641. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1642. break;
  1643. case FSF_ADAPTER_STATUS_AVAILABLE:
  1644. switch (header->fsf_status_qual.word[0]) {
  1645. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1646. zfcp_test_link(unit->port);
  1647. /* fall through */
  1648. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1649. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1650. break;
  1651. }
  1652. break;
  1653. case FSF_GOOD:
  1654. unit->handle = header->lun_handle;
  1655. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1656. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1657. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1658. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1659. exclusive = (bottom->lun_access_info &
  1660. FSF_UNIT_ACCESS_EXCLUSIVE);
  1661. readwrite = (bottom->lun_access_info &
  1662. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1663. if (!exclusive)
  1664. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1665. &unit->status);
  1666. if (!readwrite) {
  1667. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1668. &unit->status);
  1669. dev_info(&adapter->ccw_device->dev,
  1670. "SCSI device at LUN 0x%016Lx on port "
  1671. "0x%016Lx opened read-only\n",
  1672. (unsigned long long)unit->fcp_lun,
  1673. (unsigned long long)unit->port->wwpn);
  1674. }
  1675. if (exclusive && !readwrite) {
  1676. dev_err(&adapter->ccw_device->dev,
  1677. "Exclusive read-only access not "
  1678. "supported (unit 0x%016Lx, "
  1679. "port 0x%016Lx)\n",
  1680. (unsigned long long)unit->fcp_lun,
  1681. (unsigned long long)unit->port->wwpn);
  1682. zfcp_erp_unit_failed(unit, 35, req);
  1683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1684. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1685. } else if (!exclusive && readwrite) {
  1686. dev_err(&adapter->ccw_device->dev,
  1687. "Shared read-write access not "
  1688. "supported (unit 0x%016Lx, port "
  1689. "0x%016Lx)\n",
  1690. (unsigned long long)unit->fcp_lun,
  1691. (unsigned long long)unit->port->wwpn);
  1692. zfcp_erp_unit_failed(unit, 36, req);
  1693. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1694. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1695. }
  1696. }
  1697. break;
  1698. }
  1699. }
  1700. /**
  1701. * zfcp_fsf_open_unit - open unit
  1702. * @erp_action: pointer to struct zfcp_erp_action
  1703. * Returns: 0 on success, error otherwise
  1704. */
  1705. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1706. {
  1707. struct qdio_buffer_element *sbale;
  1708. struct zfcp_adapter *adapter = erp_action->adapter;
  1709. struct zfcp_fsf_req *req;
  1710. int retval = -EIO;
  1711. spin_lock_bh(&adapter->req_q_lock);
  1712. if (zfcp_fsf_req_sbal_get(adapter))
  1713. goto out;
  1714. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1715. ZFCP_REQ_AUTO_CLEANUP,
  1716. adapter->pool.fsf_req_erp);
  1717. if (IS_ERR(req)) {
  1718. retval = PTR_ERR(req);
  1719. goto out;
  1720. }
  1721. sbale = zfcp_qdio_sbale_req(req);
  1722. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1723. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1724. req->qtcb->header.port_handle = erp_action->port->handle;
  1725. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1726. req->handler = zfcp_fsf_open_unit_handler;
  1727. req->data = erp_action->unit;
  1728. req->erp_action = erp_action;
  1729. erp_action->fsf_req = req;
  1730. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1731. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1732. zfcp_fsf_start_erp_timer(req);
  1733. retval = zfcp_fsf_req_send(req);
  1734. if (retval) {
  1735. zfcp_fsf_req_free(req);
  1736. erp_action->fsf_req = NULL;
  1737. }
  1738. out:
  1739. spin_unlock_bh(&adapter->req_q_lock);
  1740. return retval;
  1741. }
  1742. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1743. {
  1744. struct zfcp_unit *unit = req->data;
  1745. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1746. return;
  1747. switch (req->qtcb->header.fsf_status) {
  1748. case FSF_PORT_HANDLE_NOT_VALID:
  1749. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1750. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1751. break;
  1752. case FSF_LUN_HANDLE_NOT_VALID:
  1753. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1754. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1755. break;
  1756. case FSF_PORT_BOXED:
  1757. zfcp_erp_port_boxed(unit->port, 52, req);
  1758. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1759. ZFCP_STATUS_FSFREQ_RETRY;
  1760. break;
  1761. case FSF_ADAPTER_STATUS_AVAILABLE:
  1762. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1763. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1764. zfcp_test_link(unit->port);
  1765. /* fall through */
  1766. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1767. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1768. break;
  1769. }
  1770. break;
  1771. case FSF_GOOD:
  1772. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1773. break;
  1774. }
  1775. }
  1776. /**
  1777. * zfcp_fsf_close_unit - close zfcp unit
  1778. * @erp_action: pointer to struct zfcp_unit
  1779. * Returns: 0 on success, error otherwise
  1780. */
  1781. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1782. {
  1783. struct qdio_buffer_element *sbale;
  1784. struct zfcp_adapter *adapter = erp_action->adapter;
  1785. struct zfcp_fsf_req *req;
  1786. int retval = -EIO;
  1787. spin_lock_bh(&adapter->req_q_lock);
  1788. if (zfcp_fsf_req_sbal_get(adapter))
  1789. goto out;
  1790. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1791. ZFCP_REQ_AUTO_CLEANUP,
  1792. adapter->pool.fsf_req_erp);
  1793. if (IS_ERR(req)) {
  1794. retval = PTR_ERR(req);
  1795. goto out;
  1796. }
  1797. sbale = zfcp_qdio_sbale_req(req);
  1798. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1799. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1800. req->qtcb->header.port_handle = erp_action->port->handle;
  1801. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1802. req->handler = zfcp_fsf_close_unit_handler;
  1803. req->data = erp_action->unit;
  1804. req->erp_action = erp_action;
  1805. erp_action->fsf_req = req;
  1806. zfcp_fsf_start_erp_timer(req);
  1807. retval = zfcp_fsf_req_send(req);
  1808. if (retval) {
  1809. zfcp_fsf_req_free(req);
  1810. erp_action->fsf_req = NULL;
  1811. }
  1812. out:
  1813. spin_unlock_bh(&adapter->req_q_lock);
  1814. return retval;
  1815. }
  1816. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1817. {
  1818. lat_rec->sum += lat;
  1819. lat_rec->min = min(lat_rec->min, lat);
  1820. lat_rec->max = max(lat_rec->max, lat);
  1821. }
  1822. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1823. {
  1824. struct fsf_qual_latency_info *lat_inf;
  1825. struct latency_cont *lat;
  1826. struct zfcp_unit *unit = req->unit;
  1827. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1828. switch (req->qtcb->bottom.io.data_direction) {
  1829. case FSF_DATADIR_READ:
  1830. lat = &unit->latencies.read;
  1831. break;
  1832. case FSF_DATADIR_WRITE:
  1833. lat = &unit->latencies.write;
  1834. break;
  1835. case FSF_DATADIR_CMND:
  1836. lat = &unit->latencies.cmd;
  1837. break;
  1838. default:
  1839. return;
  1840. }
  1841. spin_lock(&unit->latencies.lock);
  1842. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1843. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1844. lat->counter++;
  1845. spin_unlock(&unit->latencies.lock);
  1846. }
  1847. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1848. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1849. {
  1850. struct fsf_qual_latency_info *lat_inf;
  1851. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1852. struct request *req = scsi_cmnd->request;
  1853. struct zfcp_blk_drv_data trace;
  1854. int ticks = fsf_req->adapter->timer_ticks;
  1855. trace.flags = 0;
  1856. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1857. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1858. trace.flags |= ZFCP_BLK_LAT_VALID;
  1859. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1860. trace.channel_lat = lat_inf->channel_lat * ticks;
  1861. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1862. }
  1863. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1864. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1865. trace.inb_usage = fsf_req->qdio_inb_usage;
  1866. trace.outb_usage = fsf_req->qdio_outb_usage;
  1867. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1868. }
  1869. #else
  1870. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1871. {
  1872. }
  1873. #endif
  1874. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1875. {
  1876. struct scsi_cmnd *scpnt;
  1877. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1878. &(req->qtcb->bottom.io.fcp_rsp);
  1879. u32 sns_len;
  1880. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1881. unsigned long flags;
  1882. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1883. scpnt = req->data;
  1884. if (unlikely(!scpnt)) {
  1885. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1886. return;
  1887. }
  1888. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1889. set_host_byte(scpnt, DID_SOFT_ERROR);
  1890. goto skip_fsfstatus;
  1891. }
  1892. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1893. set_host_byte(scpnt, DID_ERROR);
  1894. goto skip_fsfstatus;
  1895. }
  1896. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1897. scpnt->result |= fcp_rsp_iu->scsi_status;
  1898. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1899. zfcp_fsf_req_latency(req);
  1900. zfcp_fsf_trace_latency(req);
  1901. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1902. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1903. set_host_byte(scpnt, DID_OK);
  1904. else {
  1905. set_host_byte(scpnt, DID_ERROR);
  1906. goto skip_fsfstatus;
  1907. }
  1908. }
  1909. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1910. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1911. fcp_rsp_iu->fcp_rsp_len;
  1912. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1913. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1914. memcpy(scpnt->sense_buffer,
  1915. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1916. }
  1917. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1918. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1919. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1920. scpnt->underflow)
  1921. set_host_byte(scpnt, DID_ERROR);
  1922. }
  1923. skip_fsfstatus:
  1924. if (scpnt->result != 0)
  1925. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1926. else if (scpnt->retries > 0)
  1927. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1928. else
  1929. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1930. scpnt->host_scribble = NULL;
  1931. (scpnt->scsi_done) (scpnt);
  1932. /*
  1933. * We must hold this lock until scsi_done has been called.
  1934. * Otherwise we may call scsi_done after abort regarding this
  1935. * command has completed.
  1936. * Note: scsi_done must not block!
  1937. */
  1938. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1939. }
  1940. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1941. {
  1942. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1943. &(req->qtcb->bottom.io.fcp_rsp);
  1944. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1945. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1946. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1947. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1948. }
  1949. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1950. {
  1951. struct zfcp_unit *unit;
  1952. struct fsf_qtcb_header *header = &req->qtcb->header;
  1953. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1954. unit = req->data;
  1955. else
  1956. unit = req->unit;
  1957. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1958. goto skip_fsfstatus;
  1959. switch (header->fsf_status) {
  1960. case FSF_HANDLE_MISMATCH:
  1961. case FSF_PORT_HANDLE_NOT_VALID:
  1962. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1963. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1964. break;
  1965. case FSF_FCPLUN_NOT_VALID:
  1966. case FSF_LUN_HANDLE_NOT_VALID:
  1967. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1968. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1969. break;
  1970. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1971. zfcp_fsf_class_not_supp(req);
  1972. break;
  1973. case FSF_ACCESS_DENIED:
  1974. zfcp_fsf_access_denied_unit(req, unit);
  1975. break;
  1976. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1977. dev_err(&req->adapter->ccw_device->dev,
  1978. "Incorrect direction %d, unit 0x%016Lx on port "
  1979. "0x%016Lx closed\n",
  1980. req->qtcb->bottom.io.data_direction,
  1981. (unsigned long long)unit->fcp_lun,
  1982. (unsigned long long)unit->port->wwpn);
  1983. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1984. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1985. break;
  1986. case FSF_CMND_LENGTH_NOT_VALID:
  1987. dev_err(&req->adapter->ccw_device->dev,
  1988. "Incorrect CDB length %d, unit 0x%016Lx on "
  1989. "port 0x%016Lx closed\n",
  1990. req->qtcb->bottom.io.fcp_cmnd_length,
  1991. (unsigned long long)unit->fcp_lun,
  1992. (unsigned long long)unit->port->wwpn);
  1993. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1994. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1995. break;
  1996. case FSF_PORT_BOXED:
  1997. zfcp_erp_port_boxed(unit->port, 53, req);
  1998. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1999. ZFCP_STATUS_FSFREQ_RETRY;
  2000. break;
  2001. case FSF_LUN_BOXED:
  2002. zfcp_erp_unit_boxed(unit, 54, req);
  2003. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2004. ZFCP_STATUS_FSFREQ_RETRY;
  2005. break;
  2006. case FSF_ADAPTER_STATUS_AVAILABLE:
  2007. if (header->fsf_status_qual.word[0] ==
  2008. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2009. zfcp_test_link(unit->port);
  2010. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2011. break;
  2012. }
  2013. skip_fsfstatus:
  2014. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2015. zfcp_fsf_send_fcp_ctm_handler(req);
  2016. else {
  2017. zfcp_fsf_send_fcp_command_task_handler(req);
  2018. req->unit = NULL;
  2019. zfcp_unit_put(unit);
  2020. }
  2021. }
  2022. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2023. {
  2024. u32 *fcp_dl_ptr;
  2025. /*
  2026. * fcp_dl_addr = start address of fcp_cmnd structure +
  2027. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2028. * SEE FCP-2 documentation
  2029. */
  2030. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2031. (fcp_cmd->add_fcp_cdb_length << 2));
  2032. *fcp_dl_ptr = fcp_dl;
  2033. }
  2034. /**
  2035. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2036. * @adapter: adapter where scsi command is issued
  2037. * @unit: unit where command is sent to
  2038. * @scsi_cmnd: scsi command to be sent
  2039. * @timer: timer to be started when request is initiated
  2040. * @req_flags: flags for fsf_request
  2041. */
  2042. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2043. struct zfcp_unit *unit,
  2044. struct scsi_cmnd *scsi_cmnd,
  2045. int use_timer, int req_flags)
  2046. {
  2047. struct zfcp_fsf_req *req;
  2048. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2049. unsigned int sbtype;
  2050. int real_bytes, retval = -EIO;
  2051. if (unlikely(!(atomic_read(&unit->status) &
  2052. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2053. return -EBUSY;
  2054. spin_lock(&adapter->req_q_lock);
  2055. if (!zfcp_fsf_sbal_available(adapter))
  2056. goto out;
  2057. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2058. adapter->pool.fsf_req_scsi);
  2059. if (IS_ERR(req)) {
  2060. retval = PTR_ERR(req);
  2061. goto out;
  2062. }
  2063. zfcp_unit_get(unit);
  2064. req->unit = unit;
  2065. req->data = scsi_cmnd;
  2066. req->handler = zfcp_fsf_send_fcp_command_handler;
  2067. req->qtcb->header.lun_handle = unit->handle;
  2068. req->qtcb->header.port_handle = unit->port->handle;
  2069. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2070. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2071. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2072. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2073. /*
  2074. * set depending on data direction:
  2075. * data direction bits in SBALE (SB Type)
  2076. * data direction bits in QTCB
  2077. * data direction bits in FCP_CMND IU
  2078. */
  2079. switch (scsi_cmnd->sc_data_direction) {
  2080. case DMA_NONE:
  2081. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2082. sbtype = SBAL_FLAGS0_TYPE_READ;
  2083. break;
  2084. case DMA_FROM_DEVICE:
  2085. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2086. sbtype = SBAL_FLAGS0_TYPE_READ;
  2087. fcp_cmnd_iu->rddata = 1;
  2088. break;
  2089. case DMA_TO_DEVICE:
  2090. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2091. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2092. fcp_cmnd_iu->wddata = 1;
  2093. break;
  2094. case DMA_BIDIRECTIONAL:
  2095. default:
  2096. retval = -EIO;
  2097. goto failed_scsi_cmnd;
  2098. }
  2099. if (likely((scsi_cmnd->device->simple_tags) ||
  2100. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2101. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2102. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2103. else
  2104. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2105. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2106. fcp_cmnd_iu->add_fcp_cdb_length =
  2107. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2108. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2109. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2110. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2111. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2112. scsi_sglist(scsi_cmnd),
  2113. FSF_MAX_SBALS_PER_REQ);
  2114. if (unlikely(real_bytes < 0)) {
  2115. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2116. retval = -EIO;
  2117. else {
  2118. dev_err(&adapter->ccw_device->dev,
  2119. "Oversize data package, unit 0x%016Lx "
  2120. "on port 0x%016Lx closed\n",
  2121. (unsigned long long)unit->fcp_lun,
  2122. (unsigned long long)unit->port->wwpn);
  2123. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2124. retval = -EINVAL;
  2125. }
  2126. goto failed_scsi_cmnd;
  2127. }
  2128. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2129. if (use_timer)
  2130. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2131. retval = zfcp_fsf_req_send(req);
  2132. if (unlikely(retval))
  2133. goto failed_scsi_cmnd;
  2134. goto out;
  2135. failed_scsi_cmnd:
  2136. zfcp_unit_put(unit);
  2137. zfcp_fsf_req_free(req);
  2138. scsi_cmnd->host_scribble = NULL;
  2139. out:
  2140. spin_unlock(&adapter->req_q_lock);
  2141. return retval;
  2142. }
  2143. /**
  2144. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2145. * @adapter: pointer to struct zfcp-adapter
  2146. * @unit: pointer to struct zfcp_unit
  2147. * @tm_flags: unsigned byte for task management flags
  2148. * @req_flags: int request flags
  2149. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2150. */
  2151. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2152. struct zfcp_unit *unit,
  2153. u8 tm_flags, int req_flags)
  2154. {
  2155. struct qdio_buffer_element *sbale;
  2156. struct zfcp_fsf_req *req = NULL;
  2157. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2158. if (unlikely(!(atomic_read(&unit->status) &
  2159. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2160. return NULL;
  2161. spin_lock_bh(&adapter->req_q_lock);
  2162. if (zfcp_fsf_req_sbal_get(adapter))
  2163. goto out;
  2164. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2165. adapter->pool.fsf_req_scsi);
  2166. if (IS_ERR(req)) {
  2167. req = NULL;
  2168. goto out;
  2169. }
  2170. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2171. req->data = unit;
  2172. req->handler = zfcp_fsf_send_fcp_command_handler;
  2173. req->qtcb->header.lun_handle = unit->handle;
  2174. req->qtcb->header.port_handle = unit->port->handle;
  2175. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2176. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2177. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2178. sizeof(u32);
  2179. sbale = zfcp_qdio_sbale_req(req);
  2180. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2181. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2182. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2183. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2184. fcp_cmnd_iu->task_management_flags = tm_flags;
  2185. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2186. if (!zfcp_fsf_req_send(req))
  2187. goto out;
  2188. zfcp_fsf_req_free(req);
  2189. req = NULL;
  2190. out:
  2191. spin_unlock_bh(&adapter->req_q_lock);
  2192. return req;
  2193. }
  2194. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2195. {
  2196. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2197. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2198. }
  2199. /**
  2200. * zfcp_fsf_control_file - control file upload/download
  2201. * @adapter: pointer to struct zfcp_adapter
  2202. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2203. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2204. */
  2205. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2206. struct zfcp_fsf_cfdc *fsf_cfdc)
  2207. {
  2208. struct qdio_buffer_element *sbale;
  2209. struct zfcp_fsf_req *req = NULL;
  2210. struct fsf_qtcb_bottom_support *bottom;
  2211. int direction, retval = -EIO, bytes;
  2212. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2213. return ERR_PTR(-EOPNOTSUPP);
  2214. switch (fsf_cfdc->command) {
  2215. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2216. direction = SBAL_FLAGS0_TYPE_WRITE;
  2217. break;
  2218. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2219. direction = SBAL_FLAGS0_TYPE_READ;
  2220. break;
  2221. default:
  2222. return ERR_PTR(-EINVAL);
  2223. }
  2224. spin_lock_bh(&adapter->req_q_lock);
  2225. if (zfcp_fsf_req_sbal_get(adapter))
  2226. goto out;
  2227. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2228. if (IS_ERR(req)) {
  2229. retval = -EPERM;
  2230. goto out;
  2231. }
  2232. req->handler = zfcp_fsf_control_file_handler;
  2233. sbale = zfcp_qdio_sbale_req(req);
  2234. sbale[0].flags |= direction;
  2235. bottom = &req->qtcb->bottom.support;
  2236. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2237. bottom->option = fsf_cfdc->option;
  2238. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2239. FSF_MAX_SBALS_PER_REQ);
  2240. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2241. retval = -ENOMEM;
  2242. zfcp_fsf_req_free(req);
  2243. goto out;
  2244. }
  2245. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2246. retval = zfcp_fsf_req_send(req);
  2247. out:
  2248. spin_unlock_bh(&adapter->req_q_lock);
  2249. if (!retval) {
  2250. wait_event(req->completion_wq,
  2251. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2252. return req;
  2253. }
  2254. return ERR_PTR(retval);
  2255. }