zfcp_fsf.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560
  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_check(struct zfcp_adapter *adapter)
  582. {
  583. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  584. spin_lock_bh(&adapter->req_q_lock);
  585. if (atomic_read(&req_q->count))
  586. return 1;
  587. spin_unlock_bh(&adapter->req_q_lock);
  588. return 0;
  589. }
  590. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  591. {
  592. unsigned int count = atomic_read(&adapter->req_q.count);
  593. if (!count)
  594. atomic_inc(&adapter->qdio_outb_full);
  595. return count > 0;
  596. }
  597. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  598. {
  599. long ret;
  600. spin_unlock_bh(&adapter->req_q_lock);
  601. ret = wait_event_interruptible_timeout(adapter->request_wq,
  602. zfcp_fsf_sbal_check(adapter), 5 * HZ);
  603. if (ret > 0)
  604. return 0;
  605. if (!ret)
  606. atomic_inc(&adapter->qdio_outb_full);
  607. spin_lock_bh(&adapter->req_q_lock);
  608. return -EIO;
  609. }
  610. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  611. {
  612. struct zfcp_fsf_req *req;
  613. req = mempool_alloc(pool, GFP_ATOMIC);
  614. if (!req)
  615. return NULL;
  616. memset(req, 0, sizeof(*req));
  617. req->pool = pool;
  618. return req;
  619. }
  620. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  621. {
  622. struct zfcp_fsf_req_qtcb *qtcb;
  623. if (likely(pool))
  624. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  625. else
  626. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  627. GFP_ATOMIC);
  628. if (unlikely(!qtcb))
  629. return NULL;
  630. memset(qtcb, 0, sizeof(*qtcb));
  631. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  632. qtcb->fsf_req.pool = pool;
  633. return &qtcb->fsf_req;
  634. }
  635. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  636. u32 fsf_cmd, int req_flags,
  637. mempool_t *pool)
  638. {
  639. struct qdio_buffer_element *sbale;
  640. struct zfcp_fsf_req *req;
  641. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  642. if (req_flags & ZFCP_REQ_NO_QTCB)
  643. req = zfcp_fsf_alloc_noqtcb(pool);
  644. else
  645. req = zfcp_fsf_alloc_qtcb(pool);
  646. if (unlikely(!req))
  647. return ERR_PTR(-EIO);
  648. if (adapter->req_no == 0)
  649. adapter->req_no++;
  650. INIT_LIST_HEAD(&req->list);
  651. init_timer(&req->timer);
  652. init_waitqueue_head(&req->completion_wq);
  653. req->adapter = adapter;
  654. req->fsf_command = fsf_cmd;
  655. req->req_id = adapter->req_no++;
  656. req->sbal_number = 1;
  657. req->sbal_first = req_q->first;
  658. req->sbal_last = req_q->first;
  659. req->sbale_curr = 1;
  660. sbale = zfcp_qdio_sbale_req(req);
  661. sbale[0].addr = (void *) req->req_id;
  662. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  663. if (likely(req->qtcb)) {
  664. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  665. req->qtcb->prefix.req_id = req->req_id;
  666. req->qtcb->prefix.ulp_info = 26;
  667. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  668. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  669. req->qtcb->header.req_handle = req->req_id;
  670. req->qtcb->header.fsf_command = req->fsf_command;
  671. req->seq_no = adapter->fsf_req_seq_no;
  672. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  673. sbale[1].addr = (void *) req->qtcb;
  674. sbale[1].length = sizeof(struct fsf_qtcb);
  675. }
  676. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  677. zfcp_fsf_req_free(req);
  678. return ERR_PTR(-EIO);
  679. }
  680. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  681. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  682. return req;
  683. }
  684. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  685. {
  686. struct zfcp_adapter *adapter = req->adapter;
  687. unsigned long flags;
  688. int idx;
  689. /* put allocated FSF request into hash table */
  690. spin_lock_irqsave(&adapter->req_list_lock, flags);
  691. idx = zfcp_reqlist_hash(req->req_id);
  692. list_add_tail(&req->list, &adapter->req_list[idx]);
  693. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  694. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  695. req->issued = get_clock();
  696. if (zfcp_qdio_send(req)) {
  697. del_timer(&req->timer);
  698. spin_lock_irqsave(&adapter->req_list_lock, flags);
  699. /* lookup request again, list might have changed */
  700. if (zfcp_reqlist_find_safe(adapter, req))
  701. zfcp_reqlist_remove(adapter, req);
  702. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  703. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  704. return -EIO;
  705. }
  706. /* Don't increase for unsolicited status */
  707. if (req->qtcb)
  708. adapter->fsf_req_seq_no++;
  709. return 0;
  710. }
  711. /**
  712. * zfcp_fsf_status_read - send status read request
  713. * @adapter: pointer to struct zfcp_adapter
  714. * @req_flags: request flags
  715. * Returns: 0 on success, ERROR otherwise
  716. */
  717. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  718. {
  719. struct zfcp_fsf_req *req;
  720. struct fsf_status_read_buffer *sr_buf;
  721. struct qdio_buffer_element *sbale;
  722. int retval = -EIO;
  723. spin_lock_bh(&adapter->req_q_lock);
  724. if (zfcp_fsf_req_sbal_get(adapter))
  725. goto out;
  726. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  727. ZFCP_REQ_NO_QTCB,
  728. adapter->pool.fsf_req_status_read);
  729. if (IS_ERR(req)) {
  730. retval = PTR_ERR(req);
  731. goto out;
  732. }
  733. sbale = zfcp_qdio_sbale_req(req);
  734. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  735. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  736. req->sbale_curr = 2;
  737. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  738. if (!sr_buf) {
  739. retval = -ENOMEM;
  740. goto failed_buf;
  741. }
  742. memset(sr_buf, 0, sizeof(*sr_buf));
  743. req->data = sr_buf;
  744. sbale = zfcp_qdio_sbale_curr(req);
  745. sbale->addr = (void *) sr_buf;
  746. sbale->length = sizeof(*sr_buf);
  747. retval = zfcp_fsf_req_send(req);
  748. if (retval)
  749. goto failed_req_send;
  750. goto out;
  751. failed_req_send:
  752. mempool_free(sr_buf, adapter->pool.data_status_read);
  753. failed_buf:
  754. zfcp_fsf_req_free(req);
  755. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  756. out:
  757. spin_unlock_bh(&adapter->req_q_lock);
  758. return retval;
  759. }
  760. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  761. {
  762. struct zfcp_unit *unit = req->data;
  763. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  764. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  765. return;
  766. switch (req->qtcb->header.fsf_status) {
  767. case FSF_PORT_HANDLE_NOT_VALID:
  768. if (fsq->word[0] == fsq->word[1]) {
  769. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  770. req);
  771. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  772. }
  773. break;
  774. case FSF_LUN_HANDLE_NOT_VALID:
  775. if (fsq->word[0] == fsq->word[1]) {
  776. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  777. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  778. }
  779. break;
  780. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  781. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  782. break;
  783. case FSF_PORT_BOXED:
  784. zfcp_erp_port_boxed(unit->port, 47, req);
  785. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  786. ZFCP_STATUS_FSFREQ_RETRY;
  787. break;
  788. case FSF_LUN_BOXED:
  789. zfcp_erp_unit_boxed(unit, 48, req);
  790. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  791. ZFCP_STATUS_FSFREQ_RETRY;
  792. break;
  793. case FSF_ADAPTER_STATUS_AVAILABLE:
  794. switch (fsq->word[0]) {
  795. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  796. zfcp_test_link(unit->port);
  797. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  798. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  799. break;
  800. }
  801. break;
  802. case FSF_GOOD:
  803. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  804. break;
  805. }
  806. }
  807. /**
  808. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  809. * @old_req_id: unsigned long
  810. * @adapter: pointer to struct zfcp_adapter
  811. * @unit: pointer to struct zfcp_unit
  812. * @req_flags: integer specifying the request flags
  813. * Returns: pointer to struct zfcp_fsf_req
  814. *
  815. * FIXME(design): should be watched by a timeout !!!
  816. */
  817. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  818. struct zfcp_adapter *adapter,
  819. struct zfcp_unit *unit,
  820. int req_flags)
  821. {
  822. struct qdio_buffer_element *sbale;
  823. struct zfcp_fsf_req *req = NULL;
  824. spin_lock(&adapter->req_q_lock);
  825. if (!zfcp_fsf_sbal_available(adapter))
  826. goto out;
  827. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  828. req_flags, adapter->pool.fsf_req_abort);
  829. if (IS_ERR(req)) {
  830. req = NULL;
  831. goto out;
  832. }
  833. if (unlikely(!(atomic_read(&unit->status) &
  834. ZFCP_STATUS_COMMON_UNBLOCKED)))
  835. goto out_error_free;
  836. sbale = zfcp_qdio_sbale_req(req);
  837. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  838. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  839. req->data = unit;
  840. req->handler = zfcp_fsf_abort_fcp_command_handler;
  841. req->qtcb->header.lun_handle = unit->handle;
  842. req->qtcb->header.port_handle = unit->port->handle;
  843. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  844. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  845. if (!zfcp_fsf_req_send(req))
  846. goto out;
  847. out_error_free:
  848. zfcp_fsf_req_free(req);
  849. req = NULL;
  850. out:
  851. spin_unlock(&adapter->req_q_lock);
  852. return req;
  853. }
  854. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  855. {
  856. struct zfcp_adapter *adapter = req->adapter;
  857. struct zfcp_send_ct *send_ct = req->data;
  858. struct fsf_qtcb_header *header = &req->qtcb->header;
  859. send_ct->status = -EINVAL;
  860. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  861. goto skip_fsfstatus;
  862. switch (header->fsf_status) {
  863. case FSF_GOOD:
  864. zfcp_san_dbf_event_ct_response(req);
  865. send_ct->status = 0;
  866. break;
  867. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  868. zfcp_fsf_class_not_supp(req);
  869. break;
  870. case FSF_ADAPTER_STATUS_AVAILABLE:
  871. switch (header->fsf_status_qual.word[0]){
  872. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  873. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  874. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  875. break;
  876. }
  877. break;
  878. case FSF_ACCESS_DENIED:
  879. break;
  880. case FSF_PORT_BOXED:
  881. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  882. ZFCP_STATUS_FSFREQ_RETRY;
  883. break;
  884. case FSF_PORT_HANDLE_NOT_VALID:
  885. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  886. case FSF_GENERIC_COMMAND_REJECTED:
  887. case FSF_PAYLOAD_SIZE_MISMATCH:
  888. case FSF_REQUEST_SIZE_TOO_LARGE:
  889. case FSF_RESPONSE_SIZE_TOO_LARGE:
  890. case FSF_SBAL_MISMATCH:
  891. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  892. break;
  893. }
  894. skip_fsfstatus:
  895. if (send_ct->handler)
  896. send_ct->handler(send_ct->handler_data);
  897. }
  898. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  899. struct scatterlist *sg_req,
  900. struct scatterlist *sg_resp, int max_sbals)
  901. {
  902. int bytes;
  903. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  904. sg_req, max_sbals);
  905. if (bytes <= 0)
  906. return -ENOMEM;
  907. req->qtcb->bottom.support.req_buf_length = bytes;
  908. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  909. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  910. sg_resp, max_sbals);
  911. if (bytes <= 0)
  912. return -ENOMEM;
  913. req->qtcb->bottom.support.resp_buf_length = bytes;
  914. return 0;
  915. }
  916. /**
  917. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  918. * @ct: pointer to struct zfcp_send_ct with data for request
  919. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  920. * @erp_action: if non-null the Generic Service request sent within ERP
  921. */
  922. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  923. struct zfcp_erp_action *erp_action)
  924. {
  925. struct zfcp_wka_port *wka_port = ct->wka_port;
  926. struct zfcp_adapter *adapter = wka_port->adapter;
  927. struct zfcp_fsf_req *req;
  928. int ret = -EIO;
  929. spin_lock_bh(&adapter->req_q_lock);
  930. if (zfcp_fsf_req_sbal_get(adapter))
  931. goto out;
  932. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  933. ZFCP_REQ_AUTO_CLEANUP, pool);
  934. if (IS_ERR(req)) {
  935. ret = PTR_ERR(req);
  936. goto out;
  937. }
  938. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  939. FSF_MAX_SBALS_PER_REQ);
  940. if (ret)
  941. goto failed_send;
  942. req->handler = zfcp_fsf_send_ct_handler;
  943. req->qtcb->header.port_handle = wka_port->handle;
  944. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  945. req->qtcb->bottom.support.timeout = ct->timeout;
  946. req->data = ct;
  947. zfcp_san_dbf_event_ct_request(req);
  948. if (erp_action) {
  949. erp_action->fsf_req = req;
  950. req->erp_action = erp_action;
  951. zfcp_fsf_start_erp_timer(req);
  952. } else
  953. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  954. ret = zfcp_fsf_req_send(req);
  955. if (ret)
  956. goto failed_send;
  957. goto out;
  958. failed_send:
  959. zfcp_fsf_req_free(req);
  960. if (erp_action)
  961. erp_action->fsf_req = NULL;
  962. out:
  963. spin_unlock_bh(&adapter->req_q_lock);
  964. return ret;
  965. }
  966. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  967. {
  968. struct zfcp_send_els *send_els = req->data;
  969. struct zfcp_port *port = send_els->port;
  970. struct fsf_qtcb_header *header = &req->qtcb->header;
  971. send_els->status = -EINVAL;
  972. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  973. goto skip_fsfstatus;
  974. switch (header->fsf_status) {
  975. case FSF_GOOD:
  976. zfcp_san_dbf_event_els_response(req);
  977. send_els->status = 0;
  978. break;
  979. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  980. zfcp_fsf_class_not_supp(req);
  981. break;
  982. case FSF_ADAPTER_STATUS_AVAILABLE:
  983. switch (header->fsf_status_qual.word[0]){
  984. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  985. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  986. zfcp_test_link(port);
  987. /*fall through */
  988. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  989. case FSF_SQ_RETRY_IF_POSSIBLE:
  990. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  991. break;
  992. }
  993. break;
  994. case FSF_ELS_COMMAND_REJECTED:
  995. case FSF_PAYLOAD_SIZE_MISMATCH:
  996. case FSF_REQUEST_SIZE_TOO_LARGE:
  997. case FSF_RESPONSE_SIZE_TOO_LARGE:
  998. break;
  999. case FSF_ACCESS_DENIED:
  1000. zfcp_fsf_access_denied_port(req, port);
  1001. break;
  1002. case FSF_SBAL_MISMATCH:
  1003. /* should never occure, avoided in zfcp_fsf_send_els */
  1004. /* fall through */
  1005. default:
  1006. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1007. break;
  1008. }
  1009. skip_fsfstatus:
  1010. if (send_els->handler)
  1011. send_els->handler(send_els->handler_data);
  1012. }
  1013. /**
  1014. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1015. * @els: pointer to struct zfcp_send_els with data for the command
  1016. */
  1017. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1018. {
  1019. struct zfcp_fsf_req *req;
  1020. struct zfcp_adapter *adapter = els->adapter;
  1021. struct fsf_qtcb_bottom_support *bottom;
  1022. int ret = -EIO;
  1023. if (unlikely(!(atomic_read(&els->port->status) &
  1024. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1025. return -EBUSY;
  1026. spin_lock(&adapter->req_q_lock);
  1027. if (!zfcp_fsf_sbal_available(adapter))
  1028. goto out;
  1029. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1030. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1031. if (IS_ERR(req)) {
  1032. ret = PTR_ERR(req);
  1033. goto out;
  1034. }
  1035. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2);
  1036. if (ret)
  1037. goto failed_send;
  1038. bottom = &req->qtcb->bottom.support;
  1039. req->handler = zfcp_fsf_send_els_handler;
  1040. bottom->d_id = els->d_id;
  1041. bottom->service_class = FSF_CLASS_3;
  1042. bottom->timeout = 2 * R_A_TOV;
  1043. req->data = els;
  1044. zfcp_san_dbf_event_els_request(req);
  1045. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1046. ret = zfcp_fsf_req_send(req);
  1047. if (ret)
  1048. goto failed_send;
  1049. goto out;
  1050. failed_send:
  1051. zfcp_fsf_req_free(req);
  1052. out:
  1053. spin_unlock(&adapter->req_q_lock);
  1054. return ret;
  1055. }
  1056. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1057. {
  1058. struct qdio_buffer_element *sbale;
  1059. struct zfcp_fsf_req *req;
  1060. struct zfcp_adapter *adapter = erp_action->adapter;
  1061. int retval = -EIO;
  1062. spin_lock_bh(&adapter->req_q_lock);
  1063. if (!zfcp_fsf_sbal_available(adapter))
  1064. goto out;
  1065. req = zfcp_fsf_req_create(adapter,
  1066. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1067. ZFCP_REQ_AUTO_CLEANUP,
  1068. adapter->pool.fsf_req_erp);
  1069. if (IS_ERR(req)) {
  1070. retval = PTR_ERR(req);
  1071. goto out;
  1072. }
  1073. sbale = zfcp_qdio_sbale_req(req);
  1074. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1075. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1076. req->qtcb->bottom.config.feature_selection =
  1077. FSF_FEATURE_CFDC |
  1078. FSF_FEATURE_LUN_SHARING |
  1079. FSF_FEATURE_NOTIFICATION_LOST |
  1080. FSF_FEATURE_UPDATE_ALERT;
  1081. req->erp_action = erp_action;
  1082. req->handler = zfcp_fsf_exchange_config_data_handler;
  1083. erp_action->fsf_req = req;
  1084. zfcp_fsf_start_erp_timer(req);
  1085. retval = zfcp_fsf_req_send(req);
  1086. if (retval) {
  1087. zfcp_fsf_req_free(req);
  1088. erp_action->fsf_req = NULL;
  1089. }
  1090. out:
  1091. spin_unlock_bh(&adapter->req_q_lock);
  1092. return retval;
  1093. }
  1094. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1095. struct fsf_qtcb_bottom_config *data)
  1096. {
  1097. struct qdio_buffer_element *sbale;
  1098. struct zfcp_fsf_req *req = NULL;
  1099. int retval = -EIO;
  1100. spin_lock_bh(&adapter->req_q_lock);
  1101. if (zfcp_fsf_req_sbal_get(adapter))
  1102. goto out;
  1103. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1104. 0, NULL);
  1105. if (IS_ERR(req)) {
  1106. retval = PTR_ERR(req);
  1107. goto out;
  1108. }
  1109. sbale = zfcp_qdio_sbale_req(req);
  1110. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1111. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1112. req->handler = zfcp_fsf_exchange_config_data_handler;
  1113. req->qtcb->bottom.config.feature_selection =
  1114. FSF_FEATURE_CFDC |
  1115. FSF_FEATURE_LUN_SHARING |
  1116. FSF_FEATURE_NOTIFICATION_LOST |
  1117. FSF_FEATURE_UPDATE_ALERT;
  1118. if (data)
  1119. req->data = data;
  1120. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1121. retval = zfcp_fsf_req_send(req);
  1122. out:
  1123. spin_unlock_bh(&adapter->req_q_lock);
  1124. if (!retval)
  1125. wait_event(req->completion_wq,
  1126. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1127. zfcp_fsf_req_free(req);
  1128. return retval;
  1129. }
  1130. /**
  1131. * zfcp_fsf_exchange_port_data - request information about local port
  1132. * @erp_action: ERP action for the adapter for which port data is requested
  1133. * Returns: 0 on success, error otherwise
  1134. */
  1135. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1136. {
  1137. struct qdio_buffer_element *sbale;
  1138. struct zfcp_fsf_req *req;
  1139. struct zfcp_adapter *adapter = erp_action->adapter;
  1140. int retval = -EIO;
  1141. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1142. return -EOPNOTSUPP;
  1143. spin_lock_bh(&adapter->req_q_lock);
  1144. if (!zfcp_fsf_sbal_available(adapter))
  1145. goto out;
  1146. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1147. ZFCP_REQ_AUTO_CLEANUP,
  1148. adapter->pool.fsf_req_erp);
  1149. if (IS_ERR(req)) {
  1150. retval = PTR_ERR(req);
  1151. goto out;
  1152. }
  1153. sbale = zfcp_qdio_sbale_req(req);
  1154. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1155. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1156. req->handler = zfcp_fsf_exchange_port_data_handler;
  1157. req->erp_action = erp_action;
  1158. erp_action->fsf_req = req;
  1159. zfcp_fsf_start_erp_timer(req);
  1160. retval = zfcp_fsf_req_send(req);
  1161. if (retval) {
  1162. zfcp_fsf_req_free(req);
  1163. erp_action->fsf_req = NULL;
  1164. }
  1165. out:
  1166. spin_unlock_bh(&adapter->req_q_lock);
  1167. return retval;
  1168. }
  1169. /**
  1170. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1171. * @adapter: pointer to struct zfcp_adapter
  1172. * @data: pointer to struct fsf_qtcb_bottom_port
  1173. * Returns: 0 on success, error otherwise
  1174. */
  1175. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1176. struct fsf_qtcb_bottom_port *data)
  1177. {
  1178. struct qdio_buffer_element *sbale;
  1179. struct zfcp_fsf_req *req = NULL;
  1180. int retval = -EIO;
  1181. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1182. return -EOPNOTSUPP;
  1183. spin_lock_bh(&adapter->req_q_lock);
  1184. if (!zfcp_fsf_sbal_available(adapter))
  1185. goto out;
  1186. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1187. NULL);
  1188. if (IS_ERR(req)) {
  1189. retval = PTR_ERR(req);
  1190. goto out;
  1191. }
  1192. if (data)
  1193. req->data = data;
  1194. sbale = zfcp_qdio_sbale_req(req);
  1195. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1196. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1197. req->handler = zfcp_fsf_exchange_port_data_handler;
  1198. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1199. retval = zfcp_fsf_req_send(req);
  1200. out:
  1201. spin_unlock_bh(&adapter->req_q_lock);
  1202. if (!retval)
  1203. wait_event(req->completion_wq,
  1204. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1205. zfcp_fsf_req_free(req);
  1206. return retval;
  1207. }
  1208. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1209. {
  1210. struct zfcp_port *port = req->data;
  1211. struct fsf_qtcb_header *header = &req->qtcb->header;
  1212. struct fsf_plogi *plogi;
  1213. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1214. return;
  1215. switch (header->fsf_status) {
  1216. case FSF_PORT_ALREADY_OPEN:
  1217. break;
  1218. case FSF_ACCESS_DENIED:
  1219. zfcp_fsf_access_denied_port(req, port);
  1220. break;
  1221. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1222. dev_warn(&req->adapter->ccw_device->dev,
  1223. "Not enough FCP adapter resources to open "
  1224. "remote port 0x%016Lx\n",
  1225. (unsigned long long)port->wwpn);
  1226. zfcp_erp_port_failed(port, 31, req);
  1227. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1228. break;
  1229. case FSF_ADAPTER_STATUS_AVAILABLE:
  1230. switch (header->fsf_status_qual.word[0]) {
  1231. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1232. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1233. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1234. break;
  1235. case FSF_SQ_NO_RETRY_POSSIBLE:
  1236. dev_warn(&req->adapter->ccw_device->dev,
  1237. "Remote port 0x%016Lx could not be opened\n",
  1238. (unsigned long long)port->wwpn);
  1239. zfcp_erp_port_failed(port, 32, req);
  1240. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1241. break;
  1242. }
  1243. break;
  1244. case FSF_GOOD:
  1245. port->handle = header->port_handle;
  1246. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1247. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1248. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1249. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1250. &port->status);
  1251. /* check whether D_ID has changed during open */
  1252. /*
  1253. * FIXME: This check is not airtight, as the FCP channel does
  1254. * not monitor closures of target port connections caused on
  1255. * the remote side. Thus, they might miss out on invalidating
  1256. * locally cached WWPNs (and other N_Port parameters) of gone
  1257. * target ports. So, our heroic attempt to make things safe
  1258. * could be undermined by 'open port' response data tagged with
  1259. * obsolete WWPNs. Another reason to monitor potential
  1260. * connection closures ourself at least (by interpreting
  1261. * incoming ELS' and unsolicited status). It just crosses my
  1262. * mind that one should be able to cross-check by means of
  1263. * another GID_PN straight after a port has been opened.
  1264. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1265. */
  1266. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1267. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1268. if (plogi->serv_param.wwpn != port->wwpn)
  1269. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1270. &port->status);
  1271. else {
  1272. port->wwnn = plogi->serv_param.wwnn;
  1273. zfcp_fc_plogi_evaluate(port, plogi);
  1274. }
  1275. }
  1276. break;
  1277. case FSF_UNKNOWN_OP_SUBTYPE:
  1278. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1279. break;
  1280. }
  1281. }
  1282. /**
  1283. * zfcp_fsf_open_port - create and send open port request
  1284. * @erp_action: pointer to struct zfcp_erp_action
  1285. * Returns: 0 on success, error otherwise
  1286. */
  1287. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1288. {
  1289. struct qdio_buffer_element *sbale;
  1290. struct zfcp_adapter *adapter = erp_action->adapter;
  1291. struct zfcp_fsf_req *req;
  1292. int retval = -EIO;
  1293. spin_lock_bh(&adapter->req_q_lock);
  1294. if (zfcp_fsf_req_sbal_get(adapter))
  1295. goto out;
  1296. req = zfcp_fsf_req_create(adapter,
  1297. FSF_QTCB_OPEN_PORT_WITH_DID,
  1298. ZFCP_REQ_AUTO_CLEANUP,
  1299. adapter->pool.fsf_req_erp);
  1300. if (IS_ERR(req)) {
  1301. retval = PTR_ERR(req);
  1302. goto out;
  1303. }
  1304. sbale = zfcp_qdio_sbale_req(req);
  1305. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1306. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1307. req->handler = zfcp_fsf_open_port_handler;
  1308. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1309. req->data = erp_action->port;
  1310. req->erp_action = erp_action;
  1311. erp_action->fsf_req = req;
  1312. zfcp_fsf_start_erp_timer(req);
  1313. retval = zfcp_fsf_req_send(req);
  1314. if (retval) {
  1315. zfcp_fsf_req_free(req);
  1316. erp_action->fsf_req = NULL;
  1317. }
  1318. out:
  1319. spin_unlock_bh(&adapter->req_q_lock);
  1320. return retval;
  1321. }
  1322. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1323. {
  1324. struct zfcp_port *port = req->data;
  1325. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1326. return;
  1327. switch (req->qtcb->header.fsf_status) {
  1328. case FSF_PORT_HANDLE_NOT_VALID:
  1329. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1330. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1331. break;
  1332. case FSF_ADAPTER_STATUS_AVAILABLE:
  1333. break;
  1334. case FSF_GOOD:
  1335. zfcp_erp_modify_port_status(port, 33, req,
  1336. ZFCP_STATUS_COMMON_OPEN,
  1337. ZFCP_CLEAR);
  1338. break;
  1339. }
  1340. }
  1341. /**
  1342. * zfcp_fsf_close_port - create and send close port request
  1343. * @erp_action: pointer to struct zfcp_erp_action
  1344. * Returns: 0 on success, error otherwise
  1345. */
  1346. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1347. {
  1348. struct qdio_buffer_element *sbale;
  1349. struct zfcp_adapter *adapter = erp_action->adapter;
  1350. struct zfcp_fsf_req *req;
  1351. int retval = -EIO;
  1352. spin_lock_bh(&adapter->req_q_lock);
  1353. if (zfcp_fsf_req_sbal_get(adapter))
  1354. goto out;
  1355. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1356. ZFCP_REQ_AUTO_CLEANUP,
  1357. adapter->pool.fsf_req_erp);
  1358. if (IS_ERR(req)) {
  1359. retval = PTR_ERR(req);
  1360. goto out;
  1361. }
  1362. sbale = zfcp_qdio_sbale_req(req);
  1363. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1364. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1365. req->handler = zfcp_fsf_close_port_handler;
  1366. req->data = erp_action->port;
  1367. req->erp_action = erp_action;
  1368. req->qtcb->header.port_handle = erp_action->port->handle;
  1369. erp_action->fsf_req = req;
  1370. zfcp_fsf_start_erp_timer(req);
  1371. retval = zfcp_fsf_req_send(req);
  1372. if (retval) {
  1373. zfcp_fsf_req_free(req);
  1374. erp_action->fsf_req = NULL;
  1375. }
  1376. out:
  1377. spin_unlock_bh(&adapter->req_q_lock);
  1378. return retval;
  1379. }
  1380. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1381. {
  1382. struct zfcp_wka_port *wka_port = req->data;
  1383. struct fsf_qtcb_header *header = &req->qtcb->header;
  1384. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1385. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1386. goto out;
  1387. }
  1388. switch (header->fsf_status) {
  1389. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1390. dev_warn(&req->adapter->ccw_device->dev,
  1391. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1392. case FSF_ADAPTER_STATUS_AVAILABLE:
  1393. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1394. case FSF_ACCESS_DENIED:
  1395. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1396. break;
  1397. case FSF_PORT_ALREADY_OPEN:
  1398. break;
  1399. case FSF_GOOD:
  1400. wka_port->handle = header->port_handle;
  1401. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1402. }
  1403. out:
  1404. wake_up(&wka_port->completion_wq);
  1405. }
  1406. /**
  1407. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1408. * @wka_port: pointer to struct zfcp_wka_port
  1409. * Returns: 0 on success, error otherwise
  1410. */
  1411. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1412. {
  1413. struct qdio_buffer_element *sbale;
  1414. struct zfcp_adapter *adapter = wka_port->adapter;
  1415. struct zfcp_fsf_req *req;
  1416. int retval = -EIO;
  1417. spin_lock_bh(&adapter->req_q_lock);
  1418. if (zfcp_fsf_req_sbal_get(adapter))
  1419. goto out;
  1420. req = zfcp_fsf_req_create(adapter,
  1421. FSF_QTCB_OPEN_PORT_WITH_DID,
  1422. ZFCP_REQ_AUTO_CLEANUP,
  1423. adapter->pool.fsf_req_erp);
  1424. if (unlikely(IS_ERR(req))) {
  1425. retval = PTR_ERR(req);
  1426. goto out;
  1427. }
  1428. sbale = zfcp_qdio_sbale_req(req);
  1429. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1430. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1431. req->handler = zfcp_fsf_open_wka_port_handler;
  1432. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1433. req->data = wka_port;
  1434. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1435. retval = zfcp_fsf_req_send(req);
  1436. if (retval)
  1437. zfcp_fsf_req_free(req);
  1438. out:
  1439. spin_unlock_bh(&adapter->req_q_lock);
  1440. return retval;
  1441. }
  1442. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1443. {
  1444. struct zfcp_wka_port *wka_port = req->data;
  1445. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1446. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1447. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
  1448. }
  1449. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1450. wake_up(&wka_port->completion_wq);
  1451. }
  1452. /**
  1453. * zfcp_fsf_close_wka_port - create and send close wka port request
  1454. * @erp_action: pointer to struct zfcp_erp_action
  1455. * Returns: 0 on success, error otherwise
  1456. */
  1457. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1458. {
  1459. struct qdio_buffer_element *sbale;
  1460. struct zfcp_adapter *adapter = wka_port->adapter;
  1461. struct zfcp_fsf_req *req;
  1462. int retval = -EIO;
  1463. spin_lock_bh(&adapter->req_q_lock);
  1464. if (zfcp_fsf_req_sbal_get(adapter))
  1465. goto out;
  1466. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1467. ZFCP_REQ_AUTO_CLEANUP,
  1468. adapter->pool.fsf_req_erp);
  1469. if (unlikely(IS_ERR(req))) {
  1470. retval = PTR_ERR(req);
  1471. goto out;
  1472. }
  1473. sbale = zfcp_qdio_sbale_req(req);
  1474. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1475. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1476. req->handler = zfcp_fsf_close_wka_port_handler;
  1477. req->data = wka_port;
  1478. req->qtcb->header.port_handle = wka_port->handle;
  1479. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1480. retval = zfcp_fsf_req_send(req);
  1481. if (retval)
  1482. zfcp_fsf_req_free(req);
  1483. out:
  1484. spin_unlock_bh(&adapter->req_q_lock);
  1485. return retval;
  1486. }
  1487. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1488. {
  1489. struct zfcp_port *port = req->data;
  1490. struct fsf_qtcb_header *header = &req->qtcb->header;
  1491. struct zfcp_unit *unit;
  1492. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1493. goto skip_fsfstatus;
  1494. switch (header->fsf_status) {
  1495. case FSF_PORT_HANDLE_NOT_VALID:
  1496. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1497. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1498. break;
  1499. case FSF_ACCESS_DENIED:
  1500. zfcp_fsf_access_denied_port(req, port);
  1501. break;
  1502. case FSF_PORT_BOXED:
  1503. zfcp_erp_port_boxed(port, 50, req);
  1504. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1505. ZFCP_STATUS_FSFREQ_RETRY;
  1506. /* can't use generic zfcp_erp_modify_port_status because
  1507. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1508. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1509. list_for_each_entry(unit, &port->unit_list_head, list)
  1510. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1511. &unit->status);
  1512. break;
  1513. case FSF_ADAPTER_STATUS_AVAILABLE:
  1514. switch (header->fsf_status_qual.word[0]) {
  1515. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1516. /* fall through */
  1517. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1518. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1519. break;
  1520. }
  1521. break;
  1522. case FSF_GOOD:
  1523. /* can't use generic zfcp_erp_modify_port_status because
  1524. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1525. */
  1526. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1527. list_for_each_entry(unit, &port->unit_list_head, list)
  1528. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1529. &unit->status);
  1530. break;
  1531. }
  1532. skip_fsfstatus:
  1533. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1534. }
  1535. /**
  1536. * zfcp_fsf_close_physical_port - close physical port
  1537. * @erp_action: pointer to struct zfcp_erp_action
  1538. * Returns: 0 on success
  1539. */
  1540. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1541. {
  1542. struct qdio_buffer_element *sbale;
  1543. struct zfcp_adapter *adapter = erp_action->adapter;
  1544. struct zfcp_fsf_req *req;
  1545. int retval = -EIO;
  1546. spin_lock_bh(&adapter->req_q_lock);
  1547. if (zfcp_fsf_req_sbal_get(adapter))
  1548. goto out;
  1549. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1550. ZFCP_REQ_AUTO_CLEANUP,
  1551. adapter->pool.fsf_req_erp);
  1552. if (IS_ERR(req)) {
  1553. retval = PTR_ERR(req);
  1554. goto out;
  1555. }
  1556. sbale = zfcp_qdio_sbale_req(req);
  1557. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1558. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1559. req->data = erp_action->port;
  1560. req->qtcb->header.port_handle = erp_action->port->handle;
  1561. req->erp_action = erp_action;
  1562. req->handler = zfcp_fsf_close_physical_port_handler;
  1563. erp_action->fsf_req = req;
  1564. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1565. &erp_action->port->status);
  1566. zfcp_fsf_start_erp_timer(req);
  1567. retval = zfcp_fsf_req_send(req);
  1568. if (retval) {
  1569. zfcp_fsf_req_free(req);
  1570. erp_action->fsf_req = NULL;
  1571. }
  1572. out:
  1573. spin_unlock_bh(&adapter->req_q_lock);
  1574. return retval;
  1575. }
  1576. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1577. {
  1578. struct zfcp_adapter *adapter = req->adapter;
  1579. struct zfcp_unit *unit = req->data;
  1580. struct fsf_qtcb_header *header = &req->qtcb->header;
  1581. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1582. struct fsf_queue_designator *queue_designator =
  1583. &header->fsf_status_qual.fsf_queue_designator;
  1584. int exclusive, readwrite;
  1585. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1586. return;
  1587. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1588. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1589. ZFCP_STATUS_UNIT_SHARED |
  1590. ZFCP_STATUS_UNIT_READONLY,
  1591. &unit->status);
  1592. switch (header->fsf_status) {
  1593. case FSF_PORT_HANDLE_NOT_VALID:
  1594. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1595. /* fall through */
  1596. case FSF_LUN_ALREADY_OPEN:
  1597. break;
  1598. case FSF_ACCESS_DENIED:
  1599. zfcp_fsf_access_denied_unit(req, unit);
  1600. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1601. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1602. break;
  1603. case FSF_PORT_BOXED:
  1604. zfcp_erp_port_boxed(unit->port, 51, req);
  1605. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1606. ZFCP_STATUS_FSFREQ_RETRY;
  1607. break;
  1608. case FSF_LUN_SHARING_VIOLATION:
  1609. if (header->fsf_status_qual.word[0])
  1610. dev_warn(&adapter->ccw_device->dev,
  1611. "LUN 0x%Lx on port 0x%Lx is already in "
  1612. "use by CSS%d, MIF Image ID %x\n",
  1613. (unsigned long long)unit->fcp_lun,
  1614. (unsigned long long)unit->port->wwpn,
  1615. queue_designator->cssid,
  1616. queue_designator->hla);
  1617. else
  1618. zfcp_act_eval_err(adapter,
  1619. header->fsf_status_qual.word[2]);
  1620. zfcp_erp_unit_access_denied(unit, 60, req);
  1621. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1622. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1623. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1624. break;
  1625. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1626. dev_warn(&adapter->ccw_device->dev,
  1627. "No handle is available for LUN "
  1628. "0x%016Lx on port 0x%016Lx\n",
  1629. (unsigned long long)unit->fcp_lun,
  1630. (unsigned long long)unit->port->wwpn);
  1631. zfcp_erp_unit_failed(unit, 34, req);
  1632. /* fall through */
  1633. case FSF_INVALID_COMMAND_OPTION:
  1634. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1635. break;
  1636. case FSF_ADAPTER_STATUS_AVAILABLE:
  1637. switch (header->fsf_status_qual.word[0]) {
  1638. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1639. zfcp_test_link(unit->port);
  1640. /* fall through */
  1641. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1642. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1643. break;
  1644. }
  1645. break;
  1646. case FSF_GOOD:
  1647. unit->handle = header->lun_handle;
  1648. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1649. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1650. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1651. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1652. exclusive = (bottom->lun_access_info &
  1653. FSF_UNIT_ACCESS_EXCLUSIVE);
  1654. readwrite = (bottom->lun_access_info &
  1655. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1656. if (!exclusive)
  1657. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1658. &unit->status);
  1659. if (!readwrite) {
  1660. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1661. &unit->status);
  1662. dev_info(&adapter->ccw_device->dev,
  1663. "SCSI device at LUN 0x%016Lx on port "
  1664. "0x%016Lx opened read-only\n",
  1665. (unsigned long long)unit->fcp_lun,
  1666. (unsigned long long)unit->port->wwpn);
  1667. }
  1668. if (exclusive && !readwrite) {
  1669. dev_err(&adapter->ccw_device->dev,
  1670. "Exclusive read-only access not "
  1671. "supported (unit 0x%016Lx, "
  1672. "port 0x%016Lx)\n",
  1673. (unsigned long long)unit->fcp_lun,
  1674. (unsigned long long)unit->port->wwpn);
  1675. zfcp_erp_unit_failed(unit, 35, req);
  1676. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1677. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1678. } else if (!exclusive && readwrite) {
  1679. dev_err(&adapter->ccw_device->dev,
  1680. "Shared read-write access not "
  1681. "supported (unit 0x%016Lx, port "
  1682. "0x%016Lx)\n",
  1683. (unsigned long long)unit->fcp_lun,
  1684. (unsigned long long)unit->port->wwpn);
  1685. zfcp_erp_unit_failed(unit, 36, req);
  1686. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1687. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1688. }
  1689. }
  1690. break;
  1691. }
  1692. }
  1693. /**
  1694. * zfcp_fsf_open_unit - open unit
  1695. * @erp_action: pointer to struct zfcp_erp_action
  1696. * Returns: 0 on success, error otherwise
  1697. */
  1698. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1699. {
  1700. struct qdio_buffer_element *sbale;
  1701. struct zfcp_adapter *adapter = erp_action->adapter;
  1702. struct zfcp_fsf_req *req;
  1703. int retval = -EIO;
  1704. spin_lock_bh(&adapter->req_q_lock);
  1705. if (zfcp_fsf_req_sbal_get(adapter))
  1706. goto out;
  1707. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1708. ZFCP_REQ_AUTO_CLEANUP,
  1709. adapter->pool.fsf_req_erp);
  1710. if (IS_ERR(req)) {
  1711. retval = PTR_ERR(req);
  1712. goto out;
  1713. }
  1714. sbale = zfcp_qdio_sbale_req(req);
  1715. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1716. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1717. req->qtcb->header.port_handle = erp_action->port->handle;
  1718. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1719. req->handler = zfcp_fsf_open_unit_handler;
  1720. req->data = erp_action->unit;
  1721. req->erp_action = erp_action;
  1722. erp_action->fsf_req = req;
  1723. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1724. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1725. zfcp_fsf_start_erp_timer(req);
  1726. retval = zfcp_fsf_req_send(req);
  1727. if (retval) {
  1728. zfcp_fsf_req_free(req);
  1729. erp_action->fsf_req = NULL;
  1730. }
  1731. out:
  1732. spin_unlock_bh(&adapter->req_q_lock);
  1733. return retval;
  1734. }
  1735. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1736. {
  1737. struct zfcp_unit *unit = req->data;
  1738. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1739. return;
  1740. switch (req->qtcb->header.fsf_status) {
  1741. case FSF_PORT_HANDLE_NOT_VALID:
  1742. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1743. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1744. break;
  1745. case FSF_LUN_HANDLE_NOT_VALID:
  1746. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1747. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1748. break;
  1749. case FSF_PORT_BOXED:
  1750. zfcp_erp_port_boxed(unit->port, 52, req);
  1751. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1752. ZFCP_STATUS_FSFREQ_RETRY;
  1753. break;
  1754. case FSF_ADAPTER_STATUS_AVAILABLE:
  1755. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1756. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1757. zfcp_test_link(unit->port);
  1758. /* fall through */
  1759. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1760. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1761. break;
  1762. }
  1763. break;
  1764. case FSF_GOOD:
  1765. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1766. break;
  1767. }
  1768. }
  1769. /**
  1770. * zfcp_fsf_close_unit - close zfcp unit
  1771. * @erp_action: pointer to struct zfcp_unit
  1772. * Returns: 0 on success, error otherwise
  1773. */
  1774. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1775. {
  1776. struct qdio_buffer_element *sbale;
  1777. struct zfcp_adapter *adapter = erp_action->adapter;
  1778. struct zfcp_fsf_req *req;
  1779. int retval = -EIO;
  1780. spin_lock_bh(&adapter->req_q_lock);
  1781. if (zfcp_fsf_req_sbal_get(adapter))
  1782. goto out;
  1783. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1784. ZFCP_REQ_AUTO_CLEANUP,
  1785. adapter->pool.fsf_req_erp);
  1786. if (IS_ERR(req)) {
  1787. retval = PTR_ERR(req);
  1788. goto out;
  1789. }
  1790. sbale = zfcp_qdio_sbale_req(req);
  1791. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1792. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1793. req->qtcb->header.port_handle = erp_action->port->handle;
  1794. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1795. req->handler = zfcp_fsf_close_unit_handler;
  1796. req->data = erp_action->unit;
  1797. req->erp_action = erp_action;
  1798. erp_action->fsf_req = req;
  1799. zfcp_fsf_start_erp_timer(req);
  1800. retval = zfcp_fsf_req_send(req);
  1801. if (retval) {
  1802. zfcp_fsf_req_free(req);
  1803. erp_action->fsf_req = NULL;
  1804. }
  1805. out:
  1806. spin_unlock_bh(&adapter->req_q_lock);
  1807. return retval;
  1808. }
  1809. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1810. {
  1811. lat_rec->sum += lat;
  1812. lat_rec->min = min(lat_rec->min, lat);
  1813. lat_rec->max = max(lat_rec->max, lat);
  1814. }
  1815. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1816. {
  1817. struct fsf_qual_latency_info *lat_inf;
  1818. struct latency_cont *lat;
  1819. struct zfcp_unit *unit = req->unit;
  1820. unsigned long flags;
  1821. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1822. switch (req->qtcb->bottom.io.data_direction) {
  1823. case FSF_DATADIR_READ:
  1824. lat = &unit->latencies.read;
  1825. break;
  1826. case FSF_DATADIR_WRITE:
  1827. lat = &unit->latencies.write;
  1828. break;
  1829. case FSF_DATADIR_CMND:
  1830. lat = &unit->latencies.cmd;
  1831. break;
  1832. default:
  1833. return;
  1834. }
  1835. spin_lock_irqsave(&unit->latencies.lock, flags);
  1836. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1837. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1838. lat->counter++;
  1839. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1840. }
  1841. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1842. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1843. {
  1844. struct fsf_qual_latency_info *lat_inf;
  1845. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1846. struct request *req = scsi_cmnd->request;
  1847. struct zfcp_blk_drv_data trace;
  1848. int ticks = fsf_req->adapter->timer_ticks;
  1849. trace.flags = 0;
  1850. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1851. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1852. trace.flags |= ZFCP_BLK_LAT_VALID;
  1853. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1854. trace.channel_lat = lat_inf->channel_lat * ticks;
  1855. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1856. }
  1857. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1858. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1859. trace.inb_usage = fsf_req->qdio_inb_usage;
  1860. trace.outb_usage = fsf_req->qdio_outb_usage;
  1861. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1862. }
  1863. #else
  1864. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1865. {
  1866. }
  1867. #endif
  1868. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1869. {
  1870. struct scsi_cmnd *scpnt;
  1871. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1872. &(req->qtcb->bottom.io.fcp_rsp);
  1873. u32 sns_len;
  1874. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1875. unsigned long flags;
  1876. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1877. scpnt = req->data;
  1878. if (unlikely(!scpnt)) {
  1879. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1880. return;
  1881. }
  1882. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1883. set_host_byte(scpnt, DID_SOFT_ERROR);
  1884. set_driver_byte(scpnt, SUGGEST_RETRY);
  1885. goto skip_fsfstatus;
  1886. }
  1887. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1888. set_host_byte(scpnt, DID_ERROR);
  1889. goto skip_fsfstatus;
  1890. }
  1891. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1892. scpnt->result |= fcp_rsp_iu->scsi_status;
  1893. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1894. zfcp_fsf_req_latency(req);
  1895. zfcp_fsf_trace_latency(req);
  1896. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1897. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1898. set_host_byte(scpnt, DID_OK);
  1899. else {
  1900. set_host_byte(scpnt, DID_ERROR);
  1901. goto skip_fsfstatus;
  1902. }
  1903. }
  1904. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1905. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1906. fcp_rsp_iu->fcp_rsp_len;
  1907. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1908. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1909. memcpy(scpnt->sense_buffer,
  1910. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1911. }
  1912. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1913. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1914. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1915. scpnt->underflow)
  1916. set_host_byte(scpnt, DID_ERROR);
  1917. }
  1918. skip_fsfstatus:
  1919. if (scpnt->result != 0)
  1920. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1921. else if (scpnt->retries > 0)
  1922. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1923. else
  1924. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1925. scpnt->host_scribble = NULL;
  1926. (scpnt->scsi_done) (scpnt);
  1927. /*
  1928. * We must hold this lock until scsi_done has been called.
  1929. * Otherwise we may call scsi_done after abort regarding this
  1930. * command has completed.
  1931. * Note: scsi_done must not block!
  1932. */
  1933. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1934. }
  1935. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1936. {
  1937. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1938. &(req->qtcb->bottom.io.fcp_rsp);
  1939. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1940. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1941. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1942. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1943. }
  1944. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1945. {
  1946. struct zfcp_unit *unit;
  1947. struct fsf_qtcb_header *header = &req->qtcb->header;
  1948. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1949. unit = req->data;
  1950. else
  1951. unit = req->unit;
  1952. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1953. goto skip_fsfstatus;
  1954. switch (header->fsf_status) {
  1955. case FSF_HANDLE_MISMATCH:
  1956. case FSF_PORT_HANDLE_NOT_VALID:
  1957. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1958. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1959. break;
  1960. case FSF_FCPLUN_NOT_VALID:
  1961. case FSF_LUN_HANDLE_NOT_VALID:
  1962. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1963. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1964. break;
  1965. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1966. zfcp_fsf_class_not_supp(req);
  1967. break;
  1968. case FSF_ACCESS_DENIED:
  1969. zfcp_fsf_access_denied_unit(req, unit);
  1970. break;
  1971. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1972. dev_err(&req->adapter->ccw_device->dev,
  1973. "Incorrect direction %d, unit 0x%016Lx on port "
  1974. "0x%016Lx closed\n",
  1975. req->qtcb->bottom.io.data_direction,
  1976. (unsigned long long)unit->fcp_lun,
  1977. (unsigned long long)unit->port->wwpn);
  1978. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1979. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1980. break;
  1981. case FSF_CMND_LENGTH_NOT_VALID:
  1982. dev_err(&req->adapter->ccw_device->dev,
  1983. "Incorrect CDB length %d, unit 0x%016Lx on "
  1984. "port 0x%016Lx closed\n",
  1985. req->qtcb->bottom.io.fcp_cmnd_length,
  1986. (unsigned long long)unit->fcp_lun,
  1987. (unsigned long long)unit->port->wwpn);
  1988. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1989. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1990. break;
  1991. case FSF_PORT_BOXED:
  1992. zfcp_erp_port_boxed(unit->port, 53, req);
  1993. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1994. ZFCP_STATUS_FSFREQ_RETRY;
  1995. break;
  1996. case FSF_LUN_BOXED:
  1997. zfcp_erp_unit_boxed(unit, 54, req);
  1998. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1999. ZFCP_STATUS_FSFREQ_RETRY;
  2000. break;
  2001. case FSF_ADAPTER_STATUS_AVAILABLE:
  2002. if (header->fsf_status_qual.word[0] ==
  2003. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2004. zfcp_test_link(unit->port);
  2005. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2006. break;
  2007. }
  2008. skip_fsfstatus:
  2009. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2010. zfcp_fsf_send_fcp_ctm_handler(req);
  2011. else {
  2012. zfcp_fsf_send_fcp_command_task_handler(req);
  2013. req->unit = NULL;
  2014. zfcp_unit_put(unit);
  2015. }
  2016. }
  2017. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2018. {
  2019. u32 *fcp_dl_ptr;
  2020. /*
  2021. * fcp_dl_addr = start address of fcp_cmnd structure +
  2022. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2023. * SEE FCP-2 documentation
  2024. */
  2025. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2026. (fcp_cmd->add_fcp_cdb_length << 2));
  2027. *fcp_dl_ptr = fcp_dl;
  2028. }
  2029. /**
  2030. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2031. * @adapter: adapter where scsi command is issued
  2032. * @unit: unit where command is sent to
  2033. * @scsi_cmnd: scsi command to be sent
  2034. * @timer: timer to be started when request is initiated
  2035. * @req_flags: flags for fsf_request
  2036. */
  2037. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2038. struct zfcp_unit *unit,
  2039. struct scsi_cmnd *scsi_cmnd,
  2040. int use_timer, int req_flags)
  2041. {
  2042. struct zfcp_fsf_req *req;
  2043. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2044. unsigned int sbtype;
  2045. int real_bytes, retval = -EIO;
  2046. if (unlikely(!(atomic_read(&unit->status) &
  2047. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2048. return -EBUSY;
  2049. spin_lock(&adapter->req_q_lock);
  2050. if (!zfcp_fsf_sbal_available(adapter))
  2051. goto out;
  2052. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2053. adapter->pool.fsf_req_scsi);
  2054. if (IS_ERR(req)) {
  2055. retval = PTR_ERR(req);
  2056. goto out;
  2057. }
  2058. zfcp_unit_get(unit);
  2059. req->unit = unit;
  2060. req->data = scsi_cmnd;
  2061. req->handler = zfcp_fsf_send_fcp_command_handler;
  2062. req->qtcb->header.lun_handle = unit->handle;
  2063. req->qtcb->header.port_handle = unit->port->handle;
  2064. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2065. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2066. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2067. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2068. /*
  2069. * set depending on data direction:
  2070. * data direction bits in SBALE (SB Type)
  2071. * data direction bits in QTCB
  2072. * data direction bits in FCP_CMND IU
  2073. */
  2074. switch (scsi_cmnd->sc_data_direction) {
  2075. case DMA_NONE:
  2076. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2077. sbtype = SBAL_FLAGS0_TYPE_READ;
  2078. break;
  2079. case DMA_FROM_DEVICE:
  2080. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2081. sbtype = SBAL_FLAGS0_TYPE_READ;
  2082. fcp_cmnd_iu->rddata = 1;
  2083. break;
  2084. case DMA_TO_DEVICE:
  2085. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2086. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2087. fcp_cmnd_iu->wddata = 1;
  2088. break;
  2089. case DMA_BIDIRECTIONAL:
  2090. default:
  2091. retval = -EIO;
  2092. goto failed_scsi_cmnd;
  2093. }
  2094. if (likely((scsi_cmnd->device->simple_tags) ||
  2095. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2096. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2097. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2098. else
  2099. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2100. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2101. fcp_cmnd_iu->add_fcp_cdb_length =
  2102. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2103. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2104. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2105. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2106. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2107. scsi_sglist(scsi_cmnd),
  2108. FSF_MAX_SBALS_PER_REQ);
  2109. if (unlikely(real_bytes < 0)) {
  2110. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2111. retval = -EIO;
  2112. else {
  2113. dev_err(&adapter->ccw_device->dev,
  2114. "Oversize data package, unit 0x%016Lx "
  2115. "on port 0x%016Lx closed\n",
  2116. (unsigned long long)unit->fcp_lun,
  2117. (unsigned long long)unit->port->wwpn);
  2118. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2119. retval = -EINVAL;
  2120. }
  2121. goto failed_scsi_cmnd;
  2122. }
  2123. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2124. if (use_timer)
  2125. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2126. retval = zfcp_fsf_req_send(req);
  2127. if (unlikely(retval))
  2128. goto failed_scsi_cmnd;
  2129. goto out;
  2130. failed_scsi_cmnd:
  2131. zfcp_unit_put(unit);
  2132. zfcp_fsf_req_free(req);
  2133. scsi_cmnd->host_scribble = NULL;
  2134. out:
  2135. spin_unlock(&adapter->req_q_lock);
  2136. return retval;
  2137. }
  2138. /**
  2139. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2140. * @adapter: pointer to struct zfcp-adapter
  2141. * @unit: pointer to struct zfcp_unit
  2142. * @tm_flags: unsigned byte for task management flags
  2143. * @req_flags: int request flags
  2144. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2145. */
  2146. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2147. struct zfcp_unit *unit,
  2148. u8 tm_flags, int req_flags)
  2149. {
  2150. struct qdio_buffer_element *sbale;
  2151. struct zfcp_fsf_req *req = NULL;
  2152. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2153. if (unlikely(!(atomic_read(&unit->status) &
  2154. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2155. return NULL;
  2156. spin_lock(&adapter->req_q_lock);
  2157. if (!zfcp_fsf_sbal_available(adapter))
  2158. goto out;
  2159. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2160. adapter->pool.fsf_req_scsi);
  2161. if (IS_ERR(req)) {
  2162. req = NULL;
  2163. goto out;
  2164. }
  2165. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2166. req->data = unit;
  2167. req->handler = zfcp_fsf_send_fcp_command_handler;
  2168. req->qtcb->header.lun_handle = unit->handle;
  2169. req->qtcb->header.port_handle = unit->port->handle;
  2170. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2171. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2172. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2173. sizeof(u32);
  2174. sbale = zfcp_qdio_sbale_req(req);
  2175. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2176. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2177. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2178. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2179. fcp_cmnd_iu->task_management_flags = tm_flags;
  2180. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2181. if (!zfcp_fsf_req_send(req))
  2182. goto out;
  2183. zfcp_fsf_req_free(req);
  2184. req = NULL;
  2185. out:
  2186. spin_unlock(&adapter->req_q_lock);
  2187. return req;
  2188. }
  2189. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2190. {
  2191. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2192. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2193. }
  2194. /**
  2195. * zfcp_fsf_control_file - control file upload/download
  2196. * @adapter: pointer to struct zfcp_adapter
  2197. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2198. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2199. */
  2200. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2201. struct zfcp_fsf_cfdc *fsf_cfdc)
  2202. {
  2203. struct qdio_buffer_element *sbale;
  2204. struct zfcp_fsf_req *req = NULL;
  2205. struct fsf_qtcb_bottom_support *bottom;
  2206. int direction, retval = -EIO, bytes;
  2207. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2208. return ERR_PTR(-EOPNOTSUPP);
  2209. switch (fsf_cfdc->command) {
  2210. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2211. direction = SBAL_FLAGS0_TYPE_WRITE;
  2212. break;
  2213. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2214. direction = SBAL_FLAGS0_TYPE_READ;
  2215. break;
  2216. default:
  2217. return ERR_PTR(-EINVAL);
  2218. }
  2219. spin_lock_bh(&adapter->req_q_lock);
  2220. if (zfcp_fsf_req_sbal_get(adapter))
  2221. goto out;
  2222. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2223. if (IS_ERR(req)) {
  2224. retval = -EPERM;
  2225. goto out;
  2226. }
  2227. req->handler = zfcp_fsf_control_file_handler;
  2228. sbale = zfcp_qdio_sbale_req(req);
  2229. sbale[0].flags |= direction;
  2230. bottom = &req->qtcb->bottom.support;
  2231. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2232. bottom->option = fsf_cfdc->option;
  2233. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2234. FSF_MAX_SBALS_PER_REQ);
  2235. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2236. retval = -ENOMEM;
  2237. zfcp_fsf_req_free(req);
  2238. goto out;
  2239. }
  2240. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2241. retval = zfcp_fsf_req_send(req);
  2242. out:
  2243. spin_unlock_bh(&adapter->req_q_lock);
  2244. if (!retval) {
  2245. wait_event(req->completion_wq,
  2246. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2247. return req;
  2248. }
  2249. return ERR_PTR(retval);
  2250. }