zfcp_fsf.c 67 KB

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