zfcp_fsf.c 69 KB

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