zfcp_fsf.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corp. 2002, 2015
  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_or(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_INCOMING_ELS)
  233. zfcp_fc_conditional_port_scan(adapter);
  234. break;
  235. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  236. adapter->adapter_features = sr_buf->payload.word[0];
  237. break;
  238. }
  239. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  240. zfcp_fsf_req_free(req);
  241. atomic_inc(&adapter->stat_miss);
  242. queue_work(adapter->work_queue, &adapter->stat_work);
  243. }
  244. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  245. {
  246. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  247. case FSF_SQ_FCP_RSP_AVAILABLE:
  248. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  249. case FSF_SQ_NO_RETRY_POSSIBLE:
  250. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  251. return;
  252. case FSF_SQ_COMMAND_ABORTED:
  253. break;
  254. case FSF_SQ_NO_RECOM:
  255. dev_err(&req->adapter->ccw_device->dev,
  256. "The FCP adapter reported a problem "
  257. "that cannot be recovered\n");
  258. zfcp_qdio_siosl(req->adapter);
  259. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  260. break;
  261. }
  262. /* all non-return stats set FSFREQ_ERROR*/
  263. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  264. }
  265. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  266. {
  267. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  268. return;
  269. switch (req->qtcb->header.fsf_status) {
  270. case FSF_UNKNOWN_COMMAND:
  271. dev_err(&req->adapter->ccw_device->dev,
  272. "The FCP adapter does not recognize the command 0x%x\n",
  273. req->qtcb->header.fsf_command);
  274. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  276. break;
  277. case FSF_ADAPTER_STATUS_AVAILABLE:
  278. zfcp_fsf_fsfstatus_qual_eval(req);
  279. break;
  280. }
  281. }
  282. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  283. {
  284. struct zfcp_adapter *adapter = req->adapter;
  285. struct fsf_qtcb *qtcb = req->qtcb;
  286. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  287. zfcp_dbf_hba_fsf_response(req);
  288. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  289. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  290. return;
  291. }
  292. switch (qtcb->prefix.prot_status) {
  293. case FSF_PROT_GOOD:
  294. case FSF_PROT_FSF_STATUS_PRESENTED:
  295. return;
  296. case FSF_PROT_QTCB_VERSION_ERROR:
  297. dev_err(&adapter->ccw_device->dev,
  298. "QTCB version 0x%x not supported by FCP adapter "
  299. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  300. psq->word[0], psq->word[1]);
  301. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  302. break;
  303. case FSF_PROT_ERROR_STATE:
  304. case FSF_PROT_SEQ_NUMB_ERROR:
  305. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  306. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  307. break;
  308. case FSF_PROT_UNSUPP_QTCB_TYPE:
  309. dev_err(&adapter->ccw_device->dev,
  310. "The QTCB type is not supported by the FCP adapter\n");
  311. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  312. break;
  313. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  314. atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  315. &adapter->status);
  316. break;
  317. case FSF_PROT_DUPLICATE_REQUEST_ID:
  318. dev_err(&adapter->ccw_device->dev,
  319. "0x%Lx is an ambiguous request identifier\n",
  320. (unsigned long long)qtcb->bottom.support.req_handle);
  321. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  322. break;
  323. case FSF_PROT_LINK_DOWN:
  324. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  325. /* go through reopen to flush pending requests */
  326. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  327. break;
  328. case FSF_PROT_REEST_QUEUE:
  329. /* All ports should be marked as ready to run again */
  330. zfcp_erp_set_adapter_status(adapter,
  331. ZFCP_STATUS_COMMON_RUNNING);
  332. zfcp_erp_adapter_reopen(adapter,
  333. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  334. ZFCP_STATUS_COMMON_ERP_FAILED,
  335. "fspse_8");
  336. break;
  337. default:
  338. dev_err(&adapter->ccw_device->dev,
  339. "0x%x is not a valid transfer protocol status\n",
  340. qtcb->prefix.prot_status);
  341. zfcp_qdio_siosl(adapter);
  342. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  343. }
  344. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  345. }
  346. /**
  347. * zfcp_fsf_req_complete - process completion of a FSF request
  348. * @fsf_req: The FSF request that has been completed.
  349. *
  350. * When a request has been completed either from the FCP adapter,
  351. * or it has been dismissed due to a queue shutdown, this function
  352. * is called to process the completion status and trigger further
  353. * events related to the FSF request.
  354. */
  355. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  356. {
  357. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  358. zfcp_fsf_status_read_handler(req);
  359. return;
  360. }
  361. del_timer(&req->timer);
  362. zfcp_fsf_protstatus_eval(req);
  363. zfcp_fsf_fsfstatus_eval(req);
  364. req->handler(req);
  365. if (req->erp_action)
  366. zfcp_erp_notify(req->erp_action, 0);
  367. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  368. zfcp_fsf_req_free(req);
  369. else
  370. complete(&req->completion);
  371. }
  372. /**
  373. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  374. * @adapter: pointer to struct zfcp_adapter
  375. *
  376. * Never ever call this without shutting down the adapter first.
  377. * Otherwise the adapter would continue using and corrupting s390 storage.
  378. * Included BUG_ON() call to ensure this is done.
  379. * ERP is supposed to be the only user of this function.
  380. */
  381. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  382. {
  383. struct zfcp_fsf_req *req, *tmp;
  384. LIST_HEAD(remove_queue);
  385. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  386. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  387. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  388. list_del(&req->list);
  389. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  390. zfcp_fsf_req_complete(req);
  391. }
  392. }
  393. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  394. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  395. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  396. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  397. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  398. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  399. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  400. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  401. {
  402. u32 fdmi_speed = 0;
  403. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  404. fdmi_speed |= FC_PORTSPEED_1GBIT;
  405. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  406. fdmi_speed |= FC_PORTSPEED_2GBIT;
  407. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  408. fdmi_speed |= FC_PORTSPEED_4GBIT;
  409. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  410. fdmi_speed |= FC_PORTSPEED_10GBIT;
  411. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  412. fdmi_speed |= FC_PORTSPEED_8GBIT;
  413. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  414. fdmi_speed |= FC_PORTSPEED_16GBIT;
  415. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  416. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  417. return fdmi_speed;
  418. }
  419. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  420. {
  421. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  422. struct zfcp_adapter *adapter = req->adapter;
  423. struct Scsi_Host *shost = adapter->scsi_host;
  424. struct fc_els_flogi *nsp, *plogi;
  425. /* adjust pointers for missing command code */
  426. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  427. - sizeof(u32));
  428. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  429. - sizeof(u32));
  430. if (req->data)
  431. memcpy(req->data, bottom, sizeof(*bottom));
  432. fc_host_port_name(shost) = nsp->fl_wwpn;
  433. fc_host_node_name(shost) = nsp->fl_wwnn;
  434. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  435. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  436. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  437. (u16)FSF_STATUS_READS_RECOM);
  438. if (fc_host_permanent_port_name(shost) == -1)
  439. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  440. zfcp_scsi_set_prot(adapter);
  441. /* no error return above here, otherwise must fix call chains */
  442. /* do not evaluate invalid fields */
  443. if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
  444. return 0;
  445. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  446. fc_host_speed(shost) =
  447. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  448. adapter->hydra_version = bottom->adapter_type;
  449. switch (bottom->fc_topology) {
  450. case FSF_TOPO_P2P:
  451. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  452. adapter->peer_wwpn = plogi->fl_wwpn;
  453. adapter->peer_wwnn = plogi->fl_wwnn;
  454. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  455. break;
  456. case FSF_TOPO_FABRIC:
  457. if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
  458. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  459. else
  460. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  461. break;
  462. case FSF_TOPO_AL:
  463. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  464. /* fall through */
  465. default:
  466. dev_err(&adapter->ccw_device->dev,
  467. "Unknown or unsupported arbitrated loop "
  468. "fibre channel topology detected\n");
  469. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  470. return -EIO;
  471. }
  472. return 0;
  473. }
  474. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  475. {
  476. struct zfcp_adapter *adapter = req->adapter;
  477. struct fsf_qtcb *qtcb = req->qtcb;
  478. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  479. struct Scsi_Host *shost = adapter->scsi_host;
  480. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  481. return;
  482. adapter->fsf_lic_version = bottom->lic_version;
  483. adapter->adapter_features = bottom->adapter_features;
  484. adapter->connection_features = bottom->connection_features;
  485. adapter->peer_wwpn = 0;
  486. adapter->peer_wwnn = 0;
  487. adapter->peer_d_id = 0;
  488. switch (qtcb->header.fsf_status) {
  489. case FSF_GOOD:
  490. if (zfcp_fsf_exchange_config_evaluate(req))
  491. return;
  492. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  493. dev_err(&adapter->ccw_device->dev,
  494. "FCP adapter maximum QTCB size (%d bytes) "
  495. "is too small\n",
  496. bottom->max_qtcb_size);
  497. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  498. return;
  499. }
  500. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  501. &adapter->status);
  502. break;
  503. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  504. fc_host_node_name(shost) = 0;
  505. fc_host_port_name(shost) = 0;
  506. fc_host_port_id(shost) = 0;
  507. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  508. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  509. adapter->hydra_version = 0;
  510. /* avoids adapter shutdown to be able to recognize
  511. * events such as LINK UP */
  512. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  513. &adapter->status);
  514. zfcp_fsf_link_down_info_eval(req,
  515. &qtcb->header.fsf_status_qual.link_down_info);
  516. if (zfcp_fsf_exchange_config_evaluate(req))
  517. return;
  518. break;
  519. default:
  520. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  521. return;
  522. }
  523. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  524. adapter->hardware_version = bottom->hardware_version;
  525. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  526. min(FC_SERIAL_NUMBER_SIZE, 17));
  527. EBCASC(fc_host_serial_number(shost),
  528. min(FC_SERIAL_NUMBER_SIZE, 17));
  529. }
  530. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  531. dev_err(&adapter->ccw_device->dev,
  532. "The FCP adapter only supports newer "
  533. "control block versions\n");
  534. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  535. return;
  536. }
  537. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  538. dev_err(&adapter->ccw_device->dev,
  539. "The FCP adapter only supports older "
  540. "control block versions\n");
  541. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  542. }
  543. }
  544. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  545. {
  546. struct zfcp_adapter *adapter = req->adapter;
  547. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  548. struct Scsi_Host *shost = adapter->scsi_host;
  549. if (req->data)
  550. memcpy(req->data, bottom, sizeof(*bottom));
  551. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  552. fc_host_permanent_port_name(shost) = bottom->wwpn;
  553. } else
  554. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  555. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  556. fc_host_supported_speeds(shost) =
  557. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  558. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  559. FC_FC4_LIST_SIZE);
  560. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  561. FC_FC4_LIST_SIZE);
  562. }
  563. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  564. {
  565. struct fsf_qtcb *qtcb = req->qtcb;
  566. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  567. return;
  568. switch (qtcb->header.fsf_status) {
  569. case FSF_GOOD:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. break;
  572. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  573. zfcp_fsf_exchange_port_evaluate(req);
  574. zfcp_fsf_link_down_info_eval(req,
  575. &qtcb->header.fsf_status_qual.link_down_info);
  576. break;
  577. }
  578. }
  579. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  580. {
  581. struct zfcp_fsf_req *req;
  582. if (likely(pool))
  583. req = mempool_alloc(pool, GFP_ATOMIC);
  584. else
  585. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  586. if (unlikely(!req))
  587. return NULL;
  588. memset(req, 0, sizeof(*req));
  589. req->pool = pool;
  590. return req;
  591. }
  592. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  593. {
  594. struct fsf_qtcb *qtcb;
  595. if (likely(pool))
  596. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  597. else
  598. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  599. if (unlikely(!qtcb))
  600. return NULL;
  601. memset(qtcb, 0, sizeof(*qtcb));
  602. return qtcb;
  603. }
  604. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  605. u32 fsf_cmd, u8 sbtype,
  606. mempool_t *pool)
  607. {
  608. struct zfcp_adapter *adapter = qdio->adapter;
  609. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  610. if (unlikely(!req))
  611. return ERR_PTR(-ENOMEM);
  612. if (adapter->req_no == 0)
  613. adapter->req_no++;
  614. INIT_LIST_HEAD(&req->list);
  615. init_timer(&req->timer);
  616. init_completion(&req->completion);
  617. req->adapter = adapter;
  618. req->fsf_command = fsf_cmd;
  619. req->req_id = adapter->req_no;
  620. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  621. if (likely(pool))
  622. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  623. else
  624. req->qtcb = zfcp_qtcb_alloc(NULL);
  625. if (unlikely(!req->qtcb)) {
  626. zfcp_fsf_req_free(req);
  627. return ERR_PTR(-ENOMEM);
  628. }
  629. req->seq_no = adapter->fsf_req_seq_no;
  630. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  631. req->qtcb->prefix.req_id = req->req_id;
  632. req->qtcb->prefix.ulp_info = 26;
  633. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  634. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  635. req->qtcb->header.req_handle = req->req_id;
  636. req->qtcb->header.fsf_command = req->fsf_command;
  637. }
  638. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  639. req->qtcb, sizeof(struct fsf_qtcb));
  640. return req;
  641. }
  642. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  643. {
  644. struct zfcp_adapter *adapter = req->adapter;
  645. struct zfcp_qdio *qdio = adapter->qdio;
  646. int with_qtcb = (req->qtcb != NULL);
  647. int req_id = req->req_id;
  648. zfcp_reqlist_add(adapter->req_list, req);
  649. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  650. req->issued = get_tod_clock();
  651. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  652. del_timer(&req->timer);
  653. /* lookup request again, list might have changed */
  654. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  655. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  656. return -EIO;
  657. }
  658. /* Don't increase for unsolicited status */
  659. if (with_qtcb)
  660. adapter->fsf_req_seq_no++;
  661. adapter->req_no++;
  662. return 0;
  663. }
  664. /**
  665. * zfcp_fsf_status_read - send status read request
  666. * @adapter: pointer to struct zfcp_adapter
  667. * @req_flags: request flags
  668. * Returns: 0 on success, ERROR otherwise
  669. */
  670. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  671. {
  672. struct zfcp_adapter *adapter = qdio->adapter;
  673. struct zfcp_fsf_req *req;
  674. struct fsf_status_read_buffer *sr_buf;
  675. struct page *page;
  676. int retval = -EIO;
  677. spin_lock_irq(&qdio->req_q_lock);
  678. if (zfcp_qdio_sbal_get(qdio))
  679. goto out;
  680. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  681. SBAL_SFLAGS0_TYPE_STATUS,
  682. adapter->pool.status_read_req);
  683. if (IS_ERR(req)) {
  684. retval = PTR_ERR(req);
  685. goto out;
  686. }
  687. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  688. if (!page) {
  689. retval = -ENOMEM;
  690. goto failed_buf;
  691. }
  692. sr_buf = page_address(page);
  693. memset(sr_buf, 0, sizeof(*sr_buf));
  694. req->data = sr_buf;
  695. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  696. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  697. retval = zfcp_fsf_req_send(req);
  698. if (retval)
  699. goto failed_req_send;
  700. goto out;
  701. failed_req_send:
  702. req->data = NULL;
  703. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  704. failed_buf:
  705. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  706. zfcp_fsf_req_free(req);
  707. out:
  708. spin_unlock_irq(&qdio->req_q_lock);
  709. return retval;
  710. }
  711. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  712. {
  713. struct scsi_device *sdev = req->data;
  714. struct zfcp_scsi_dev *zfcp_sdev;
  715. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  716. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  717. return;
  718. zfcp_sdev = sdev_to_zfcp(sdev);
  719. switch (req->qtcb->header.fsf_status) {
  720. case FSF_PORT_HANDLE_NOT_VALID:
  721. if (fsq->word[0] == fsq->word[1]) {
  722. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  723. "fsafch1");
  724. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  725. }
  726. break;
  727. case FSF_LUN_HANDLE_NOT_VALID:
  728. if (fsq->word[0] == fsq->word[1]) {
  729. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  730. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  731. }
  732. break;
  733. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  734. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  735. break;
  736. case FSF_PORT_BOXED:
  737. zfcp_erp_set_port_status(zfcp_sdev->port,
  738. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  739. zfcp_erp_port_reopen(zfcp_sdev->port,
  740. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  741. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  742. break;
  743. case FSF_LUN_BOXED:
  744. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  745. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  746. "fsafch4");
  747. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  748. break;
  749. case FSF_ADAPTER_STATUS_AVAILABLE:
  750. switch (fsq->word[0]) {
  751. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  752. zfcp_fc_test_link(zfcp_sdev->port);
  753. /* fall through */
  754. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  755. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  756. break;
  757. }
  758. break;
  759. case FSF_GOOD:
  760. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  761. break;
  762. }
  763. }
  764. /**
  765. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  766. * @scmnd: The SCSI command to abort
  767. * Returns: pointer to struct zfcp_fsf_req
  768. */
  769. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  770. {
  771. struct zfcp_fsf_req *req = NULL;
  772. struct scsi_device *sdev = scmnd->device;
  773. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  774. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  775. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  776. spin_lock_irq(&qdio->req_q_lock);
  777. if (zfcp_qdio_sbal_get(qdio))
  778. goto out;
  779. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  780. SBAL_SFLAGS0_TYPE_READ,
  781. qdio->adapter->pool.scsi_abort);
  782. if (IS_ERR(req)) {
  783. req = NULL;
  784. goto out;
  785. }
  786. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  787. ZFCP_STATUS_COMMON_UNBLOCKED)))
  788. goto out_error_free;
  789. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  790. req->data = sdev;
  791. req->handler = zfcp_fsf_abort_fcp_command_handler;
  792. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  793. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  794. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  795. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  796. if (!zfcp_fsf_req_send(req))
  797. goto out;
  798. out_error_free:
  799. zfcp_fsf_req_free(req);
  800. req = NULL;
  801. out:
  802. spin_unlock_irq(&qdio->req_q_lock);
  803. return req;
  804. }
  805. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  806. {
  807. struct zfcp_adapter *adapter = req->adapter;
  808. struct zfcp_fsf_ct_els *ct = req->data;
  809. struct fsf_qtcb_header *header = &req->qtcb->header;
  810. ct->status = -EINVAL;
  811. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  812. goto skip_fsfstatus;
  813. switch (header->fsf_status) {
  814. case FSF_GOOD:
  815. zfcp_dbf_san_res("fsscth2", req);
  816. ct->status = 0;
  817. break;
  818. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  819. zfcp_fsf_class_not_supp(req);
  820. break;
  821. case FSF_ADAPTER_STATUS_AVAILABLE:
  822. switch (header->fsf_status_qual.word[0]){
  823. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  824. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  825. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  826. break;
  827. }
  828. break;
  829. case FSF_PORT_BOXED:
  830. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  831. break;
  832. case FSF_PORT_HANDLE_NOT_VALID:
  833. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  834. /* fall through */
  835. case FSF_GENERIC_COMMAND_REJECTED:
  836. case FSF_PAYLOAD_SIZE_MISMATCH:
  837. case FSF_REQUEST_SIZE_TOO_LARGE:
  838. case FSF_RESPONSE_SIZE_TOO_LARGE:
  839. case FSF_SBAL_MISMATCH:
  840. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  841. break;
  842. }
  843. skip_fsfstatus:
  844. if (ct->handler)
  845. ct->handler(ct->handler_data);
  846. }
  847. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  848. struct zfcp_qdio_req *q_req,
  849. struct scatterlist *sg_req,
  850. struct scatterlist *sg_resp)
  851. {
  852. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  853. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  854. zfcp_qdio_set_sbale_last(qdio, q_req);
  855. }
  856. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  857. struct scatterlist *sg_req,
  858. struct scatterlist *sg_resp)
  859. {
  860. struct zfcp_adapter *adapter = req->adapter;
  861. struct zfcp_qdio *qdio = adapter->qdio;
  862. struct fsf_qtcb *qtcb = req->qtcb;
  863. u32 feat = adapter->adapter_features;
  864. if (zfcp_adapter_multi_buffer_active(adapter)) {
  865. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  866. return -EIO;
  867. qtcb->bottom.support.req_buf_length =
  868. zfcp_qdio_real_bytes(sg_req);
  869. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  870. return -EIO;
  871. qtcb->bottom.support.resp_buf_length =
  872. zfcp_qdio_real_bytes(sg_resp);
  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. ct->d_id = wka_port->d_id;
  943. req->data = ct;
  944. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  945. ret = zfcp_fsf_req_send(req);
  946. if (ret)
  947. goto failed_send;
  948. goto out;
  949. failed_send:
  950. zfcp_fsf_req_free(req);
  951. out:
  952. spin_unlock_irq(&qdio->req_q_lock);
  953. return ret;
  954. }
  955. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  956. {
  957. struct zfcp_fsf_ct_els *send_els = req->data;
  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_SBAL_MISMATCH:
  985. /* should never occur, avoided in zfcp_fsf_send_els */
  986. /* fall through */
  987. default:
  988. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  989. break;
  990. }
  991. skip_fsfstatus:
  992. if (send_els->handler)
  993. send_els->handler(send_els->handler_data);
  994. }
  995. /**
  996. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  997. * @els: pointer to struct zfcp_send_els with data for the command
  998. */
  999. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  1000. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  1001. {
  1002. struct zfcp_fsf_req *req;
  1003. struct zfcp_qdio *qdio = adapter->qdio;
  1004. int ret = -EIO;
  1005. spin_lock_irq(&qdio->req_q_lock);
  1006. if (zfcp_qdio_sbal_get(qdio))
  1007. goto out;
  1008. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1009. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1010. if (IS_ERR(req)) {
  1011. ret = PTR_ERR(req);
  1012. goto out;
  1013. }
  1014. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1015. if (!zfcp_adapter_multi_buffer_active(adapter))
  1016. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1017. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1018. if (ret)
  1019. goto failed_send;
  1020. hton24(req->qtcb->bottom.support.d_id, d_id);
  1021. req->handler = zfcp_fsf_send_els_handler;
  1022. els->d_id = d_id;
  1023. req->data = els;
  1024. zfcp_dbf_san_req("fssels1", req, d_id);
  1025. ret = zfcp_fsf_req_send(req);
  1026. if (ret)
  1027. goto failed_send;
  1028. goto out;
  1029. failed_send:
  1030. zfcp_fsf_req_free(req);
  1031. out:
  1032. spin_unlock_irq(&qdio->req_q_lock);
  1033. return ret;
  1034. }
  1035. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1036. {
  1037. struct zfcp_fsf_req *req;
  1038. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1039. int retval = -EIO;
  1040. spin_lock_irq(&qdio->req_q_lock);
  1041. if (zfcp_qdio_sbal_get(qdio))
  1042. goto out;
  1043. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1044. SBAL_SFLAGS0_TYPE_READ,
  1045. qdio->adapter->pool.erp_req);
  1046. if (IS_ERR(req)) {
  1047. retval = PTR_ERR(req);
  1048. goto out;
  1049. }
  1050. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1051. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1052. req->qtcb->bottom.config.feature_selection =
  1053. FSF_FEATURE_NOTIFICATION_LOST |
  1054. FSF_FEATURE_UPDATE_ALERT;
  1055. req->erp_action = erp_action;
  1056. req->handler = zfcp_fsf_exchange_config_data_handler;
  1057. erp_action->fsf_req_id = req->req_id;
  1058. zfcp_fsf_start_erp_timer(req);
  1059. retval = zfcp_fsf_req_send(req);
  1060. if (retval) {
  1061. zfcp_fsf_req_free(req);
  1062. erp_action->fsf_req_id = 0;
  1063. }
  1064. out:
  1065. spin_unlock_irq(&qdio->req_q_lock);
  1066. return retval;
  1067. }
  1068. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1069. struct fsf_qtcb_bottom_config *data)
  1070. {
  1071. struct zfcp_fsf_req *req = NULL;
  1072. int retval = -EIO;
  1073. spin_lock_irq(&qdio->req_q_lock);
  1074. if (zfcp_qdio_sbal_get(qdio))
  1075. goto out_unlock;
  1076. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1077. SBAL_SFLAGS0_TYPE_READ, NULL);
  1078. if (IS_ERR(req)) {
  1079. retval = PTR_ERR(req);
  1080. goto out_unlock;
  1081. }
  1082. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1083. req->handler = zfcp_fsf_exchange_config_data_handler;
  1084. req->qtcb->bottom.config.feature_selection =
  1085. FSF_FEATURE_NOTIFICATION_LOST |
  1086. FSF_FEATURE_UPDATE_ALERT;
  1087. if (data)
  1088. req->data = data;
  1089. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1090. retval = zfcp_fsf_req_send(req);
  1091. spin_unlock_irq(&qdio->req_q_lock);
  1092. if (!retval)
  1093. wait_for_completion(&req->completion);
  1094. zfcp_fsf_req_free(req);
  1095. return retval;
  1096. out_unlock:
  1097. spin_unlock_irq(&qdio->req_q_lock);
  1098. return retval;
  1099. }
  1100. /**
  1101. * zfcp_fsf_exchange_port_data - request information about local port
  1102. * @erp_action: ERP action for the adapter for which port data is requested
  1103. * Returns: 0 on success, error otherwise
  1104. */
  1105. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1106. {
  1107. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1108. struct zfcp_fsf_req *req;
  1109. int retval = -EIO;
  1110. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1111. return -EOPNOTSUPP;
  1112. spin_lock_irq(&qdio->req_q_lock);
  1113. if (zfcp_qdio_sbal_get(qdio))
  1114. goto out;
  1115. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1116. SBAL_SFLAGS0_TYPE_READ,
  1117. qdio->adapter->pool.erp_req);
  1118. if (IS_ERR(req)) {
  1119. retval = PTR_ERR(req);
  1120. goto out;
  1121. }
  1122. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1123. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1124. req->handler = zfcp_fsf_exchange_port_data_handler;
  1125. req->erp_action = erp_action;
  1126. erp_action->fsf_req_id = req->req_id;
  1127. zfcp_fsf_start_erp_timer(req);
  1128. retval = zfcp_fsf_req_send(req);
  1129. if (retval) {
  1130. zfcp_fsf_req_free(req);
  1131. erp_action->fsf_req_id = 0;
  1132. }
  1133. out:
  1134. spin_unlock_irq(&qdio->req_q_lock);
  1135. return retval;
  1136. }
  1137. /**
  1138. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1139. * @qdio: pointer to struct zfcp_qdio
  1140. * @data: pointer to struct fsf_qtcb_bottom_port
  1141. * Returns: 0 on success, error otherwise
  1142. */
  1143. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1144. struct fsf_qtcb_bottom_port *data)
  1145. {
  1146. struct zfcp_fsf_req *req = NULL;
  1147. int retval = -EIO;
  1148. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1149. return -EOPNOTSUPP;
  1150. spin_lock_irq(&qdio->req_q_lock);
  1151. if (zfcp_qdio_sbal_get(qdio))
  1152. goto out_unlock;
  1153. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1154. SBAL_SFLAGS0_TYPE_READ, NULL);
  1155. if (IS_ERR(req)) {
  1156. retval = PTR_ERR(req);
  1157. goto out_unlock;
  1158. }
  1159. if (data)
  1160. req->data = data;
  1161. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1162. req->handler = zfcp_fsf_exchange_port_data_handler;
  1163. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1164. retval = zfcp_fsf_req_send(req);
  1165. spin_unlock_irq(&qdio->req_q_lock);
  1166. if (!retval)
  1167. wait_for_completion(&req->completion);
  1168. zfcp_fsf_req_free(req);
  1169. return retval;
  1170. out_unlock:
  1171. spin_unlock_irq(&qdio->req_q_lock);
  1172. return retval;
  1173. }
  1174. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1175. {
  1176. struct zfcp_port *port = req->data;
  1177. struct fsf_qtcb_header *header = &req->qtcb->header;
  1178. struct fc_els_flogi *plogi;
  1179. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1180. goto out;
  1181. switch (header->fsf_status) {
  1182. case FSF_PORT_ALREADY_OPEN:
  1183. break;
  1184. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1185. dev_warn(&req->adapter->ccw_device->dev,
  1186. "Not enough FCP adapter resources to open "
  1187. "remote port 0x%016Lx\n",
  1188. (unsigned long long)port->wwpn);
  1189. zfcp_erp_set_port_status(port,
  1190. ZFCP_STATUS_COMMON_ERP_FAILED);
  1191. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1192. break;
  1193. case FSF_ADAPTER_STATUS_AVAILABLE:
  1194. switch (header->fsf_status_qual.word[0]) {
  1195. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1196. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1197. case FSF_SQ_NO_RETRY_POSSIBLE:
  1198. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1199. break;
  1200. }
  1201. break;
  1202. case FSF_GOOD:
  1203. port->handle = header->port_handle;
  1204. atomic_or(ZFCP_STATUS_COMMON_OPEN |
  1205. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1206. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1207. &port->status);
  1208. /* check whether D_ID has changed during open */
  1209. /*
  1210. * FIXME: This check is not airtight, as the FCP channel does
  1211. * not monitor closures of target port connections caused on
  1212. * the remote side. Thus, they might miss out on invalidating
  1213. * locally cached WWPNs (and other N_Port parameters) of gone
  1214. * target ports. So, our heroic attempt to make things safe
  1215. * could be undermined by 'open port' response data tagged with
  1216. * obsolete WWPNs. Another reason to monitor potential
  1217. * connection closures ourself at least (by interpreting
  1218. * incoming ELS' and unsolicited status). It just crosses my
  1219. * mind that one should be able to cross-check by means of
  1220. * another GID_PN straight after a port has been opened.
  1221. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1222. */
  1223. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1224. if (req->qtcb->bottom.support.els1_length >=
  1225. FSF_PLOGI_MIN_LEN)
  1226. zfcp_fc_plogi_evaluate(port, plogi);
  1227. break;
  1228. case FSF_UNKNOWN_OP_SUBTYPE:
  1229. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1230. break;
  1231. }
  1232. out:
  1233. put_device(&port->dev);
  1234. }
  1235. /**
  1236. * zfcp_fsf_open_port - create and send open port request
  1237. * @erp_action: pointer to struct zfcp_erp_action
  1238. * Returns: 0 on success, error otherwise
  1239. */
  1240. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1241. {
  1242. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1243. struct zfcp_port *port = erp_action->port;
  1244. struct zfcp_fsf_req *req;
  1245. int retval = -EIO;
  1246. spin_lock_irq(&qdio->req_q_lock);
  1247. if (zfcp_qdio_sbal_get(qdio))
  1248. goto out;
  1249. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1250. SBAL_SFLAGS0_TYPE_READ,
  1251. qdio->adapter->pool.erp_req);
  1252. if (IS_ERR(req)) {
  1253. retval = PTR_ERR(req);
  1254. goto out;
  1255. }
  1256. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1257. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1258. req->handler = zfcp_fsf_open_port_handler;
  1259. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1260. req->data = port;
  1261. req->erp_action = erp_action;
  1262. erp_action->fsf_req_id = req->req_id;
  1263. get_device(&port->dev);
  1264. zfcp_fsf_start_erp_timer(req);
  1265. retval = zfcp_fsf_req_send(req);
  1266. if (retval) {
  1267. zfcp_fsf_req_free(req);
  1268. erp_action->fsf_req_id = 0;
  1269. put_device(&port->dev);
  1270. }
  1271. out:
  1272. spin_unlock_irq(&qdio->req_q_lock);
  1273. return retval;
  1274. }
  1275. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1276. {
  1277. struct zfcp_port *port = req->data;
  1278. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1279. return;
  1280. switch (req->qtcb->header.fsf_status) {
  1281. case FSF_PORT_HANDLE_NOT_VALID:
  1282. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1283. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1284. break;
  1285. case FSF_ADAPTER_STATUS_AVAILABLE:
  1286. break;
  1287. case FSF_GOOD:
  1288. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1289. break;
  1290. }
  1291. }
  1292. /**
  1293. * zfcp_fsf_close_port - create and send close port request
  1294. * @erp_action: pointer to struct zfcp_erp_action
  1295. * Returns: 0 on success, error otherwise
  1296. */
  1297. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1298. {
  1299. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1300. struct zfcp_fsf_req *req;
  1301. int retval = -EIO;
  1302. spin_lock_irq(&qdio->req_q_lock);
  1303. if (zfcp_qdio_sbal_get(qdio))
  1304. goto out;
  1305. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1306. SBAL_SFLAGS0_TYPE_READ,
  1307. qdio->adapter->pool.erp_req);
  1308. if (IS_ERR(req)) {
  1309. retval = PTR_ERR(req);
  1310. goto out;
  1311. }
  1312. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1313. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1314. req->handler = zfcp_fsf_close_port_handler;
  1315. req->data = erp_action->port;
  1316. req->erp_action = erp_action;
  1317. req->qtcb->header.port_handle = erp_action->port->handle;
  1318. erp_action->fsf_req_id = req->req_id;
  1319. zfcp_fsf_start_erp_timer(req);
  1320. retval = zfcp_fsf_req_send(req);
  1321. if (retval) {
  1322. zfcp_fsf_req_free(req);
  1323. erp_action->fsf_req_id = 0;
  1324. }
  1325. out:
  1326. spin_unlock_irq(&qdio->req_q_lock);
  1327. return retval;
  1328. }
  1329. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1330. {
  1331. struct zfcp_fc_wka_port *wka_port = req->data;
  1332. struct fsf_qtcb_header *header = &req->qtcb->header;
  1333. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1334. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1335. goto out;
  1336. }
  1337. switch (header->fsf_status) {
  1338. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1339. dev_warn(&req->adapter->ccw_device->dev,
  1340. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1341. /* fall through */
  1342. case FSF_ADAPTER_STATUS_AVAILABLE:
  1343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1344. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1345. break;
  1346. case FSF_GOOD:
  1347. wka_port->handle = header->port_handle;
  1348. /* fall through */
  1349. case FSF_PORT_ALREADY_OPEN:
  1350. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1351. }
  1352. out:
  1353. wake_up(&wka_port->completion_wq);
  1354. }
  1355. /**
  1356. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1357. * @wka_port: pointer to struct zfcp_fc_wka_port
  1358. * Returns: 0 on success, error otherwise
  1359. */
  1360. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1361. {
  1362. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1363. struct zfcp_fsf_req *req = NULL;
  1364. int retval = -EIO;
  1365. spin_lock_irq(&qdio->req_q_lock);
  1366. if (zfcp_qdio_sbal_get(qdio))
  1367. goto out;
  1368. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1369. SBAL_SFLAGS0_TYPE_READ,
  1370. qdio->adapter->pool.erp_req);
  1371. if (IS_ERR(req)) {
  1372. retval = PTR_ERR(req);
  1373. goto out;
  1374. }
  1375. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1376. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1377. req->handler = zfcp_fsf_open_wka_port_handler;
  1378. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1379. req->data = wka_port;
  1380. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1381. retval = zfcp_fsf_req_send(req);
  1382. if (retval)
  1383. zfcp_fsf_req_free(req);
  1384. out:
  1385. spin_unlock_irq(&qdio->req_q_lock);
  1386. if (req && !IS_ERR(req))
  1387. zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req->req_id);
  1388. return retval;
  1389. }
  1390. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1391. {
  1392. struct zfcp_fc_wka_port *wka_port = req->data;
  1393. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1394. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1395. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1396. }
  1397. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1398. wake_up(&wka_port->completion_wq);
  1399. }
  1400. /**
  1401. * zfcp_fsf_close_wka_port - create and send close wka port request
  1402. * @wka_port: WKA port to open
  1403. * Returns: 0 on success, error otherwise
  1404. */
  1405. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1406. {
  1407. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1408. struct zfcp_fsf_req *req = NULL;
  1409. int retval = -EIO;
  1410. spin_lock_irq(&qdio->req_q_lock);
  1411. if (zfcp_qdio_sbal_get(qdio))
  1412. goto out;
  1413. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1414. SBAL_SFLAGS0_TYPE_READ,
  1415. qdio->adapter->pool.erp_req);
  1416. if (IS_ERR(req)) {
  1417. retval = PTR_ERR(req);
  1418. goto out;
  1419. }
  1420. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1421. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1422. req->handler = zfcp_fsf_close_wka_port_handler;
  1423. req->data = wka_port;
  1424. req->qtcb->header.port_handle = wka_port->handle;
  1425. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1426. retval = zfcp_fsf_req_send(req);
  1427. if (retval)
  1428. zfcp_fsf_req_free(req);
  1429. out:
  1430. spin_unlock_irq(&qdio->req_q_lock);
  1431. if (req && !IS_ERR(req))
  1432. zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req->req_id);
  1433. return retval;
  1434. }
  1435. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1436. {
  1437. struct zfcp_port *port = req->data;
  1438. struct fsf_qtcb_header *header = &req->qtcb->header;
  1439. struct scsi_device *sdev;
  1440. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1441. return;
  1442. switch (header->fsf_status) {
  1443. case FSF_PORT_HANDLE_NOT_VALID:
  1444. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1445. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1446. break;
  1447. case FSF_PORT_BOXED:
  1448. /* can't use generic zfcp_erp_modify_port_status because
  1449. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1450. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1451. shost_for_each_device(sdev, port->adapter->scsi_host)
  1452. if (sdev_to_zfcp(sdev)->port == port)
  1453. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1454. &sdev_to_zfcp(sdev)->status);
  1455. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1456. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1457. "fscpph2");
  1458. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1459. break;
  1460. case FSF_ADAPTER_STATUS_AVAILABLE:
  1461. switch (header->fsf_status_qual.word[0]) {
  1462. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1463. /* fall through */
  1464. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1465. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1466. break;
  1467. }
  1468. break;
  1469. case FSF_GOOD:
  1470. /* can't use generic zfcp_erp_modify_port_status because
  1471. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1472. */
  1473. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1474. shost_for_each_device(sdev, port->adapter->scsi_host)
  1475. if (sdev_to_zfcp(sdev)->port == port)
  1476. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1477. &sdev_to_zfcp(sdev)->status);
  1478. break;
  1479. }
  1480. }
  1481. /**
  1482. * zfcp_fsf_close_physical_port - close physical port
  1483. * @erp_action: pointer to struct zfcp_erp_action
  1484. * Returns: 0 on success
  1485. */
  1486. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1487. {
  1488. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1489. struct zfcp_fsf_req *req;
  1490. int retval = -EIO;
  1491. spin_lock_irq(&qdio->req_q_lock);
  1492. if (zfcp_qdio_sbal_get(qdio))
  1493. goto out;
  1494. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1495. SBAL_SFLAGS0_TYPE_READ,
  1496. qdio->adapter->pool.erp_req);
  1497. if (IS_ERR(req)) {
  1498. retval = PTR_ERR(req);
  1499. goto out;
  1500. }
  1501. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1502. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1503. req->data = erp_action->port;
  1504. req->qtcb->header.port_handle = erp_action->port->handle;
  1505. req->erp_action = erp_action;
  1506. req->handler = zfcp_fsf_close_physical_port_handler;
  1507. erp_action->fsf_req_id = req->req_id;
  1508. zfcp_fsf_start_erp_timer(req);
  1509. retval = zfcp_fsf_req_send(req);
  1510. if (retval) {
  1511. zfcp_fsf_req_free(req);
  1512. erp_action->fsf_req_id = 0;
  1513. }
  1514. out:
  1515. spin_unlock_irq(&qdio->req_q_lock);
  1516. return retval;
  1517. }
  1518. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1519. {
  1520. struct zfcp_adapter *adapter = req->adapter;
  1521. struct scsi_device *sdev = req->data;
  1522. struct zfcp_scsi_dev *zfcp_sdev;
  1523. struct fsf_qtcb_header *header = &req->qtcb->header;
  1524. union fsf_status_qual *qual = &header->fsf_status_qual;
  1525. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1526. return;
  1527. zfcp_sdev = sdev_to_zfcp(sdev);
  1528. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1529. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1530. &zfcp_sdev->status);
  1531. switch (header->fsf_status) {
  1532. case FSF_PORT_HANDLE_NOT_VALID:
  1533. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1534. /* fall through */
  1535. case FSF_LUN_ALREADY_OPEN:
  1536. break;
  1537. case FSF_PORT_BOXED:
  1538. zfcp_erp_set_port_status(zfcp_sdev->port,
  1539. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1540. zfcp_erp_port_reopen(zfcp_sdev->port,
  1541. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1542. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1543. break;
  1544. case FSF_LUN_SHARING_VIOLATION:
  1545. if (qual->word[0])
  1546. dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
  1547. "LUN 0x%Lx on port 0x%Lx is already in "
  1548. "use by CSS%d, MIF Image ID %x\n",
  1549. zfcp_scsi_dev_lun(sdev),
  1550. (unsigned long long)zfcp_sdev->port->wwpn,
  1551. qual->fsf_queue_designator.cssid,
  1552. qual->fsf_queue_designator.hla);
  1553. zfcp_erp_set_lun_status(sdev,
  1554. ZFCP_STATUS_COMMON_ERP_FAILED |
  1555. ZFCP_STATUS_COMMON_ACCESS_DENIED);
  1556. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1557. break;
  1558. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1559. dev_warn(&adapter->ccw_device->dev,
  1560. "No handle is available for LUN "
  1561. "0x%016Lx on port 0x%016Lx\n",
  1562. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1563. (unsigned long long)zfcp_sdev->port->wwpn);
  1564. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1565. /* fall through */
  1566. case FSF_INVALID_COMMAND_OPTION:
  1567. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1568. break;
  1569. case FSF_ADAPTER_STATUS_AVAILABLE:
  1570. switch (header->fsf_status_qual.word[0]) {
  1571. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1572. zfcp_fc_test_link(zfcp_sdev->port);
  1573. /* fall through */
  1574. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1575. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1576. break;
  1577. }
  1578. break;
  1579. case FSF_GOOD:
  1580. zfcp_sdev->lun_handle = header->lun_handle;
  1581. atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1582. break;
  1583. }
  1584. }
  1585. /**
  1586. * zfcp_fsf_open_lun - open LUN
  1587. * @erp_action: pointer to struct zfcp_erp_action
  1588. * Returns: 0 on success, error otherwise
  1589. */
  1590. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1591. {
  1592. struct zfcp_adapter *adapter = erp_action->adapter;
  1593. struct zfcp_qdio *qdio = adapter->qdio;
  1594. struct zfcp_fsf_req *req;
  1595. int retval = -EIO;
  1596. spin_lock_irq(&qdio->req_q_lock);
  1597. if (zfcp_qdio_sbal_get(qdio))
  1598. goto out;
  1599. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1600. SBAL_SFLAGS0_TYPE_READ,
  1601. adapter->pool.erp_req);
  1602. if (IS_ERR(req)) {
  1603. retval = PTR_ERR(req);
  1604. goto out;
  1605. }
  1606. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1607. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1608. req->qtcb->header.port_handle = erp_action->port->handle;
  1609. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1610. req->handler = zfcp_fsf_open_lun_handler;
  1611. req->data = erp_action->sdev;
  1612. req->erp_action = erp_action;
  1613. erp_action->fsf_req_id = req->req_id;
  1614. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1615. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1616. zfcp_fsf_start_erp_timer(req);
  1617. retval = zfcp_fsf_req_send(req);
  1618. if (retval) {
  1619. zfcp_fsf_req_free(req);
  1620. erp_action->fsf_req_id = 0;
  1621. }
  1622. out:
  1623. spin_unlock_irq(&qdio->req_q_lock);
  1624. return retval;
  1625. }
  1626. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1627. {
  1628. struct scsi_device *sdev = req->data;
  1629. struct zfcp_scsi_dev *zfcp_sdev;
  1630. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1631. return;
  1632. zfcp_sdev = sdev_to_zfcp(sdev);
  1633. switch (req->qtcb->header.fsf_status) {
  1634. case FSF_PORT_HANDLE_NOT_VALID:
  1635. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1636. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1637. break;
  1638. case FSF_LUN_HANDLE_NOT_VALID:
  1639. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1640. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1641. break;
  1642. case FSF_PORT_BOXED:
  1643. zfcp_erp_set_port_status(zfcp_sdev->port,
  1644. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1645. zfcp_erp_port_reopen(zfcp_sdev->port,
  1646. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1647. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1648. break;
  1649. case FSF_ADAPTER_STATUS_AVAILABLE:
  1650. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1651. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1652. zfcp_fc_test_link(zfcp_sdev->port);
  1653. /* fall through */
  1654. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1655. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1656. break;
  1657. }
  1658. break;
  1659. case FSF_GOOD:
  1660. atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1661. break;
  1662. }
  1663. }
  1664. /**
  1665. * zfcp_fsf_close_LUN - close LUN
  1666. * @erp_action: pointer to erp_action triggering the "close LUN"
  1667. * Returns: 0 on success, error otherwise
  1668. */
  1669. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1670. {
  1671. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1672. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1673. struct zfcp_fsf_req *req;
  1674. int retval = -EIO;
  1675. spin_lock_irq(&qdio->req_q_lock);
  1676. if (zfcp_qdio_sbal_get(qdio))
  1677. goto out;
  1678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1679. SBAL_SFLAGS0_TYPE_READ,
  1680. qdio->adapter->pool.erp_req);
  1681. if (IS_ERR(req)) {
  1682. retval = PTR_ERR(req);
  1683. goto out;
  1684. }
  1685. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1686. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1687. req->qtcb->header.port_handle = erp_action->port->handle;
  1688. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1689. req->handler = zfcp_fsf_close_lun_handler;
  1690. req->data = erp_action->sdev;
  1691. req->erp_action = erp_action;
  1692. erp_action->fsf_req_id = req->req_id;
  1693. zfcp_fsf_start_erp_timer(req);
  1694. retval = zfcp_fsf_req_send(req);
  1695. if (retval) {
  1696. zfcp_fsf_req_free(req);
  1697. erp_action->fsf_req_id = 0;
  1698. }
  1699. out:
  1700. spin_unlock_irq(&qdio->req_q_lock);
  1701. return retval;
  1702. }
  1703. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1704. {
  1705. lat_rec->sum += lat;
  1706. lat_rec->min = min(lat_rec->min, lat);
  1707. lat_rec->max = max(lat_rec->max, lat);
  1708. }
  1709. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1710. {
  1711. struct fsf_qual_latency_info *lat_in;
  1712. struct latency_cont *lat = NULL;
  1713. struct zfcp_scsi_dev *zfcp_sdev;
  1714. struct zfcp_blk_drv_data blktrc;
  1715. int ticks = req->adapter->timer_ticks;
  1716. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1717. blktrc.flags = 0;
  1718. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1719. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1720. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1721. blktrc.inb_usage = 0;
  1722. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1723. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1724. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1725. zfcp_sdev = sdev_to_zfcp(scsi->device);
  1726. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1727. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1728. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1729. switch (req->qtcb->bottom.io.data_direction) {
  1730. case FSF_DATADIR_DIF_READ_STRIP:
  1731. case FSF_DATADIR_DIF_READ_CONVERT:
  1732. case FSF_DATADIR_READ:
  1733. lat = &zfcp_sdev->latencies.read;
  1734. break;
  1735. case FSF_DATADIR_DIF_WRITE_INSERT:
  1736. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1737. case FSF_DATADIR_WRITE:
  1738. lat = &zfcp_sdev->latencies.write;
  1739. break;
  1740. case FSF_DATADIR_CMND:
  1741. lat = &zfcp_sdev->latencies.cmd;
  1742. break;
  1743. }
  1744. if (lat) {
  1745. spin_lock(&zfcp_sdev->latencies.lock);
  1746. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1747. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1748. lat->counter++;
  1749. spin_unlock(&zfcp_sdev->latencies.lock);
  1750. }
  1751. }
  1752. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1753. sizeof(blktrc));
  1754. }
  1755. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1756. {
  1757. struct scsi_cmnd *scmnd = req->data;
  1758. struct scsi_device *sdev = scmnd->device;
  1759. struct zfcp_scsi_dev *zfcp_sdev;
  1760. struct fsf_qtcb_header *header = &req->qtcb->header;
  1761. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1762. return;
  1763. zfcp_sdev = sdev_to_zfcp(sdev);
  1764. switch (header->fsf_status) {
  1765. case FSF_HANDLE_MISMATCH:
  1766. case FSF_PORT_HANDLE_NOT_VALID:
  1767. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1768. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1769. break;
  1770. case FSF_FCPLUN_NOT_VALID:
  1771. case FSF_LUN_HANDLE_NOT_VALID:
  1772. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1773. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1774. break;
  1775. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1776. zfcp_fsf_class_not_supp(req);
  1777. break;
  1778. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1779. dev_err(&req->adapter->ccw_device->dev,
  1780. "Incorrect direction %d, LUN 0x%016Lx on port "
  1781. "0x%016Lx closed\n",
  1782. req->qtcb->bottom.io.data_direction,
  1783. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1784. (unsigned long long)zfcp_sdev->port->wwpn);
  1785. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1786. "fssfch3");
  1787. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1788. break;
  1789. case FSF_CMND_LENGTH_NOT_VALID:
  1790. dev_err(&req->adapter->ccw_device->dev,
  1791. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1792. "port 0x%016Lx closed\n",
  1793. req->qtcb->bottom.io.fcp_cmnd_length,
  1794. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1795. (unsigned long long)zfcp_sdev->port->wwpn);
  1796. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1797. "fssfch4");
  1798. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1799. break;
  1800. case FSF_PORT_BOXED:
  1801. zfcp_erp_set_port_status(zfcp_sdev->port,
  1802. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1803. zfcp_erp_port_reopen(zfcp_sdev->port,
  1804. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1805. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1806. break;
  1807. case FSF_LUN_BOXED:
  1808. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1809. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1810. "fssfch6");
  1811. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1812. break;
  1813. case FSF_ADAPTER_STATUS_AVAILABLE:
  1814. if (header->fsf_status_qual.word[0] ==
  1815. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1816. zfcp_fc_test_link(zfcp_sdev->port);
  1817. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1818. break;
  1819. }
  1820. }
  1821. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1822. {
  1823. struct scsi_cmnd *scpnt;
  1824. struct fcp_resp_with_ext *fcp_rsp;
  1825. unsigned long flags;
  1826. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1827. scpnt = req->data;
  1828. if (unlikely(!scpnt)) {
  1829. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1830. return;
  1831. }
  1832. zfcp_fsf_fcp_handler_common(req);
  1833. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1834. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1835. goto skip_fsfstatus;
  1836. }
  1837. switch (req->qtcb->header.fsf_status) {
  1838. case FSF_INCONSISTENT_PROT_DATA:
  1839. case FSF_INVALID_PROT_PARM:
  1840. set_host_byte(scpnt, DID_ERROR);
  1841. goto skip_fsfstatus;
  1842. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1843. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1844. goto skip_fsfstatus;
  1845. case FSF_APP_TAG_CHECK_FAILURE:
  1846. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1847. goto skip_fsfstatus;
  1848. case FSF_REF_TAG_CHECK_FAILURE:
  1849. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1850. goto skip_fsfstatus;
  1851. }
  1852. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1853. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1854. skip_fsfstatus:
  1855. zfcp_fsf_req_trace(req, scpnt);
  1856. zfcp_dbf_scsi_result(scpnt, req);
  1857. scpnt->host_scribble = NULL;
  1858. (scpnt->scsi_done) (scpnt);
  1859. /*
  1860. * We must hold this lock until scsi_done has been called.
  1861. * Otherwise we may call scsi_done after abort regarding this
  1862. * command has completed.
  1863. * Note: scsi_done must not block!
  1864. */
  1865. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1866. }
  1867. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1868. {
  1869. switch (scsi_get_prot_op(scsi_cmnd)) {
  1870. case SCSI_PROT_NORMAL:
  1871. switch (scsi_cmnd->sc_data_direction) {
  1872. case DMA_NONE:
  1873. *data_dir = FSF_DATADIR_CMND;
  1874. break;
  1875. case DMA_FROM_DEVICE:
  1876. *data_dir = FSF_DATADIR_READ;
  1877. break;
  1878. case DMA_TO_DEVICE:
  1879. *data_dir = FSF_DATADIR_WRITE;
  1880. break;
  1881. case DMA_BIDIRECTIONAL:
  1882. return -EINVAL;
  1883. }
  1884. break;
  1885. case SCSI_PROT_READ_STRIP:
  1886. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1887. break;
  1888. case SCSI_PROT_WRITE_INSERT:
  1889. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1890. break;
  1891. case SCSI_PROT_READ_PASS:
  1892. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1893. break;
  1894. case SCSI_PROT_WRITE_PASS:
  1895. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1896. break;
  1897. default:
  1898. return -EINVAL;
  1899. }
  1900. return 0;
  1901. }
  1902. /**
  1903. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1904. * @scsi_cmnd: scsi command to be sent
  1905. */
  1906. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1907. {
  1908. struct zfcp_fsf_req *req;
  1909. struct fcp_cmnd *fcp_cmnd;
  1910. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1911. int retval = -EIO;
  1912. struct scsi_device *sdev = scsi_cmnd->device;
  1913. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1914. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1915. struct zfcp_qdio *qdio = adapter->qdio;
  1916. struct fsf_qtcb_bottom_io *io;
  1917. unsigned long flags;
  1918. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1919. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1920. return -EBUSY;
  1921. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1922. if (atomic_read(&qdio->req_q_free) <= 0) {
  1923. atomic_inc(&qdio->req_q_full);
  1924. goto out;
  1925. }
  1926. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1927. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1928. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1929. sbtype, adapter->pool.scsi_req);
  1930. if (IS_ERR(req)) {
  1931. retval = PTR_ERR(req);
  1932. goto out;
  1933. }
  1934. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1935. io = &req->qtcb->bottom.io;
  1936. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1937. req->data = scsi_cmnd;
  1938. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1939. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1940. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1941. io->service_class = FSF_CLASS_3;
  1942. io->fcp_cmnd_length = FCP_CMND_LEN;
  1943. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1944. io->data_block_length = scsi_cmnd->device->sector_size;
  1945. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1946. }
  1947. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1948. goto failed_scsi_cmnd;
  1949. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1950. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1951. if (scsi_prot_sg_count(scsi_cmnd)) {
  1952. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1953. scsi_prot_sg_count(scsi_cmnd));
  1954. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1955. scsi_prot_sglist(scsi_cmnd));
  1956. if (retval)
  1957. goto failed_scsi_cmnd;
  1958. io->prot_data_length = zfcp_qdio_real_bytes(
  1959. scsi_prot_sglist(scsi_cmnd));
  1960. }
  1961. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1962. scsi_sglist(scsi_cmnd));
  1963. if (unlikely(retval))
  1964. goto failed_scsi_cmnd;
  1965. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1966. if (zfcp_adapter_multi_buffer_active(adapter))
  1967. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1968. retval = zfcp_fsf_req_send(req);
  1969. if (unlikely(retval))
  1970. goto failed_scsi_cmnd;
  1971. goto out;
  1972. failed_scsi_cmnd:
  1973. zfcp_fsf_req_free(req);
  1974. scsi_cmnd->host_scribble = NULL;
  1975. out:
  1976. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1977. return retval;
  1978. }
  1979. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1980. {
  1981. struct fcp_resp_with_ext *fcp_rsp;
  1982. struct fcp_resp_rsp_info *rsp_info;
  1983. zfcp_fsf_fcp_handler_common(req);
  1984. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1985. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1986. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1987. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1988. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1989. }
  1990. /**
  1991. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1992. * @scmnd: SCSI command to send the task management command for
  1993. * @tm_flags: unsigned byte for task management flags
  1994. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1995. */
  1996. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1997. u8 tm_flags)
  1998. {
  1999. struct zfcp_fsf_req *req = NULL;
  2000. struct fcp_cmnd *fcp_cmnd;
  2001. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  2002. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  2003. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  2004. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2005. return NULL;
  2006. spin_lock_irq(&qdio->req_q_lock);
  2007. if (zfcp_qdio_sbal_get(qdio))
  2008. goto out;
  2009. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2010. SBAL_SFLAGS0_TYPE_WRITE,
  2011. qdio->adapter->pool.scsi_req);
  2012. if (IS_ERR(req)) {
  2013. req = NULL;
  2014. goto out;
  2015. }
  2016. req->data = scmnd;
  2017. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2018. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2019. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2020. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2021. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2022. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2023. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2024. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2025. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2026. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2027. if (!zfcp_fsf_req_send(req))
  2028. goto out;
  2029. zfcp_fsf_req_free(req);
  2030. req = NULL;
  2031. out:
  2032. spin_unlock_irq(&qdio->req_q_lock);
  2033. return req;
  2034. }
  2035. /**
  2036. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2037. * @adapter: pointer to struct zfcp_adapter
  2038. * @sbal_idx: response queue index of SBAL to be processed
  2039. */
  2040. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2041. {
  2042. struct zfcp_adapter *adapter = qdio->adapter;
  2043. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2044. struct qdio_buffer_element *sbale;
  2045. struct zfcp_fsf_req *fsf_req;
  2046. unsigned long req_id;
  2047. int idx;
  2048. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2049. sbale = &sbal->element[idx];
  2050. req_id = (unsigned long) sbale->addr;
  2051. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2052. if (!fsf_req) {
  2053. /*
  2054. * Unknown request means that we have potentially memory
  2055. * corruption and must stop the machine immediately.
  2056. */
  2057. zfcp_qdio_siosl(adapter);
  2058. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2059. req_id, dev_name(&adapter->ccw_device->dev));
  2060. }
  2061. fsf_req->qdio_req.sbal_response = sbal_idx;
  2062. zfcp_fsf_req_complete(fsf_req);
  2063. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2064. break;
  2065. }
  2066. }