zfcp_fsf.c 73 KB

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