zfcp_fsf.c 72 KB

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