zfcp_fsf.c 71 KB

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